20 #ifndef GESTUREDETECTOR_H_ 21 #define GESTUREDETECTOR_H_ 25 #include <android/sensor.h> 26 #include <android/log.h> 27 #include <android_native_app_glue.h> 28 #include <android/native_window_jni.h> 29 #include "JNIHelper.h" 36 const int32_t DOUBLE_TAP_TIMEOUT = 300 * 1000000;
37 const int32_t TAP_TIMEOUT = 180 * 1000000;
38 const int32_t DOUBLE_TAP_SLOP = 100;
39 const int32_t TOUCH_SLOP = 8;
42 GESTURE_STATE_NONE = 0,
43 GESTURE_STATE_START = 1,
44 GESTURE_STATE_MOVE = 2,
45 GESTURE_STATE_END = 4,
46 GESTURE_STATE_ACTION = (GESTURE_STATE_START | GESTURE_STATE_END),
48 typedef int32_t GESTURE_STATE;
57 class GestureDetector {
63 virtual ~GestureDetector() {}
64 virtual void SetConfiguration(AConfiguration* config);
66 virtual GESTURE_STATE Detect(
const AInputEvent* motion_event) = 0;
74 class TapDetector :
public GestureDetector {
76 int32_t down_pointer_id_;
82 virtual ~TapDetector() {}
83 virtual GESTURE_STATE Detect(
const AInputEvent* motion_event);
91 class DoubletapDetector :
public GestureDetector {
93 TapDetector tap_detector_;
94 int64_t last_tap_time_;
100 virtual ~DoubletapDetector() {}
101 virtual GESTURE_STATE Detect(
const AInputEvent* motion_event);
102 virtual void SetConfiguration(AConfiguration* config);
112 class PinchDetector :
public GestureDetector {
114 int32_t FindIndex(
const AInputEvent* event, int32_t
id);
115 const AInputEvent* event_;
116 std::vector<int32_t> vec_pointers_;
120 virtual ~PinchDetector() {}
121 virtual GESTURE_STATE Detect(
const AInputEvent* event);
122 bool GetPointers(Vec2& v1, Vec2& v2);
130 class DragDetector :
public GestureDetector {
132 int32_t FindIndex(
const AInputEvent* event, int32_t
id);
133 const AInputEvent* event_;
134 std::vector<int32_t> vec_pointers_;
137 DragDetector() : event_(nullptr) {}
138 virtual ~DragDetector() {}
139 virtual GESTURE_STATE Detect(
const AInputEvent* event);
140 bool GetPointer(Vec2& v);
Definition: gestureDetector.h:32