blob: f4ee092df53d2ff1234e71fdaf7496be3655b849 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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;
}
}
|