pull/32/head
kunfei 5 years ago
parent af90d2e3c4
commit 1c13a62438
  1. 9
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt
  2. 5
      app/src/main/java/io/legado/app/ui/widget/page/PageView.kt
  3. 14
      app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.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<ReadBookViewModel>(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

@ -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()
}
}

@ -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,6 +197,10 @@ abstract class PageDelegate(protected val pageView: PageView) {
override fun onSingleTapUp(e: MotionEvent): Boolean {
val x = e.x
val y = e.y
if (centerRectF.contains(x, y)) {
pageView.clickCenter()
setTouchPoint(x, y)
} else {
direction = if (x > viewWidth / 2) Direction.NEXT else Direction.PREV
if (direction == Direction.NEXT) {
//判断是否下一页存在
@ -213,6 +221,7 @@ abstract class PageDelegate(protected val pageView: PageView) {
}
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()
}
}
Loading…
Cancel
Save