Code example for VelocityTracker

Methods: addMovement, clear, computeCurrentVelocity, getXVelocity, recycle

0
	public boolean onTouch(View arg0, MotionEvent event) {
		int x = (int) event.getX();
		if (mVelocityTracker == null) {
			mVelocityTracker = VelocityTracker.obtain();//获得VelocityTracker类实��?
			} 
			mVelocityTracker.addMovement(event);//将事件加入到VelocityTracker类实例中
		switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN:
			mLastMotionX = x;
			break; 
		case MotionEvent.ACTION_MOVE:
			mVelocityTracker.computeCurrentVelocity(1000, 1000); 
			int dx = x - mLastMotionX;
			if(dx != 0){
				doRotate(dx,TYPE_ROTATING);
				if(degree > 90){			
					degree = 0;		
					break;      
				} 
			}else{ 
				return false; 
			} 
			mLastMotionX = x;
			break; 
		case MotionEvent.ACTION_UP:
			//设置units的�?��?000,意思为��?��时间内运动了多少个像��? 
			mVelocityTracker.computeCurrentVelocity(1000); 
			float VelocityX = mVelocityTracker.getXVelocity();
			if(VelocityX > 500 || VelocityX < -500 ){
				//endRotateByVelocity(); 
				doRotate(0,TYPE_VELROTATE);
			}else{ 
				//endRotate(); 
				doRotate(0,TYPE_ENDROTATE);
			} 
			setView(); 
			setViewVisibile(); 
			degree = 0;
			 
			   releaseVelocityTracker();   
               break;   
  
           case MotionEvent.ACTION_CANCEL:  
               releaseVelocityTracker();   
               break;   
		} 
		return true; 
	} 
	private void setView(){ 
		if(currentTab == 0){
			currentView = layoutmain;
			nextView = layoutnext;
			lastView = layoutlast;
		}else if(currentTab == 1){
			currentView = layoutnext;
			nextView = layoutlast;
			lastView = layoutmain;
		}else if(currentTab == 2){
			currentView = layoutlast;
			nextView = layoutmain;
			lastView = layoutnext;
		} 
	} 
	private void releaseVelocityTracker() { 
		if(null != mVelocityTracker) {  
            mVelocityTracker.clear();  
            mVelocityTracker.recycle();  
            mVelocityTracker = null;  
        }   
		 
	} 
	private void setViewVisibile() {