Fixed bug with preview stretch on orientation change (#23)

* #20 Fixed bug with preview stretch on orientation change

* Changed OrientationHelper
pull/25/head
Andrew 7 years ago committed by Mattia Iavarone
parent a693ad9425
commit 51f90275f5
  1. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java
  2. 6
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
  3. 7
      cameraview/src/main/utils/com/otaliastudios/cameraview/OrientationHelper.java

@ -449,7 +449,7 @@ class Camera1 extends CameraController {
@Override
boolean shouldFlipSizes() {
return mSensorOffset % 180 != 0;
return (mDeviceOrientation + mSensorOffset) % 180 != 0;
}
@Override

@ -22,6 +22,7 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Display;
import android.view.MotionEvent;
import android.view.ViewGroup;
import android.view.WindowManager;
@ -169,8 +170,7 @@ public class CameraView extends FrameLayout {
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (!isInEditMode()) {
WindowManager manager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
mOrientationHelper.enable(manager.getDefaultDisplay());
mOrientationHelper.enable(getContext());
}
}
@ -487,6 +487,8 @@ public class CameraView extends FrameLayout {
if (checkPermissions(getSessionType())) {
mIsStarted = true;
// Update display orientation for current CameraController
mOrientationHelper.enable(getContext());
mCameraController.start();
}
}

@ -7,6 +7,7 @@ import android.util.SparseIntArray;
import android.view.Display;
import android.view.OrientationEventListener;
import android.view.Surface;
import android.view.WindowManager;
class OrientationHelper {
@ -67,10 +68,10 @@ class OrientationHelper {
};
}
void enable(Display display) {
mDisplay = display;
void enable(Context context) {
mDisplay = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
mListener.enable();
mLastKnownDisplayOffset = DISPLAY_ORIENTATIONS.get(display.getRotation());
mLastKnownDisplayOffset = DISPLAY_ORIENTATIONS.get(mDisplay.getRotation());
mCallbacks.onDisplayOffsetChanged(mLastKnownDisplayOffset);
}

Loading…
Cancel
Save