Add flag to disable automatic gesture handling (#1068)

* Add flag to disable automatic gesture handling

* Toggle onInterceptTouchEvents based on active gestures instead of adding a new flag

* Add test for gesture toggle
pull/1089/head
Ryan Loebs 4 years ago committed by GitHub
parent a219073468
commit f608ec3918
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraViewTest.java
  2. 10
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.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);

@ -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")

Loading…
Cancel
Save