diff --git a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/OrientationHelperTest.java b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/OrientationHelperTest.java index d2e0cea46..f4d664251 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 void testRotation() { 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 8006d0950..e104590c7 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 @@ interface Callback { 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) {