Android GestureDetector机制要点解析
1、需要的记录的信息
载体是java侧是类MotionEvent,cpp侧是gPointerCoordsClassInfo
记录的信息包括:
public float x;
public float y;
public float pressure;
public float size;
public float touchMajor;
public float touchMinor;
public float toolMajor;
public float toolMinor;
public float orientation;
2.原始点信息获取
InputConsumer::populateMotionEvent(MotionEvent* motionEvent)---->
motionEvent->addSample(sampleData->eventTime, sampleData->coords);-->
mSampleEventTimes.push(eventTime);
mSamplePointerCoords.appendArray(pointerCoords, getPointerCount()
3、动作判断---手势侦测
GestureDetector::onTouchEvent(MotionEvent ev),其中ev是通过parcel传递过来的运动信息。
===============================
此函数中涉及集中事件的分发,它们的上报时机如下:
ACTION_DOWN is for the first finger that touches the screen. This starts the gesture. The pointer data for this finger is always at index 0 in the MotionEvent.
ACTION_POINTER_DOWN is for extra fingers that enter the screen beyond the first. The pointer data for this finger is at the index returned by getActionIndex().
ACTION_POINTER_UP is sent when a finger leaves the screen but at least one finger is still touching it. The last data sample about the finger that went up is at the index returned by getActionIndex().
ACTION_UP is sent when the last finger leaves the screen. The last data sample about the finger that went up is at index 0. This ends the gesture.
ACTION_CANCEL means the entire gesture was aborted for some reason. This ends the gesture.
more detail
===============================
DoubleTap的判断
两次点获取的时间间隔小于DOUBLE_TAP_TIMEOUT,同时距离的平方小于mDoubleTapSlopSquare
OnFling的判断
X和Y方向的速度都超过mMinimumFlingVelocity