From e7b699ae686076bc66e5ed887811bc4ed092b0e3 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 11 Nov 2020 08:54:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=BC=BA=E7=82=B9=E5=87=BB=E7=BF=BB?= =?UTF-8?q?=E9=A1=B5=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/ReadBookActivity.kt | 2 +- .../legado/app/ui/book/read/page/PageView.kt | 68 +++++++++++++++---- 2 files changed, 56 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 2072a45f4..19166cd0e 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -557,7 +557,7 @@ class ReadBookActivity : ReadBookBaseActivity(), viewModel.changeTo(book) } - override fun clickCenter() { + override fun showActionMenu() { when { BaseReadAloudService.isRun -> { showReadAloudDialog() diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index 6a0ea71da..2cf00e902 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -72,7 +72,18 @@ class PageView(context: Context, attrs: AttributeSet) : private var firstCharIndex: Int = 0 val slopSquare by lazy { ViewConfiguration.get(context).scaledTouchSlop } + private val topLeftRectF = RectF(0F, 0F, width * 0.33f, height * 0.33f) + private val topCenterRectF = RectF(width * 0.33f, 0F, width * 0.66f, height * 0.33f) + private val topRightRectF = RectF(width * 0.36f, 0F, width.toFloat(), height * 0.33f) + private val middleLeftRectF = RectF(0F, height * 0.33f, width * 0.33f, height * 0.66f) private val centerRectF = RectF(width * 0.33f, height * 0.33f, width * 0.66f, height * 0.66f) + private val middleRightRectF = + RectF(width * 0.66f, height * 0.33f, width.toFloat(), height * 0.66f) + private val bottomLeftRectF = RectF(0F, height * 0.66f, width * 0.33f, height.toFloat()) + private val bottomCenterRectF = + RectF(width * 0.33f, height * 0.66f, width * 0.66f, height.toFloat()) + private val bottomRightRectF = + RectF(width * 0.66f, height * 0.66f, width.toFloat(), height.toFloat()) private val autoPageRect by lazy { Rect() } private val autoPagePint by lazy { Paint().apply { @@ -91,7 +102,15 @@ class PageView(context: Context, attrs: AttributeSet) : override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { super.onSizeChanged(w, h, oldw, oldh) + topLeftRectF.set(0F, 0F, width * 0.33f, height * 0.33f) + topCenterRectF.set(width * 0.33f, 0F, width * 0.66f, height * 0.33f) + topRightRectF.set(width * 0.36f, 0F, width.toFloat(), height * 0.33f) + middleLeftRectF.set(0F, height * 0.33f, width * 0.33f, height * 0.66f) centerRectF.set(width * 0.33f, height * 0.33f, width * 0.66f, height * 0.66f) + middleRightRectF.set(width * 0.66f, height * 0.33f, width.toFloat(), height * 0.66f) + bottomLeftRectF.set(0F, height * 0.66f, width * 0.33f, height.toFloat()) + bottomCenterRectF.set(width * 0.33f, height * 0.66f, width * 0.66f, height.toFloat()) + bottomRightRectF.set(width * 0.66f, height * 0.66f, width.toFloat(), height.toFloat()) prevPage.x = -w.toFloat() pageDelegate?.setViewSize(w, h) if (oldw != 0 && oldh != 0) { @@ -240,24 +259,47 @@ class PageView(context: Context, attrs: AttributeSet) : * 单击 */ private fun onSingleTapUp(): Boolean { - if (isTextSelected) { - isTextSelected = false - return true - } - if (centerRectF.contains(startX, startY)) { - if (!isAbortAnim) { - callBack.clickCenter() + when { + isTextSelected -> isTextSelected = false + centerRectF.contains(startX, startY) -> if (!isAbortAnim) { + click(AppConfig.clickActionMiddleCenter) + } + bottomCenterRectF.contains(startX, startY) -> { + click(AppConfig.clickActionBottomCenter) + } + bottomLeftRectF.contains(startX, startY) -> { + click(AppConfig.clickActionBottomLeft) + } + bottomRightRectF.contains(startX, startY) -> { + click(AppConfig.clickActionBottomRight) + } + middleLeftRectF.contains(startX, startY) -> { + click(AppConfig.clickActionMiddleLeft) + } + middleRightRectF.contains(startX, startY) -> { + click(AppConfig.clickActionMiddleRight) } - } else if (AppConfig.clickTurnPage) { - if (startX > width / 2) { - pageDelegate?.nextPageByAnim(defaultAnimationSpeed) - } else { - pageDelegate?.prevPageByAnim(defaultAnimationSpeed) + topLeftRectF.contains(startX, startY) -> { + click(AppConfig.clickActionTopLeft) + } + topCenterRectF.contains(startX, startY) -> { + click(AppConfig.clickActionTopCenter) + } + topRightRectF.contains(startX, startY) -> { + click(AppConfig.clickActionTopRight) } } return true } + private fun click(action: Int) { + when (action) { + 0 -> callBack.showActionMenu() + 1 -> pageDelegate?.nextPageByAnim(defaultAnimationSpeed) + 2 -> pageDelegate?.prevPageByAnim(defaultAnimationSpeed) + } + } + /** * 选择文本 */ @@ -409,7 +451,7 @@ class PageView(context: Context, attrs: AttributeSet) : val isInitFinish: Boolean val isAutoPage: Boolean val autoPageProgress: Int - fun clickCenter() + fun showActionMenu() fun screenOffTimerStart() fun showTextActionMenu() }