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

Commit 57b654fc authored by Prabir Pradhan's avatar Prabir Pradhan Committed by Automerger Merge Worker
Browse files

Merge "Use SOURCE_CLASS_POINTER as the default source for MotionEvent" into...

Merge "Use SOURCE_CLASS_POINTER as the default source for MotionEvent" into sc-v2-dev am: 72e278d9 am: 0e229b7f

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16432384

Change-Id: I8a3495d162b6957263febbc291265e9bd37fa0e5
parents 19ad73cf 0e229b7f
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -1872,7 +1872,7 @@ public final class MotionEvent extends InputEvent implements Parcelable {
            float x, float y, float pressure, float size, int metaState,
            float x, float y, float pressure, float size, int metaState,
            float xPrecision, float yPrecision, int deviceId, int edgeFlags) {
            float xPrecision, float yPrecision, int deviceId, int edgeFlags) {
        return obtain(downTime, eventTime, action, x, y, pressure, size, metaState,
        return obtain(downTime, eventTime, action, x, y, pressure, size, metaState,
                xPrecision, yPrecision, deviceId, edgeFlags, InputDevice.SOURCE_UNKNOWN,
                xPrecision, yPrecision, deviceId, edgeFlags, InputDevice.SOURCE_CLASS_POINTER,
                DEFAULT_DISPLAY);
                DEFAULT_DISPLAY);
    }
    }


+24 −0
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package android.view;
package android.view;


import static android.view.InputDevice.SOURCE_CLASS_POINTER;
import static android.view.MotionEvent.ACTION_DOWN;
import static android.view.MotionEvent.ACTION_DOWN;
import static android.view.MotionEvent.ACTION_POINTER_DOWN;
import static android.view.MotionEvent.ACTION_POINTER_DOWN;
import static android.view.MotionEvent.TOOL_TYPE_FINGER;
import static android.view.MotionEvent.TOOL_TYPE_FINGER;
@@ -214,4 +215,27 @@ public class MotionEventTest {
        rotInvalid.transform(mat);
        rotInvalid.transform(mat);
        assertEquals(-1, rotInvalid.getSurfaceRotation());
        assertEquals(-1, rotInvalid.getSurfaceRotation());
    }
    }

    @Test
    public void testUsesPointerSourceByDefault() {
        final MotionEvent event = MotionEvent.obtain(0 /* downTime */, 0 /* eventTime */,
                ACTION_DOWN, 0 /* x */, 0 /* y */, 0 /* metaState */);
        assertTrue(event.isFromSource(SOURCE_CLASS_POINTER));
    }

    @Test
    public void testLocationOffsetOnlyAppliedToNonPointerSources() {
        final MotionEvent event = MotionEvent.obtain(0 /* downTime */, 0 /* eventTime */,
                ACTION_DOWN, 10 /* x */, 20 /* y */, 0 /* metaState */);
        event.offsetLocation(40, 50);

        // The offset should be applied since a pointer source is used by default.
        assertEquals(50, (int) event.getX());
        assertEquals(70, (int) event.getY());

        // The offset should not be applied if the source is changed to a non-pointer source.
        event.setSource(InputDevice.SOURCE_JOYSTICK);
        assertEquals(10, (int) event.getX());
        assertEquals(20, (int) event.getY());
    }
}
}