1 package com.android.systemui.util 2 3 import android.annotation.SuppressLint 4 import android.content.Context 5 import android.util.AttributeSet 6 import android.view.ViewGroup 7 import android.widget.TextView 8 9 /** 10 * A TextField that doesn't relayout when changing from marquee to ellipsis. 11 */ 12 @SuppressLint("AppCompatCustomView") 13 open class SafeMarqueeTextView @JvmOverloads constructor( 14 context: Context, 15 attrs: AttributeSet? = null, 16 defStyleAttr: Int = 0, 17 defStyleRes: Int = 0 18 ) : TextView(context, attrs, defStyleAttr, defStyleRes) { 19 20 private var safelyIgnoreLayout = false 21 private val hasStableWidth 22 get() = layoutParams.width != ViewGroup.LayoutParams.WRAP_CONTENT 23 requestLayoutnull24 override fun requestLayout() { 25 if (safelyIgnoreLayout) { 26 return 27 } 28 super.requestLayout() 29 } 30 startMarqueenull31 override fun startMarquee() { 32 val wasIgnoring = safelyIgnoreLayout 33 safelyIgnoreLayout = hasStableWidth 34 super.startMarquee() 35 safelyIgnoreLayout = wasIgnoring 36 } 37 stopMarqueenull38 override fun stopMarquee() { 39 val wasIgnoring = safelyIgnoreLayout 40 safelyIgnoreLayout = hasStableWidth 41 super.stopMarquee() 42 safelyIgnoreLayout = wasIgnoring 43 } 44 }