2
votes

I am creating a splash screen for my BlackBerry app. Right now the image is not properly placed in all the simulators on which I am testing. What should be the size of my image for the splash screen, so that it fits in all the device sizes?

2
List the devices you are willing to support, then list their screen dimension. And create your image having dimension (minimum width of all the screen width, minimum height of all the screen height). Then you can place it vertically and horizontally centered. Also you can use any image and resize them on runtime using Bitmap.scaleInto(params). - Rupak

2 Answers

4
votes

The main part is, creating Startup Class which extends UiApplication.

This is the StartUp.java

public class StartUp extends UiApplication
{
public static void main(String[]args)
{
    StartUp start=new StartUp();
    start.enterEventDispatcher();
}
public StartUp() 
{
    this.pushScreen(new SplashScreen());
    invokeLater(new Runnable() 
    {
        public void run() 
        {
            try 
            {
                Thread.sleep(2000);// Sleeps it for few seconds
                UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
                pushScreen(new LoadingScreen());
            } 
            catch (Exception e) 
            {
                exceptionHandling(e.getMessage());
            }
        }
    });

}

public static void exceptionHandling(final String exception)
{
    UiApplication.getUiApplication().invokeLater(new Runnable() 
    {       
        public void run() 
        {
            Dialog.alert(exception);
        }
    });
}
}

and the SplashScreen.java

public class SplashScreen extends MainScreen
{
Bitmap bitmap=Bitmap.getBitmapResource("loading-screen.png");//This is my company logo;
BitmapField loadingImage=new BitmapField(bitmap);
public SplashScreen() 
{
    createGUI();
}

private void createGUI() 
{
    try 
    {
        VerticalFieldManager vertical=new VerticalFieldManager()
        {
            protected void paint(Graphics g) 
            {
                g.drawBitmap(0, 0,Display.getWidth(),Display.getHeight(), bitmap, 0, 0);
                super.paint(g);
            }
            protected void sublayout(int maxWidth, int maxHeight) 
            {
                super.sublayout(Display.getWidth(),Display.getHeight());
                setExtent(Display.getWidth(),Display.getHeight());
            }
        };

   //           Nothing to write;

        add(vertical);
    }
    catch (Exception e) 
    {
        StartUp.exceptionHandling(e.getMessage());
    }
}
}

and your FirstScreen.java

public class FirstScreen extends MainScreen
{
VerticalFieldManager vertical;  

public FirstScreen()
{               
    createGUI();
}

private void createGUI() 
{
    setTitle("Loading Screen");
    vertical=new VerticalFieldManager()
    {
        protected void sublayout(int maxWidth, int maxHeight) 
        {
            super.sublayout(Display.getWidth(),Display.getHeight());
            setExtent(Display.getWidth(),Display.getHeight());
        }
    };
    add(vertical);
}

public boolean onMenu(int instance) 
{
    return true;
}
}

Try this you can get.

2
votes

Just take any image like 400X400 and put that image to your project's res folder.

Then in splash screen class file you can resize the image with device's height & width.

    Bitmap splashImage = Bitmap.getBitmapResource("Splash.png");//your splash screen's name with it's extension if it is PNG then .png & if JPG then .jpg
    Bitmap scale = new Bitmap(Display.getWidth(),Display.getHeight());
    splashImage.scaleInto(scale, Bitmap.FILTER_BILINEAR);

    VerticalFieldManager mainManager = new VerticalFieldManager(
        VerticalFieldManager.NO_VERTICAL_SCROLL
                | VerticalFieldManager.USE_ALL_HEIGHT
                | VerticalFieldManager.USE_ALL_WIDTH) {
        public void paint(Graphics g) {
            g.drawBitmap(0, 0, scale.getWidth(), scale.getHeight(), scale, 0, 0);
            super.paint(g);
        }
       };
    add(mainManager);
    //This vertical field can set your converted image as screen background
    // Note :- you must have to extends FullScreen insteadOf MainScreen