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