[tuxdroid-svn] r5654 - software_suite_v3/software/plugin/plugin-weather/branches/random_sentences/p
Status: Beta
Brought to you by:
ks156
|
From: ks156 <c2m...@c2...> - 2009-10-14 11:26:04
|
Author: ks156
Date: 2009-10-14 13:25:47 +0200 (Wed, 14 Oct 2009)
New Revision: 5654
Modified:
software_suite_v3/software/plugin/plugin-weather/branches/random_sentences/plugin-weather/src/net/karmaLab/tuxDroid/plugins/WeatherPlugin.java
Log:
* Updated the gadget to return a sentence from a list
Modified: software_suite_v3/software/plugin/plugin-weather/branches/random_sentences/plugin-weather/src/net/karmaLab/tuxDroid/plugins/WeatherPlugin.java
===================================================================
--- software_suite_v3/software/plugin/plugin-weather/branches/random_sentences/plugin-weather/src/net/karmaLab/tuxDroid/plugins/WeatherPlugin.java 2009-10-14 11:05:24 UTC (rev 5653)
+++ software_suite_v3/software/plugin/plugin-weather/branches/random_sentences/plugin-weather/src/net/karmaLab/tuxDroid/plugins/WeatherPlugin.java 2009-10-14 11:25:47 UTC (rev 5654)
@@ -34,6 +34,8 @@
import java.net.URL;
import java.net.HttpURLConnection;
+import java.util.Random;
+
import com.kysoh.tuxdroid.plugin.framework.plugin.SimplePlugin;
import com.kysoh.tuxdroid.plugin.framework.plugin.SimplePluginConfiguration;
import com.kysoh.tuxdroid.plugin.framework.plugin.SimplePluginException;
@@ -94,6 +96,40 @@
}
+ String[] todayWeatherSentences = {
+ "Current weather at {0} is \"{1}\" with a temperature of {2} degrees {3}; Humidity level is {4} percent.",
+ "In {0}, the weather is {1} with a temperature of {2} degrees {3}. The humidity level is {4} per cent.",
+ "The weather is currently {1} in {0} with a humidity of {4} per cent. The temperature is around {2} degrees {3}.",
+ "With a temperature of {2} degrees {3}, the weather in {0} is {1}, and the humidity level is {4} per cent."
+ };
+
+ String[] todayUnknownWeatherSentences = {
+ "Current weather at {0} is \"unknown\" with a temperature of {1} degrees {2}; Humidity level is {3} percent.",
+ "In {0}, the weather is unknown with a temperature of {1} degrees {2}. The humidity level is {3} per cent.",
+ "The weather is currently unknown in {0} with a humidity of {3} per cent. The temperature is around {1} degrees {2}.",
+ "With a temperature of {1} degrees {2}, the weather in {0} is unknown, and the humidity level is {3} per cent."
+ };
+
+ String[] tomorrowWeatherSentences = {
+ "Tomorrow's forecast. \"{0}\" temperatures from {1} to {2} degrees.",
+ "Tomorrow, the weather will be {0} with temperatures between {1} and {2} degrees.",
+ "With temperatures between {1} and {2} degrees, tomorrow's forecast is expected to be {0}.",
+ "Tomorrow's weather will be {0} with temperatures between {1} and {2} degrees.",
+ "Tomorrow, the weather will be {0} with temperatures from {1} up to {2} degrees."
+ };
+
+ String[] errorSentences = {
+ "Location could not be found. Please check the city name or enter another close by location.",
+ "Impossible to find the specified city name. Are you sure this city really exists ?",
+ "The city you specified could not be found in my database. Make sure the city name exists, or specify another close by city name.",
+ "I'm sorry, but I cannot give you the weather for the specified location. Please try another close by city name."
+ };
+
+ private String pickSentence(String[] list) {
+ Random rand = new Random();
+ return list[rand.nextInt(list.length)];
+ }
+
public static enum Unit {
celsius, fahrenheit
}
@@ -173,10 +209,10 @@
humidity = ((String) humidity.subSequence(0, humidity.length() - 1)).trim();
humidity = humidity.replaceAll("[^a-zA-Z0-9]", "");
if (weather.length() == 0) {
- throwMessage("Current weather at {0} is \"unknown\" with a temperature of {1} degrees {2}; Humidity level is {3} percent.", configuration().getLocation().replace("%20", " "), temperature, configuration().getUnit() == Unit.celsius ? "celsius" : "fahrenheit",
+ throwMessage(this.pickSentence(todayUnknownWeatherSentences), configuration().getLocation().replace("%20", " "), temperature, configuration().getUnit() == Unit.celsius ? "celsius" : "fahrenheit",
humidity);
} else {
- throwMessage("Current weather at {0} is \"{1}\" with a temperature of {2} degrees {3}; Humidity level is {4} percent.", configuration().getLocation().replace("%20", " "), weather, temperature, configuration().getUnit() == Unit.celsius ? "celsius" : "fahrenheit",
+ throwMessage(this.pickSentence(todayWeatherSentences), configuration().getLocation().replace("%20", " "), weather, temperature, configuration().getUnit() == Unit.celsius ? "celsius" : "fahrenheit",
humidity);
}
@@ -203,13 +239,13 @@
temperatureHigh = getData(current, "high");
}
- throwMessage("Tomorrow's forecast. \"{0}\" temperatures from {1} to {2} degrees.", weather, temperature, temperatureHigh);
+ throwMessage(this.pickSentence(tomorrowWeatherSentences), weather, temperature, temperatureHigh);
}
outputFile.deleteOnExit();
file.deleteOnExit();
} catch (Exception e) {
// When a location is unknown, the Google API send back a XML content without data.
- throwMessage("Location could not be found. Please check the city name or enter another close by location.");
+ throwMessage(this.pickSentence(errorSentences));
}
}
|