#1251 - Fix messages containing RTL languages being clipped

This commit is contained in:
moezbhatti
2019-03-05 22:12:05 -05:00
parent a5c45c2b34
commit 45b3e18cba
@@ -21,20 +21,28 @@ package com.moez.QKSMS.common.widget
import android.content.Context
import android.util.AttributeSet
class TightTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : QkTextView(context, attrs) {
class TightTextView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null
) : QkTextView(context, attrs) {
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
layout?.let {
val maxLineWidth = (0 until layout.lineCount)
.asSequence()
.map { layout.getLineMax(it) }
.max() ?: 0f
// Get a non-null copy of the layout, if available. Then ensure we've got multiple lines
val layout = layout ?: return
if (layout.lineCount <= 1) {
return
}
val width = (Math.ceil(maxLineWidth.toDouble()).toInt() + compoundPaddingLeft + compoundPaddingRight)
val height = measuredHeight
setMeasuredDimension(width, height)
val maxLineWidth = (0 until layout.lineCount)
.map(layout::getLineWidth)
.max() ?: 0f
val width = Math.ceil(maxLineWidth.toDouble()).toInt() + compoundPaddingLeft + compoundPaddingRight
if (width < measuredWidth) {
val widthSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.getMode(widthMeasureSpec))
super.onMeasure(widthSpec, heightMeasureSpec)
}
}