From f0485413379032e3f6a6ef02941a588a827ea4c5 Mon Sep 17 00:00:00 2001 From: Horis <821938089@qq.com> Date: Wed, 5 Oct 2022 20:19:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/ReadBookActivity.kt | 1 + .../app/ui/book/read/page/ContentTextView.kt | 56 ++++++++++++++++++- .../ui/book/read/page/entities/TextLine.kt | 5 ++ 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 0a55ce9fa..92c1b84ff 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -191,6 +191,7 @@ class ReadBookActivity : BaseReadBookActivity(), override fun onConfigurationChanged(newConfig: Configuration) { super.onConfigurationChanged(newConfig) + upSystemUiVisibility() binding.readView.upStatusBar() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index 54caf9c89..1ce08d25e 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -332,7 +332,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at y: Float, select: (textPos: TextPos) -> Unit, ) { - touch(x, y) { _, textPos, _, _, column -> + touchRough(x, y) { _, textPos, _, _, column -> if (column is TextColumn) { column.selected = true invalidate() @@ -345,7 +345,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at * 开始选择符移动 */ fun selectStartMove(x: Float, y: Float) { - touch(x, y) { relativeOffset, textPos, _, textLine, textColumn -> + touchRough(x, y) { relativeOffset, textPos, _, textLine, textColumn -> if (selectStart.compare(textPos) != 0) { if (textPos.compare(selectEnd) <= 0) { selectStart.upData(pos = textPos) @@ -364,7 +364,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at * 结束选择符移动 */ fun selectEndMove(x: Float, y: Float) { - touch(x, y) { relativeOffset, textPos, _, textLine, textColumn -> + touchRough(x, y) { relativeOffset, textPos, _, textLine, textColumn -> if (textPos.compare(selectEnd) != 0) { if (textPos.compare(selectStart) >= 0) { selectEnd.upData(textPos) @@ -418,6 +418,56 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } + /** + * 触碰位置信息 + * 文本选择专用 + * @param touched 回调 + */ + private fun touchRough( + x: Float, + y: Float, + touched: ( + relativeOffset: Float, + textPos: TextPos, + textPage: TextPage, + textLine: TextLine, + column: BaseColumn + ) -> Unit + ) { + if (!visibleRect.contains(x, y)) return + var relativeOffset: Float + for (relativePos in 0..2) { + relativeOffset = relativeOffset(relativePos) + if (relativePos > 0) { + //滚动翻页 + if (!callBack.isScroll) return + if (relativeOffset >= ChapterProvider.visibleHeight) return + } + val textPage = relativePage(relativePos) + for ((lineIndex, textLine) in textPage.lines.withIndex()) { + if (textLine.isTouchY(y, relativeOffset)) { + for ((charIndex, textColumn) in textLine.columns.withIndex()) { + if (textColumn.isTouch(x)) { + touched.invoke( + relativeOffset, + TextPos(relativePos, lineIndex, charIndex), + textPage, textLine, textColumn + ) + return + } + } + val (charIndex, textColumn) = textLine.columns.withIndex().last() + touched.invoke( + relativeOffset, + TextPos(relativePos, lineIndex, charIndex), + textPage, textLine, textColumn + ) + return + } + } + } + } + /** * 选择开始文字 */ diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt index ea4b8bd08..59d9b24db 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt @@ -56,4 +56,9 @@ data class TextLine( && x >= lineStart && x <= lineEnd } + + fun isTouchY(y: Float, relativeOffset: Float): Boolean { + return y > lineTop + relativeOffset + && y < lineBottom + relativeOffset + } }