pull/32/head
kunfei 5 years ago
parent edd3ab77f9
commit 04b471f7c1
  1. 19
      app/src/main/java/io/legado/app/ui/widget/page/ChapterProvider.kt
  2. 41
      app/src/main/java/io/legado/app/ui/widget/page/ContentTextView.kt

@ -0,0 +1,19 @@
package io.legado.app.ui.widget.page
import android.widget.TextView
class ChapterProvider {
fun getTextChapter(textView: TextView, content: String) {
textView.text = content
val layout = textView.layout
val topOfLastLine = textView.height - textView.paddingTop - textView.paddingBottom - textView.lineHeight
val lineNum = layout.getLineForVertical(topOfLastLine)
val lastCharNum = layout.getLineEnd(lineNum)
}
}

@ -0,0 +1,41 @@
package io.legado.app.ui.widget.page
import android.content.Context
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatTextView
class ContentTextView : AppCompatTextView {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
/**
* 去除当前页无法显示的字
* @return 去掉的字数
*/
fun resize(): Int {
val oldContent = text
val newContent = oldContent.subSequence(0, getCharNum())
text = newContent
return oldContent.length - newContent.length
}
/**
* 获取当前页总字数
*/
fun getCharNum(): Int {
return layout.getLineEnd(getLineNum())
}
/**
* 获取当前页总行数
*/
fun getLineNum(): Int {
val layout = layout
val topOfLastLine = height - paddingTop - paddingBottom - lineHeight
return layout.getLineForVertical(topOfLastLine)
}
}
Loading…
Cancel
Save