Reputation: 2050
I'm trying to use gesture builder to recieve up/down and left/right gestures on my app. I followed the guide here (http://www.vogella.com/articles/AndroidGestures/article.html) and it seems to work but isn't quite responding the the gestures correct. It's showing left and right on the overlay in bright yellow (gesture found) but when Toast
creates the pop-up to show the name of gesture recognised it's showing that right/up/down are all recognised or left/up/down are. Also it's doesn't recognise actual swipes up and down as valid gestures (faded out yellow on Overlay).
I've tried re-building the Gesture library using the Gesture Builder several times in case there was an error there but there doesn't seem to be.
The code being used is as per that above link.
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
gTap = new GestureDetector(this,(android.view.GestureDetector.OnGestureListener) this);
//Remove title bar
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
//Define textView
textView1 = (TextView) findViewById(R.id.textView1);
textView2 = (TextView) findViewById(R.id.textView2);
textView3 = (TextView) findViewById(R.id.textView3);
textView4 = (TextView) findViewById(R.id.textView4);
GestureOverlayView gestureOverlayView = new GestureOverlayView(this);
View inflate = getLayoutInflater().inflate(R.layout.main, null);
gestureOverlayView.addView(inflate);
gestureOverlayView.addOnGesturePerformedListener(this);
gestureLib = GestureLibraries.fromRawResource(this, R.raw.gestures);
if (!gestureLib.load()) {
finish();
}
setContentView(gestureOverlayView);
//Load font file
Typeface type = Typeface.createFromAsset(getAssets(),"fonts/optima.ttf");
//Set various textViews to font
textView1.setTypeface(type);
textView2.setTypeface(type);
textView3.setTypeface(type);
textView4.setTypeface(type);
prevPass = "Memorable";
}
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
ArrayList<Prediction> predictions = gestureLib.recognize(gesture);
for (Prediction prediction : predictions) {
if (prediction.score > 1.0) {
Toast.makeText(this, prediction.name, Toast.LENGTH_SHORT)
.show();
}
}
}
Upvotes: 2
Views: 1002