Archive for March, 2011

More sleeping with the enemy. Next up: Android

Saturday, March 12th, 2011

As it’s now all about the money, it makes sense to look into developing for the only other viable modern smartphone OS, so I got an e-book on Android development and set out to port two of my simpler iPhone apps to it.

Much like the iPhone originals, rewriting them for Android didn’t take long, and gave me a good chance to assess Android development and compare it to the experience of iPhone development.

What did I find?

Well, first off, I almost hate to say this, because I know that one gets used to what they know, and something unfamiliar can often be perceived as frustrating, poorly designed, garbage, etc…

That said… I really, really am not a fan of Eclipse, which is the IDE that the official Android development pages tout as the de-fact Android development IDE.

When the T-Mobile G1 first came out, we dabbled a bit in Android development.

It was hard to get past the fact that there was no visual layout tool for Android that was even in the same ballpark as Interface Builder for iPhone.

It’s been a couple of years. I figured that they MUST have improved the layout tool by now.

Ummm. NO.

Sorry, but it’s absolutely terrible.

On top of that, I think the Android emulator leaves a lot to be desired compared to the iPhone/iPad simulator.

But I could live with those. I actually, at times, found myself enjoying Android development.

Except for one little thing.

Almost every time I wanted to figure out how to do something with my UI, and I searched online to find the answer, most, if not all of the answers started with something to the effect of: “in the layout xml, you…”

I’m not a fan of Java’s layouts. I’m also not a fan of performing tasks in xml. Lacking a good Interface Builder equivalent, I do most of my UI creation in code. Therefore I need answers for how to accomplish things IN CODE. I’m amazed at how hard it can be to find such answers for Android.

But the real problem is, it’s not just that the answers are hard to find, sometimes they don’t exist. Android is a very nice mobile OS, with some very nice features. However, the SDK seems kind of half-baked, because a lot of the features aren’t available programmatically, or at least are unnecessarily hard to get to programmatically.

Here’s one example:

I have a button. I have two graphics files for that button. One for the up state and one for the down state.

I expect that for any SDK for any OS that I’m using, I can find a call such that I can set those up and down images in a couple of lines of code like this:

 

setImageForState (img, BUTTON_STATE_UP);

setImageForState (img, BUTTON_STATE_DOWN);

 

Done.

And sure enough, on the iPhone, we have:

 

[button setImage:upImage for State:UIControlStateNormal];

[button setImage:downImage for State:UIControlStateSelected];

 

So how do we accomplish the same thing in an Android app?

Would you believe:

 

button.setOnTouchListener(new View.OnTouchListener() {

public boolean onTouch(View v, MotionEvent event) {

if(event.getAction()==MotionEvent.ACTION_DOWN)

button.setImageResource(R.drawable.buttonpressed);

if(event.getAction()==MotionEvent.ACTION_UP)

button.setImageResource(R.drawable.buttonup);

return false;

}

});

 

No, I’m not kidding, and it took a while to find this solution, most answers just said, “in the layout xml…”

Sorry, but that’s ridiculous.

So the bottom line is, Android is a perfectly fine mobile operating system, and it may one day be a pleasure to write for if they actually develop a decent layout design tool for it and give developers simple programmatic access to all of the functionality available through layout xml.