Friday, November 6, 2009

KeyboardView problem

A few days ago I tried playing with KeyboardView to make my own virtual keyboard for a little application. I had a big surprise which cost me a couple of hours (around 4-5). I even posted an issue here. Nothing special happened and no one responded to my post. I took the matter into my own hands and tried again different ways. I managed to locate the bug: THE CONTEXT. You cannot create a KeyboardView using the application context. You HAVE to use the Activity context. The developers from Android SDK said "they HAD to make the application context, but it doesn't really do anything" !? Maybe they SHOULD have warned the developers about the RISKS of using it. And by the way, if you use the Activity context and manage the orientation change event you WILL experience the memory leaks and the application crash.
So kids, do not play with Context at home. And if you do choose carefully whether to have memory leaks or to create your own KeyboardView (or maybe better, your own Android SDK).

Sony Ericsson Xperia X10 skin

It seems that Xperia X3 from my previous post is actually called X10 and it's indeed a new Android phone. You can find all the details here. I don't know when we will be able to buy one but if you're an Android developer you can at least use Xperia X10 skin on your emulator. The skin supports Android SDK 2.0 and you can download it from by clicking here. If you don't like it, you can find out other skins here.

Monday, November 2, 2009

Sony Ericsson Xperia X3 surprise





So there are about 24 hours left until Sony Ericsson comes up with news on Xperia X3 (also known as Rachael). There are some leaked pictures and technical specifications on the web but we can't get excited until tomorrow. But if the rumors will be confirmed this is going to be a hell o' a phone:
- OS: Android
- Processor: 1GHz Qualcomm Snapdragon
- Camera: 8 mega-pixels
- HSDPA (10Mbps)
- HSUPA (2Mbps)
- Navigation: AGPS
- Audio connector: 3.5mm (which is pretty cool)

With a little bit of luck in the near future we will be able to run Windows XP on a mobile phone using a virtual machine. All we need is a little bit of RAM and processor which supports visualization. Until then we, the mobile enthusiasts, will run XP on PCs and notebooks like normal people.

Sunday, November 1, 2009

AnimationDrawable problem

You may encounter a big problem when playing with an AnimationDrawable object in Android: it won't start! Actually it will remain blocked on the first frame and it will confuse you why it didn't start moving. So you may lose this way a couple of hours just trying to find where is the problem. The code seems to be okay, you did something like this:

public class Present extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LinearLayout l = (LinearLayout) findViewById(R.id.main);
AnimationDrawable d = (AnimationDrawable) getResources().getDrawable(R.drawable.myanimation);
d.setBackgroundDrawable(d);
d.start();
}
}

I saw a couple of people complaining on forums but no one answered to their problem.
Now the catch is that no UI object is created until the onCreate function call is terminated. I assume that android internal framework doesn't start rendering the UI after setContentView, but it waits for the onCreate to terminate then it starts showing all the graphic elements. So what you need to do is call "d.start()" after we get past onCreate. Though I'm not saying it's the best solution, here is a little workaround:

public class Present extends Activity{
class AnimationStarterThread extends Thread{
private AnimationDrawable myAnimation;
public AnimationStarterThread(AnimationDrawable ad)
{
myAnimation = ad;
}
public void run()
{
ad.wait();
try {
Thread.sleep(100);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
ad.start();
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LinearLayout l = (LinearLayout) findViewById(R.id.main);
AnimationDrawable d = (AnimationDrawable) getResources().getDrawable(R.drawable.myanimation);
d.setBackgroundDrawable(d);
AnimationStarterThread ast = new AnimationStarterThread();
ast.start();

//do other initialisations

ad.notify();
}
}


It's very far from an elegant solution. If I'll find a way to hook the event of UI post-initialization(this is the way to do it) I'll post an update.