基本完成了按钮的UI设计,暂未实装按钮触摸事件
This commit is contained in:
@@ -449,7 +449,7 @@ object ReadBookConfig {
|
||||
var letterSpacing: Float = 0.1f,//字间距
|
||||
var lineSpacingExtra: Int = 12,//行间距
|
||||
var paragraphSpacing: Int = 2,//段距
|
||||
var titleMode: Int = 0,//标题居中
|
||||
var titleMode: Int = 0,//标题位置 0:居左 1:居中 2:隐藏
|
||||
var titleSize: Int = 0,
|
||||
var titleTopSpacing: Int = 0,
|
||||
var titleBottomSpacing: Int = 0,
|
||||
|
||||
@@ -355,6 +355,9 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
menu?.findItem(R.id.menu_re_segment)?.isChecked = it.getReSegment()
|
||||
ReadBook.loadContent(false)
|
||||
}
|
||||
R.id.menu_enable_review -> ReadBook.book?.let {
|
||||
// TODO
|
||||
}
|
||||
R.id.menu_page_anim -> showPageAnimConfig {
|
||||
binding.readView.upPageAnim()
|
||||
ReadBook.loadContent(false)
|
||||
|
||||
@@ -4,6 +4,8 @@ import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Paint
|
||||
import android.graphics.RectF
|
||||
import android.text.StaticLayout
|
||||
import android.text.TextPaint
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import io.legado.app.R
|
||||
@@ -150,6 +152,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
||||
ChapterProvider.contentPaint
|
||||
}
|
||||
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.textChars.forEach {
|
||||
if (it.isImage) {
|
||||
drawImage(canvas, textPage, textLine, it, lineTop, lineBottom)
|
||||
@@ -158,7 +166,74 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
||||
if (it.isSearchResult) {
|
||||
textPaint.color = context.accentColor
|
||||
}
|
||||
canvas.drawText(it.charData, it.start, lineBase, textPaint)
|
||||
if (it.charData == "\uD83D\uDCAC" && it.isLineEnd) {
|
||||
if (textLine.reviewCount <= 0) return@forEach
|
||||
canvas.drawLine(
|
||||
it.start,
|
||||
lineBase - textPaint.textSize * 2 / 5,
|
||||
it.start + textPaint.textSize / 6,
|
||||
lineBase - textPaint.textSize / 4,
|
||||
linePaint
|
||||
)
|
||||
canvas.drawLine(
|
||||
it.start,
|
||||
lineBase - textPaint.textSize * 0.38F,
|
||||
it.start + textPaint.textSize / 6,
|
||||
lineBase - textPaint.textSize * 0.55F,
|
||||
linePaint
|
||||
)
|
||||
canvas.drawLine(
|
||||
it.start + textPaint.textSize / 6,
|
||||
lineBase - textPaint.textSize / 4,
|
||||
it.start + textPaint.textSize / 6,
|
||||
lineBase,
|
||||
linePaint
|
||||
)
|
||||
canvas.drawLine(
|
||||
it.start + textPaint.textSize / 6,
|
||||
lineBase - textPaint.textSize * 0.55F,
|
||||
it.start + textPaint.textSize / 6,
|
||||
lineBase - textPaint.textSize * 0.8F,
|
||||
linePaint
|
||||
)
|
||||
canvas.drawLine(
|
||||
it.start + textPaint.textSize / 6,
|
||||
lineBase,
|
||||
it.start + textPaint.textSize * 1.6F,
|
||||
lineBase,
|
||||
linePaint
|
||||
)
|
||||
canvas.drawLine(
|
||||
it.start + textPaint.textSize / 6,
|
||||
lineBase - textPaint.textSize * 0.8F,
|
||||
it.start + textPaint.textSize * 1.6F,
|
||||
lineBase - textPaint.textSize * 0.8F,
|
||||
linePaint
|
||||
)
|
||||
canvas.drawLine(
|
||||
it.start + textPaint.textSize * 1.6F,
|
||||
lineBase - textPaint.textSize * 0.8F,
|
||||
it.start + textPaint.textSize * 1.6F,
|
||||
lineBase,
|
||||
linePaint
|
||||
)
|
||||
if (textLine.reviewCount < 100) canvas.drawText(
|
||||
textLine.reviewCount.toString(),
|
||||
it.start + textPaint.textSize * 0.87F -
|
||||
StaticLayout.getDesiredWidth(
|
||||
textLine.reviewCount.toString(),
|
||||
reviewCountPaint
|
||||
) / 2,
|
||||
lineBase - textPaint.textSize / 6,
|
||||
reviewCountPaint
|
||||
)
|
||||
else canvas.drawText(
|
||||
"99+",
|
||||
it.start + textPaint.textSize * 0.35F,
|
||||
lineBase - textPaint.textSize / 6,
|
||||
reviewCountPaint
|
||||
)
|
||||
} else canvas.drawText(it.charData, it.start, lineBase, textPaint)
|
||||
}
|
||||
if (it.selected) {
|
||||
canvas.drawRect(it.start, lineTop, it.end, lineBottom, selectedPaint)
|
||||
@@ -276,6 +351,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
||||
callBack.onImageLongPress(x, y, textChar.charData)
|
||||
} else {
|
||||
if (!selectAble) return@touch
|
||||
if (textChar.charData == "\uD83D\uDCAC" && textChar.isLineEnd) return@touch
|
||||
textChar.selected = true
|
||||
invalidate()
|
||||
select(relativePos, lineIndex, charIndex)
|
||||
@@ -292,6 +368,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
||||
select: (relativePage: Int, lineIndex: Int, charIndex: Int) -> Unit,
|
||||
) {
|
||||
touch(x, y) { _, relativePos, _, lineIndex, _, charIndex, textChar ->
|
||||
if (textChar.charData == "\uD83D\uDCAC" && textChar.isLineEnd) return@touch
|
||||
textChar.selected = true
|
||||
invalidate()
|
||||
select(relativePos, lineIndex, charIndex)
|
||||
@@ -415,6 +492,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
||||
textPos.lineIndex = lineIndex
|
||||
for ((charIndex, textChar) in textLine.textChars.withIndex()) {
|
||||
textPos.charIndex = charIndex
|
||||
if (textChar.charData == "\uD83D\uDCAC" && textChar.isLineEnd) continue
|
||||
textChar.selected =
|
||||
textPos.compare(selectStart) >= 0 && textPos.compare(selectEnd) <= 0
|
||||
textChar.isSearchResult = textChar.selected && callBack.isSelectingSearchResult
|
||||
|
||||
@@ -6,7 +6,8 @@ data class TextChar(
|
||||
var end: Float,
|
||||
var selected: Boolean = false,
|
||||
var isImage: Boolean = false,
|
||||
var isSearchResult: Boolean = false
|
||||
var isSearchResult: Boolean = false,
|
||||
var isLineEnd: Boolean = false
|
||||
) {
|
||||
|
||||
fun isTouch(x: Float): Boolean {
|
||||
|
||||
@@ -8,6 +8,7 @@ import io.legado.app.utils.textHeight
|
||||
data class TextLine(
|
||||
var text: String = "",
|
||||
val textChars: ArrayList<TextChar> = arrayListOf(),
|
||||
val reviewCount: Int = 0,
|
||||
var lineTop: Float = 0f,
|
||||
var lineBase: Float = 0f,
|
||||
var lineBottom: Float = 0f,
|
||||
|
||||
@@ -111,7 +111,12 @@ data class TextPage(
|
||||
val cw = StaticLayout.getDesiredWidth(char, ChapterProvider.contentPaint)
|
||||
val x1 = x + cw
|
||||
textLine.textChars.add(
|
||||
TextChar(char, start = x, end = x1)
|
||||
TextChar(
|
||||
char,
|
||||
start = x,
|
||||
end = x1,
|
||||
isLineEnd = textLine.text.length - 1 == i
|
||||
)
|
||||
)
|
||||
x = x1
|
||||
}
|
||||
|
||||
@@ -116,7 +116,13 @@ object ChapterProvider {
|
||||
if (ReadBookConfig.titleMode != 2) {
|
||||
displayTitle.splitNotBlank("\n").forEach { text ->
|
||||
setTypeText(
|
||||
book, absStartX, durY, text, textPages, stringBuilder, titlePaint,
|
||||
book,
|
||||
absStartX,
|
||||
durY,
|
||||
text + "\ud83d\udcac",
|
||||
textPages,
|
||||
stringBuilder,
|
||||
titlePaint,
|
||||
isTitle = true,
|
||||
isTitleWithNoContent = contents.isEmpty(),
|
||||
isVolumeTitle = bookChapter.isVolume
|
||||
@@ -171,7 +177,13 @@ object ChapterProvider {
|
||||
val text = content.substring(start, content.length)
|
||||
if (text.isNotBlank()) {
|
||||
setTypeText(
|
||||
book, absStartX, durY, text, textPages, stringBuilder, contentPaint
|
||||
book,
|
||||
absStartX,
|
||||
durY,
|
||||
text + "\ud83d\udcac",
|
||||
textPages,
|
||||
stringBuilder,
|
||||
contentPaint
|
||||
).let {
|
||||
absStartX = it.first
|
||||
durY = it.second
|
||||
@@ -276,9 +288,8 @@ object ChapterProvider {
|
||||
srcList: LinkedList<String>? = null
|
||||
): Pair<Int, Float> {
|
||||
var absStartX = x
|
||||
val layout = if (ReadBookConfig.useZhLayout) {
|
||||
ZhLayout(text, textPaint, visibleWidth)
|
||||
} else StaticLayout(
|
||||
val layout = if (ReadBookConfig.useZhLayout) ZhLayout(text, textPaint, visibleWidth)
|
||||
else StaticLayout(
|
||||
text, textPaint, visibleWidth, Layout.Alignment.ALIGN_NORMAL, 0f, 0f, true
|
||||
)
|
||||
var durY = when {
|
||||
@@ -398,10 +409,15 @@ object ChapterProvider {
|
||||
}
|
||||
val bodyIndent = ReadBookConfig.paragraphIndent
|
||||
val icw = StaticLayout.getDesiredWidth(bodyIndent, textPaint) / bodyIndent.length
|
||||
bodyIndent.toStringArray().forEach { char ->
|
||||
for ((index, char) in bodyIndent.toStringArray().withIndex()) {
|
||||
val x1 = x + icw
|
||||
textLine.textChars.add(
|
||||
TextChar(charData = char, start = absStartX + x, end = absStartX + x1)
|
||||
TextChar(
|
||||
charData = char,
|
||||
start = absStartX + x,
|
||||
end = absStartX + x1,
|
||||
isLineEnd = bodyIndent.length - 1 == index
|
||||
)
|
||||
)
|
||||
x = x1
|
||||
}
|
||||
@@ -492,7 +508,8 @@ object ChapterProvider {
|
||||
TextChar(
|
||||
charData = char,
|
||||
start = absStartX + xStart,
|
||||
end = absStartX + xEnd
|
||||
end = absStartX + xEnd,
|
||||
isLineEnd = true
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -612,12 +629,12 @@ object ChapterProvider {
|
||||
* 更新绘制尺寸
|
||||
*/
|
||||
fun upLayout() {
|
||||
when(AppConfig.doublePageHorizontal){
|
||||
when (AppConfig.doublePageHorizontal) {
|
||||
"0" -> doublePage = false
|
||||
"1" -> doublePage = true
|
||||
"2" -> {
|
||||
doublePage = (viewWidth > viewHeight)
|
||||
&& ReadBook.pageAnim() != 3
|
||||
&& ReadBook.pageAnim() != 3
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -299,7 +299,7 @@ class BookSourceEditActivity :
|
||||
reviewEntities.clear()
|
||||
reviewEntities.apply {
|
||||
add(EditEntity("reviewUrl", rr?.reviewUrl, R.string.rule_review_url))
|
||||
add(EditEntity("avatarRule", rr?.reviewUrl, R.string.rule_avatar))
|
||||
add(EditEntity("avatarRule", rr?.avatarRule, R.string.rule_avatar))
|
||||
add(EditEntity("contentRule", rr?.contentRule, R.string.rule_review_content))
|
||||
add(EditEntity("postTimeRule", rr?.postTimeRule, R.string.rule_post_time))
|
||||
add(EditEntity("reviewQuoteUrl", rr?.reviewQuoteUrl, R.string.rule_review_quote))
|
||||
|
||||
@@ -84,6 +84,13 @@
|
||||
android:checked="false"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_enable_review"
|
||||
android:title="@string/review"
|
||||
android:checkable="true"
|
||||
android:checked="false"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_image_style"
|
||||
android:title="@string/image_style"
|
||||
|
||||
Reference in New Issue
Block a user