 |
Community: Mobile & Embedded Archives
LWUIT sounds great!!!
Posted by netomarin on May 07, 2008 at 08:06 PM | Permalink
| Comments (0)
Hi all,
This post it´s just to express my excitement with this great API. I´ve just read the tutorial and make little examples, and it´s look easy.
I'm realy thinking about use it on CoSMo, to make it more "friendly" and with a better look.
Now, I'm creating an expenses tracker with LWUIT and when it´s finished I'll post it here with my impressions about it!!
Cya!
Neto Marin
Java ME Internationalization with "home made" solution!
Posted by netomarin on May 01, 2008 at 12:58 PM | Permalink
| Comments (0)
Hi all,
After a long and tenebrous winter, finally I had time to write again somethings that I think are usefull about mobile development, and, mainly, about Java ME! =)
And, how my purpose here is to show you my experiences and solutions to some problems that I have in my daily work, I'll write about a home made solution created to implement internationalization support on my application!
Attention: If you want to see a portuguese version of this post, please visit http://netomarin.blogspot.com
The Problem
I wanted to create an application that could reach biggest possilbe number of people, but before the application I have a difficulty: Idioms!!
I would not like to have a different build to each idiom I had to support. So, my first ideia it was use JSR 238 (Mobile Internationalization API), but when I looked at the devices matrix, I found just few devices and only Sony Ericsson devices.
In this case, a solution is using a workaround that allows a user to have a option of choosing among several languages within a single distribution, which it will make my life easier.
"Home made" Solution
I know that JSR 238 cover the internationalization as a whole, and not only the question of language, but as in my case the problem was ONLY the language of the application, my homemade solution is focused on support for multiple languages.
Then, I created the class LanguageManager which has two static methods for the use of language, the interface MessagesKey that contains all the keys to the messages used in the application and, of course, properties files for each language you want to provide.
Properties File
This file has no mystery. This is the classic format "KEY = VALUE", and each pair should be in its own line. To facilitate the reading of this file, it may have comments on lines beginning with "#".
In addition to the rule of "composition" of the contents, the file name should also follow a rule: It should be in a separate directory called "properties" and his name shall be composed of the code of language with the extension .properties, such as "pt-br.properties". Below is an example of an excerpt from a propertie that I use:
pt-br.properties
#COMMANDS
CMD_CONTINUE=Continuar
CMD_EXIT=Sair
CMD_SEARCH=Pesquisar
The MessagesKey interface
To be possible to find the desired message, this class must contain the key desired, because with a reference to a constant in this class that sought to be the desired message. Each key in the properties file must have its correspondent in that class. Below, example of class containing the keys listed in the excerpt above the properties:
public interface MessagesKey {
/**
* Command Label
*/
public static final String CMD_CONTINUE = "CMD_CONTINUE";
public static final String CMD_EXIT = "CMD_EXIT";
public static final String CMD_SEARCH = "CMD_SEARCH";
}
The LanguageManager class
This class is responsible for loading the desired language and is also the class to be used by the developer to obtain the desired text based on the key informed. To do this "work", it has two methods:
- public static boolean loadLanguage (String language) throws LanguageNotFoundException
This method is responsible for loading the language. The parameter it receives is the prefix of the language (in the case of the brazilian Portuguese, would be pt-br), which is used to load the corresponding propertie (pt-br.properties, in our example). This load is reading each line of text file and then giving the pair key / value to a static Hashtable (private) of the class.
Note: This method should be called at least once before you try to use the messages internationalised, as it is responsible for loading the Hashtable with the messages, otherwise you will certainly have a NullPointerException! =)
- public static String getMessageText (String messageKey)
To access the Hashtable which owns the messages that should be displayed, access is made by that method that will simply return the string that has provided in association with key parameter. To avoid runtime errors and simply facilitate the treatment, this method has no exception, just returns null if there is no value for the key indicated.
Example of how to use:
Below, an example of how to use the solution mentioned above:
- Loading the language: This step must be done preferably when you load the application for the first time. To make my work easier, I created a parameter in my JAD indicates that the default language, and then put pt-br. Example:
LanguageManager.loadLanguage(this.getAppProperty("DefaultLanguage"));
or using the language "explicitly":
LanguageManager.loadLanguage("pt-br");
- Creating a new Command, where the label it is "internationalized":
Command continueCmd = new Command(LanguageManager.getMessageText(MessagesKey.CMD_CONTINUE), Command.OK, 1);
Well, I hope it has been easy and this may help someone! :)
Here comes the source of example that I use in my application (only the package internationalization): internationalization.zip
Cya
Neto Marin
Getting started with JME - Part II / III
Posted by netomarin on May 15, 2007 at 11:56 AM | Permalink
| Comments (2)
Hi all !!
Let´s talk today about witch IDE use to JME development and after, about MIDlet (and MIDlet life-cycle) and User Interface.
Part II
IDE
Until few days ago I used to develop my applications with Eclipse, mainly by your excellent code editor and great re-factor stuff thats made faster the code re usability. But, at last Sun Tech Days I was very surprised with the examples using NetBeans 5.5 and since that I´m using NetBeans in some personal projects.
What I can say is, if you are getting start with JME development, maybe NetBeans could be the better choice because it´s allow you to create an entire application without enter a single code line, and also allow you to go directly to the source and make the code like you want!! :-)
But, to start using NetBeans 5.5 to mobile development you´ll need to install also the "Mobility Pack". The responsible to give to NetBeans the "power" of Mobile Development! ;-) Both can be found at:
MIDlet
Well, after this all "bla bla bla" let´s go to the "entrance door" of you JME applcation. :-)
It´s through the MIDlet that your JME application is started and over it your application will make important actions and because it will have at least one class that extends from MIDlet. For example, is from the MIDlet that you´ll be able to get the Display instance for your application.
The life-cycle of a MIDlet is something like the picture:

Taking a look to the picture, we can feel that we´ll hat to develop at minimum 3 methods: startApp, pauseApp and destroyApp. By the own name of the methods, you can suppose the method´s purpose: start, pause and the end of the application, respectably.
An important observation to do is about the startApp method. How we can observe at the picture, this method is called ever when the application goes from paused to active status, and because this you should not create new objects or program this method like it´s called just once per execution. You should program it like a "re-start" method, let the objects creations and attribution to the MIDlet constructor.
User Interface
Now, you already know from where start you JME development, so it´s time to make the user interface and handle the commands that the user will use. On this point the better thing to do is visit the article: MIDP GUI Programming: Programming the Phone Interface thats describes very well the UI development to mobile phones. ;-)
Scenes from next chapter !! :D
On the next post I´ll talk a little about the GCF (Generic Connection Framework) thats allow you to connect your mobile application to the Internet or send a SMS message. Also, I´ll write something about how to distribute and deploy your JME application. It´s just wait!!! ;-)
Cya
[]s
Neto Marin
|