|
|
|
@ -242,104 +242,108 @@ class ReadView(context: Context, attrs: AttributeSet) : |
|
|
|
|
/** |
|
|
|
|
* 长按选择 |
|
|
|
|
*/ |
|
|
|
|
private fun onLongPress() = with(curPage.textPage) { |
|
|
|
|
curPage.selectText(startX, startY) { relativePage, lineIndex, charIndex -> |
|
|
|
|
isTextSelected = true |
|
|
|
|
firstRelativePage = relativePage |
|
|
|
|
firstLineIndex = lineIndex |
|
|
|
|
firstCharIndex = charIndex |
|
|
|
|
var lineStart = lineIndex |
|
|
|
|
var lineEnd = lineIndex |
|
|
|
|
var start: Int |
|
|
|
|
var end: Int |
|
|
|
|
if (lineIndex - 1 > 0 && lineIndex + 1 < lineSize) { |
|
|
|
|
// 中间行 |
|
|
|
|
val lineText = with(textLines) { |
|
|
|
|
get(lineIndex - 1).text + get(lineIndex).text + get(lineIndex + 1).text |
|
|
|
|
} |
|
|
|
|
boundary.setText(lineText) |
|
|
|
|
start = boundary.first() |
|
|
|
|
end = boundary.next() |
|
|
|
|
val cIndex = textLines[lineIndex - 1].text.length + charIndex |
|
|
|
|
while (end != BreakIterator.DONE) { |
|
|
|
|
if (cIndex in start until end) { |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
start = end |
|
|
|
|
end = boundary.next() |
|
|
|
|
} |
|
|
|
|
if (start < textLines[lineIndex - 1].text.length) { |
|
|
|
|
lineStart = lineIndex - 1 |
|
|
|
|
} else { |
|
|
|
|
start -= textLines[lineIndex - 1].text.length |
|
|
|
|
} |
|
|
|
|
if (end > textLines[lineIndex - 1].text.length + textLines[lineIndex].text.length) { |
|
|
|
|
lineEnd = lineIndex + 1 |
|
|
|
|
end = (end - textLines[lineIndex - 1].text.length |
|
|
|
|
- textLines[lineIndex].text.length) |
|
|
|
|
} else { |
|
|
|
|
end = end - textLines[lineIndex - 1].text.length - 1 |
|
|
|
|
} |
|
|
|
|
} else if (lineIndex - 1 > 0) { |
|
|
|
|
// 尾行 |
|
|
|
|
val lineText = with(textLines) { |
|
|
|
|
get(lineIndex - 1).text + get(lineIndex).text |
|
|
|
|
} |
|
|
|
|
boundary.setText(lineText) |
|
|
|
|
start = boundary.first() |
|
|
|
|
end = boundary.next() |
|
|
|
|
val cIndex = textLines[lineIndex - 1].text.length + charIndex |
|
|
|
|
while (end != BreakIterator.DONE) { |
|
|
|
|
if (cIndex in start until end) { |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
start = end |
|
|
|
|
end = boundary.next() |
|
|
|
|
} |
|
|
|
|
if (start < textLines[lineIndex - 1].text.length) { |
|
|
|
|
lineStart = lineIndex - 1 |
|
|
|
|
} else { |
|
|
|
|
start -= textLines[lineIndex - 1].text.length |
|
|
|
|
} |
|
|
|
|
end = end - textLines[lineIndex - 1].text.length - 1 |
|
|
|
|
} else if (lineIndex + 1 < lineSize) { |
|
|
|
|
// 首行 |
|
|
|
|
val lineText = with(textLines) { |
|
|
|
|
get(lineIndex).text + get(lineIndex + 1).text |
|
|
|
|
} |
|
|
|
|
boundary.setText(lineText) |
|
|
|
|
start = boundary.first() |
|
|
|
|
end = boundary.next() |
|
|
|
|
while (end != BreakIterator.DONE) { |
|
|
|
|
if (charIndex in start until end) { |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
start = end |
|
|
|
|
end = boundary.next() |
|
|
|
|
} |
|
|
|
|
if (end > textLines[lineIndex].text.length) { |
|
|
|
|
lineEnd = lineIndex + 1 |
|
|
|
|
end -= textLines[lineIndex].text.length |
|
|
|
|
} else { |
|
|
|
|
end -= 1 |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
// 单行 |
|
|
|
|
val lineText = textLines[lineIndex].text |
|
|
|
|
boundary.setText(lineText) |
|
|
|
|
start = boundary.first() |
|
|
|
|
end = boundary.next() |
|
|
|
|
while (end != BreakIterator.DONE) { |
|
|
|
|
if (charIndex in start until end) { |
|
|
|
|
break |
|
|
|
|
private fun onLongPress() { |
|
|
|
|
kotlin.runCatching { |
|
|
|
|
with(curPage.textPage) { |
|
|
|
|
curPage.selectText(startX, startY) { relativePage, lineIndex, charIndex -> |
|
|
|
|
isTextSelected = true |
|
|
|
|
firstRelativePage = relativePage |
|
|
|
|
firstLineIndex = lineIndex |
|
|
|
|
firstCharIndex = charIndex |
|
|
|
|
var lineStart = lineIndex |
|
|
|
|
var lineEnd = lineIndex |
|
|
|
|
var start: Int |
|
|
|
|
var end: Int |
|
|
|
|
if (lineIndex - 1 > 0 && lineIndex + 1 < lineSize) { |
|
|
|
|
// 中间行 |
|
|
|
|
val lineText = with(textLines) { |
|
|
|
|
get(lineIndex - 1).text + get(lineIndex).text + get(lineIndex + 1).text |
|
|
|
|
} |
|
|
|
|
boundary.setText(lineText) |
|
|
|
|
start = boundary.first() |
|
|
|
|
end = boundary.next() |
|
|
|
|
val cIndex = textLines[lineIndex - 1].text.length + charIndex |
|
|
|
|
while (end != BreakIterator.DONE) { |
|
|
|
|
if (cIndex in start until end) { |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
start = end |
|
|
|
|
end = boundary.next() |
|
|
|
|
} |
|
|
|
|
if (start < textLines[lineIndex - 1].text.length) { |
|
|
|
|
lineStart = lineIndex - 1 |
|
|
|
|
} else { |
|
|
|
|
start -= textLines[lineIndex - 1].text.length |
|
|
|
|
} |
|
|
|
|
if (end > textLines[lineIndex - 1].text.length + textLines[lineIndex].text.length) { |
|
|
|
|
lineEnd = lineIndex + 1 |
|
|
|
|
end = (end - textLines[lineIndex - 1].text.length |
|
|
|
|
- textLines[lineIndex].text.length) |
|
|
|
|
} else { |
|
|
|
|
end = end - textLines[lineIndex - 1].text.length - 1 |
|
|
|
|
} |
|
|
|
|
} else if (lineIndex - 1 > 0) { |
|
|
|
|
// 尾行 |
|
|
|
|
val lineText = with(textLines) { |
|
|
|
|
get(lineIndex - 1).text + get(lineIndex).text |
|
|
|
|
} |
|
|
|
|
boundary.setText(lineText) |
|
|
|
|
start = boundary.first() |
|
|
|
|
end = boundary.next() |
|
|
|
|
val cIndex = textLines[lineIndex - 1].text.length + charIndex |
|
|
|
|
while (end != BreakIterator.DONE) { |
|
|
|
|
if (cIndex in start until end) { |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
start = end |
|
|
|
|
end = boundary.next() |
|
|
|
|
} |
|
|
|
|
if (start < textLines[lineIndex - 1].text.length) { |
|
|
|
|
lineStart = lineIndex - 1 |
|
|
|
|
} else { |
|
|
|
|
start -= textLines[lineIndex - 1].text.length |
|
|
|
|
} |
|
|
|
|
end = end - textLines[lineIndex - 1].text.length - 1 |
|
|
|
|
} else if (lineIndex + 1 < lineSize) { |
|
|
|
|
// 首行 |
|
|
|
|
val lineText = with(textLines) { |
|
|
|
|
get(lineIndex).text + get(lineIndex + 1).text |
|
|
|
|
} |
|
|
|
|
boundary.setText(lineText) |
|
|
|
|
start = boundary.first() |
|
|
|
|
end = boundary.next() |
|
|
|
|
while (end != BreakIterator.DONE) { |
|
|
|
|
if (charIndex in start until end) { |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
start = end |
|
|
|
|
end = boundary.next() |
|
|
|
|
} |
|
|
|
|
if (end > textLines[lineIndex].text.length) { |
|
|
|
|
lineEnd = lineIndex + 1 |
|
|
|
|
end -= textLines[lineIndex].text.length |
|
|
|
|
} else { |
|
|
|
|
end -= 1 |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
// 单行 |
|
|
|
|
val lineText = textLines[lineIndex].text |
|
|
|
|
boundary.setText(lineText) |
|
|
|
|
start = boundary.first() |
|
|
|
|
end = boundary.next() |
|
|
|
|
while (end != BreakIterator.DONE) { |
|
|
|
|
if (charIndex in start until end) { |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
start = end |
|
|
|
|
end = boundary.next() |
|
|
|
|
} |
|
|
|
|
end -= 1 |
|
|
|
|
} |
|
|
|
|
start = end |
|
|
|
|
end = boundary.next() |
|
|
|
|
curPage.selectStartMoveIndex(firstRelativePage, lineStart, start) |
|
|
|
|
curPage.selectEndMoveIndex(firstRelativePage, lineEnd, end) |
|
|
|
|
} |
|
|
|
|
end -= 1 |
|
|
|
|
} |
|
|
|
|
curPage.selectStartMoveIndex(firstRelativePage, lineStart, start) |
|
|
|
|
curPage.selectEndMoveIndex(firstRelativePage, lineEnd, end) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|