update SlidePageDelegate

pull/32/head
Administrator 5 years ago
parent ed5492536d
commit 3f13a65d7f
  1. 3
      app/src/main/java/io/legado/app/ui/widget/page/delegate/CoverPageDelegate.kt
  2. 24
      app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.kt
  3. 15
      app/src/main/java/io/legado/app/ui/widget/page/delegate/SimulationPageDelegate.kt
  4. 3
      app/src/main/java/io/legado/app/ui/widget/page/delegate/SlidePageDelegate.kt

@ -43,8 +43,7 @@ class CoverPageDelegate(pageView: PageView) : PageDelegate(pageView) {
} }
} }
scroller.startScroll(touchX.toInt(), 0, distanceX.toInt(), 0, getDuration(distanceX)) startScroll(touchX.toInt(), 0, distanceX.toInt(), 0)
start()
} }
override fun onScrollStop() { override fun onScrollStop() {

@ -6,6 +6,7 @@ import android.view.GestureDetector
import android.view.MotionEvent import android.view.MotionEvent
import android.widget.Scroller import android.widget.Scroller
import androidx.interpolator.view.animation.FastOutLinearInInterpolator import androidx.interpolator.view.animation.FastOutLinearInInterpolator
import io.legado.app.service.ReadAloudService.Companion.stop
import io.legado.app.ui.widget.page.ContentView import io.legado.app.ui.widget.page.ContentView
import io.legado.app.ui.widget.page.PageView import io.legado.app.ui.widget.page.PageView
import io.legado.app.utils.screenshot import io.legado.app.utils.screenshot
@ -34,7 +35,7 @@ abstract class PageDelegate(protected val pageView: PageView) {
protected var viewWidth: Int = pageView.width protected var viewWidth: Int = pageView.width
protected var viewHeight: Int = pageView.height protected var viewHeight: Int = pageView.height
protected val scroller: Scroller by lazy { Scroller(pageView.context, FastOutLinearInInterpolator()) } private val scroller: Scroller by lazy { Scroller(pageView.context, FastOutLinearInInterpolator()) }
private val detector: GestureDetector by lazy { GestureDetector(pageView.context, GestureListener()) } private val detector: GestureDetector by lazy { GestureDetector(pageView.context, GestureListener()) }
@ -71,13 +72,14 @@ abstract class PageDelegate(protected val pageView: PageView) {
pageView.invalidate() pageView.invalidate()
} }
protected fun start() { protected fun startScroll(startX: Int, startY: Int, dx: Int, dy: Int) {
scroller.startScroll(startX, startY, dx, dy, getDuration((if(dx !=0) dx else dy).toFloat()))
isRunning = true isRunning = true
isStarted = true isStarted = true
invalidate() invalidate()
} }
protected fun stop() { protected fun stopScroll() {
isRunning = false isRunning = false
isStarted = false isStarted = false
bitmap = null bitmap = null
@ -101,7 +103,7 @@ abstract class PageDelegate(protected val pageView: PageView) {
} else if (isStarted) { } else if (isStarted) {
setTouchPoint(scroller.finalX.toFloat(), scroller.finalY.toFloat(), false) setTouchPoint(scroller.finalX.toFloat(), scroller.finalY.toFloat(), false)
onScrollStop() onScrollStop()
stop() stopScroll()
} }
} }
@ -162,14 +164,14 @@ abstract class PageDelegate(protected val pageView: PageView) {
abstract fun onScrollStop()//scroller finish abstract fun onScrollStop()//scroller finish
open fun onScroll() {//移动contentView, slidePage open fun onScroll() {//移动contentView, slidePage
} }
enum class Direction { enum class Direction {
NONE, PREV, NEXT NONE, PREV, NEXT
} }
private inner class GestureListener : GestureDetector.OnGestureListener {
private inner class GestureListener : GestureDetector.SimpleOnGestureListener() {
override fun onDown(e: MotionEvent): Boolean { override fun onDown(e: MotionEvent): Boolean {
// abort() // abort()
@ -188,8 +190,6 @@ abstract class PageDelegate(protected val pageView: PageView) {
return true return true
} }
override fun onShowPress(e: MotionEvent) {}
override fun onSingleTapUp(e: MotionEvent): Boolean { override fun onSingleTapUp(e: MotionEvent): Boolean {
val x = e.x val x = e.x
val y = e.y val y = e.y
@ -253,14 +253,6 @@ abstract class PageDelegate(protected val pageView: PageView) {
} }
return isMoved return isMoved
} }
override fun onLongPress(e: MotionEvent) {
}
override fun onFling(e1: MotionEvent, e2: MotionEvent, velocityX: Float, velocityY: Float): Boolean {
return false
}
} }
interface PageInterface { interface PageInterface {

@ -0,0 +1,15 @@
package io.legado.app.ui.widget.page.delegate
import android.graphics.Canvas
import io.legado.app.ui.widget.page.PageView
class SimulationPageDelegate(pageView: PageView) : PageDelegate(pageView) {
override fun onScrollStart() {
}
override fun onDraw(canvas: Canvas) {
}
override fun onScrollStop() {
}
}

@ -27,8 +27,7 @@ class SlidePageDelegate(pageView: PageView) : PageDelegate(pageView) {
} }
} }
scroller.startScroll(touchX.toInt(), 0, distanceX.toInt(), 0, getDuration(distanceX)) startScroll(touchX.toInt(), 0, distanceX.toInt(), 0)
start()
} }
override fun onDraw(canvas: Canvas) { override fun onDraw(canvas: Canvas) {

Loading…
Cancel
Save