From b7507a999723d0ccfecf16038ecebca1c40e0bf0 Mon Sep 17 00:00:00 2001 From: mincheli Date: Wed, 24 Apr 2019 18:10:28 +0800 Subject: [PATCH] Adjust event location when two-finger dragging in TouchExplorer To scroll on the screen when using TalkBack, a user need to dragging two finger pointers. If the dragging pointer are closer that a given distance we use the location of the primary one. Otherwise, we should adjust the event location to take the middle between the two finger pointers. Bug: 126354276 Test: atest TouchExplorerTest Change-Id: I9e95ccec964d7930498febdd02731b94826fbb7b --- .../android/server/accessibility/TouchExplorer.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/services/accessibility/java/com/android/server/accessibility/TouchExplorer.java b/services/accessibility/java/com/android/server/accessibility/TouchExplorer.java index 1e3f20ecd01a1..294cc5aad132c 100644 --- a/services/accessibility/java/com/android/server/accessibility/TouchExplorer.java +++ b/services/accessibility/java/com/android/server/accessibility/TouchExplorer.java @@ -703,12 +703,17 @@ private void handleMotionEventStateDragging(MotionEvent event, int policyFlags) final float secondPtrX = event.getX(1); final float secondPtrY = event.getY(1); - final float deltaX = firstPtrX - secondPtrX; - final float deltaY = firstPtrY - secondPtrY; + final int pointerIndex = event.findPointerIndex(mDraggingPointerId); + final float deltaX = + (pointerIndex == 0) ? (secondPtrX - firstPtrX) + : (firstPtrX - secondPtrX); + final float deltaY = + (pointerIndex == 0) ? (secondPtrY - firstPtrY) + : (firstPtrY - secondPtrY); final double distance = Math.hypot(deltaX, deltaY); if (distance > mScaledMinPointerDistanceToUseMiddleLocation) { - event.setLocation(deltaX / 2, deltaY / 2); + event.offsetLocation(deltaX / 2, deltaY / 2); } // If still dragging send a drag event.