ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • SimpleGesture
    과거...../개발일지 2010. 8. 18. 16:55

    한번 만들어놓고 필요할때마다 붙혀서  쓰는 소스다. ㅋㅋ

    fling, dbtouch 등등 편리하게 쓸수 있는 소스다

     // gesture
     private GestureDetector mGestureDetector;
     
     // swipe
     private static final int SWIPE_MIN_DISTANCE = 200;
     private static final int SWIPE_MAX_OFF_PATH = 250;
     private static final int SWIPE_THRESHOLD_VELOCITY = 1000;
     
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
     .
     .
     .
     .
           
            //gesture
            mGestureDetector = new GestureDetector(this, new Gesture());

     .
     .
     .
     .
     .
     .
                    
        }   


    @Override
        public boolean dispatchTouchEvent(MotionEvent ev) {
         super.dispatchTouchEvent(ev);
         mGestureDetector.onTouchEvent(ev);
         return true;
        }
          

    private class Gesture extends GestureDetector.SimpleOnGestureListener {
      @Override
      public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
        float velocityY) {
       super.onFling(e1, e2, velocityX, velocityY);
      
       if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
         && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY ){ //next page
            
                    
       } else if(e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE){
           }
       
       
       return true;
      }
     }


Designed by Tistory.