Archive for August, 2009

How to use resource files in your blackberry app

Posted on August 30, 2009. Filed under: blackberry, software development | Tags: , , , , |

 

In a previous post I gave the steps on how to add resource files to your application.  In today’s discourse I will describe how to update your application to use those resource files.

They really are quite simple to use, provided that you realize the couple tricks.

Follow these steps to reference the resource file in your class.

Step 1 – include the resource interface

The magic of blackberry means that the resource files are converted into an interface and by implementing that interface on your class you get access to all the strings.

For example, my resource file is called ‘myApp.rrh’ and to include this resource file on my class, I do something like…

public class myApp extends UiApplication extends myAppResource

Trick #1 – The resource files’ interface name is an exact match to the resource file name + the key word ‘Resource’

Step 2 – include a reference to the resource

create a static variable and include it in your class…

private static ResourceBundle _res = ResourceBundle.getBundle(BUNDLE_ID,BUNDLE_NAME);

Trick #2 – BUNDLE_ID and BUNDLE_NAME are auto-generated by blackberry magic

reference your resource through the key name defined in your header file…

LabelField title = new LabelField(_res.getString(appName), LabelField.USE_ALL_WIDTH)

Step 3 – include a reference to a resource array

You can also create a resource array.  In the resource editor, right click your resource and select ‘ConvertToMultipleValues’.  The interface for adding values to this resource array is a bit clunky but hey “a poor craftsman blames his tools”.

You access the values through a string array…

String[] messages = _res.getStringArray(msg);

And that is about it.

Read Full Post | Make a Comment ( 1 so far )

How to add resource file to provide multi lingual support

Posted on August 28, 2009. Filed under: software development |

 

To reach the widest audience for your application you want to provide support for many different languages and cultures.  This process is known as internationalization.  The most common way of achieving this goal is through resource files for the different target languages (or cultures).

The first step to using resources is to add the resource files to your application (of course this is for the Blackberry plugin for Eclipse).

  1. open the package explorer and find your source package
  2. from the context menu (right-click) OR file->new, select Other [you can also use ctrl-N]
  3. open up the blackberry folder and select ‘Blackberry Resource File’
  4. click next
  5. Select the folder where you wish to save the file.  Generally you want to include it with your source code.
  6. type in the name of your resource file ‘applicationName.rrh’ .  IMPORTANT: the file must end with rrh.
  7. you will see that you have two files:  applicationName.rrh and applicationName.rrc.  the RRH file defines the symbols for each of your strings, and the RRC contains the strings.
  8. add in a file for each culture that you wish to include using the format: applicationName_xxx.rrc.  You must replace xxx with the culture abbreviation and you need the underscore
  9. You have now created your files.  Click on the files and start editing to your heart content.

Some of the common cultures:

Language neutral culture abbreviation
English en
French fr
spanish es
Chinese zh
Japanese ja

Culture definitions:

invariant culture This culture category is culture-insensitive. The category is to be used as essentially a default culture when consistency is desired.

One situation where this category might be desirable to use is creating a trial application with a hard-coded expiration date. Using an invariant will allow you to check for a specific date, regardless of the culture’s format, which will greatly simplify the task of comparing these dates.

The invariant culture is not based on the English language per se, but it is associated with it and bears more similarities to it than to any other identifiable culture.

Neutral Culture A neutral culture is associated with a language but has no relationship to countries or regions. For instance, the English spoken in England is different from that spoken in the United States. The same holds true for Spanish spoken in Mexico versus that spoken in Spain.

Although neutral cultures, like the invariant culture, might be tempting to use, they should be avoided as well, if possible, for the same reasons that invariants should be avoided. The language spoken in different countries that are covered by a neutral culture will almost certainly be different in at least a few respects. In reality, the differences will be many.

Specific Culture This is the most precise of the three categories and is represented by a neutral culture, a hyphen, and then a specific culture abbreviation. For instance, in the designations "en-CA" and "en-US", en represent the neutral culture (English), and CA and US represent the specific culture (Canada and the United States, respectively).
Read Full Post | Make a Comment ( 1 so far )

Blackberry simulator and Internet access

Posted on August 10, 2009. Filed under: blackberry, MDS, software development | Tags: , , , |

“communication is 9 parts listening and 1 part speaking”

I ran across another gotcha today when I was trying to get my application to make a web service call.  I could not communicate with the internet.  Either I’m getting better at this or I got lucky, but figuring out the solution only took about an hour this time.  The help files that I ran across were actually helpful this time.

 

