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"
  android:label="@string/activity_transparent"
  android:theme="@android:style/Theme.Translucent.NoTitleBar">
</activity>


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());
setResult(RESULT_OK,mIntent);
finish();

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.

Monday, December 01, 2008

T-Mobile G1 Battery Conditioning and Calibrating



The T-Mobile G1 is a great device, a great device with a slightly wonky screen. It maybe new to the market but it is making quite a stir. Often due to its Android OS, but unfortunately its terrible battery life gets almost as much attention. Following a couple of simple steps I'm now obtaining reasonable life from my G1 with it now lasting a day between charges.

There are two issues here, battery meter calibration and battery conditioning - the G1's battery meter seems to come particularaly poorly calibrated, mine was reading 1% remaining when I still had around 15%-20% remaining (use Power Meter from App Store to see the voltages). Maybe it is down to the flexability of the Android OS, maybe not, either way you need to calibrate the battery meter yourself.

To calibrate the battery meter let the phone run down to 0% battery and turn itself off, for the last percent or two don't apply too much load to the device, just let it drain out. Even while using it my G1 hung on to its last 1% of battery for almost 2 hours. Now the battery meter knows the real 0% point. Then get it charging, I'd recommend charging it with it turned off for 5 or 6 hours. I've done this twice now, the second was a couple of days after the first time made the most difference to battery life. This should have now calibrated the meter and conditioned the battery.

I personally wouldn't do this too often, I'm under the impression the Lithium Ion batteries don't like being discharged to this level or at least left in that state for too long - although that may be a myth.