Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing Gesture Recognition In An Android App

I am adding gesture recognition to my app. I have added the view as described in the Android Developers Gestures article but when it comes to adding:

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

where do I put this in my code, do I have to create a new class for it, or can I have it in an inner class, or does it not need a class at all?! I have a set up similar to Lunar Lander which comprises of two files, one of which is a thread that handles pretty much all the physics and drawing of the game. The other file begins the thread and saveInstanceState method.

Furthermore, what type is mLibrary?! I cannot find out anywhere!!

I imagine I will put the OnGesturePerformed method in my thread as this is where I handle all keyUp and Down events.

like image 737
Darius Avatar asked Apr 09 '26 14:04

Darius


1 Answers

Read this article: http://developer.android.com/design/patterns/gestures.html.

After that piece of code you can see that you have to implement a listener.

public class GesturesActivity extends Activity implements OnGesturePerformedListener {
public void onCreate(Bundle savedInstanceState) {
    ..
}
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
    //do the stuff you want ;)
}

For a complete example download this. http://code.google.com/p/apps-for-android/downloads/detail?name=GesturesDemos.zip&can=2&q=#makechanges

like image 198
fmo Avatar answered Apr 11 '26 04:04

fmo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!