From ebbc1c56474c51a8f404dc4ce58689fed71b90c0 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 12 Jul 2016 16:36:43 +0200 Subject: [PATCH] get the proper video preview size at switching to video mode --- .../com/simplemobiletools/camera/Preview.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/simplemobiletools/camera/Preview.java b/app/src/main/java/com/simplemobiletools/camera/Preview.java index 6c279279..5f91d9d7 100644 --- a/app/src/main/java/com/simplemobiletools/camera/Preview.java +++ b/app/src/main/java/com/simplemobiletools/camera/Preview.java @@ -300,12 +300,12 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O } private Camera.Size getOptimalVideoSize() { - final List sizes = mParameters.getSupportedVideoSizes(); + final List sizes = getSupportedVideoSizes(); Collections.sort(sizes, new SizesComparator()); Camera.Size maxSize = sizes.get(0); for (Camera.Size size : sizes) { - final boolean isSixteenToNine = isProperRatio(size); - if (isSixteenToNine) { + final boolean isProperRatio = isProperRatio(size); + if (isProperRatio) { maxSize = size; break; } @@ -313,6 +313,14 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O return maxSize; } + public List getSupportedVideoSizes() { + if (mParameters.getSupportedVideoSizes() != null) { + return mParameters.getSupportedVideoSizes(); + } else { + return mParameters.getSupportedPreviewSizes(); + } + } + private int compensateDeviceRotation() { int degrees = 0; boolean isFrontCamera = (mCurrCameraId == Camera.CameraInfo.CAMERA_FACING_FRONT); @@ -549,9 +557,12 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O return false; mSwitchToVideoAsap = false; - final Camera.Size preferred = mParameters.getPreferredPreviewSizeForVideo(); - if (preferred == null) - return false; + Camera.Size preferred = mParameters.getPreferredPreviewSizeForVideo(); + if (preferred == null) { + final List previewSizes = mParameters.getSupportedPreviewSizes(); + Collections.sort(previewSizes, new SizesComparator()); + preferred = previewSizes.get(0); + } mParameters.setPreviewSize(preferred.width, preferred.height); mCamera.setParameters(mParameters);