diff options
author | Martin Fietz <Martin.Fietz@gmail.com> | 2016-03-27 18:26:47 +0200 |
---|---|---|
committer | Martin Fietz <Martin.Fietz@gmail.com> | 2016-03-27 18:26:47 +0200 |
commit | b3c41ce9c7b265b3d8b20a24b1a14fa12dc3d2cf (patch) | |
tree | f98ce63dfa832ebfd5d36b83ee7d8f2afd28b822 /app/src/main/java/de/danoeh/antennapod/view | |
parent | 178014ff93126f98c61ef5e0e895649d2bf412d9 (diff) | |
download | AntennaPod-b3c41ce9c7b265b3d8b20a24b1a14fa12dc3d2cf.zip |
Episode view: Go to previous/next list item when swiping right/left
Diffstat (limited to 'app/src/main/java/de/danoeh/antennapod/view')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/view/OnSwipeGesture.java | 9 | ||||
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/view/SwipeGestureDetector.java | 44 |
2 files changed, 53 insertions, 0 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/view/OnSwipeGesture.java b/app/src/main/java/de/danoeh/antennapod/view/OnSwipeGesture.java new file mode 100644 index 000000000..eb72a7135 --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/view/OnSwipeGesture.java @@ -0,0 +1,9 @@ +package de.danoeh.antennapod.view; + +public interface OnSwipeGesture { + + boolean onSwipeLeftToRight(); + + boolean onSwipeRightToLeft(); + +} diff --git a/app/src/main/java/de/danoeh/antennapod/view/SwipeGestureDetector.java b/app/src/main/java/de/danoeh/antennapod/view/SwipeGestureDetector.java new file mode 100644 index 000000000..f4ee092df --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/view/SwipeGestureDetector.java @@ -0,0 +1,44 @@ +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; + } + +} |