From e7701895e61072c51eb12b4e477702897de1b9e2 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 4 Sep 2020 16:12:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BF=BB=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ContentTextView.kt | 184 +++++------------- 1 file changed, 49 insertions(+), 135 deletions(-) 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 da57d224b..8b62ccbd9 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 @@ -164,7 +164,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at canvas.drawBitmap(it, null, rectF, null) } } - } } @@ -204,7 +203,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } /** - * 选择初始文字 + * 选择文字 */ fun selectText( x: Float, @@ -243,7 +242,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } - } /** @@ -251,83 +249,37 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at */ fun selectStartMove(x: Float, y: Float) { if (!visibleRect.contains(x, y)) return - var relativeOffset = relativeOffset(0) - for ((lineIndex, textLine) in textPage.textLines.withIndex()) { - if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { - for ((charIndex, textChar) in textLine.textChars.withIndex()) { - if (x > textChar.start && x < textChar.end) { - if (selectStart[0] != 0 || selectStart[1] != lineIndex || selectStart[2] != charIndex) { - if (selectToInt(0, lineIndex, charIndex) > selectToInt(selectEnd)) { - return - } - selectStart[0] = 0 - selectStart[1] = lineIndex - selectStart[2] = charIndex - upSelectedStart( - textChar.start, - textLine.lineBottom + relativeOffset, - textLine.lineTop + relativeOffset - ) - upSelectChars() - } - return - } - } - return - } - } - if (!ReadBookConfig.isScroll) return - //滚动翻页 - relativeOffset = relativeOffset(1) - if (relativeOffset >= ChapterProvider.visibleHeight) return - for ((lineIndex, textLine) in relativePage(1).textLines.withIndex()) { - if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { - for ((charIndex, textChar) in textLine.textChars.withIndex()) { - if (x > textChar.start && x < textChar.end) { - if (selectStart[0] != 1 || selectStart[1] != lineIndex || selectStart[2] != charIndex) { - if (selectToInt(1, lineIndex, charIndex) > selectToInt(selectEnd)) { - return - } - selectStart[0] = 1 - selectStart[1] = lineIndex - selectStart[2] = charIndex - upSelectedStart( - textChar.start, - textLine.lineBottom + relativeOffset, - textLine.lineTop + relativeOffset - ) - upSelectChars() - } - return - } - } - return + var relativeOffset: Float + for (relativePos in 0..2) { + relativeOffset = relativeOffset(relativePos) + if (relativePos > 0) { + //滚动翻页 + if (!ReadBookConfig.isScroll) return + if (relativeOffset >= ChapterProvider.visibleHeight) return } - } - relativeOffset = relativeOffset(2) - if (relativeOffset >= ChapterProvider.visibleHeight) return - for ((lineIndex, textLine) in relativePage(2).textLines.withIndex()) { - if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { - for ((charIndex, textChar) in textLine.textChars.withIndex()) { - if (x > textChar.start && x < textChar.end) { - if (selectStart[0] != 2 || selectStart[1] != lineIndex || selectStart[2] != charIndex) { - if (selectToInt(2, lineIndex, charIndex) > selectToInt(selectEnd)) { - return + for ((lineIndex, textLine) in relativePage(relativePos).textLines.withIndex()) { + if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { + for ((charIndex, textChar) in textLine.textChars.withIndex()) { + if (x > textChar.start && x < textChar.end) { + if (selectStart[0] != relativePos || selectStart[1] != lineIndex || selectStart[2] != charIndex) { + if (selectToInt(relativePos, lineIndex, charIndex) > selectToInt(selectEnd)) { + return + } + selectStart[0] = relativePos + selectStart[1] = lineIndex + selectStart[2] = charIndex + upSelectedStart( + textChar.start, + textLine.lineBottom + relativeOffset, + textLine.lineTop + relativeOffset + ) + upSelectChars() } - selectStart[0] = 2 - selectStart[1] = lineIndex - selectStart[2] = charIndex - upSelectedStart( - textChar.start, - textLine.lineBottom + relativeOffset, - textLine.lineTop + relativeOffset - ) - upSelectChars() + return } - return } + return } - return } } } @@ -337,71 +289,33 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at */ fun selectEndMove(x: Float, y: Float) { if (!visibleRect.contains(x, y)) return - var relativeOffset = relativeOffset(0) - for ((lineIndex, textLine) in textPage.textLines.withIndex()) { - if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { - for ((charIndex, textChar) in textLine.textChars.withIndex()) { - if (x > textChar.start && x < textChar.end) { - if (selectEnd[0] != 0 || selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { - if (selectToInt(0, lineIndex, charIndex) < selectToInt(selectStart)) { - return - } - selectEnd[0] = 0 - selectEnd[1] = lineIndex - selectEnd[2] = charIndex - upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) - upSelectChars() - } - return - } - } - return - } - } - if (!ReadBookConfig.isScroll) return - //滚动翻页 - relativeOffset = relativeOffset(1) - if (relativeOffset >= ChapterProvider.visibleHeight) return - for ((lineIndex, textLine) in relativePage(1).textLines.withIndex()) { - if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { - for ((charIndex, textChar) in textLine.textChars.withIndex()) { - if (x > textChar.start && x < textChar.end) { - if (selectEnd[0] != 1 || selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { - if (selectToInt(1, lineIndex, charIndex) < selectToInt(selectStart)) { - return - } - selectEnd[0] = 1 - selectEnd[1] = lineIndex - selectEnd[2] = charIndex - upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) - upSelectChars() - } - return - } - } - return + var relativeOffset: Float + for (relativePos in 0..2) { + relativeOffset = relativeOffset(relativePos) + if (relativePos > 0) { + //滚动翻页 + if (!ReadBookConfig.isScroll) return + if (relativeOffset >= ChapterProvider.visibleHeight) return } - } - relativeOffset = relativeOffset(2) - if (relativeOffset >= ChapterProvider.visibleHeight) return - for ((lineIndex, textLine) in relativePage(2).textLines.withIndex()) { - if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { - for ((charIndex, textChar) in textLine.textChars.withIndex()) { - if (x > textChar.start && x < textChar.end) { - if (selectEnd[0] != 2 || selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { - if (selectToInt(2, lineIndex, charIndex) < selectToInt(selectStart)) { - return + for ((lineIndex, textLine) in relativePage(relativePos).textLines.withIndex()) { + if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { + for ((charIndex, textChar) in textLine.textChars.withIndex()) { + if (x > textChar.start && x < textChar.end) { + if (selectEnd[0] != relativePos || selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { + if (selectToInt(relativePos, lineIndex, charIndex) < selectToInt(selectStart)) { + return + } + selectEnd[0] = relativePos + selectEnd[1] = lineIndex + selectEnd[2] = charIndex + upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) + upSelectChars() } - selectEnd[0] = 2 - selectEnd[1] = lineIndex - selectEnd[2] = charIndex - upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) - upSelectChars() + return } - return } + return } - return } } }