I'm developing an app which needs to detect common (double tap, fling, etc) and custom gestures (circle). To achieve this i'm using the GestureOverlayView as you can see in my code:
private GestureDetectorCompat mGestureDetector;
private GestureLibrary mGestureLibrary;
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.main);
mGestureDetector = new GestureDetectorCompat(this, mGestureListener);
mGestureLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
if (!mGestureLibrary.load()) {
Log.e(TAG, "unable to load the custom gestures");
finish();
}
GestureOverlayView gestureOverlay = (GestureOverlayView) findViewById(R.id.gestures_overlay);
gestureOverlay.addOnGesturePerformedListener(mGesturePerformedListener);
}
private final SimpleOnGestureListener mGestureListener = new SimpleOnGestureListener(){
public boolean onDoubleTap(MotionEvent event) {
// DO STUFF
return true;
}
};
private final OnGesturePerformedListener mGesturePerformedListener = new OnGesturePerformedListener() {
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
// DO MORE STUFF
}
};
public boolean onTouchEvent(MotionEvent event){
return mGestureDetector.onTouchEvent(event) || super.onTouchEvent(event);
}
And the layout:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/frame"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<SurfaceView android:id="@+id/camera_preview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.gesture.GestureOverlayView
android:id="@+id/gestures_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gestureColor="#00000000"
android:uncertainGestureColor="#00000000"
android:gestureStrokeType="multiple"
android:eventsInterceptionEnabled="false"/>
</FrameLayout>
I have no problems detecting the custom gestures, but looks like the GestureOverlayView is intercepting the events so the onTouchEvent method isn't reached and the stuff related to the double tap is never executed.
I set the eventsInterceptionEnabled
attribute to false in the GestureOverlayView configuration but the code is still not working.
Any ideas?