[tuxdroid-svn] r5644 - software_suite_v3/software/plugin/plugin-clock/branches/random_sentences/sou
Status: Beta
Brought to you by:
ks156
|
From: ks156 <c2m...@c2...> - 2009-10-14 07:27:57
|
Author: ks156
Date: 2009-10-14 09:27:43 +0200 (Wed, 14 Oct 2009)
New Revision: 5644
Modified:
software_suite_v3/software/plugin/plugin-clock/branches/random_sentences/sources/net/karmaLab/tuxDroid/plugins/ClockPlugin.java
Log:
* Improved the code with :
- Special sentences for xh15, xh30, xh45
- Special sentences for noon and midnight
- Added variations sentences for all other hours
Modified: software_suite_v3/software/plugin/plugin-clock/branches/random_sentences/sources/net/karmaLab/tuxDroid/plugins/ClockPlugin.java
===================================================================
--- software_suite_v3/software/plugin/plugin-clock/branches/random_sentences/sources/net/karmaLab/tuxDroid/plugins/ClockPlugin.java 2009-10-14 07:24:12 UTC (rev 5643)
+++ software_suite_v3/software/plugin/plugin-clock/branches/random_sentences/sources/net/karmaLab/tuxDroid/plugins/ClockPlugin.java 2009-10-14 07:27:43 UTC (rev 5644)
@@ -25,6 +25,7 @@
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
+import java.util.Random;
import com.kysoh.tuxdroid.plugin.framework.plugin.SimplePlugin;
import com.kysoh.tuxdroid.plugin.framework.plugin.SimplePluginConfiguration;
@@ -39,6 +40,17 @@
* @throws Exception
* errors
*/
+
+ String[] normalSentences = {
+ "Current time is {0} hours and {1} minutes.",
+ "At the next top, it will be exactly {0} hours {1} ... TOP !",
+ "It's {1} hours and {0} minutes ... oops, {0} hours and {1} minutes"
+ };
+ String[] sharpSentences = {
+ "Current time is {0} o'clock",
+ "At the next top, it will be exactly {0} o'clock ... TOP !",
+ };
+
public static void main(String[] args) throws Exception {
new ClockPlugin().boot(args, new SimplePluginConfiguration());
}
@@ -59,12 +71,50 @@
calendar.setTime(new Date());
int h = calendar.get(Calendar.HOUR_OF_DAY);
int m = calendar.get(Calendar.MINUTE);
- if (m != 0) {
- throwMessage("Current time is {0} hours and {1} minutes.", h, m);
- } else {
- throwMessage("Current time is {0} hours.", h);
+
+ Random rand = new Random();
+ Boolean random = rand.nextBoolean();
+
+ if (m == 0)
+ {
+ if (h == 0)
+ throwMessage("It's midnight");
+ else if (h == 12)
+ throwMessage("It's noon");
+ else
+ throwMessage(this.pickUpWeatherSentence(sharpSentences), h);
+ }
+ else if (m == 15)
+ {
+ if (random)
+ throwMessage("It's quarter past {0}", h);
+ else
+ throwMessage(this.pickUpWeatherSentence(normalSentences), h, m);
}
+ else if (m == 30)
+ {
+ if (random)
+ throwMessage("It's half past {0}", h);
+ else
+ throwMessage(this.pickUpWeatherSentence(normalSentences), h, m);
+ }
+ else if (m == 45)
+ {
+ if (random)
+ throwMessage("It's quarter to {0}", (h + 1));
+ else
+ throwMessage(this.pickUpWeatherSentence(normalSentences), h, m);
+ }
+ else
+ {
+ throwMessage(this.pickUpWeatherSentence(normalSentences), h, m);
+ }
}
+
+ private String pickUpWeatherSentence(String[] list) {
+ Random rand = new Random();
+ return list[rand.nextInt(list.length)];
+ }
@Override
public void onPluginStop() {
|