From 4a13d766f0711366ed682f87284038d4b42d9e45 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 21 Mar 2017 21:23:15 +0100 Subject: [PATCH] recheck the previews aspect ratio on resolution change --- .../com/simplemobiletools/camera/Preview.kt | 19 ++++++++++++------- .../camera/dialogs/ChangeResolutionDialog.kt | 1 + 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/Preview.kt b/app/src/main/kotlin/com/simplemobiletools/camera/Preview.kt index b0237e26..316d2c24 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/Preview.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/Preview.kt @@ -132,10 +132,7 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan mMaxZoom = mParameters!!.maxZoom mZoomRatios = mParameters!!.zoomRatios mSupportedPreviewSizes = mParameters!!.supportedPreviewSizes.sortedByDescending { it.width * it.height } - mIsSixteenToNine = isSixteenToNine() - requestLayout() - invalidate() - mSetupPreviewAfterMeasure = true + refreshPreview() val focusModes = mParameters!!.supportedFocusModes if (focusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) @@ -163,6 +160,13 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan return true } + private fun refreshPreview() { + mIsSixteenToNine = isSixteenToNine() + mSetupPreviewAfterMeasure = true + requestLayout() + invalidate() + } + private fun isSixteenToNine(): Boolean { val selectedSize = getSelectedResolution() val selectedRatio = Math.abs(selectedSize.width / selectedSize.height.toFloat()) @@ -287,8 +291,6 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan mCanTakePicture = true } - fun getSupportedVideoSizes(): List = mParameters!!.supportedVideoSizes ?: mParameters!!.supportedPreviewSizes - private fun focusArea(takePictureAfter: Boolean) { if (mCamera == null) return @@ -332,9 +334,12 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan } fun showChangeResolutionDialog() { + val oldResolution = getSelectedResolution() if (mCamera != null) { ChangeResolutionDialog(mActivity, config.lastUsedCamera == Camera.CameraInfo.CAMERA_FACING_BACK, mCamera!!) { - + if (oldResolution != getSelectedResolution()) { + refreshPreview() + } } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/dialogs/ChangeResolutionDialog.kt b/app/src/main/kotlin/com/simplemobiletools/camera/dialogs/ChangeResolutionDialog.kt index d4eecdfa..0fcfdaf7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/dialogs/ChangeResolutionDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/dialogs/ChangeResolutionDialog.kt @@ -21,6 +21,7 @@ class ChangeResolutionDialog(val activity: SimpleActivity, val isBackCamera: Boo AlertDialog.Builder(activity) .setPositiveButton(R.string.ok, null) + .setOnDismissListener { callback() } .create().apply { activity.setupDialogStuff(view, this, if (isBackCamera) R.string.back_camera else R.string.front_camera) }