From 3f13a65d7f1e59f82e5ae58de85a5dcb2d5a892d Mon Sep 17 00:00:00 2001 From: Administrator <1760316362@qq.com> Date: Thu, 22 Aug 2019 16:09:18 +0800 Subject: [PATCH] update SlidePageDelegate --- .../widget/page/delegate/CoverPageDelegate.kt | 3 +-- .../ui/widget/page/delegate/PageDelegate.kt | 24 +++++++------------ .../page/delegate/SimulationPageDelegate.kt | 15 ++++++++++++ .../widget/page/delegate/SlidePageDelegate.kt | 3 +-- 4 files changed, 25 insertions(+), 20 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/widget/page/delegate/SimulationPageDelegate.kt diff --git a/app/src/main/java/io/legado/app/ui/widget/page/delegate/CoverPageDelegate.kt b/app/src/main/java/io/legado/app/ui/widget/page/delegate/CoverPageDelegate.kt index a0a5bde9e..ccab1295f 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/delegate/CoverPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/delegate/CoverPageDelegate.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() { diff --git a/app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.kt b/app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.kt index ea32785c7..9261a0e06 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.kt @@ -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 { diff --git a/app/src/main/java/io/legado/app/ui/widget/page/delegate/SimulationPageDelegate.kt b/app/src/main/java/io/legado/app/ui/widget/page/delegate/SimulationPageDelegate.kt new file mode 100644 index 000000000..2020e3a60 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/widget/page/delegate/SimulationPageDelegate.kt @@ -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() { + } +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/widget/page/delegate/SlidePageDelegate.kt b/app/src/main/java/io/legado/app/ui/widget/page/delegate/SlidePageDelegate.kt index 434c45de1..584a4aa2e 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/delegate/SlidePageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/delegate/SlidePageDelegate.kt @@ -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) {