|
|
|
@ -29,7 +29,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
|
private var selectCharStart = 0 |
|
|
|
|
private var selectLineEnd = 0 |
|
|
|
|
private var selectCharEnd = 0 |
|
|
|
|
private var textPage: TextPage? = null |
|
|
|
|
private var textPage: TextPage = TextPage() |
|
|
|
|
//滚动参数 |
|
|
|
|
private val maxScrollOffset = 100f |
|
|
|
|
private var pageOffset = 0f |
|
|
|
@ -39,7 +39,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
|
activityCallBack = activity as CallBack |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun setContent(textPage: TextPage?) { |
|
|
|
|
fun setContent(textPage: TextPage) { |
|
|
|
|
this.textPage = textPage |
|
|
|
|
invalidate() |
|
|
|
|
} |
|
|
|
@ -55,7 +55,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
|
|
|
|
|
|
override fun onDraw(canvas: Canvas) { |
|
|
|
|
super.onDraw(canvas) |
|
|
|
|
textPage?.let { textPage -> |
|
|
|
|
textPage.textLines.forEach { textLine -> |
|
|
|
|
val textPaint = if (textLine.isTitle) { |
|
|
|
|
ChapterProvider.titlePaint |
|
|
|
@ -86,7 +85,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun onScroll(mOffset: Float) { |
|
|
|
|
var offset = mOffset |
|
|
|
@ -105,10 +103,10 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
|
pageOffset = 0f |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun selectText(x: Float, y: Float): Boolean { |
|
|
|
|
textPage?.let { textPage -> |
|
|
|
|
for ((lineIndex, textLine) in textPage.textLines.withIndex()) { |
|
|
|
|
if (y > textLine.lineTop && y < textLine.lineBottom) { |
|
|
|
|
for ((charIndex, textChar) in textLine.textChars.withIndex()) { |
|
|
|
@ -133,12 +131,10 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun selectStartMove(x: Float, y: Float) { |
|
|
|
|
textPage?.let { textPage -> |
|
|
|
|
for ((lineIndex, textLine) in textPage.textLines.withIndex()) { |
|
|
|
|
if (y > textLine.lineTop && y < textLine.lineBottom) { |
|
|
|
|
for ((charIndex, textChar) in textLine.textChars.withIndex()) { |
|
|
|
@ -159,10 +155,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun selectEndMove(x: Float, y: Float) { |
|
|
|
|
textPage?.let { textPage -> |
|
|
|
|
for ((lineIndex, textLine) in textPage.textLines.withIndex()) { |
|
|
|
|
if (y > textLine.lineTop && y < textLine.lineBottom) { |
|
|
|
|
for ((charIndex, textChar) in textLine.textChars.withIndex()) { |
|
|
|
@ -183,7 +177,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun upSelectChars(textPage: TextPage) { |
|
|
|
|
for ((lineIndex, textLine) in textPage.textLines.withIndex()) { |
|
|
|
@ -212,38 +205,38 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun cancelSelect() { |
|
|
|
|
textPage?.let { textPage -> |
|
|
|
|
textPage.textLines.forEach { textLine -> |
|
|
|
|
textLine.textChars.forEach { |
|
|
|
|
it.selected = false |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
invalidate() |
|
|
|
|
} |
|
|
|
|
activityCallBack.onCancelSelect() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val selectedText: String |
|
|
|
|
get() { |
|
|
|
|
val stringBuilder = StringBuilder() |
|
|
|
|
textPage?.let { |
|
|
|
|
for (lineIndex in selectLineStart..selectLineEnd) { |
|
|
|
|
if (lineIndex == selectLineStart && lineIndex == selectLineEnd) { |
|
|
|
|
stringBuilder.append( |
|
|
|
|
it.textLines[lineIndex].text.substring( |
|
|
|
|
textPage.textLines[lineIndex].text.substring( |
|
|
|
|
selectCharStart, |
|
|
|
|
selectCharEnd + 1 |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
} else if (lineIndex == selectLineStart) { |
|
|
|
|
stringBuilder.append(it.textLines[lineIndex].text.substring(selectCharStart)) |
|
|
|
|
stringBuilder.append( |
|
|
|
|
textPage.textLines[lineIndex].text.substring( |
|
|
|
|
selectCharStart |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
} else if (lineIndex == selectLineEnd) { |
|
|
|
|
stringBuilder.append( |
|
|
|
|
it.textLines[lineIndex].text.substring(0, selectCharEnd + 1) |
|
|
|
|
textPage.textLines[lineIndex].text.substring(0, selectCharEnd + 1) |
|
|
|
|
) |
|
|
|
|
} else { |
|
|
|
|
stringBuilder.append(it.textLines[lineIndex].text) |
|
|
|
|
} |
|
|
|
|
stringBuilder.append(textPage.textLines[lineIndex].text) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return stringBuilder.toString() |
|
|
|
|