mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-23 04:57:59 +01:00
fix #441, rely on the system at "Device rotation" option
This commit is contained in:
parent
41d0b0bef9
commit
bd68292824
1 changed files with 9 additions and 33 deletions
|
@ -12,7 +12,6 @@ import android.graphics.BitmapFactory
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.graphics.Matrix
|
import android.graphics.Matrix
|
||||||
import android.graphics.drawable.ColorDrawable
|
import android.graphics.drawable.ColorDrawable
|
||||||
import android.hardware.SensorManager
|
|
||||||
import android.media.ExifInterface
|
import android.media.ExifInterface
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
@ -21,7 +20,10 @@ import android.os.Handler
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import android.support.v4.view.ViewPager
|
import android.support.v4.view.ViewPager
|
||||||
import android.util.DisplayMetrics
|
import android.util.DisplayMetrics
|
||||||
import android.view.*
|
import android.view.Menu
|
||||||
|
import android.view.MenuItem
|
||||||
|
import android.view.View
|
||||||
|
import android.view.WindowManager
|
||||||
import android.view.animation.DecelerateInterpolator
|
import android.view.animation.DecelerateInterpolator
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.simplemobiletools.commons.dialogs.PropertiesDialog
|
import com.simplemobiletools.commons.dialogs.PropertiesDialog
|
||||||
|
@ -48,17 +50,14 @@ import java.io.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, ViewPagerFragment.FragmentListener {
|
class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, ViewPagerFragment.FragmentListener {
|
||||||
private var mOrientationEventListener: OrientationEventListener? = null
|
|
||||||
private var mPath = ""
|
private var mPath = ""
|
||||||
private var mDirectory = ""
|
private var mDirectory = ""
|
||||||
|
|
||||||
private var mIsFullScreen = false
|
private var mIsFullScreen = false
|
||||||
private var mPos = -1
|
private var mPos = -1
|
||||||
private var mShowAll = false
|
private var mShowAll = false
|
||||||
private var mIsSlideshowActive = false
|
private var mIsSlideshowActive = false
|
||||||
private var mSkipConfirmationDialog = false
|
private var mSkipConfirmationDialog = false
|
||||||
private var mRotationDegrees = 0f
|
private var mRotationDegrees = 0f
|
||||||
private var mLastHandledOrientation = 0
|
|
||||||
private var mPrevHashcode = 0
|
private var mPrevHashcode = 0
|
||||||
|
|
||||||
private var mSlideshowHandler = Handler()
|
private var mSlideshowHandler = Handler()
|
||||||
|
@ -125,7 +124,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
mOrientationEventListener?.disable()
|
|
||||||
stopSlideshow()
|
stopSlideshow()
|
||||||
storeStateVariables()
|
storeStateVariables()
|
||||||
}
|
}
|
||||||
|
@ -146,7 +144,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initViewPager() {
|
private fun initViewPager() {
|
||||||
setupOrientationEventListener()
|
|
||||||
measureScreen()
|
measureScreen()
|
||||||
val uri = intent.data
|
val uri = intent.data
|
||||||
if (uri != null) {
|
if (uri != null) {
|
||||||
|
@ -214,8 +211,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
view_pager.background = ColorDrawable(Color.BLACK)
|
view_pager.background = ColorDrawable(Color.BLACK)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.hideSystemUI)
|
if (config.hideSystemUI) {
|
||||||
fragmentClicked()
|
fragmentClicked()
|
||||||
|
}
|
||||||
|
|
||||||
window.decorView.setOnSystemUiVisibilityChangeListener { visibility ->
|
window.decorView.setOnSystemUiVisibilityChangeListener { visibility ->
|
||||||
mIsFullScreen = visibility and View.SYSTEM_UI_FLAG_FULLSCREEN != 0
|
mIsFullScreen = visibility and View.SYSTEM_UI_FLAG_FULLSCREEN != 0
|
||||||
|
@ -231,35 +229,13 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LOCKED
|
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LOCKED
|
||||||
}
|
}
|
||||||
} else if (config.screenRotation == ROTATE_BY_DEVICE_ROTATION && mOrientationEventListener?.canDetectOrientation() == true) {
|
} else if (config.screenRotation == ROTATE_BY_DEVICE_ROTATION) {
|
||||||
mOrientationEventListener?.enable()
|
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR
|
||||||
} else if (config.screenRotation == ROTATE_BY_SYSTEM_SETTING) {
|
} else if (config.screenRotation == ROTATE_BY_SYSTEM_SETTING) {
|
||||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
|
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupOrientationEventListener() {
|
|
||||||
mOrientationEventListener = object : OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) {
|
|
||||||
override fun onOrientationChanged(orientation: Int) {
|
|
||||||
val currOrient = when (orientation) {
|
|
||||||
in 75..134 -> ORIENT_LANDSCAPE_RIGHT
|
|
||||||
in 225..285 -> ORIENT_LANDSCAPE_LEFT
|
|
||||||
else -> ORIENT_PORTRAIT
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mIsOrientationLocked && mLastHandledOrientation != currOrient) {
|
|
||||||
mLastHandledOrientation = currOrient
|
|
||||||
|
|
||||||
requestedOrientation = when (currOrient) {
|
|
||||||
ORIENT_LANDSCAPE_LEFT -> ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
|
|
||||||
ORIENT_LANDSCAPE_RIGHT -> ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
|
|
||||||
else -> ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
menuInflater.inflate(R.menu.menu_viewpager, menu)
|
menuInflater.inflate(R.menu.menu_viewpager, menu)
|
||||||
val currentMedium = getCurrentMedium() ?: return true
|
val currentMedium = getCurrentMedium() ?: return true
|
||||||
|
@ -458,7 +434,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.slideshowRandomOrder) {
|
if (config.slideshowRandomOrder) {
|
||||||
Collections.shuffle(mSlideshowMedia)
|
mSlideshowMedia.shuffle()
|
||||||
mPos = 0
|
mPos = 0
|
||||||
} else {
|
} else {
|
||||||
mPath = getCurrentPath()
|
mPath = getCurrentPath()
|
||||||
|
|
Loading…
Reference in a new issue