try filling the screen with the default back camera photo resolution

This commit is contained in:
tibbi 2017-03-22 20:12:57 +01:00
parent e84ab36c79
commit 586890b5e9
3 changed files with 19 additions and 3 deletions

View File

@ -39,7 +39,7 @@ class Config(context: Context) : BaseConfig(context) {
set(enabled) = prefs.edit().putBoolean(LAST_FLASHLIGHT_STATE, enabled).apply() set(enabled) = prefs.edit().putBoolean(LAST_FLASHLIGHT_STATE, enabled).apply()
var backPhotoResIndex: Int 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() set(backPhotoResIndex) = prefs.edit().putInt(BACK_PHOTO_RESOLUTION_INDEX, backPhotoResIndex).apply()
var backVideoResIndex: Int var backVideoResIndex: Int

View File

@ -164,13 +164,17 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
} }
private fun getSelectedResolution(): Camera.Size { private fun getSelectedResolution(): Camera.Size {
val index = getResolutionIndex() var index = getResolutionIndex()
val resolutions = if (mIsVideoMode) { val resolutions = if (mIsVideoMode) {
mParameters!!.supportedVideoSizes ?: mParameters!!.supportedPreviewSizes mParameters!!.supportedVideoSizes ?: mParameters!!.supportedPreviewSizes
} else { } else {
mParameters!!.supportedPictureSizes mParameters!!.supportedPictureSizes
}.sortedByDescending { it.width * it.height } }.sortedByDescending { it.width * it.height }
if (index == -1) {
index = getDefaultFullscreenResolution(resolutions) ?: 0
}
return resolutions[index] return resolutions[index]
} }
@ -183,6 +187,18 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
} }
} }
private fun getDefaultFullscreenResolution(resolutions: List<Camera.Size>): 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) { fun setTargetUri(uri: Uri) {
mTargetUri = uri mTargetUri = uri
} }

View File

@ -4,7 +4,7 @@ import android.content.Context
import android.hardware.Camera import android.hardware.Camera
import com.simplemobiletools.camera.R import com.simplemobiletools.camera.R
private val RATIO_TOLERANCE = 0.1f val RATIO_TOLERANCE = 0.1f
fun Camera.Size.isSixteenToNine(): Boolean { fun Camera.Size.isSixteenToNine(): Boolean {
val selectedRatio = Math.abs(width / height.toFloat()) val selectedRatio = Math.abs(width / height.toFloat())