add a couple more resolution aspect ratios

This commit is contained in:
tibbi 2017-09-26 19:52:26 +02:00
parent 7386cc557c
commit 36a4aeb43e
1 changed files with 22 additions and 0 deletions

View File

@ -13,6 +13,13 @@ fun Camera.Size.isSixteenToNine(): Boolean {
return diff < RATIO_TOLERANCE return diff < RATIO_TOLERANCE
} }
fun Camera.Size.isFiveToThree(): Boolean {
val selectedRatio = Math.abs(width / height.toFloat())
val checkedRatio = 5 / 3.toFloat()
val diff = Math.abs(selectedRatio - checkedRatio)
return diff < RATIO_TOLERANCE
}
fun Camera.Size.isFourToThree(): Boolean { fun Camera.Size.isFourToThree(): Boolean {
val selectedRatio = Math.abs(width / height.toFloat()) val selectedRatio = Math.abs(width / height.toFloat())
val checkedRatio = 4 / 3.toFloat() val checkedRatio = 4 / 3.toFloat()
@ -20,6 +27,13 @@ fun Camera.Size.isFourToThree(): Boolean {
return diff < RATIO_TOLERANCE return diff < RATIO_TOLERANCE
} }
fun Camera.Size.isThreeToFour(): Boolean {
val selectedRatio = Math.abs(width / height.toFloat())
val checkedRatio = 3 / 4.toFloat()
val diff = Math.abs(selectedRatio - checkedRatio)
return diff < RATIO_TOLERANCE
}
fun Camera.Size.isThreeToTwo(): Boolean { fun Camera.Size.isThreeToTwo(): Boolean {
val selectedRatio = Math.abs(width / height.toFloat()) val selectedRatio = Math.abs(width / height.toFloat())
val checkedRatio = 3 / 2.toFloat() val checkedRatio = 3 / 2.toFloat()
@ -34,10 +48,18 @@ fun Camera.Size.isSixToFive(): Boolean {
return diff < RATIO_TOLERANCE return diff < RATIO_TOLERANCE
} }
fun Camera.Size.isOneNineToOne() = Math.abs(1.9 - (width / height.toFloat())) < RATIO_TOLERANCE
fun Camera.Size.isSquare() = width == height
fun Camera.Size.getAspectRatio(context: Context) = when { fun Camera.Size.getAspectRatio(context: Context) = when {
isSixteenToNine() -> "16:9" isSixteenToNine() -> "16:9"
isFiveToThree() -> "5:3"
isFourToThree() -> "4:3" isFourToThree() -> "4:3"
isThreeToFour() -> "3:4"
isThreeToTwo() -> "3:2" isThreeToTwo() -> "3:2"
isSixToFive() -> "6:5" isSixToFive() -> "6:5"
isOneNineToOne() -> "1.9:1"
isSquare() -> "1:1"
else -> context.resources.getString(R.string.other) else -> context.resources.getString(R.string.other)
} }