Code example for VelocityTracker

Methods: addMovementcomputeCurrentVelocitygetXVelocityrecycle

0
			return super.onTouchEvent(event);
		} 
		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;
			return true; 
 
		case MotionEvent.ACTION_MOVE:
			int deltaX = (int) (mLastMotionX - x);
			mLastMotionX = x;
 
			scrollBy(deltaX, 0);
			return true; 
 
		case MotionEvent.ACTION_UP:
 
			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;
			return true; 
Stop searching for code, let great code find you!  Add Codota to your java IDE