本文整理匯總了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);
}
}
}
}
}