android.view.MotionEvent.obtain()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(601)

本文整理了Java中android.view.MotionEvent.obtain()方法的一些代码示例,展示了MotionEvent.obtain()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MotionEvent.obtain()方法的具体详情如下:
包路径:android.view.MotionEvent
类名称:MotionEvent
方法名:obtain

MotionEvent.obtain介绍

暂无

代码示例

代码示例来源:origin: robolectric/robolectric

private static MotionEvent doMotion(long time, float x, float y) {
 return MotionEvent.obtain(0, time, MotionEvent.ACTION_MOVE, x, y, 0);
}

代码示例来源:origin: robolectric/robolectric

private static MotionEvent doPointerDown(long time, float x, float y) {
 return MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, x, y, 0);
}

代码示例来源:origin: h6ah4i/android-advancedrecyclerview

public void startLongPressDetection(MotionEvent e, int timeout) {
  cancelLongPressDetection();
  mDownMotionEvent = MotionEvent.obtain(e);
  sendEmptyMessageAtTime(MSG_LONGPRESS, e.getDownTime() + timeout);
}

代码示例来源:origin: h6ah4i/android-advancedrecyclerview

public void startLongPressDetection(MotionEvent e, int timeout) {
  cancelLongPressDetection();
  mDownMotionEvent = MotionEvent.obtain(e);
  sendEmptyMessageAtTime(MSG_LONGPRESS, e.getDownTime() + timeout);
}

代码示例来源:origin: nisrulz/sensey

@Test
public void detectNothingForSlightlyScrollUp() {
  MotionEvent ev1 = MotionEvent.obtain(10, 10, 0, 0, 2, 0);
  MotionEvent ev2 = MotionEvent.obtain(10, 10, 0, 0, 1, 0);
  testTouchTypeDetector.gestureListener.onScroll(ev1, ev2, 0, 0);
  verifyNoMoreInteractions(mockListener);
}

代码示例来源:origin: facebook/litho

@Test
public void testEmptyOnTouchEvent() {
 mTouchDelegate.onTouchEvent(
   MotionEvent.obtain(
     SystemClock.uptimeMillis(),
     SystemClock.uptimeMillis(),
     MotionEvent.ACTION_DOWN,
     0,
     0,
     0));
}

代码示例来源:origin: robolectric/robolectric

@Before
public void setUp() throws Exception {
 event = MotionEvent.obtain(100, 200, MotionEvent.ACTION_MOVE, 5.0f, 10.0f, 0);
 shadowMotionEvent = shadowOf(event);
}

代码示例来源:origin: nisrulz/sensey

@Test
public void detectOnScrollLeft() {
  MotionEvent ev1 = MotionEvent.obtain(10, 10, 0, 200, 0, 0);
  MotionEvent ev2 = MotionEvent.obtain(10, 10, 0, 50, 0, 0);
  testTouchTypeDetector.gestureListener.onScroll(ev1, ev2, 0, 0);
  verify(mockListener, only()).onScroll(SCROLL_DIR_LEFT);
}

代码示例来源:origin: nisrulz/sensey

@Test
public void detectOnScrollRight() {
  MotionEvent ev1 = MotionEvent.obtain(10, 10, 0, 50, 0, 0);
  MotionEvent ev2 = MotionEvent.obtain(10, 10, 0, 200, 0, 0);
  testTouchTypeDetector.gestureListener.onScroll(ev1, ev2, 0, 0);
  verify(mockListener, only()).onScroll(SCROLL_DIR_RIGHT);
}

代码示例来源:origin: nisrulz/sensey

@Test
public void ignoreOnSwipeBottom() {
  MotionEvent ev1 = MotionEvent.obtain(10, 10, 0, 160, 50, 0);
  MotionEvent ev2 = MotionEvent.obtain(10, 10, 0, 50, 500, 0);
  testTouchTypeDetector.gestureListener.onFling(ev1, ev2, 201, 201);
  verify(mockListener, only()).onSwipe(SWIPE_DIR_DOWN);
}

代码示例来源:origin: nisrulz/sensey

@Test
public void ignoreOnSwipeTop() {
  MotionEvent ev1 = MotionEvent.obtain(10, 10, 0, 50, 500, 0);
  MotionEvent ev2 = MotionEvent.obtain(10, 10, 0, 160, 50, 0);
  testTouchTypeDetector.gestureListener.onFling(ev1, ev2, 201, 201);
  verify(mockListener, only()).onSwipe(SWIPE_DIR_UP);
}

代码示例来源:origin: robolectric/robolectric

@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);
}

代码示例来源:origin: robolectric/robolectric

@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();
}

代码示例来源:origin: robolectric/robolectric

@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);
}

代码示例来源:origin: robolectric/robolectric

@Before
public void setUp() throws Exception {
 detector = new ScaleGestureDetector(ApplicationProvider.getApplicationContext(), null);
 motionEvent = MotionEvent.obtain(-1, -1, MotionEvent.ACTION_UP, 100, 30, -1);
}

代码示例来源:origin: PhilJay/MPAndroidChart

mDecelerationCurrentPoint.y += distanceY;
MotionEvent event = MotionEvent.obtain(currentTime, currentTime, MotionEvent.ACTION_MOVE, mDecelerationCurrentPoint.x,
    mDecelerationCurrentPoint.y, 0);

代码示例来源:origin: facebook/litho

@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();
}

代码示例来源:origin: robolectric/robolectric

@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);
}

代码示例来源:origin: robolectric/robolectric

/**
  * 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;
 }
}

代码示例来源:origin: robolectric/robolectric

@Test
public void testObtainFromMotionEvent() {
 motionEventDynamic = MotionEvent.obtain(motionEvent2);
 assertThat(motionEventDynamic).isNotNull();
 MotionEventEqualitySubject.assertThat(motionEventDynamic)
   .isEqualToWithinTolerance(motionEvent2, TOLERANCE);
}

相关文章