Analyzes the given motion event and if applicable triggers the appropriate callbacks on the OnGestureListener
supplied.
215 {
216 final int action = ev.getAction();
217 final float y = ev.getY();
218 final float x = ev.getX();
219
220 boolean handled = false;
221
222 switch (action & MotionEvent.ACTION_MASK)
223 {
224 case MotionEvent.ACTION_POINTER_DOWN:
225 if (mIgnoreMultitouch)
226 {
227
228 cancel();
229 }
230 break;
231
232 case MotionEvent.ACTION_POINTER_UP:
233
234 if (mIgnoreMultitouch && ev.getPointerCount() == 2)
235 {
236 int index = (((action & MotionEvent.ACTION_POINTER_INDEX_MASK) >>
237 MotionEvent.ACTION_POINTER_INDEX_SHIFT) == 0)
238 ? 1
239 : 0;
240 mLastMotionX = ev.getX(index);
241 mLastMotionY = ev.getY(index);
242 }
243 break;
244
245 case MotionEvent.ACTION_DOWN:
246 if (mDoubleTapListener != null)
247 {
248 boolean hadTapMessage = mHandler.hasMessages(TAP);
249 if (hadTapMessage)
250 mHandler.removeMessages(TAP);
251 if ((mCurrentDownEvent != null) && (mPreviousUpEvent != null) &&
252 hadTapMessage &&
253 isConsideredDoubleTap(mCurrentDownEvent, mPreviousUpEvent, ev))
254 {
255
256 mIsDoubleTapping = true;
257
258 handled |= mDoubleTapListener.
onDoubleTap(mCurrentDownEvent);
259
261 }
262 else
263 {
264
265 mHandler.sendEmptyMessageDelayed(TAP, DOUBLE_TAP_TIMEOUT);
266 }
267 }
268
269 mLastMotionX = x;
270 mLastMotionY = y;
271 if (mCurrentDownEvent != null)
272 {
273 mCurrentDownEvent.recycle();
274 }
275 mCurrentDownEvent = MotionEvent.obtain(ev);
276 mAlwaysInTapRegion = true;
277 mAlwaysInBiggerTapRegion = true;
278 mStillDown = true;
279 mInLongPress = false;
280
281 if (mIsLongpressEnabled)
282 {
283 mHandler.removeMessages(LONG_PRESS);
284 mHandler.sendEmptyMessageAtTime(LONG_PRESS, mCurrentDownEvent.getDownTime() +
285 TAP_TIMEOUT +
286 mLongpressTimeout);
287 }
288 mHandler.sendEmptyMessageAtTime(SHOW_PRESS,
289 mCurrentDownEvent.getDownTime() + TAP_TIMEOUT);
290 handled |= mListener.
onDown(ev);
291 break;
292
293 case MotionEvent.ACTION_MOVE:
294 if (mIgnoreMultitouch && ev.getPointerCount() > 1)
295 {
296 break;
297 }
298 final float scrollX = mLastMotionX - x;
299 final float scrollY = mLastMotionY - y;
300 if (mIsDoubleTapping)
301 {
302
304 }
305 else if (mAlwaysInTapRegion)
306 {
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)
311 {
312 mLastMotionX = x;
313 mLastMotionY = y;
314 mAlwaysInTapRegion = false;
315 mHandler.removeMessages(TAP);
316 mHandler.removeMessages(SHOW_PRESS);
317 mHandler.removeMessages(LONG_PRESS);
318 }
319 if (distance > mLargeTouchSlopSquare)
320 {
321 mAlwaysInBiggerTapRegion = false;
322 }
323 handled = mListener.
onScroll(mCurrentDownEvent, ev, scrollX, scrollY);
324 }
325 else if ((Math.abs(scrollX) >= 1) || (Math.abs(scrollY) >= 1))
326 {
327 handled = mListener.
onScroll(mCurrentDownEvent, ev, scrollX, scrollY);
328 mLastMotionX = x;
329 mLastMotionY = y;
330 }
331 break;
332
333 case MotionEvent.ACTION_UP:
334 mStillDown = false;
335 MotionEvent currentUpEvent = MotionEvent.obtain(ev);
336 if (mIsDoubleTapping)
337 {
338
340 }
341 else if (mInLongPress)
342 {
343 mHandler.removeMessages(TAP);
345 mInLongPress = false;
346 }
347 else if (mAlwaysInTapRegion)
348 {
350 }
351 else
352 {
353
354 }
355 if (mPreviousUpEvent != null)
356 {
357 mPreviousUpEvent.recycle();
358 }
359
360 mPreviousUpEvent = currentUpEvent;
361 mIsDoubleTapping = false;
362 mHandler.removeMessages(SHOW_PRESS);
363 mHandler.removeMessages(LONG_PRESS);
364 handled |= mListener.
onUp(ev);
365 break;
366 case MotionEvent.ACTION_CANCEL:
367 cancel();
368 break;
369 }
370 return handled;
371 }
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)