diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/Config.kt b/app/src/main/kotlin/com/simplemobiletools/camera/Config.kt index 86d0600d..d2959c2f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/Config.kt @@ -39,7 +39,7 @@ class Config(context: Context) : BaseConfig(context) { set(enabled) = prefs.edit().putBoolean(LAST_FLASHLIGHT_STATE, enabled).apply() var backPhotoResIndex: Int - get() = prefs.getInt(BACK_PHOTO_RESOLUTION_INDEX, 0) + get() = prefs.getInt(BACK_PHOTO_RESOLUTION_INDEX, -1) set(backPhotoResIndex) = prefs.edit().putInt(BACK_PHOTO_RESOLUTION_INDEX, backPhotoResIndex).apply() var backVideoResIndex: Int diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/Preview.kt b/app/src/main/kotlin/com/simplemobiletools/camera/Preview.kt index 9dc8320f..ea4ac505 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/Preview.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/Preview.kt @@ -164,13 +164,17 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan } private fun getSelectedResolution(): Camera.Size { - val index = getResolutionIndex() + var index = getResolutionIndex() val resolutions = if (mIsVideoMode) { mParameters!!.supportedVideoSizes ?: mParameters!!.supportedPreviewSizes } else { mParameters!!.supportedPictureSizes }.sortedByDescending { it.width * it.height } + if (index == -1) { + index = getDefaultFullscreenResolution(resolutions) ?: 0 + } + return resolutions[index] } @@ -183,6 +187,18 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan } } + private fun getDefaultFullscreenResolution(resolutions: List): Int? { + val screenAspectRatio = mActivity.realScreenSize.y / mActivity.realScreenSize.x.toFloat() + resolutions.forEachIndexed { index, size -> + val diff = screenAspectRatio - (size.width / size.height.toFloat()) + if (Math.abs(diff) < RATIO_TOLERANCE) { + config.backPhotoResIndex = index + return index + } + } + return null + } + fun setTargetUri(uri: Uri) { mTargetUri = uri } diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/extensions/size.kt b/app/src/main/kotlin/com/simplemobiletools/camera/extensions/size.kt index b329ae31..f34cfb49 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/extensions/size.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/extensions/size.kt @@ -4,7 +4,7 @@ import android.content.Context import android.hardware.Camera import com.simplemobiletools.camera.R -private val RATIO_TOLERANCE = 0.1f +val RATIO_TOLERANCE = 0.1f fun Camera.Size.isSixteenToNine(): Boolean { val selectedRatio = Math.abs(width / height.toFloat())