How to detect clock-wise gesture in android

421 views Asked by At

I don't know how to detect clock-wise gesture in android. I implemented GestureDetector.OnGestureListener

private GestureDetector= new GestureDetector(this);


@Override
public boolean onDown(MotionEvent e) {
    return false;
}

@Override
public void onShowPress(MotionEvent e) {

}

@Override
public boolean onSingleTapUp(MotionEvent e) {
    return false;
}

@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
    return false;
}

@Override
public void onLongPress(MotionEvent e) {

}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {

    return false;
}

Any idea? Thanks.

1

There are 1 answers

1
Gabe Sechan On BEST ANSWER

There isn't built in support for that. You'll need to build it from onTouch events. When you detect a touch event with ACTION_MOVE, save it. Then look at the last N points and see if its moving clockwise. If so, perform whatever action you want. Clear the list of points on an ACTION_UP.

To check for a clockwise set of points, an algorithm is described here: How to determine if a list of polygon points are in clockwise order?

Actually I also found a tutorial at http://android-coding.blogspot.com/2012/03/gestures-detection-and-canvas-scale.html

The answer is basically using Google's (mostly undocumented) android.gesture package and their machine learning algorithms to do a best guess match to an example clockwise gesture.