2

I need to design the UI for a blackberry app. This app should support multiple blackberry resolutions.

One way would be to check the screen_width and screen_height every time, and accordingly fetch images from the res folder. Is there any other more efficient, or a better method to do this? I will also need to do the same for font sizes, of text, according to screen size.

Please help me know the standard method to support multiple BB resolutions

Mayur More
  • 951
  • 2
  • 15
  • 37
  • If we are talking about legacy BB Java development, then I'm afraid no. Else if you are developing a WebWorks app, then regular web strategies apply. – Mister Smith Sep 10 '13 at 12:15
  • Yes i am talking about legacy BB Java development. So how were these apps managed previously? – Mayur More Sep 10 '13 at 12:23
  • 1
    Well, you had to solve this problem by yourself, no built-in mechanism was provided like in Android. This has been asked here a few times, here is a similar question: http://stackoverflow.com/q/3496175/813951 – Mister Smith Sep 10 '13 at 12:37
  • 1
    Also refer [here](http://stackoverflow.com/q/8165145), [here](http://stackoverflow.com/q/3024263), [here](http://stackoverflow.com/q/3451738) and [here](http://stackoverflow.com/q/3024263). – Mister Smith Sep 10 '13 at 12:44

1 Answers1

3

You can try, what I have tried in my applications without any issues so far.

Step 1:

Create a separate package like com.your_app_name.uiconfig which will contain an abstract class say ModelConfig and different classes for different resolutions like class BB83xxConfig for resolution 320x240 (width x height), class BB95xxConfig for resolution 360 x 480 (width x height).

Step 2:

ModelConfig class will provide the concrete implementation of the methods that will be common to all irrespective of the screen resolutions and the declaration of abstract methods whose concrete implementation will be provided in the respective classes based on the screen resolution.

Step 3: Make each and every class, that is implemented for particular resolution extend ModelConfig and provide concrete implementation of methods as per requirement.

Step 4: Use singleton pattern to get the instance of ModelConfig, so that it is intantiated only once and that instance is used throughout.

ModelConfig.java (Just a sample)

public abstract class ModelConfig {

private static ModelConfig modelConfig = null;

public static ModelConfig getConfig() {

    if (modelConfig == null) {

        if (DeviceInfo.getDeviceName().startsWith("83")) {
            modelConfig = new BB83xxConfig();
        } else if (DeviceInfo.getDeviceName().startsWith("85")) {
            // 85xx also has 360 x 240 same as 83xx device
            modelConfig = new BB83xxConfig();
        } else if (DeviceInfo.getDeviceName().startsWith("89")) {
            modelConfig = new BB89xxConfig();
        } else if (DeviceInfo.getDeviceName().startsWith("90")) {
            modelConfig = new BB90xxConfig();
        } else if (DeviceInfo.getDeviceName().startsWith("95")) {
            modelConfig = new BB95xxConfig();
        } else if (DeviceInfo.getDeviceName().startsWith("96")) {
            modelConfig = new BB96xxConfig();
        } else if (DeviceInfo.getDeviceName().startsWith("97")) {
            modelConfig = new BB97xxConfig();
        } else if (DeviceInfo.getDeviceName().startsWith("99")) {
            modelConfig = new BB99xxConfig();
        } else if (DeviceInfo.getDeviceName().startsWith("98")) {
            // 9800 also has 360 x 480 same as 95xx device
            modelConfig = new BB95xxConfig();
        }else {
            modelConfig = new DefaultConfig();
        }
    }

    return modelConfig;
}

// Font height for the default font used for the application.
public abstract int getApplicationFontHeight();

// Font height for the header label font.
public abstract int getHeaderLabelFontHeight();

// Height for the coloured background of Header.
public abstract int getHeaderBarHeight();

// Height for the individual row in the list.
public abstract int getCustomListRowHeight();   

public abstract int getStandardButtonWidth();

public abstract int getStandardLabelWidth();    

public abstract int getTitleFontHeight();   

// get Background colour for Header.
public int getHeaderBackgroundColor() {
    return 0x26406D;
}   

// get Bitmap showing Right Arrow.
public Bitmap getBitmapRightArrow() {
    return Bitmap.getBitmapResource("right_arrow.png");
}

// get Bitmap rounded black border for editfield.
public Bitmap getBitmapRoundedBorderEdit(){
    return Bitmap.getBitmapResource("rounded_border_black.png");
}

// get Bitmap rounded gray border and white background.
public Bitmap getBtmpRoundedBorderBgrnd(){
    return Bitmap.getBitmapResource("rounded_border_grey.png");
}

// get Bitmap rounded gray border and white background.
public Bitmap getBtmpTransparentBgrnd(){
    return Bitmap.getBitmapResource("img_transparent_background.png");
}

// get Bitmap showing down Arrow.
public Bitmap getBitmapDownArrow(){

    return Bitmap.getBitmapResource("down_arrow.png");
}   

}

BB95xxConfig.java (just a sample)

/*
 * Common resolution 360*480 pixels (width x height)
 */
public class BB95xxConfig extends ModelConfig {
    // Font height for the default font used for the application.
    // returns Desired height in pixels.
    public int getApplicationFontHeight() {
        return 18;
    }

    // Font height for the header label font.
    // returns Desired height in pixels.
    public int getHeaderLabelFontHeight() {
        return 20;
    }

    // returns Desired height in pixels for the header background.
    public int getHeaderBarHeight() {
        return Display.getHeight() / 10;
    }

    public int getCustomListRowHeight() {
        return 50;
    }   

    public int getStandardButtonWidth() {
        return 108;
    }

    public int getStandardLabelWidth() {
        return 150;
    }

    public int getTitleFontHeight() {
            return 11;
    }
}
Ritesh Gune
  • 16,629
  • 6
  • 44
  • 72