From ee1d3979f9ff23767a1a2ab8d2da855d53a1188a Mon Sep 17 00:00:00 2001 From: Artur Artikov Date: Fri, 19 Oct 2018 17:51:09 +0700 Subject: [PATCH] Use cached orientation in OrientationHelper (#290) --- .../com/otaliastudios/cameraview/OrientationHelperTest.java | 5 +++++ .../com/otaliastudios/cameraview/OrientationHelper.java | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/OrientationHelperTest.java b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/OrientationHelperTest.java index d2e0cea4..f4d66425 100644 --- a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/OrientationHelperTest.java +++ b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/OrientationHelperTest.java @@ -90,5 +90,10 @@ public class OrientationHelperTest extends BaseTest { helper.mListener.onOrientationChanged(270); assertEquals(helper.getDeviceOrientation(), 270); verify(callback, times(1)).onDeviceOrientationChanged(270); + + // It is still 270 after ORIENTATION_UNKNOWN + helper.mListener.onOrientationChanged(OrientationEventListener.ORIENTATION_UNKNOWN); + assertEquals(helper.getDeviceOrientation(), 270); + verify(callback, times(1)).onDeviceOrientationChanged(270); } } diff --git a/cameraview/src/main/utils/com/otaliastudios/cameraview/OrientationHelper.java b/cameraview/src/main/utils/com/otaliastudios/cameraview/OrientationHelper.java index 8006d095..e104590c 100644 --- a/cameraview/src/main/utils/com/otaliastudios/cameraview/OrientationHelper.java +++ b/cameraview/src/main/utils/com/otaliastudios/cameraview/OrientationHelper.java @@ -28,7 +28,7 @@ class OrientationHelper { public void onOrientationChanged(int orientation) { int or = 0; if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN) { - or = 0; + or = mDeviceOrientation != -1 ? mDeviceOrientation : 0; } else if (orientation >= 315 || orientation < 45) { or = 0; } else if (orientation >= 45 && orientation < 135) {