|
|
|
@ -3,8 +3,6 @@ package io.legado.app.ui.book.read.page |
|
|
|
|
import android.content.Context |
|
|
|
|
import android.graphics.Canvas |
|
|
|
|
import android.graphics.Paint |
|
|
|
|
import android.text.Layout |
|
|
|
|
import android.text.StaticLayout |
|
|
|
|
import android.util.AttributeSet |
|
|
|
|
import android.view.View |
|
|
|
|
import io.legado.app.R |
|
|
|
@ -30,7 +28,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
|
private var selectCharStart = 0 |
|
|
|
|
private var selectLineEnd = 0 |
|
|
|
|
private var selectCharEnd = 0 |
|
|
|
|
private var textPage: TextPage = TextPage() |
|
|
|
|
private var textPage: TextPage = TextPage().textToLine() |
|
|
|
|
//滚动参数 |
|
|
|
|
private val pageFactory: TextPageFactory get() = callBack.pageFactory |
|
|
|
|
private val maxScrollOffset = 100f |
|
|
|
@ -60,29 +58,13 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
|
|
|
|
|
|
override fun onDraw(canvas: Canvas) { |
|
|
|
|
super.onDraw(canvas) |
|
|
|
|
|
|
|
|
|
if (textPage.textLines.isEmpty()) { |
|
|
|
|
drawMsg(canvas, textPage.text) |
|
|
|
|
if (ReadBookConfig.isScroll) { |
|
|
|
|
drawScrollPage(canvas) |
|
|
|
|
} else { |
|
|
|
|
drawHorizontalPage(canvas) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Suppress("DEPRECATION") |
|
|
|
|
private fun drawMsg(canvas: Canvas, msg: String) { |
|
|
|
|
val layout = StaticLayout( |
|
|
|
|
msg, ChapterProvider.contentPaint, width, |
|
|
|
|
Layout.Alignment.ALIGN_NORMAL, 1f, 0f, false |
|
|
|
|
) |
|
|
|
|
val y = (height - layout.height) / 2f |
|
|
|
|
for (lineIndex in 0 until layout.lineCount) { |
|
|
|
|
val x = (width - layout.getLineMax(lineIndex)) / 2 |
|
|
|
|
val words = |
|
|
|
|
msg.substring(layout.getLineStart(lineIndex), layout.getLineEnd(lineIndex)) |
|
|
|
|
canvas.drawText(words, x, y, ChapterProvider.contentPaint) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun drawHorizontalPage(canvas: Canvas) { |
|
|
|
|
textPage.textLines.forEach { textLine -> |
|
|
|
|
val textPaint = if (textLine.isTitle) { |
|
|
|
@ -110,6 +92,10 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun drawScrollPage(canvas: Canvas) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun onScroll(mOffset: Float) { |
|
|
|
|
var offset = mOffset |
|
|
|
|
if (offset > maxScrollOffset) { |
|
|
|
|