Skip to content →

[Blackberry] Transition Screen

Artikel kali ini masih tentang Blackberry, iseng-iseng nemu script untuk transisi screen. Haha.. Tau kan maksudnya transisi screen? Jadi kalo semisal kita pindah halaman nggak monoton langsung ganti halaman, tapi ada semacam animasinya, ada 4 jenis transisi yang disediakan antara lain FADE, SLIDE, WIPE, dan ZOOM. Berikut penjelasan singkatnya :

  • FADE, perpindahan screen dengan memudarkan halaman pertama dari tingkat opacity 0% – 100% dan halaman kedua dari tingkat 100% – 0%
  • SLIDE, perpindahan screen dengan menggeser halaman dari atas ke bawah atau sebaliknya.
  • WIPE, perpindahan screen dengan menggeser halaman dari kanan ke kiri atau sebaliknya.
  • ZOOM, perpindahan screen dengan menampilkan halaman kedua dengan cara zooming.

Source code dibawah ini sebenarnya dapat di download di web resminya developer Blackberry, disini. Ya saya sih cuma ngasih bentuk simpel nya aja, sama aja sih sebenarnya.

TransitionUtilities.java

public class TransitionUtilities {
	public static final int TRANSITION_SLIDE = 0;
	public static final int TRANSITION_FADE = 1;
	public static final int TRANSITION_WIPE = 2;
	public static final int TRANSITION_ZOOM = 3;
	public static final int DELAY = 1000;

	public static void transition(int type, Screen nextScreen) {
		Screen screen = nextScreen;
		TransitionContext transitionContextIn;
		TransitionContext transitionContextOut;
		UiEngineInstance engine = Ui.getUiEngineInstance();
		switch (type) {
		case TRANSITION_SLIDE:
			transitionContextIn = new TransitionContext(
					TransitionContext.TRANSITION_SLIDE);
			transitionContextIn.setIntAttribute(
					TransitionContext.ATTR_DURATION, DELAY);
			transitionContextIn.setIntAttribute(
					TransitionContext.ATTR_DIRECTION,
					TransitionContext.DIRECTION_UP);

			transitionContextOut = new TransitionContext(
					TransitionContext.TRANSITION_SLIDE);
			transitionContextOut.setIntAttribute(
					TransitionContext.ATTR_DURATION, DELAY);
			transitionContextOut.setIntAttribute(
					TransitionContext.ATTR_DIRECTION,
					TransitionContext.DIRECTION_DOWN);
			transitionContextOut.setIntAttribute(TransitionContext.ATTR_KIND,
					TransitionContext.KIND_OUT);

			engine.setTransition(null, screen, UiEngineInstance.TRIGGER_PUSH,
					transitionContextIn);
			engine.setTransition(screen, null, UiEngineInstance.TRIGGER_POP,
					transitionContextOut);
			break;
		case TRANSITION_FADE:
			transitionContextIn = new TransitionContext(
					TransitionContext.TRANSITION_FADE);
			transitionContextIn.setIntAttribute(
					TransitionContext.ATTR_DURATION, DELAY);

			transitionContextOut = new TransitionContext(
					TransitionContext.TRANSITION_FADE);
			transitionContextOut.setIntAttribute(
					TransitionContext.ATTR_DURATION, DELAY);
			transitionContextOut.setIntAttribute(TransitionContext.ATTR_KIND,
					TransitionContext.KIND_OUT);

			engine.setTransition(null, screen, UiEngineInstance.TRIGGER_PUSH,
					transitionContextIn);
			engine.setTransition(screen, null, UiEngineInstance.TRIGGER_POP,
					transitionContextOut);
			break;
		case TRANSITION_WIPE:
			transitionContextIn = new TransitionContext(
					TransitionContext.TRANSITION_WIPE);
			transitionContextIn.setIntAttribute(
					TransitionContext.ATTR_DURATION, DELAY);
			transitionContextIn.setIntAttribute(
					TransitionContext.ATTR_DIRECTION,
					TransitionContext.DIRECTION_LEFT);

			transitionContextOut = new TransitionContext(
					TransitionContext.TRANSITION_WIPE);
			transitionContextOut.setIntAttribute(
					TransitionContext.ATTR_DURATION, DELAY);
			transitionContextOut.setIntAttribute(
					TransitionContext.ATTR_DIRECTION,
					TransitionContext.DIRECTION_RIGHT);
			transitionContextOut.setIntAttribute(TransitionContext.ATTR_KIND,
					TransitionContext.KIND_OUT);

			engine.setTransition(null, screen, UiEngineInstance.TRIGGER_PUSH,
					transitionContextIn);
			engine.setTransition(screen, null, UiEngineInstance.TRIGGER_POP,
					transitionContextOut);
			break;
		case TRANSITION_ZOOM:
			transitionContextIn = new TransitionContext(
					TransitionContext.TRANSITION_ZOOM);
			transitionContextIn.setIntAttribute(
					TransitionContext.ATTR_DURATION, DELAY);

			transitionContextOut = new TransitionContext(
					TransitionContext.TRANSITION_ZOOM);
			transitionContextOut.setIntAttribute(
					TransitionContext.ATTR_DURATION, 1000);
			transitionContextOut.setIntAttribute(TransitionContext.ATTR_KIND,
					TransitionContext.KIND_OUT);

			engine.setTransition(null, screen, UiEngineInstance.TRIGGER_PUSH,
					transitionContextIn);
			engine.setTransition(screen, null, UiEngineInstance.TRIGGER_POP,
					transitionContextOut);
			break;
		}

		synchronized (UiApplication.getEventLock()) {
			UiApplication.getUiApplication().pushScreen(screen);
		}
	}
}

Nah kelas diatas sebagai “mesin” transisi nya. Untuk menggunakannya tinggal panggil method diatas, berikut contohnya :

public final class MyScreen extends MainScreen {
	public MyScreen() {
		setTitle("MyTitle");

		ButtonField tombol = new ButtonField("Next");
		tombol.setChangeListener(new FieldChangeListener() {

			public void fieldChanged(Field field, int context) {
				TransitionUtilities.transition(1, new Halaman2());
			}
		});
	}
}

Pada kode yang saya bold, terdapat 2 parameter yaitu parameter jenis transisi dan screen tujuan.

  • Jenis 0 : Slide
  • Jenis 1 : Fade
  • Jenis 2 : Wipe
  • Jenis 3 : Zoom

Pengaturan ini terdapat pada Kelas TransitionUtilities.java diatas. Selamat mencoba, adios~

 

Published in Blackberry Java

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *