private static MotionEvent doMotion(long time, float x, float y) { return MotionEvent.obtain(0, time, MotionEvent.ACTION_MOVE, x, y, 0); }
private static MotionEvent doPointerDown(long time, float x, float y) { return MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, x, y, 0); }
public void startLongPressDetection(MotionEvent e, int timeout) { cancelLongPressDetection(); mDownMotionEvent = MotionEvent.obtain(e); sendEmptyMessageAtTime(MSG_LONGPRESS, e.getDownTime() + timeout); }
public void startLongPressDetection(MotionEvent e, int timeout) { cancelLongPressDetection(); mDownMotionEvent = MotionEvent.obtain(e); sendEmptyMessageAtTime(MSG_LONGPRESS, e.getDownTime() + timeout); }
@Test public void testEmptyOnTouchEvent() { mTouchDelegate.onTouchEvent( MotionEvent.obtain( SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, 0, 0, 0)); }
@Before public void setUp() throws Exception { event = MotionEvent.obtain(100, 200, MotionEvent.ACTION_MOVE, 5.0f, 10.0f, 0); shadowMotionEvent = shadowOf(event); }
@Test public void onTouchEvent_shouldCallMovementMethodOnTouchEventWithSetMotionEvent() throws Exception { TestMovementMethod testMovementMethod = new TestMovementMethod(); textView.setMovementMethod(testMovementMethod); textView.setLayoutParams(new FrameLayout.LayoutParams(100, 100)); textView.measure(100, 100); MotionEvent event = MotionEvent.obtain(0, 0, 0, 0, 0, 0); textView.dispatchTouchEvent(event); assertEquals(testMovementMethod.event, event); }
@Test public void dispatchTouchEvent_listensToFalseFromListener() throws Exception { final AtomicBoolean called = new AtomicBoolean(false); view.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { called.set(true); return false; } }); MotionEvent event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 12f, 34f, 0); view.dispatchTouchEvent(event); assertThat(shadowOf(view).getLastTouchEvent()).isSameAs(event); assertThat(called.get()).isTrue(); }
@Test public void shouldKnowWhenOnInterceptTouchEventWasCalled() throws Exception { ViewGroup viewGroup = new FrameLayout(context); MotionEvent touchEvent = MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0, 0, 0); viewGroup.onInterceptTouchEvent(touchEvent); assertThat(shadowOf(viewGroup).getInterceptedTouchEvent()).isEqualTo(touchEvent); }
@Before public void setUp() throws Exception { detector = new ScaleGestureDetector(ApplicationProvider.getApplicationContext(), null); motionEvent = MotionEvent.obtain(-1, -1, MotionEvent.ACTION_UP, 100, 30, -1); }
mDecelerationCurrentPoint.y += distanceY; MotionEvent event = MotionEvent.obtain(currentTime, currentTime, MotionEvent.ACTION_MOVE, mDecelerationCurrentPoint.x, mDecelerationCurrentPoint.y, 0);
@Test public void testMoveItemWithoutTouchables() throws Exception { Drawable d1 = new ColorDrawable(BLACK); MountItem mountItem1 = mount(1, d1); Drawable d2 = new ColorDrawable(BLACK); MountItem mountItem2 = mount(2, d2); assertThat(getDrawableItemsSize()).isEqualTo(2); assertThat(getDrawableMountItemAt(0)).isEqualTo(mountItem1); assertThat(getDrawableMountItemAt(1)).isEqualTo(mountItem2); mHost.moveItem(mountItem2, 2, 0); // There are no Touchable Drawables so this call should return false and not crash. assertThat(mHost.onTouchEvent(obtain(0, 0, 0, 0, 0, 0))).isFalse(); }
@Test public void dispatchTouchEvent_sendsMotionEventToOnTouchEvent() throws Exception { TouchableView touchableView = new TouchableView(context); MotionEvent event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 12f, 34f, 0); touchableView.dispatchTouchEvent(event); assertThat(touchableView.event).isSameAs(event); view.dispatchTouchEvent(event); assertThat(shadowOf(view).getLastTouchEvent()).isSameAs(event); }
/** * Construct a new MotionEvent involving two pointers at {@code time}. Pointer 2 will be * considered active. */ private static MotionEvent doMotion( long time, float pointer1X, float pointer1Y, float pointer2X, float pointer2Y) { MotionEvent event = MotionEvent.obtain(0, time, MotionEvent.ACTION_MOVE, pointer2X, pointer2Y, 0); ShadowMotionEvent shadowEvent = Shadows.shadowOf(event); shadowEvent.setPointer2(pointer1X, pointer1Y); shadowEvent.setPointerIndex(0); // we put our active pointer (the second one down) first, so flip the IDs so that they match up // properly shadowEvent.setPointerIds(1, 0); return event; } }
@Test public void testObtainFromMotionEvent() { motionEventDynamic = MotionEvent.obtain(motionEvent2); assertThat(motionEventDynamic).isNotNull(); MotionEventEqualitySubject.assertThat(motionEventDynamic) .isEqualToWithinTolerance(motionEvent2, TOLERANCE); }