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

Commit 440751b8 authored by Omar Abdelmonem's avatar Omar Abdelmonem Committed by Android (Google) Code Review
Browse files

Merge "Fix pinch gesture dragging TouchpadDebugView" into main

parents dc52779e 49d44909
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -180,7 +180,8 @@ public class TouchpadDebugView extends LinearLayout {

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getClassification() == MotionEvent.CLASSIFICATION_TWO_FINGER_SWIPE) {
        if (event.getClassification() == MotionEvent.CLASSIFICATION_TWO_FINGER_SWIPE
                || event.getClassification() == MotionEvent.CLASSIFICATION_PINCH) {
            return false;
        }

+70 −1
Original line number Diff line number Diff line
@@ -402,4 +402,73 @@ public class TouchpadDebugViewTest {
        // Verify that no updateViewLayout is called (as expected for a two-finger drag gesture).
        verify(mWindowManager, times(0)).updateViewLayout(any(), any());
    }

    @Test
    public void testPinchDrag() {
        float offsetY = ViewConfiguration.get(mTestableContext).getScaledTouchSlop() + 10;

        MotionEvent actionDown = new MotionEventBuilder(MotionEvent.ACTION_DOWN, SOURCE_MOUSE)
                .pointer(new PointerBuilder(0, MotionEvent.TOOL_TYPE_FINGER)
                        .x(40f)
                        .y(40f)
                )
                .classification(MotionEvent.CLASSIFICATION_PINCH)
                .build();
        mTouchpadDebugView.dispatchTouchEvent(actionDown);

        MotionEvent pointerDown = new MotionEventBuilder(MotionEvent.ACTION_POINTER_DOWN,
                SOURCE_MOUSE)
                .pointer(new PointerBuilder(0, MotionEvent.TOOL_TYPE_FINGER)
                        .x(40f)
                        .y(40f)
                )
                .pointer(new PointerBuilder(1, MotionEvent.TOOL_TYPE_FINGER)
                        .x(40f)
                        .y(45f)
                )
                .classification(MotionEvent.CLASSIFICATION_PINCH)
                .build();
        mTouchpadDebugView.dispatchTouchEvent(pointerDown);

        // Simulate ACTION_MOVE event (both fingers moving apart).
        MotionEvent actionMove = new MotionEventBuilder(MotionEvent.ACTION_MOVE, SOURCE_MOUSE)
                .pointer(new PointerBuilder(0, MotionEvent.TOOL_TYPE_FINGER)
                        .x(40f)
                        .y(40f - offsetY)
                )
                .rawXCursorPosition(mWindowLayoutParams.x + 10f)
                .rawYCursorPosition(mWindowLayoutParams.y + 10f)
                .pointer(new PointerBuilder(1, MotionEvent.TOOL_TYPE_FINGER)
                        .x(40f)
                        .y(45f + offsetY)
                )
                .classification(MotionEvent.CLASSIFICATION_PINCH)
                .build();
        mTouchpadDebugView.dispatchTouchEvent(actionMove);

        MotionEvent pointerUp = new MotionEventBuilder(MotionEvent.ACTION_POINTER_UP, SOURCE_MOUSE)
                .pointer(new PointerBuilder(0, MotionEvent.TOOL_TYPE_FINGER)
                        .x(40f)
                        .y(40f - offsetY)
                )
                .pointer(new PointerBuilder(1, MotionEvent.TOOL_TYPE_FINGER)
                        .x(40f)
                        .y(45f + offsetY)
                )
                .classification(MotionEvent.CLASSIFICATION_PINCH)
                .build();
        mTouchpadDebugView.dispatchTouchEvent(pointerUp);

        MotionEvent actionUp = new MotionEventBuilder(MotionEvent.ACTION_UP, SOURCE_MOUSE)
                .pointer(new PointerBuilder(0, MotionEvent.TOOL_TYPE_FINGER)
                        .x(40f)
                        .y(40f - offsetY)
                )
                .classification(MotionEvent.CLASSIFICATION_PINCH)
                .build();
        mTouchpadDebugView.dispatchTouchEvent(actionUp);

        // Verify that no updateViewLayout is called (as expected for a two-finger drag gesture).
        verify(mWindowManager, times(0)).updateViewLayout(any(), any());
    }
}