]> git.ktnx.net Git - mobile-ledger.git/blob - app/src/main/java/net/ktnx/mobileledger/OnSwipeTouchListener.java
update accounts table visual upon refreshilg the account data from the backend
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / OnSwipeTouchListener.java
1 package net.ktnx.mobileledger;
2
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;
9
10 public abstract class OnSwipeTouchListener implements View.OnTouchListener {
11     public final GestureDetector gestureDetector;
12
13     OnSwipeTouchListener(Context ctx) {
14         gestureDetector = new GestureDetector(ctx, new GestureListener() );
15     }
16
17     private final class GestureListener extends SimpleOnGestureListener {
18         private static final int SWIPE_THRESHOLD = 100;
19         private static final int SWIPE_VELOCITY_THRESHOLD = 100;
20
21         @Override
22         public boolean onDown(MotionEvent e) {
23             Log.d("sw-l", "onDown");
24             return false;
25         }
26
27         @Override
28         public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
29             boolean result = false;
30
31             Log.d("sw-l", "onFling");
32
33             try {
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) {
38                         if (diffX > 0) {
39                             Log.d("sw-l", "calling onSwipeRight");
40                             onSwipeRight();
41                         }
42                         else {
43                             Log.d("sw-l", "calling onSwipeLeft");
44                             onSwipeLeft();
45                         }
46                     }
47                     result = true;
48                 }
49                 else if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
50                     if (diffY > 0) {
51                         onSwipeDown();
52                     }
53                     else {
54                         onSwipeUp();
55                     }
56                     result = true;
57                 }
58             }
59             catch (Exception e) {
60                 e.printStackTrace();
61             }
62
63             return result;
64         }
65     }
66
67     public void onSwipeRight() {}
68     public void onSwipeLeft() {
69         Log.d("sw-l", "LEFT");
70     }
71     public void onSwipeUp() {}
72     public void onSwipeDown() {}
73 }