Use cached orientation in OrientationHelper (#290)

pull/297/head
Artur Artikov 6 years ago committed by Mattia Iavarone
parent 14581075b7
commit ee1d3979f9
  1. 5
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/OrientationHelperTest.java
  2. 2
      cameraview/src/main/utils/com/otaliastudios/cameraview/OrientationHelper.java

@ -90,5 +90,10 @@ public class OrientationHelperTest extends BaseTest {
helper.mListener.onOrientationChanged(270); helper.mListener.onOrientationChanged(270);
assertEquals(helper.getDeviceOrientation(), 270); assertEquals(helper.getDeviceOrientation(), 270);
verify(callback, times(1)).onDeviceOrientationChanged(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);
} }
} }

@ -28,7 +28,7 @@ class OrientationHelper {
public void onOrientationChanged(int orientation) { public void onOrientationChanged(int orientation) {
int or = 0; int or = 0;
if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN) { if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN) {
or = 0; or = mDeviceOrientation != -1 ? mDeviceOrientation : 0;
} else if (orientation >= 315 || orientation < 45) { } else if (orientation >= 315 || orientation < 45) {
or = 0; or = 0;
} else if (orientation >= 45 && orientation < 135) { } else if (orientation >= 45 && orientation < 135) {

Loading…
Cancel
Save