1 package net.ktnx.mobileledger;
3 import android.content.Context;
4 import android.util.Log;
5 import android.view.GestureDetector;
6 import android.view.GestureDetector.SimpleOnGestureListener;
7 import android.view.MotionEvent;
8 import android.view.View;
10 public abstract class OnSwipeTouchListener implements View.OnTouchListener {
11 public final GestureDetector gestureDetector;
13 OnSwipeTouchListener(Context ctx) {
14 gestureDetector = new GestureDetector(ctx, new GestureListener() );
17 private final class GestureListener extends SimpleOnGestureListener {
18 private static final int SWIPE_THRESHOLD = 100;
19 private static final int SWIPE_VELOCITY_THRESHOLD = 100;
22 public boolean onDown(MotionEvent e) {
23 Log.d("sw-l", "onDown");
28 public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
29 boolean result = false;
31 Log.d("sw-l", "onFling");
34 float diffX = e2.getX() - e1.getX();
35 float diffY = e2.getY() - e1.getY();
36 if (Math.abs(diffX) > Math.abs(diffY)) {
37 if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
39 Log.d("sw-l", "calling onSwipeRight");
43 Log.d("sw-l", "calling onSwipeLeft");
49 else if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
67 public void onSwipeRight() {}
68 public void onSwipeLeft() {
69 Log.d("sw-l", "LEFT");
71 public void onSwipeUp() {}
72 public void onSwipeDown() {}