pull/293/head
gedoor 4 years ago
parent 7903479319
commit 274ddede33
  1. 4
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/CoverPageDelegate.kt
  2. 8
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt
  3. 2
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/NoAnimPageDelegate.kt
  4. 22
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt
  5. 10
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt
  6. 4
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt
  7. 4
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/SlidePageDelegate.kt

@ -57,7 +57,7 @@ class CoverPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) {
} }
} }
override fun onAnimStart() { override fun onAnimStart(animationSpeed: Int) {
val distanceX: Float val distanceX: Float
when (mDirection) { when (mDirection) {
Direction.NEXT -> distanceX = Direction.NEXT -> distanceX =
@ -77,7 +77,7 @@ class CoverPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) {
viewWidth - (touchX - startX) viewWidth - (touchX - startX)
} }
} }
startScroll(touchX.toInt(), 0, distanceX.toInt(), 0) startScroll(touchX.toInt(), 0, distanceX.toInt(), 0, animationSpeed)
} }
} }

@ -103,20 +103,20 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie
} }
} }
override fun nextPageByAnim() { override fun nextPageByAnim(animationSpeed: Int) {
abort() abort()
if (!hasNext()) return if (!hasNext()) return
setDirection(Direction.NEXT) setDirection(Direction.NEXT)
setTouchPoint(viewWidth.toFloat(), 0f) setTouchPoint(viewWidth.toFloat(), 0f)
onAnimStart() onAnimStart(animationSpeed)
} }
override fun prevPageByAnim() { override fun prevPageByAnim(animationSpeed: Int) {
abort() abort()
if (!hasPrev()) return if (!hasPrev()) return
setDirection(Direction.PREV) setDirection(Direction.PREV)
setTouchPoint(0f, 0f) setTouchPoint(0f, 0f)
onAnimStart() onAnimStart(animationSpeed)
} }
override fun onDestroy() { override fun onDestroy() {

@ -5,7 +5,7 @@ import io.legado.app.ui.book.read.page.PageView
class NoAnimPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) { class NoAnimPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) {
override fun onAnimStart() { override fun onAnimStart(animationSpeed: Int) {
if (!isCancel) { if (!isCancel) {
pageView.fillPage(mDirection) pageView.fillPage(mDirection)
} }

@ -24,7 +24,7 @@ abstract class PageDelegate(protected val pageView: PageView) :
pageView.width * 0.66f, pageView.height * 0.66f pageView.width * 0.66f, pageView.height * 0.66f
) )
protected val context: Context = pageView.context protected val context: Context = pageView.context
private val animationSpeed = 300 private val defaultAnimationSpeed = 300
//起始点 //起始点
protected var startX: Float = 0f protected var startX: Float = 0f
@ -115,7 +115,7 @@ abstract class PageDelegate(protected val pageView: PageView) :
pageView.invalidate() pageView.invalidate()
} }
protected fun startScroll(startX: Int, startY: Int, dx: Int, dy: Int) { protected fun startScroll(startX: Int, startY: Int, dx: Int, dy: Int, animationSpeed: Int) {
val duration = if (dx != 0) { val duration = if (dx != 0) {
(animationSpeed * abs(dx)) / viewWidth (animationSpeed * abs(dx)) / viewWidth
} else { } else {
@ -163,7 +163,7 @@ abstract class PageDelegate(protected val pageView: PageView) :
return false return false
} }
open fun onAnimStart() {}//scroller start open fun onAnimStart(animationSpeed: Int) {}//scroller start
open fun onDraw(canvas: Canvas) {}//绘制 open fun onDraw(canvas: Canvas) {}//绘制
@ -171,15 +171,15 @@ abstract class PageDelegate(protected val pageView: PageView) :
open fun onScroll() {}//移动contentView, slidePage open fun onScroll() {}//移动contentView, slidePage
abstract fun nextPageByAnim() abstract fun nextPageByAnim(animationSpeed: Int)
abstract fun prevPageByAnim() abstract fun prevPageByAnim(animationSpeed: Int)
open fun keyTurnPage(direction: Direction) { open fun keyTurnPage(direction: Direction) {
if (isRunning) return if (isRunning) return
when (direction) { when (direction) {
Direction.NEXT -> nextPageByAnim() Direction.NEXT -> nextPageByAnim(100)
Direction.PREV -> prevPageByAnim() Direction.PREV -> prevPageByAnim(100)
else -> return else -> return
} }
} }
@ -207,7 +207,7 @@ abstract class PageDelegate(protected val pageView: PageView) :
if (selectedOnDown) { if (selectedOnDown) {
selectedOnDown = false selectedOnDown = false
} }
if (!noNext) onAnimStart() if (!noNext) onAnimStart(defaultAnimationSpeed)
} }
} }
} }
@ -247,7 +247,7 @@ abstract class PageDelegate(protected val pageView: PageView) :
return true return true
} }
if (isMoved) { if (isMoved) {
if (!noNext) onAnimStart() if (!noNext) onAnimStart(defaultAnimationSpeed)
return true return true
} }
val x = e.x val x = e.x
@ -259,9 +259,9 @@ abstract class PageDelegate(protected val pageView: PageView) :
if (x > viewWidth / 2 || if (x > viewWidth / 2 ||
AppConfig.clickAllNext AppConfig.clickAllNext
) { ) {
nextPageByAnim() nextPageByAnim(defaultAnimationSpeed)
} else { } else {
prevPageByAnim() prevPageByAnim(defaultAnimationSpeed)
} }
} }
return true return true

