From 690481663272ee4cce5dd7670edfe7b0b33a5f85 Mon Sep 17 00:00:00 2001 From: Arne Coucheron Date: Mon, 14 Aug 2017 17:02:03 +0200 Subject: Snap: Fix panorama layout Loosely based on old cyngn patches. Change-Id: I7fdb6ba82243f2f28e8ea655f83f0339d49de5ad --- .../android/camera/WideAnglePanoramaModule.java | 1 + src/com/android/camera/WideAnglePanoramaUI.java | 45 ++++++++++++++++++---- src/com/android/camera/ui/CameraControls.java | 2 +- 3 files changed, 39 insertions(+), 9 deletions(-) (limited to 'src/com/android/camera') diff --git a/src/com/android/camera/WideAnglePanoramaModule.java b/src/com/android/camera/WideAnglePanoramaModule.java index c257661ca..0e7d0805d 100644 --- a/src/com/android/camera/WideAnglePanoramaModule.java +++ b/src/com/android/camera/WideAnglePanoramaModule.java @@ -458,6 +458,7 @@ public class WideAnglePanoramaModule Log.d(TAG, "camera preview h = " + mCameraPreviewHeight + " , w = " + mCameraPreviewWidth); parameters.setPreviewSize(mCameraPreviewWidth, mCameraPreviewHeight); + mUI.setPreviewSize(mCameraPreviewWidth, mCameraPreviewHeight); List frameRates = parameters.getSupportedPreviewFpsRange(); int last = frameRates.size() - 1; diff --git a/src/com/android/camera/WideAnglePanoramaUI.java b/src/com/android/camera/WideAnglePanoramaUI.java index 99b08b9b5..f3b30db1c 100644 --- a/src/com/android/camera/WideAnglePanoramaUI.java +++ b/src/com/android/camera/WideAnglePanoramaUI.java @@ -108,6 +108,10 @@ public class WideAnglePanoramaUI implements private RotateLayout mPanoFailedDialog; private Button mPanoFailedButton; + private int mTopMargin = 0; + private int mBottomMargin = 0; + private float mAspectRatio = 1.0f; + /** Constructor. */ public WideAnglePanoramaUI( CameraActivity activity, @@ -144,6 +148,14 @@ public class WideAnglePanoramaUI implements muteButton.setVisibility(View.GONE); } + private void calculateMargins(Point size) { + int l = size.x > size.y ? size.x : size.y; + int tm = mActivity.getResources().getDimensionPixelSize(R.dimen.preview_top_margin); + int bm = mActivity.getResources().getDimensionPixelSize(R.dimen.preview_bottom_margin); + mTopMargin = l / 4 * tm / (tm + bm); + mBottomMargin = l / 4 - mTopMargin; + } + public void onStartCapture() { hideSwitcher(); mShutterButton.setImageResource(R.drawable.shutter_button_stop); @@ -363,16 +375,19 @@ public class WideAnglePanoramaUI implements Display display = mActivity.getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size); + mActivity.getWindowManager().getDefaultDisplay().getRealSize(size); + calculateMargins(size); + mCameraControls.setMargins(mTopMargin, mBottomMargin); int width = size.x; - int height = size.y; + int height = size.y - mTopMargin - mBottomMargin; int xOffset = 0; int yOffset = 0; int w = width; int h = height; h = w * 4 / 3; - yOffset = (height - h) / 2; + yOffset = (height - h) / 2 + mTopMargin; FrameLayout.LayoutParams param = new FrameLayout.LayoutParams(w, h); mTextureView.setLayoutParams(param); @@ -383,12 +398,7 @@ public class WideAnglePanoramaUI implements mPreviewBorder.setY(yOffset); mPreviewYOffset = yOffset; - int t = mPreviewYOffset; - int b1 = mTextureView.getBottom() - mPreviewYOffset; - int r = mTextureView.getRight(); - int b2 = mTextureView.getBottom(); - - mCameraControls.setPreviewRatio(1.0f, true); + mTextureView.layout(0, mPreviewYOffset, mTextureView.getRight(), mTextureView.getBottom()); } public void resetSavingProgress() { @@ -711,4 +721,23 @@ public class WideAnglePanoramaUI implements mPreviewCover.setVisibility(View.GONE); } } + + public void setPreviewSize(int width, int height) { + if (width == 0 || height == 0) { + Log.w(TAG, "Preview size should not be 0."); + return; + } + float ratio; + if (width > height) { + ratio = (float) width / height; + } else { + ratio = (float) height / width; + } + + if (ratio != mAspectRatio) { + mAspectRatio = ratio; + } + + mCameraControls.setPreviewRatio(mAspectRatio, false); + } } diff --git a/src/com/android/camera/ui/CameraControls.java b/src/com/android/camera/ui/CameraControls.java index db93c0edb..54355078c 100755 --- a/src/com/android/camera/ui/CameraControls.java +++ b/src/com/android/camera/ui/CameraControls.java @@ -1066,7 +1066,7 @@ public class CameraControls extends RotatableLayout { mPaint.setColor(getResources().getColor(R.color.camera_control_bg_transparent)); } } - invalidate(); + requestLayout(); } public void showRefocusToast(boolean show) { -- cgit v1.2.3