Loading services/accessibility/java/com/android/server/accessibility/gestures/TouchExplorer.java +99 −99 Original line number Diff line number Diff line Loading @@ -16,7 +16,23 @@ package com.android.server.accessibility.gestures; import static android.view.MotionEvent.ACTION_CANCEL; import static android.view.MotionEvent.ACTION_DOWN; import static android.view.MotionEvent.ACTION_HOVER_ENTER; import static android.view.MotionEvent.ACTION_HOVER_EXIT; import static android.view.MotionEvent.ACTION_HOVER_MOVE; import static android.view.MotionEvent.ACTION_MOVE; import static android.view.MotionEvent.ACTION_POINTER_DOWN; import static android.view.MotionEvent.ACTION_POINTER_UP; import static android.view.MotionEvent.ACTION_UP; import static android.view.MotionEvent.INVALID_POINTER_ID; import static android.view.accessibility.AccessibilityEvent.TYPE_GESTURE_DETECTION_END; import static android.view.accessibility.AccessibilityEvent.TYPE_GESTURE_DETECTION_START; import static android.view.accessibility.AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_END; import static android.view.accessibility.AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_START; import static android.view.accessibility.AccessibilityEvent.TYPE_TOUCH_INTERACTION_END; import static android.view.accessibility.AccessibilityEvent.TYPE_TOUCH_INTERACTION_START; import static android.view.accessibility.AccessibilityEvent.TYPE_VIEW_HOVER_EXIT; import static com.android.server.accessibility.gestures.TouchState.ALL_POINTER_ID_BITS; Loading Loading @@ -144,8 +160,8 @@ public class TouchExplorer extends BaseEventStreamTransformation * @param detector The gesture detector to handle accessibility touch event. If null the default * one created in place, or for testing purpose. */ public TouchExplorer(Context context, AccessibilityManagerService service, GestureManifold detector) { public TouchExplorer( Context context, AccessibilityManagerService service, GestureManifold detector) { mContext = context; mAms = service; mState = new TouchState(); Loading @@ -157,12 +173,12 @@ public class TouchExplorer extends BaseEventStreamTransformation mExitGestureDetectionModeDelayed = new ExitGestureDetectionModeDelayed(); mSendHoverEnterAndMoveDelayed = new SendHoverEnterAndMoveDelayed(); mSendHoverExitDelayed = new SendHoverExitDelayed(); mSendTouchExplorationEndDelayed = new SendAccessibilityEventDelayed( AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_END, mDetermineUserIntentTimeout); mSendTouchInteractionEndDelayed = new SendAccessibilityEventDelayed( AccessibilityEvent.TYPE_TOUCH_INTERACTION_END, mDetermineUserIntentTimeout); mSendTouchExplorationEndDelayed = new SendAccessibilityEventDelayed( TYPE_TOUCH_EXPLORATION_GESTURE_END, mDetermineUserIntentTimeout); mSendTouchInteractionEndDelayed = new SendAccessibilityEventDelayed( TYPE_TOUCH_INTERACTION_END, mDetermineUserIntentTimeout); if (detector == null) { mGestureDetector = new GestureManifold(context, this, mState); } else { Loading Loading @@ -242,7 +258,7 @@ public class TouchExplorer extends BaseEventStreamTransformation } } if (event.getActionMasked() == MotionEvent.ACTION_CANCEL) { if (event.getActionMasked() == ACTION_CANCEL) { clear(event, policyFlags); return; } Loading Loading @@ -276,19 +292,16 @@ public class TouchExplorer extends BaseEventStreamTransformation // The event for gesture end should be strictly after the // last hover exit event. if (mSendTouchExplorationEndDelayed.isPending() && eventType == AccessibilityEvent.TYPE_VIEW_HOVER_EXIT) { if (mSendTouchExplorationEndDelayed.isPending() && eventType == TYPE_VIEW_HOVER_EXIT) { mSendTouchExplorationEndDelayed.cancel(); mDispatcher.sendAccessibilityEvent( AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_END); mDispatcher.sendAccessibilityEvent(TYPE_TOUCH_EXPLORATION_GESTURE_END); } // The event for touch interaction end should be strictly after the // last hover exit and the touch exploration gesture end events. if (mSendTouchInteractionEndDelayed.isPending() && eventType == AccessibilityEvent.TYPE_VIEW_HOVER_EXIT) { if (mSendTouchInteractionEndDelayed.isPending() && eventType == TYPE_VIEW_HOVER_EXIT) { mSendTouchInteractionEndDelayed.cancel(); mDispatcher.sendAccessibilityEvent(AccessibilityEvent.TYPE_TOUCH_INTERACTION_END); mDispatcher.sendAccessibilityEvent(TYPE_TOUCH_INTERACTION_END); } super.onAccessibilityEvent(event); } Loading @@ -314,7 +327,7 @@ public class TouchExplorer extends BaseEventStreamTransformation } // Announce the end of a new touch interaction. mDispatcher.sendAccessibilityEvent(AccessibilityEvent.TYPE_TOUCH_INTERACTION_END); mDispatcher.sendAccessibilityEvent(TYPE_TOUCH_INTERACTION_END); mSendTouchInteractionEndDelayed.cancel(); // Try to use the standard accessibility API to click if (!mAms.performActionOnAccessibilityFocusedItem( Loading @@ -334,7 +347,7 @@ public class TouchExplorer extends BaseEventStreamTransformation mExitGestureDetectionModeDelayed.post(); // Send accessibility event to announce the start // of gesture recognition. mDispatcher.sendAccessibilityEvent(AccessibilityEvent.TYPE_GESTURE_DETECTION_START); mDispatcher.sendAccessibilityEvent(TYPE_GESTURE_DETECTION_START); return false; } Loading @@ -350,11 +363,11 @@ public class TouchExplorer extends BaseEventStreamTransformation @Override public boolean onGestureCancelled(MotionEvent event, MotionEvent rawEvent, int policyFlags) { if (mState.isGestureDetecting()) { endGestureDetection(event.getActionMasked() == MotionEvent.ACTION_UP); endGestureDetection(event.getActionMasked() == ACTION_UP); return true; } else if (mState.isTouchExploring()) { // If the finger is still moving, pass the event on. if (event.getActionMasked() == MotionEvent.ACTION_MOVE) { if (event.getActionMasked() == ACTION_MOVE) { final int pointerId = mReceivedPointerTracker.getPrimaryPointerId(); final int pointerIdBits = (1 << pointerId); Loading @@ -365,7 +378,7 @@ public class TouchExplorer extends BaseEventStreamTransformation mSendHoverExitDelayed.cancel(); mDispatcher.sendMotionEvent( event, MotionEvent.ACTION_HOVER_MOVE, ACTION_HOVER_MOVE, mState.getLastReceivedEvent(), pointerIdBits, policyFlags); Loading @@ -382,7 +395,7 @@ public class TouchExplorer extends BaseEventStreamTransformation MotionEvent event, MotionEvent rawEvent, int policyFlags) { switch (event.getActionMasked()) { // The only way to leave the clear state is for a pointer to go down. case MotionEvent.ACTION_DOWN: case ACTION_DOWN: handleActionDown(event, rawEvent, policyFlags); break; default: Loading Loading @@ -423,7 +436,7 @@ public class TouchExplorer extends BaseEventStreamTransformation } mSendTouchExplorationEndDelayed.forceSendAndRemove(); mSendTouchInteractionEndDelayed.forceSendAndRemove(); mDispatcher.sendAccessibilityEvent(AccessibilityEvent.TYPE_TOUCH_INTERACTION_START); mDispatcher.sendAccessibilityEvent(TYPE_TOUCH_INTERACTION_START); if (mTouchExplorationPassthroughRegion.contains( (int) event.getX(), (int) event.getY())) { // The touch exploration passthrough overrides the gesture detection passthrough in Loading Loading @@ -455,18 +468,18 @@ public class TouchExplorer extends BaseEventStreamTransformation private void handleMotionEventStateTouchInteracting( MotionEvent event, MotionEvent rawEvent, int policyFlags) { switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: case ACTION_DOWN: // Continue the previous interaction. mSendTouchInteractionEndDelayed.cancel(); handleActionDown(event, rawEvent, policyFlags); break; case MotionEvent.ACTION_POINTER_DOWN: case ACTION_POINTER_DOWN: handleActionPointerDown(event, rawEvent, policyFlags); break; case MotionEvent.ACTION_MOVE: case ACTION_MOVE: handleActionMoveStateTouchInteracting(event, rawEvent, policyFlags); break; case MotionEvent.ACTION_UP: case ACTION_UP: handleActionUp(event, rawEvent, policyFlags); break; } Loading @@ -482,16 +495,16 @@ public class TouchExplorer extends BaseEventStreamTransformation private void handleMotionEventStateTouchExploring( MotionEvent event, MotionEvent rawEvent, int policyFlags) { switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: case ACTION_DOWN: // We should have already received ACTION_DOWN. Ignore. break; case MotionEvent.ACTION_POINTER_DOWN: case ACTION_POINTER_DOWN: handleActionPointerDown(event, rawEvent, policyFlags); break; case MotionEvent.ACTION_MOVE: case ACTION_MOVE: handleActionMoveStateTouchExploring(event, rawEvent, policyFlags); break; case MotionEvent.ACTION_UP: case ACTION_UP: handleActionUp(event, rawEvent, policyFlags); break; default: Loading Loading @@ -553,7 +566,7 @@ public class TouchExplorer extends BaseEventStreamTransformation mDraggingPointerId = pointerId; event.setEdgeFlags(mReceivedPointerTracker.getLastReceivedDownEdgeFlags()); mDispatcher.sendMotionEvent( event, MotionEvent.ACTION_DOWN, rawEvent, pointerIdBits, policyFlags); event, ACTION_DOWN, rawEvent, pointerIdBits, policyFlags); } else { // Two pointers moving arbitrary are delegated to the view hierarchy. mState.startDelegating(); Loading Loading @@ -606,7 +619,7 @@ public class TouchExplorer extends BaseEventStreamTransformation // Touch exploration. sendTouchExplorationGestureStartAndHoverEnterIfNeeded(policyFlags); mDispatcher.sendMotionEvent( event, MotionEvent.ACTION_HOVER_MOVE, rawEvent, pointerIdBits, policyFlags); event, ACTION_HOVER_MOVE, rawEvent, pointerIdBits, policyFlags); break; case 2: if (mGestureDetector.isMultiFingerGesturesEnabled()) { Loading Loading @@ -671,48 +684,48 @@ public class TouchExplorer extends BaseEventStreamTransformation int pointerIdBits = 0; // Clear the dragging pointer id if it's no longer valid. if (event.findPointerIndex(mDraggingPointerId) == -1) { Slog.e(LOG_TAG, "mDraggingPointerId doesn't match any pointers on current event. " + "mDraggingPointerId: " + Integer.toString(mDraggingPointerId) + ", Event: " + event); Slog.e( LOG_TAG, "mDraggingPointerId doesn't match any pointers on current event. " + "mDraggingPointerId: " + Integer.toString(mDraggingPointerId) + ", Event: " + event); mDraggingPointerId = INVALID_POINTER_ID; } else { pointerIdBits = (1 << mDraggingPointerId); } switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: { Slog.e(LOG_TAG, "Dragging state can be reached only if two " + "pointers are already down"); case ACTION_DOWN: Slog.e( LOG_TAG, "Dragging state can be reached only if two " + "pointers are already down"); clear(event, policyFlags); return; } case MotionEvent.ACTION_POINTER_DOWN: { case ACTION_POINTER_DOWN: // We are in dragging state so we have two pointers and another one // goes down => delegate the three pointers to the view hierarchy mState.startDelegating(); if (mDraggingPointerId != INVALID_POINTER_ID) { mDispatcher.sendMotionEvent( event, MotionEvent.ACTION_UP, rawEvent, pointerIdBits, policyFlags); event, ACTION_UP, rawEvent, pointerIdBits, policyFlags); } mDispatcher.sendDownForAllNotInjectedPointers(event, policyFlags); } break; case MotionEvent.ACTION_MOVE: { break; case ACTION_MOVE: if (mDraggingPointerId == INVALID_POINTER_ID) { break; } switch (event.getPointerCount()) { case 1: { case 1: // do nothing } break; case 2: { break; case 2: if (isDraggingGesture(event)) { // If still dragging send a drag event. adjustEventLocationForDrag(event); mDispatcher.sendMotionEvent( event, MotionEvent.ACTION_MOVE, rawEvent, pointerIdBits, policyFlags); event, ACTION_MOVE, rawEvent, pointerIdBits, policyFlags); } else { // The two pointers are moving either in different directions or // no close enough => delegate the gesture to the view hierarchy. Loading @@ -721,52 +734,40 @@ public class TouchExplorer extends BaseEventStreamTransformation event = MotionEvent.obtainNoHistory(event); // Send an event to the end of the drag gesture. mDispatcher.sendMotionEvent( event, MotionEvent.ACTION_UP, rawEvent, pointerIdBits, policyFlags); event, ACTION_UP, rawEvent, pointerIdBits, policyFlags); // Deliver all pointers to the view hierarchy. mDispatcher.sendDownForAllNotInjectedPointers(event, policyFlags); } } break; default: { break; default: mState.startDelegating(); event = MotionEvent.obtainNoHistory(event); // Send an event to the end of the drag gesture. mDispatcher.sendMotionEvent( event, MotionEvent.ACTION_UP, rawEvent, pointerIdBits, policyFlags); event, ACTION_UP, rawEvent, pointerIdBits, policyFlags); // Deliver all pointers to the view hierarchy. mDispatcher.sendDownForAllNotInjectedPointers(event, policyFlags); } } } break; case MotionEvent.ACTION_POINTER_UP: { final int pointerId = event.getPointerId(event.getActionIndex()); if (pointerId == mDraggingPointerId) { break; case ACTION_POINTER_UP: if (event.getPointerId(GestureUtils.getActionIndex(event)) == mDraggingPointerId) { mDraggingPointerId = INVALID_POINTER_ID; // Send an event to the end of the drag gesture. mDispatcher.sendMotionEvent( event, MotionEvent.ACTION_UP, rawEvent, pointerIdBits, policyFlags); event, ACTION_UP, rawEvent, pointerIdBits, policyFlags); } } break; case MotionEvent.ACTION_UP: { break; case ACTION_UP: mAms.onTouchInteractionEnd(); // Announce the end of a new touch interaction. mDispatcher.sendAccessibilityEvent( AccessibilityEvent.TYPE_TOUCH_INTERACTION_END); final int pointerId = event.getPointerId(event.getActionIndex()); if (pointerId == mDraggingPointerId) { mDispatcher.sendAccessibilityEvent(TYPE_TOUCH_INTERACTION_END); if (event.getPointerId(GestureUtils.getActionIndex(event)) == mDraggingPointerId) { mDraggingPointerId = INVALID_POINTER_ID; // Send an event to the end of the drag gesture. mDispatcher.sendMotionEvent( event, MotionEvent.ACTION_UP, rawEvent, pointerIdBits, policyFlags); event, ACTION_UP, rawEvent, pointerIdBits, policyFlags); } } break; break; } } Loading @@ -783,20 +784,20 @@ public class TouchExplorer extends BaseEventStreamTransformation return; } switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: { case ACTION_DOWN: { Slog.e(LOG_TAG, "Delegating state can only be reached if " + "there is at least one pointer down!"); clear(event, policyFlags); return; } case MotionEvent.ACTION_UP: { case ACTION_UP: { // Deliver the event. mDispatcher.sendMotionEvent( event, event.getAction(), rawEvent, ALL_POINTER_ID_BITS, policyFlags); // Announce the end of a the touch interaction. mAms.onTouchInteractionEnd(); mDispatcher.sendAccessibilityEvent(AccessibilityEvent.TYPE_TOUCH_INTERACTION_END); mDispatcher.sendAccessibilityEvent(TYPE_TOUCH_INTERACTION_END); } break; default: { Loading @@ -811,10 +812,10 @@ public class TouchExplorer extends BaseEventStreamTransformation mAms.onTouchInteractionEnd(); // Announce the end of the gesture recognition. mDispatcher.sendAccessibilityEvent(AccessibilityEvent.TYPE_GESTURE_DETECTION_END); mDispatcher.sendAccessibilityEvent(TYPE_GESTURE_DETECTION_END); // Don't announce the end of a the touch interaction if users didn't lift their fingers. if (interactionEnd) { mDispatcher.sendAccessibilityEvent(AccessibilityEvent.TYPE_TOUCH_INTERACTION_END); mDispatcher.sendAccessibilityEvent(TYPE_TOUCH_INTERACTION_END); } mExitGestureDetectionModeDelayed.cancel(); Loading @@ -829,14 +830,14 @@ public class TouchExplorer extends BaseEventStreamTransformation */ private void sendHoverExitAndTouchExplorationGestureEndIfNeeded(int policyFlags) { MotionEvent event = mDispatcher.getLastInjectedHoverEvent(); if (event != null && event.getActionMasked() != MotionEvent.ACTION_HOVER_EXIT) { if (event != null && event.getActionMasked() != ACTION_HOVER_EXIT) { final int pointerIdBits = event.getPointerIdBits(); if (!mSendTouchExplorationEndDelayed.isPending()) { mSendTouchExplorationEndDelayed.post(); } mDispatcher.sendMotionEvent( event, MotionEvent.ACTION_HOVER_EXIT, ACTION_HOVER_EXIT, mState.getLastReceivedEvent(), pointerIdBits, policyFlags); Loading @@ -851,11 +852,11 @@ public class TouchExplorer extends BaseEventStreamTransformation */ private void sendTouchExplorationGestureStartAndHoverEnterIfNeeded(int policyFlags) { MotionEvent event = mDispatcher.getLastInjectedHoverEvent(); if (event != null && event.getActionMasked() == MotionEvent.ACTION_HOVER_EXIT) { if (event != null && event.getActionMasked() == ACTION_HOVER_EXIT) { final int pointerIdBits = event.getPointerIdBits(); mDispatcher.sendMotionEvent( event, MotionEvent.ACTION_HOVER_ENTER, ACTION_HOVER_ENTER, mState.getLastReceivedEvent(), pointerIdBits, policyFlags); Loading Loading @@ -942,7 +943,7 @@ public class TouchExplorer extends BaseEventStreamTransformation if (mState.isDelegating()) { return false; } if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { if (event.getActionMasked() == ACTION_DOWN) { final int x = (int) event.getX(); final int y = (int) event.getY(); if (mTouchExplorationPassthroughRegion.contains(x, y) Loading @@ -969,7 +970,7 @@ public class TouchExplorer extends BaseEventStreamTransformation @Override public void run() { // Announce the end of gesture recognition. mDispatcher.sendAccessibilityEvent(AccessibilityEvent.TYPE_GESTURE_DETECTION_END); mDispatcher.sendAccessibilityEvent(TYPE_GESTURE_DETECTION_END); clear(); } } Loading Loading @@ -1033,12 +1034,11 @@ public class TouchExplorer extends BaseEventStreamTransformation public void run() { // Send an accessibility event to announce the touch exploration start. mDispatcher.sendAccessibilityEvent( AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_START); mDispatcher.sendAccessibilityEvent(TYPE_TOUCH_EXPLORATION_GESTURE_START); if (!mEvents.isEmpty() && !mRawEvents.isEmpty()) { // Deliver a down event. mDispatcher.sendMotionEvent(mEvents.get(0), MotionEvent.ACTION_HOVER_ENTER, mDispatcher.sendMotionEvent(mEvents.get(0), ACTION_HOVER_ENTER, mRawEvents.get(0), mPointerIdBits, mPolicyFlags); if (DEBUG) { Slog.d(LOG_TAG_SEND_HOVER_DELAYED, Loading @@ -1048,7 +1048,7 @@ public class TouchExplorer extends BaseEventStreamTransformation // Deliver move events. final int eventCount = mEvents.size(); for (int i = 1; i < eventCount; i++) { mDispatcher.sendMotionEvent(mEvents.get(i), MotionEvent.ACTION_HOVER_MOVE, mDispatcher.sendMotionEvent(mEvents.get(i), ACTION_HOVER_MOVE, mRawEvents.get(i), mPointerIdBits, mPolicyFlags); if (DEBUG) { Slog.d(LOG_TAG_SEND_HOVER_DELAYED, Loading Loading @@ -1119,7 +1119,7 @@ public class TouchExplorer extends BaseEventStreamTransformation } mDispatcher.sendMotionEvent( mPrototype, MotionEvent.ACTION_HOVER_EXIT, ACTION_HOVER_EXIT, mRawEvent, mPointerIdBits, mPolicyFlags); Loading Loading
services/accessibility/java/com/android/server/accessibility/gestures/TouchExplorer.java +99 −99 Original line number Diff line number Diff line Loading @@ -16,7 +16,23 @@ package com.android.server.accessibility.gestures; import static android.view.MotionEvent.ACTION_CANCEL; import static android.view.MotionEvent.ACTION_DOWN; import static android.view.MotionEvent.ACTION_HOVER_ENTER; import static android.view.MotionEvent.ACTION_HOVER_EXIT; import static android.view.MotionEvent.ACTION_HOVER_MOVE; import static android.view.MotionEvent.ACTION_MOVE; import static android.view.MotionEvent.ACTION_POINTER_DOWN; import static android.view.MotionEvent.ACTION_POINTER_UP; import static android.view.MotionEvent.ACTION_UP; import static android.view.MotionEvent.INVALID_POINTER_ID; import static android.view.accessibility.AccessibilityEvent.TYPE_GESTURE_DETECTION_END; import static android.view.accessibility.AccessibilityEvent.TYPE_GESTURE_DETECTION_START; import static android.view.accessibility.AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_END; import static android.view.accessibility.AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_START; import static android.view.accessibility.AccessibilityEvent.TYPE_TOUCH_INTERACTION_END; import static android.view.accessibility.AccessibilityEvent.TYPE_TOUCH_INTERACTION_START; import static android.view.accessibility.AccessibilityEvent.TYPE_VIEW_HOVER_EXIT; import static com.android.server.accessibility.gestures.TouchState.ALL_POINTER_ID_BITS; Loading Loading @@ -144,8 +160,8 @@ public class TouchExplorer extends BaseEventStreamTransformation * @param detector The gesture detector to handle accessibility touch event. If null the default * one created in place, or for testing purpose. */ public TouchExplorer(Context context, AccessibilityManagerService service, GestureManifold detector) { public TouchExplorer( Context context, AccessibilityManagerService service, GestureManifold detector) { mContext = context; mAms = service; mState = new TouchState(); Loading @@ -157,12 +173,12 @@ public class TouchExplorer extends BaseEventStreamTransformation mExitGestureDetectionModeDelayed = new ExitGestureDetectionModeDelayed(); mSendHoverEnterAndMoveDelayed = new SendHoverEnterAndMoveDelayed(); mSendHoverExitDelayed = new SendHoverExitDelayed(); mSendTouchExplorationEndDelayed = new SendAccessibilityEventDelayed( AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_END, mDetermineUserIntentTimeout); mSendTouchInteractionEndDelayed = new SendAccessibilityEventDelayed( AccessibilityEvent.TYPE_TOUCH_INTERACTION_END, mDetermineUserIntentTimeout); mSendTouchExplorationEndDelayed = new SendAccessibilityEventDelayed( TYPE_TOUCH_EXPLORATION_GESTURE_END, mDetermineUserIntentTimeout); mSendTouchInteractionEndDelayed = new SendAccessibilityEventDelayed( TYPE_TOUCH_INTERACTION_END, mDetermineUserIntentTimeout); if (detector == null) { mGestureDetector = new GestureManifold(context, this, mState); } else { Loading Loading @@ -242,7 +258,7 @@ public class TouchExplorer extends BaseEventStreamTransformation } } if (event.getActionMasked() == MotionEvent.ACTION_CANCEL) { if (event.getActionMasked() == ACTION_CANCEL) { clear(event, policyFlags); return; } Loading Loading @@ -276,19 +292,16 @@ public class TouchExplorer extends BaseEventStreamTransformation // The event for gesture end should be strictly after the // last hover exit event. if (mSendTouchExplorationEndDelayed.isPending() && eventType == AccessibilityEvent.TYPE_VIEW_HOVER_EXIT) { if (mSendTouchExplorationEndDelayed.isPending() && eventType == TYPE_VIEW_HOVER_EXIT) { mSendTouchExplorationEndDelayed.cancel(); mDispatcher.sendAccessibilityEvent( AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_END); mDispatcher.sendAccessibilityEvent(TYPE_TOUCH_EXPLORATION_GESTURE_END); } // The event for touch interaction end should be strictly after the // last hover exit and the touch exploration gesture end events. if (mSendTouchInteractionEndDelayed.isPending() && eventType == AccessibilityEvent.TYPE_VIEW_HOVER_EXIT) { if (mSendTouchInteractionEndDelayed.isPending() && eventType == TYPE_VIEW_HOVER_EXIT) { mSendTouchInteractionEndDelayed.cancel(); mDispatcher.sendAccessibilityEvent(AccessibilityEvent.TYPE_TOUCH_INTERACTION_END); mDispatcher.sendAccessibilityEvent(TYPE_TOUCH_INTERACTION_END); } super.onAccessibilityEvent(event); } Loading @@ -314,7 +327,7 @@ public class TouchExplorer extends BaseEventStreamTransformation } // Announce the end of a new touch interaction. mDispatcher.sendAccessibilityEvent(AccessibilityEvent.TYPE_TOUCH_INTERACTION_END); mDispatcher.sendAccessibilityEvent(TYPE_TOUCH_INTERACTION_END); mSendTouchInteractionEndDelayed.cancel(); // Try to use the standard accessibility API to click if (!mAms.performActionOnAccessibilityFocusedItem( Loading @@ -334,7 +347,7 @@ public class TouchExplorer extends BaseEventStreamTransformation mExitGestureDetectionModeDelayed.post(); // Send accessibility event to announce the start // of gesture recognition. mDispatcher.sendAccessibilityEvent(AccessibilityEvent.TYPE_GESTURE_DETECTION_START); mDispatcher.sendAccessibilityEvent(TYPE_GESTURE_DETECTION_START); return false; } Loading @@ -350,11 +363,11 @@ public class TouchExplorer extends BaseEventStreamTransformation @Override public boolean onGestureCancelled(MotionEvent event, MotionEvent rawEvent, int policyFlags) { if (mState.isGestureDetecting()) { endGestureDetection(event.getActionMasked() == MotionEvent.ACTION_UP); endGestureDetection(event.getActionMasked() == ACTION_UP); return true; } else if (mState.isTouchExploring()) { // If the finger is still moving, pass the event on. if (event.getActionMasked() == MotionEvent.ACTION_MOVE) { if (event.getActionMasked() == ACTION_MOVE) { final int pointerId = mReceivedPointerTracker.getPrimaryPointerId(); final int pointerIdBits = (1 << pointerId); Loading @@ -365,7 +378,7 @@ public class TouchExplorer extends BaseEventStreamTransformation mSendHoverExitDelayed.cancel(); mDispatcher.sendMotionEvent( event, MotionEvent.ACTION_HOVER_MOVE, ACTION_HOVER_MOVE, mState.getLastReceivedEvent(), pointerIdBits, policyFlags); Loading @@ -382,7 +395,7 @@ public class TouchExplorer extends BaseEventStreamTransformation MotionEvent event, MotionEvent rawEvent, int policyFlags) { switch (event.getActionMasked()) { // The only way to leave the clear state is for a pointer to go down. case MotionEvent.ACTION_DOWN: case ACTION_DOWN: handleActionDown(event, rawEvent, policyFlags); break; default: Loading Loading @@ -423,7 +436,7 @@ public class TouchExplorer extends BaseEventStreamTransformation } mSendTouchExplorationEndDelayed.forceSendAndRemove(); mSendTouchInteractionEndDelayed.forceSendAndRemove(); mDispatcher.sendAccessibilityEvent(AccessibilityEvent.TYPE_TOUCH_INTERACTION_START); mDispatcher.sendAccessibilityEvent(TYPE_TOUCH_INTERACTION_START); if (mTouchExplorationPassthroughRegion.contains( (int) event.getX(), (int) event.getY())) { // The touch exploration passthrough overrides the gesture detection passthrough in Loading Loading @@ -455,18 +468,18 @@ public class TouchExplorer extends BaseEventStreamTransformation private void handleMotionEventStateTouchInteracting( MotionEvent event, MotionEvent rawEvent, int policyFlags) { switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: case ACTION_DOWN: // Continue the previous interaction. mSendTouchInteractionEndDelayed.cancel(); handleActionDown(event, rawEvent, policyFlags); break; case MotionEvent.ACTION_POINTER_DOWN: case ACTION_POINTER_DOWN: handleActionPointerDown(event, rawEvent, policyFlags); break; case MotionEvent.ACTION_MOVE: case ACTION_MOVE: handleActionMoveStateTouchInteracting(event, rawEvent, policyFlags); break; case MotionEvent.ACTION_UP: case ACTION_UP: handleActionUp(event, rawEvent, policyFlags); break; } Loading @@ -482,16 +495,16 @@ public class TouchExplorer extends BaseEventStreamTransformation private void handleMotionEventStateTouchExploring( MotionEvent event, MotionEvent rawEvent, int policyFlags) { switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: case ACTION_DOWN: // We should have already received ACTION_DOWN. Ignore. break; case MotionEvent.ACTION_POINTER_DOWN: case ACTION_POINTER_DOWN: handleActionPointerDown(event, rawEvent, policyFlags); break; case MotionEvent.ACTION_MOVE: case ACTION_MOVE: handleActionMoveStateTouchExploring(event, rawEvent, policyFlags); break; case MotionEvent.ACTION_UP: case ACTION_UP: handleActionUp(event, rawEvent, policyFlags); break; default: Loading Loading @@ -553,7 +566,7 @@ public class TouchExplorer extends BaseEventStreamTransformation mDraggingPointerId = pointerId; event.setEdgeFlags(mReceivedPointerTracker.getLastReceivedDownEdgeFlags()); mDispatcher.sendMotionEvent( event, MotionEvent.ACTION_DOWN, rawEvent, pointerIdBits, policyFlags); event, ACTION_DOWN, rawEvent, pointerIdBits, policyFlags); } else { // Two pointers moving arbitrary are delegated to the view hierarchy. mState.startDelegating(); Loading Loading @@ -606,7 +619,7 @@ public class TouchExplorer extends BaseEventStreamTransformation // Touch exploration. sendTouchExplorationGestureStartAndHoverEnterIfNeeded(policyFlags); mDispatcher.sendMotionEvent( event, MotionEvent.ACTION_HOVER_MOVE, rawEvent, pointerIdBits, policyFlags); event, ACTION_HOVER_MOVE, rawEvent, pointerIdBits, policyFlags); break; case 2: if (mGestureDetector.isMultiFingerGesturesEnabled()) { Loading Loading @@ -671,48 +684,48 @@ public class TouchExplorer extends BaseEventStreamTransformation int pointerIdBits = 0; // Clear the dragging pointer id if it's no longer valid. if (event.findPointerIndex(mDraggingPointerId) == -1) { Slog.e(LOG_TAG, "mDraggingPointerId doesn't match any pointers on current event. " + "mDraggingPointerId: " + Integer.toString(mDraggingPointerId) + ", Event: " + event); Slog.e( LOG_TAG, "mDraggingPointerId doesn't match any pointers on current event. " + "mDraggingPointerId: " + Integer.toString(mDraggingPointerId) + ", Event: " + event); mDraggingPointerId = INVALID_POINTER_ID; } else { pointerIdBits = (1 << mDraggingPointerId); } switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: { Slog.e(LOG_TAG, "Dragging state can be reached only if two " + "pointers are already down"); case ACTION_DOWN: Slog.e( LOG_TAG, "Dragging state can be reached only if two " + "pointers are already down"); clear(event, policyFlags); return; } case MotionEvent.ACTION_POINTER_DOWN: { case ACTION_POINTER_DOWN: // We are in dragging state so we have two pointers and another one // goes down => delegate the three pointers to the view hierarchy mState.startDelegating(); if (mDraggingPointerId != INVALID_POINTER_ID) { mDispatcher.sendMotionEvent( event, MotionEvent.ACTION_UP, rawEvent, pointerIdBits, policyFlags); event, ACTION_UP, rawEvent, pointerIdBits, policyFlags); } mDispatcher.sendDownForAllNotInjectedPointers(event, policyFlags); } break; case MotionEvent.ACTION_MOVE: { break; case ACTION_MOVE: if (mDraggingPointerId == INVALID_POINTER_ID) { break; } switch (event.getPointerCount()) { case 1: { case 1: // do nothing } break; case 2: { break; case 2: if (isDraggingGesture(event)) { // If still dragging send a drag event. adjustEventLocationForDrag(event); mDispatcher.sendMotionEvent( event, MotionEvent.ACTION_MOVE, rawEvent, pointerIdBits, policyFlags); event, ACTION_MOVE, rawEvent, pointerIdBits, policyFlags); } else { // The two pointers are moving either in different directions or // no close enough => delegate the gesture to the view hierarchy. Loading @@ -721,52 +734,40 @@ public class TouchExplorer extends BaseEventStreamTransformation event = MotionEvent.obtainNoHistory(event); // Send an event to the end of the drag gesture. mDispatcher.sendMotionEvent( event, MotionEvent.ACTION_UP, rawEvent, pointerIdBits, policyFlags); event, ACTION_UP, rawEvent, pointerIdBits, policyFlags); // Deliver all pointers to the view hierarchy. mDispatcher.sendDownForAllNotInjectedPointers(event, policyFlags); } } break; default: { break; default: mState.startDelegating(); event = MotionEvent.obtainNoHistory(event); // Send an event to the end of the drag gesture. mDispatcher.sendMotionEvent( event, MotionEvent.ACTION_UP, rawEvent, pointerIdBits, policyFlags); event, ACTION_UP, rawEvent, pointerIdBits, policyFlags); // Deliver all pointers to the view hierarchy. mDispatcher.sendDownForAllNotInjectedPointers(event, policyFlags); } } } break; case MotionEvent.ACTION_POINTER_UP: { final int pointerId = event.getPointerId(event.getActionIndex()); if (pointerId == mDraggingPointerId) { break; case ACTION_POINTER_UP: if (event.getPointerId(GestureUtils.getActionIndex(event)) == mDraggingPointerId) { mDraggingPointerId = INVALID_POINTER_ID; // Send an event to the end of the drag gesture. mDispatcher.sendMotionEvent( event, MotionEvent.ACTION_UP, rawEvent, pointerIdBits, policyFlags); event, ACTION_UP, rawEvent, pointerIdBits, policyFlags); } } break; case MotionEvent.ACTION_UP: { break; case ACTION_UP: mAms.onTouchInteractionEnd(); // Announce the end of a new touch interaction. mDispatcher.sendAccessibilityEvent( AccessibilityEvent.TYPE_TOUCH_INTERACTION_END); final int pointerId = event.getPointerId(event.getActionIndex()); if (pointerId == mDraggingPointerId) { mDispatcher.sendAccessibilityEvent(TYPE_TOUCH_INTERACTION_END); if (event.getPointerId(GestureUtils.getActionIndex(event)) == mDraggingPointerId) { mDraggingPointerId = INVALID_POINTER_ID; // Send an event to the end of the drag gesture. mDispatcher.sendMotionEvent( event, MotionEvent.ACTION_UP, rawEvent, pointerIdBits, policyFlags); event, ACTION_UP, rawEvent, pointerIdBits, policyFlags); } } break; break; } } Loading @@ -783,20 +784,20 @@ public class TouchExplorer extends BaseEventStreamTransformation return; } switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: { case ACTION_DOWN: { Slog.e(LOG_TAG, "Delegating state can only be reached if " + "there is at least one pointer down!"); clear(event, policyFlags); return; } case MotionEvent.ACTION_UP: { case ACTION_UP: { // Deliver the event. mDispatcher.sendMotionEvent( event, event.getAction(), rawEvent, ALL_POINTER_ID_BITS, policyFlags); // Announce the end of a the touch interaction. mAms.onTouchInteractionEnd(); mDispatcher.sendAccessibilityEvent(AccessibilityEvent.TYPE_TOUCH_INTERACTION_END); mDispatcher.sendAccessibilityEvent(TYPE_TOUCH_INTERACTION_END); } break; default: { Loading @@ -811,10 +812,10 @@ public class TouchExplorer extends BaseEventStreamTransformation mAms.onTouchInteractionEnd(); // Announce the end of the gesture recognition. mDispatcher.sendAccessibilityEvent(AccessibilityEvent.TYPE_GESTURE_DETECTION_END); mDispatcher.sendAccessibilityEvent(TYPE_GESTURE_DETECTION_END); // Don't announce the end of a the touch interaction if users didn't lift their fingers. if (interactionEnd) { mDispatcher.sendAccessibilityEvent(AccessibilityEvent.TYPE_TOUCH_INTERACTION_END); mDispatcher.sendAccessibilityEvent(TYPE_TOUCH_INTERACTION_END); } mExitGestureDetectionModeDelayed.cancel(); Loading @@ -829,14 +830,14 @@ public class TouchExplorer extends BaseEventStreamTransformation */ private void sendHoverExitAndTouchExplorationGestureEndIfNeeded(int policyFlags) { MotionEvent event = mDispatcher.getLastInjectedHoverEvent(); if (event != null && event.getActionMasked() != MotionEvent.ACTION_HOVER_EXIT) { if (event != null && event.getActionMasked() != ACTION_HOVER_EXIT) { final int pointerIdBits = event.getPointerIdBits(); if (!mSendTouchExplorationEndDelayed.isPending()) { mSendTouchExplorationEndDelayed.post(); } mDispatcher.sendMotionEvent( event, MotionEvent.ACTION_HOVER_EXIT, ACTION_HOVER_EXIT, mState.getLastReceivedEvent(), pointerIdBits, policyFlags); Loading @@ -851,11 +852,11 @@ public class TouchExplorer extends BaseEventStreamTransformation */ private void sendTouchExplorationGestureStartAndHoverEnterIfNeeded(int policyFlags) { MotionEvent event = mDispatcher.getLastInjectedHoverEvent(); if (event != null && event.getActionMasked() == MotionEvent.ACTION_HOVER_EXIT) { if (event != null && event.getActionMasked() == ACTION_HOVER_EXIT) { final int pointerIdBits = event.getPointerIdBits(); mDispatcher.sendMotionEvent( event, MotionEvent.ACTION_HOVER_ENTER, ACTION_HOVER_ENTER, mState.getLastReceivedEvent(), pointerIdBits, policyFlags); Loading Loading @@ -942,7 +943,7 @@ public class TouchExplorer extends BaseEventStreamTransformation if (mState.isDelegating()) { return false; } if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { if (event.getActionMasked() == ACTION_DOWN) { final int x = (int) event.getX(); final int y = (int) event.getY(); if (mTouchExplorationPassthroughRegion.contains(x, y) Loading @@ -969,7 +970,7 @@ public class TouchExplorer extends BaseEventStreamTransformation @Override public void run() { // Announce the end of gesture recognition. mDispatcher.sendAccessibilityEvent(AccessibilityEvent.TYPE_GESTURE_DETECTION_END); mDispatcher.sendAccessibilityEvent(TYPE_GESTURE_DETECTION_END); clear(); } } Loading Loading @@ -1033,12 +1034,11 @@ public class TouchExplorer extends BaseEventStreamTransformation public void run() { // Send an accessibility event to announce the touch exploration start. mDispatcher.sendAccessibilityEvent( AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_START); mDispatcher.sendAccessibilityEvent(TYPE_TOUCH_EXPLORATION_GESTURE_START); if (!mEvents.isEmpty() && !mRawEvents.isEmpty()) { // Deliver a down event. mDispatcher.sendMotionEvent(mEvents.get(0), MotionEvent.ACTION_HOVER_ENTER, mDispatcher.sendMotionEvent(mEvents.get(0), ACTION_HOVER_ENTER, mRawEvents.get(0), mPointerIdBits, mPolicyFlags); if (DEBUG) { Slog.d(LOG_TAG_SEND_HOVER_DELAYED, Loading @@ -1048,7 +1048,7 @@ public class TouchExplorer extends BaseEventStreamTransformation // Deliver move events. final int eventCount = mEvents.size(); for (int i = 1; i < eventCount; i++) { mDispatcher.sendMotionEvent(mEvents.get(i), MotionEvent.ACTION_HOVER_MOVE, mDispatcher.sendMotionEvent(mEvents.get(i), ACTION_HOVER_MOVE, mRawEvents.get(i), mPointerIdBits, mPolicyFlags); if (DEBUG) { Slog.d(LOG_TAG_SEND_HOVER_DELAYED, Loading Loading @@ -1119,7 +1119,7 @@ public class TouchExplorer extends BaseEventStreamTransformation } mDispatcher.sendMotionEvent( mPrototype, MotionEvent.ACTION_HOVER_EXIT, ACTION_HOVER_EXIT, mRawEvent, mPointerIdBits, mPolicyFlags); Loading