19 dp_factor_ = 160.f / AConfiguration_getDensity(config);
28 if (AMotionEvent_getPointerCount(motion_event) > 1) {
33 int32_t action = AMotionEvent_getAction(motion_event);
34 unsigned int flags = action & AMOTION_EVENT_ACTION_MASK;
36 case AMOTION_EVENT_ACTION_DOWN:
38 down_x_ = AMotionEvent_getX(motion_event, 0);
39 down_y_ = AMotionEvent_getY(motion_event, 0);
41 case AMOTION_EVENT_ACTION_UP: {
42 int64_t eventTime = AMotionEvent_getEventTime(motion_event);
43 int64_t downTime = AMotionEvent_getDownTime(motion_event);
46 float x = AMotionEvent_getX(motion_event, 0) -
down_x_;
47 float y = AMotionEvent_getY(motion_event, 0) -
down_y_;
66 if (AMotionEvent_getPointerCount(motion_event) > 1) {
71 bool tap_detected = tap_detector_.Detect(motion_event);
73 int32_t action = AMotionEvent_getAction(motion_event);
74 unsigned int flags = action & AMOTION_EVENT_ACTION_MASK;
76 case AMOTION_EVENT_ACTION_DOWN: {
77 int64_t eventTime = AMotionEvent_getEventTime(motion_event);
79 float x = AMotionEvent_getX(motion_event, 0) - last_tap_x_;
80 float y = AMotionEvent_getY(motion_event, 0) - last_tap_y_;
87 case AMOTION_EVENT_ACTION_UP:
89 last_tap_time_ = AMotionEvent_getEventTime(motion_event);
90 last_tap_x_ = AMotionEvent_getX(motion_event, 0);
91 last_tap_y_ = AMotionEvent_getY(motion_event, 0);
99 dp_factor_ = 160.f / AConfiguration_getDensity(config);
100 tap_detector_.SetConfiguration(config);
108 int32_t count = AMotionEvent_getPointerCount(event);
109 for (
auto i = 0; i < count; ++i) {
110 if (
id == AMotionEvent_getPointerId(event, i))
return i;
117 int32_t action = AMotionEvent_getAction(event);
118 uint32_t flags = action & AMOTION_EVENT_ACTION_MASK;
121 int32_t count = AMotionEvent_getPointerCount(event);
123 case AMOTION_EVENT_ACTION_DOWN:
124 vec_pointers_.push_back(AMotionEvent_getPointerId(event, 0));
126 case AMOTION_EVENT_ACTION_POINTER_DOWN: {
127 int32_t iIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >>
128 AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
129 vec_pointers_.push_back(AMotionEvent_getPointerId(event, iIndex));
135 case AMOTION_EVENT_ACTION_UP:
136 vec_pointers_.pop_back();
138 case AMOTION_EVENT_ACTION_POINTER_UP: {
139 int32_t index = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >>
140 AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
141 int32_t released_pointer_id = AMotionEvent_getPointerId(event, index);
143 std::vector<int32_t>::iterator it = vec_pointers_.begin();
144 std::vector<int32_t>::iterator it_end = vec_pointers_.end();
146 for (; it != it_end; ++it, ++i) {
147 if (*it == released_pointer_id) {
148 vec_pointers_.erase(it);
161 case AMOTION_EVENT_ACTION_MOVE:
171 case AMOTION_EVENT_ACTION_CANCEL:
179 if (vec_pointers_.size() < 2)
return false;
181 int32_t index = FindIndex(event_, vec_pointers_[0]);
182 if (index == -1)
return false;
184 float x = AMotionEvent_getX(event_, index);
185 float y = AMotionEvent_getY(event_, index);
187 index = FindIndex(event_, vec_pointers_[1]);
188 if (index == -1)
return false;
190 float x2 = AMotionEvent_getX(event_, index);
191 float y2 = AMotionEvent_getY(event_, index);
193 v1 = lug::Math::Vec2f{x, y};
194 v2 = lug::Math::Vec2f{x2, y2};
204 int32_t count = AMotionEvent_getPointerCount(event);
205 for (
auto i = 0; i < count; ++i) {
206 if (
id == AMotionEvent_getPointerId(event, i))
return i;
213 int32_t action = AMotionEvent_getAction(event);
214 int32_t index = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >>
215 AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
216 uint32_t flags = action & AMOTION_EVENT_ACTION_MASK;
219 int32_t count = AMotionEvent_getPointerCount(event);
221 case AMOTION_EVENT_ACTION_DOWN:
222 vec_pointers_.push_back(AMotionEvent_getPointerId(event, 0));
225 case AMOTION_EVENT_ACTION_POINTER_DOWN:
226 vec_pointers_.push_back(AMotionEvent_getPointerId(event, index));
228 case AMOTION_EVENT_ACTION_UP:
229 vec_pointers_.pop_back();
232 case AMOTION_EVENT_ACTION_POINTER_UP: {
233 int32_t released_pointer_id = AMotionEvent_getPointerId(event, index);
235 auto it = vec_pointers_.begin();
236 auto it_end = vec_pointers_.end();
238 for (; it != it_end; ++it, ++i) {
239 if (*it == released_pointer_id) {
240 vec_pointers_.erase(it);
253 case AMOTION_EVENT_ACTION_MOVE:
263 case AMOTION_EVENT_ACTION_CANCEL:
271 if (vec_pointers_.size() < 1)
return false;
273 int32_t iIndex = FindIndex(event_, vec_pointers_[0]);
274 if (iIndex == -1)
return false;
276 float x = AMotionEvent_getX(event_, iIndex);
277 float y = AMotionEvent_getY(event_, iIndex);
279 v = lug::Math::Vec2f{x, y};
const int32_t TAP_TIMEOUT
virtual GESTURE_STATE Detect(const AInputEvent *event)
const int32_t DOUBLE_TAP_SLOP
virtual GESTURE_STATE Detect(const AInputEvent *motion_event)
bool GetPointers(lug::Math::Vec2f &v1, lug::Math::Vec2f &v2)
virtual GESTURE_STATE Detect(const AInputEvent *event)
virtual GESTURE_STATE Detect(const AInputEvent *motion_event)
int32_t FindIndex(const AInputEvent *event, int32_t id)
virtual void SetConfiguration(AConfiguration *config)
virtual void SetConfiguration(AConfiguration *config)
bool GetPointer(lug::Math::Vec2f &v)
int32_t FindIndex(const AInputEvent *event, int32_t id)
const int32_t DOUBLE_TAP_TIMEOUT