Loading presentation/src/main/java/com/moez/QKSMS/common/widget/TightTextView.kt +17 −9 Original line number Diff line number Diff line Loading @@ -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 { // 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 maxLineWidth = (0 until layout.lineCount) .asSequence() .map { layout.getLineMax(it) } .map(layout::getLineWidth) .max() ?: 0f val width = (Math.ceil(maxLineWidth.toDouble()).toInt() + compoundPaddingLeft + compoundPaddingRight) val height = measuredHeight setMeasuredDimension(width, height) val width = Math.ceil(maxLineWidth.toDouble()).toInt() + compoundPaddingLeft + compoundPaddingRight if (width < measuredWidth) { val widthSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.getMode(widthMeasureSpec)) super.onMeasure(widthSpec, heightMeasureSpec) } } Loading Loading
presentation/src/main/java/com/moez/QKSMS/common/widget/TightTextView.kt +17 −9 Original line number Diff line number Diff line Loading @@ -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 { // 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 maxLineWidth = (0 until layout.lineCount) .asSequence() .map { layout.getLineMax(it) } .map(layout::getLineWidth) .max() ?: 0f val width = (Math.ceil(maxLineWidth.toDouble()).toInt() + compoundPaddingLeft + compoundPaddingRight) val height = measuredHeight setMeasuredDimension(width, height) val width = Math.ceil(maxLineWidth.toDouble()).toInt() + compoundPaddingLeft + compoundPaddingRight if (width < measuredWidth) { val widthSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.getMode(widthMeasureSpec)) super.onMeasure(widthSpec, heightMeasureSpec) } } Loading