Quote:
Originally Posted by MobileDeveloperUK
Hi
I am having trouble using the SplashScreen example proved in the RIM website
I get it compiled without error but when I load it in the Simulator , i the app never shows up
Has anyone else experienced it ?
What are the project settings to be used while using the program ?
|
I have already worked with a Splash screen and its working nicely. Have implemented KeyListener for Enter and Menu keys and on click on the screen also takes it ahead i.e. kills the duration period and moves to next screen.
Code:
/**
*
*/
package gd;
import java.util.Timer;
import java.util.TimerTask;
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 backend.UserBean;
import backend.Data;
import backend.XmlReply;
/**
* @author Trupti
*/
public class SplashScreen extends FullScreen {
private Timer timer = new Timer();
private Bitmap bitmap;
private BitmapField bf;
private String next = "";
private UserBean user = null;
public SplashScreen(String nextScreen, UserBean ub) {
super(Field.FIELD_HCENTER);
SplashScreen");
next = nextScreen;
this.user = ub;
try {
bitmap = Bitmap.getBitmapResource("flash.png");
} catch(Exception e) {
System.out.println("********* Exception : " + e.getMessage());
e.printStackTrace();
}
bf = new BitmapField(bitmap, DrawStyle.HCENTER | DrawStyle.VCENTER | BitmapField.FOCUSABLE);
this.add(bf);
SplashScreenListener listener = new SplashScreenListener(this);
this.addKeyListener(listener);
this.setChangeListener(listener);
timer.schedule(new CountDown(), 5000);
}
public void dismiss() {
timer.cancel();
bitmap = null;
timer = null;
UiApplication.getUiApplication().popScreen(this);
if (next.equalsIgnoreCase("l")) {
UiApplication.getUiApplication().pushScreen(new LoginScreen());
}else if(next.equalsIgnoreCase("a")) {
UiApplication.getUiApplication().pushScreen(new LoggedUserScreen(user));
}
}
// class CountDown
private class CountDown extends TimerTask {
public void run() {
DismissThread thread = new DismissThread();
UiApplication.getUiApplication().invokeLater(thread);
}
}
// class DismissThread
private class DismissThread implements Runnable {
public void run() {
dismiss();
}
}
// class SplashScreenListener
public static class SplashScreenListener implements KeyListener, FieldChangeListener {
private SplashScreen screen;
public void fieldChanged(Field f, int context) {
screen.dismiss();
}
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 SplashScreenListener(SplashScreen splash) {
screen = splash;
}
}
protected boolean navigationClick(int status, int time) {
fieldChangeNotify(0);
return true;
}
protected boolean navigationUnclick(int status, int time) {
return false;
}
protected boolean navigationMovement(int dx, int dy, int status, int time) {
return false;
}
}
You can change certain things like in const, you can have a MainScreen object
private MainScreen next;
public SplashScreen(MainScreen nextScreen) {
.....
this.next = nextScreen;
}
public void dismiss() {
timer.cancel();
bitmap = null;
timer = null;
UiApplication.getUiApplication().popScreen(this);
UiApplication.getUiApplication().pushScreen(next);
}
Hope this helps.