Monday, June 13, 2011

Undersranding android gestures

Android gestures is another dark horse because it is wrapped into android library  and becomes a part of SDK.

From Android SDK it is clear that gesture library should be put in raw folder in resources or it could be just a separate file in private or public folder, but what is the gesture library format?. You can browse Android SDK here that describes only high level design.

I still cannot find gesture library format but I saw on the market there are many applications that uses gestures.

My first clue was to use Gesture Builder from Android example SDK.
It is located under \samples\android-8\GestureBuilder

Lets take a close look:

GestureLibrary lib;
// create lib instanse from file name pass empty file
lib = GestureLibraries.fromFile(new File("gestures")));
..
lib.addGesture("gesture's name", gestureProcessor); // adding
lib.save();

// We could build gesture object  from overlay
private class GestureProcessor implements GestureOverlayView.OnGestureListener {
    public void onGestureStarted(GestureOverlayView overlay, MotionEvent event) {
    }

    public void onGesture(GestureOverlayView overlay, MotionEvent event) {
    }

    public void onGestureEnded(GestureOverlayView overlay, MotionEvent event) {
       mGesture = overlay.getGesture();
       if (mGesture.getLength() < LENGTH_THRESHOLD) {
         overlay.clear(false);
       }
}


No comments: