0

Hello stackoverflow community,

i have a very strange problem with my SimpleOnGestureListener:

public class OnSwipeTouchListener implements View.OnTouchListener {
//constructor...
@SuppressWarnings("deprecation")
private final GestureDetector gestureDetector = new GestureDetector(new GestureListener());

public boolean onTouch(final View v, final MotionEvent event) {
    return gestureDetector.onTouchEvent(event);
}

private final class GestureListener extends GestureDetector.SimpleOnGestureListener {

    private static final int SWIPE_THRESHOLD = 100;
    private static final int SWIPE_VELOCITY_THRESHOLD = 100;    

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        try {
             float diffX = e2.getRawX() - e1.getRawX();
             if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
                    if (diffX > 0) {
                        onSwipeRight();
                    }
                    if(diffX < 0) {
                        onSwipeLeft();
                    }
                }
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        return false;
    }
}

public void onSwipeRight() {
    Log.i("PPTREMOTE", "Swiped Right!");
    main.previousSlide();
}

public void onSwipeLeft() {
    Log.i("PPTREMOTE", "Swiped Left!");
    main.nextSlide();
  }
}

My problem is very strange. onFling is only called, when I'm swiping left ?!

theporenta

theporenta
  • 71
  • 1
  • 3
  • i think you may want if velocityX > 0 rather than difx – LanternMike May 19 '13 at 18:05
  • Maybe you're, but onFling isn't even called, when I'm swiping right so velocityX should not be the problem at the moment. ;) – theporenta May 19 '13 at 18:18
  • 1
    are you sure its not being called or your if statement is not passing. I saw another post where getRawX seemed to return the same for both points meaning difx could be 0 if that's so. Seems getX() is used. http://stackoverflow.com/questions/937313/android-basic-gesture-detection – LanternMike May 19 '13 at 18:26
  • I'm absolutely sure about that, I already tried it with getX()... – theporenta May 19 '13 at 18:55
  • If you debug the app and set a breakpoint at "float diffX ...", what do you see? – Christine May 19 '13 at 19:54
  • When I swipe left everything looks fine, if i swipe right nothing happens (the breakpoint isn't reached)... – theporenta May 20 '13 at 09:06

0 Answers0