Android API class GestureRecognition

edited February 2014 in Android Mode

Greetings,

So I had attempted to incorporate the ketai library within my program, but due to sporadic crashes.. felt I should access the Android API directly. I am trying to print out the velocity of a swipe gesture, but am having issues printing results. Everything compiles fine, but I'm not sure what I am overseeing. Code below:

import android.app.Activity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.MotionEvent;

 GestureDetector gestureDetector;
   View.OnTouchListener gestureListener;

void mouseDragged()
{



   runOnUiThread(new Runnable() {
    @ Override
    public void run() {
      //Initialize the recognizer on the UI thread
      gestureVal();

    }
  });


}

void gestureVal(){

   gestureDetector = new GestureDetector(this, new MyGestureDetector());
        gestureListener = new View.OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                return gestureDetector.onTouchEvent(event);
            }

        };

}

    public class MyGestureDetector extends SimpleOnGestureListener {
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
          println("VELOCITY X = " + velocityX);
          return true;

        }

    }

Answers

  • What issue do you face? Is there an error message or (even better!) a stack trace?

  • Nothing. Compiles fine, without any errors. I'm going by the print message, though. (its not printing )

  • You create class MyGestureDetector, but you never instantiate the class. For use, see Google's GestureDetector docs.

  • I thought I was instantiating a new class object from within my gestureVal() function , and calling it into the loop? I looked at the API, and from what I gathered, I am a bit lost on what I am doing wrong exactly.

Sign In or Register to comment.