Tuesday, December 16, 2008

Mippin goes Android

I've spent the last 3 days delving into the depths of the Android SDK and you know what? they've been a pretty plesant 3 days. The API documentation takes a little getting used to but when you figure out the best way to navigate it is to use search (I should've figured that one out a little quicker for a google product) it all starts to fall into place pretty quickly. The Android guys have provided a pretty complete set of default widgets and themes to make development rapid and to make your final product blend well into the phones UI.

The result of my time spent on the Android SDK is the Mippin app, which is now in the Android Market Store. That's right I finished the first version of the app yesterday evening and within 10 minutes I'd signed up, paid my $25 to become a registered Android developer and published the app into the Market place, seconds later it was live for download. That was a great experience, so simple, I spent the evening checking my phone every half hour to see how many downloads the app had and to see the comments coming in. In the first 12 hours there were over 3000 downloads - not bad.

As yet I haven't published the source code for the app, but if there is anything in there that you'd like to know how it was done just comment on this post and I'll get back to you. The development process showed that in the end there is usually a pretty simple way of doing each seemingly tricky task, usually I ended up writing many lines of code before realising I could add a single line into an XML file. But here are my top 3 tricks I figured out while developing the app:

1. The translucent blurred background on the keyboard view
This is much simpler than it really should be, Android provides a set of default themes for any View and they can be applied in the AndroidManifest.xml file, this one is android:theme="@android:style/Theme.Translucent.NoTitleBar", like this:

<activity android:name=".TranslucentBlurActivity" class=".TranslucentBlurActivity"

2. Get on top of Intents and returning results from them
Intents are one of the keys to happy Android developing. They generally start an activity to complete a task. You can create intents which are set to return values. For example to launch my search box I create this intent from my Activity when the menu item is selected:

Intent intent = new Intent(MipWeb.this,OSKActivity.class);
intent.putExtra("boxtype", TranslucentBlurActivity.BOX_SEARCH);
startActivityForResult(intent, ACTION_SEARCH_BOX);

Then in the activity of the search box I return the search term enter using this code

Intent mIntent = new Intent();
mIntent.putExtra("search", searchBox.getText().toString());

This sends the result to the onActivityResult() method in the calling Activity.

3. Auto rotation doesn't need to be hard
In the onCreate() method of an Activity just call setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); this works for all standard widgets that support orientation like the WebView.

happy coding.

1 comment:

Scott said...

I'm liking Mippin on the G1. Very easy to get a lot out of it!
Scott L