...
This commit is contained in:
parent
c249e79e9a
commit
55a0b209ec
@ -8,6 +8,10 @@ import android.text.Layout
|
|||||||
import android.text.StaticLayout
|
import android.text.StaticLayout
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import androidx.appcompat.widget.AppCompatTextView
|
import androidx.appcompat.widget.AppCompatTextView
|
||||||
|
import androidx.core.view.marginBottom
|
||||||
|
import androidx.core.view.marginLeft
|
||||||
|
import androidx.core.view.marginRight
|
||||||
|
import androidx.core.view.marginTop
|
||||||
import com.mime.dualscreenview.common.Blog
|
import com.mime.dualscreenview.common.Blog
|
||||||
import kotlinx.coroutines.MainScope
|
import kotlinx.coroutines.MainScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@ -149,7 +153,7 @@ class PagedTextView : AppCompatTextView {
|
|||||||
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
||||||
super.onSizeChanged(w, h, oldw, oldh)
|
super.onSizeChanged(w, h, oldw, oldh)
|
||||||
Blog.LOGD(log = "onSizeChanged>> ${this::class.java.name}")
|
Blog.LOGD(log = "onSizeChanged>> ${this::class.java.name}")
|
||||||
pageHeight = h
|
pageHeight = ((h - (marginTop + marginBottom + paddingTop + paddingBottom)) * 0.85f).toInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
|
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
|
||||||
@ -175,9 +179,9 @@ class PagedTextView : AppCompatTextView {
|
|||||||
pageList.clear()
|
pageList.clear()
|
||||||
Blog.LOGD(log = "paginate>> ${this::class.java.name} && ${layout.text}")
|
Blog.LOGD(log = "paginate>> ${this::class.java.name} && ${layout.text}")
|
||||||
val layout = from(layout)
|
val layout = from(layout)
|
||||||
val lines = if(min(maxLines, layout.lineCount) > 10) {min(maxLines, layout.lineCount) - 2} else {min(maxLines, layout.lineCount)}
|
val lines = if(min(maxLines, layout.lineCount) > 10) {min(maxLines, layout.lineCount) - 1} else {min(maxLines, layout.lineCount)}
|
||||||
var startOffset = 0
|
var startOffset = 0
|
||||||
val heightWithoutPaddings = (pageHeight - (paddingTop + paddingBottom)) * 0.85
|
val heightWithoutPaddings = pageHeight - (marginTop + marginBottom + paddingTop + paddingBottom)
|
||||||
var height = heightWithoutPaddings
|
var height = heightWithoutPaddings
|
||||||
|
|
||||||
for (i in 0 until lines) {
|
for (i in 0 until lines) {
|
||||||
@ -191,8 +195,13 @@ class PagedTextView : AppCompatTextView {
|
|||||||
|
|
||||||
if (i == lines - 1) {
|
if (i == lines - 1) {
|
||||||
pageList.add(
|
pageList.add(
|
||||||
|
if(layout.lineCount > i) {
|
||||||
|
layout.text.subSequence(startOffset, layout.getLineEnd(i + 1))
|
||||||
|
} else {
|
||||||
layout.text.subSequence(startOffset, layout.getLineEnd(i))
|
layout.text.subSequence(startOffset, layout.getLineEnd(i))
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mPagedTextGenerateInterface?.completePagination(pageList)
|
mPagedTextGenerateInterface?.completePagination(pageList)
|
||||||
@ -214,7 +223,7 @@ class PagedTextView : AppCompatTextView {
|
|||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
StaticLayout.Builder
|
StaticLayout.Builder
|
||||||
.obtain(originalText, 0, originalText.length, paint, layout.width - (paddingLeft + paddingRight))
|
.obtain(originalText, 0, originalText.length, paint, ((layout.width - (paddingLeft + paddingRight + marginLeft + marginRight) * 0.85f)).toInt())
|
||||||
.setAlignment(layout.alignment)
|
.setAlignment(layout.alignment)
|
||||||
.setLineSpacing(lineSpacingExtra, lineSpacingMultiplier)
|
.setLineSpacing(lineSpacingExtra, lineSpacingMultiplier)
|
||||||
.setIncludePad(includeFontPadding)
|
.setIncludePad(includeFontPadding)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user