From 85e9f297775886da7ddd0fd1e1e261d70ac47031 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 1 Apr 2018 11:18:28 +0200 Subject: [PATCH] adding some int helper extensions for getting orientation/degrees --- build.gradle | 2 +- .../simplemobiletools/commons/extensions/Int.kt | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 74680233d..a32bd5db5 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { propMinSdkVersion = 16 propTargetSdkVersion = propCompileSdkVersion propVersionCode = 1 - propVersionName = '3.17.19' + propVersionName = '3.17.21' kotlin_version = '1.2.31' support_libs = '27.1.0' } diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Int.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Int.kt index 4ed94c1ff..5d8ce9de7 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Int.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Int.kt @@ -1,6 +1,7 @@ package com.simplemobiletools.commons.extensions import android.graphics.Color +import android.media.ExifInterface import java.util.* fun Int.getContrastColor(): Int { @@ -82,3 +83,17 @@ private fun hsv2hsl(hsv: FloatArray): FloatArray { return floatArrayOf(hue, newSat, newHue / 2f) } + +fun Int.orientationFromDegrees() = when (this) { + 270 -> ExifInterface.ORIENTATION_ROTATE_270 + 180 -> ExifInterface.ORIENTATION_ROTATE_180 + 90 -> ExifInterface.ORIENTATION_ROTATE_90 + else -> ExifInterface.ORIENTATION_NORMAL +}.toString() + +fun Int.degreesFromOrientation() = when (this) { + ExifInterface.ORIENTATION_ROTATE_270 -> 270 + ExifInterface.ORIENTATION_ROTATE_180 -> 180 + ExifInterface.ORIENTATION_ROTATE_90 -> 90 + else -> 0 +}