Android Pt.2 Digging Deeper Into ADK

I’ve been using and coding with bluetooth for quite some time using Java, C++, and J2ME. Java’s support for bluetooth is fairly decent although for the JDK you need to use an SDK from a 3rd party – I’ve used bluecove.org for this. In the past I’ve used bluetooth for connecting serial devices to exchange data payloads in an XML or ASCII text bump. Today I’m going to see if I can get my droid tablet to pair with my laptop and send something – maybe a picture.

Eclipse ADK
I’m going to be using the Eclipse ADK plugin for development (see my other post for info. on that). A smart place to start is the great set of sample applications that come with the ADK. In Eclipse go to new project, other, and android. Under there you should see a Android Sample folder with a lot of templates to get going quickly. I picked off the “widget preview” project as a good place to get started. In this example you can get a good view of UI and event handling and also lots of samples for controllers and other OS level stuff. I see there are also samples for some bluetooth stuff…cool…maybe this will be easy 🙂

The next step is to make sure that you have the latest and greatest installed. Using the ADK Manager from either inside Eclipse or from the start menu I’ve added all the latest updates to my current SDKs and also added the new 4.0.3 SDK for tablets. You should be able to right-click the project and click Run As and pick off Android Application.

If that choice is missing then you need to add a run configuration from the same menu – I described this in my earlier post so I won’t again here….onto the code! You should run your program just to make sure that all the stuff is working properly – it does take quite some time to startup the tablet OS emulator. It could be that this program just takes a while to load.I found that I had to change my run configuration launch to “manual” in order to select between launching the app as a tablet vs. a phone.

This project is one class file that loads up related sets of widgets. If you look at the code there are a couple of click handlers that pass variables to control what sets of widgets are on screen. The widgets don’t really do anything, but you get to see the basic set for your apps. Moving on the Contact Manager example is a good example to look at because it interacts with the base OS data structures for accounts and contacts. The contact manager’s main class extends Activity, implements the OnAccountsUpdateListener interface., and initializes the app and gui in the onCreate function. The program contains several utility classes for data handling and synch with the base OS contact/account management machinery. To see the GUI layout look in the reslayout folder and double-click one of the xml files. The Pixel Perfect interface should open up automatically. If it does not switch manually to the perspective – or right click the XML file and use open with to open the editor you want. Pixel Perfect is the GUI layout tool for the ADK. Compared to other GUI layout tools it is a bit odd to work with. Why? There is no visible set of “properties” to manipulate.

If you have used WindowBuilder Pro (another Google tool that is now part of Eclipse for designing desktop Java apps), Pixel Perfect’s layout tools and buttons look and work similar. To access properties of a specific widget dropped onto a canvas you need to right click it – or go to the XML and edit it by hand. It takes a  bit of fiddling around and the terminology is a bit odd – there are better places to read about this than here:

  • http://www.google.com/events/io/2009/sessions/PixelPerfectCodeInteractionDesignAndroid.html
  • http://developer.android.com/guide/developing/debugging/debugging-ui.html#pixelperfect

Pixel Perfect combines with a few other tools later in the development cycle to help optimize your GUI. These are available through the HierarchyViewer tool – a pretty cool tool that helps you inspect and tune all your screens during run time testing.

This was about Bluetooth right?
Ah yeah – that’s right – well let’s take a peek at some bluetooth and compare it a bit to J2ME and J2SE in my next post. I want to spend a bit more time messing with the Perfect Pixel stuff.

Leave a Reply

%d bloggers like this: