mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -58,14 +58,11 @@ class CoverPageDelegate(readView: ReadView) : HorizontalPageDelegate(readView) {
|
||||
override fun setBitmap() {
|
||||
when (mDirection) {
|
||||
PageDirection.PREV -> {
|
||||
prevBitmap?.recycle()
|
||||
prevBitmap = prevPage.screenshot()
|
||||
prevBitmap = prevPage.screenshot(prevBitmap, canvas)
|
||||
}
|
||||
PageDirection.NEXT -> {
|
||||
nextBitmap?.recycle()
|
||||
nextBitmap = nextPage.screenshot()
|
||||
curBitmap?.recycle()
|
||||
curBitmap = curPage.screenshot()
|
||||
nextBitmap = nextPage.screenshot(nextBitmap, canvas)
|
||||
curBitmap = curPage.screenshot(curBitmap, canvas)
|
||||
}
|
||||
else -> Unit
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.legado.app.ui.book.read.page.delegate
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Canvas
|
||||
import android.view.MotionEvent
|
||||
import io.legado.app.ui.book.read.page.ReadView
|
||||
import io.legado.app.ui.book.read.page.entities.PageDirection
|
||||
@@ -11,6 +12,7 @@ abstract class HorizontalPageDelegate(readView: ReadView) : PageDelegate(readVie
|
||||
protected var curBitmap: Bitmap? = null
|
||||
protected var prevBitmap: Bitmap? = null
|
||||
protected var nextBitmap: Bitmap? = null
|
||||
protected var canvas: Canvas = Canvas()
|
||||
private val slopSquare by lazy { readView.slopSquare * readView.slopSquare }
|
||||
|
||||
override fun setDirection(direction: PageDirection) {
|
||||
@@ -21,17 +23,13 @@ abstract class HorizontalPageDelegate(readView: ReadView) : PageDelegate(readVie
|
||||
open fun setBitmap() {
|
||||
when (mDirection) {
|
||||
PageDirection.PREV -> {
|
||||
prevBitmap?.recycle()
|
||||
prevBitmap = prevPage.screenshot()
|
||||
curBitmap?.recycle()
|
||||
curBitmap = curPage.screenshot()
|
||||
prevBitmap = prevPage.screenshot(prevBitmap, canvas)
|
||||
curBitmap = curPage.screenshot(curBitmap, canvas)
|
||||
}
|
||||
|
||||
PageDirection.NEXT -> {
|
||||
nextBitmap?.recycle()
|
||||
nextBitmap = nextPage.screenshot()
|
||||
curBitmap?.recycle()
|
||||
curBitmap = curPage.screenshot()
|
||||
nextBitmap = nextPage.screenshot(nextBitmap, canvas)
|
||||
curBitmap = curPage.screenshot(curBitmap, canvas)
|
||||
}
|
||||
|
||||
else -> Unit
|
||||
|
||||
@@ -12,6 +12,10 @@ class NoAnimPageDelegate(readView: ReadView) : HorizontalPageDelegate(readView)
|
||||
stopScroll()
|
||||
}
|
||||
|
||||
override fun setBitmap() {
|
||||
// nothing
|
||||
}
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.os.Build
|
||||
import android.text.Html
|
||||
import android.view.MotionEvent
|
||||
@@ -133,12 +134,21 @@ fun View.visible(visible: Boolean) {
|
||||
}
|
||||
}
|
||||
|
||||
fun View.screenshot(): Bitmap? {
|
||||
fun View.screenshot(bitmap: Bitmap? = null, canvas: Canvas? = null): Bitmap? {
|
||||
return if (width > 0 && height > 0) {
|
||||
val screenshot = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
|
||||
val c = Canvas(screenshot)
|
||||
val screenshot = if (bitmap != null && bitmap.width == width && bitmap.height == height) {
|
||||
bitmap.eraseColor(Color.TRANSPARENT)
|
||||
bitmap
|
||||
} else {
|
||||
bitmap?.recycle()
|
||||
Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
|
||||
}
|
||||
val c = canvas ?: Canvas()
|
||||
c.setBitmap(screenshot)
|
||||
c.save()
|
||||
c.translate(-scrollX.toFloat(), -scrollY.toFloat())
|
||||
this.draw(c)
|
||||
c.restore()
|
||||
c.setBitmap(null)
|
||||
screenshot.prepareToDraw()
|
||||
screenshot
|
||||
|
||||
Reference in New Issue
Block a user