adding some basic slideshow functionality
This commit is contained in:
parent
1d04016c9b
commit
86a5107cc6
4 changed files with 25 additions and 4 deletions
|
@ -15,6 +15,7 @@ import android.media.ExifInterface
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
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
|
||||||
|
@ -51,6 +52,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
private var mRotationDegrees = 0f
|
private var mRotationDegrees = 0f
|
||||||
private var mLastHandledOrientation = 0
|
private var mLastHandledOrientation = 0
|
||||||
private var mPrevHashcode = 0
|
private var mPrevHashcode = 0
|
||||||
|
private var mSlideshowHandler = Handler()
|
||||||
|
private var mSlideshowInterval = SLIDESHOW_DEFAULT_INTERVAL
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
var screenWidth = 0
|
var screenWidth = 0
|
||||||
|
@ -189,6 +192,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
mOrientationEventListener.disable()
|
mOrientationEventListener.disable()
|
||||||
|
stopSlideshow()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
|
@ -256,13 +260,29 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
|
|
||||||
private fun startSlideshow() {
|
private fun startSlideshow() {
|
||||||
hideSystemUI()
|
hideSystemUI()
|
||||||
|
mSlideshowInterval = config.slideshowInterval
|
||||||
mIsSlideshowActive = true
|
mIsSlideshowActive = true
|
||||||
|
scheduleSwipe()
|
||||||
|
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun stopSlideshow() {
|
private fun stopSlideshow() {
|
||||||
if (mIsSlideshowActive) {
|
if (mIsSlideshowActive) {
|
||||||
showSystemUI()
|
showSystemUI()
|
||||||
mIsSlideshowActive = false
|
mIsSlideshowActive = false
|
||||||
|
mSlideshowHandler.removeCallbacksAndMessages(null)
|
||||||
|
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun scheduleSwipe() {
|
||||||
|
mSlideshowHandler.removeCallbacksAndMessages(null)
|
||||||
|
if (mIsSlideshowActive) {
|
||||||
|
mSlideshowHandler.postDelayed({
|
||||||
|
if (mIsSlideshowActive && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && !isDestroyed) {
|
||||||
|
view_pager.currentItem = ++view_pager.currentItem
|
||||||
|
}
|
||||||
|
}, mSlideshowInterval * 1000L)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -587,6 +607,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
updateActionbarTitle()
|
updateActionbarTitle()
|
||||||
mRotationDegrees = 0f
|
mRotationDegrees = 0f
|
||||||
supportInvalidateOptionsMenu()
|
supportInvalidateOptionsMenu()
|
||||||
|
scheduleSwipe()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPageScrollStateChanged(state: Int) {
|
override fun onPageScrollStateChanged(state: Int) {
|
||||||
|
|
|
@ -8,7 +8,7 @@ import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.activities.SimpleActivity
|
import com.simplemobiletools.gallery.activities.SimpleActivity
|
||||||
import com.simplemobiletools.gallery.extensions.config
|
import com.simplemobiletools.gallery.extensions.config
|
||||||
import com.simplemobiletools.gallery.helpers.SLIDESHOW_DEFAULT_DURATION
|
import com.simplemobiletools.gallery.helpers.SLIDESHOW_DEFAULT_INTERVAL
|
||||||
import kotlinx.android.synthetic.main.dialog_slideshow.view.*
|
import kotlinx.android.synthetic.main.dialog_slideshow.view.*
|
||||||
|
|
||||||
class SlideshowDialog(val activity: SimpleActivity, val callback: () -> Unit) {
|
class SlideshowDialog(val activity: SimpleActivity, val callback: () -> Unit) {
|
||||||
|
@ -61,7 +61,7 @@ class SlideshowDialog(val activity: SimpleActivity, val callback: () -> Unit) {
|
||||||
private fun dialogConfirmed() {
|
private fun dialogConfirmed() {
|
||||||
var interval = view.interval_value.text.toString()
|
var interval = view.interval_value.text.toString()
|
||||||
if (interval.trim('0').isEmpty())
|
if (interval.trim('0').isEmpty())
|
||||||
interval = SLIDESHOW_DEFAULT_DURATION.toString()
|
interval = SLIDESHOW_DEFAULT_INTERVAL.toString()
|
||||||
|
|
||||||
activity.config.apply {
|
activity.config.apply {
|
||||||
slideshowInterval = interval.toInt()
|
slideshowInterval = interval.toInt()
|
||||||
|
|
|
@ -234,7 +234,7 @@ class Config(context: Context) : BaseConfig(context) {
|
||||||
set(replaceShare) = prefs.edit().putBoolean(REPLACE_SHARE_WITH_ROTATE, replaceShare).apply()
|
set(replaceShare) = prefs.edit().putBoolean(REPLACE_SHARE_WITH_ROTATE, replaceShare).apply()
|
||||||
|
|
||||||
var slideshowInterval: Int
|
var slideshowInterval: Int
|
||||||
get() = prefs.getInt(SLIDESHOW_INTERVAL, SLIDESHOW_DEFAULT_DURATION)
|
get() = prefs.getInt(SLIDESHOW_INTERVAL, SLIDESHOW_DEFAULT_INTERVAL)
|
||||||
set(slideshowInterval) = prefs.edit().putInt(SLIDESHOW_INTERVAL, slideshowInterval).apply()
|
set(slideshowInterval) = prefs.edit().putInt(SLIDESHOW_INTERVAL, slideshowInterval).apply()
|
||||||
|
|
||||||
var slideshowIncludeVideos: Boolean
|
var slideshowIncludeVideos: Boolean
|
||||||
|
|
|
@ -39,7 +39,7 @@ val SLIDESHOW_INTERVAL = "slideshow_interval"
|
||||||
val SLIDESHOW_INCLUDE_VIDEOS = "slideshow_include_videos"
|
val SLIDESHOW_INCLUDE_VIDEOS = "slideshow_include_videos"
|
||||||
val SLIDESHOW_RANDOM_ORDER = "slideshow_random_order"
|
val SLIDESHOW_RANDOM_ORDER = "slideshow_random_order"
|
||||||
val SLIDESHOW_USE_FADE = "slideshow_use_fade"
|
val SLIDESHOW_USE_FADE = "slideshow_use_fade"
|
||||||
val SLIDESHOW_DEFAULT_DURATION = 5
|
val SLIDESHOW_DEFAULT_INTERVAL = 5
|
||||||
|
|
||||||
val NOMEDIA = ".nomedia"
|
val NOMEDIA = ".nomedia"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue