Thursday, October 23, 2008

BistroMath

My second Android application is a special-purpose calculator for solving some of the problems which often arise when it comes to paying the bill in a restaurant - like computing the tip or splitting the bill among N people. This seemed like a reasonably useful application for a device which the user always carries around and one that is very simple to do. In fact it turns out that tip calculators are somewhat the "hello world" equivalent of mobile application development. To be useful, the user experience would have to be very simple and rapid - not necessarily obvious with the clunky keyboard setup of the G1!

The calculator uses a table view of buttons as a virtual keypad for inputting numbers and another table on the top to display the results. The display table is fully specified in the XML layout file, while the cells of the keypad table are generated by the code. There is a menu to select the input fields (price, tax, tip, number of people and currency exchange rate) which can also be selected by touching the specific fields on the display using customized touch-event handlers.

When the keyboard is active, the virtual keypad is hidden and the activity intercepts keystroke events for updating the display. The application is not using any input widget, but raw events to update the display grid at every key-stroke.

The code is open-source and can be found at http://code.google.com/p/android-labs/source/browse/trunk/BistroMath