|
|
@ -5,7 +5,6 @@ import android.graphics.Canvas |
|
|
|
import android.graphics.Paint |
|
|
|
import android.graphics.Paint |
|
|
|
import android.graphics.RectF |
|
|
|
import android.graphics.RectF |
|
|
|
import android.util.AttributeSet |
|
|
|
import android.util.AttributeSet |
|
|
|
import android.util.Log |
|
|
|
|
|
|
|
import android.view.View |
|
|
|
import android.view.View |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.constant.PreferKey |
|
|
|
import io.legado.app.constant.PreferKey |
|
|
@ -24,7 +23,6 @@ import io.legado.app.utils.activity |
|
|
|
import io.legado.app.utils.getCompatColor |
|
|
|
import io.legado.app.utils.getCompatColor |
|
|
|
import io.legado.app.utils.getPrefBoolean |
|
|
|
import io.legado.app.utils.getPrefBoolean |
|
|
|
import io.legado.app.utils.toastOnUi |
|
|
|
import io.legado.app.utils.toastOnUi |
|
|
|
import kotlinx.coroutines.CoroutineScope |
|
|
|
|
|
|
|
import kotlin.math.min |
|
|
|
import kotlin.math.min |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -168,23 +166,21 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
lineBottom: Float, |
|
|
|
lineBottom: Float, |
|
|
|
isImageLine: Boolean |
|
|
|
isImageLine: Boolean |
|
|
|
) { |
|
|
|
) { |
|
|
|
ReadBook.book?.let { book -> |
|
|
|
val book = ReadBook.book ?: return |
|
|
|
ImageProvider.getImage(book, textPage.chapterIndex, textChar.charData, true) |
|
|
|
ImageProvider.getImage(book, textPage.chapterIndex, textChar.charData, true)?.let { |
|
|
|
?.let { |
|
|
|
val rectF = if (isImageLine) { |
|
|
|
val rectF = if (isImageLine) { |
|
|
|
RectF(textChar.start, lineTop, textChar.end, lineBottom) |
|
|
|
RectF(textChar.start, lineTop, textChar.end, lineBottom) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
/*以宽度为基准保持图片的原始比例叠加,当div为负数时,允许高度比字符更高*/ |
|
|
|
/*以宽度为基准保持图片的原始比例叠加,当div为负数时,允许高度比字符更高*/ |
|
|
|
val h = (textChar.end - textChar.start) / it.width * it.height |
|
|
|
val h = (textChar.end - textChar.start) / it.width * it.height |
|
|
|
val div = (lineBottom - lineTop - h) / 2 |
|
|
|
val div = (lineBottom - lineTop - h) / 2 |
|
|
|
RectF(textChar.start, lineTop + div, textChar.end, lineBottom - div) |
|
|
|
RectF(textChar.start, lineTop + div, textChar.end, lineBottom - div) |
|
|
|
} |
|
|
|
} |
|
|
|
kotlin.runCatching { |
|
|
|
kotlin.runCatching { |
|
|
|
canvas.drawBitmap(it, null, rectF, null) |
|
|
|
canvas.drawBitmap(it, null, rectF, null) |
|
|
|
}.onFailure { e -> |
|
|
|
}.onFailure { e -> |
|
|
|
context.toastOnUi(e.localizedMessage) |
|
|
|
context.toastOnUi(e.localizedMessage) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -242,9 +238,9 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
} |
|
|
|
} |
|
|
|
val page = relativePage(relativePos) |
|
|
|
val page = relativePage(relativePos) |
|
|
|
for ((lineIndex, textLine) in page.textLines.withIndex()) { |
|
|
|
for ((lineIndex, textLine) in page.textLines.withIndex()) { |
|
|
|
if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { |
|
|
|
if (textLine.isTouch(y, relativeOffset)) { |
|
|
|
for ((charIndex, textChar) in textLine.textChars.withIndex()) { |
|
|
|
for ((charIndex, textChar) in textLine.textChars.withIndex()) { |
|
|
|
if (x > textChar.start && x < textChar.end) { |
|
|
|
if (textChar.isTouch(x)) { |
|
|
|
if (textChar.isImage) { |
|
|
|
if (textChar.isImage) { |
|
|
|
activity?.supportFragmentManager?.let { |
|
|
|
activity?.supportFragmentManager?.let { |
|
|
|
PhotoDialog.show(it, page.chapterIndex, textChar.charData) |
|
|
|
PhotoDialog.show(it, page.chapterIndex, textChar.charData) |
|
|
@ -278,13 +274,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
if (relativeOffset >= ChapterProvider.visibleHeight) return |
|
|
|
if (relativeOffset >= ChapterProvider.visibleHeight) return |
|
|
|
} |
|
|
|
} |
|
|
|
for ((lineIndex, textLine) in relativePage(relativePos).textLines.withIndex()) { |
|
|
|
for ((lineIndex, textLine) in relativePage(relativePos).textLines.withIndex()) { |
|
|
|
if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { |
|
|
|
if (textLine.isTouch(y, relativeOffset)) { |
|
|
|
for ((charIndex, textChar) in textLine.textChars.withIndex()) { |
|
|
|
for ((charIndex, textChar) in textLine.textChars.withIndex()) { |
|
|
|
if (x > textChar.start && x < textChar.end) { |
|
|
|
if (textChar.isTouch(x)) { |
|
|
|
if (selectStart[0] != relativePos || selectStart[1] != lineIndex || selectStart[2] != charIndex) { |
|
|
|
if (selectStart[0] != relativePos || selectStart[1] != lineIndex || selectStart[2] != charIndex) { |
|
|
|
if (selectToInt(relativePos, lineIndex, charIndex) > selectToInt( |
|
|
|
if (selectToInt(relativePos, lineIndex, charIndex) |
|
|
|
selectEnd |
|
|
|
> selectToInt(selectEnd) |
|
|
|
) |
|
|
|
|
|
|
|
) { |
|
|
|
) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
@ -320,15 +315,10 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
if (!callBack.isScroll) return |
|
|
|
if (!callBack.isScroll) return |
|
|
|
if (relativeOffset >= ChapterProvider.visibleHeight) return |
|
|
|
if (relativeOffset >= ChapterProvider.visibleHeight) return |
|
|
|
} |
|
|
|
} |
|
|
|
Log.e("y", "$y") |
|
|
|
|
|
|
|
for ((lineIndex, textLine) in relativePage(relativePos).textLines.withIndex()) { |
|
|
|
for ((lineIndex, textLine) in relativePage(relativePos).textLines.withIndex()) { |
|
|
|
if (y > textLine.lineTop + relativeOffset |
|
|
|
if (textLine.isTouch(y, relativeOffset)) { |
|
|
|
&& y < textLine.lineBottom + relativeOffset |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
Log.e("line", "$relativePos $lineIndex") |
|
|
|
|
|
|
|
for ((charIndex, textChar) in textLine.textChars.withIndex()) { |
|
|
|
for ((charIndex, textChar) in textLine.textChars.withIndex()) { |
|
|
|
if (x > textChar.start && x < textChar.end) { |
|
|
|
if (textChar.isTouch(x)) { |
|
|
|
Log.e("char", "$relativePos $lineIndex $charIndex") |
|
|
|
|
|
|
|
if (selectEnd[0] != relativePos |
|
|
|
if (selectEnd[0] != relativePos |
|
|
|
|| selectEnd[1] != lineIndex |
|
|
|
|| selectEnd[1] != lineIndex |
|
|
|
|| selectEnd[2] != charIndex |
|
|
|
|| selectEnd[2] != charIndex |
|
|
@ -540,7 +530,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
fun onCancelSelect() |
|
|
|
fun onCancelSelect() |
|
|
|
val headerHeight: Int |
|
|
|
val headerHeight: Int |
|
|
|
val pageFactory: TextPageFactory |
|
|
|
val pageFactory: TextPageFactory |
|
|
|
val scope: CoroutineScope |
|
|
|
|
|
|
|
val isScroll: Boolean |
|
|
|
val isScroll: Boolean |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|