|
|
@ -17,8 +17,10 @@ import io.legado.app.help.ImageLoader |
|
|
|
class CoverImageView : androidx.appcompat.widget.AppCompatImageView { |
|
|
|
class CoverImageView : androidx.appcompat.widget.AppCompatImageView { |
|
|
|
internal var width: Float = 0.toFloat() |
|
|
|
internal var width: Float = 0.toFloat() |
|
|
|
internal var height: Float = 0.toFloat() |
|
|
|
internal var height: Float = 0.toFloat() |
|
|
|
|
|
|
|
private var nameHeight = 0f |
|
|
|
private val textPaint = TextPaint() |
|
|
|
private var authorHeight = 0f |
|
|
|
|
|
|
|
private val namePaint = TextPaint() |
|
|
|
|
|
|
|
private val authorPaint = TextPaint() |
|
|
|
private var name: String? = null |
|
|
|
private var name: String? = null |
|
|
|
private var author: String? = null |
|
|
|
private var author: String? = null |
|
|
|
|
|
|
|
|
|
|
@ -33,10 +35,14 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
init { |
|
|
|
init { |
|
|
|
textPaint.typeface = Typeface.DEFAULT_BOLD |
|
|
|
namePaint.typeface = Typeface.DEFAULT_BOLD |
|
|
|
textPaint.isAntiAlias = true |
|
|
|
namePaint.isAntiAlias = true |
|
|
|
textPaint.textAlign = Paint.Align.CENTER |
|
|
|
namePaint.textAlign = Paint.Align.CENTER |
|
|
|
textPaint.textSkewX = -0.2f |
|
|
|
namePaint.textSkewX = -0.2f |
|
|
|
|
|
|
|
authorPaint.typeface = Typeface.DEFAULT |
|
|
|
|
|
|
|
authorPaint.isAntiAlias = true |
|
|
|
|
|
|
|
authorPaint.textAlign = Paint.Align.CENTER |
|
|
|
|
|
|
|
authorPaint.textSkewX = -0.1f |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { |
|
|
|
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { |
|
|
@ -52,8 +58,12 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { |
|
|
|
super.onLayout(changed, left, top, right, bottom) |
|
|
|
super.onLayout(changed, left, top, right, bottom) |
|
|
|
width = getWidth().toFloat() |
|
|
|
width = getWidth().toFloat() |
|
|
|
height = getHeight().toFloat() |
|
|
|
height = getHeight().toFloat() |
|
|
|
textPaint.textSize = width / 6 |
|
|
|
namePaint.textSize = width / 6 |
|
|
|
textPaint.strokeWidth = textPaint.textSize / 10 |
|
|
|
namePaint.strokeWidth = namePaint.textSize / 10 |
|
|
|
|
|
|
|
authorPaint.textSize = width / 9 |
|
|
|
|
|
|
|
authorPaint.strokeWidth = authorPaint.textSize / 10 |
|
|
|
|
|
|
|
nameHeight = height * 3 / 5 |
|
|
|
|
|
|
|
authorHeight = nameHeight + authorPaint.fontSpacing |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onDraw(canvas: Canvas) { |
|
|
|
override fun onDraw(canvas: Canvas) { |
|
|
@ -75,12 +85,20 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { |
|
|
|
} |
|
|
|
} |
|
|
|
super.onDraw(canvas) |
|
|
|
super.onDraw(canvas) |
|
|
|
name?.let { |
|
|
|
name?.let { |
|
|
|
textPaint.color = Color.WHITE |
|
|
|
namePaint.color = Color.WHITE |
|
|
|
textPaint.style = Paint.Style.STROKE |
|
|
|
namePaint.style = Paint.Style.STROKE |
|
|
|
canvas.drawText(it, width / 2, height * 3 / 5, textPaint) |
|
|
|
canvas.drawText(it, width / 2, nameHeight, namePaint) |
|
|
|
textPaint.color = Color.BLACK |
|
|
|
namePaint.color = Color.BLACK |
|
|
|
textPaint.style = Paint.Style.FILL |
|
|
|
namePaint.style = Paint.Style.FILL |
|
|
|
canvas.drawText(it, width / 2, height * 3 / 5, textPaint) |
|
|
|
canvas.drawText(it, width / 2, nameHeight, namePaint) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
author?.let { |
|
|
|
|
|
|
|
authorPaint.color = Color.WHITE |
|
|
|
|
|
|
|
authorPaint.style = Paint.Style.STROKE |
|
|
|
|
|
|
|
canvas.drawText(it, width / 2, authorHeight, authorPaint) |
|
|
|
|
|
|
|
authorPaint.color = Color.BLACK |
|
|
|
|
|
|
|
authorPaint.style = Paint.Style.FILL |
|
|
|
|
|
|
|
canvas.drawText(it, width / 2, authorHeight, authorPaint) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -91,7 +109,12 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { |
|
|
|
name.length > 5 -> name.substring(0, 4) + "…" |
|
|
|
name.length > 5 -> name.substring(0, 4) + "…" |
|
|
|
else -> name |
|
|
|
else -> name |
|
|
|
} |
|
|
|
} |
|
|
|
this.author = author |
|
|
|
this.author = |
|
|
|
|
|
|
|
when { |
|
|
|
|
|
|
|
author == null -> null |
|
|
|
|
|
|
|
author.length > 8 -> author.substring(0, 7) + "…" |
|
|
|
|
|
|
|
else -> author |
|
|
|
|
|
|
|
} |
|
|
|
invalidate() |
|
|
|
invalidate() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|