From 9858a149eaeca1ceb8101fc19ec584173fc600ab Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 20 Feb 2018 23:20:34 +0100 Subject: [PATCH] properly determine image width and height at rotation by aspect ratio --- .../gallery/activities/ViewPagerActivity.kt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index b63add956..2abb43dee 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -826,10 +826,20 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun checkOrientation() { if (!mIsOrientationLocked && config.screenRotation == ROTATE_BY_ASPECT_RATIO) { + var flipSides = false + try { + val pathToLoad = getCurrentPath() + val exif = android.media.ExifInterface(pathToLoad) + val orientation = exif.getAttributeInt(android.media.ExifInterface.TAG_ORIENTATION, -1) + flipSides = orientation == ExifInterface.ORIENTATION_ROTATE_90 || orientation == ExifInterface.ORIENTATION_ROTATE_270 + } catch (e: Exception) { + } val res = getCurrentPath().getResolution() ?: return - if (res.x > res.y) { + val width = if (flipSides) res.y else res.x + val height = if (flipSides) res.x else res.y + if (width > height) { requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE - } else if (res.x < res.y) { + } else if (width < height) { requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT } }