pull/2091/head
821938089 2 years ago
parent a644951a08
commit 7b02f722a3
  1. 1
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 6
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  3. 3
      app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt
  4. 33
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/CoverPageDelegate.kt
  5. 2
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt
  6. 5
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/NoAnimPageDelegate.kt

@ -164,6 +164,7 @@ class ReadBookActivity : BaseReadBookActivity(),
binding.cursorRight.setColorFilter(accentColor) binding.cursorRight.setColorFilter(accentColor)
binding.cursorLeft.setOnTouchListener(this) binding.cursorLeft.setOnTouchListener(this)
binding.cursorRight.setOnTouchListener(this) binding.cursorRight.setOnTouchListener(this)
window.setBackgroundDrawable(null)
upScreenTimeOut() upScreenTimeOut()
ReadBook.callBack = this ReadBook.callBack = this
} }

@ -49,8 +49,6 @@ class PageView(context: Context) : FrameLayout(context) {
init { init {
if (!isInEditMode) { if (!isInEditMode) {
//设置背景防止切换背景时文字重叠
setBackgroundColor(context.getCompatColor(R.color.background))
upStyle() upStyle()
} }
binding.contentTextView.upView = { binding.contentTextView.upView = {
@ -202,7 +200,11 @@ class PageView(context: Context) : FrameLayout(context) {
} }
fun upBg() { fun upBg() {
if (ReadBookConfig.bgAlpha < 100) {
binding.vwRoot.backgroundColor = ReadBookConfig.bgMeanColor binding.vwRoot.backgroundColor = ReadBookConfig.bgMeanColor
} else {
binding.vwRoot.background = null
}
binding.vwBg.background = ReadBookConfig.bg binding.vwBg.background = ReadBookConfig.bg
upBgAlpha() upBgAlpha()
} }

@ -26,6 +26,7 @@ import io.legado.app.ui.book.read.page.entities.TextPos
import io.legado.app.ui.book.read.page.provider.ChapterProvider import io.legado.app.ui.book.read.page.provider.ChapterProvider
import io.legado.app.ui.book.read.page.provider.TextPageFactory import io.legado.app.ui.book.read.page.provider.TextPageFactory
import io.legado.app.utils.activity import io.legado.app.utils.activity
import io.legado.app.utils.invisible
import io.legado.app.utils.screenshot import io.legado.app.utils.screenshot
import java.text.BreakIterator import java.text.BreakIterator
import java.util.* import java.util.*
@ -97,6 +98,8 @@ class ReadView(context: Context, attrs: AttributeSet) :
addView(nextPage) addView(nextPage)
addView(curPage) addView(curPage)
addView(prevPage) addView(prevPage)
nextPage.invisible()
prevPage.invisible()
if (!isInEditMode) { if (!isInEditMode) {
upBg() upBg()
setWillNotDraw(false) setWillNotDraw(false)

@ -5,6 +5,7 @@ import android.graphics.Matrix
import android.graphics.drawable.GradientDrawable import android.graphics.drawable.GradientDrawable
import io.legado.app.ui.book.read.page.ReadView import io.legado.app.ui.book.read.page.ReadView
import io.legado.app.ui.book.read.page.entities.PageDirection import io.legado.app.ui.book.read.page.entities.PageDirection
import io.legado.app.utils.screenshot
class CoverPageDelegate(readView: ReadView) : HorizontalPageDelegate(readView) { class CoverPageDelegate(readView: ReadView) : HorizontalPageDelegate(readView) {
private val bitmapMatrix = Matrix() private val bitmapMatrix = Matrix()
@ -30,18 +31,46 @@ class CoverPageDelegate(readView: ReadView) : HorizontalPageDelegate(readView) {
val distanceX = if (offsetX > 0) offsetX - viewWidth else offsetX + viewWidth val distanceX = if (offsetX > 0) offsetX - viewWidth else offsetX + viewWidth
if (mDirection == PageDirection.PREV) { if (mDirection == PageDirection.PREV) {
if (offsetX <= viewWidth) {
bitmapMatrix.setTranslate(distanceX, 0.toFloat()) bitmapMatrix.setTranslate(distanceX, 0.toFloat())
curBitmap?.let { canvas.drawBitmap(it, 0f, 0f, null) }
prevBitmap?.let { canvas.drawBitmap(it, bitmapMatrix, null) } prevBitmap?.let { canvas.drawBitmap(it, bitmapMatrix, null) }
addShadow(distanceX.toInt(), canvas) addShadow(distanceX.toInt(), canvas)
} else {
prevBitmap?.let { canvas.drawBitmap(it, 0f, 0f, null) }
}
} else if (mDirection == PageDirection.NEXT) { } else if (mDirection == PageDirection.NEXT) {
bitmapMatrix.setTranslate(distanceX - viewWidth, 0.toFloat()) bitmapMatrix.setTranslate(distanceX - viewWidth, 0.toFloat())
nextBitmap?.let { canvas.drawBitmap(it, 0f, 0f, null) } nextBitmap?.let {
canvas.apply {
save()
val width = it.width.toFloat()
val height = it.height.toFloat()
clipRect(width + offsetX, 0f, width, height)
drawBitmap(it, 0f, 0f, null)
restore()
}
}
curBitmap?.let { canvas.drawBitmap(it, bitmapMatrix, null) } curBitmap?.let { canvas.drawBitmap(it, bitmapMatrix, null) }
addShadow(distanceX.toInt(), canvas) addShadow(distanceX.toInt(), canvas)
} }
} }
override fun setBitmap() {
when (mDirection) {
PageDirection.PREV -> {
prevBitmap?.recycle()
prevBitmap = prevPage.screenshot()
}
PageDirection.NEXT -> {
nextBitmap?.recycle()
nextBitmap = nextPage.screenshot()
curBitmap?.recycle()
curBitmap = curPage.screenshot()
}
else -> Unit
}
}
private fun addShadow(left: Int, canvas: Canvas) { private fun addShadow(left: Int, canvas: Canvas) {
if (left < 0) { if (left < 0) {
shadowDrawableR.setBounds(left + viewWidth, 0, left + viewWidth + 30, viewHeight) shadowDrawableR.setBounds(left + viewWidth, 0, left + viewWidth + 30, viewHeight)

@ -17,7 +17,7 @@ abstract class HorizontalPageDelegate(readView: ReadView) : PageDelegate(readVie
setBitmap() setBitmap()
} }
private fun setBitmap() { open fun setBitmap() {
when (mDirection) { when (mDirection) {
PageDirection.PREV -> { PageDirection.PREV -> {
prevBitmap?.recycle() prevBitmap?.recycle()

@ -2,9 +2,14 @@ package io.legado.app.ui.book.read.page.delegate
import android.graphics.Canvas import android.graphics.Canvas
import io.legado.app.ui.book.read.page.ReadView import io.legado.app.ui.book.read.page.ReadView
import io.legado.app.ui.book.read.page.entities.PageDirection
class NoAnimPageDelegate(readView: ReadView) : HorizontalPageDelegate(readView) { class NoAnimPageDelegate(readView: ReadView) : HorizontalPageDelegate(readView) {
override fun setDirection(direction: PageDirection) {
mDirection = direction
}
override fun onAnimStart(animationSpeed: Int) { override fun onAnimStart(animationSpeed: Int) {
if (!isCancel) { if (!isCancel) {
readView.fillPage(mDirection) readView.fillPage(mDirection)

Loading…
Cancel
Save