From 45a56d6926739d3a6017e6ffdd95ebb1a0a27f12 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 25 Mar 2017 14:05:56 +0100 Subject: [PATCH] rotate the screen as needed if autorotate is enabled --- .../gallery/activities/ViewPagerActivity.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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 2fda7d2a0..3743f9fb9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.gallery.activities import android.app.Activity import android.content.Intent +import android.content.pm.ActivityInfo import android.database.Cursor import android.graphics.Bitmap import android.graphics.BitmapFactory @@ -388,6 +389,11 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun checkOrientation() { if (config.autoRotateScreen) { val res = getCurrentFile().getResolution() + if (res.x > res.y) { + requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE + } else if (res.x < res.y) { + requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + } } } @@ -433,9 +439,11 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View updateActionbarTitle() mRotationDegrees = 0f supportInvalidateOptionsMenu() - checkOrientation() } override fun onPageScrollStateChanged(state: Int) { + if (state == ViewPager.SCROLL_STATE_IDLE) { + checkOrientation() + } } }