|
|
@ -6,9 +6,9 @@ import android.graphics.Canvas |
|
|
|
import android.graphics.RectF |
|
|
|
import android.graphics.RectF |
|
|
|
import android.view.GestureDetector |
|
|
|
import android.view.GestureDetector |
|
|
|
import android.view.MotionEvent |
|
|
|
import android.view.MotionEvent |
|
|
|
|
|
|
|
import android.view.animation.DecelerateInterpolator |
|
|
|
import android.widget.Scroller |
|
|
|
import android.widget.Scroller |
|
|
|
import androidx.annotation.CallSuper |
|
|
|
import androidx.annotation.CallSuper |
|
|
|
import androidx.interpolator.view.animation.FastOutLinearInInterpolator |
|
|
|
|
|
|
|
import com.google.android.material.snackbar.Snackbar |
|
|
|
import com.google.android.material.snackbar.Snackbar |
|
|
|
import io.legado.app.constant.PreferKey |
|
|
|
import io.legado.app.constant.PreferKey |
|
|
|
import io.legado.app.help.AppConfig |
|
|
|
import io.legado.app.help.AppConfig |
|
|
@ -47,16 +47,13 @@ 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 |
|
|
|
//textView在顶端或低端 |
|
|
|
|
|
|
|
protected var atTop: Boolean = false |
|
|
|
|
|
|
|
protected var atBottom: Boolean = false |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private val snackBar: Snackbar by lazy { |
|
|
|
private val snackBar: Snackbar by lazy { |
|
|
|
Snackbar.make(pageView, "", Snackbar.LENGTH_SHORT) |
|
|
|
Snackbar.make(pageView, "", Snackbar.LENGTH_SHORT) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private val scroller: Scroller by lazy { |
|
|
|
private val scroller: Scroller by lazy { |
|
|
|
Scroller(pageView.context, FastOutLinearInInterpolator()) |
|
|
|
Scroller(pageView.context, DecelerateInterpolator()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private val detector: GestureDetector by lazy { |
|
|
|
private val detector: GestureDetector by lazy { |
|
|
@ -83,7 +80,7 @@ abstract class PageDelegate(protected val pageView: PageView) : |
|
|
|
touchY = y |
|
|
|
touchY = y |
|
|
|
|
|
|
|
|
|
|
|
if (invalidate) { |
|
|
|
if (invalidate) { |
|
|
|
invalidate() |
|
|
|
pageView.invalidate() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -93,7 +90,7 @@ abstract class PageDelegate(protected val pageView: PageView) : |
|
|
|
touchY = y |
|
|
|
touchY = y |
|
|
|
|
|
|
|
|
|
|
|
if (invalidate) { |
|
|
|
if (invalidate) { |
|
|
|
invalidate() |
|
|
|
pageView.postInvalidate() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
onScroll() |
|
|
|
onScroll() |
|
|
@ -103,10 +100,6 @@ abstract class PageDelegate(protected val pageView: PageView) : |
|
|
|
detector.setIsLongpressEnabled(selectAble) |
|
|
|
detector.setIsLongpressEnabled(selectAble) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected fun invalidate() { |
|
|
|
|
|
|
|
pageView.invalidate() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
open fun fling( |
|
|
|
open fun fling( |
|
|
|
startX: Int, startY: Int, velocityX: Int, velocityY: Int, |
|
|
|
startX: Int, startY: Int, velocityX: Int, velocityY: Int, |
|
|
|
minX: Int, maxX: Int, minY: Int, maxY: Int |
|
|
|
minX: Int, maxX: Int, minY: Int, maxY: Int |
|
|
@ -114,7 +107,7 @@ abstract class PageDelegate(protected val pageView: PageView) : |
|
|
|
scroller.fling(startX, startY, velocityX, velocityY, minX, maxX, minY, maxY) |
|
|
|
scroller.fling(startX, startY, velocityX, velocityY, minX, maxX, minY, maxY) |
|
|
|
isRunning = true |
|
|
|
isRunning = true |
|
|
|
isStarted = true |
|
|
|
isStarted = true |
|
|
|
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) { |
|
|
@ -127,13 +120,13 @@ abstract class PageDelegate(protected val pageView: PageView) : |
|
|
|
) |
|
|
|
) |
|
|
|
isRunning = true |
|
|
|
isRunning = true |
|
|
|
isStarted = true |
|
|
|
isStarted = true |
|
|
|
invalidate() |
|
|
|
pageView.invalidate() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun stopScroll() { |
|
|
|
private fun stopScroll() { |
|
|
|
isRunning = false |
|
|
|
isRunning = false |
|
|
|
isStarted = false |
|
|
|
isStarted = false |
|
|
|
invalidate() |
|
|
|
pageView.invalidate() |
|
|
|
bitmap?.recycle() |
|
|
|
bitmap?.recycle() |
|
|
|
bitmap = null |
|
|
|
bitmap = null |
|
|
|
} |
|
|
|
} |
|
|
@ -141,7 +134,7 @@ abstract class PageDelegate(protected val pageView: PageView) : |
|
|
|
fun setViewSize(width: Int, height: Int) { |
|
|
|
fun setViewSize(width: Int, height: Int) { |
|
|
|
viewWidth = width |
|
|
|
viewWidth = width |
|
|
|
viewHeight = height |
|
|
|
viewHeight = height |
|
|
|
invalidate() |
|
|
|
pageView.invalidate() |
|
|
|
centerRectF.set( |
|
|
|
centerRectF.set( |
|
|
|
width * 0.33f, height * 0.33f, |
|
|
|
width * 0.33f, height * 0.33f, |
|
|
|
width * 0.66f, height * 0.66f |
|
|
|
width * 0.66f, height * 0.66f |
|
|
|