Pages

Friday, February 3, 2012

Splash Screen

Kebiasaan sebuah aplikasi entah itu aplikasi yang berbasi java  atau lainnya, menggunakan splash screen sebagai tampilan pertama untuk memperlihatkan logo atau pengenalan sebuah aplikasi, dalam tutorial ini saya akan coba jelaskan proses pembuatan splash screen pada aplikasi blackberry.

Contoh detail script splash screen :
package mainapp;
import java.util.Timer;
import java.util.TimerTask;
import utils.AnimatedGIFField;
import utils.GraphicUtil;
import net.rim.device.api.notification.NotificationsConstants;
import net.rim.device.api.notification.NotificationsManager;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.system.EncodedImage;
import net.rim.device.api.system.GIFEncodedImage;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;
public final class SplashScreen extends MainScreen
{
private int _width;
private int _height;
private Bitmap splashImage;
private int offsetY;
private GIFEncodedImage _waitImage;
private AnimatedGIFField _waitField;
private int offsetYWait;
    public SplashScreen()
    {
EncodedImage backgroundImage = EncodedImage.getEncodedImageResource(Const.splasScreenImage);
     _waitImage = Const.getLargeLoadAnimation();
     SplashManager manager = new SplashManager(0);
     _waitField = new AnimatedGIFField(_waitImage);
     manager.add(_waitField);
add(manager);
     _width = Display.getWidth();
     _height = Display.getHeight();
int ratiow = 100 * _width / backgroundImage.getWidth();
int desiredHeight = backgroundImage.getHeight() * ratiow / 100;
     splashImage = GraphicUtil.resizeBitmap(backgroundImage, _width, desiredHeight);
     offsetY = (_height - splashImage.getHeight()) >> 1;
     int splashY = _height - (_height / 4);
        offsetYWait = splashY - (_waitField.getHeight() / 2); 
    
     final Timer timer = new Timer();
     TimerTask tt = new TimerTask(){
 public void run() {
  timer.cancel();
  UiApplication.getUiApplication().invokeLater(new Runnable() { 
     public void run(){
     UiApplication.getUiApplication().pushScreen(new Login());
                    close();
    }
 });
 }
};
timer.schedule(tt, 3000, 3000);
Object theSource = new Object() {
public String toString() {
return Const.nulinesProfileName;
}
};
NotificationsManager.registerSource(Const.notificationId,
theSource, NotificationsConstants.IMPORTANT);
    }
    private final class SplashManager extends Manager 
{
public SplashManager(long style)
{
super(style);
}
protected void paintBackground(Graphics graphics)
{
graphics.setColor(Color.BLACK);
graphics.fillRect(0, 0, _width, _height);
if (splashImage != null){
graphics.drawBitmap(0, offsetY, splashImage.getWidth(), splashImage.getHeight(), splashImage, 0, 0);
}
super.paintBackground(graphics);
}
protected void sublayout(int width, int height) {
layoutChild(_waitField, width, height);
setPositionChild(_waitField, (width - _waitField.getWidth()) >> 1, offsetYWait);
setExtent(Display.getWidth(), Display.getHeight());
}
}
}

No comments:

Post a Comment