Added an animation to the viewpager.

This commit is contained in:
Amine Bou 2017-12-05 20:08:45 +01:00
parent 3a28772096
commit 173247041a
3 changed files with 47 additions and 0 deletions

View File

@ -4,6 +4,8 @@
- Fixed #142.
- Added an animation to the viewpager.
- Changed versions handling.
**1.5.4.22**

View File

@ -6,6 +6,7 @@ import android.support.v4.app.FragmentStatePagerAdapter
import android.support.v7.app.AppCompatActivity
import apps.amine.bou.readerforselfoss.api.selfoss.Item
import apps.amine.bou.readerforselfoss.fragments.ArticleFragment
import apps.amine.bou.readerforselfoss.transformers.DepthPageTransformer
import com.ftinc.scoop.Scoop
import kotlinx.android.synthetic.main.activity_reader.*
import me.relex.circleindicator.CircleIndicator
@ -26,6 +27,7 @@ class ReaderActivity : AppCompatActivity() {
pager.adapter = adapter
pager.currentItem = currentItem
pager.setPageTransformer(true, DepthPageTransformer())
(indicator as CircleIndicator).setViewPager(pager)
}

View File

@ -0,0 +1,43 @@
package apps.amine.bou.readerforselfoss.transformers
import android.support.v4.view.ViewPager
import android.view.View
class DepthPageTransformer : ViewPager.PageTransformer {
override fun transformPage(view: View, position: Float) {
val pageWidth = view.width
when {
position < -1 -> // [-Infinity,-1)
// This page is way off-screen to the left.
view.alpha = 0F
position <= 0 -> { // [-1,0]
// Use the default slide transition when moving to the left page
view.alpha = 1F
view.translationX = 0F
view.scaleX = 1F
view.scaleY = 1F
}
position <= 1 -> { // (0,1]
// Fade the page out.
view.alpha = 1 - position
// Counteract the default slide transition
view.translationX = pageWidth * -position
// Scale the page down (between MIN_SCALE and 1)
val scaleFactor = MIN_SCALE + (1 - MIN_SCALE) * (1 - Math.abs(position))
view.scaleX = scaleFactor
view.scaleY = scaleFactor
}
else -> // (1,+Infinity]
// This page is way off-screen to the right.
view.alpha = 0F
}
}
companion object {
private val MIN_SCALE = 0.75f
}
}