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
Trusted Contributor
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom

Screen Transitions (from one click to manually scrolling through the Screens)

Hey Guys

 

I am busy modifying a Test  Application to try and meet my Applications requirements... I have searched on the forum but cant seem to find a sollution..

 

This is Class "ScreenTransitions".

 

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.component.*;

public final class ScreenTransitions extends UiApplication
{
private boolean _threadRunning;
private boolean _pauseThread;
private TransitionThread _tt;

public static void main(String[] args)
{
ScreenTransitions app = new ScreenTransitions();
app.enterEventDispatcher();
}



public ScreenTransitions()
{
pushScreen(new ScreenTransitionsScreen());
}


public void startOrStopThread()
{
if(_threadRunning == false)
{
_tt = new TransitionThread();
_tt.start();

_threadRunning = true;

}
else
{
if(_pauseThread)
{
_pauseThread = false;
}
else
{
_pauseThread = true;
}
}
}

final class ScreenTransitionsScreen extends MainScreen
{
ScreenTransitionsScreen()
{
setTitle("Screen Transitions");

add(new LabelField("Click trackpad or screen to start and stop animation", Field.NON_FOCUSABLE));
}

protected boolean invokeAction(int action)
{
if(action == ACTION_INVOKE)
{
startOrStopThread();
return true;
}

return super.invokeAction(action);
}
public boolean touchEvent(TouchEvent event)
{
if(event.getEvent() == TouchEvent.UNCLICK)
{
invokeAction(ACTION_INVOKE);
return true;
}

return super.touchEvent(event);

}
}


final class TransitionThread extends Thread
{
public static final int WIPE = 0;
public static final int WIPE1 = 1;
public static final int WIPE2 = 2;
public static final int WIPE3 = 3;
public static final int WIPE4 = 4;
public static final int WIPE5 = 5;

boolean _pushed;

TransitionThread()
{
}

public void run()
{
int type = 0;

while(true)
{
while(_pauseThread)
{
try
{
sleep(500);
}
catch(InterruptedException e)
{
}
}

if(!_pushed)
{

push(type);
snooze();
}
if(!_pauseThread)
{
pop();
}


if(type == 3)
{
type = 0;
}
else
{
type ++;
}
}
}


void pop()
{
synchronized(UiApplication.getEventLock())
{
Screen activeScreen = getActiveScreen();
popScreen(activeScreen);
_pushed = false;
}
}
void push(int type)
{
TransitionScreen screen = null;
TransitionContext transitionContextIn;
TransitionContext transitionContextOut;
UiEngineInstance engine = Ui.getUiEngineInstance();
switch(type)
{

case WIPE1:
screen = new TransitionScreen("Wipe1", Color.YELLOWGREEN);

transitionContextIn = new TransitionContext(TransitionContext.TRANSITION_WIPE);
transitionContextIn.setIntAttribute(TransitionContext.ATTR_DURATION, 1000);
transitionContextIn.setIntAttribute(TransitionContext.ATTR_DIRECTION, TransitionContext.DIRECTION_LEFT);

transitionContextOut = new TransitionContext(TransitionContext.TRANSITION_WIPE);
transitionContextOut.setIntAttribute(TransitionContext.ATTR_DURATION, 1000);
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 WIPE2:
screen = new TransitionScreen("Wipe2", Color.PURPLE);

transitionContextIn = new TransitionContext(TransitionContext.TRANSITION_WIPE);
transitionContextIn.setIntAttribute(TransitionContext.ATTR_DURATION, 1000);
transitionContextIn.setIntAttribute(TransitionContext.ATTR_DIRECTION, TransitionContext.DIRECTION_LEFT);

transitionContextOut = new TransitionContext(TransitionContext.TRANSITION_WIPE);
transitionContextOut.setIntAttribute(TransitionContext.ATTR_DURATION, 1000);
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 WIPE3:
screen = new TransitionScreen("Wipe3", Color.FUCHSIA);

transitionContextIn = new TransitionContext(TransitionContext.TRANSITION_WIPE);
transitionContextIn.setIntAttribute(TransitionContext.ATTR_DURATION, 1000);
transitionContextIn.setIntAttribute(TransitionContext.ATTR_DIRECTION, TransitionContext.DIRECTION_LEFT);

transitionContextOut = new TransitionContext(TransitionContext.TRANSITION_WIPE);
transitionContextOut.setIntAttribute(TransitionContext.ATTR_DURATION, 1000);
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 WIPE4:
screen = new TransitionScreen("Wipe4", Color.CORNFLOWERBLUE);

transitionContextIn = new TransitionContext(TransitionContext.TRANSITION_WIPE);
transitionContextIn.setIntAttribute(TransitionContext.ATTR_DURATION, 1000);
transitionContextIn.setIntAttribute(TransitionContext.ATTR_DIRECTION, TransitionContext.DIRECTION_LEFT);

transitionContextOut = new TransitionContext(TransitionContext.TRANSITION_WIPE);
transitionContextOut.setIntAttribute(TransitionContext.ATTR_DURATION, 1000);
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 WIPE5:
screen = new TransitionScreen("Wipe5", Color.BLACK);

transitionContextIn = new TransitionContext(TransitionContext.TRANSITION_WIPE);
transitionContextIn.setIntAttribute(TransitionContext.ATTR_DURATION, 1000);
transitionContextIn.setIntAttribute(TransitionContext.ATTR_DIRECTION, TransitionContext.DIRECTION_LEFT);

transitionContextOut = new TransitionContext(TransitionContext.TRANSITION_WIPE);
transitionContextOut.setIntAttribute(TransitionContext.ATTR_DURATION, 1000);
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;
}

synchronized(UiApplication.getEventLock())
{
pushScreen(screen);
_pushed = true;
}
}

private void snooze()
{
try
{
sleep(2000);
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
}
}

 

This is Class "TransitionScreen"

 

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.decor.*;


public class TransitionScreen extends MainScreen
{

public TransitionScreen(String title, int color)
{
setTitle(title);
VerticalFieldManager manager = (VerticalFieldManager)getMainManager();
manager.setBackground(BackgroundFactory.createSolidBackground(color));
}
protected boolean invokeAction(int action)
{
if(action == ACTION_INVOKE)
{
ScreenTransitions app = (ScreenTransitions)UiApplication.getUiApplication();
app.startOrStopThread();
return true;
}

return super.invokeAction(action);
}

public boolean touchEvent(TouchEvent event)
{
if(event.getEvent() == TouchEvent.UNCLICK)
{
invokeAction(ACTION_INVOKE);
return true;
}

return super.touchEvent(event);
}
}

}

 

Let me explain to you what this app does and what i want it to do...

Once you click on your trackwheel on the main screen the app does the following:

main screen, wipe1,main screen wipe2,main screen, wipe3, etc.(this happens automatically after the first click on the trackpad)

 

What I want this app to do is for the user to be able to scroll through all the screens of the app (Left and Right only).

 

If anyone can tell me where in the code snippet this automatic scroll takes place and what should be in place of it I would really appreciate it.

 

Please let me know if you have any queries

 

Thank you All

 

 

 

Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: Screen Transitions (from one click to manually scrolling through the Screens)

The transition thread is driving the animation in its run method by calling the push function which picks which transition to use. Is this code someone gave you? It would be easier to roll your own code than modify this unless you're going to have a "background" screen that controls the animation like this does.
Trusted Contributor
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom

Re: Screen Transitions (from one click to manually scrolling through the Screens)

Hi there

 

I am new to development so It is not that simple for me to write a code as big as this, I have Created the piece of code to get the left and right Scrolling to work. 

 

A friend of mine also mentioned that the  startOrStopThread();  influences the Screens to swipe automatically.