|
|
|
@ -1,14 +1,12 @@ |
|
|
|
|
package io.legado.app.ui.book.read.page.delegate |
|
|
|
|
|
|
|
|
|
import android.graphics.Canvas |
|
|
|
|
import android.graphics.Matrix |
|
|
|
|
import android.graphics.drawable.GradientDrawable |
|
|
|
|
import io.legado.app.ui.book.read.page.PageView |
|
|
|
|
|
|
|
|
|
class CoverPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) { |
|
|
|
|
|
|
|
|
|
private val shadowDrawableR: GradientDrawable |
|
|
|
|
private val bitmapMatrix = Matrix() |
|
|
|
|
|
|
|
|
|
init { |
|
|
|
|
val shadowColors = intArrayOf(0x66111111, 0x00000000) |
|
|
|
@ -38,17 +36,9 @@ class CoverPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) { |
|
|
|
|
viewWidth - (touchX - startX) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
startScroll(touchX.toInt(), 0, distanceX.toInt(), 0) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onAnimStop() { |
|
|
|
|
curPage.x = 0.toFloat() |
|
|
|
|
if (!isCancel) { |
|
|
|
|
pageView.fillPage(mDirection) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onDraw(canvas: Canvas) { |
|
|
|
|
val offsetX = touchX - startX |
|
|
|
|
|
|
|
|
@ -57,16 +47,14 @@ class CoverPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) { |
|
|
|
|
) return |
|
|
|
|
|
|
|
|
|
val distanceX = if (offsetX > 0) offsetX - viewWidth else offsetX + viewWidth |
|
|
|
|
bitmap?.let { |
|
|
|
|
if (!isMoved) return |
|
|
|
|
if (mDirection == Direction.PREV) { |
|
|
|
|
bitmapMatrix.setTranslate(distanceX, 0.toFloat()) |
|
|
|
|
canvas.drawBitmap(it, bitmapMatrix, null) |
|
|
|
|
prevPage.translationX = offsetX - viewWidth |
|
|
|
|
} else if (mDirection == Direction.NEXT) { |
|
|
|
|
curPage.translationX = offsetX |
|
|
|
|
} |
|
|
|
|
addShadow(distanceX.toInt(), canvas) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun addShadow(left: Int, canvas: Canvas) { |
|
|
|
|
if (left < 0) { |
|
|
|
@ -77,4 +65,13 @@ class CoverPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) { |
|
|
|
|
shadowDrawableR.draw(canvas) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onAnimStop() { |
|
|
|
|
curPage.x = 0.toFloat() |
|
|
|
|
prevPage.x = -viewWidth.toFloat() |
|
|
|
|
if (!isCancel) { |
|
|
|
|
pageView.fillPage(mDirection) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|