diff options
author | Ameer Armaly <aarmaly@google.com> | 2020-08-18 13:49:44 -0700 |
---|---|---|
committer | Ameer Armaly <aarmaly@google.com> | 2020-10-11 08:04:42 -0700 |
commit | aa25d2041fd1e53058f8a6342172231de3822f79 (patch) | |
tree | 296e84133fd7d80aedde4b5a05a7f7948cd15f11 /services/accessibility | |
parent | 1f49d41a6a637f04e29a843bdef27709eb49557d (diff) |
[DO NOT MERGE] Start dragging where the fingers initially went down.
This does not apply when transitioning from touch exploration to dragging.
Bug: 162521649
Test: manual
Change-Id: I92022ca0359040a6563e6a48c110face574dc9df
Diffstat (limited to 'services/accessibility')
-rw-r--r-- | services/accessibility/java/com/android/server/accessibility/gestures/TouchExplorer.java | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/services/accessibility/java/com/android/server/accessibility/gestures/TouchExplorer.java b/services/accessibility/java/com/android/server/accessibility/gestures/TouchExplorer.java index b5417cc1504d..90806969816e 100644 --- a/services/accessibility/java/com/android/server/accessibility/gestures/TouchExplorer.java +++ b/services/accessibility/java/com/android/server/accessibility/gestures/TouchExplorer.java @@ -608,12 +608,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()); - mDispatcher.sendMotionEvent( - event, MotionEvent.ACTION_DOWN, rawEvent, pointerIdBits, policyFlags); + MotionEvent downEvent = computeDownEventForDrag(event); + if (downEvent != null) { + mDispatcher.sendMotionEvent(downEvent, MotionEvent.ACTION_DOWN, rawEvent, + pointerIdBits, policyFlags); + mDispatcher.sendMotionEvent(event, MotionEvent.ACTION_MOVE, rawEvent, + pointerIdBits, policyFlags); + } else { + mDispatcher.sendMotionEvent(event, MotionEvent.ACTION_DOWN, rawEvent, + pointerIdBits, policyFlags); + } + mState.startDragging(); } else { // Two pointers moving arbitrary are delegated to the view hierarchy. mState.startDelegating(); @@ -987,6 +995,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, + MotionEvent.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; } |