|
|
@ -9,7 +9,6 @@ import io.legado.app.R |
|
|
|
import io.legado.app.constant.PreferKey |
|
|
|
import io.legado.app.constant.PreferKey |
|
|
|
import io.legado.app.help.ReadBookConfig |
|
|
|
import io.legado.app.help.ReadBookConfig |
|
|
|
import io.legado.app.lib.theme.accentColor |
|
|
|
import io.legado.app.lib.theme.accentColor |
|
|
|
import io.legado.app.ui.book.read.page.entities.SelectPoint |
|
|
|
|
|
|
|
import io.legado.app.ui.book.read.page.entities.TextPage |
|
|
|
import io.legado.app.ui.book.read.page.entities.TextPage |
|
|
|
import io.legado.app.utils.activity |
|
|
|
import io.legado.app.utils.activity |
|
|
|
import io.legado.app.utils.getCompatColor |
|
|
|
import io.legado.app.utils.getCompatColor |
|
|
@ -24,6 +23,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
private var activityCallBack: CallBack? = null |
|
|
|
private var activityCallBack: CallBack? = null |
|
|
|
|
|
|
|
var headerHeight = 0 |
|
|
|
var selectAble = context.getPrefBoolean(PreferKey.textSelectAble) |
|
|
|
var selectAble = context.getPrefBoolean(PreferKey.textSelectAble) |
|
|
|
var selectStartLine = 0 |
|
|
|
var selectStartLine = 0 |
|
|
|
var selectStartChar = 0 |
|
|
|
var selectStartChar = 0 |
|
|
@ -84,7 +84,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun selectText(x: Float, y: Float): SelectPoint? { |
|
|
|
fun selectText(x: Float, y: Float): Boolean { |
|
|
|
textPage?.let { textPage -> |
|
|
|
textPage?.let { textPage -> |
|
|
|
for ((lineIndex, textLine) in textPage.textLines.withIndex()) { |
|
|
|
for ((lineIndex, textLine) in textPage.textLines.withIndex()) { |
|
|
|
if (y > textLine.lineTop && y < textLine.lineBottom) { |
|
|
|
if (y > textLine.lineTop && y < textLine.lineBottom) { |
|
|
@ -96,19 +96,22 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
selectStartChar = charIndex |
|
|
|
selectStartChar = charIndex |
|
|
|
selectEndLine = lineIndex |
|
|
|
selectEndLine = lineIndex |
|
|
|
selectEndChar = charIndex |
|
|
|
selectEndChar = charIndex |
|
|
|
return SelectPoint( |
|
|
|
upSelectedStart( |
|
|
|
textChar.leftBottomPosition.x, |
|
|
|
textChar.leftBottomPosition.x, |
|
|
|
textChar.leftBottomPosition.y.toFloat(), |
|
|
|
textChar.leftBottomPosition.y.toFloat() |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
upSelectedEnd( |
|
|
|
textChar.rightTopPosition.x, |
|
|
|
textChar.rightTopPosition.x, |
|
|
|
textChar.leftBottomPosition.y.toFloat() |
|
|
|
textChar.leftBottomPosition.y.toFloat() |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
break |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return null |
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun selectStartMove(x: Float, y: Float) { |
|
|
|
fun selectStartMove(x: Float, y: Float) { |
|
|
@ -117,18 +120,15 @@ 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) { |
|
|
|
textChar.selected = true |
|
|
|
if (selectStartLine != lineIndex || selectStartChar != charIndex) { |
|
|
|
invalidate() |
|
|
|
selectStartLine = lineIndex |
|
|
|
selectStartLine = lineIndex |
|
|
|
selectStartChar = charIndex |
|
|
|
selectStartChar = charIndex |
|
|
|
upSelectedStart( |
|
|
|
selectEndLine = lineIndex |
|
|
|
textChar.leftBottomPosition.x, |
|
|
|
selectEndChar = charIndex |
|
|
|
textChar.leftBottomPosition.y.toFloat() |
|
|
|
SelectPoint( |
|
|
|
) |
|
|
|
textChar.leftBottomPosition.x, |
|
|
|
upSelectChars(textPage) |
|
|
|
textChar.leftBottomPosition.y.toFloat(), |
|
|
|
} |
|
|
|
textChar.rightTopPosition.x, |
|
|
|
|
|
|
|
textChar.leftBottomPosition.y.toFloat() |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
break |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -144,18 +144,16 @@ 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) { |
|
|
|
textChar.selected = true |
|
|
|
if (selectEndLine != lineIndex || selectEndChar != charIndex) { |
|
|
|
invalidate() |
|
|
|
selectEndLine = lineIndex |
|
|
|
selectStartLine = lineIndex |
|
|
|
selectEndChar = charIndex |
|
|
|
selectStartChar = charIndex |
|
|
|
upSelectedEnd( |
|
|
|
selectEndLine = lineIndex |
|
|
|
textChar.rightTopPosition.x, |
|
|
|
selectEndChar = charIndex |
|
|
|
textChar.leftBottomPosition.y.toFloat() |
|
|
|
SelectPoint( |
|
|
|
) |
|
|
|
textChar.leftBottomPosition.x, |
|
|
|
upSelectChars(textPage) |
|
|
|
textChar.leftBottomPosition.y.toFloat(), |
|
|
|
} |
|
|
|
textChar.rightTopPosition.x, |
|
|
|
break |
|
|
|
textChar.leftBottomPosition.y.toFloat() |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
break |
|
|
|
break |
|
|
@ -164,6 +162,31 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun upSelectChars(textPage: TextPage) { |
|
|
|
|
|
|
|
for ((lineIndex, textLine) in textPage.textLines.withIndex()) { |
|
|
|
|
|
|
|
for ((charIndex, textChar) in textLine.textChars.withIndex()) { |
|
|
|
|
|
|
|
textChar.selected = when (lineIndex) { |
|
|
|
|
|
|
|
selectStartLine -> { |
|
|
|
|
|
|
|
charIndex >= selectStartChar |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
selectEndLine -> { |
|
|
|
|
|
|
|
charIndex <= selectEndChar |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else -> lineIndex in (selectStartLine + 1) until selectEndLine |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
invalidate() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun upSelectedStart(x: Float, y: Float) { |
|
|
|
|
|
|
|
activityCallBack?.upSelectedStart(x, y + headerHeight) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun upSelectedEnd(x: Float, y: Float) { |
|
|
|
|
|
|
|
activityCallBack?.upSelectedEnd(x, y + headerHeight) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun cancelSelect() { |
|
|
|
fun cancelSelect() { |
|
|
|
textPage?.let { textPage -> |
|
|
|
textPage?.let { textPage -> |
|
|
|
textPage.textLines.forEach { textLine -> |
|
|
|
textPage.textLines.forEach { textLine -> |
|
|
@ -177,6 +200,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
interface CallBack { |
|
|
|
interface CallBack { |
|
|
|
|
|
|
|
fun upSelectedStart(x: Float, y: Float) |
|
|
|
|
|
|
|
fun upSelectedEnd(x: Float, y: Float) |
|
|
|
fun onCancelSelect() |
|
|
|
fun onCancelSelect() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|