Wednesday, April 29, 2009

Watchtower updated. Now with Spy Glass!



Watchtower is a program that turns an Android phone into a wireless surveillance device. I recently revised Watchtower: it now includes the option of staying awake, a new icon, and a cleaner UI.

The real advance has been a desktop program called Spy Glass, which shows you the view through the Watchtower. It is completely written in Java, and works beautifully on Linux, Mac and Windows.



Downloads for both Spy Glass and Watchtower, and updated information is available.


Go get it now, that's all I can say.



Alright, for the more technical aspects. This was the first time I wrote something large in Java, for the desktop. I had looked at Java earlier (in the jdk 1.0 days), when it would compile and run on my Linux machine, and the binary also worked on Windows. I had written some dopey Blackjack program for the commandline, and was suitably impressed about how a single class file could work beautifully on two systems. I did not bother writing applets, partly because I had a terrible network connection and no use for them, and partly because my Pentium 100 would have a cardiac arrest at the sight of applets.

Before writing Watchtower, I had used Remote Droid for the Android, which turns the phone into a remote keyboard and mouse. Very handy when controlling a media center, and it worked perfectly in Linux. The Remote Droid authors had written their desktop program in Java. I figured it was a good idea for Watchtower to have its own pre-packaged desktop program, to make it easier for lay persons to use. Given that the Java marketing slogans routinely abuse the words network, cross platform and rapid, I figured it was a good time to give Java a try.

The good parts: The Jetty project has written a full J2EE web server in Java, which makes it trivial to embed a full web server in Java code. All I had to do was write a simple servlet which accepts POST requests, stores the images in a location and displays them. The Apache library had awesome servlet-side code which could parse a POST request and return the file.

So all one had to do was put it together, write some trivial Java code to display an image, and update the image when it changed. My work is a single class which is a servlet, contains an embedded web server, and is a JFrame as well! The Eclipse IDE was astonishingly good, perhaps better than IntelliJ on this project due to the vast hordes using Eclipse along with Jetty.

I put in some effort to unpack all the jetty and apache class files, put my own class files, and then packed it all together as a single jar. Again, the Java commandline tools were quite painless, and it was easy to handle, once I knew what I was doing.

In summary, this was ridiculously easy.

The bad parts: the documentation was often quite confusing. Java API documentation is a great reference, and beyond the Java Tutorial, one has to do a lot of searching on the Internet to find how to hook the parts together. Some of this was my own lack of understanding, since I was totally clueless at the start. That said, it seems that there should be a better way to highlight what the bits are doing beyond some pithy API document. Google was very helpful, of course. A minor hurdle remains that jar files cannot have file-specific icons, which means that spy glass gets platform-specific icons.

Finally, I am using some beautiful icons developed by Jacal Team and Artua. Thanks to them for sharing their work and letting others use it.