Code example for VelocityTracker

Methods: addMovement, clear, computeCurrentVelocity, getXVelocity

0
		} 
	} 
	 
	@Override 
	public boolean onTouchEvent(MotionEvent event){
		velocityTracker.addMovement(event);
		 
		final int action = event.getAction() & MotionEvent.ACTION_MASK;
		 
		switch(action){
		case MotionEvent.ACTION_DOWN:
			float x = event.getX() - centerPoint.x;
			float y = event.getY() - centerPoint.y;
			int pressedRange = (int) Math.sqrt(x * x + y * y);
			 
			//calculate the pressedRange to make sure it's in the clickable circle 
			switch(mode){
			case MODE_CONFIRM:
				if(pressedRange <= innerPressRange){
					isDrawCenterButtonPressed = true;
					isCenterPressed = true;
				} 
			case MODE_PICK:
				if(outerPressRange > pressedRange){
					isDrawPressPoint = true;
					increment = null;
					invalidate();
					if(pressedRange > innerPressRange){
						isCirclePressed = true;
						if(null != mOnTimePickListener) mOnTimePickListener.onStartPick();
						performDial(getDegrees(Math.atan2(y, x)));
					} 
				} 
				break; 
			} 
			 
			break; 
		case MotionEvent.ACTION_MOVE:
			float dx = event.getX() - centerPoint.x;
			float dy = event.getY() - centerPoint.y;
			if(isDrawPressPoint){
				getParent().requestDisallowInterceptTouchEvent(true);
				if(isCirclePressed){
					int tDegree = getDegrees(Math.atan2(dy, dx));
					performDial(tDegree);
					 
					int incrementValue = 0;
					if(null == increment){
						increment = tDegree;
					}else{ 
						incrementValue = tDegree - increment;
						int positiveIncrement = Math.abs(incrementValue);
						if(positiveIncrement > 180)
							incrementValue = -(incrementValue / positiveIncrement) * (360 - positiveIncrement);
					} 
					if(null != mOnTimePickListener) mOnTimePickListener.onPick(tDegree, incrementValue);
					increment = tDegree;
					invalidate();
				} 
			} 
			 
			if(isCenterPressed){
				if(Math.sqrt(dx * dx + dy * dy) <= innerPressRange){
					isDrawCenterButtonPressed = true;
				}else{ 
					isDrawCenterButtonPressed = false;
				} 
				invalidate();
			} 
			break; 
		case MotionEvent.ACTION_UP:
		case MotionEvent.ACTION_CANCEL:
			if(null != mOnTimePickListener){
				mOnTimePickListener.onStopPick();
				if(isDrawCenterButtonPressed) mOnTimePickListener.onCenterClick();
			} 
			 
			if(mode == MODE_PICK) isDrawPressPoint = false;
			isDrawCenterButtonPressed = false;
			isCirclePressed = false;
			isCenterPressed = false;
			 
			invalidate();
			 
			velocityTracker.computeCurrentVelocity(1000);
			xVelocity = velocityTracker.getXVelocity();
			 
			velocityTracker.clear();
			 
			break; 
		} 
		 
		return isCirclePressed || isCenterPressed;