LWUIT makes physical keyboard speak a foreign language

By

November 28, 2012UncategorizedNo comments

If it ever happened that You have been creating some app for an outdated feature phone that runs Java ME, You probably considered using LWUIT lib just to make Your life easier. Yes, I have been coding for some fossil devices and using some prehistoric technologies that everybody is starting to forget… Well how funny may it sound a coding experience is an experience while someone is paying for it :) .

While developing this application I have faced some issues when customer decided that the standard physical keyboard of the device that we were developing for has to support some Danish specific symbols. First idea that shoots right to your brain is that the tester hasn’t changed language on the device. This will not help. LWUIT also features a very nice and customizable on screen keyboard but what can You do when device has only a numeric keypad? After some investigations through trial an error I have found an answer that is quite simple but I was stunned that nobody has written about it (or maybe Google has censorship for LWUIT intel). Anyway if You have faced such problems and cannot make the physical keyboard speak characters like Æ, Ø or Å I hope my description will help.

What You have to do is exploit notoriously undocumented com.sun.lwuit.TextField class method called addInputMode(…). Here’s an example:

As You see in the example what You have to do is create a hash table in a [code of the number button symbol] : [string of assigned symbols] fashion. Assigned characters in the string have to be in the sequence You are expecting to toggle through them and case also matters. So if You want lowercase symbols You have to add one more input mode with lowercase character table. And don’t forget to set the input mode order for the actual instance of TextField. Good luck !

Leave a Reply