diff --git a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraViewTest.java b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraViewTest.java index 4ee81244..30be1f6f 100644 --- a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraViewTest.java +++ b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraViewTest.java @@ -216,6 +216,17 @@ public class CameraViewTest extends BaseTest { assertEquals(cameraView.getGestureAction(Gesture.PINCH), GestureAction.NONE); } + @Test + public void testGesture_enabled() { + // Ensure touch events are intercepted when at least one gesture is set + cameraView.mapGesture(Gesture.PINCH, GestureAction.ZOOM); + assertTrue(cameraView.onInterceptTouchEvent(null)); + + // Ensure touch events are NOT intercepted when no gestures are set + cameraView.clearGesture(Gesture.PINCH); + assertFalse(cameraView.onInterceptTouchEvent(null)); + } + @Test public void testGesture_enablingDisablingLayouts() { cameraView.clearGesture(Gesture.TAP); diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java index f3fd9de8..656a2a43 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java @@ -133,6 +133,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver { private Engine mEngine; private Filter mPendingFilter; private int mFrameProcessingExecutors; + private int mActiveGestures; // Components private Handler mUiHandler; @@ -605,6 +606,12 @@ public class CameraView extends FrameLayout implements LifecycleObserver { mGestureMap.get(Gesture.SCROLL_VERTICAL) != none); break; } + + mActiveGestures = 0; + for(GestureAction act : mGestureMap.values()) { + mActiveGestures += act == GestureAction.NONE ? 0 : 1; + } + return true; } mapGesture(gesture, none); @@ -633,7 +640,8 @@ public class CameraView extends FrameLayout implements LifecycleObserver { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { - return true; // Steal our own events. + // Steal our own events if gestures are enabled + return mActiveGestures > 0; } @SuppressLint("ClickableViewAccessibility")