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 @Override
boolean shouldFlipSizes() { boolean shouldFlipSizes() {
return mSensorOffset % 180 != 0; return (mDeviceOrientation + mSensorOffset) % 180 != 0;
} }
@Override @Override

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

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

Loading…
Cancel
Save