Category Archives: Android

Android Preferences and Custom Buttons

I delved into the Preference API for Android this weekend. It turns out that I needed a couple of “buttons” to allow the user to go to the main screen (for various genuine reasons!). The Android API doesn’t let you do it with buttons, but there’s an equally easy way.

I have found that using a combination of a “placeholder” Preference and then providing an onClickListener in the corresponding PreferenceActivity class provides what I needed.

In my instance, I needed a “Save” and “Clear” option in my preference screen, so I added the following PreferenceCatgory in my preferences.xml

<PreferenceCategory
android:title="Manage Your Preferences">
<Preference
android:title="Save"
android:summary="Store your preferences"
android:key="savePref" />
<Preference
android:title="Clear"
android:summary="Clear all your preferences"
android:key="clearPref" />
</PreferenceCategory>

and then inside my onCreate method, I just assigned listeners to the individual clear and save preferences:

findPreference("clearPref").setOnPreferenceClickListener(onPreferenceClickListener);

which is given an instance of my inner `Preference.OnPreferenceClickListener` class:

private class PreferenceOnClickListener implements Preference.OnPreferenceClickListener {
public boolean onPreferenceClick(Preference preference) {
//Do something...
return false;
}
}

easy?!

CyanogenMod & AndroidScreenCast

So having finally grown enough cojones, I decided to root my HTC Desire HD and install CyanogenMod. Why didn’t I do it sooner? I was scared of bricking it. The phone that is.

Having done so, I am so pleased. It’s like I have a new device: it’s snappy, responsive, fresh-looking and exciting. I can take screenshots — yes, that wasn’t possible before — or install a firewall; I can even operate it from my desktop. How awesome is that?

Going forward, because you’re not relying on your carrier to pre-package the latest and greatest version with their bloatware, you can get updates to the Android platform almost as quick as they’re made available by Google. Furthermore, you get the ROMs listed for your device within a neat little app called ROM Manager that’ll even take care of backing up your system prior to upgrading. It’s very impressive (if a little script-kiddie-ish!).

My favourite thing — apart from having the ability to restrict apps via DroidWall — has to be what I mentioned earlier: using my phone from my desktop PC. AndroidScreenCast utilises the Android SDK to let you point-and-click on your phone from your PC, all via USB. It works really well — if a little slow at times — and means I don’t have to keep picking my phone up to reply to SMS and so-on. It’s a great little tool.

Hell, I might even start contributing to it soon. It’s all open source and in Java; perfect!

rooted Desire HD with CyanogenMod

Screenshot of my rooted Desire HD running CyanogenMod