package de.danoeh.antennapod.view; import android.util.Log; import android.view.GestureDetector; import android.view.MotionEvent; public class SwipeGestureDetector extends GestureDetector.SimpleOnGestureListener { private static final String TAG = "SwipeGestureDetector"; private static final int SWIPE_MIN_DISTANCE = 120; private static final int SWIPE_MAX_OFF_PATH = 250; private static final int SWIPE_THRESHOLD_VELOCITY = 200; private final OnSwipeGesture callback; public SwipeGestureDetector(OnSwipeGesture callback) { this.callback = callback; } @Override public boolean onDown(MotionEvent e) { return true; } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { try { if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) return false; if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { return callback.onSwipeRightToLeft(); } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { return callback.onSwipeLeftToRight(); } } catch (Exception e) { Log.d(TAG, Log.getStackTraceString(e)); } return false; } }