Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 10
Registered: ‎04-30-2010
My Device: All
My Carrier: None
Accepted Solution

Push screen automatically

Hi,

 

I have two simple screens. What I'd like to do is to push the second screen automatically after certain amount of time. Any thoughts on how to accomplish this?

 

Thanks,

Diego

Developer
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: Push screen automatically

You can schedule a TimerTask with the Timer class.

Contributor
Posts: 10
Registered: ‎04-30-2010
My Device: All
My Carrier: None

Re: Push screen automatically

Any sample code? :smileyhappy:

Developer
Posts: 37
Registered: ‎01-12-2010
My Device: Blackberry 8320
My Carrier: TMO

Re: Push screen automatically

This takes a different approach from mreed's recommendation, but here you go.

 

 

/**
 * Copyright (c) 2010 72hills All rights reserved.
 */
package farklebb;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.system.PersistentObject;
import net.rim.device.api.system.PersistentStore;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.FontFamily;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.Screen;
import net.rim.device.api.ui.XYRect;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.DialogClosedListener;
import net.rim.device.api.ui.container.VerticalFieldManager;
public class Splash extends Screen implements DialogClosedListener{
Bitmap b;
XYRect dest;
int bitmapLeft, bitmapTop;
final static long delay = 2000;
Dialog eula;
public Splash(Manager delegate){
super(delegate, Screen.NO_VERTICAL_SCROLL);
try {
b = Bitmap.getBitmapResource("youFarkle480.jpg");
dest = new XYRect(0,0,Display.getWidth(),Display.getHeight());
bitmapLeft = (b.getWidth() - dest.width) / 2;
bitmapTop = (b.getHeight() - dest.height) / 2;
} catch (NullPointerException e) {}
String eulaMsg = "Do you accept the end user license agreement " +
eula = new Dialog(Dialog.D_YES_NO,eulaMsg,Dialog.NO,null,Dialog.FIELD_LEFT);
}
protected void sublayout(int width, int height) {
this.setExtent(width, height);
this.setPosition(0,0);
this.getApplication().invokeLater(new Runnable(){
public void run() {
if(EULAPref.getPreference()){
getUiEngine().pushScreen(new StartScreen());
getUiEngine().popScreen(Splash.this);
}else{
Font font = null;
try {
font = FontFamily.forName(
"BBCasual").getFont(FontFamily.SCALABLE_FONT, 
12);
} catch (ClassNotFoundException e) {}
eula.setFont(font);
eula.setDialogClosedListener(Splash.this);
getUiEngine().pushScreen(eula);
}
}},delay,false);
}
protected void paint(Graphics g) {
g.setColor(0xffffff);
g.fillRect(0, 0, getWidth(), getHeight());
g.drawBitmap(dest, b, bitmapLeft, bitmapTop);
}
public void dialogClosed(Dialog dialog, int choice) {
if(dialog == eula){
if(choice == Dialog.YES){
EULAPref.setPreference(true);
getUiEngine().pushScreen(new Splash(new VerticalFieldManager()));
getUiEngine().popScreen(this);
}else{
getUiEngine().popScreen(this);
System.exit(0);
}
}
}
static class EULAPref {
static PersistentObject persistEULAPref;
//  convert string to long (com.youfarkle.pref.eula) = 0x8c1cb4adce8b7cf7L
static {
persistEULAPref = PersistentStore.getPersistentObject( 0x8c1cb4adce8b7cf7L );
}
static boolean getPreference(){
boolean eula;
Object eulaBoolean;
eulaBoolean = persistEULAPref.getContents();
if( eulaBoolean == null ) {
eula = setPreference(false);//declined
}else{
eula = ((Boolean)eulaBoolean).booleanValue();
eulaBoolean = null;
}
return eula;
}
static boolean setPreference(boolean choice){
boolean eula;
Boolean eulaBoolean = new Boolean(choice);
if (persistEULAPref != null) {
synchronized (persistEULAPref) {
persistEULAPref.setContents(eulaBoolean);
persistEULAPref.commit();
}
}
eula = eulaBoolean.booleanValue();
eulaBoolean = null;
return eula;
}
}
}

 

public class Splash extends Screen {

 

final static long delay = 2000;

 

  public Splash(Manager delegate){

 

super(delegate, Screen.NO_VERTICAL_SCROLL);

 

}

 

protected void sublayout(int width, int height) {

 

this.setExtent(width, height);

  this.setPosition(0,0);

 

this.getApplication().invokeLater(new Runnable(){

 

public void run() {

 

getUiEngine().pushScreen(new MyOtherScreen());

  getUiEngine().popScreen(Splash.this);

 

},

delay,

false);

  }

 

}

 

Hope that helps.

 

tooter