Implementing Gesture Recognition In An Android App
I am adding gesture re开发者_开发问答cognition 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.
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
精彩评论