Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0a142b5c authored by Ameer Armaly's avatar Ameer Armaly
Browse files

Break up TouchExplorer.handleMotionEventStateTouchExploring for better readability.

Test: atest CtsAccessibilityServiceTestCases
Change-Id: I3d85918b53601af617f137300526d4fd47fe0571
parent 277082c2
Loading
Loading
Loading
Loading
+162 −138
Original line number Diff line number Diff line
@@ -409,10 +409,29 @@ class TouchExplorer extends BaseEventStreamTransformation
     * @param rawEvent The raw (unmodified) motion event.
     * @param policyFlags The policy flags associated with the event.
     */
    private void handleMotionEventStateTouchExploring(MotionEvent event, MotionEvent rawEvent,
            int policyFlags) {
    private void handleMotionEventStateTouchExploring(
            MotionEvent event, MotionEvent rawEvent, int policyFlags) {
        switch (event.getActionMasked()) {
            case MotionEvent.ACTION_DOWN: {
            case MotionEvent.ACTION_DOWN:
                handleActionDownStateTouchExploring(event, policyFlags);
                break;
            case MotionEvent.ACTION_POINTER_DOWN:
                handleActionPointerDownStateTouchExploring();
                break;
            case MotionEvent.ACTION_MOVE:
                handleActionMoveStateTouchExploring(event, rawEvent, policyFlags);
                break;
            case MotionEvent.ACTION_UP:
                handleActionUpStateTouchExploring(event, policyFlags);
                break;
        }
    }

    /**
     * Handles ACTION_DOWN while in the default touch exploring state. This event represents the
     * first finger touching the screen.
     */
    private void handleActionDownStateTouchExploring(MotionEvent event, int policyFlags) {
        mAms.onTouchInteractionStart();

        // If we still have not notified the user for the last
@@ -426,7 +445,8 @@ class TouchExplorer extends BaseEventStreamTransformation
            sendHoverExitAndTouchExplorationGestureEndIfNeeded(policyFlags);
        }

                // Avoid duplicated TYPE_TOUCH_INTERACTION_START event when 2nd tap of double tap.
        // Avoid duplicated TYPE_TOUCH_INTERACTION_START event when 2nd tap of double
        // tap.
        if (!mGestureDetector.firstTapDetected()) {
            mSendTouchExplorationEndDelayed.forceSendAndRemove();
            mSendTouchInteractionEndDelayed.forceSendAndRemove();
@@ -436,48 +456,54 @@ class TouchExplorer extends BaseEventStreamTransformation
            mSendTouchInteractionEndDelayed.cancel();
        }

                if (!mGestureDetector.firstTapDetected()
                        && !mState.isTouchExplorationInProgress()) {
        if (!mGestureDetector.firstTapDetected() && !mState.isTouchExplorationInProgress()) {
            if (!mSendHoverEnterAndMoveDelayed.isPending()) {
                // Deliver hover enter with a delay to have a chance
                // to detect what the user is trying to do.
                final int pointerId = mReceivedPointerTracker.getPrimaryPointerId();
                final int pointerIdBits = (1 << pointerId);
                        mSendHoverEnterAndMoveDelayed.post(event, true, pointerIdBits,
                                policyFlags);
                mSendHoverEnterAndMoveDelayed.post(event, true, pointerIdBits, policyFlags);
            } else {
                // Cache the event until we discern exploration from gesturing.
                mSendHoverEnterAndMoveDelayed.addEvent(event);
            }
        }
            } break;
            case MotionEvent.ACTION_POINTER_DOWN: {
    }

    /**
     * Handles ACTION_POINTER_DOWN when in the touch exploring state. This event represents an
     * additional finger touching the screen.
     */
    private void handleActionPointerDownStateTouchExploring() {
        // Another finger down means that if we have not started to deliver
        // hover events, we will not have to. The code for ACTION_MOVE will
        // decide what we will actually do next.
        mSendHoverEnterAndMoveDelayed.cancel();
        mSendHoverExitDelayed.cancel();
            } break;
            case MotionEvent.ACTION_MOVE: {
    }
    /**
     * Handles ACTION_MOVE while in the initial touch exploring state. This is where transitions to
     * delegating and dragging states are handled.
     */
    private void handleActionMoveStateTouchExploring(
            MotionEvent event, MotionEvent rawEvent, int policyFlags) {
        final int pointerId = mReceivedPointerTracker.getPrimaryPointerId();
        final int pointerIndex = event.findPointerIndex(pointerId);
        final int pointerIdBits = (1 << pointerId);
        switch (event.getPointerCount()) {
                    case 1: {
            case 1:
                // We have not started sending events since we try to
                // figure out what the user is doing.
                if (mSendHoverEnterAndMoveDelayed.isPending()) {
                    // Cache the event until we discern exploration from gesturing.
                    mSendHoverEnterAndMoveDelayed.addEvent(event);
                        } else {
                            if (mState.isTouchExplorationInProgress()) {
                } else if (mState.isTouchExplorationInProgress()) {
                    sendTouchExplorationGestureStartAndHoverEnterIfNeeded(policyFlags);
                                sendMotionEvent(event, MotionEvent.ACTION_HOVER_MOVE, pointerIdBits,
                                        policyFlags);
                    sendMotionEvent(
                            event, MotionEvent.ACTION_HOVER_MOVE, pointerIdBits, policyFlags);
                }
                        }
                    } break;
                    case 2: {
                break;
            case 2:
                // More than one pointer so the user is not touch exploring
                // and now we have to decide whether to delegate or drag.
                if (mSendHoverEnterAndMoveDelayed.isPending()) {
@@ -485,8 +511,7 @@ class TouchExplorer extends BaseEventStreamTransformation
                    // scheduled sending events.
                    mSendHoverEnterAndMoveDelayed.cancel();
                    mSendHoverExitDelayed.cancel();
                        } else {
                            if (mState.isTouchExplorationInProgress()) {
                } else if (mState.isTouchExplorationInProgress()) {
                    // If the user is touch exploring the second pointer may be
                    // performing a double tap to activate an item without need
                    // for the user to lift his exploring finger.
@@ -496,8 +521,8 @@ class TouchExplorer extends BaseEventStreamTransformation
                            mReceivedPointerTracker.getReceivedPointerDownX(pointerId)
                                    - rawEvent.getX(pointerIndex);
                    final float deltaY =
                                        mReceivedPointerTracker.getReceivedPointerDownY(
                                        pointerId) - rawEvent.getY(pointerIndex);
                            mReceivedPointerTracker.getReceivedPointerDownY(pointerId)
                                    - rawEvent.getY(pointerIndex);
                    final double moveDelta = Math.hypot(deltaX, deltaY);
                    if (moveDelta < mDoubleTapSlop) {
                        break;
@@ -506,7 +531,6 @@ class TouchExplorer extends BaseEventStreamTransformation
                    // end since we transition to another state.
                    sendHoverExitAndTouchExplorationGestureEndIfNeeded(policyFlags);
                }
                        }

                // Remove move history before send injected non-move events
                event = MotionEvent.obtainNoHistory(event);
@@ -515,17 +539,15 @@ class TouchExplorer extends BaseEventStreamTransformation
                    // a given distance perform a drag.
                    mState.startDragging();
                    mDraggingPointerId = pointerId;
                            event.setEdgeFlags(
                                    mReceivedPointerTracker.getLastReceivedDownEdgeFlags());
                            sendMotionEvent(event, MotionEvent.ACTION_DOWN, pointerIdBits,
                                    policyFlags);
                    event.setEdgeFlags(mReceivedPointerTracker.getLastReceivedDownEdgeFlags());
                    sendMotionEvent(event, MotionEvent.ACTION_DOWN, pointerIdBits, policyFlags);
                } else {
                    // Two pointers moving arbitrary are delegated to the view hierarchy.
                    mState.startDelegating();
                    sendDownForAllNotInjectedPointers(event, policyFlags);
                }
                    } break;
                    default: {
                break;
            default:
                // More than one pointer so the user is not touch exploring
                // and now we have to decide whether to delegate or drag.
                if (mSendHoverEnterAndMoveDelayed.isPending()) {
@@ -543,10 +565,15 @@ class TouchExplorer extends BaseEventStreamTransformation
                mState.startDelegating();
                event = MotionEvent.obtainNoHistory(event);
                sendDownForAllNotInjectedPointers(event, policyFlags);
                break;
        }
    }
            } break;
            case MotionEvent.ACTION_UP: {

    /**
     * Handles ACTION_UP while in the initial touch exploring state. This event represents all
     * fingers being lifted from the screen.
     */
    private void handleActionUpStateTouchExploring(MotionEvent event, int policyFlags) {
        mAms.onTouchInteractionEnd();
        final int pointerId = event.getPointerId(event.getActionIndex());
        final int pointerIdBits = (1 << pointerId);
@@ -562,9 +589,6 @@ class TouchExplorer extends BaseEventStreamTransformation
        if (!mSendTouchInteractionEndDelayed.isPending()) {
            mSendTouchInteractionEndDelayed.post();
        }

            } break;
        }
    }

    /**