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

Commit 069ff163 authored by mincheli's avatar mincheli Committed by Minche Li
Browse files

Always adjust event location to the middle of two fingers when two-finger dragging in TouchExplorer

No need to check the min distsance, always adjust the event location.
Remove mScaledMinPointerDistanceToUseMiddleLocation and
MIN_POINTER_DISTANCE_TO_USE_MIDDLE_LOCATION_DIP.

Bug: 134124639
Test: atest TouchExplorerTest
Change-Id: I8be1d665e307d0191aecef3f6f16d825514ce628
parent 5e192393
Loading
Loading
Loading
Loading
+2 −20
Original line number Diff line number Diff line
@@ -75,10 +75,6 @@ class TouchExplorer extends BaseEventStreamTransformation
    // pointers so they can be considered moving in the same direction.
    private static final float MAX_DRAGGING_ANGLE_COS = 0.525321989f; // cos(pi/4)

    // The minimal distance before we take the middle of the distance between
    // the two dragging pointers as opposed to use the location of the primary one.
    private static final int MIN_POINTER_DISTANCE_TO_USE_MIDDLE_LOCATION_DIP = 200;

    // The timeout after which we are no longer trying to detect a gesture.
    private static final int EXIT_GESTURE_DETECTION_TIMEOUT = 2000;

@@ -115,10 +111,6 @@ class TouchExplorer extends BaseEventStreamTransformation
    // Helper to detect gestures.
    private final AccessibilityGestureDetector mGestureDetector;

    // The scaled minimal distance before we take the middle of the distance between
    // the two dragging pointers as opposed to use the location of the primary one.
    private final int mScaledMinPointerDistanceToUseMiddleLocation;

    // Helper class to track received pointers.
    private final TouchState.ReceivedPointerTracker mReceivedPointerTracker;

@@ -188,9 +180,6 @@ class TouchExplorer extends BaseEventStreamTransformation
        } else {
            mGestureDetector = detector;
        }
        final float density = context.getResources().getDisplayMetrics().density;
        mScaledMinPointerDistanceToUseMiddleLocation =
            (int) (MIN_POINTER_DISTANCE_TO_USE_MIDDLE_LOCATION_DIP * density);
    }

    @Override
@@ -610,11 +599,11 @@ class TouchExplorer extends BaseEventStreamTransformation
                    } break;
                    case 2: {
                        if (isDraggingGesture(event)) {
                            // Adjust event location to the middle location of the two pointers.
                            final float firstPtrX = event.getX(0);
                            final float firstPtrY = event.getY(0);
                            final float secondPtrX = event.getX(1);
                            final float secondPtrY = event.getY(1);

                            final int pointerIndex = event.findPointerIndex(mDraggingPointerId);
                            final float deltaX =
                                    (pointerIndex == 0) ? (secondPtrX - firstPtrX)
@@ -622,12 +611,7 @@ class TouchExplorer extends BaseEventStreamTransformation
                            final float deltaY =
                                    (pointerIndex == 0) ? (secondPtrY - firstPtrY)
                                            : (firstPtrY - secondPtrY);
                            final double distance = Math.hypot(deltaX, deltaY);

                            if (distance > mScaledMinPointerDistanceToUseMiddleLocation) {
                            event.offsetLocation(deltaX / 2, deltaY / 2);
                            }

                            // If still dragging send a drag event.
                            sendMotionEvent(event, MotionEvent.ACTION_MOVE, pointerIdBits,
                                    policyFlags);
@@ -1181,8 +1165,6 @@ class TouchExplorer extends BaseEventStreamTransformation
                + ", mLongPressingPointerId: " + mLongPressingPointerId
                + ", mLongPressingPointerDeltaX: " + mLongPressingPointerDeltaX
                + ", mLongPressingPointerDeltaY: " + mLongPressingPointerDeltaY
                + ", mScaledMinPointerDistanceToUseMiddleLocation: "
                + mScaledMinPointerDistanceToUseMiddleLocation
                + ", mTempPoint: " + mTempPoint
                + " }";
    }