Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a gesture overlay view in android

Tags:

android

So I'm trying to use a gesture overlay view in android to make a "swipe" action. So that when the user "swipes" left it executes certain code and when they swipe right it executes other code. I tried declairing the gestureoverlay like this:

GestureOverlayView gest = (GestureOverlayView) findViewById(R.id.hatgest);

But then i don't know where to go from there and i cant find anything helpful in the dev guide or online. For a button i would normally use an "onclicklistener" how would i do this with the gesture overlay? Does anyone have any examples of code that i can reference? Thanks

like image 323
Peter Avatar asked Mar 25 '11 15:03

Peter


1 Answers

Firstly make you custom gestures from gesture builder. Gesture builder app comes in the sdk. Put the file created from gesture builder app into raw folder of the application you are about to use these gestures. You can also get help from documentation

  public class YourClass extends Activity implements OnGesturePerformedListener {

    private GestureLibrary mLibrary;
    mLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
    if (!mLibrary.load()) {
      finish();
    }

    GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures);
    gestures.addOnGesturePerformedListener(this);

    public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
      ArrayList < Prediction > predictions = mLibrary.recognize(gesture);
      Log.v("performed", "performed");

      // We want at least one prediction
      if (predictions.size() > 0) {
        Prediction prediction = predictions.get(0);

        // We want at least some confidence in the result
        if (prediction.score > 1.0) {
          if (prediction.name.equalsIgnorecase("right")) {
            //do you thing here//
          }
        }
      }
    }
  }
like image 80
ozmank Avatar answered Oct 20 '22 16:10

ozmank