|
|
@ -24,10 +24,10 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
} |
|
|
|
} |
|
|
|
private var activityCallBack: CallBack |
|
|
|
private var activityCallBack: CallBack |
|
|
|
var selectAble = context.getPrefBoolean(PreferKey.textSelectAble) |
|
|
|
var selectAble = context.getPrefBoolean(PreferKey.textSelectAble) |
|
|
|
var selectStartLine = 0 |
|
|
|
private var selectLineStart = 0 |
|
|
|
var selectStartChar = 0 |
|
|
|
private var selectCharStart = 0 |
|
|
|
var selectEndLine = 0 |
|
|
|
private var selectLineEnd = 0 |
|
|
|
var selectEndChar = 0 |
|
|
|
private var selectCharEnd = 0 |
|
|
|
private var textPage: TextPage? = null |
|
|
|
private var textPage: TextPage? = null |
|
|
|
|
|
|
|
|
|
|
|
init { |
|
|
|
init { |
|
|
@ -91,10 +91,10 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
if (x > textChar.leftBottomPosition.x && x < textChar.rightTopPosition.x) { |
|
|
|
if (x > textChar.leftBottomPosition.x && x < textChar.rightTopPosition.x) { |
|
|
|
textChar.selected = true |
|
|
|
textChar.selected = true |
|
|
|
invalidate() |
|
|
|
invalidate() |
|
|
|
selectStartLine = lineIndex |
|
|
|
selectLineStart = lineIndex |
|
|
|
selectStartChar = charIndex |
|
|
|
selectCharStart = charIndex |
|
|
|
selectEndLine = lineIndex |
|
|
|
selectLineEnd = lineIndex |
|
|
|
selectEndChar = charIndex |
|
|
|
selectCharEnd = charIndex |
|
|
|
upSelectedStart( |
|
|
|
upSelectedStart( |
|
|
|
textChar.leftBottomPosition.x, |
|
|
|
textChar.leftBottomPosition.x, |
|
|
|
textChar.leftBottomPosition.y.toFloat() |
|
|
|
textChar.leftBottomPosition.y.toFloat() |
|
|
@ -119,9 +119,9 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
if (y > textLine.lineTop && y < textLine.lineBottom) { |
|
|
|
if (y > textLine.lineTop && y < textLine.lineBottom) { |
|
|
|
for ((charIndex, textChar) in textLine.textChars.withIndex()) { |
|
|
|
for ((charIndex, textChar) in textLine.textChars.withIndex()) { |
|
|
|
if (x > textChar.leftBottomPosition.x && x < textChar.rightTopPosition.x) { |
|
|
|
if (x > textChar.leftBottomPosition.x && x < textChar.rightTopPosition.x) { |
|
|
|
if (selectStartLine != lineIndex || selectStartChar != charIndex) { |
|
|
|
if (selectLineStart != lineIndex || selectCharStart != charIndex) { |
|
|
|
selectStartLine = lineIndex |
|
|
|
selectLineStart = lineIndex |
|
|
|
selectStartChar = charIndex |
|
|
|
selectCharStart = charIndex |
|
|
|
upSelectedStart( |
|
|
|
upSelectedStart( |
|
|
|
textChar.leftBottomPosition.x, |
|
|
|
textChar.leftBottomPosition.x, |
|
|
|
textChar.leftBottomPosition.y.toFloat() |
|
|
|
textChar.leftBottomPosition.y.toFloat() |
|
|
@ -143,9 +143,9 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
if (y > textLine.lineTop && y < textLine.lineBottom) { |
|
|
|
if (y > textLine.lineTop && y < textLine.lineBottom) { |
|
|
|
for ((charIndex, textChar) in textLine.textChars.withIndex()) { |
|
|
|
for ((charIndex, textChar) in textLine.textChars.withIndex()) { |
|
|
|
if (x > textChar.leftBottomPosition.x && x < textChar.rightTopPosition.x) { |
|
|
|
if (x > textChar.leftBottomPosition.x && x < textChar.rightTopPosition.x) { |
|
|
|
if (selectEndLine != lineIndex || selectEndChar != charIndex) { |
|
|
|
if (selectLineEnd != lineIndex || selectCharEnd != charIndex) { |
|
|
|
selectEndLine = lineIndex |
|
|
|
selectLineEnd = lineIndex |
|
|
|
selectEndChar = charIndex |
|
|
|
selectCharEnd = charIndex |
|
|
|
upSelectedEnd( |
|
|
|
upSelectedEnd( |
|
|
|
textChar.rightTopPosition.x, |
|
|
|
textChar.rightTopPosition.x, |
|
|
|
textChar.leftBottomPosition.y.toFloat() |
|
|
|
textChar.leftBottomPosition.y.toFloat() |
|
|
@ -165,14 +165,14 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
for ((lineIndex, textLine) in textPage.textLines.withIndex()) { |
|
|
|
for ((lineIndex, textLine) in textPage.textLines.withIndex()) { |
|
|
|
for ((charIndex, textChar) in textLine.textChars.withIndex()) { |
|
|
|
for ((charIndex, textChar) in textLine.textChars.withIndex()) { |
|
|
|
textChar.selected = |
|
|
|
textChar.selected = |
|
|
|
if (lineIndex == selectStartLine && lineIndex == selectEndLine) { |
|
|
|
if (lineIndex == selectLineStart && lineIndex == selectLineEnd) { |
|
|
|
charIndex in selectStartChar..selectEndChar |
|
|
|
charIndex in selectCharStart..selectCharEnd |
|
|
|
} else if (lineIndex == selectStartLine) { |
|
|
|
} else if (lineIndex == selectLineStart) { |
|
|
|
charIndex >= selectStartChar |
|
|
|
charIndex >= selectCharStart |
|
|
|
} else if (lineIndex == selectEndLine) { |
|
|
|
} else if (lineIndex == selectLineEnd) { |
|
|
|
charIndex <= selectEndChar |
|
|
|
charIndex <= selectCharEnd |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
lineIndex in (selectStartLine + 1) until selectEndLine |
|
|
|
lineIndex in (selectLineStart + 1) until selectLineEnd |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -201,7 +201,28 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
|
|
|
|
|
|
|
|
val selectedText: String |
|
|
|
val selectedText: String |
|
|
|
get() { |
|
|
|
get() { |
|
|
|
return "" |
|
|
|
val stringBuilder = StringBuilder() |
|
|
|
|
|
|
|
textPage?.let { |
|
|
|
|
|
|
|
for (lineIndex in selectLineStart..selectLineEnd) { |
|
|
|
|
|
|
|
if (lineIndex == selectLineStart && lineIndex == selectLineEnd) { |
|
|
|
|
|
|
|
stringBuilder.append( |
|
|
|
|
|
|
|
it.textLines[lineIndex].text.substring( |
|
|
|
|
|
|
|
selectCharStart + 1, |
|
|
|
|
|
|
|
selectCharEnd + 2 |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} else if (lineIndex == selectLineStart) { |
|
|
|
|
|
|
|
stringBuilder.append(it.textLines[lineIndex].text.substring(selectCharStart + 1)) |
|
|
|
|
|
|
|
} else if (lineIndex == selectLineEnd) { |
|
|
|
|
|
|
|
stringBuilder.append( |
|
|
|
|
|
|
|
it.textLines[lineIndex].text.substring(0, selectCharEnd + 1) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
stringBuilder.append(it.textLines[lineIndex].text) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return stringBuilder.toString() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
interface CallBack { |
|
|
|
interface CallBack { |
|
|
|