优化
This commit is contained in:
@@ -4,7 +4,6 @@ import android.content.Context
|
|||||||
import android.graphics.Canvas
|
import android.graphics.Canvas
|
||||||
import android.graphics.Paint
|
import android.graphics.Paint
|
||||||
import android.graphics.RectF
|
import android.graphics.RectF
|
||||||
import android.text.TextPaint
|
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
@@ -163,12 +162,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
|||||||
ChapterProvider.contentPaint
|
ChapterProvider.contentPaint
|
||||||
}
|
}
|
||||||
val textColor = if (textLine.isReadAloud) context.accentColor else ReadBookConfig.textColor
|
val textColor = if (textLine.isReadAloud) context.accentColor else ReadBookConfig.textColor
|
||||||
val linePaint = Paint()
|
|
||||||
linePaint.strokeWidth = textPaint.textSize / 21
|
|
||||||
linePaint.color = textColor
|
|
||||||
val reviewCountPaint = TextPaint()
|
|
||||||
reviewCountPaint.textSize = textPaint.textSize * 0.6F
|
|
||||||
reviewCountPaint.color = textColor
|
|
||||||
textLine.columns.forEach {
|
textLine.columns.forEach {
|
||||||
when (it) {
|
when (it) {
|
||||||
is TextColumn -> {
|
is TextColumn -> {
|
||||||
@@ -182,7 +175,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
is ImageColumn -> drawImage(canvas, textPage, textLine, it, lineTop, lineBottom)
|
is ImageColumn -> drawImage(canvas, textPage, textLine, it, lineTop, lineBottom)
|
||||||
is ReviewColumn -> it.drawToCanvas(canvas, linePaint, reviewCountPaint, lineBase)
|
is ReviewColumn -> it.drawToCanvas(canvas, lineBase, textPaint.textSize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package io.legado.app.ui.book.read.page.entities.column
|
|||||||
|
|
||||||
import android.graphics.Canvas
|
import android.graphics.Canvas
|
||||||
import android.graphics.Paint
|
import android.graphics.Paint
|
||||||
import android.text.StaticLayout
|
import android.graphics.Path
|
||||||
import android.text.TextPaint
|
import io.legado.app.ui.book.read.page.provider.ChapterProvider
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 评论按钮列
|
* 评论按钮列
|
||||||
@@ -11,74 +11,33 @@ import android.text.TextPaint
|
|||||||
data class ReviewColumn(
|
data class ReviewColumn(
|
||||||
override var start: Float,
|
override var start: Float,
|
||||||
override var end: Float,
|
override var end: Float,
|
||||||
var count: Int = 0
|
val count: Int = 0
|
||||||
) : BaseColumn {
|
) : BaseColumn {
|
||||||
|
|
||||||
fun getCountText(): String {
|
val countText by lazy {
|
||||||
if (count > 99) {
|
if (count > 99) {
|
||||||
return "99+"
|
return@lazy "99+"
|
||||||
}
|
}
|
||||||
return count.toString()
|
return@lazy count.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun drawToCanvas(canvas: Canvas, paint: Paint, countPaint: TextPaint, y: Float) {
|
val path by lazy { Path() }
|
||||||
|
|
||||||
|
fun drawToCanvas(canvas: Canvas, baseLine: Float, height: Float) {
|
||||||
if (count == 0) return
|
if (count == 0) return
|
||||||
canvas.drawLine(
|
path.moveTo(start, baseLine - height / 2)
|
||||||
start,
|
path.lineTo(start + height / 6, baseLine - height)
|
||||||
y - paint.textSize * 2 / 5,
|
path.lineTo(end, baseLine - height)
|
||||||
start + paint.textSize / 6,
|
path.lineTo(end, baseLine)
|
||||||
y - paint.textSize / 4,
|
path.lineTo(start + height / 6, baseLine)
|
||||||
paint
|
path.close()
|
||||||
)
|
ChapterProvider.reviewPaint.style = Paint.Style.STROKE
|
||||||
canvas.drawLine(
|
canvas.drawPath(path, ChapterProvider.reviewPaint)
|
||||||
start,
|
|
||||||
y - paint.textSize * 0.38F,
|
|
||||||
start + paint.textSize / 6,
|
|
||||||
y - paint.textSize * 0.55F,
|
|
||||||
paint
|
|
||||||
)
|
|
||||||
canvas.drawLine(
|
|
||||||
start + paint.textSize / 6,
|
|
||||||
y - paint.textSize / 4,
|
|
||||||
start + paint.textSize / 6,
|
|
||||||
y,
|
|
||||||
paint
|
|
||||||
)
|
|
||||||
canvas.drawLine(
|
|
||||||
start + paint.textSize / 6,
|
|
||||||
y - paint.textSize * 0.55F,
|
|
||||||
start + paint.textSize / 6,
|
|
||||||
y - paint.textSize * 0.8F,
|
|
||||||
paint
|
|
||||||
)
|
|
||||||
canvas.drawLine(
|
|
||||||
start + paint.textSize / 6,
|
|
||||||
y,
|
|
||||||
start + paint.textSize * 1.6F,
|
|
||||||
y,
|
|
||||||
paint
|
|
||||||
)
|
|
||||||
canvas.drawLine(
|
|
||||||
start + paint.textSize / 6,
|
|
||||||
y - paint.textSize * 0.8F,
|
|
||||||
start + paint.textSize * 1.6F,
|
|
||||||
y - paint.textSize * 0.8F,
|
|
||||||
paint
|
|
||||||
)
|
|
||||||
canvas.drawLine(
|
|
||||||
start + paint.textSize * 1.6F,
|
|
||||||
y - paint.textSize * 0.8F,
|
|
||||||
start + paint.textSize * 1.6F,
|
|
||||||
y,
|
|
||||||
paint
|
|
||||||
)
|
|
||||||
val text = getCountText()
|
|
||||||
val textWidth = StaticLayout.getDesiredWidth(getCountText(), countPaint)
|
|
||||||
canvas.drawText(
|
canvas.drawText(
|
||||||
text,
|
countText,
|
||||||
start + paint.textSize * 0.87F - textWidth / 2,
|
(start + end) / 2,
|
||||||
y - paint.textSize / 6,
|
baseLine - height / 6,
|
||||||
countPaint
|
ChapterProvider.reviewPaint
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package io.legado.app.ui.book.read.page.provider
|
package io.legado.app.ui.book.read.page.provider
|
||||||
|
|
||||||
|
import android.graphics.Paint
|
||||||
import android.graphics.Typeface
|
import android.graphics.Typeface
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
@@ -97,6 +98,9 @@ object ChapterProvider {
|
|||||||
@JvmStatic
|
@JvmStatic
|
||||||
var contentPaint: TextPaint = TextPaint()
|
var contentPaint: TextPaint = TextPaint()
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
var reviewPaint: TextPaint = TextPaint()
|
||||||
|
|
||||||
var doublePage = false
|
var doublePage = false
|
||||||
private set
|
private set
|
||||||
|
|
||||||
@@ -552,6 +556,9 @@ object ChapterProvider {
|
|||||||
getPaints(typeface).let {
|
getPaints(typeface).let {
|
||||||
titlePaint = it.first
|
titlePaint = it.first
|
||||||
contentPaint = it.second
|
contentPaint = it.second
|
||||||
|
reviewPaint.color = contentPaint.color
|
||||||
|
reviewPaint.textSize = contentPaint.textSize * 0.6f
|
||||||
|
reviewPaint.textAlign = Paint.Align.CENTER
|
||||||
}
|
}
|
||||||
//间距
|
//间距
|
||||||
lineSpacingExtra = ReadBookConfig.lineSpacingExtra / 10f
|
lineSpacingExtra = ReadBookConfig.lineSpacingExtra / 10f
|
||||||
|
|||||||
Reference in New Issue
Block a user