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