The Java experience made me want to rewrite all the pieces of Python code to a more cross-platform language. Java is cross platform in the sense that a compiled Java program runs on all platforms for which there exists a JVM (This holds for all major operating systems, including Windows, Mac OS and Linux.). First application to get Java implementation was the Google Alarm Clock. Since I am using the alarm on a daily basis, I thought to give it a try (after that I intend to test the Pi4j Java library to use Raspberry Pi GPIO with Java). The application works fine, but lacks some features, but I'm constantly improving it and making it better. Here's what I come up with so far.
How it works
The basic principle of the application is the same as the Python script I've introduced in September last year. We add an event to the Google calendar (it can be done within the application), and once the alarm clock is started it queries Google Calendar for events matching our criteria:
Code: Select all
CalendarService myService =
new CalendarService("SimpleGoogleAlarmClock");
myService.setUserCredentials(mail, decryptedPass);
URL feedUrl = new URL("http://www.google.com/calendar/feeds/default/private/full");
CalendarQuery myQuery = new CalendarQuery(feedUrl);
myQuery.setMinimumStartTime(s);
myQuery.setMaximumStartTime(e);
myQuery.setFullTextQuery(query);
myQuery.setStringCustomParameter("singleevents", "true");
myQuery.setStringCustomParameter("sortorder", "a");
CalendarEventFeed myResultsFeed =
myService.query(myQuery, CalendarEventFeed.class);
for (int i = 0; i < myResultsFeed.getEntries().size(); i++) {
CalendarEventEntry MatchEntry = (CalendarEventEntry) myResultsFeed.getEntries().get(i);
String time = MatchEntry.getTimes().get(0).getStartTime().toUiString();
String wakeup = MatchEntry.getTitle().getPlainText();
queryArea.append("\t" + time + " " + wakeup + "\n");
}The application would work both on Windows and Linux machines. I suppose Mac users would be able to use it fully as well. As long as you have Java installed on your machine, you are good to go.There is no need to download and install any additional libraries, programs, files, as all the libraries needed are included with the project. You can even run the application on Raspberry Pi (just type sudo apt-get update && sudo apt-get install oracle-java7-jdk from your console to install it). The application is set to recognize the operating system it is running on and adjust paths and external commands according to the OS. Moreover, there is no need for working directory. The application would work from anywhere, just make sure the lib subdirectory is placed in the same directory as the jar file.
To start the application, just double click on the GoogleAlarmClock.jar file from Desktop mode, or if you want to start it from command line (Desktop is needed though), type:
Code: Select all
java -jar /path/to/GoogleAlarmClock.jar
Once the local date and time on your machine matches the event start date-time of an event, the application starts (depending on the operating system: Windows: Windows Media Player; Linux: mpg321) music player that plays random mp3 from pre-set directory.
If you want to read more about my Google Alarm Clock, head to my blog:
http://www.bartbania.com/index.php/goog ... goes-java/