Analyzes the given motion event and if applicable triggers the appropriate callbacks on the OnGestureListener supplied.
216 final int action = ev.getAction();
217 final float y = ev.getY();
218 final float x = ev.getX();
220 boolean handled =
false;
222 switch (action & MotionEvent.ACTION_MASK)
224 case MotionEvent.ACTION_POINTER_DOWN:
225 if (mIgnoreMultitouch)
232 case MotionEvent.ACTION_POINTER_UP:
234 if (mIgnoreMultitouch && ev.getPointerCount() == 2)
236 int index = (((action & MotionEvent.ACTION_POINTER_INDEX_MASK) >>
237 MotionEvent.ACTION_POINTER_INDEX_SHIFT) == 0)
240 mLastMotionX = ev.getX(index);
241 mLastMotionY = ev.getY(index);
245 case MotionEvent.ACTION_DOWN:
246 if (mDoubleTapListener !=
null)
248 boolean hadTapMessage = mHandler.hasMessages(TAP);
250 mHandler.removeMessages(TAP);
251 if ((mCurrentDownEvent !=
null) && (mPreviousUpEvent !=
null) &&
253 isConsideredDoubleTap(mCurrentDownEvent, mPreviousUpEvent, ev))
256 mIsDoubleTapping =
true;
258 handled |= mDoubleTapListener.
onDoubleTap(mCurrentDownEvent);
265 mHandler.sendEmptyMessageDelayed(TAP, DOUBLE_TAP_TIMEOUT);
271 if (mCurrentDownEvent !=
null)
273 mCurrentDownEvent.recycle();
275 mCurrentDownEvent = MotionEvent.obtain(ev);
276 mAlwaysInTapRegion =
true;
277 mAlwaysInBiggerTapRegion =
true;
279 mInLongPress =
false;
281 if (mIsLongpressEnabled)
283 mHandler.removeMessages(LONG_PRESS);
284 mHandler.sendEmptyMessageAtTime(LONG_PRESS, mCurrentDownEvent.getDownTime() +
288 mHandler.sendEmptyMessageAtTime(SHOW_PRESS,
289 mCurrentDownEvent.getDownTime() + TAP_TIMEOUT);
290 handled |= mListener.
onDown(ev);
293 case MotionEvent.ACTION_MOVE:
294 if (mIgnoreMultitouch && ev.getPointerCount() > 1)
298 final float scrollX = mLastMotionX - x;
299 final float scrollY = mLastMotionY - y;
300 if (mIsDoubleTapping)
305 else if (mAlwaysInTapRegion)
307 final int deltaX = (int)(x - mCurrentDownEvent.getX());
308 final int deltaY = (int)(y - mCurrentDownEvent.getY());
309 int distance = (deltaX * deltaX) + (deltaY * deltaY);
310 if (distance > mTouchSlopSquare)
314 mAlwaysInTapRegion =
false;
315 mHandler.removeMessages(TAP);
316 mHandler.removeMessages(SHOW_PRESS);
317 mHandler.removeMessages(LONG_PRESS);
319 if (distance > mLargeTouchSlopSquare)
321 mAlwaysInBiggerTapRegion =
false;
323 handled = mListener.
onScroll(mCurrentDownEvent, ev, scrollX, scrollY);
325 else if ((Math.abs(scrollX) >= 1) || (Math.abs(scrollY) >= 1))
327 handled = mListener.
onScroll(mCurrentDownEvent, ev, scrollX, scrollY);
333 case MotionEvent.ACTION_UP:
335 MotionEvent currentUpEvent = MotionEvent.obtain(ev);
336 if (mIsDoubleTapping)
341 else if (mInLongPress)
343 mHandler.removeMessages(TAP);
345 mInLongPress =
false;
347 else if (mAlwaysInTapRegion)
355 if (mPreviousUpEvent !=
null)
357 mPreviousUpEvent.recycle();
360 mPreviousUpEvent = currentUpEvent;
361 mIsDoubleTapping =
false;
362 mHandler.removeMessages(SHOW_PRESS);
363 mHandler.removeMessages(LONG_PRESS);
364 handled |= mListener.
onUp(ev);
366 case MotionEvent.ACTION_CANCEL:
boolean onDoubleTapEvent(MotionEvent e)
boolean onDoubleTap(MotionEvent e)
boolean onSingleTapUp(MotionEvent e)
void onLongPressUp(MotionEvent e)
boolean onDown(MotionEvent e)
boolean onUp(MotionEvent e)
boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)