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: 37
Registered: ‎07-23-2011
My Device: 9700
My Carrier: Airtel

Swipe gesture

I implemented Swipe gesture in my app OS 7.0, its working well. But i swipe from right to left the next screen pushed immedialtely, its not looks like swipe. I need to implement swipe like 9900Bold pictures view.
Here is my code:


protected boolean touchEvent(TouchEvent message) {
  switch(message.getEvent()) {
  case TouchEvent.GESTURE:
   TouchGesture gesture = message.getGesture();  
   switch(gesture.getEvent()) {   
   case TouchGesture.SWIPE:    
    if(gesture.getSwipeDirection() == TouchGesture.SWIPE_WEST) {     UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
UiApplication.getUiApplication().pushScreen(new Preview());     
     return true;
    } else if(gesture.getSwipeDirection() == TouchGesture.SWIPE_EAST) {      UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
  UiApplication.getUiApplication().pushScreen(new PreviewMarks();
  return true;
  }
  return false;
 }
 
Please help me to swipe the screen, and let me know whether i want to use invoke later while push my screen.

Developer
Posts: 134
Registered: ‎08-03-2011
My Device: torch, Z10
My Carrier: Vodafone, Airtel

Re: Swipe gesture

try like this.

 

protected boolean touchEvent(TouchEvent message) {
switch(message.getEvent()) {
case TouchEvent.GESTURE:
TouchGesture gesture = message.getGesture();
switch(gesture.getEvent()) {
case TouchGesture.SWIPE:
if(gesture.getSwipeDirection() == TouchGesture.SWIPE_WEST) {

UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
UiApplication.getUiApplication().pushScreen(new Preview());
}
},500,true);
return true;
}
else if(gesture.getSwipeDirection() == TouchGesture.SWIPE_EAST) {
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
UiApplication.getUiApplication().pushScreen(new PreviewMarks());
}
},500,true);
return true;
}
return false;
}
}
return super.touchEvent(message);
}

-----------------------------------------------------------------------
"Like" if you liked the post.
"Accept as Solution" if the post solves your question.
-----------------------------------------------------------------------
Developer
Posts: 134
Registered: ‎08-03-2011
My Device: torch, Z10
My Carrier: Vodafone, Airtel

Re: Swipe gesture

[ Edited ]

you can use without this " 500,true "

UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
UiApplication.getUiApplication().pushScreen(new Preview());
}
});

-----------------------------------------------------------------------
"Like" if you liked the post.
"Accept as Solution" if the post solves your question.
-----------------------------------------------------------------------
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Swipe gesture

Are you looking for the old screen to slide out of view and the new one to slide into view?

 

If so, this is a Transition.  I'm not great on these, but if you search round you should find some samples to help.  Look at the TranistinoContext for the sorts of Transitions you can have. 

Contributor
Posts: 37
Registered: ‎07-23-2011
My Device: 9700
My Carrier: Airtel

Re: Swipe gesture

Yes i need to move the old screen and new screen will be displayed when i swipe the screen.

Contributor
Posts: 37
Registered: ‎07-23-2011
My Device: 9700
My Carrier: Airtel

Re: Swipe gesture

[ Edited ]

I implemented the Transition animation using swipe and its working well, but just now i remebered that the screen status bar must be fixed only the contents must move from left to right and vice versa. But now for me the full screen moves. Is there any way to do transitions effects for manager without statusbar.

switch(gesture.getEvent()) {
   case TouchGesture.SWIPE:
    if(gesture.getSwipeDirection() == TouchGesture.SWIPE_WEST) {     
      UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
       push();     
     return true;
    }                  
   }
void push()
      {                           
          Preview screen = null;
          TransitionContext transitionContextIn;
          TransitionContext transitionContextOut;
          UiEngineInstance engine = Ui.getUiEngineInstance();         
          screen = new Preview();  
          transitionContextIn = new TransitionContext(TransitionContext.TRANSITION_SLIDE);
transitionContextIn.setIntAttribute(TransitionContext.ATTR_DURATION, 500);
transitionContextIn.setIntAttribute(TransitionContext.ATTR_DIRECTION, TransitionContext.DIRECTION_LEFT); transitionContextOut = new TransitionContext(TransitionContext.TRANSITION_SLIDE);
transitionContextOut.setIntAttribute(TransitionContext.ATTR_DURATION, 500);
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); synchronized(UiApplication.getEventLock()) { UiApplication.getUiApplication().pushScreen(screen); _pushed = true; } }