diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt index db6810886..980055745 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt @@ -22,6 +22,7 @@ import io.legado.app.service.ReadAloudService import io.legado.app.ui.changesource.ChangeSourceDialog import io.legado.app.ui.chapterlist.ChapterListActivity import io.legado.app.ui.readbook.config.MoreConfigDialog +import io.legado.app.ui.readbook.config.ReadAloudDialog import io.legado.app.ui.readbook.config.ReadStyleDialog import io.legado.app.ui.replacerule.ReplaceRuleActivity import io.legado.app.ui.sourceedit.SourceEditActivity @@ -282,6 +283,14 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea viewModel.moveToPrevChapter() } + override fun clickCenter() { + if (readAloudStatus != Status.STOP) { + ReadAloudDialog().show(supportFragmentManager, "readAloud") + } else { + read_menu.runMenuIn() + } + } + private fun onClickReadAloud() { if (!ReadAloudService.isRun) { readAloudStatus = Status.STOP diff --git a/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt b/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt index 1744020d8..e29f5e83d 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt @@ -211,6 +211,10 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att nextPage?.upBattery(battery) } + override fun clickCenter() { + callback?.clickCenter() + } + interface CallBack { fun chapterSize(): Int fun durChapterIndex(): Int @@ -220,5 +224,6 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att fun moveToNextChapter() fun moveToPrevChapter() fun setPageIndex(pageIndex: Int) + fun clickCenter() } } 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 9261a0e06..f1d730469 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 @@ -2,18 +2,18 @@ package io.legado.app.ui.widget.page.delegate import android.graphics.Bitmap import android.graphics.Canvas +import android.graphics.RectF 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 import kotlin.math.abs abstract class PageDelegate(protected val pageView: PageView) { - + val centerRectF = RectF() //起始点 protected var startX: Float = 0.toFloat() protected var startY: Float = 0.toFloat() @@ -95,6 +95,10 @@ abstract class PageDelegate(protected val pageView: PageView) { viewWidth = width viewHeight = height invalidate() + centerRectF.set( + width / 3f, height / 3f, + width * 2f / 3, height * 2f / 3 + ) } fun scroll() { @@ -193,26 +197,31 @@ abstract class PageDelegate(protected val pageView: PageView) { override fun onSingleTapUp(e: MotionEvent): Boolean { val x = e.x val y = e.y - direction = if (x > viewWidth / 2) Direction.NEXT else Direction.PREV - if (direction == Direction.NEXT) { - //判断是否下一页存在 - val hasNext = pageView.hasNext() - //设置动画方向 - if (!hasNext) { - return true - } - //下一页截图 - bitmap = nextPage?.screenshot() + if (centerRectF.contains(x, y)) { + pageView.clickCenter() + setTouchPoint(x, y) } else { - val hasPrev = pageView.hasPrev() - if (!hasPrev) { - return true + direction = if (x > viewWidth / 2) Direction.NEXT else Direction.PREV + if (direction == Direction.NEXT) { + //判断是否下一页存在 + val hasNext = pageView.hasNext() + //设置动画方向 + if (!hasNext) { + return true + } + //下一页截图 + bitmap = nextPage?.screenshot() + } else { + val hasPrev = pageView.hasPrev() + if (!hasPrev) { + return true + } + //上一页截图 + bitmap = prevPage?.screenshot() } - //上一页截图 - bitmap = prevPage?.screenshot() + setTouchPoint(x, y) + onScrollStart() } - setTouchPoint(x, y) - onScrollStart() return true } @@ -258,5 +267,6 @@ abstract class PageDelegate(protected val pageView: PageView) { interface PageInterface { fun hasNext(): Boolean fun hasPrev(): Boolean + fun clickCenter() } } \ No newline at end of file