mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-27 06:57:59 +01:00
properly handle device rotation at the video player
This commit is contained in:
parent
7cb5fce4bd
commit
346fe5e444
2 changed files with 24 additions and 5 deletions
|
@ -26,9 +26,7 @@ import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
|
||||||
import com.simplemobiletools.commons.helpers.isPiePlus
|
import com.simplemobiletools.commons.helpers.isPiePlus
|
||||||
import com.simplemobiletools.gallery.pro.R
|
import com.simplemobiletools.gallery.pro.R
|
||||||
import com.simplemobiletools.gallery.pro.extensions.*
|
import com.simplemobiletools.gallery.pro.extensions.*
|
||||||
import com.simplemobiletools.gallery.pro.helpers.CLICK_MAX_DURATION
|
import com.simplemobiletools.gallery.pro.helpers.*
|
||||||
import com.simplemobiletools.gallery.pro.helpers.DRAG_THRESHOLD
|
|
||||||
import com.simplemobiletools.gallery.pro.helpers.MIN_SKIP_LENGTH
|
|
||||||
import kotlinx.android.synthetic.main.activity_video_player.*
|
import kotlinx.android.synthetic.main.activity_video_player.*
|
||||||
import kotlinx.android.synthetic.main.bottom_video_time_holder.*
|
import kotlinx.android.synthetic.main.bottom_video_time_holder.*
|
||||||
|
|
||||||
|
@ -39,6 +37,7 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
||||||
private var mIsPlaying = false
|
private var mIsPlaying = false
|
||||||
private var mWasVideoStarted = false
|
private var mWasVideoStarted = false
|
||||||
private var mIsDragged = false
|
private var mIsDragged = false
|
||||||
|
private var mIsOrientationLocked = false
|
||||||
private var mScreenWidth = 0
|
private var mScreenWidth = 0
|
||||||
private var mCurrTime = 0
|
private var mCurrTime = 0
|
||||||
private var mDuration = 0
|
private var mDuration = 0
|
||||||
|
@ -60,6 +59,7 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
||||||
public override fun onCreate(savedInstanceState: Bundle?) {
|
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_video_player)
|
setContentView(R.layout.activity_video_player)
|
||||||
|
setupOrientation()
|
||||||
|
|
||||||
handlePermission(PERMISSION_WRITE_STORAGE) {
|
handlePermission(PERMISSION_WRITE_STORAGE) {
|
||||||
if (it) {
|
if (it) {
|
||||||
|
@ -132,6 +132,16 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
||||||
initTimeHolder()
|
initTimeHolder()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setupOrientation() {
|
||||||
|
if (!mIsOrientationLocked) {
|
||||||
|
if (config.screenRotation == ROTATE_BY_DEVICE_ROTATION) {
|
||||||
|
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR
|
||||||
|
} else if (config.screenRotation == ROTATE_BY_SYSTEM_SETTING) {
|
||||||
|
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun initPlayer() {
|
private fun initPlayer() {
|
||||||
mUri = intent.data ?: return
|
mUri = intent.data ?: return
|
||||||
supportActionBar?.title = getFilenameFromUri(mUri!!)
|
supportActionBar?.title = getFilenameFromUri(mUri!!)
|
||||||
|
@ -381,9 +391,18 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
||||||
|
|
||||||
val multiplier = if (screenWidth > screenHeight) 0.5 else 0.8
|
val multiplier = if (screenWidth > screenHeight) 0.5 else 0.8
|
||||||
mScreenWidth = (screenWidth * multiplier).toInt()
|
mScreenWidth = (screenWidth * multiplier).toInt()
|
||||||
|
|
||||||
|
if (config.screenRotation == ROTATE_BY_ASPECT_RATIO) {
|
||||||
|
if (mVideoSize.x > mVideoSize.y) {
|
||||||
|
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
|
||||||
|
} else if (mVideoSize.x < mVideoSize.y) {
|
||||||
|
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun changeOrientation() {
|
private fun changeOrientation() {
|
||||||
|
mIsOrientationLocked = true
|
||||||
requestedOrientation = if (resources.configuration.orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
|
requestedOrientation = if (resources.configuration.orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
|
||||||
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
|
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -119,7 +119,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
window.attributes = attributes
|
window.attributes = attributes
|
||||||
}
|
}
|
||||||
|
|
||||||
setupRotation()
|
setupOrientation()
|
||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
|
|
||||||
supportActionBar?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
|
supportActionBar?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
|
||||||
|
@ -358,7 +358,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupRotation() {
|
private fun setupOrientation() {
|
||||||
if (!mIsOrientationLocked) {
|
if (!mIsOrientationLocked) {
|
||||||
if (config.screenRotation == ROTATE_BY_DEVICE_ROTATION) {
|
if (config.screenRotation == ROTATE_BY_DEVICE_ROTATION) {
|
||||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR
|
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR
|
||||||
|
|
Loading…
Reference in a new issue