|
|
@ -164,7 +164,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
canvas.drawBitmap(it, null, rectF, null) |
|
|
|
canvas.drawBitmap(it, null, rectF, null) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -204,7 +203,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 选择初始文字 |
|
|
|
* 选择文字 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun selectText( |
|
|
|
fun selectText( |
|
|
|
x: Float, |
|
|
|
x: Float, |
|
|
@ -243,7 +242,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -251,70 +249,23 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun selectStartMove(x: Float, y: Float) { |
|
|
|
fun selectStartMove(x: Float, y: Float) { |
|
|
|
if (!visibleRect.contains(x, y)) return |
|
|
|
if (!visibleRect.contains(x, y)) return |
|
|
|
var relativeOffset = relativeOffset(0) |
|
|
|
var relativeOffset: Float |
|
|
|
for ((lineIndex, textLine) in textPage.textLines.withIndex()) { |
|
|
|
for (relativePos in 0..2) { |
|
|
|
if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { |
|
|
|
relativeOffset = relativeOffset(relativePos) |
|
|
|
for ((charIndex, textChar) in textLine.textChars.withIndex()) { |
|
|
|
if (relativePos > 0) { |
|
|
|
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 (!ReadBookConfig.isScroll) return |
|
|
|
if (relativeOffset >= ChapterProvider.visibleHeight) return |
|
|
|
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 |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
for ((lineIndex, textLine) in relativePage(relativePos).textLines.withIndex()) { |
|
|
|
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) { |
|
|
|
if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { |
|
|
|
for ((charIndex, textChar) in textLine.textChars.withIndex()) { |
|
|
|
for ((charIndex, textChar) in textLine.textChars.withIndex()) { |
|
|
|
if (x > textChar.start && x < textChar.end) { |
|
|
|
if (x > textChar.start && x < textChar.end) { |
|
|
|
if (selectStart[0] != 2 || selectStart[1] != lineIndex || selectStart[2] != charIndex) { |
|
|
|
if (selectStart[0] != relativePos || selectStart[1] != lineIndex || selectStart[2] != charIndex) { |
|
|
|
if (selectToInt(2, lineIndex, charIndex) > selectToInt(selectEnd)) { |
|
|
|
if (selectToInt(relativePos, lineIndex, charIndex) > selectToInt(selectEnd)) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
selectStart[0] = 2 |
|
|
|
selectStart[0] = relativePos |
|
|
|
selectStart[1] = lineIndex |
|
|
|
selectStart[1] = lineIndex |
|
|
|
selectStart[2] = charIndex |
|
|
|
selectStart[2] = charIndex |
|
|
|
upSelectedStart( |
|
|
|
upSelectedStart( |
|
|
@ -331,68 +282,30 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 结束选择符移动 |
|
|
|
* 结束选择符移动 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun selectEndMove(x: Float, y: Float) { |
|
|
|
fun selectEndMove(x: Float, y: Float) { |
|
|
|
if (!visibleRect.contains(x, y)) return |
|
|
|
if (!visibleRect.contains(x, y)) return |
|
|
|
var relativeOffset = relativeOffset(0) |
|
|
|
var relativeOffset: Float |
|
|
|
for ((lineIndex, textLine) in textPage.textLines.withIndex()) { |
|
|
|
for (relativePos in 0..2) { |
|
|
|
if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { |
|
|
|
relativeOffset = relativeOffset(relativePos) |
|
|
|
for ((charIndex, textChar) in textLine.textChars.withIndex()) { |
|
|
|
if (relativePos > 0) { |
|
|
|
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 (!ReadBookConfig.isScroll) return |
|
|
|
if (relativeOffset >= ChapterProvider.visibleHeight) return |
|
|
|
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 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
relativeOffset = relativeOffset(2) |
|
|
|
for ((lineIndex, textLine) in relativePage(relativePos).textLines.withIndex()) { |
|
|
|
if (relativeOffset >= ChapterProvider.visibleHeight) return |
|
|
|
|
|
|
|
for ((lineIndex, textLine) in relativePage(2).textLines.withIndex()) { |
|
|
|
|
|
|
|
if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { |
|
|
|
if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { |
|
|
|
for ((charIndex, textChar) in textLine.textChars.withIndex()) { |
|
|
|
for ((charIndex, textChar) in textLine.textChars.withIndex()) { |
|
|
|
if (x > textChar.start && x < textChar.end) { |
|
|
|
if (x > textChar.start && x < textChar.end) { |
|
|
|
if (selectEnd[0] != 2 || selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { |
|
|
|
if (selectEnd[0] != relativePos || selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { |
|
|
|
if (selectToInt(2, lineIndex, charIndex) < selectToInt(selectStart)) { |
|
|
|
if (selectToInt(relativePos, lineIndex, charIndex) < selectToInt(selectStart)) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
selectEnd[0] = 2 |
|
|
|
selectEnd[0] = relativePos |
|
|
|
selectEnd[1] = lineIndex |
|
|
|
selectEnd[1] = lineIndex |
|
|
|
selectEnd[2] = charIndex |
|
|
|
selectEnd[2] = charIndex |
|
|
|
upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) |
|
|
|
upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) |
|
|
@ -405,6 +318,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 选择开始文字 |
|
|
|
* 选择开始文字 |
|
|
|