diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index d93bb840d..cb31722c0 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -164,6 +164,7 @@ class ReadBookActivity : BaseReadBookActivity(), binding.cursorRight.setColorFilter(accentColor) binding.cursorLeft.setOnTouchListener(this) binding.cursorRight.setOnTouchListener(this) + window.setBackgroundDrawable(null) upScreenTimeOut() ReadBook.callBack = this } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index 8f7e85619..5d9e1b463 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -49,8 +49,6 @@ class PageView(context: Context) : FrameLayout(context) { init { if (!isInEditMode) { - //设置背景防止切换背景时文字重叠 - setBackgroundColor(context.getCompatColor(R.color.background)) upStyle() } binding.contentTextView.upView = { @@ -202,7 +200,11 @@ class PageView(context: Context) : FrameLayout(context) { } fun upBg() { - binding.vwRoot.backgroundColor = ReadBookConfig.bgMeanColor + if (ReadBookConfig.bgAlpha < 100) { + binding.vwRoot.backgroundColor = ReadBookConfig.bgMeanColor + } else { + binding.vwRoot.background = null + } binding.vwBg.background = ReadBookConfig.bg upBgAlpha() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt index 135d5562c..55b9356c2 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt @@ -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.TextPageFactory import io.legado.app.utils.activity +import io.legado.app.utils.invisible import io.legado.app.utils.screenshot import java.text.BreakIterator import java.util.* @@ -97,6 +98,8 @@ class ReadView(context: Context, attrs: AttributeSet) : addView(nextPage) addView(curPage) addView(prevPage) + nextPage.invisible() + prevPage.invisible() if (!isInEditMode) { upBg() setWillNotDraw(false) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/CoverPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/CoverPageDelegate.kt index c0024c81c..2c9a767aa 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/CoverPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/CoverPageDelegate.kt @@ -5,6 +5,7 @@ import android.graphics.Matrix import android.graphics.drawable.GradientDrawable import io.legado.app.ui.book.read.page.ReadView import io.legado.app.ui.book.read.page.entities.PageDirection +import io.legado.app.utils.screenshot class CoverPageDelegate(readView: ReadView) : HorizontalPageDelegate(readView) { private val bitmapMatrix = Matrix() @@ -30,18 +31,46 @@ class CoverPageDelegate(readView: ReadView) : HorizontalPageDelegate(readView) { val distanceX = if (offsetX > 0) offsetX - viewWidth else offsetX + viewWidth if (mDirection == PageDirection.PREV) { - bitmapMatrix.setTranslate(distanceX, 0.toFloat()) - curBitmap?.let { canvas.drawBitmap(it, 0f, 0f, null) } - prevBitmap?.let { canvas.drawBitmap(it, bitmapMatrix, null) } - addShadow(distanceX.toInt(), canvas) + if (offsetX <= viewWidth) { + bitmapMatrix.setTranslate(distanceX, 0.toFloat()) + prevBitmap?.let { canvas.drawBitmap(it, bitmapMatrix, null) } + addShadow(distanceX.toInt(), canvas) + } else { + prevBitmap?.let { canvas.drawBitmap(it, 0f, 0f, null) } + } } else if (mDirection == PageDirection.NEXT) { 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) } 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) { if (left < 0) { shadowDrawableR.setBounds(left + viewWidth, 0, left + viewWidth + 30, viewHeight) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt index 0d70b03f2..471006247 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt @@ -17,7 +17,7 @@ abstract class HorizontalPageDelegate(readView: ReadView) : PageDelegate(readVie setBitmap() } - private fun setBitmap() { + open fun setBitmap() { when (mDirection) { PageDirection.PREV -> { prevBitmap?.recycle() diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/NoAnimPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/NoAnimPageDelegate.kt index 9809a4f71..706a509d6 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/NoAnimPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/NoAnimPageDelegate.kt @@ -2,9 +2,14 @@ package io.legado.app.ui.book.read.page.delegate import android.graphics.Canvas 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) { + override fun setDirection(direction: PageDirection) { + mDirection = direction + } + override fun onAnimStart(animationSpeed: Int) { if (!isCancel) { readView.fillPage(mDirection)