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

Commit 49d44909 authored by Omar Abdelmonem's avatar Omar Abdelmonem
Browse files

Fix pinch gesture dragging TouchpadDebugView

Bug: 369355763
Test: Unit testing to verify that the window doesn't move when
      it receives a pinch gesture while the cursor is on the view.
Flag: com.android.hardware.input.touchpad_visualizer
Change-Id: I46936fc9c76f70cf3e75a75700289936238ac967
parent 84452cde
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());
    }
}