Fix for #927 OrientationHelper.enable() called twice (#928)

* Update OrientationHelper.java

Fixed issue #927 Added boolean to prevent listener activating multiple times.

* Update CameraView.java

Added disable() of the orientation helper class in onPause.

* Update OrientationHelper.java

Co-authored-by: Mattia Iavarone <mat.iavarone@gmail.com>
pull/954/head
thijsonline 4 years ago committed by GitHub
parent 170d87ed39
commit daf7a0bf44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
  2. 9
      cameraview/src/main/java/com/otaliastudios/cameraview/internal/OrientationHelper.java

@ -855,6 +855,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
public void close() {
if (mInEditor) return;
mOrientationHelper.disable();
mCameraEngine.stop(false);
if (mCameraPreview != null) mCameraPreview.onPause();
}

@ -37,6 +37,8 @@ public class OrientationHelper {
@VisibleForTesting
final DisplayManager.DisplayListener mDisplayOffsetListener;
private int mDisplayOffset = -1;
private boolean mEnabled;
/**
* Creates a new orientation helper.
@ -97,6 +99,11 @@ public class OrientationHelper {
* Enables this listener.
*/
public void enable() {
if (mEnabled) {
//already enabled, will ignore call
return;
}
mEnabled = true;
mDisplayOffset = findDisplayOffset();
if (Build.VERSION.SDK_INT >= 17) {
DisplayManager manager = (DisplayManager)
@ -110,6 +117,8 @@ public class OrientationHelper {
* Disables this listener.
*/
public void disable() {
if (!mEnabled) return;
mEnabled = false;
mDeviceOrientationListener.disable();
if (Build.VERSION.SDK_INT >= 17) {
DisplayManager manager = (DisplayManager)

Loading…
Cancel
Save