mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-06-27 09:02:59 +02:00
show the aspect ratio at the resolutions dialog too
This commit is contained in:
@ -7,6 +7,7 @@ import android.view.View
|
||||
import com.simplemobiletools.camera.Preview.Companion.config
|
||||
import com.simplemobiletools.camera.R
|
||||
import com.simplemobiletools.camera.activities.SimpleActivity
|
||||
import com.simplemobiletools.camera.extensions.getAspectRatio
|
||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import com.simplemobiletools.commons.models.RadioItem
|
||||
@ -70,7 +71,8 @@ class ChangeResolutionDialog(val activity: SimpleActivity, val isBackCamera: Boo
|
||||
val sorted = resolutions.sortedByDescending { it.width * it.height }
|
||||
sorted.forEachIndexed { index, size ->
|
||||
val megapixels = String.format("%.1f", (size.width * size.height.toFloat()) / 1000000)
|
||||
items.add(RadioItem(index, "${size.width} x ${size.height} ($megapixels MP)"))
|
||||
val aspectRatio = size.getAspectRatio(activity)
|
||||
items.add(RadioItem(index, "${size.width} x ${size.height} ($megapixels MP, $aspectRatio)"))
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
@ -1,8 +1,10 @@
|
||||
package com.simplemobiletools.camera.extensions
|
||||
|
||||
import android.content.Context
|
||||
import android.hardware.Camera
|
||||
import com.simplemobiletools.camera.R
|
||||
|
||||
private val RATIO_TOLERANCE = 0.2f
|
||||
private val RATIO_TOLERANCE = 0.1f
|
||||
|
||||
fun Camera.Size.isSixteenToNine(): Boolean {
|
||||
val selectedRatio = Math.abs(width / height.toFloat())
|
||||
@ -10,3 +12,38 @@ fun Camera.Size.isSixteenToNine(): Boolean {
|
||||
val diff = Math.abs(selectedRatio - checkedRatio)
|
||||
return diff < RATIO_TOLERANCE
|
||||
}
|
||||
|
||||
fun Camera.Size.isFourToThree(): Boolean {
|
||||
val selectedRatio = Math.abs(width / height.toFloat())
|
||||
val checkedRatio = 4 / 3.toFloat()
|
||||
val diff = Math.abs(selectedRatio - checkedRatio)
|
||||
return diff < RATIO_TOLERANCE
|
||||
}
|
||||
|
||||
fun Camera.Size.isThreeToTwo(): Boolean {
|
||||
val selectedRatio = Math.abs(width / height.toFloat())
|
||||
val checkedRatio = 3 / 2.toFloat()
|
||||
val diff = Math.abs(selectedRatio - checkedRatio)
|
||||
return diff < RATIO_TOLERANCE
|
||||
}
|
||||
|
||||
fun Camera.Size.isSixToFive(): Boolean {
|
||||
val selectedRatio = Math.abs(width / height.toFloat())
|
||||
val checkedRatio = 6 / 5.toFloat()
|
||||
val diff = Math.abs(selectedRatio - checkedRatio)
|
||||
return diff < RATIO_TOLERANCE
|
||||
}
|
||||
|
||||
fun Camera.Size.getAspectRatio(context: Context): String {
|
||||
return if (isSixteenToNine()) {
|
||||
"16:9"
|
||||
} else if (isFourToThree()) {
|
||||
"4:3"
|
||||
} else if (isThreeToTwo()) {
|
||||
"3:2"
|
||||
} else if (isSixToFive()) {
|
||||
"6:5"
|
||||
} else {
|
||||
context.resources.getString(R.string.other)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user