mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-2756 Fix text ellipsizing logic in custom TextInputWidget
- Implement pending text and buffer type storage in setText to handle ellipsize logic properly. - Override onMeasure to apply ellipsize after measuring widget dimensions. - Ensure that text is correctly truncated based on available width.
This commit is contained in:
parent
363237f0c5
commit
cd90c48348
2 changed files with 32 additions and 1 deletions
|
@ -4,9 +4,12 @@ import android.R.id.copy
|
|||
import android.R.id.paste
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Paint
|
||||
import android.os.Parcelable
|
||||
import android.text.InputType
|
||||
import android.text.Spanned
|
||||
import android.text.TextPaint
|
||||
import android.text.TextUtils
|
||||
import android.text.TextWatcher
|
||||
import android.text.util.Linkify
|
||||
import android.util.AttributeSet
|
||||
|
@ -257,6 +260,34 @@ class TextInputWidget : AppCompatEditText {
|
|||
super.onDraw(canvas)
|
||||
}
|
||||
|
||||
private var pendingText : CharSequence? = null
|
||||
private var pendingType: BufferType? = null
|
||||
|
||||
override fun setText(text: CharSequence?, type: BufferType?) {
|
||||
// try to cover most popular cases of setting up the text: by resId and by text
|
||||
if (ellipsize != null) {
|
||||
pendingText = text
|
||||
pendingType = type
|
||||
}
|
||||
super.setText(text, pendingType)
|
||||
}
|
||||
|
||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
||||
if (pendingText != null) {
|
||||
var text = pendingText
|
||||
if (ellipsize != null) {
|
||||
val textPaint = TextPaint(Paint.ANTI_ALIAS_FLAG or Paint.SUBPIXEL_TEXT_FLAG)
|
||||
textPaint.textSize = textSize
|
||||
// We don't have layout initialized until onMeasure is called
|
||||
text = TextUtils.ellipsize(text, textPaint, layout.width.toFloat(), ellipsize)
|
||||
}
|
||||
super.setText(text, pendingType)
|
||||
pendingText = null
|
||||
pendingType = null
|
||||
}
|
||||
}
|
||||
|
||||
fun setLinksClickable() {
|
||||
makeLinksActive()
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/graphic"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="W. J. T. Mitchell — There Are No Visual Media.pdf" />
|
||||
tools:text="@string/about" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</FrameLayout>
|
Loading…
Add table
Add a link
Reference in a new issue