@ -12,7 +12,7 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) {
//速度追踪器 //速度追踪器
private val mVelocity: VelocityTracker = VelocityTracker.obtain() private val mVelocity: VelocityTracker = VelocityTracker.obtain()
override fun onAnimStart() { override fun onAnimStart(animationSpeed: Int) {
//惯性滚动 //惯性滚动
fling( fling(
0, touchY.toInt(), 0, mVelocity.yVelocity.toInt(), 0, touchY.toInt(), 0, mVelocity.yVelocity.toInt(),
@ -78,13 +78,13 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) {
mVelocity.recycle() mVelocity.recycle()
} }
override fun nextPageByAnim() { override fun nextPageByAnim(animationSpeed: Int) {
abort() abort()
startScroll(0, 0, 0, -ChapterProvider.visibleHeight) startScroll(0, 0, 0, -ChapterProvider.visibleHeight, animationSpeed)
} }
override fun prevPageByAnim() { override fun prevPageByAnim(animationSpeed: Int) {
abort() abort()
startScroll(0, 0, 0, ChapterProvider.visibleHeight) startScroll(0, 0, 0, ChapterProvider.visibleHeight, animationSpeed)
} }
} }

@ -154,7 +154,7 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi
} }
} }
override fun onAnimStart() { override fun onAnimStart(animationSpeed: Int) {
var dx: Float var dx: Float
val dy: Float val dy: Float
// dy 垂直方向滑动的距离,负值会使滚动向上滚动 // dy 垂直方向滑动的距离,负值会使滚动向上滚动
@ -184,7 +184,7 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi
(1 - touchY) // 防止mTouchY最终变为0 (1 - touchY) // 防止mTouchY最终变为0
} }
} }
startScroll(touchX.toInt(), touchY.toInt(), dx.toInt(), dy.toInt()) startScroll(touchX.toInt(), touchY.toInt(), dx.toInt(), dy.toInt(), animationSpeed)
} }
override fun onAnimStop() { override fun onAnimStop() {

@ -8,7 +8,7 @@ class SlidePageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) {
private val bitmapMatrix = Matrix() private val bitmapMatrix = Matrix()
override fun onAnimStart() { override fun onAnimStart(animationSpeed: Int) {
val distanceX: Float val distanceX: Float
when (mDirection) { when (mDirection) {
Direction.NEXT -> distanceX = Direction.NEXT -> distanceX =
@ -28,7 +28,7 @@ class SlidePageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) {
viewWidth - (touchX - startX) viewWidth - (touchX - startX)
} }
} }
startScroll(touchX.toInt(), 0, distanceX.toInt(), 0) startScroll(touchX.toInt(), 0, distanceX.toInt(), 0, animationSpeed)
} }
override fun onDraw(canvas: Canvas) { override fun onDraw(canvas: Canvas) {

Loading…
Cancel
Save