|
|
@ -31,6 +31,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
private val selectStart = arrayOf(0, 0, 0) |
|
|
|
private val selectStart = arrayOf(0, 0, 0) |
|
|
|
private val selectEnd = arrayOf(0, 0, 0) |
|
|
|
private val selectEnd = arrayOf(0, 0, 0) |
|
|
|
private var textPage: TextPage = TextPage() |
|
|
|
private var textPage: TextPage = TextPage() |
|
|
|
|
|
|
|
|
|
|
|
//滚动参数 |
|
|
|
//滚动参数 |
|
|
|
private val pageFactory: TextPageFactory get() = callBack.pageFactory |
|
|
|
private val pageFactory: TextPageFactory get() = callBack.pageFactory |
|
|
|
private val maxScrollOffset = 100f |
|
|
|
private val maxScrollOffset = 100f |
|
|
@ -210,7 +211,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
selectEnd[0] = 0 |
|
|
|
selectEnd[0] = 0 |
|
|
|
selectEnd[1] = lineIndex |
|
|
|
selectEnd[1] = lineIndex |
|
|
|
selectEnd[2] = charIndex |
|
|
|
selectEnd[2] = charIndex |
|
|
|
upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) |
|
|
|
upSelectedStart( |
|
|
|
|
|
|
|
textChar.start, |
|
|
|
|
|
|
|
textLine.lineBottom + relativeOffset, |
|
|
|
|
|
|
|
textLine.lineTop + relativeOffset |
|
|
|
|
|
|
|
) |
|
|
|
upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) |
|
|
|
upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) |
|
|
|
select(0, lineIndex, charIndex) |
|
|
|
select(0, lineIndex, charIndex) |
|
|
|
return |
|
|
|
return |
|
|
@ -236,7 +241,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
selectEnd[0] = 1 |
|
|
|
selectEnd[0] = 1 |
|
|
|
selectEnd[1] = lineIndex |
|
|
|
selectEnd[1] = lineIndex |
|
|
|
selectEnd[2] = charIndex |
|
|
|
selectEnd[2] = charIndex |
|
|
|
upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) |
|
|
|
upSelectedStart( |
|
|
|
|
|
|
|
textChar.start, |
|
|
|
|
|
|
|
textLine.lineBottom + relativeOffset, |
|
|
|
|
|
|
|
textLine.lineTop + relativeOffset |
|
|
|
|
|
|
|
) |
|
|
|
upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) |
|
|
|
upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) |
|
|
|
select(1, lineIndex, charIndex) |
|
|
|
select(1, lineIndex, charIndex) |
|
|
|
return |
|
|
|
return |
|
|
@ -259,7 +268,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
selectEnd[0] = 2 |
|
|
|
selectEnd[0] = 2 |
|
|
|
selectEnd[1] = lineIndex |
|
|
|
selectEnd[1] = lineIndex |
|
|
|
selectEnd[2] = charIndex |
|
|
|
selectEnd[2] = charIndex |
|
|
|
upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) |
|
|
|
upSelectedStart( |
|
|
|
|
|
|
|
textChar.start, |
|
|
|
|
|
|
|
textLine.lineBottom + relativeOffset, |
|
|
|
|
|
|
|
textLine.lineTop + relativeOffset |
|
|
|
|
|
|
|
) |
|
|
|
upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) |
|
|
|
upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) |
|
|
|
select(2, lineIndex, charIndex) |
|
|
|
select(2, lineIndex, charIndex) |
|
|
|
return |
|
|
|
return |
|
|
@ -287,7 +300,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
selectStart[0] = 0 |
|
|
|
selectStart[0] = 0 |
|
|
|
selectStart[1] = lineIndex |
|
|
|
selectStart[1] = lineIndex |
|
|
|
selectStart[2] = charIndex |
|
|
|
selectStart[2] = charIndex |
|
|
|
upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) |
|
|
|
upSelectedStart( |
|
|
|
|
|
|
|
textChar.start, |
|
|
|
|
|
|
|
textLine.lineBottom + relativeOffset, |
|
|
|
|
|
|
|
textLine.lineTop + relativeOffset |
|
|
|
|
|
|
|
) |
|
|
|
upSelectChars() |
|
|
|
upSelectChars() |
|
|
|
} |
|
|
|
} |
|
|
|
return |
|
|
|
return |
|
|
@ -311,7 +328,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
selectStart[0] = 1 |
|
|
|
selectStart[0] = 1 |
|
|
|
selectStart[1] = lineIndex |
|
|
|
selectStart[1] = lineIndex |
|
|
|
selectStart[2] = charIndex |
|
|
|
selectStart[2] = charIndex |
|
|
|
upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) |
|
|
|
upSelectedStart( |
|
|
|
|
|
|
|
textChar.start, |
|
|
|
|
|
|
|
textLine.lineBottom + relativeOffset, |
|
|
|
|
|
|
|
textLine.lineTop + relativeOffset |
|
|
|
|
|
|
|
) |
|
|
|
upSelectChars() |
|
|
|
upSelectChars() |
|
|
|
} |
|
|
|
} |
|
|
|
return |
|
|
|
return |
|
|
@ -333,7 +354,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
selectStart[0] = 2 |
|
|
|
selectStart[0] = 2 |
|
|
|
selectStart[1] = lineIndex |
|
|
|
selectStart[1] = lineIndex |
|
|
|
selectStart[2] = charIndex |
|
|
|
selectStart[2] = charIndex |
|
|
|
upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) |
|
|
|
upSelectedStart( |
|
|
|
|
|
|
|
textChar.start, |
|
|
|
|
|
|
|
textLine.lineBottom + relativeOffset, |
|
|
|
|
|
|
|
textLine.lineTop + relativeOffset |
|
|
|
|
|
|
|
) |
|
|
|
upSelectChars() |
|
|
|
upSelectChars() |
|
|
|
} |
|
|
|
} |
|
|
|
return |
|
|
|
return |
|
|
@ -427,7 +452,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
selectStart[2] = charIndex |
|
|
|
selectStart[2] = charIndex |
|
|
|
val textLine = relativePage(relativePage).textLines[lineIndex] |
|
|
|
val textLine = relativePage(relativePage).textLines[lineIndex] |
|
|
|
val textChar = textLine.textChars[charIndex] |
|
|
|
val textChar = textLine.textChars[charIndex] |
|
|
|
upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset(relativePage)) |
|
|
|
upSelectedStart( |
|
|
|
|
|
|
|
textChar.start, |
|
|
|
|
|
|
|
textLine.lineBottom + relativeOffset(relativePage), |
|
|
|
|
|
|
|
textLine.lineTop |
|
|
|
|
|
|
|
) |
|
|
|
upSelectChars() |
|
|
|
upSelectChars() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -475,12 +504,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
invalidate() |
|
|
|
invalidate() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun upSelectedStart(x: Float, y: Float) { |
|
|
|
private fun upSelectedStart(x: Float, y: Float, top: Float) = callBack.apply { |
|
|
|
callBack.upSelectedStart(x, y + callBack.headerHeight) |
|
|
|
upSelectedStart(x, y + headerHeight, top + headerHeight) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun upSelectedEnd(x: Float, y: Float) { |
|
|
|
private fun upSelectedEnd(x: Float, y: Float) = callBack.apply { |
|
|
|
callBack.upSelectedEnd(x, y + callBack.headerHeight) |
|
|
|
upSelectedEnd(x, y + headerHeight) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun cancelSelect() { |
|
|
|
fun cancelSelect() { |
|
|
@ -580,7 +609,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
interface CallBack { |
|
|
|
interface CallBack { |
|
|
|
fun upSelectedStart(x: Float, y: Float) |
|
|
|
fun upSelectedStart(x: Float, y: Float, top: Float) |
|
|
|
fun upSelectedEnd(x: Float, y: Float) |
|
|
|
fun upSelectedEnd(x: Float, y: Float) |
|
|
|
fun onCancelSelect() |
|
|
|
fun onCancelSelect() |
|
|
|
val headerHeight: Int |
|
|
|
val headerHeight: Int |
|
|
|