The easiest way to test if your blackberry simulator has internet access is to use the ‘Browser’ from inside the simulator.  If you can open a web page then your applications will have network access.

 

The key to this whole thing is MDS (Mobile Data System?) and activating it automatically when you start the blackberry simulator.  Once I followed these steps (as taken from Eclipse Help system) everything worked just fine!

 

Start the BlackBerry MDS Simulator when you start the BlackBerry Smartphone Simulator
  1. On the Run menu, click Debug Configurations or Run Configurations.
  2. Perform one of the following tasks:
    • To work with an existing start configuration, under BlackBerry Simulator, select a start configuration.
    • To work with a new start configuration, right-click BlackBerry Simulator, select New.
  3. Click the Simulator tab.
  4. Click the General tab.
  5. Select the Launch Mobile Data System Connection Service (MDS-CS) with simulator option.
  6. Click OK.

 

The keywords that I used to find this …

  • Test a BlackBerry Application that uses an HTTP connection.
Read Full Post | Make a Comment ( 1 so far )

Blackberry Applications

Posted on August 7, 2009. Filed under: blackberry, development | Tags: , |

“The secret to winning at roulette is to know when you are ahead.”

First off, this post is more touchy-feely than about any concrete details.  It is more a summary of what has worked and what hasn’t worked.  Later on I will go into more code details but I wanted to get some initial thoughts out.

Well, here I am a week or so later and I have made some great strides forward.  I have been working on a crazy little app that takes a phone number, decodes from the number to letters and displays a list of the resulting ‘words’.

For example: 228 –> { abc, abc, tuv } provides {aat, aau, aav, abt, abu, abv, act, acu, acv, bat, bau, bav, bbt, bbu, bbv, cat, cau, cav, cbt, cbu, cbv, cct, ccu, ccv }

It isn’t terribly useful but it provides a framework to explore the API and learn how to put the pieces together.

Some of the things that I have learned:

  1. Managers are important
  2. Creating your own custom controls by overriding the basic ‘field’  controls are essential
  3. If you want to impress people then you must know about paint()ing
  4. That people are quite forgiving and accepting on the blackberry forums

Importance of managers

It is debatable on whether PHBs are important in any role other than to provide a focus of scorn and ridicule from their employees.  Hey wait a minute, I’m not talking about that talk of manager; I’m talking about this type of manager.

I learned that to correctly position, navigate and style an application you have to understand how the managers work.  I started out by using verticalFieldManager and horizontalFieldManagers to get the layout that I wanted.  However, I ran into problems creating the style that I desired.  I often had colours not extending the full width of the screen or I had navigation issues or the controls were all left-aligned.

Now, looking back, I’m sure that I could have used the provided managers and just provided my own delegates during construction.  However I decided to create my own custom manager and that made a huge difference in reaching my goal of learning about the framework and getting the app looking and reacting how I wanted it to. 

I will definitely give details on my manager experience in a future discussion.

Creating custom controls

As you can imagine with an application that takes in a phone number, I had to have quite a few buttons that match up with a phone’s keypad.  I started out using the ButtonField but it quickly became evident that I would have problems with colours and event handling. 

I decided to override the base ‘Field’ class and create my own button.  It was quite simple, once I learned how to override essential base methods.

  • getPreferredWidth – used to set the width of your field
  • getPreferredHeight – used to set the height of your field
  • layout – used to set the ‘extent’ of your control
  • paint – oh, the key stone of functions
  • onFocus – fires when field receives focus
  • onUnFocus – fires when field loses focus
  • keyChar – fires when field receives a key event
  • navigationClick – fires when field receives a wheel or touch event

Paint, Paint, Paint

Oh yes, get to know it, get to love it, get to hate it.  In my brief experience, this is THE function to know about if you want your application to look anything other than a VT100 terminal application.  Obviously, this is where you create your own look and feel and impose your style ideals on your unsuspecting customers.

Oh, when you look into this function, also get to learn about Graphic class and how to create your own contexts

Blackberry forums

While searching for how to accomplish my goals I have read many a post where individuals asked and (much to my surprise) received help.

I must say that people on the forums are very forgiving and accepting and generally helpful.  The main challenge that I have found is typing the correct keywords into Google to find the appropriate thread.

Technorati Tags: ,
Read Full Post | Make a Comment ( None so far )

Liked it here?
Why not try sites on the blogroll...