손가락 젓기 전환 Activity

2252 단어 android전환젓다
다음 코드는Activity 사이의 스크래치 전환에 사용되며, 대략적인 실현 원리는 손가락의 스크래치 속도와 스크래치 방향을 판단하여 어느 Activity로 점프하는지를 결정하는 것이다. switchTo**Activity()는Activity로 점프하는 방법이다.
	private VelocityTracker velocityTracker;//               
	private static final int VELOCITY = 600;        
        @Override
	public boolean onTouchEvent(MotionEvent event) {
		String localClassName = getLocalClassName();//      
		LogUtil.log(TAG, "class Name:"+localClassName);
		int action = event.getAction();
		//float x = event.getX();
		//float y = event.getY();
		
		switch (action) {
		case MotionEvent.ACTION_DOWN:
			if(velocityTracker == null){
				velocityTracker = VelocityTracker.obtain();//             
				velocityTracker.addMovement(event);
			}			
			//lastMotionX = x;
			
			break;
		
		case MotionEvent.ACTION_MOVE:
			//int deltaX = (int) (lastMotionX - x);
			if(velocityTracker != null){
				velocityTracker.addMovement(event);
			}
			//lastMotionX = x;
			break;
			
		case MotionEvent.ACTION_UP:
			
			int velocityX = 0;
			if(velocityTracker != null){
				velocityTracker.addMovement(event);
				velocityTracker.computeCurrentVelocity(1000);//           
				velocityX = (int) velocityTracker.getXVelocity();//      X  
			}
			
			if(velocityX > VELOCITY ){
				if("ui.MainActivity".equals(localClassName)){
					switchToTvLiveActivity();
				}else if("ui.LocalMediaActivity".equals(localClassName)){
					switchToMainActivity();
				}else if("ui.NetMediaActivity".equals(localClassName)){
					switchToLocalMediaActivity();
				}else if("ui.TvLiveActivity".equals(localClassName)){
					switchToNetMediaActivity();
				}
			} else if(velocityX < -VELOCITY ){
				if("ui.MainActivity".equals(localClassName)){
					switchToLocalMediaActivity();
				}else if("ui.LocalMediaActivity".equals(localClassName)){
					switchToNetMediaActivity();
				}else if("ui.NetMediaActivity".equals(localClassName)){
					switchToTvLiveActivity();
				}else if("ui.TvLiveActivity".equals(localClassName)){
					switchToMainActivity();
				}
			}
			
			if(velocityTracker != null){
				velocityTracker.recycle();//  
				velocityTracker = null;
			}
			
			break;
		}
		
		return true;
	}

좋은 웹페이지 즐겨찾기