本文整理汇总了Java中android.view.MotionEvent.getEventTime方法的典型用法代码示例。如果您正苦于以下问题:Java MotionEvent.getEventTime方法的具体用法?Java MotionEvent.getEventTime怎么用?Java MotionEvent.getEventTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.MotionEvent
的用法示例。
在下文中一共展示了MotionEvent.getEventTime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pinchVelocity
import android.view.MotionEvent; //导入方法依赖的package包/类
/**
* <p>Calculates the pinch velocity for the last <code>timeWindow</code> milliseconds.</p>
* @param event
* @param pointerA id of pointer A
* @param pointerB id of pointer B
* @param timeWindow
* @return spacing between both pointers
*/
public static final float pinchVelocity(MotionEvent event, int pointerA, int pointerB, long timeWindow) {
int indexA = event.findPointerIndex(pointerA);
int indexB = event.findPointerIndex(pointerB);
long eventTime = event.getEventTime();
long timeDelta = 0;
float previousSpacing = spacingByIndex(event, indexA, indexB);
float scale = 1;
for(int i = 0, n = event.getHistorySize(); i < n && timeDelta < timeWindow; i++) {
int index = (n - 1) - i;
float x = event.getHistoricalX(indexA, index) - event.getHistoricalX(indexB, index);
float y = event.getHistoricalY(indexA, index) - event.getHistoricalY(indexB, index);
float spacing = (float) Math.sqrt(x * x + y * y);
scale *= previousSpacing / spacing;
previousSpacing = spacing;
timeDelta = eventTime - event.getHistoricalEventTime(index);
}
return (float) Math.pow(Math.pow(scale, 1d / timeWindow), 1000d);
}
示例2: onTouch
import android.view.MotionEvent; //导入方法依赖的package包/类
private boolean onTouch(View v, MotionEvent event) {
if (parent.isEmpty()) {
return false;
}
animator.cancel();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
initialTouchX = event.getRawX();
initialTouchY = event.getRawY();
startTimeMS = event.getEventTime();
onMoveStart(v);
v.setPressed(true);
return true;
case MotionEvent.ACTION_MOVE:
animator.cancel();
onMove(v, event.getRawX() - initialTouchX, event.getRawY() - initialTouchY);
return true;
case MotionEvent.ACTION_UP:
v.setPressed(false);
onMoveEnd(v);
final long downTimeMS = event.getEventTime() - startTimeMS;
final float halfButtonSize = Math.min(v.getHeight(), v.getWidth()) / 2f;
final boolean wasClicked = downTimeMS < CLICK_MAX_DURATION_MS
&& ViewUtil.distance(initialTouchX, initialTouchY, event.getRawX(), event.getRawY()) < halfButtonSize;
if (wasClicked) {
v.performClick();
}
return true;
default:
return true;
}
}
示例3: isMatchAndProcessed
import android.view.MotionEvent; //导入方法依赖的package包/类
/**
* Compares if {@code event} on {@code touchedView} is a continuation of the event stream
* tracked by this PendingDrag. This includes whether the event stream has had sufficient
* regular updates, at least more often than {@link #MAX_MOTION_EVENT_MILLISECONDS_DELTA}
* (in an effort to disregard it from dropped previous streams with dropped
* {@link MotionEvent#ACTION_UP} and {@link MotionEvent#ACTION_CANCEL}). If that threshold
* is exceeded (for matching view and pointer id), the PendingDrag will no longer be alive
* ({@link #isAlive()}, and not match any future events.
* <p/>
* If the event is a match and alive, it will pass the event through a {@link GestureDetector}
* to determine if the event triggers a click (or other interesting gestures in the future).
* Check {@link #isClick()} to determine whether a click was detected.
* <p/>
* This method should only be called from {@link Dragger#onTouchBlockImpl}.
*
* @param event The event to compare to.
* @param touchedView The view that received the touch event.
* @return Whether the event was a match and the drag is still alive.
*/
boolean isMatchAndProcessed(MotionEvent event, BlockView touchedView) {
if (!mAlive) {
return false;
}
final int pointerId = event.getPointerId(event.getActionIndex());
long curEventTime = event.getEventTime();
long deltaMs = curEventTime - mLatestEventTime;
if (deltaMs < MAX_MOTION_EVENT_MILLISECONDS_DELTA) {
if (pointerId == mPointerId && touchedView == mTouchedView) {
mLatestEventTime = curEventTime;
mGestureDetector.onTouchEvent(event);
return true;
}
} else {
mAlive = false; // Exceeded threshold and expired.
}
return false; // Not a pointer & view match or died.
}
示例4: updateStateByEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
protected void updateStateByEvent(MotionEvent curr){
final MotionEvent prev = mPrevEvent;
// Reset mCurrEvent
if (mCurrEvent != null) {
mCurrEvent.recycle();
mCurrEvent = null;
}
mCurrEvent = MotionEvent.obtain(curr);
// Delta time
mTimeDelta = curr.getEventTime() - prev.getEventTime();
// Pressure
mCurrPressure = curr.getPressure(curr.getActionIndex());
mPrevPressure = prev.getPressure(prev.getActionIndex());
}
示例5: updateStateByEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
protected void updateStateByEvent(MotionEvent curr) {
final MotionEvent prev = mPrevEvent;
// Reset mCurrEvent
if (mCurrEvent != null) {
mCurrEvent.recycle();
mCurrEvent = null;
}
mCurrEvent = MotionEvent.obtain(curr);
// Delta time
mTimeDelta = curr.getEventTime() - prev.getEventTime();
// Pressure
mCurrPressure = curr.getPressure(curr.getActionIndex());
mPrevPressure = prev.getPressure(prev.getActionIndex());
}
示例6: onTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
/** Handles the touch event */
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mIsCapturingGesture = true;
mIsClickCandidate = true;
mActionDownTime = event.getEventTime();
mActionDownX = event.getX();
mActionDownY = event.getY();
break;
case MotionEvent.ACTION_MOVE:
if (Math.abs(event.getX() - mActionDownX) > mSingleTapSlopPx ||
Math.abs(event.getY() - mActionDownY) > mSingleTapSlopPx) {
mIsClickCandidate = false;
}
break;
case MotionEvent.ACTION_CANCEL:
mIsCapturingGesture = false;
mIsClickCandidate = false;
break;
case MotionEvent.ACTION_UP:
mIsCapturingGesture = false;
if (Math.abs(event.getX() - mActionDownX) > mSingleTapSlopPx ||
Math.abs(event.getY() - mActionDownY) > mSingleTapSlopPx) {
mIsClickCandidate = false;
}
if (mIsClickCandidate) {
if (event.getEventTime() - mActionDownTime <= ViewConfiguration.getLongPressTimeout()) {
if (mClickListener != null) {
mClickListener.onClick();
}
} else {
// long click, not handled
}
}
mIsClickCandidate = false;
break;
}
return true;
}
示例7: onHoverExit
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
protected void onHoverExit(final MotionEvent event) {
final Key lastKey = getLastHoverKey();
if (DEBUG_HOVER) {
Log.d(TAG, "onHoverExit: key=" + getHoverKeyOf(event) + " last=" + lastKey);
}
if (lastKey != null) {
super.onHoverExitFrom(lastKey);
}
setLastHoverKey(null);
final int actionIndex = event.getActionIndex();
final int x = (int)event.getX(actionIndex);
final int y = (int)event.getY(actionIndex);
final int pointerId = event.getPointerId(actionIndex);
final long eventTime = event.getEventTime();
// A hover exit event at one pixel width or height area on the edges of more keys keyboard
// are treated as closing.
mMoreKeysKeyboardValidBounds.set(0, 0, mKeyboardView.getWidth(), mKeyboardView.getHeight());
mMoreKeysKeyboardValidBounds.inset(CLOSING_INSET_IN_PIXEL, CLOSING_INSET_IN_PIXEL);
if (mMoreKeysKeyboardValidBounds.contains(x, y)) {
// Invoke {@link MoreKeysKeyboardView#onUpEvent(int,int,int,long)} as if this hover
// exit event selects a key.
mKeyboardView.onUpEvent(x, y, pointerId, eventTime);
// TODO: Should fix this reference. This is a hack to clear the state of
// {@link PointerTracker}.
PointerTracker.dismissAllMoreKeysPanels();
return;
}
// Close the more keys keyboard.
// TODO: Should fix this reference. This is a hack to clear the state of
// {@link PointerTracker}.
PointerTracker.dismissAllMoreKeysPanels();
}
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:34,代码来源:MoreKeysKeyboardAccessibilityDelegate.java
示例8: initSwipe
import android.view.MotionEvent; //导入方法依赖的package包/类
private void initSwipe(MotionEvent event, int ignore) {
if (ignore < 0) {
initialTime = event.getEventTime();
}
for (int i = 0, l = event.getPointerCount(); i < l; ++i) {
if (i != ignore) {
pointerId = event.getPointerId(i);
initialX = event.getX(i);
if (ignore > -1) {
initialX -= deltaX;
}
break;
}
}
}
示例9: onInterceptTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (!isEnabled()) {
return false;
}
final int action = event.getActionMasked();
switch (action) {
case MotionEvent.ACTION_DOWN: {
removeAllCallbacks();
mInputText.setVisibility(View.INVISIBLE);
mLastDownOrMoveEventY = mLastDownEventY = event.getY();
mLastDownEventTime = event.getEventTime();
mIngonreMoveEvents = false;
if (mLastDownEventY < mTopSelectionDividerTop) {
if (mScrollState == OnScrollListener.SCROLL_STATE_IDLE) {
mPressedStateHelper.buttonPressDelayed(PressedStateHelper.BUTTON_DECREMENT);
}
} else if (mLastDownEventY > mBottomSelectionDividerBottom) {
if (mScrollState == OnScrollListener.SCROLL_STATE_IDLE) {
mPressedStateHelper.buttonPressDelayed(PressedStateHelper.BUTTON_INCREMENT);
}
}
getParent().requestDisallowInterceptTouchEvent(true);
if (!mFlingScroller.isFinished()) {
mFlingScroller.forceFinished(true);
mAdjustScroller.forceFinished(true);
onScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
} else if (!mAdjustScroller.isFinished()) {
mFlingScroller.forceFinished(true);
mAdjustScroller.forceFinished(true);
} else if (mLastDownEventY < mTopSelectionDividerTop) {
postChangeCurrentByOneFromLongPress(false, ViewConfiguration.getLongPressTimeout());
} else if (mLastDownEventY > mBottomSelectionDividerBottom) {
postChangeCurrentByOneFromLongPress(true, ViewConfiguration.getLongPressTimeout());
}
return true;
}
}
return false;
}
示例10: onTouchMove
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public void onTouchMove(MotionEvent event) {
if (!hold && event.getEventTime() - event.getDownTime() >= holdDelay) {
hold = true;
onVibrate(100);
}
}
示例11: onHoverEnter
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
protected void onHoverEnter(final MotionEvent event) {
if (DEBUG_HOVER) {
Log.d(TAG, "onHoverEnter: key=" + getHoverKeyOf(event));
}
super.onHoverEnter(event);
final int actionIndex = event.getActionIndex();
final int x = (int)event.getX(actionIndex);
final int y = (int)event.getY(actionIndex);
final int pointerId = event.getPointerId(actionIndex);
final long eventTime = event.getEventTime();
mKeyboardView.onDownEvent(x, y, pointerId, eventTime);
}
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:14,代码来源:MoreKeysKeyboardAccessibilityDelegate.java
示例12: onHoverMove
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
protected void onHoverMove(final MotionEvent event) {
super.onHoverMove(event);
final int actionIndex = event.getActionIndex();
final int x = (int)event.getX(actionIndex);
final int y = (int)event.getY(actionIndex);
final int pointerId = event.getPointerId(actionIndex);
final long eventTime = event.getEventTime();
mKeyboardView.onMoveEvent(x, y, pointerId, eventTime);
}
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:11,代码来源:MoreKeysKeyboardAccessibilityDelegate.java
示例13: onScroll
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
boolean result = false;
if (containsPan() &&
(e2.getPointerId(e1.getActionIndex()) == e1.getPointerId(e1.getActionIndex()))) {
if (panDownTime != e1.getEventTime()) {
panDownTime = e1.getEventTime();
scrolling = true;
component.getInstance().fireEvent(
component.getDomObject().getRef(), HighLevelGesture.PAN_START.toString(),
createFireEventParam(e1, CUR_EVENT));
} else {
component.getInstance().fireEvent(
component.getDomObject().getRef(), HighLevelGesture.PAN_MOVE.toString(),
createFireEventParam(e2, CUR_EVENT));
}
result = true;
}
if (component.containsGesture(HighLevelGesture.SWIPE)) {
if (swipeDownTime != e1.getEventTime()) {
swipeDownTime = e1.getEventTime();
List<Map<String, Object>> list = createFireEventParam(e2);
Map<String, Object> param = list.get(list.size() - 1);
if (Math.abs(distanceX) > Math.abs(distanceY)) {
param.put(GestureInfo.DIRECTION, distanceX > 0 ? "left" : "right");
} else {
param.put(GestureInfo.DIRECTION, distanceY > 0 ? "up" : "down");
}
component.getInstance().fireEvent( component.getDomObject().getRef(),
HighLevelGesture.SWIPE.toString(), param);
result = true;
}
}
return result;
}
示例14: captureDown
import android.view.MotionEvent; //导入方法依赖的package包/类
private void captureDown(MotionEvent event, int pointerIndex) {
final int pointerId = event.getPointerId(pointerIndex);
final int i = findIndex(pointerId);
if (i != UNTRACKED_POINTER) {
mDownX[i] = event.getX(pointerIndex);
mDownY[i] = event.getY(pointerIndex);
mDownTime[i] = event.getEventTime();
}
}
示例15: onActionUp
import android.view.MotionEvent; //导入方法依赖的package包/类
private void onActionUp(MotionEvent event)
{
long duration = event.getEventTime() - event.getDownTime();
if (duration < mClickTimeout
&& mTouchHelper.getDeltaXFrom(FTouchHelper.EVENT_DOWN) < mTouchSlop
&& mTouchHelper.getDeltaYFrom(FTouchHelper.EVENT_DOWN) < mTouchSlop)
{
toggleChecked(mAttrModel.isNeedToggleAnim(), true);
} else
{
if (mTouchHelper.isNeedCosume())
{
final int left = mViewThumb.getLeft();
final boolean checked = left >= ((getLeftNormal() + getLeftChecked()) / 2);
boolean updatePosition = false;
if (checked)
{
if (left != getLeftChecked())
{
updatePosition = true;
}
} else
{
if (left != getLeftNormal())
{
updatePosition = true;
}
}
if (setChecked(checked, true, true))
{
// 更新状态成功,内部会更新view的位置
} else
{
if (updatePosition)
{
updateViewByState(true);
}
}
}
}
}