/*
Demonstrate a splash screen that automatically resizes the splash bitmap to the
size of the given device display.....
Based on and extends code from:
http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800256/How_To_-_Create_a_splash_screen.html?nodeid=800334&vernum=0
Additional code from:
Funambol is a mobile platform developed by Funambol, Inc.
Copyright (C) 2003 - 2007 Funambol, Inc.
sync4j-cvs-2008-07-21\funambol\clients\j2me\mail\UI\basic\src\com\funambol\mailclient\ ui \ utils\UiUtils.java
they were using javax.microedition.lcdui.Image
changed to use net.rim.device.api.system.Bitmap
Included here as part of the license at the head of UiUtils.java
-----------------------------------------------------------------------------------
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
-----------------------------------------------------------------------------------
Under the above term here is my modifications for net.rim platform
mkSplashScreen()
Daniel Chapiesky
dchapiesky@cmtechnologyservices.net
Example use:
DemoApp()
{
DemoMainScreen myMainScreen = new DemoMainScreen();
DemoSplashScreen mySplashScreen = new mkSplashScreen("img/mySplashScreen.png", this, myMainScreen);
//
// the constructor of mkSplashScreen automatically pushes its self/ pops its self / and then pushes
// the myMainScreen...
//
}
*/
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import java.util.*;
public class mkSplashScreen extends MainScreen
{
private MainScreen next;
private UiApplication application;
private Timer timer = new Timer();
private static Bitmap original_bitmap;
private static Bitmap _bitmap;
public mkSplashScreen(String splashImageName, UiApplication ui, MainScreen next)
{
super(Field.USE_ALL_HEIGHT | Field.FIELD_LEFT);
original_bitmap = Bitmap.getBitmapResource(splashImageName);
Display myDisplay = new Display();
_bitmap = bestFit(original_bitmap, myDisplay.getWidth(), myDisplay.getHeight());
this.application = ui;
this.next = next;
this.add(new BitmapField(_bitmap));
mkSplashScreenListener listener = new mkSplashScreenListener(this);
this.addKeyListener(listener);
timer.schedule(new CountDown(), 5000);
application.pushScreen(this);
}
public void dismiss()
{
timer.cancel();
application.popScreen(this);
application.pushScreen(next);
}
private class CountDown extends TimerTask
{
public void run()
{
DismissThread dThread = new DismissThread();
application.invokeLater(dThread);
}
}
private class DismissThread implements Runnable
{
public void run()
{
dismiss();
}
}
protected boolean navigationClick(int status, int time)
{
dismiss();
return true;
}
protected boolean navigationUnclick(int status, int time)
{
return false;
}
protected boolean navigationMovement(int dx, int dy, int status, int time)
{
return false;
}
public static class mkSplashScreenListener implements
KeyListener
{
private mkSplashScreen screen;
public boolean keyChar(char key, int status, int time)
{
//intercept the ESC and MENU key - exit the splash screen
boolean retval = false;
switch (key)
{
case Characters.CONTROL_MENU:
case Characters.ESCAPE:
screen.dismiss();
retval = true;
break;
}
return retval;
}
public boolean keyDown(int keycode, int time)
{
return false;
}
public boolean keyRepeat(int keycode, int time)
{
return false;
}
public boolean keyStatus(int keycode, int time)
{
return false;
}
public boolean keyUp(int keycode, int time)
{
return false;
}
public mkSplashScreenListener(mkSplashScreen splash)
{
screen = splash;
}
}
// based on code from
//
// * Funambol is a mobile platform developed by Funambol, Inc.
// * Copyright (C) 2003 - 2007 Funambol, Inc.
// sync4j-cvs-2008-07-21\funambol\clients\j2me\mail\UI\basic\src\com\funambol\mailclient\ ui \ utils\UiUtils.java
//
// they were using javax.microedition.lcdui.Image
//
// changed to use net.rim.device.api.system.Bitmap
//
// Included here as part of the license at the head of UiUtils.java
//
// -----------------------------------------------------------------------------------
// * This program is free software; you can redistribute it and/or modify it under
// * the terms of the GNU Affero General Public License version 3 as published by
// * the Free Software Foundation with the addition of the following permission
// * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
// * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE
// * WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
// -----------------------------------------------------------------------------------
//
// Under the above term here is my modifications for net.rim platform
//
// Daniel Chapiesky
// dchapiesky@cmtechnologyservices.net
//
private static int[] rescaleArray(int[] ini, int x, int y, int x2, int y2)
{
int out[] = new int[x2*y2];
for (int yy = 0; yy < y2; yy++)
{
int dy = yy * y / y2;
for (int xx = 0; xx < x2; xx++)
{
int dx = xx * x / x2;
out[(x2 * yy) + xx] = ini[(x * dy) + dx];
}
}
return out;
}
public static Bitmap resizeBitmap(Bitmap image, int width, int height)
{
// Note from DCC:
// an int being 4 bytes is large enough for Alpha/Red/Green/Blue in an 8-bit plane...
// my brain was fried for a little while here because I am used to larger plane sizes for each
// of the color channels....
//
//Need an array (for RGB, with the size of original image)
//
int rgb[] = new int[image.getWidth()*image.getHeight()];
//Get the RGB array of image into "rgb"
//
image.getARGB(rgb, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight());
//Call to our function and obtain RGB2
//
int rgb2[] = rescaleArray(rgb, image.getWidth(), image.getHeight(), width, height);
//Create an image with that RGB array
//
Bitmap temp2 = new Bitmap(width, height);
temp2.setARGB(rgb2, 0, width, 0, 0, width, height);
return temp2;
}
public static Bitmap bestFit(Bitmap image, int maxWidth, int maxHeight)
{
// getting image properties
int w = image.getWidth();
int h = image.getHeight();
// get the ratio
int ratiow = 100 * maxWidth / w;
int ratioh = 100 * maxHeight / h;
// this is to find the best ratio to
// resize the image without deformations
int ratio = Math.min(ratiow, ratioh);
// computing final desired dimensions
int desiredWidth = w * ratio / 100;
int desiredHeight = h * ratio / 100;
//resizing
return resizeBitmap(image, desiredWidth, desiredHeight);
}
}