include swipe and shutter callback

* Swipe Left and Right callback on CameraListener.
* Shutter event callback on CameraListener.
pull/1030/head
EzequielAdrianM 5 years ago
parent 5d10277d7b
commit 394c3c9c40
  1. 26
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraListener.java
  2. 21
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
  3. 15
      demo/src/main/kotlin/com/otaliastudios/cameraview/demo/CameraActivity.kt

@ -161,4 +161,28 @@ public abstract class CameraListener {
}
}
/**
* Notifies that the shutter event is happening. You can update UI to show some
* trigger effect, so user visually confirms that picture is being taken
* or video recording is about to start.
*/
@UiThread
public void onShutter() {}
/**
* Notifies that a finger gesture just triggered a swipe left event.
* This can be used to exchange between different filters or to
* swap between front and back cameras.
*/
@UiThread
public void onSwipeLeft() {}
/**
* Notifies that a finger gesture just triggered a swipe right event.
* This can be used to exchange between different filters or to
* swap between front and back cameras.
*/
@UiThread
public void onSwipeRight() {}
}

@ -152,6 +152,8 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
@VisibleForTesting PinchGestureFinder mPinchGestureFinder;
@VisibleForTesting TapGestureFinder mTapGestureFinder;
@VisibleForTesting ScrollGestureFinder mScrollGestureFinder;
private float x1,x2;
static final int MIN_SWIPE_DISTANCE = 150;
// Views
@VisibleForTesting GridLinesLayout mGridLinesLayout;
@ -655,6 +657,22 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
onGesture(mTapGestureFinder, options);
}
if(event.getAction() == MotionEvent.ACTION_DOWN) x1 = event.getX();
if(event.getAction() == MotionEvent.ACTION_UP) {
x2 = event.getX();
float deltaX = x2 - x1;
if(deltaX > MIN_SWIPE_DISTANCE) {
for (CameraListener listener : mListeners) {
listener.onSwipeRight();
}
}
if (deltaX < MIN_SWIPE_DISTANCE) {
for (CameraListener listener : mListeners) {
listener.onSwipeLeft();
}
}
}
return true;
}
@ -2228,6 +2246,9 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
if (shouldPlaySound && mPlaySounds) {
playSound(MediaActionSound.SHUTTER_CLICK);
}
for (CameraListener listener : mListeners) {
listener.onShutter();
}
}
@Override

@ -221,6 +221,21 @@ class CameraActivity : AppCompatActivity(), View.OnClickListener, OptionView.Cal
super.onZoomChanged(newValue, bounds, fingers)
message("Zoom:$newValue", false)
}
override fun onShutter() {
super.onShutter()
LOG.w("Shutter Triggered!")
}
override fun onSwipeLeft() {
super.onSwipeLeft()
LOG.w("Swipe Left!")
}
override fun onSwipeRight() {
super.onSwipeRight()
LOG.w("Swipe Right!")
}
}
override fun onClick(view: View) {

Loading…
Cancel
Save