|
|
@ -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) |
|
|
|