|
|
@ -3,8 +3,6 @@ package io.legado.app.ui.book.read.page |
|
|
|
import android.content.Context |
|
|
|
import android.content.Context |
|
|
|
import android.graphics.Canvas |
|
|
|
import android.graphics.Canvas |
|
|
|
import android.graphics.Paint |
|
|
|
import android.graphics.Paint |
|
|
|
import android.text.Layout |
|
|
|
|
|
|
|
import android.text.StaticLayout |
|
|
|
|
|
|
|
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 |
|
|
@ -30,7 +28,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
private var selectCharStart = 0 |
|
|
|
private var selectCharStart = 0 |
|
|
|
private var selectLineEnd = 0 |
|
|
|
private var selectLineEnd = 0 |
|
|
|
private var selectCharEnd = 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 pageFactory: TextPageFactory get() = callBack.pageFactory |
|
|
|
private val maxScrollOffset = 100f |
|
|
|
private val maxScrollOffset = 100f |
|
|
@ -60,29 +58,13 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
|
|
|
|
|
|
|
|
override fun onDraw(canvas: Canvas) { |
|
|
|
override fun onDraw(canvas: Canvas) { |
|
|
|
super.onDraw(canvas) |
|
|
|
super.onDraw(canvas) |
|
|
|
|
|
|
|
if (ReadBookConfig.isScroll) { |
|
|
|
if (textPage.textLines.isEmpty()) { |
|
|
|
drawScrollPage(canvas) |
|
|
|
drawMsg(canvas, textPage.text) |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
drawHorizontalPage(canvas) |
|
|
|
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) { |
|
|
|
private fun drawHorizontalPage(canvas: Canvas) { |
|
|
|
textPage.textLines.forEach { textLine -> |
|
|
|
textPage.textLines.forEach { textLine -> |
|
|
|
val textPaint = if (textLine.isTitle) { |
|
|
|
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) { |
|
|
|
fun onScroll(mOffset: Float) { |
|
|
|
var offset = mOffset |
|
|
|
var offset = mOffset |
|
|
|
if (offset > maxScrollOffset) { |
|
|
|
if (offset > maxScrollOffset) { |
|
|
|