|
|
@ -1,19 +1,17 @@ |
|
|
|
package io.legado.app.ui.widget.page |
|
|
|
package io.legado.app.ui.widget.page |
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context |
|
|
|
import android.content.Context |
|
|
|
import android.graphics.Bitmap |
|
|
|
import android.graphics.* |
|
|
|
import android.graphics.Canvas |
|
|
|
|
|
|
|
import android.graphics.Rect |
|
|
|
|
|
|
|
import android.graphics.drawable.GradientDrawable |
|
|
|
import android.graphics.drawable.GradientDrawable |
|
|
|
import android.util.AttributeSet |
|
|
|
import android.util.AttributeSet |
|
|
|
import android.util.Log |
|
|
|
|
|
|
|
import android.view.MotionEvent |
|
|
|
import android.view.MotionEvent |
|
|
|
import android.view.View |
|
|
|
|
|
|
|
import android.widget.FrameLayout |
|
|
|
import android.widget.FrameLayout |
|
|
|
import androidx.appcompat.widget.AppCompatTextView |
|
|
|
|
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
|
|
|
|
|
import io.legado.app.utils.dp |
|
|
|
import io.legado.app.utils.screenshot |
|
|
|
import io.legado.app.utils.screenshot |
|
|
|
import kotlin.math.abs |
|
|
|
import kotlinx.android.synthetic.main.view_book_page.view.* |
|
|
|
|
|
|
|
import org.jetbrains.anko.backgroundColor |
|
|
|
|
|
|
|
import org.jetbrains.anko.horizontalPadding |
|
|
|
|
|
|
|
|
|
|
|
class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, attrs) { |
|
|
|
class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, attrs) { |
|
|
|
|
|
|
|
|
|
|
@ -22,34 +20,99 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att |
|
|
|
private var downX: Float = 0.toFloat() |
|
|
|
private var downX: Float = 0.toFloat() |
|
|
|
private var offset: Float = 0.toFloat() |
|
|
|
private var offset: Float = 0.toFloat() |
|
|
|
|
|
|
|
|
|
|
|
private val srcRect: Rect = Rect() |
|
|
|
private val shadowDrawableR: GradientDrawable |
|
|
|
private val destRect: Rect = Rect() |
|
|
|
private val shadowDrawableL: GradientDrawable |
|
|
|
private val shadowDrawable: GradientDrawable |
|
|
|
|
|
|
|
|
|
|
|
private val bitmapMatrix = Matrix() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private var cover: Boolean = true |
|
|
|
|
|
|
|
|
|
|
|
init { |
|
|
|
init { |
|
|
|
val shadowColors = intArrayOf(0x66111111, 0x00000000) |
|
|
|
val shadowColors = intArrayOf(0x66111111, 0x00000000) |
|
|
|
shadowDrawable = GradientDrawable( |
|
|
|
shadowDrawableR = GradientDrawable( |
|
|
|
GradientDrawable.Orientation.LEFT_RIGHT, shadowColors |
|
|
|
GradientDrawable.Orientation.LEFT_RIGHT, shadowColors |
|
|
|
) |
|
|
|
) |
|
|
|
shadowDrawable.gradientType = GradientDrawable.LINEAR_GRADIENT |
|
|
|
shadowDrawableR.gradientType = GradientDrawable.LINEAR_GRADIENT |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
shadowDrawableL = GradientDrawable( |
|
|
|
|
|
|
|
GradientDrawable.Orientation.RIGHT_LEFT, shadowColors |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
shadowDrawableL.gradientType = GradientDrawable.LINEAR_GRADIENT |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inflate(context, R.layout.view_book_page, this) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setWillNotDraw(false) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
page_panel.backgroundColor = Color.WHITE |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
page_panel.horizontalPadding = 16.dp |
|
|
|
|
|
|
|
|
|
|
|
inflate(context, R.layout.page_view, this) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onDraw(canvas: Canvas?) { |
|
|
|
override fun dispatchDraw(canvas: Canvas?) { |
|
|
|
canvas?.save() |
|
|
|
super.dispatchDraw(canvas) |
|
|
|
super.onDraw(canvas) |
|
|
|
|
|
|
|
canvas?.restore() |
|
|
|
bitmap?.let { |
|
|
|
|
|
|
|
val dx = if (offset > 0) offset - width else offset + width |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bitmapMatrix.setTranslate(dx, 0.toFloat()) |
|
|
|
|
|
|
|
canvas?.drawBitmap(it, bitmapMatrix, null) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (cover) { |
|
|
|
|
|
|
|
addShadow(dx.toInt(), canvas) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun addShadow(left: Int, canvas: Canvas?) { |
|
|
|
|
|
|
|
canvas?.let { |
|
|
|
|
|
|
|
if (left < 0) { |
|
|
|
|
|
|
|
shadowDrawableR.setBounds(left + width, 0, left+ width + 30, height) |
|
|
|
|
|
|
|
shadowDrawableR.draw(it) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
shadowDrawableL.setBounds(left - 30, 0, left, height) |
|
|
|
|
|
|
|
shadowDrawableL.draw(it) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onTouchEvent(event: MotionEvent?): Boolean { |
|
|
|
override fun onTouchEvent(event: MotionEvent?): Boolean { |
|
|
|
|
|
|
|
when (event?.action) { |
|
|
|
|
|
|
|
MotionEvent.ACTION_DOWN -> { |
|
|
|
|
|
|
|
bitmap = page_panel.screenshot() |
|
|
|
|
|
|
|
downX = event.x |
|
|
|
|
|
|
|
offset = 0.toFloat() |
|
|
|
|
|
|
|
if (!cover) { |
|
|
|
|
|
|
|
page_panel.translationX = 0.toFloat() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
invalidate() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MotionEvent.ACTION_MOVE -> { |
|
|
|
|
|
|
|
offset = event.x - downX |
|
|
|
|
|
|
|
if (!cover) { |
|
|
|
|
|
|
|
page_panel.translationX = offset |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
invalidate() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MotionEvent.ACTION_UP -> { |
|
|
|
|
|
|
|
bitmap = null |
|
|
|
|
|
|
|
if (!cover) { |
|
|
|
|
|
|
|
page_panel.translationX = 0.toFloat() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
invalidate() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return true |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun setPageFactory(factory: PageFactory<*>){ |
|
|
|
fun setTranslate(translationX: Float, translationY: Float) { |
|
|
|
|
|
|
|
page_panel.translationX = translationX |
|
|
|
|
|
|
|
page_panel.translationY = translationY |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun setPageFactory(factory: PageFactory<*>) { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|