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

Commit 934e919a authored by Ameer Armaly's avatar Ameer Armaly Committed by Android (Google) Code Review
Browse files

Merge "Start dragging where the fingers initially went down."

parents 08aaab16 d3e6dd17
Loading
Loading
Loading
Loading
+54 −3
Original line number Diff line number Diff line
@@ -612,12 +612,20 @@ public class TouchExplorer extends BaseEventStreamTransformation
                if (isDraggingGesture(event)) {
                    // Two pointers moving in the same direction within
                    // a given distance perform a drag.
                    mState.startDragging();
                    computeDraggingPointerIdIfNeeded(event);
                    pointerIdBits = 1 << mDraggingPointerId;
                    event.setEdgeFlags(mReceivedPointerTracker.getLastReceivedDownEdgeFlags());
                    MotionEvent downEvent = computeDownEventForDrag(event);
                    if (downEvent != null) {
                        mDispatcher.sendMotionEvent(
                                downEvent, ACTION_DOWN, rawEvent, pointerIdBits, policyFlags);
                        mDispatcher.sendMotionEvent(
                                event, ACTION_MOVE, rawEvent, pointerIdBits, policyFlags);
                    } else {
                        mDispatcher.sendMotionEvent(
                                event, ACTION_DOWN, rawEvent, pointerIdBits, policyFlags);
                    }
                    mState.startDragging();
                } else {
                    // Two pointers moving arbitrary are delegated to the view hierarchy.
                    mState.startDelegating();
@@ -1004,6 +1012,49 @@ public class TouchExplorer extends BaseEventStreamTransformation
        return distance;
    }

    /**
     * Creates a down event using the down coordinates of the dragging pointer and other information
     * from the supplied event. The supplied event's down time is adjusted to reflect the time when
     * the dragging pointer initially went down.
     */
    private MotionEvent computeDownEventForDrag(MotionEvent event) {
        // Creating a down event only  makes sense if we haven't started touch exploring yet.
        if (mState.isTouchExploring()
                || mDraggingPointerId == INVALID_POINTER_ID
                || event == null) {
            return null;
        }
        final float x = mReceivedPointerTracker.getReceivedPointerDownX(mDraggingPointerId);
        final float y = mReceivedPointerTracker.getReceivedPointerDownY(mDraggingPointerId);
        final long time = mReceivedPointerTracker.getReceivedPointerDownTime(mDraggingPointerId);
        MotionEvent.PointerCoords[] coords = new MotionEvent.PointerCoords[1];
        coords[0] = new MotionEvent.PointerCoords();
        coords[0].x = x;
        coords[0].y = y;
        MotionEvent.PointerProperties[] properties = new MotionEvent.PointerProperties[1];
        properties[0] = new MotionEvent.PointerProperties();
        properties[0].id = mDraggingPointerId;
        properties[0].toolType = MotionEvent.TOOL_TYPE_FINGER;
        MotionEvent downEvent =
                MotionEvent.obtain(
                        time,
                        time,
                        ACTION_DOWN,
                        1,
                        properties,
                        coords,
                        event.getMetaState(),
                        event.getButtonState(),
                        event.getXPrecision(),
                        event.getYPrecision(),
                        event.getDeviceId(),
                        event.getEdgeFlags(),
                        event.getSource(),
                        event.getFlags());
        event.setDownTime(time);
        return downEvent;
    }

    public TouchState getState() {
        return mState;
    }
+3 −2
Original line number Diff line number Diff line
@@ -187,7 +187,7 @@ public class TouchExplorerTest {
        moveEachPointers(mLastEvent, p(10, 10), p(10, 10));
        send(mLastEvent);
        goToStateClearFrom(STATE_DRAGGING_2FINGERS);
        assertCapturedEvents(ACTION_DOWN, ACTION_MOVE, ACTION_MOVE, ACTION_UP);
        assertCapturedEvents(ACTION_DOWN, ACTION_MOVE, ACTION_MOVE, ACTION_MOVE, ACTION_UP);
    }

    @Test
@@ -288,7 +288,7 @@ public class TouchExplorerTest {
        assertState(STATE_DRAGGING);
        goToStateClearFrom(STATE_DRAGGING_2FINGERS);
        assertState(STATE_CLEAR);
        assertCapturedEvents(ACTION_DOWN, ACTION_UP);
        assertCapturedEvents(ACTION_DOWN, ACTION_MOVE, ACTION_UP);
        assertCapturedEventsNoHistory();
    }

@@ -301,6 +301,7 @@ public class TouchExplorerTest {
        assertState(STATE_CLEAR);
        assertCapturedEvents(
                /* goto dragging state */ ACTION_DOWN,
                ACTION_MOVE,
                /* leave dragging state */ ACTION_UP,
                ACTION_DOWN,
                ACTION_POINTER_DOWN,