Added an animation to the viewpager.
This commit is contained in:
parent
3a28772096
commit
173247041a
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
- Fixed #142.
|
- Fixed #142.
|
||||||
|
|
||||||
|
- Added an animation to the viewpager.
|
||||||
|
|
||||||
- Changed versions handling.
|
- Changed versions handling.
|
||||||
|
|
||||||
**1.5.4.22**
|
**1.5.4.22**
|
||||||
|
@ -6,6 +6,7 @@ import android.support.v4.app.FragmentStatePagerAdapter
|
|||||||
import android.support.v7.app.AppCompatActivity
|
import android.support.v7.app.AppCompatActivity
|
||||||
import apps.amine.bou.readerforselfoss.api.selfoss.Item
|
import apps.amine.bou.readerforselfoss.api.selfoss.Item
|
||||||
import apps.amine.bou.readerforselfoss.fragments.ArticleFragment
|
import apps.amine.bou.readerforselfoss.fragments.ArticleFragment
|
||||||
|
import apps.amine.bou.readerforselfoss.transformers.DepthPageTransformer
|
||||||
import com.ftinc.scoop.Scoop
|
import com.ftinc.scoop.Scoop
|
||||||
import kotlinx.android.synthetic.main.activity_reader.*
|
import kotlinx.android.synthetic.main.activity_reader.*
|
||||||
import me.relex.circleindicator.CircleIndicator
|
import me.relex.circleindicator.CircleIndicator
|
||||||
@ -26,6 +27,7 @@ class ReaderActivity : AppCompatActivity() {
|
|||||||
pager.adapter = adapter
|
pager.adapter = adapter
|
||||||
pager.currentItem = currentItem
|
pager.currentItem = currentItem
|
||||||
|
|
||||||
|
pager.setPageTransformer(true, DepthPageTransformer())
|
||||||
(indicator as CircleIndicator).setViewPager(pager)
|
(indicator as CircleIndicator).setViewPager(pager)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user