From 36a4aeb43ec444588b083c17d5c3a1905df7e3b4 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 26 Sep 2017 19:52:26 +0200 Subject: [PATCH] add a couple more resolution aspect ratios --- .../camera/extensions/size.kt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) 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 94a0c31e..ecf8ffa8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/extensions/size.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/extensions/size.kt @@ -13,6 +13,13 @@ fun Camera.Size.isSixteenToNine(): Boolean { 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 { val selectedRatio = Math.abs(width / height.toFloat()) val checkedRatio = 4 / 3.toFloat() @@ -20,6 +27,13 @@ fun Camera.Size.isFourToThree(): Boolean { 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 { val selectedRatio = Math.abs(width / height.toFloat()) val checkedRatio = 3 / 2.toFloat() @@ -34,10 +48,18 @@ fun Camera.Size.isSixToFive(): Boolean { 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 { isSixteenToNine() -> "16:9" + isFiveToThree() -> "5:3" isFourToThree() -> "4:3" + isThreeToFour() -> "3:4" isThreeToTwo() -> "3:2" isSixToFive() -> "6:5" + isOneNineToOne() -> "1.9:1" + isSquare() -> "1:1" else -> context.resources.getString(R.string.other) }