@@ -162,7 +162,7 @@ class TouchExplorer implements EventStreamTransformation {
162162 private EventStreamTransformation mNext ;
163163
164164 // Helper to track gesture velocity.
165- private VelocityTracker mVelocityTracker ;
165+ private final VelocityTracker mVelocityTracker = VelocityTracker . obtain () ;
166166
167167 // Helper class to track received pointers.
168168 private final ReceivedPointerTracker mReceivedPointerTracker ;
@@ -309,18 +309,18 @@ public void setNext(EventStreamTransformation next) {
309309 }
310310
311311 @ Override
312- public void onMotionEvent (MotionEvent event , int policyFlags ) {
312+ public void onMotionEvent (MotionEvent event , MotionEvent rawEvent , int policyFlags ) {
313313 if (DEBUG ) {
314314 Slog .d (LOG_TAG , "Received event: " + event + ", policyFlags=0x"
315315 + Integer .toHexString (policyFlags ));
316316 Slog .d (LOG_TAG , getStateSymbolicName (mCurrentState ));
317317 }
318318
319- mReceivedPointerTracker .onMotionEvent (event );
319+ mReceivedPointerTracker .onMotionEvent (rawEvent );
320320
321321 switch (mCurrentState ) {
322322 case STATE_TOUCH_EXPLORING : {
323- handleMotionEventStateTouchExploring (event , policyFlags );
323+ handleMotionEventStateTouchExploring (event , rawEvent , policyFlags );
324324 } break ;
325325 case STATE_DRAGGING : {
326326 handleMotionEventStateDragging (event , policyFlags );
@@ -329,7 +329,7 @@ public void onMotionEvent(MotionEvent event, int policyFlags) {
329329 handleMotionEventStateDelegating (event , policyFlags );
330330 } break ;
331331 case STATE_GESTURE_DETECTING : {
332- handleMotionEventGestureDetecting (event , policyFlags );
332+ handleMotionEventGestureDetecting (rawEvent , policyFlags );
333333 } break ;
334334 default :
335335 throw new IllegalStateException ("Illegal state: " + mCurrentState );
@@ -382,16 +382,15 @@ public void onAccessibilityEvent(AccessibilityEvent event) {
382382 * Handles a motion event in touch exploring state.
383383 *
384384 * @param event The event to be handled.
385+ * @param rawEvent The raw (unmodified) motion event.
385386 * @param policyFlags The policy flags associated with the event.
386387 */
387- private void handleMotionEventStateTouchExploring (MotionEvent event , int policyFlags ) {
388+ private void handleMotionEventStateTouchExploring (MotionEvent event , MotionEvent rawEvent ,
389+ int policyFlags ) {
388390 ReceivedPointerTracker receivedTracker = mReceivedPointerTracker ;
389391 final int activePointerCount = receivedTracker .getActivePointerCount ();
390392
391- if (mVelocityTracker == null ) {
392- mVelocityTracker = VelocityTracker .obtain ();
393- }
394- mVelocityTracker .addMovement (event );
393+ mVelocityTracker .addMovement (rawEvent );
395394
396395 mDoubleTapDetector .onMotionEvent (event , policyFlags );
397396
@@ -410,7 +409,7 @@ private void handleMotionEventStateTouchExploring(MotionEvent event, int policyF
410409 // have a distance slop before getting into gesture detection
411410 // mode and not using the points within this slop significantly
412411 // decreases the quality of gesture recognition.
413- handleMotionEventGestureDetecting (event , policyFlags );
412+ handleMotionEventGestureDetecting (rawEvent , policyFlags );
414413 //$FALL-THROUGH$
415414 case MotionEvent .ACTION_POINTER_DOWN : {
416415 switch (activePointerCount ) {
@@ -471,12 +470,13 @@ private void handleMotionEventStateTouchExploring(MotionEvent event, int policyF
471470 // have a distance slop before getting into gesture detection
472471 // mode and not using the points within this slop significantly
473472 // decreases the quality of gesture recognition.
474- handleMotionEventGestureDetecting (event , policyFlags );
475-
473+ handleMotionEventGestureDetecting (rawEvent , policyFlags );
474+ // It is *important* to use the distance traveled by the pointers
475+ // on the screen which may or may not be magnified.
476476 final float deltaX = receivedTracker .getReceivedPointerDownX (pointerId )
477- - event .getX (pointerIndex );
477+ - rawEvent .getX (pointerIndex );
478478 final float deltaY = receivedTracker .getReceivedPointerDownY (pointerId )
479- - event .getY (pointerIndex );
479+ - rawEvent .getY (pointerIndex );
480480 final double moveDelta = Math .hypot (deltaX , deltaY );
481481 // The user has moved enough for us to decide.
482482 if (moveDelta > mDoubleTapSlop ) {
@@ -491,6 +491,7 @@ private void handleMotionEventStateTouchExploring(MotionEvent event, int policyF
491491 // We have to perform gesture detection, so
492492 // clear the current state and try to detect.
493493 mCurrentState = STATE_GESTURE_DETECTING ;
494+ mVelocityTracker .clear ();
494495 mSendHoverEnterDelayed .remove ();
495496 mSendHoverExitDelayed .remove ();
496497 mPerformLongPressDelayed .remove ();
@@ -535,10 +536,12 @@ private void handleMotionEventStateTouchExploring(MotionEvent event, int policyF
535536 // If the user is touch exploring the second pointer may be
536537 // performing a double tap to activate an item without need
537538 // for the user to lift his exploring finger.
539+ // It is *important* to use the distance traveled by the pointers
540+ // on the screen which may or may not be magnified.
538541 final float deltaX = receivedTracker .getReceivedPointerDownX (pointerId )
539- - event .getX (pointerIndex );
542+ - rawEvent .getX (pointerIndex );
540543 final float deltaY = receivedTracker .getReceivedPointerDownY (pointerId )
541- - event .getY (pointerIndex );
544+ - rawEvent .getY (pointerIndex );
542545 final double moveDelta = Math .hypot (deltaX , deltaY );
543546 if (moveDelta < mDoubleTapSlop ) {
544547 break ;
@@ -565,6 +568,7 @@ private void handleMotionEventStateTouchExploring(MotionEvent event, int policyF
565568 mCurrentState = STATE_DELEGATING ;
566569 sendDownForAllActiveNotInjectedPointers (event , policyFlags );
567570 }
571+ mVelocityTracker .clear ();
568572 } break ;
569573 default : {
570574 // More than one pointer so the user is not touch exploring
@@ -585,6 +589,7 @@ private void handleMotionEventStateTouchExploring(MotionEvent event, int policyF
585589 // More than two pointers are delegated to the view hierarchy.
586590 mCurrentState = STATE_DELEGATING ;
587591 sendDownForAllActiveNotInjectedPointers (event , policyFlags );
592+ mVelocityTracker .clear ();
588593 }
589594 }
590595 } break ;
@@ -615,10 +620,7 @@ private void handleMotionEventStateTouchExploring(MotionEvent event, int policyF
615620 }
616621 } break ;
617622 }
618- if (mVelocityTracker != null ) {
619- mVelocityTracker .clear ();
620- mVelocityTracker = null ;
621- }
623+ mVelocityTracker .clear ();
622624 } break ;
623625 case MotionEvent .ACTION_CANCEL : {
624626 clear (event , policyFlags );
@@ -1046,7 +1048,10 @@ private void sendMotionEvent(MotionEvent prototype, int action, int pointerIdBit
10461048 // Make sure that the user will see the event.
10471049 policyFlags |= WindowManagerPolicy .FLAG_PASS_TO_USER ;
10481050 if (mNext != null ) {
1049- mNext .onMotionEvent (event , policyFlags );
1051+ // TODO: For now pass null for the raw event since the touch
1052+ // explorer is the last event transformation and it does
1053+ // not care about the raw event.
1054+ mNext .onMotionEvent (event , null , policyFlags );
10501055 }
10511056
10521057 mInjectedPointerTracker .onMotionEvent (event );
0 commit comments