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))
start()
startScroll(touchX.toInt(), 0, distanceX.toInt(), 0)
}
override fun onScrollStop() {

@ -6,6 +6,7 @@ import android.view.GestureDetector
import android.view.MotionEvent
import android.widget.Scroller
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.PageView
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 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()) }
@ -71,13 +72,14 @@ abstract class PageDelegate(protected val pageView: PageView) {
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
isStarted = true
invalidate()
}
protected fun stop() {
protected fun stopScroll() {
isRunning = false
isStarted = false
bitmap = null
@ -101,7 +103,7 @@ abstract class PageDelegate(protected val pageView: PageView) {
} else if (isStarted) {
setTouchPoint(scroller.finalX.toFloat(), scroller.finalY.toFloat(), false)
onScrollStop()
stop()
stopScroll()
}
}
@ -162,14 +164,14 @@ abstract class PageDelegate(protected val pageView: PageView) {
abstract fun onScrollStop()//scroller finish
open fun onScroll() {//移动contentView, slidePage
}
enum class Direction {
NONE, PREV, NEXT
}
private inner class GestureListener : GestureDetector.OnGestureListener {
private inner class GestureListener : GestureDetector.SimpleOnGestureListener() {
override fun onDown(e: MotionEvent): Boolean {
// abort()
@ -188,8 +190,6 @@ abstract class PageDelegate(protected val pageView: PageView) {
return true
}
override fun onShowPress(e: MotionEvent) {}
override fun onSingleTapUp(e: MotionEvent): Boolean {
val x = e.x
val y = e.y
@ -253,14 +253,6 @@ abstract class PageDelegate(protected val pageView: PageView) {
}
return isMoved
}
override fun onLongPress(e: MotionEvent) {
}
override fun onFling(e1: MotionEvent, e2: MotionEvent, velocityX: Float, velocityY: Float): Boolean {
return false
}
}
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))
start()
startScroll(touchX.toInt(), 0, distanceX.toInt(), 0)
}
override fun onDraw(canvas: Canvas) {

Loading…
Cancel
Save