|
|
@ -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 { |
|
|
|