Search in sources :

Example 46 with PointerProperties

use of android.view.MotionEvent.PointerProperties in project robolectric by robolectric.

the class MotionEventTest method testObtainFromPropertyArrays.

@Test
public void testObtainFromPropertyArrays() {
    PointerCoords coords0 = PointerCoordsBuilder.newBuilder().setCoords(X_3F, Y_4F).setPressure(PRESSURE_1F).setSize(SIZE_1F).setTool(1.2f, 1.4f).build();
    PointerCoords coords1 = PointerCoordsBuilder.newBuilder().setCoords(X_3F + 1.0f, Y_4F - 2.0f).setPressure(PRESSURE_1F + 0.2f).setSize(SIZE_1F + 0.5f).setTouch(2.2f, 0.6f).build();
    PointerProperties properties0 = PointerPropertiesBuilder.newBuilder().setId(0).setToolType(MotionEvent.TOOL_TYPE_FINGER).build();
    PointerProperties properties1 = PointerPropertiesBuilder.newBuilder().setId(1).setToolType(MotionEvent.TOOL_TYPE_FINGER).build();
    motionEventDynamic = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, 2, new PointerProperties[] { properties0, properties1 }, new PointerCoords[] { coords0, coords1 }, META_STATE, 0, X_PRECISION_3F, Y_PRECISION_4F, DEVICE_ID_1, EDGE_FLAGS, InputDevice.SOURCE_TOUCHSCREEN, 0);
    // We expect to have data for two pointers
    assertThat(motionEventDynamic).hasPointerCount(2);
    assertThat(motionEventDynamic).hasFlags(0);
    assertThat(motionEventDynamic).pointerId(0).isEqualTo(0);
    assertThat(motionEventDynamic).pointerId(1).isEqualTo(1);
    MotionEventEqualitySubject.assertThat(motionEventDynamic).pointerCoords(0).isEqualToWithinTolerance(coords0, TOLERANCE);
    MotionEventEqualitySubject.assertThat(motionEventDynamic).pointerCoords(1).isEqualToWithinTolerance(coords1, TOLERANCE);
    assertThat(motionEventDynamic).pointerProperties(0).isEqualTo(properties0);
    assertThat(motionEventDynamic).pointerProperties(1).isEqualTo(properties1);
}
Also used : PointerCoords(android.view.MotionEvent.PointerCoords) PointerProperties(android.view.MotionEvent.PointerProperties) Test(org.junit.Test)

Example 47 with PointerProperties

use of android.view.MotionEvent.PointerProperties in project robolectric by robolectric.

the class MotionEventTest method testGetCurrentDataWithTwoPointers.

@Test
public void testGetCurrentDataWithTwoPointers() {
    PointerCoords coords0 = PointerCoordsBuilder.newBuilder().setCoords(10.0f, 20.0f).setPressure(1.2f).setSize(2.0f).setTool(1.2f, 1.4f).build();
    PointerCoords coords1 = PointerCoordsBuilder.newBuilder().setCoords(30.0f, 40.0f).setPressure(1.4f).setSize(3.0f).setTouch(2.2f, 0.6f).build();
    PointerProperties properties0 = PointerPropertiesBuilder.newBuilder().setId(0).setToolType(MotionEvent.TOOL_TYPE_FINGER).build();
    PointerProperties properties1 = PointerPropertiesBuilder.newBuilder().setId(1).setToolType(MotionEvent.TOOL_TYPE_FINGER).build();
    motionEventDynamic = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, 2, new PointerProperties[] { properties0, properties1 }, new PointerCoords[] { coords0, coords1 }, 0, 0, 1.0f, 1.0f, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
    // We expect to have data for two pointers
    assertThat(motionEventDynamic).pointerId(0).isEqualTo(0);
    assertThat(motionEventDynamic).pointerId(1).isEqualTo(1);
    assertThat(motionEventDynamic).hasPointerCount(2);
    assertThat(motionEventDynamic).hasFlags(0);
    MotionEventEqualitySubject.assertThat(motionEventDynamic).pointerCoords(0).isEqualToWithinTolerance(coords0, TOLERANCE);
    MotionEventEqualitySubject.assertThat(motionEventDynamic).pointerCoords(1).isEqualToWithinTolerance(coords1, TOLERANCE);
    assertThat(motionEventDynamic).pointerProperties(0).isEqualTo(properties0);
    assertThat(motionEventDynamic).pointerProperties(1).isEqualTo(properties1);
}
Also used : PointerCoords(android.view.MotionEvent.PointerCoords) PointerProperties(android.view.MotionEvent.PointerProperties) Test(org.junit.Test)

Example 48 with PointerProperties

use of android.view.MotionEvent.PointerProperties in project robolectric by robolectric.

the class MotionEventTest method testPointerPropertiesCopyConstructor.

@Test
public void testPointerPropertiesCopyConstructor() {
    PointerProperties properties = new PointerProperties();
    properties.id = 1;
    properties.toolType = MotionEvent.TOOL_TYPE_MOUSE;
    PointerProperties copy = new PointerProperties(properties);
    assertThat(copy).hasId(1);
    assertThat(copy).hasToolType(MotionEvent.TOOL_TYPE_MOUSE);
}
Also used : PointerProperties(android.view.MotionEvent.PointerProperties) Test(org.junit.Test)

Example 49 with PointerProperties

use of android.view.MotionEvent.PointerProperties in project robolectric by robolectric.

the class MotionEventTest method testPointerPropertiesDefaultConstructor.

@Test
public void testPointerPropertiesDefaultConstructor() {
    PointerProperties properties = new PointerProperties();
    assertThat(properties).hasId(MotionEvent.INVALID_POINTER_ID);
    assertThat(properties).hasToolType(MotionEvent.TOOL_TYPE_UNKNOWN);
}
Also used : PointerProperties(android.view.MotionEvent.PointerProperties) Test(org.junit.Test)

Example 50 with PointerProperties

use of android.view.MotionEvent.PointerProperties in project robolectric by robolectric.

the class ShadowMotionEvent method nativeGetPointerProperties.

@Implementation(minSdk = LOLLIPOP)
@HiddenApi
protected static void nativeGetPointerProperties(long nativePtr, int pointerIndex, PointerProperties outPointerPropertiesObj) {
    NativeInput.MotionEvent event = getNativeMotionEvent(nativePtr);
    int pointerCount = event.getPointerCount();
    validatePointerIndex(pointerIndex, pointerCount);
    validatePointerProperties(outPointerPropertiesObj);
    PointerProperties pointerProperties = event.getPointerProperties(pointerIndex);
    // pointerPropertiesFromNative(env, pointerProperties, outPointerPropertiesObj);
    outPointerPropertiesObj.copyFrom(pointerProperties);
}
Also used : PointerProperties(android.view.MotionEvent.PointerProperties) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Aggregations

PointerProperties (android.view.MotionEvent.PointerProperties)55 PointerCoords (android.view.MotionEvent.PointerCoords)38 Point (android.graphics.Point)22 MotionEvent (android.view.MotionEvent)19 Pair (android.util.Pair)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 Test (org.junit.Test)7 Rect (android.graphics.Rect)5 DeviceProfile (com.android.launcher3.DeviceProfile)2 InvariantDeviceProfile (com.android.launcher3.InvariantDeviceProfile)2 GesturePoint (android.gesture.GesturePoint)1 HiddenApi (org.robolectric.annotation.HiddenApi)1 Implementation (org.robolectric.annotation.Implementation)1