本文整理了Java中android.view.MotionEvent.getHistoricalX()
方法的一些代码示例,展示了MotionEvent.getHistoricalX()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MotionEvent.getHistoricalX()
方法的具体详情如下:
包路径:android.view.MotionEvent
类名称:MotionEvent
方法名:getHistoricalX
暂无
代码示例来源:origin: tumblr/Backboard
/**
* <i>Note that this method does not check the validity of</i> <code>index</code>.
*
* @param event
* the event to inspect
* @param index
* the historical index (in {@link MotionEvent#getHistoricalX(int)} or {@link MotionEvent#getHistoricalY(int)})
* @return the historical value that this property represents on the given
* <code>MotionEvent</code>.
*/
public float getHistoricalValue(@Nullable final MotionEvent event, final int index) {
if (event != null) {
switch (this) {
case X:
return event.getHistoricalX(index);
case Y:
return event.getHistoricalY(index);
default:
return 0;
}
}
return 0;
}
代码示例来源:origin: EverythingMe/overscroll-decor
public boolean init(View view, MotionEvent event) {
// We must have history available to calc the dx. Normally it's there - if it isn't temporarily,
// we declare the event 'invalid' and expect it in consequent events.
if (event.getHistorySize() == 0) {
return false;
}
// Allow for counter-orientation-direction operations (e.g. item swiping) to run fluently.
final float dy = event.getY(0) - event.getHistoricalY(0, 0);
final float dx = event.getX(0) - event.getHistoricalX(0, 0);
if (Math.abs(dx) > Math.abs(dy)) {
return false;
}
mAbsOffset = view.getTranslationY();
mDeltaOffset = dy;
mDir = mDeltaOffset > 0;
return true;
}
}
代码示例来源:origin: EverythingMe/overscroll-decor
public boolean init(View view, MotionEvent event) {
// We must have history available to calc the dx. Normally it's there - if it isn't temporarily,
// we declare the event 'invalid' and expect it in consequent events.
if (event.getHistorySize() == 0) {
return false;
}
// Allow for counter-orientation-direction operations (e.g. item swiping) to run fluently.
final float dy = event.getY(0) - event.getHistoricalY(0, 0);
final float dx = event.getX(0) - event.getHistoricalX(0, 0);
if (Math.abs(dx) < Math.abs(dy)) {
return false;
}
mAbsOffset = view.getTranslationX();
mDeltaOffset = dx;
mDir = mDeltaOffset > 0;
return true;
}
}
代码示例来源:origin: EverythingMe/overscroll-decor
protected MotionEvent createShortLeftMoveEvent() {
MotionEvent event = mock(MotionEvent.class);
when(event.getAction()).thenReturn(MotionEvent.ACTION_MOVE);
when(event.getX()).thenReturn(100f);
when(event.getY()).thenReturn(200f);
when(event.getX(0)).thenReturn(100f);
when(event.getY(0)).thenReturn(200f);
when(event.getHistorySize()).thenReturn(1);
when(event.getHistoricalX(eq(0))).thenReturn(120f);
when(event.getHistoricalY(eq(0))).thenReturn(220f);
when(event.getHistoricalX(eq(0), eq(0))).thenReturn(120f);
when(event.getHistoricalY(eq(0), eq(0))).thenReturn(220f);
return event;
}
代码示例来源:origin: EverythingMe/overscroll-decor
protected MotionEvent createShortUpwardsMoveEvent() {
MotionEvent event = mock(MotionEvent.class);
when(event.getAction()).thenReturn(MotionEvent.ACTION_MOVE);
when(event.getX()).thenReturn(200f);
when(event.getY()).thenReturn(100f);
when(event.getX(0)).thenReturn(200f);
when(event.getY(0)).thenReturn(100f);
when(event.getHistorySize()).thenReturn(1);
when(event.getHistoricalX(eq(0))).thenReturn(220f);
when(event.getHistoricalY(eq(0))).thenReturn(120f);
when(event.getHistoricalX(eq(0), eq(0))).thenReturn(220f);
when(event.getHistoricalY(eq(0), eq(0))).thenReturn(120f);
return event;
}
代码示例来源:origin: EverythingMe/overscroll-decor
protected MotionEvent createLongRightMoveEvent() {
MotionEvent event = mock(MotionEvent.class);
when(event.getAction()).thenReturn(MotionEvent.ACTION_MOVE);
when(event.getX()).thenReturn(150f);
when(event.getY()).thenReturn(250f);
when(event.getX(0)).thenReturn(150f);
when(event.getY(0)).thenReturn(250f);
when(event.getHistorySize()).thenReturn(1);
when(event.getHistoricalX(eq(0))).thenReturn(100f);
when(event.getHistoricalY(eq(0))).thenReturn(200f);
when(event.getHistoricalX(eq(0), eq(0))).thenReturn(100f);
when(event.getHistoricalY(eq(0), eq(0))).thenReturn(200f);
return event;
}
代码示例来源:origin: EverythingMe/overscroll-decor
protected MotionEvent createLongDownwardsMoveEvent() {
MotionEvent event = mock(MotionEvent.class);
when(event.getAction()).thenReturn(MotionEvent.ACTION_MOVE);
when(event.getX()).thenReturn(250f);
when(event.getY()).thenReturn(150f);
when(event.getX(0)).thenReturn(250f);
when(event.getY(0)).thenReturn(150f);
when(event.getHistorySize()).thenReturn(1);
when(event.getHistoricalX(eq(0))).thenReturn(200f);
when(event.getHistoricalY(eq(0))).thenReturn(100f);
when(event.getHistoricalX(eq(0), eq(0))).thenReturn(200f);
when(event.getHistoricalY(eq(0), eq(0))).thenReturn(100f);
return event;
}
代码示例来源:origin: EverythingMe/overscroll-decor
protected MotionEvent createShortDownwardsMoveEvent() {
MotionEvent event = mock(MotionEvent.class);
when(event.getAction()).thenReturn(MotionEvent.ACTION_MOVE);
when(event.getX()).thenReturn(200f);
when(event.getY()).thenReturn(100f);
when(event.getX(0)).thenReturn(200f);
when(event.getY(0)).thenReturn(100f);
when(event.getHistorySize()).thenReturn(1);
when(event.getHistoricalX(eq(0))).thenReturn(190f);
when(event.getHistoricalY(eq(0))).thenReturn(80f);
when(event.getHistoricalX(eq(0), eq(0))).thenReturn(190f);
when(event.getHistoricalY(eq(0), eq(0))).thenReturn(80f);
return event;
}
代码示例来源:origin: EverythingMe/overscroll-decor
protected MotionEvent createLongUpwardsMoveEvent() {
MotionEvent event = mock(MotionEvent.class);
when(event.getAction()).thenReturn(MotionEvent.ACTION_MOVE);
when(event.getX()).thenReturn(200f);
when(event.getY()).thenReturn(100f);
when(event.getX(0)).thenReturn(200f);
when(event.getY(0)).thenReturn(100f);
when(event.getHistorySize()).thenReturn(1);
when(event.getHistoricalX(eq(0))).thenReturn(250f);
when(event.getHistoricalY(eq(0))).thenReturn(150f);
when(event.getHistoricalX(eq(0), eq(0))).thenReturn(250f);
when(event.getHistoricalY(eq(0), eq(0))).thenReturn(150f);
return event;
}
代码示例来源:origin: EverythingMe/overscroll-decor
protected MotionEvent createShortRightMoveEvent() {
MotionEvent event = mock(MotionEvent.class);
when(event.getAction()).thenReturn(MotionEvent.ACTION_MOVE);
when(event.getX()).thenReturn(100f);
when(event.getY()).thenReturn(200f);
when(event.getX(0)).thenReturn(100f);
when(event.getY(0)).thenReturn(200f);
when(event.getHistorySize()).thenReturn(1);
when(event.getHistoricalX(eq(0))).thenReturn(80f);
when(event.getHistoricalY(eq(0))).thenReturn(190f);
when(event.getHistoricalX(eq(0), eq(0))).thenReturn(80f);
when(event.getHistoricalY(eq(0), eq(0))).thenReturn(190f);
return event;
}
代码示例来源:origin: EverythingMe/overscroll-decor
protected MotionEvent createLongLeftMoveEvent() {
MotionEvent event = mock(MotionEvent.class);
when(event.getAction()).thenReturn(MotionEvent.ACTION_MOVE);
when(event.getX()).thenReturn(50f);
when(event.getY()).thenReturn(150f);
when(event.getX(0)).thenReturn(50f);
when(event.getY(0)).thenReturn(150f);
when(event.getHistorySize()).thenReturn(1);
when(event.getHistoricalX(eq(0))).thenReturn(100f);
when(event.getHistoricalY(eq(0))).thenReturn(200f);
when(event.getHistoricalX(eq(0), eq(0))).thenReturn(100f);
when(event.getHistoricalY(eq(0), eq(0))).thenReturn(200f);
return event;
}
代码示例来源:origin: EverythingMe/overscroll-decor
@Test
public void onTouchMoveAction_dragLeftInRightEnd_overscrollLeft() throws Exception {
// Arrange
MotionEvent event = createShortLeftMoveEvent();
when(mViewAdapter.isInAbsoluteStart()).thenReturn(false);
when(mViewAdapter.isInAbsoluteEnd()).thenReturn(true);
HorizontalOverScrollBounceEffectDecorator uut = getUUT();
// Act
final boolean ret = uut.onTouch(mView, event);
// Assert
final float expectedTransX = (event.getX() - event.getHistoricalX(0)) / DEFAULT_TOUCH_DRAG_MOVE_RATIO_FWD;
verify(mView).setTranslationX(expectedTransX);
verify(mView, never()).setTranslationY(anyFloat());
assertTrue(ret);
assertEquals(STATE_DRAG_END_SIDE, uut.getCurrentState());
verify(mStateListener).onOverScrollStateChange(eq(uut), eq(STATE_IDLE), eq(STATE_DRAG_END_SIDE));
verify(mUpdateListener).onOverScrollUpdate(eq(uut), eq(STATE_DRAG_END_SIDE), eq(expectedTransX));
}
代码示例来源:origin: EverythingMe/overscroll-decor
@Test
public void onTouchMoveAction_dragRightInLeftEnd_overscrollRight() throws Exception {
// Arrange
MotionEvent event = createShortRightMoveEvent();
when(mViewAdapter.isInAbsoluteStart()).thenReturn(true);
when(mViewAdapter.isInAbsoluteEnd()).thenReturn(false);
HorizontalOverScrollBounceEffectDecorator uut = getUUT();
// Act
final boolean ret = uut.onTouch(mView, event);
// Assert
final float expectedTransX = (event.getX() - event.getHistoricalX(0)) / DEFAULT_TOUCH_DRAG_MOVE_RATIO_FWD;
verify(mView).setTranslationX(expectedTransX);
verify(mView, never()).setTranslationY(anyFloat());
assertTrue(ret);
assertEquals(STATE_DRAG_START_SIDE, uut.getCurrentState());
verify(mStateListener).onOverScrollStateChange(eq(uut), eq(STATE_IDLE), eq(STATE_DRAG_START_SIDE));
verify(mUpdateListener).onOverScrollUpdate(eq(uut), eq(STATE_DRAG_START_SIDE), eq(expectedTransX));
}
代码示例来源:origin: EverythingMe/overscroll-decor
@Test
public void onTouchMoveAction_2ndRightDragInLeftEnd_overscrollRightFurther() throws Exception {
// Arrange
// Bring UUT to a right-overscroll state
MotionEvent event1 = createShortRightMoveEvent();
when(mViewAdapter.isInAbsoluteStart()).thenReturn(true);
when(mViewAdapter.isInAbsoluteEnd()).thenReturn(false);
HorizontalOverScrollBounceEffectDecorator uut = getUUT();
uut.onTouch(mView, event1);
reset(mView);
// Create 2nd right-drag event
MotionEvent event2 = createLongRightMoveEvent();
// Act
final boolean ret = uut.onTouch(mView, event2);
// Assert
final float expectedTransX1 = (event1.getX() - event1.getHistoricalX(0)) / DEFAULT_TOUCH_DRAG_MOVE_RATIO_FWD;
final float expectedTransX2 = (event2.getX() - event2.getHistoricalX(0)) / DEFAULT_TOUCH_DRAG_MOVE_RATIO_FWD;
verify(mView).setTranslationX(expectedTransX2);
verify(mView, never()).setTranslationY(anyFloat());
assertTrue(ret);
assertEquals(STATE_DRAG_START_SIDE, uut.getCurrentState());
// State-change listener called only once?
verify(mStateListener).onOverScrollStateChange(eq(uut), eq(STATE_IDLE), eq(STATE_DRAG_START_SIDE));
verify(mStateListener).onOverScrollStateChange(eq(uut), anyInt(), anyInt());
// Update-listener called exactly twice?
verify(mUpdateListener).onOverScrollUpdate(eq(uut), eq(STATE_DRAG_START_SIDE), eq(expectedTransX1));
verify(mUpdateListener).onOverScrollUpdate(eq(uut), eq(STATE_DRAG_START_SIDE), eq(expectedTransX2));
verify(mUpdateListener, times(2)).onOverScrollUpdate(eq(uut), anyInt(), anyFloat());
}
代码示例来源:origin: EverythingMe/overscroll-decor
@Test
public void onTouchMoveAction_2ndLeftDragInRightEnd_overscrollLeftFurther() throws Exception {
// Arrange
// Bring UUT to a left-overscroll state
MotionEvent event1 = createShortLeftMoveEvent();
when(mViewAdapter.isInAbsoluteStart()).thenReturn(false);
when(mViewAdapter.isInAbsoluteEnd()).thenReturn(true);
HorizontalOverScrollBounceEffectDecorator uut = getUUT();
uut.onTouch(mView, event1);
reset(mView);
// Create 2nd left-drag event
MotionEvent event2 = createLongLeftMoveEvent();
// Act
final boolean ret = uut.onTouch(mView, event2);
// Assert
final float expectedTransX1 = (event1.getX() - event1.getHistoricalX(0)) / DEFAULT_TOUCH_DRAG_MOVE_RATIO_FWD;
final float expectedTransX2 = (event2.getX() - event2.getHistoricalX(0)) / DEFAULT_TOUCH_DRAG_MOVE_RATIO_FWD;
verify(mView).setTranslationX(expectedTransX2);
verify(mView, never()).setTranslationY(anyFloat());
assertTrue(ret);
assertEquals(STATE_DRAG_END_SIDE, uut.getCurrentState());
// State-change listener called only once?
verify(mStateListener).onOverScrollStateChange(eq(uut), eq(STATE_IDLE), eq(STATE_DRAG_END_SIDE));
verify(mStateListener).onOverScrollStateChange(eq(uut), anyInt(), anyInt());
// Update-listener called exactly twice?
verify(mUpdateListener).onOverScrollUpdate(eq(uut), eq(STATE_DRAG_END_SIDE), eq(expectedTransX1));
verify(mUpdateListener).onOverScrollUpdate(eq(uut), eq(STATE_DRAG_END_SIDE), eq(expectedTransX2));
verify(mUpdateListener, times(2)).onOverScrollUpdate(eq(uut), anyInt(), anyFloat());
}
代码示例来源:origin: EverythingMe/overscroll-decor
uut.onTouch(mView, eventMoveUp);
reset(mView);
float startTransX = (eventMoveUp.getX() - eventMoveUp.getHistoricalX(0)) / touchDragRatioFwd;
when(mView.getTranslationX()).thenReturn(startTransX);
代码示例来源:origin: EverythingMe/overscroll-decor
uut.onTouch(mView, eventMoveRight);
reset(mView);
float startTransX = (eventMoveRight.getX() - eventMoveRight.getHistoricalX(0)) / touchDragRatioFwd;
when(mView.getTranslationX()).thenReturn(startTransX);
代码示例来源:origin: EverythingMe/overscroll-decor
uut.onTouch(mView, eventMoveLeft);
reset(mView);
float startTransX = (eventMoveLeft.getX() - eventMoveLeft.getHistoricalX(0)) / touchDragRatioFwd;
when(mView.getTranslationX()).thenReturn(startTransX);
代码示例来源:origin: EverythingMe/overscroll-decor
reset(mView);
float startTransX = (eventMoveLeft.getX() - eventMoveLeft.getHistoricalX(0)) / touchDragRatioFwd;
when(mView.getTranslationX()).thenReturn(startTransX);
float expectedTransX = startTransX + (eventMoveRight.getX() - eventMoveRight.getHistoricalX(0)) / touchDragRatioBck;
verify(mView).setTranslationX(expectedTransX);
verify(mView, never()).setTranslationY(anyFloat());
代码示例来源:origin: EverythingMe/overscroll-decor
uut.onTouch(mView, eventMoveDown);
reset(mView);
float startTransX = (eventMoveDown.getX() - eventMoveDown.getHistoricalX(0)) / touchDragRatioFwd;
when(mView.getTranslationX()).thenReturn(startTransX);
内容来源于网络,如有侵权,请联系作者删除!