use the selected resolution as preview, if nothing better is found

This commit is contained in:
tibbi 2018-07-10 11:41:29 +02:00
parent cf64374411
commit 63d228a50e
2 changed files with 11 additions and 4 deletions

View File

@ -1,6 +1,9 @@
package com.simplemobiletools.camera.models
import android.annotation.TargetApi
import android.content.Context
import android.os.Build
import android.util.Size
import com.simplemobiletools.camera.R
data class MySize(val width: Int, val height: Int) {
@ -41,4 +44,7 @@ data class MySize(val width: Int, val height: Int) {
isTwoToOne() -> "2:1"
else -> context.resources.getString(R.string.other)
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
fun toSize() = Size(width, height)
}

View File

@ -369,6 +369,7 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
} else {
configMap.getOutputSizes(SurfaceTexture::class.java)
}
mPreviewSize = chooseOptimalPreviewSize(outputSizes, rotatedPreviewWidth, rotatedPreviewHeight, maxPreviewWidth, maxPreviewHeight, currentResolution)
mActivity.runOnUiThread {
@ -388,11 +389,11 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
}
}
private fun chooseOptimalPreviewSize(choices: Array<Size>, textureViewWidth: Int, textureViewHeight: Int, maxWidth: Int, maxHeight: Int, aspectRatio: MySize): Size {
private fun chooseOptimalPreviewSize(choices: Array<Size>, textureViewWidth: Int, textureViewHeight: Int, maxWidth: Int, maxHeight: Int, selectedResolution: MySize): Size {
val bigEnough = ArrayList<Size>()
val notBigEnough = ArrayList<Size>()
val width = aspectRatio.width
val height = aspectRatio.height
val width = selectedResolution.width
val height = selectedResolution.height
for (option in choices) {
if (option.width <= maxWidth && option.height <= maxHeight && option.height == option.width * height / width) {
if (option.width >= textureViewWidth && option.height >= textureViewHeight) {
@ -406,7 +407,7 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
return when {
bigEnough.isNotEmpty() -> bigEnough.minBy { it.width * it.height }!!
notBigEnough.isNotEmpty() -> notBigEnough.maxBy { it.width * it.height }!!
else -> choices.first()
else -> selectedResolution.toSize()
}
}