Truncated message in the pills (#8260)

This commit is contained in:
Yoan Pintas 2023-03-23 09:01:11 +01:00 committed by GitHub
parent 68f05e0687
commit 54457c1633
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

1
changelog.d/8218.bugfix Normal file
View File

@ -0,0 +1 @@
Long name are truncated in the pills

View File

@ -22,7 +22,9 @@ import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Rect
import android.graphics.drawable.Drawable
import android.text.TextUtils
import android.text.style.ReplacementSpan
import android.widget.TextView
import androidx.annotation.UiThread
@ -101,6 +103,15 @@ class PillImageSpan(
val transY: Int = y + (fm.descent + fm.ascent - pillDrawable.bounds.bottom) / 2
canvas.save()
canvas.translate(x, transY.toFloat())
val rect = Rect()
canvas.getClipBounds(rect)
val maxWidth = rect.right
if (pillDrawable.intrinsicWidth > maxWidth) {
pillDrawable.setBounds(0, 0, maxWidth, pillDrawable.intrinsicHeight)
pillDrawable.ellipsize = TextUtils.TruncateAt.END
}
pillDrawable.draw(canvas)
canvas.restore()
}