List of usage examples for android.view VelocityTracker computeCurrentVelocity
public void computeCurrentVelocity(int units)
From source file:org.kymjs.kjframe.widget.KJViewPager.java
@Override public boolean onTouchEvent(MotionEvent event) { if (!isScroll) { return false; }// w w w. j av a 2 s. c o m if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(event); final int action = event.getAction(); final float x = event.getX(); final float y = event.getY(); switch (action) { case MotionEvent.ACTION_DOWN: if (!mScroller.isFinished()) { mScroller.abortAnimation(); } mLastMotionX = x; mLastMotionY = y; break; case MotionEvent.ACTION_MOVE: int deltaX = (int) (mLastMotionX - x); int deltaY = (int) (mLastMotionY - y); if (Math.abs(deltaX) < 200 && Math.abs(deltaY) > 10) break; mLastMotionY = y; mLastMotionX = x; scrollBy(deltaX, 0); break; case MotionEvent.ACTION_UP: // if (mTouchState == TOUCH_STATE_SCROLLING) { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000); int velocityX = (int) velocityTracker.getXVelocity(); if (velocityX > SNAP_VELOCITY && mCurScreen > 0) { // Fling enough to move left snapToScreen(mCurScreen - 1); } else if (velocityX < -SNAP_VELOCITY && mCurScreen < getChildCount() - 1) { // Fling enough to move right snapToScreen(mCurScreen + 1); } else { snapToDestination(); } if (mVelocityTracker != null) { mVelocityTracker.recycle(); mVelocityTracker = null; } mTouchState = TOUCH_STATE_REST; break; case MotionEvent.ACTION_CANCEL: mTouchState = TOUCH_STATE_REST; break; } return true; }
From source file:cn.ieclipse.af.view.ScrollLayout.java
@Override public boolean onTouchEvent(MotionEvent event) { if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); }/*from w w w. ja v a 2s . c o m*/ mVelocityTracker.addMovement(event); final int action = event.getAction(); final float x = event.getX(); final float y = event.getY(); switch (action) { case MotionEvent.ACTION_DOWN: if (debug) { Log.v(TAG, "event down!"); } if (!mScroller.isFinished()) { mScroller.abortAnimation(); } mLastMotionX = x; break; case MotionEvent.ACTION_MOVE: int deltaX = (int) (mLastMotionX - x); mLastMotionX = x; scrollBy(deltaX, 0); break; case MotionEvent.ACTION_UP: if (debug) { Log.v(TAG, "event : up"); } // if (mTouchState == TOUCH_STATE_SCROLLING) { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000); int velocityX = (int) velocityTracker.getXVelocity(); if (debug) { Log.v(TAG, "velocityX:" + velocityX); } if (velocityX > mSnapVelocity) { if (mCurScreen > 0) { // Fling enough to move left if (debug) { Log.v(TAG, "snap left"); } snapToScreen(mCurScreen - 1); } else { // TODO disableWipe(false); snapToDestination(); } } else if (velocityX < -mSnapVelocity) { if (mCurScreen < getChildCount() - 1) { // Fling enough to move right if (debug) { Log.v(TAG, "snap right"); } snapToScreen(mCurScreen + 1); } else { // TODO disableWipe(false); snapToDestination(); } } else { snapToDestination(); } if (mVelocityTracker != null) { mVelocityTracker.recycle(); mVelocityTracker = null; } // } mTouchState = TOUCH_STATE_REST; break; case MotionEvent.ACTION_CANCEL: mTouchState = TOUCH_STATE_REST; break; } return true; }
From source file:org.zywx.wbpalmstar.engine.EBounceView.java
private boolean handlerTracker() { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000); int velocityX = (int) (velocityTracker.getXVelocity() / mDensity); int velocityY = (int) (velocityTracker.getYVelocity() / mDensity); endDrag();//from ww w . j a v a 2s . co m return onTracker(velocityX, velocityY); }
From source file:jmri.enginedriver.throttle.java
public void gestureMove(MotionEvent event) { // Log.d("Engine_Driver", "gestureMove action " + event.getAction()); if (gestureInProgress) { // stop the gesture timeout timer mainapp.throttle_msg_handler.removeCallbacks(gestureStopped); mVelocityTracker.addMovement(event); if ((event.getEventTime() - gestureLastCheckTime) > gestureCheckRate) { // monitor velocity and fail gesture if it is too low gestureLastCheckTime = event.getEventTime(); final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000); int velocityX = (int) velocityTracker.getXVelocity(); int velocityY = (int) velocityTracker.getYVelocity(); // Log.d("Engine_Driver", "gestureVelocity vel " + velocityX); if ((Math.abs(velocityX) < threaded_application.min_fling_velocity) && (Math.abs(velocityY) < threaded_application.min_fling_velocity)) { gestureFailed(event);// w w w. j a v a 2s .c o m } } if (gestureInProgress) { // restart the gesture timeout timer mainapp.throttle_msg_handler.postDelayed(gestureStopped, gestureCheckRate); } } }