From e04fb369a683faa556af8471a03707028ce133ea Mon Sep 17 00:00:00 2001 From: android-dataticket Date: Thu, 9 Mar 2017 14:53:48 -0800 Subject: [PATCH] Update CameraView.java --- .../com/flurgle/camerakit/CameraView.java | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/camerakit/src/main/java/com/flurgle/camerakit/CameraView.java b/camerakit/src/main/java/com/flurgle/camerakit/CameraView.java index 9044ef91..a36e4e05 100644 --- a/camerakit/src/main/java/com/flurgle/camerakit/CameraView.java +++ b/camerakit/src/main/java/com/flurgle/camerakit/CameraView.java @@ -122,23 +122,28 @@ public class CameraView extends FrameLayout { protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (mAdjustViewBounds) { Size previewSize = getPreviewSize(); - if (getLayoutParams().width == LayoutParams.WRAP_CONTENT) { - int height = MeasureSpec.getSize(heightMeasureSpec); - float ratio = (float) height / (float) previewSize.getWidth(); - int width = (int) (previewSize.getHeight() * ratio); - super.onMeasure( - MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), - heightMeasureSpec - ); - return; - } else if (getLayoutParams().height == LayoutParams.WRAP_CONTENT) { - int width = MeasureSpec.getSize(widthMeasureSpec); - float ratio = (float) width / (float) previewSize.getHeight(); - int height = (int) (previewSize.getWidth() * ratio); - super.onMeasure( - widthMeasureSpec, - MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY) - ); + if(previewSize != null) { + if (getLayoutParams().width == LayoutParams.WRAP_CONTENT) { + int height = MeasureSpec.getSize(heightMeasureSpec); + float ratio = (float) height / (float) previewSize.getWidth(); + int width = (int) (previewSize.getHeight() * ratio); + super.onMeasure( + MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), + heightMeasureSpec + ); + return; + } else if (getLayoutParams().height == LayoutParams.WRAP_CONTENT) { + int width = MeasureSpec.getSize(widthMeasureSpec); + float ratio = (float) width / (float) previewSize.getHeight(); + int height = (int) (previewSize.getWidth() * ratio); + super.onMeasure( + widthMeasureSpec, + MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY) + ); + return; + } + }else{ + super.onMeasure(widthMeasureSpec, heightMeasureSpec); return; } }