rotate the screen as needed if autorotate is enabled

This commit is contained in:
tibbi 2017-03-25 14:05:56 +01:00
parent 2540763480
commit 45a56d6926

View file

@ -2,6 +2,7 @@ package com.simplemobiletools.gallery.activities
import android.app.Activity import android.app.Activity
import android.content.Intent import android.content.Intent
import android.content.pm.ActivityInfo
import android.database.Cursor import android.database.Cursor
import android.graphics.Bitmap import android.graphics.Bitmap
import android.graphics.BitmapFactory import android.graphics.BitmapFactory
@ -388,6 +389,11 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private fun checkOrientation() { private fun checkOrientation() {
if (config.autoRotateScreen) { if (config.autoRotateScreen) {
val res = getCurrentFile().getResolution() 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() updateActionbarTitle()
mRotationDegrees = 0f mRotationDegrees = 0f
supportInvalidateOptionsMenu() supportInvalidateOptionsMenu()
checkOrientation()
} }
override fun onPageScrollStateChanged(state: Int) { override fun onPageScrollStateChanged(state: Int) {
if (state == ViewPager.SCROLL_STATE_IDLE) {
checkOrientation()
}
} }
} }