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. 48
      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.changesource.ChangeSourceDialog
import io.legado.app.ui.chapterlist.ChapterListActivity import io.legado.app.ui.chapterlist.ChapterListActivity
import io.legado.app.ui.readbook.config.MoreConfigDialog 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.readbook.config.ReadStyleDialog
import io.legado.app.ui.replacerule.ReplaceRuleActivity import io.legado.app.ui.replacerule.ReplaceRuleActivity
import io.legado.app.ui.sourceedit.SourceEditActivity import io.legado.app.ui.sourceedit.SourceEditActivity
@ -282,6 +283,14 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
viewModel.moveToPrevChapter() viewModel.moveToPrevChapter()
} }
override fun clickCenter() {
if (readAloudStatus != Status.STOP) {
ReadAloudDialog().show(supportFragmentManager, "readAloud")
} else {
read_menu.runMenuIn()
}
}
private fun onClickReadAloud() { private fun onClickReadAloud() {
if (!ReadAloudService.isRun) { if (!ReadAloudService.isRun) {
readAloudStatus = Status.STOP readAloudStatus = Status.STOP

@ -211,6 +211,10 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att
nextPage?.upBattery(battery) nextPage?.upBattery(battery)
} }
override fun clickCenter() {
callback?.clickCenter()
}
interface CallBack { interface CallBack {
fun chapterSize(): Int fun chapterSize(): Int
fun durChapterIndex(): Int fun durChapterIndex(): Int
@ -220,5 +224,6 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att
fun moveToNextChapter() fun moveToNextChapter()
fun moveToPrevChapter() fun moveToPrevChapter()
fun setPageIndex(pageIndex: Int) 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.Bitmap
import android.graphics.Canvas import android.graphics.Canvas
import android.graphics.RectF
import android.view.GestureDetector import android.view.GestureDetector
import android.view.MotionEvent import android.view.MotionEvent
import android.widget.Scroller import android.widget.Scroller
import androidx.interpolator.view.animation.FastOutLinearInInterpolator 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.ContentView
import io.legado.app.ui.widget.page.PageView import io.legado.app.ui.widget.page.PageView
import io.legado.app.utils.screenshot import io.legado.app.utils.screenshot
import kotlin.math.abs import kotlin.math.abs
abstract class PageDelegate(protected val pageView: PageView) { abstract class PageDelegate(protected val pageView: PageView) {
val centerRectF = RectF()
//起始点 //起始点
protected var startX: Float = 0.toFloat() protected var startX: Float = 0.toFloat()
protected var startY: Float = 0.toFloat() protected var startY: Float = 0.toFloat()
@ -95,6 +95,10 @@ abstract class PageDelegate(protected val pageView: PageView) {
viewWidth = width viewWidth = width
viewHeight = height viewHeight = height
invalidate() invalidate()
centerRectF.set(
width / 3f, height / 3f,
width * 2f / 3, height * 2f / 3
)
} }
fun scroll() { fun scroll() {
@ -193,26 +197,31 @@ abstract class PageDelegate(protected val pageView: PageView) {
override fun onSingleTapUp(e: MotionEvent): Boolean { override fun onSingleTapUp(e: MotionEvent): Boolean {
val x = e.x val x = e.x
val y = e.y val y = e.y
direction = if (x > viewWidth / 2) Direction.NEXT else Direction.PREV if (centerRectF.contains(x, y)) {
if (direction == Direction.NEXT) { pageView.clickCenter()
//判断是否下一页存在 setTouchPoint(x, y)
val hasNext = pageView.hasNext()
//设置动画方向
if (!hasNext) {
return true
}
//下一页截图
bitmap = nextPage?.screenshot()
} else { } else {
val hasPrev = pageView.hasPrev() direction = if (x > viewWidth / 2) Direction.NEXT else Direction.PREV
if (!hasPrev) { if (direction == Direction.NEXT) {
return true //判断是否下一页存在
val hasNext = pageView.hasNext()
//设置动画方向
if (!hasNext) {
return true
}
//下一页截图
bitmap = nextPage?.screenshot()
} else {
val hasPrev = pageView.hasPrev()
if (!hasPrev) {
return true
}
//上一页截图
bitmap = prevPage?.screenshot()
} }
//上一页截图 setTouchPoint(x, y)
bitmap = prevPage?.screenshot() onScrollStart()
} }
setTouchPoint(x, y)
onScrollStart()
return true return true
} }
@ -258,5 +267,6 @@ abstract class PageDelegate(protected val pageView: PageView) {
interface PageInterface { interface PageInterface {
fun hasNext(): Boolean fun hasNext(): Boolean
fun hasPrev(): Boolean fun hasPrev(): Boolean
fun clickCenter()
} }
} }
Loading…
Cancel
Save