Search code examples
androidandroid-layoutgesture-recognitionmotion-detectionandroid-gesture

API or method to convert gesture to text in android


I am developing an application which will take gestures and convert those gestures to according text and store them in database. I want to know if there is any Android API or method for this task.


Solution

  • You can use a GestureDetector that generates String when a gesture is detected.

    For example use OnGestureListener callbacks :

    // From inside some Context (View, Activity, ...)
    GestureDectector detector = new GestureDetector(this, new OnGestureListener() {
    
        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            gestureDetected("FLING"); // 'gestureDetected' is then a callback to invoke on 'conversion of a gesture into a string'
        }
    });
    

    Then MotionEvent have to be 'forwarded' to the GestureDetector, for example by overriding View.onTouchEvent(MotionEvent) :

    public boolean onTouchEvent(MotionEvent event) {
        return detector.onTouchEvent(event);
    }