English 中文(简体)
BlackBerry - How to show the system status bar on top of the application screen
原标题:

My question is rather simple, but I couldn t find an answer, could be because I m using the wrong terms, but let me try: is there a way for a BlackBerry application (extending the regular Screen component) to keep the status bar visible (by status bar, to clarify, I mean the area where you see the battery strength, network name, signal strength, etc.)?

thank you

最佳回答

There is as yet (in my experience up to OS version 4.6) no API exposed to do this, strange as that is. You may of course program your own status bar, as many applications do, if you feel it necessary. But you have to gather the information and display the status information with logic coded into your own program.

问题回答

Here s some sample code. First, for a nice title bar, look here: http://www.naviina.eu/wp/blackberry/iphone-style-field-for-blackberry/

To display a battery strength image:

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.DeviceInfo;
...
public static Bitmap getBatteryImage(){
        int batteryPercent = DeviceInfo.getBatteryLevel();
        int val = 1;
        if(batteryPercent > 80){
            val = 5;
        }else if(batteryPercent > 60 ){
            val = 4;
        }else if(batteryPercent > 40){
            val = 3;
        }else if(batteryPercent > 20){
            val = 2;
        }else {
            val = 1;
        }
        Bitmap batteryImage = Bitmap.getBitmapResource("mybattery"+val+".png");
        return batteryImage;
    }
...

You need to create images mybattery1.png to mybattery5.png, and place them in your src folder. A good size to start with is 28x11 pixels (GIMP is a good free image editor). If you used the title bar code from Naviina.eu, then insert the following code in the paint method, like so:

protected void paint(Graphics graphics) {
...
        int w = this.getPreferredWidth();
        int h = this.getPreferredHeight();
        Bitmap batteryImage = getBatteryImage();
        int batteryStartY = (h - batteryImage.getHeight()) / 2;    
        graphics.drawBitmap(w - batteryImage.getWidth(), batteryStartY, w, h,
                batteryImage, 0, 0);
...
}

Some things to note: the image(s) do not refresh unless you invalidate the screen or push/pop to another screen. Also, you may want smaller images for a Pearl vs. a Curve or Storm.

You could use the StandardTitleBar, it might be a bit more straightforward.

http://www.blackberry.com/developers/docs/6.0.0api/net/rim/device/api/ui/component/StandardTitleBar.html

There are actually three places you can insert your status information in a MainScreen subclass:

  • Banner area - is located at the top of the screen
  • Title area - is below the Banner area and normally has a different background
  • Status area - at the bottom of the screen

You use setBanner(Field), setTitle(Field) and setStatus(Field) to display information as shown as follows:

    HorizontalFieldManager hfm = new HorizontalFieldManager();
    EncodedImage logo = EncodedImage.getEncodedImageResource("img/Logo.png");       
    Bitmap bm = logo.getBitmap();

    hfm.add(new BitmapField(bm));
    hfm.add(new LabelField("Banner area"));     
    setBanner(hfm);

    setTitle(new LabelField("Title area", LabelField.FIELD_HCENTER));
    setStatus(new LabelField("Status area", LabelField.FIELD_HCENTER));

The advantage is that each method accepts a Field as an argument and the programmer can compose a complex Field with managers.





相关问题
How does AlertListener work on Blackberry API 5.0?

Does the AlertListener interface works globally on all alerts on the blackberry device, or does it only work with alerts generated by your application? In other words, can I use this interface to ...

How to buffer audio in Blackberry?

I need to learn how to buffer audio stream from a remote server in Blackberry. There is a sample buffered playback app with Blackberry api but can you tell what url may I use to test the application?

Blackberry push notification implementation

How does one implement a push notification for a blackberry app? I heard that in order to do so I need to purchase a Blackberry Enterprise Server which costs me 1400 per year. Is this true? Where is ...

热门标签