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
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//
}
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With