Android- Gesture Detection, Gesture Example

Posted: September 19, 2011 in Uncategorized

below code is just example of gesture detection on android device surface, but for that here we hav “gestures” raw library file for gesture identification, so you must have some gesture library file for that


import android.app.Activity;
import android.gesture.Gesture;
import android.gesture.GestureLibraries;
import android.gesture.GestureLibrary;
import android.gesture.GestureOverlayView;
import android.gesture.Prediction;
import android.gesture.GestureOverlayView.OnGesturePerformedListener;
import android.os.Bundle;
import android.util.Log;
import java.util.ArrayList;

public class GestureActivity extends Activity implements OnGesturePerformedListener {
    /** Called when the activity is first created. */
    private GestureLibrary gLib;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        gLib = GestureLibraries.fromRawResource(this,R.raw.gestures);
        if (!gLib.load()) {
            Log.i("Gesture Lib", "could not load gesture library");
            finish();
        }
        GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures);

        gestures.addOnGesturePerformedListener(this);

    }

    @Override
    public void onGesturePerformed(GestureOverlayView arg0, Gesture arg1) {
        // TODO Auto-generated method stub
        ArrayList<Prediction> predictions = gLib.recognize(arg1);
        if(predictions.size() > 0)
        {
            Prediction prediction = predictions.get(0);
            if(prediction.score > 1.0){
                Log.i("GESTURE DETECTED"+prediction.score,prediction.name);

        }
        }
    }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s