Pin Me

BlackBerry 6.0 OS UI Components - Activity Indicator

written by: crisbbdev•edited by: Simon Hill•updated: 11/3/2010

A practical introduction to the Activity Indicator BlackBerry 6.0. OS UI component.

  • slide 1 of 2

    Introduction

    Let’s have a look at another of the new user interface components that BlackBerry 6.0 OS offers us. This time we will talk about Activity indicator and its Java field ActivityImageField.

    When you are coding, there will be tasks you perform that probably last for some time, and it’s recommended that you use an indicator to show the user that something is going on. If the duration is known, a progress indicator would be a better option but in case the duration is unknown, an activity indicator is recommended.

    To show an activity indicator we will use an ActivityImageField. This field uses a bitmap containing every frame of an animation laid out horizontally. Each frame must be exactly the same width.

    We will go into this Java field with an example snippet:

  • slide 2 of 2

    The code

    First of all, we create an ActivityIndicatorView. This is an implementation of AbstractProgressIndicatorView and is used for representing progress where the duration is not known. When you don't know how long the tasks will take, this is the recommended view.

    You can use the typical Windows style hourglass, a spinner or any other image you want. You can customize your own animation. So as we said before, you just need to create a new image created by all the images joined horizontally, each one being a frame of the animation.

    ActivityIndicatorView myview = new ActivityIndicatorView(Field.USE_ALL_WIDTH);

    A model ActivityIndicatorModel and a controller ActivityIndicatorController are available and they represent implementations of AbstractProgressIndicatorModel and AbstractProgressIndicatorController respectively. These represent the progress when the duration is not known. If the controller we set does not consume an input event, then the delegate will process the input.

    ActivityIndicatorModel mymodel = new ActivityIndicatorModel();

    ActivityIndicatorController mycontroller = new ActivityIndicatorController();

    public ActivityIndicatorDemoScreen ()

    {

    setTitle("Activity Indicator Demo");

    Now we associate each controller and model with the view; the model and the view with the controller; and the controller with the model. Please note that there’s no need to associate any view to the model.

    myview.setController(mycontroller);

    myview.setModel(mymodel);

    mycontroller.setModel(mymodel);

    mycontroller.setView(myview);

    mymodel.setController(mycontroller);

    We create a bitmap with the image we want to use as an activity indicator. You could be as creative as you want but remember that the user is waiting for some task and maybe is not as happy as you with the “creation".

    Bitmap mybitmap = Bitmap.getBitmapResource("mycustomanimation.png");

    Last, we create the ActivityImageField through the createActivityImageField of the view object. This creates an ActivityImageField and adds it to this view. The bitmap provided must be a series of frames laid out horizontally, each with equal width. The total width of the bitmap will be the width of an individual frame multiplied by the total number of frames.

    myview.createActivityImageField(bitmap, 5, Field.FIELD_HCENTER);

    add(myview);

    }

    That’s all. As a final tip, please use a descriptive text (for example, "Loading..." or "Reading..."). If an action is very long and you want to communicate what is happening at each stage, provide text that explains what is happening (for example, "Deleting..." or "Installing...").

BlackBerry UI Development

Working with the user interface of BlackBerry 6 OS. Learn about different UI components and how to use them with some easy to follow code samples and snippets.
  1. BlackBerry 6.0 OS UI components - RichList
  2. BlackBerry 6.0 OS UI components - ToolBar
  3. BlackBerry 6.0 OS UI Components - Activity Indicator
  4. BlackBerry 6.0 OS UI Components - Progress Indicator
  5. BlackBerry 6.0 OS UI Components - Table