pull/478/head
gedoor 4 years ago
parent 2e77a5f29d
commit d47d43df38
  1. 61
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt

@ -72,19 +72,18 @@ class PageView(context: Context, attrs: AttributeSet) :
private var firstCharIndex: Int = 0 private var firstCharIndex: Int = 0
val slopSquare by lazy { ViewConfiguration.get(context).scaledTouchSlop } val slopSquare by lazy { ViewConfiguration.get(context).scaledTouchSlop }
private val topLeftRectF = RectF(0F, 0F, width * 0.33f, height * 0.33f) private val tlRectF = RectF(10F, 10F, width * 0.33f, height * 0.33f)
private val topCenterRectF = RectF(width * 0.33f, 0F, width * 0.66f, height * 0.33f) private val tcRectF = RectF(width * 0.33f, 10F, width * 0.66f, height * 0.33f)
private val topRightRectF = RectF(width * 0.36f, 0F, width.toFloat(), height * 0.33f) private val trRectF = RectF(width * 0.36f, 10F, width - 10f, height * 0.33f)
private val middleLeftRectF = RectF(0F, height * 0.33f, width * 0.33f, height * 0.66f) private val mlRectF = RectF(10F, 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 mcRectF = RectF(width * 0.33f, height * 0.33f, width * 0.66f, height * 0.66f)
private val middleRightRectF = private val mrRectF = RectF(width * 0.66f, height * 0.33f, width - 10f, height * 0.66f)
RectF(width * 0.66f, height * 0.33f, width.toFloat(), height * 0.66f) private val blRectF = RectF(10F, height * 0.66f, width * 0.33f, height - 10f)
private val bottomLeftRectF = RectF(0F, height * 0.66f, width * 0.33f, height.toFloat()) private val bcRectF = RectF(width * 0.33f, height * 0.66f, width * 0.66f, height - 10f)
private val bottomCenterRectF = private val brRectF = RectF(width * 0.66f, height * 0.66f, width - 10f, height - 10f)
RectF(width * 0.33f, height * 0.66f, width * 0.66f, height.toFloat()) private val autoPageRect by lazy {
private val bottomRightRectF = Rect()
RectF(width * 0.66f, height * 0.66f, width.toFloat(), height.toFloat()) }
private val autoPageRect by lazy { Rect() }
private val autoPagePint by lazy { private val autoPagePint by lazy {
Paint().apply { Paint().apply {
color = context.accentColor color = context.accentColor
@ -102,15 +101,15 @@ class PageView(context: Context, attrs: AttributeSet) :
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
super.onSizeChanged(w, h, oldw, oldh) super.onSizeChanged(w, h, oldw, oldh)
topLeftRectF.set(0F, 0F, width * 0.33f, height * 0.33f) tlRectF.set(10F, 10F, width * 0.33f, height * 0.33f)
topCenterRectF.set(width * 0.33f, 0F, width * 0.66f, height * 0.33f) tcRectF.set(width * 0.33f, 10F, width * 0.66f, height * 0.33f)
topRightRectF.set(width * 0.36f, 0F, width.toFloat(), height * 0.33f) trRectF.set(width * 0.36f, 10F, width - 10f, height * 0.33f)
middleLeftRectF.set(0F, height * 0.33f, width * 0.33f, height * 0.66f) mlRectF.set(10F, height * 0.33f, width * 0.33f, height * 0.66f)
centerRectF.set(width * 0.33f, height * 0.33f, width * 0.66f, height * 0.66f) mcRectF.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) mrRectF.set(width * 0.66f, height * 0.33f, width - 10f, height * 0.66f)
bottomLeftRectF.set(0F, height * 0.66f, width * 0.33f, height.toFloat()) blRectF.set(10F, height * 0.66f, width * 0.33f, height - 10f)
bottomCenterRectF.set(width * 0.33f, height * 0.66f, width * 0.66f, height.toFloat()) bcRectF.set(width * 0.33f, height * 0.66f, width * 0.66f, height - 10f)
bottomRightRectF.set(width * 0.66f, height * 0.66f, width.toFloat(), height.toFloat()) brRectF.set(width * 0.66f, height * 0.66f, width - 10f, height - 10f)
prevPage.x = -w.toFloat() prevPage.x = -w.toFloat()
pageDelegate?.setViewSize(w, h) pageDelegate?.setViewSize(w, h)
if (oldw != 0 && oldh != 0) { if (oldw != 0 && oldh != 0) {
@ -261,31 +260,31 @@ class PageView(context: Context, attrs: AttributeSet) :
private fun onSingleTapUp(): Boolean { private fun onSingleTapUp(): Boolean {
when { when {
isTextSelected -> isTextSelected = false isTextSelected -> isTextSelected = false
centerRectF.contains(startX, startY) -> if (!isAbortAnim) { mcRectF.contains(startX, startY) -> if (!isAbortAnim) {
click(AppConfig.clickActionMiddleCenter) click(AppConfig.clickActionMiddleCenter)
} }
bottomCenterRectF.contains(startX, startY) -> { bcRectF.contains(startX, startY) -> {
click(AppConfig.clickActionBottomCenter) click(AppConfig.clickActionBottomCenter)
} }
bottomLeftRectF.contains(startX, startY) -> { blRectF.contains(startX, startY) -> {
click(AppConfig.clickActionBottomLeft) click(AppConfig.clickActionBottomLeft)
} }
bottomRightRectF.contains(startX, startY) -> { brRectF.contains(startX, startY) -> {
click(AppConfig.clickActionBottomRight) click(AppConfig.clickActionBottomRight)
} }
middleLeftRectF.contains(startX, startY) -> { mlRectF.contains(startX, startY) -> {
click(AppConfig.clickActionMiddleLeft) click(AppConfig.clickActionMiddleLeft)
} }
middleRightRectF.contains(startX, startY) -> { mrRectF.contains(startX, startY) -> {
click(AppConfig.clickActionMiddleRight) click(AppConfig.clickActionMiddleRight)
} }
topLeftRectF.contains(startX, startY) -> { tlRectF.contains(startX, startY) -> {
click(AppConfig.clickActionTopLeft) click(AppConfig.clickActionTopLeft)
} }
topCenterRectF.contains(startX, startY) -> { tcRectF.contains(startX, startY) -> {
click(AppConfig.clickActionTopCenter) click(AppConfig.clickActionTopCenter)
} }
topRightRectF.contains(startX, startY) -> { trRectF.contains(startX, startY) -> {
click(AppConfig.clickActionTopRight) click(AppConfig.clickActionTopRight)
} }
} }

Loading…
Cancel
Save