adding an implementation of slideshow fade animations

This commit is contained in:
tibbi 2019-06-20 15:17:55 +02:00
parent cd261dc8e1
commit 2c9ac6e440
4 changed files with 40 additions and 3 deletions

View File

@ -396,6 +396,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
if (getMediaForSlideshow()) {
view_pager.onGlobalLayout {
if (!isDestroyed) {
if (config.slideshowAnimation == SLIDESHOW_ANIMATION_FADE) {
view_pager.setPageTransformer(false, FadePageTransformer())
}
hideSystemUI(true)
mSlideshowInterval = config.slideshowInterval
mSlideshowMoveBackwards = config.slideshowMoveBackwards
@ -436,7 +440,13 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
}
})
animator.interpolator = DecelerateInterpolator()
if (config.slideshowAnimation == SLIDESHOW_ANIMATION_SLIDE) {
animator.interpolator = DecelerateInterpolator()
animator.duration = SLIDESHOW_SLIDE_DURATION
} else {
animator.duration = SLIDESHOW_FADE_DURATION
}
animator.addUpdateListener(object : ValueAnimator.AnimatorUpdateListener {
var oldDragPosition = 0
override fun onAnimationUpdate(animation: ValueAnimator) {
@ -453,7 +463,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
}
})
animator.duration = SLIDESHOW_SCROLL_DURATION
view_pager.beginFakeDrag()
animator.start()
}
@ -473,6 +482,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private fun stopSlideshow() {
if (mIsSlideshowActive) {
view_pager.setPageTransformer(false, DefaultPageTransformer())
mIsSlideshowActive = false
showSystemUI(true)
mSlideshowHandler.removeCallbacksAndMessages(null)

View File

@ -88,7 +88,8 @@ const val SLIDESHOW_MOVE_BACKWARDS = "slideshow_move_backwards"
const val SLIDESHOW_ANIMATION = "slideshow_animation"
const val SLIDESHOW_LOOP = "loop_slideshow"
const val SLIDESHOW_DEFAULT_INTERVAL = 5
const val SLIDESHOW_SCROLL_DURATION = 500L
const val SLIDESHOW_SLIDE_DURATION = 500L
const val SLIDESHOW_FADE_DURATION = 1500L
const val SLIDESHOW_START_ON_ENTER = "slideshow_start_on_enter"
// slideshow animations

View File

@ -0,0 +1,8 @@
package com.simplemobiletools.gallery.pro.helpers
import android.view.View
import androidx.viewpager.widget.ViewPager
class DefaultPageTransformer : ViewPager.PageTransformer {
override fun transformPage(view: View, position: Float) {}
}

View File

@ -0,0 +1,18 @@
package com.simplemobiletools.gallery.pro.helpers
import android.view.View
import androidx.viewpager.widget.ViewPager
class FadePageTransformer : ViewPager.PageTransformer {
override fun transformPage(view: View, position: Float) {
view.translationX = view.width * -position
view.alpha = if (position <= -1f || position >= 1f) {
0f
} else if (position == 0f) {
1f
} else {
1f - Math.abs(position)
}
}
}