You are on page 1of 3

Code sample: Creating a screen transition

The following code sample illustrates a slide transition and a fade transition. When the user
opens the application, the first screen appears on the BlackBerry® device and displays a button.
When the user clicks the button, a second screen slides onto the display from the right. The
second screen automatically fades off of the display after two seconds.

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.ui.decor.*;

public class ScreenTransitionSample extends UiApplication implements


FieldChangeListener {
private Screen _secondaryScreen;
private Runnable _popRunnable;

public static void main(String[] args) {


ScreenTransitionSample theApp = new ScreenTransitionSample ();
theApp.enterEventDispatcher();
}

public ScreenTransitionSample () {
_secondaryScreen = new FullScreen();

_secondaryScreen.setBackground( BackgroundFactory.createSolidBackground(Color.
LIGHTBLUE) );

LabelField labelField = new LabelField("The screen closes


automatically in two seconds by using a fade transition");
_secondaryScreen.add(labelField);

TransitionContext transition = new


TransitionContext(TransitionContext.TRANSITION_SLIDE);
transition.setIntAttribute(TransitionContext.ATTR_DURATION, 500);
transition.setIntAttribute(TransitionContext.ATTR_DIRECTION,
TransitionContext.DIRECTION_RIGHT);
transition.setIntAttribute(TransitionContext.ATTR_STYLE,
TransitionContext.STYLE_PUSH);

UiEngineInstance engine = Ui.getUiEngineInstance();


engine.setTransition(null, _secondaryScreen,
UiEngineInstance.TRIGGER_PUSH, transition);

transition = new TransitionContext(TransitionContext.TRANSITION_FADE);


transition.setIntAttribute(TransitionContext.ATTR_DURATION, 500);
transition.setIntAttribute(TransitionContext.ATTR_KIND,
TransitionContext.KIND_OUT);
engine.setTransition(_secondaryScreen, null,
UiEngineInstance.TRIGGER_POP, transition);

MainScreen baseScreen = new MainScreen();


baseScreen.setTitle("Screen Transition Sample");
ButtonField buttonField = new ButtonField("View Transition",
ButtonField.CONSUME_CLICK) ;
buttonField.setChangeListener(this);
baseScreen.add(buttonField);

pushScreen(baseScreen);

_popRunnable = new Runnable() {


public void run() {
popScreen(_secondaryScreen);
}
};
}

public void fieldChanged(Field field, int context)


{
pushScreen(_secondaryScreen);
invokeLater(_popRunnable, 2000, false);
}
}

Transitions

Description

TRANSITION_FADE

This transition reveals or removes a screen by fading it in or fading it out. This screen transition
creates a fading visual effect by changing the opacity of the screen.

TRANSITION_SLIDE

This transition reveals or removes a screen by sliding it on or sliding it off the display on the
device. You can use attributes to specify that both the new screen and the current screen slide, to
create an effect where both screens appear to move, or that the new screen slides over the current
screen.

TRANSITION_WIPE

This transition reveals or removes a screen by simulating wiping on or wiping off the display on
the device.

TRANSITION_ZOOM

This transition reveals or removes a screen by zooming it in or zooming it out of the display on
the device.

TRANSITION_NONE
No transition occurs.

You might also like