|
|
@ -9,6 +9,7 @@ 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.service.help.ReadBook |
|
|
|
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 |
|
|
@ -31,8 +32,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
private var textPage: TextPage? = null |
|
|
|
private var textPage: TextPage? = null |
|
|
|
//滚动参数 |
|
|
|
//滚动参数 |
|
|
|
private val maxScrollOffset = 100f |
|
|
|
private val maxScrollOffset = 100f |
|
|
|
private val pageOffset = 0f |
|
|
|
private var pageOffset = 0f |
|
|
|
private val isLastPage = false |
|
|
|
private var isLastPage = false |
|
|
|
|
|
|
|
|
|
|
|
init { |
|
|
|
init { |
|
|
|
activityCallBack = activity as CallBack |
|
|
|
activityCallBack = activity as CallBack |
|
|
@ -70,15 +71,15 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
canvas.drawText( |
|
|
|
canvas.drawText( |
|
|
|
it.charData, |
|
|
|
it.charData, |
|
|
|
it.leftBottomPosition.x, |
|
|
|
it.leftBottomPosition.x, |
|
|
|
it.leftBottomPosition.y.toFloat(), |
|
|
|
it.leftBottomPosition.y, |
|
|
|
textPaint |
|
|
|
textPaint |
|
|
|
) |
|
|
|
) |
|
|
|
if (it.selected) { |
|
|
|
if (it.selected) { |
|
|
|
canvas.drawRect( |
|
|
|
canvas.drawRect( |
|
|
|
it.leftBottomPosition.x, |
|
|
|
it.leftBottomPosition.x, |
|
|
|
it.rightTopPosition.y.toFloat(), |
|
|
|
it.rightTopPosition.y, |
|
|
|
it.rightTopPosition.x, |
|
|
|
it.rightTopPosition.x, |
|
|
|
it.leftBottomPosition.y.toFloat(), |
|
|
|
it.leftBottomPosition.y, |
|
|
|
selectedPaint |
|
|
|
selectedPaint |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
@ -87,14 +88,22 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun onScroll(offset: Float) { |
|
|
|
fun onScroll(mOffset: Float) { |
|
|
|
var mOffset = offset |
|
|
|
var offset = mOffset |
|
|
|
if (offset > maxScrollOffset) { |
|
|
|
if (offset > maxScrollOffset) { |
|
|
|
mOffset = maxScrollOffset |
|
|
|
offset = maxScrollOffset |
|
|
|
} else if (offset < -maxScrollOffset) { |
|
|
|
} else if (offset < -maxScrollOffset) { |
|
|
|
mOffset = -maxScrollOffset |
|
|
|
offset = -maxScrollOffset |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isLastPage || offset < 0) { |
|
|
|
|
|
|
|
pageOffset += offset |
|
|
|
|
|
|
|
isLastPage = false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 首页 |
|
|
|
|
|
|
|
if (pageOffset < 0 && ReadBook.durChapterIndex == 0 && ReadBook.durPageIndex == 0) { |
|
|
|
|
|
|
|
pageOffset = 0f |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -112,11 +121,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
selectCharEnd = charIndex |
|
|
|
selectCharEnd = charIndex |
|
|
|
upSelectedStart( |
|
|
|
upSelectedStart( |
|
|
|
textChar.leftBottomPosition.x, |
|
|
|
textChar.leftBottomPosition.x, |
|
|
|
textChar.leftBottomPosition.y.toFloat() |
|
|
|
textChar.leftBottomPosition.y |
|
|
|
) |
|
|
|
) |
|
|
|
upSelectedEnd( |
|
|
|
upSelectedEnd( |
|
|
|
textChar.rightTopPosition.x, |
|
|
|
textChar.rightTopPosition.x, |
|
|
|
textChar.leftBottomPosition.y.toFloat() |
|
|
|
textChar.leftBottomPosition.y |
|
|
|
) |
|
|
|
) |
|
|
|
return true |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
@ -139,7 +148,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
selectCharStart = charIndex |
|
|
|
selectCharStart = charIndex |
|
|
|
upSelectedStart( |
|
|
|
upSelectedStart( |
|
|
|
textChar.leftBottomPosition.x, |
|
|
|
textChar.leftBottomPosition.x, |
|
|
|
textChar.leftBottomPosition.y.toFloat() |
|
|
|
textChar.leftBottomPosition.y |
|
|
|
) |
|
|
|
) |
|
|
|
upSelectChars(textPage) |
|
|
|
upSelectChars(textPage) |
|
|
|
} |
|
|
|
} |
|
|
@ -163,7 +172,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
selectCharEnd = charIndex |
|
|
|
selectCharEnd = charIndex |
|
|
|
upSelectedEnd( |
|
|
|
upSelectedEnd( |
|
|
|
textChar.rightTopPosition.x, |
|
|
|
textChar.rightTopPosition.x, |
|
|
|
textChar.leftBottomPosition.y.toFloat() |
|
|
|
textChar.leftBottomPosition.y |
|
|
|
) |
|
|
|
) |
|
|
|
upSelectChars(textPage) |
|
|
|
upSelectChars(textPage) |
|
|
|
} |
|
|
|
} |
|
|
|