 |
Neto Marin's Blog
Neto Marin is one of the founders of JME Brasil and a Team Leader of Integration and Mobile Solutions at Softway. He has been working with mobile development since 2005 and is now involved in growing the JME community in Brazil, while still working with personal mobile projects.
Class Properties for JME
Posted by netomarin on June 12, 2008 at 08:20 AM | Permalink
| Comments (0)
Hi all!!
These days I had to store and travel some settings of mobile applications. So, to get my life easier decided to use the scheme properties. That is, a key = value. And you may think I am getting crazy, right !?!? Because, neither JME has the implementation of the class Properties and there is also the device must implement the JSR 75 in order to save the properties in "format" of file.
But using properties I have some advantages:
- Standardization in the form of assembly of data
- There is no need to make many parses ultimately the form of composition is quite simple!
- Cause little additional data. Compare with XML! =)
And besides the benefits, you not just have to save a file. As the implementation of class Properties in JSE, you can get an OutputStream and so, generate a ByteArrayOutputStream getting an array of bytes and save to an RMS! =)You can also receive a file properties sent by a HTTP and using InputStream, load the properties of an automatic and transparent!
Who is interested, just click here to download the zip file containing the .java file with my implementation! Feel free to use, modify and do whatever you want!!
The class does not implement ALL the methods of the "original" JSE Properties because I did not have time and because I am not interested when created. But I think we can make life easier for some!
Cya!!
[]s
Neto
The Evolution of Mobile Phones
Posted by netomarin on May 26, 2008 at 07:35 PM | Permalink
| Comments (0)
Hi all,
I've received a link sent by Mauricio Leal about the Evolution of Mobile Phones. It´s very intersting and "funny" :D
Take a look: http://www.cellular-news.com/story/31148.php
Cya
[]s
Neto
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
 |
 |
June 2008
| Sun |
Mon |
Tue |
Wed |
Thu |
Fri |
Sat |
| 1 |
2 |
3 |
4 |
5 |
6 |
7 |
| 8 |
9 |
10 |
11 |
12 |
13 |
14 |
| 15 |
16 |
17 |
18 |
19 |
20 |
21 |
| 22 |
23 |
24 |
25 |
26 |
27 |
28 |
| 29 |
30 |
|
|
|
|
|
Search this blog:
Categories
Community: Embedded Java
Community: Mobile & Embedded
Archives
June 2008
May 2008
July 2007
May 2007
Recent Entries
Class Properties for JME
The Evolution of Mobile Phones
LWUIT sounds great!!!

|