mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34:25 +08:00
优化
This commit is contained in:
parent
3fb3a615ec
commit
f4a6f8f0bb
@ -55,7 +55,6 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
|||||||
val defaultAnimationSpeed = 300
|
val defaultAnimationSpeed = 300
|
||||||
private var pressDown = false
|
private var pressDown = false
|
||||||
private var isMove = false
|
private var isMove = false
|
||||||
private var isPageMove = false
|
|
||||||
|
|
||||||
//起始点
|
//起始点
|
||||||
var startX: Float = 0f
|
var startX: Float = 0f
|
||||||
@ -83,8 +82,9 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
|||||||
private var pressOnTextSelected = false
|
private var pressOnTextSelected = false
|
||||||
private val initialTextPos = TextPos(0, 0, 0)
|
private val initialTextPos = TextPos(0, 0, 0)
|
||||||
|
|
||||||
val slopSquare by lazy { ViewConfiguration.get(context).scaledTouchSlop }
|
private val slopSquare by lazy { ViewConfiguration.get(context).scaledTouchSlop }
|
||||||
private var pageSlopSquare: Int = slopSquare
|
private var pageSlopSquare: Int = slopSquare
|
||||||
|
var pageSlopSquare2: Int = pageSlopSquare * pageSlopSquare
|
||||||
private val tlRect = RectF()
|
private val tlRect = RectF()
|
||||||
private val tcRect = RectF()
|
private val tcRect = RectF()
|
||||||
private val trRect = RectF()
|
private val trRect = RectF()
|
||||||
@ -182,7 +182,7 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
//在多点触控时,事件不走ACTION_DOWN分支而产生的特殊事件处理
|
//在多点触控时,事件不走ACTION_DOWN分支而产生的特殊事件处理
|
||||||
if (event.actionMasked == MotionEvent.ACTION_POINTER_DOWN || event.actionMasked == MotionEvent.ACTION_POINTER_UP){
|
if (event.actionMasked == MotionEvent.ACTION_POINTER_DOWN || event.actionMasked == MotionEvent.ACTION_POINTER_UP) {
|
||||||
pageDelegate?.onTouch(event)
|
pageDelegate?.onTouch(event)
|
||||||
}
|
}
|
||||||
when (event.action) {
|
when (event.action) {
|
||||||
@ -199,36 +199,34 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
|||||||
postDelayed(longPressRunnable, longPressTimeout)
|
postDelayed(longPressRunnable, longPressTimeout)
|
||||||
pressDown = true
|
pressDown = true
|
||||||
isMove = false
|
isMove = false
|
||||||
isPageMove = false
|
|
||||||
pageDelegate?.onTouch(event)
|
pageDelegate?.onTouch(event)
|
||||||
pageDelegate?.onDown()
|
pageDelegate?.onDown()
|
||||||
setStartPoint(event.x, event.y)
|
setStartPoint(event.x, event.y, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
MotionEvent.ACTION_MOVE -> {
|
MotionEvent.ACTION_MOVE -> {
|
||||||
|
val absX = abs(startX - event.x)
|
||||||
|
val absY = abs(startY - event.y)
|
||||||
if (!isMove) {
|
if (!isMove) {
|
||||||
isMove =
|
isMove = absX > slopSquare || absY > slopSquare
|
||||||
abs(startX - event.x) > slopSquare || abs(startY - event.y) > slopSquare
|
|
||||||
}
|
|
||||||
if (!isPageMove) {
|
|
||||||
isPageMove =
|
|
||||||
abs(startX - event.x) > pageSlopSquare || abs(startY - event.y) > pageSlopSquare
|
|
||||||
}
|
}
|
||||||
if (isMove) {
|
if (isMove) {
|
||||||
longPressed = false
|
longPressed = false
|
||||||
removeCallbacks(longPressRunnable)
|
removeCallbacks(longPressRunnable)
|
||||||
if (isTextSelected) {
|
if (isTextSelected) {
|
||||||
selectText(event.x, event.y)
|
selectText(event.x, event.y)
|
||||||
} else if (isPageMove) {
|
} else {
|
||||||
pageDelegate?.onTouch(event)
|
pageDelegate?.onTouch(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MotionEvent.ACTION_UP -> {
|
MotionEvent.ACTION_UP -> {
|
||||||
callBack.screenOffTimerStart()
|
callBack.screenOffTimerStart()
|
||||||
removeCallbacks(longPressRunnable)
|
removeCallbacks(longPressRunnable)
|
||||||
if (!pressDown) return true
|
if (!pressDown) return true
|
||||||
pressDown = false
|
pressDown = false
|
||||||
if (!isPageMove) {
|
if (!pageDelegate!!.isMoved && !isMove) {
|
||||||
if (!longPressed && !pressOnTextSelected) {
|
if (!longPressed && !pressOnTextSelected) {
|
||||||
if (!curPage.onClick(startX, startY)) {
|
if (!curPage.onClick(startX, startY)) {
|
||||||
onSingleTapUp()
|
onSingleTapUp()
|
||||||
@ -238,18 +236,19 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
|||||||
}
|
}
|
||||||
if (isTextSelected) {
|
if (isTextSelected) {
|
||||||
callBack.showTextActionMenu()
|
callBack.showTextActionMenu()
|
||||||
} else if (isPageMove) {
|
} else if (pageDelegate!!.isMoved) {
|
||||||
pageDelegate?.onTouch(event)
|
pageDelegate?.onTouch(event)
|
||||||
}
|
}
|
||||||
pressOnTextSelected = false
|
pressOnTextSelected = false
|
||||||
}
|
}
|
||||||
|
|
||||||
MotionEvent.ACTION_CANCEL -> {
|
MotionEvent.ACTION_CANCEL -> {
|
||||||
removeCallbacks(longPressRunnable)
|
removeCallbacks(longPressRunnable)
|
||||||
if (!pressDown) return true
|
if (!pressDown) return true
|
||||||
pressDown = false
|
pressDown = false
|
||||||
if (isTextSelected) {
|
if (isTextSelected) {
|
||||||
callBack.showTextActionMenu()
|
callBack.showTextActionMenu()
|
||||||
} else if (isPageMove) {
|
} else if (pageDelegate!!.isMoved) {
|
||||||
pageDelegate?.onTouch(event)
|
pageDelegate?.onTouch(event)
|
||||||
}
|
}
|
||||||
pressOnTextSelected = false
|
pressOnTextSelected = false
|
||||||
@ -375,27 +374,35 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
|||||||
mcRect.contains(startX, startY) -> if (!isAbortAnim) {
|
mcRect.contains(startX, startY) -> if (!isAbortAnim) {
|
||||||
click(AppConfig.clickActionMC)
|
click(AppConfig.clickActionMC)
|
||||||
}
|
}
|
||||||
|
|
||||||
bcRect.contains(startX, startY) -> {
|
bcRect.contains(startX, startY) -> {
|
||||||
click(AppConfig.clickActionBC)
|
click(AppConfig.clickActionBC)
|
||||||
}
|
}
|
||||||
|
|
||||||
blRect.contains(startX, startY) -> {
|
blRect.contains(startX, startY) -> {
|
||||||
click(AppConfig.clickActionBL)
|
click(AppConfig.clickActionBL)
|
||||||
}
|
}
|
||||||
|
|
||||||
brRect.contains(startX, startY) -> {
|
brRect.contains(startX, startY) -> {
|
||||||
click(AppConfig.clickActionBR)
|
click(AppConfig.clickActionBR)
|
||||||
}
|
}
|
||||||
|
|
||||||
mlRect.contains(startX, startY) -> {
|
mlRect.contains(startX, startY) -> {
|
||||||
click(AppConfig.clickActionML)
|
click(AppConfig.clickActionML)
|
||||||
}
|
}
|
||||||
|
|
||||||
mrRect.contains(startX, startY) -> {
|
mrRect.contains(startX, startY) -> {
|
||||||
click(AppConfig.clickActionMR)
|
click(AppConfig.clickActionMR)
|
||||||
}
|
}
|
||||||
|
|
||||||
tlRect.contains(startX, startY) -> {
|
tlRect.contains(startX, startY) -> {
|
||||||
click(AppConfig.clickActionTL)
|
click(AppConfig.clickActionTL)
|
||||||
}
|
}
|
||||||
|
|
||||||
tcRect.contains(startX, startY) -> {
|
tcRect.contains(startX, startY) -> {
|
||||||
click(AppConfig.clickActionTC)
|
click(AppConfig.clickActionTC)
|
||||||
}
|
}
|
||||||
|
|
||||||
trRect.contains(startX, startY) -> {
|
trRect.contains(startX, startY) -> {
|
||||||
click(AppConfig.clickActionTR)
|
click(AppConfig.clickActionTR)
|
||||||
}
|
}
|
||||||
@ -411,6 +418,7 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
|||||||
pageDelegate?.dismissSnackBar()
|
pageDelegate?.dismissSnackBar()
|
||||||
callBack.showActionMenu()
|
callBack.showActionMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
1 -> pageDelegate?.nextPageByAnim(defaultAnimationSpeed)
|
1 -> pageDelegate?.nextPageByAnim(defaultAnimationSpeed)
|
||||||
2 -> pageDelegate?.prevPageByAnim(defaultAnimationSpeed)
|
2 -> pageDelegate?.prevPageByAnim(defaultAnimationSpeed)
|
||||||
3 -> ReadBook.moveToNextChapter(true)
|
3 -> ReadBook.moveToNextChapter(true)
|
||||||
@ -436,6 +444,7 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
|||||||
curPage.selectStartMoveIndex(textPos)
|
curPage.selectStartMoveIndex(textPos)
|
||||||
curPage.selectEndMoveIndex(initialTextPos)
|
curPage.selectEndMoveIndex(initialTextPos)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
curPage.selectStartMoveIndex(initialTextPos)
|
curPage.selectStartMoveIndex(initialTextPos)
|
||||||
curPage.selectEndMoveIndex(textPos)
|
curPage.selectEndMoveIndex(textPos)
|
||||||
@ -461,9 +470,11 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
|||||||
PageDirection.PREV -> {
|
PageDirection.PREV -> {
|
||||||
pageFactory.moveToPrev(true)
|
pageFactory.moveToPrev(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
PageDirection.NEXT -> {
|
PageDirection.NEXT -> {
|
||||||
pageFactory.moveToNext(true)
|
pageFactory.moveToNext(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -478,15 +489,19 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
|||||||
PageAnim.coverPageAnim -> if (pageDelegate !is CoverPageDelegate) {
|
PageAnim.coverPageAnim -> if (pageDelegate !is CoverPageDelegate) {
|
||||||
pageDelegate = CoverPageDelegate(this)
|
pageDelegate = CoverPageDelegate(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
PageAnim.slidePageAnim -> if (pageDelegate !is SlidePageDelegate) {
|
PageAnim.slidePageAnim -> if (pageDelegate !is SlidePageDelegate) {
|
||||||
pageDelegate = SlidePageDelegate(this)
|
pageDelegate = SlidePageDelegate(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
PageAnim.simulationPageAnim -> if (pageDelegate !is SimulationPageDelegate) {
|
PageAnim.simulationPageAnim -> if (pageDelegate !is SimulationPageDelegate) {
|
||||||
pageDelegate = SimulationPageDelegate(this)
|
pageDelegate = SimulationPageDelegate(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
PageAnim.scrollPageAnim -> if (pageDelegate !is ScrollPageDelegate) {
|
PageAnim.scrollPageAnim -> if (pageDelegate !is ScrollPageDelegate) {
|
||||||
pageDelegate = ScrollPageDelegate(this)
|
pageDelegate = ScrollPageDelegate(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> if (pageDelegate !is NoAnimPageDelegate) {
|
else -> if (pageDelegate !is NoAnimPageDelegate) {
|
||||||
pageDelegate = NoAnimPageDelegate(this)
|
pageDelegate = NoAnimPageDelegate(this)
|
||||||
}
|
}
|
||||||
@ -524,6 +539,7 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
|||||||
fun upPageSlopSquare() {
|
fun upPageSlopSquare() {
|
||||||
val pageTouchSlop = AppConfig.pageTouchSlop
|
val pageTouchSlop = AppConfig.pageTouchSlop
|
||||||
this.pageSlopSquare = if (pageTouchSlop == 0) slopSquare else pageTouchSlop
|
this.pageSlopSquare = if (pageTouchSlop == 0) slopSquare else pageTouchSlop
|
||||||
|
pageSlopSquare2 = this.pageSlopSquare * this.pageSlopSquare
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,7 +13,7 @@ abstract class HorizontalPageDelegate(readView: ReadView) : PageDelegate(readVie
|
|||||||
protected var prevBitmap: Bitmap? = null
|
protected var prevBitmap: Bitmap? = null
|
||||||
protected var nextBitmap: Bitmap? = null
|
protected var nextBitmap: Bitmap? = null
|
||||||
protected var canvas: Canvas = Canvas()
|
protected var canvas: Canvas = Canvas()
|
||||||
private val slopSquare by lazy { readView.slopSquare * readView.slopSquare }
|
private val slopSquare get() = readView.pageSlopSquare2
|
||||||
|
|
||||||
override fun setDirection(direction: PageDirection) {
|
override fun setDirection(direction: PageDirection) {
|
||||||
super.setDirection(direction)
|
super.setDirection(direction)
|
||||||
@ -91,6 +91,7 @@ abstract class HorizontalPageDelegate(readView: ReadView) : PageDelegate(readVie
|
|||||||
}
|
}
|
||||||
setDirection(PageDirection.NEXT)
|
setDirection(PageDirection.NEXT)
|
||||||
}
|
}
|
||||||
|
readView.setStartPoint(event.x, event.y, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isMoved) {
|
if (isMoved) {
|
||||||
|
@ -17,6 +17,7 @@ class ScrollPageDelegate(readView: ReadView) : PageDelegate(readView) {
|
|||||||
|
|
||||||
//速度追踪器
|
//速度追踪器
|
||||||
private val mVelocity: VelocityTracker = VelocityTracker.obtain()
|
private val mVelocity: VelocityTracker = VelocityTracker.obtain()
|
||||||
|
private val slopSquare get() = readView.pageSlopSquare2
|
||||||
|
|
||||||
var noAnim: Boolean = false
|
var noAnim: Boolean = false
|
||||||
|
|
||||||
@ -77,12 +78,17 @@ class ScrollPageDelegate(readView: ReadView) : PageDelegate(readView) {
|
|||||||
//多点触控时即最后按下的手指产生的事件点
|
//多点触控时即最后按下的手指产生的事件点
|
||||||
val pointX = event.getX(event.pointerCount - 1)
|
val pointX = event.getX(event.pointerCount - 1)
|
||||||
val pointY = event.getY(event.pointerCount - 1)
|
val pointY = event.getY(event.pointerCount - 1)
|
||||||
readView.setTouchPoint(pointX, pointY)
|
if (isMoved) {
|
||||||
|
readView.setTouchPoint(pointX, pointY)
|
||||||
|
}
|
||||||
if (!isMoved) {
|
if (!isMoved) {
|
||||||
val deltaX = (pointX - startX).toInt()
|
val deltaX = (pointX - startX).toInt()
|
||||||
val deltaY = (pointY - startY).toInt()
|
val deltaY = (pointY - startY).toInt()
|
||||||
val distance = deltaX * deltaX + deltaY * deltaY
|
val distance = deltaX * deltaX + deltaY * deltaY
|
||||||
isMoved = distance > readView.slopSquare
|
isMoved = distance > slopSquare
|
||||||
|
if (isMoved) {
|
||||||
|
readView.setStartPoint(event.x, event.y, false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (isMoved) {
|
if (isMoved) {
|
||||||
isRunning = true
|
isRunning = true
|
||||||
|
Loading…
Reference in New Issue
Block a user