Java Code Examples for android.view.MotionEvent#getHistoricalEventTime()
The following examples show how to use
android.view.MotionEvent#getHistoricalEventTime() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultiTouchListener.java From PinchToZoom with MIT License | 6 votes |
/** * <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); }
Example 2
Source File: PointerTracker.java From openboard with GNU General Public License v3.0 | 5 votes |
private void onMoveEvent(final int x, final int y, final long eventTime, final MotionEvent me) { if (DEBUG_MOVE_EVENT) { printTouchEvent("onMoveEvent:", x, y, eventTime); } if (mIsTrackingForActionDisabled) { return; } if (sGestureEnabler.shouldHandleGesture() && me != null) { // Add historical points to gesture path. final int pointerIndex = me.findPointerIndex(mPointerId); final int historicalSize = me.getHistorySize(); for (int h = 0; h < historicalSize; h++) { final int historicalX = (int)me.getHistoricalX(pointerIndex, h); final int historicalY = (int)me.getHistoricalY(pointerIndex, h); final long historicalTime = me.getHistoricalEventTime(h); onGestureMoveEvent(historicalX, historicalY, historicalTime, false /* isMajorEvent */, null); } } if (isShowingMoreKeysPanel()) { final int translatedX = mMoreKeysPanel.translateX(x); final int translatedY = mMoreKeysPanel.translateY(y); mMoreKeysPanel.onMoveEvent(translatedX, translatedY, mPointerId, eventTime); onMoveKey(x, y); if (mIsInSlidingKeyInput) { sDrawingProxy.showSlidingKeyInputPreview(this); } return; } onMoveEventInternal(x, y, eventTime); }
Example 3
Source File: PointerTracker.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 5 votes |
private void onMoveEvent(final int x, final int y, final long eventTime, final MotionEvent me) { if (DEBUG_MOVE_EVENT) { printTouchEvent("onMoveEvent:", x, y, eventTime); } if (mIsTrackingForActionDisabled) { return; } if (sGestureEnabler.shouldHandleGesture() && me != null) { // Add historical points to gesture path. final int pointerIndex = me.findPointerIndex(mPointerId); final int historicalSize = me.getHistorySize(); for (int h = 0; h < historicalSize; h++) { final int historicalX = (int)me.getHistoricalX(pointerIndex, h); final int historicalY = (int)me.getHistoricalY(pointerIndex, h); final long historicalTime = me.getHistoricalEventTime(h); onGestureMoveEvent(historicalX, historicalY, historicalTime, false /* isMajorEvent */, null); } } if (isShowingMoreKeysPanel()) { final int translatedX = mMoreKeysPanel.translateX(x); final int translatedY = mMoreKeysPanel.translateY(y); mMoreKeysPanel.onMoveEvent(translatedX, translatedY, mPointerId, eventTime); onMoveKey(x, y); if (mIsInSlidingKeyInput) { sDrawingProxy.showSlidingKeyInputPreview(this); } return; } onMoveEventInternal(x, y, eventTime); }
Example 4
Source File: PointerTracker.java From Indic-Keyboard with Apache License 2.0 | 5 votes |
private void onMoveEvent(final int x, final int y, final long eventTime, final MotionEvent me) { if (DEBUG_MOVE_EVENT) { printTouchEvent("onMoveEvent:", x, y, eventTime); } if (mIsTrackingForActionDisabled) { return; } if (sGestureEnabler.shouldHandleGesture() && me != null) { // Add historical points to gesture path. final int pointerIndex = me.findPointerIndex(mPointerId); final int historicalSize = me.getHistorySize(); for (int h = 0; h < historicalSize; h++) { final int historicalX = (int)me.getHistoricalX(pointerIndex, h); final int historicalY = (int)me.getHistoricalY(pointerIndex, h); final long historicalTime = me.getHistoricalEventTime(h); onGestureMoveEvent(historicalX, historicalY, historicalTime, false /* isMajorEvent */, null); } } if (isShowingMoreKeysPanel()) { final int translatedX = mMoreKeysPanel.translateX(x); final int translatedY = mMoreKeysPanel.translateY(y); mMoreKeysPanel.onMoveEvent(translatedX, translatedY, mPointerId, eventTime); onMoveKey(x, y); if (mIsInSlidingKeyInput) { sDrawingProxy.showSlidingKeyInputPreview(this); } return; } onMoveEventInternal(x, y, eventTime); }
Example 5
Source File: ElasticityBounceEffectBase.java From elasticity with BSD 2-Clause "Simplified" License | 4 votes |
@Override public boolean handleMoveTouchEvent(MotionEvent event) { // Switching 'pointers' (e.g. fingers) on-the-fly isn't supported -- abort over-scroll // smoothly using the default bounce-back animation in this case. if (mOverScrollStartAttr.mPointerId != event.getPointerId(0)) { issueStateTransition(mBounceBackState); return true; } final View view = mViewAdapter.getView(); if (!mMoveAttr.init(view, event)) { // Keep intercepting the touch event as long as we're still over-scrolling... return true; } float deltaOffset = mMoveAttr.mDeltaOffset / (mMoveAttr.mDir == mOverScrollStartAttr.mDir ? mTouchDragRatioFwd : mTouchDragRatioBck); float newOffset = mMoveAttr.mAbsOffset + deltaOffset; // If moved in counter direction onto a potential under-scroll state -- don't. Instead, abort // over-scrolling abruptly, thus returning control to which-ever touch handlers there // are waiting (e.g. regular scroller handlers). if ((mOverScrollStartAttr.mDir && !mMoveAttr.mDir && (newOffset <= mOverScrollStartAttr.mAbsOffset)) || (!mOverScrollStartAttr.mDir && mMoveAttr.mDir && (newOffset >= mOverScrollStartAttr.mAbsOffset))) { translateViewAndEvent(view, mOverScrollStartAttr.mDir, mOverScrollStartAttr.mAbsOffset, event); mUpdateListener.onOverScrollUpdate(ElasticityBounceEffectBase.this, mCurrDragState, 0); issueStateTransition(mIdleState); return true; } if (view.getParent() != null) { view.getParent().requestDisallowInterceptTouchEvent(true); } long dt = event.getEventTime() - event.getHistoricalEventTime(0); if (dt > 0) { // Sometimes (though rarely) dt==0 cause originally timing is in nanos, but is presented in millis. mVelocity = deltaOffset / dt; } translateView(view, mOverScrollStartAttr.mDir, newOffset); mUpdateListener.onOverScrollUpdate(ElasticityBounceEffectBase.this, mCurrDragState, newOffset); return true; }
Example 6
Source File: OverScrollBounceEffectDecoratorBase.java From overscroll-decor with BSD 2-Clause "Simplified" License | 4 votes |
@Override public boolean handleMoveTouchEvent(MotionEvent event) { // Switching 'pointers' (e.g. fingers) on-the-fly isn't supported -- abort over-scroll // smoothly using the default bounce-back animation in this case. if (mStartAttr.mPointerId != event.getPointerId(0)) { issueStateTransition(mBounceBackState); return true; } final View view = mViewAdapter.getView(); if (!mMoveAttr.init(view, event)) { // Keep intercepting the touch event as long as we're still over-scrolling... return true; } float deltaOffset = mMoveAttr.mDeltaOffset / (mMoveAttr.mDir == mStartAttr.mDir ? mTouchDragRatioFwd : mTouchDragRatioBck); float newOffset = mMoveAttr.mAbsOffset + deltaOffset; // If moved in counter direction onto a potential under-scroll state -- don't. Instead, abort // over-scrolling abruptly, thus returning control to which-ever touch handlers there // are waiting (e.g. regular scroller handlers). if ( (mStartAttr.mDir && !mMoveAttr.mDir && (newOffset <= mStartAttr.mAbsOffset)) || (!mStartAttr.mDir && mMoveAttr.mDir && (newOffset >= mStartAttr.mAbsOffset)) ) { translateViewAndEvent(view, mStartAttr.mAbsOffset, event); mUpdateListener.onOverScrollUpdate(OverScrollBounceEffectDecoratorBase.this, mCurrDragState, 0); issueStateTransition(mIdleState); return true; } if (view.getParent() != null) { view.getParent().requestDisallowInterceptTouchEvent(true); } long dt = event.getEventTime() - event.getHistoricalEventTime(0); if (dt > 0) { // Sometimes (though rarely) dt==0 cause originally timing is in nanos, but is presented in millis. mVelocity = deltaOffset / dt; } translateView(view, newOffset); mUpdateListener.onOverScrollUpdate(OverScrollBounceEffectDecoratorBase.this, mCurrDragState, newOffset); return true; }