예제 #1
0
  @Override
  public boolean onFling(
      final MotionEvent e1, final MotionEvent e2, float velocityX, float velocityY) {
    final float xDistance = Math.abs(e1.getX() - e2.getX());
    final float yDistance = Math.abs(e1.getY() - e2.getY());

    if (xDistance > _swipe_Max_Distance || yDistance > _swipe_Max_Distance) return false;

    velocityX = Math.abs(velocityX);
    velocityY = Math.abs(velocityY);
    boolean result = false;

    if (velocityX > _swipe_Min_Velocity && xDistance > _swipe_Min_Distance) {
      if (e1.getX() > e2.getX()) // right to left
      _listener.onSwipe(SWIPE_LEFT);
      else _listener.onSwipe(SWIPE_RIGHT);
      result = true;
    } else if (velocityY > _swipe_Min_Velocity && yDistance > _swipe_Min_Distance) {
      if (e1.getY() > e2.getY()) // bottom to up
      _listener.onSwipe(SWIPE_UP);
      else _listener.onSwipe(SWIPE_DOWN);
      result = true;
    }
    return result;
  }