TinyLabs

I would love to change the world, but they won't give me the source code

Arabic on j2me – Lwuit

March18

Arabic on j2me – Lwuit

I hope my first post will be useful for j2me developers…

… ok .. let’s begin the story ..actually I was facing a huge problem of getting a Nice Looking (not the j2me native textfield as it’s very ugly it remind me of writing on a stone ) Textfield to work with direct input ( I mean without popping up extra textarea as t9 for example  ) so after giving up with painting textfield on canvas I tried the opensource  j2me Polish it’s really  a very rich UI  library also the examples are very helpful to me and the documentation is cool  and the important thing it supports the direct input in textfield ..but i faced another problem which is ARABIC input in that textfield unfortunately it wasn’t supported  …
After some research and testing for some j2me libraries . I found the great lwuit Really it’s A very flexible , UI rich , portable library it can give you the same result as if you are coding using iPhone UI libraries  and I found also that there’s bidi support and I found a video of Hebrew application based on lwuit and there’s Hebrew support in the direct input field so i began to learn the library and i googled about code snippets on how to get Hebrew or Arabic working with the code and there was a leak of documentation in that area so i began to implement the logic about a container ( hashmap for example ) that contain the Arabic unicodes for then i mapped the Arabic letters to the numeric mobile keypad the hash map looks like :

private static final String[] ARABIC_KEY_CODES = { // 0 " +0", // 1 ".,?!'\"1-()@/:_", // 2 done "\u0628\u0629\u062A\u062B2", // 3 done "\u0627\u0621\u0623\u0625\u0622\u0624\u06493", // 4 done "\u0633\u0634\u0635\u06364", // 5 done "\u062F\u0630\u0631\u06325", // 6 done "\u062C\u062D\u062E6", // 7 "\u0646\u0647\u0648\u064A7", // 8 "\u0641\u0642\u0643\u0644\u06458", // 9 done "\u0637\u0638\u0639\u063A9", };

then i iterate  over this hashmap to replace values  and i added the new arabic value  to the TextField input attributes using  addInputMode()  .

Note : you can turn the hashmap to Hebrew by replace the unicodes with the Hebrew unicodes

so by using the demo lwuit TextField example the result was

Arabic with lwuit

also you can browse the source code using git and run in order to make things faster  ( this is not a spoon feeding )

Actually thanks to lwuit team and thanks to the opensource community

I hope this info will be helpful for mobile developers also i’m really sorry as my english is not that good .

posted under j2me | 5 Comments »

Welcome To my Blog

March17

For all geeks and people who have no life this is your station