Simple Sample Code for the ActivityIndicatorView

As part of BlackBerry operating system 6.0 RIM has added the net.rim.device.api.ui.component.progressindicator module to help with things such as displaying progress and activity indicators. Progress indicators are used to show how far along a task is when the length of the task is known (ie. 5 of 7 done; or 35% complete), while activity indicators are used when the length of time is unknown (typically displayed as a pulse or a spinning object). An activity indicator as shown below is used in version 2.0 of the Hockey Scores application while the app is waiting for the scores to initially download.

The main complication in implementing this feature was that the sample code for the feature consists of 4 java files and over 800 lines of code. Fortunately actually using this feature can be much simpler, and in fact can be simplified down to only 8 lines of code.

Screen s = new Screen();
ActivityIndicatorView view = new ActivityIndicatorView(Field.FIELD_HCENTER);
Bitmap spinImage = Bitmap.getBitmapResource("spinner.png");
view.createActivityImageField(spinImage,6,0);
LabelField label = new LabelField("Loading Hockey...");
s.add(label);
s.add(view);
pushScreen(s);

Granted this doesn’t make use of all the features that the ActivityIndicatorView can make use of. However, as soon as the data is loaded there is no need to keep the ActivityIndicatorView around anyways as the screen replaces it with real data that we were waiting for anyhow.