本文整理了Java中android.view.MotionEvent.getHistorySize()
方法的一些代码示例,展示了MotionEvent.getHistorySize()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MotionEvent.getHistorySize()
方法的具体详情如下:
包路径:android.view.MotionEvent
类名称:MotionEvent
方法名:getHistorySize
暂无
代码示例来源: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 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 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 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: seven332/EhViewer
final int historySize = event.getHistorySize();
mTmpInvalidateRect.setEmpty();
boolean invalidateNow = false;
代码示例来源:origin: tumblr/Backboard
if (event.getHistorySize() > 0) {
final float deltaX = event.getHistoricalX(event.getHistorySize() - 1) - event.getX();
final float deltaY = event.getHistoricalY(event.getHistorySize() - 1) - event.getY();
代码示例来源:origin: tumblr/Backboard
@Override
public void imitate(final View view, @NonNull final MotionEvent event) {
final float viewValue = mProperty.getValue(view);
final float eventValue = mProperty.getValue(event);
mOffset = mProperty.getOffset(view);
if (event.getHistorySize() > 0) {
final float historicalValue = mProperty.getOldestValue(event);
imitate(viewValue + mOffset, eventValue, eventValue - historicalValue, event);
} else {
imitate(viewValue + mOffset, eventValue, 0, event);
}
}
代码示例来源:origin: libgdx/libgdx
if(controller != null) {
synchronized(eventQueue) {
final int historySize = motionEvent.getHistorySize();
代码示例来源:origin: tumblr/Backboard
if (event.getHistorySize() > 0) {
mime(offset, value, delta,
event.getEventTime() - event.getHistoricalEventTime(0), event);
代码示例来源:origin: ankidroid/Anki-Android
case MotionEvent.ACTION_MOVE:
if (mCurrentlyDrawing) {
for (int i = 0; i < event.getHistorySize(); i++) {
drawAlong(event.getHistoricalX(i), event.getHistoricalY(i));
代码示例来源:origin: weexteam/weex-hackernews
/**
* Create a list of event for {@link com.taobao.weex.WXSDKInstance#fireEvent(String, String, Map, Map)}.
* As there is a batch mechanism in MotionEvent, so this method returns a list.
* @param motionEvent motionEvent, which contains all pointers event in a period of time
* @return List of Map, which contains touch object.
*/
private List<Map<String, Object>> createMultipleFireEventParam(MotionEvent motionEvent,String state) {
List<Map<String, Object>> list = new ArrayList<>(motionEvent.getHistorySize() + 1);
list.addAll(getHistoricalEvents(motionEvent));
list.add(createFireEventParam(motionEvent, CUR_EVENT, state));
return list;
}
代码示例来源:origin: stackoverflow.com
float getDistance(float startX, float startY, MotionEvent ev) {
float distanceSum = 0;
final int historySize = ev.getHistorySize();
for (int h = 0; h < historySize; h++) {
// historical point
float hx = ev.getHistoricalX(0, h);
float hy = ev.getHistoricalY(0, h);
// distance between startX,startY and historical point
float dx = (hx - startX);
float dy = (hy - startY);
distanceSum += Math.sqrt(dx * dx + dy * dy);
// make historical point the start point for next loop iteration
startX = hx;
startY = hy;
}
// add distance from last historical point to event's point
float dx = (ev.getX(0) - startX);
float dy = (ev.getY(0) - startY);
distanceSum += Math.sqrt(dx * dx + dy * dy);
return distanceSum;
}
代码示例来源:origin: JasonQS/Anti-recall
private void initBottomNavigationBar(ScrollView view) {
// 底部navigation bar的show hide
view.setOnTouchListener((v, event) -> {
NavigationTabBar navigationTabBar = getActivity().findViewById(R.id.ntb);
switch (event.getAction()) {
case MotionEvent.ACTION_MOVE:
if (event.getHistorySize() < 1)
return false;
float y = event.getY();
float historicalY = event.getHistoricalY(event.getHistorySize() - 1);
if (y > historicalY)
navigationTabBar.show();
else
navigationTabBar.hide();
}
return false;
});
}
代码示例来源:origin: robolectric/robolectric
.of(other.getOrientation(i));
check("getHistorySize()").that(actual().getHistorySize()).isEqualTo(other.getHistorySize());
for (int i = 0; i < actual().getHistorySize(); i++) {
check("getHistoricalX(%s)", i).that(actual().getX(i)).isWithin(tolerance).of(other.getX(i));
check("getHistoricalY(%s)", i)
内容来源于网络,如有侵权,请联系作者删除!