Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ecfb379e authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Do not relayout when changing to Marquee

The text field size won't really change, so there's not reason to
remeasure and relayout. This saves us up to 48 measure steps when
unlocking the device.

Test: https://ui.perfetto.dev/#!/?s=519ae4c7f943f3ebad09eae63e445112c1d4286dd8376e18e69d713f1a9c2
Bug: 210432290
Change-Id: Ie3b7e0f7e942aac23605e2588cf6b942d507588f
parent ee754300
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -10821,8 +10821,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                        && mSavedMarqueeModeLayout.getLineWidth(0) > width));
    }
    /**
     * @hide
     */
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
    private void startMarquee() {
    protected void startMarquee() {
        // Do not ellipsize EditText
        if (getKeyListener() != null) return;
@@ -10848,7 +10851,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        }
    }
    private void stopMarquee() {
    /**
     * @hide
     */
    protected void stopMarquee() {
        if (mMarquee != null && !mMarquee.isStopped()) {
            mMarquee.stop();
        }
+4 −4
Original line number Diff line number Diff line
@@ -26,9 +26,9 @@
    android:layout_marginEnd="0dp"
    android:layout_gravity="center_vertical | start">

    <TextView
    <com.android.systemui.util.SafeMarqueeTextView
        android:id="@+id/tile_label"
        android:layout_width="wrap_content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="start"
        android:textDirection="locale"
@@ -37,9 +37,9 @@
        android:singleLine="true"
        android:textAppearance="@style/TextAppearance.QS.TileLabel"/>

    <TextView
    <com.android.systemui.util.SafeMarqueeTextView
        android:id="@+id/app_label"
        android:layout_width="wrap_content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="start"
        android:textDirection="locale"
+7 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.content.res.Configuration
import android.content.res.Resources.ID_NULL
import android.graphics.drawable.Drawable
import android.graphics.drawable.RippleDrawable
import android.os.Trace
import android.service.quicksettings.Tile
import android.text.TextUtils
import android.util.Log
@@ -163,6 +164,12 @@ open class QSTileViewImpl @JvmOverloads constructor(
        updateResources()
    }

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        Trace.traceBegin(Trace.TRACE_TAG_APP, "QSTileViewImpl#onMeasure")
        super.onMeasure(widthMeasureSpec, heightMeasureSpec)
        Trace.endSection()
    }

    override fun resetOverride() {
        heightOverride = HeightOverrideable.NO_OVERRIDE
        updateHeight()
+1 −2
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.systemui.util;
import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.TextView;

/**
 * TextView that changes its ellipsize value with its visibility.
@@ -27,7 +26,7 @@ import android.widget.TextView;
 * The View responds to changes in user-visibility to change its ellipsize from MARQUEE to END
 * and back. Useful for TextView that need to marquee forever.
 */
public class AutoMarqueeTextView extends TextView {
public class AutoMarqueeTextView extends SafeMarqueeTextView {

    private boolean mAggregatedVisible = false;

+44 −0
Original line number Diff line number Diff line
package com.android.systemui.util

import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.ViewGroup
import android.widget.TextView

/**
 * A TextField that doesn't relayout when changing from marquee to ellipsis.
 */
@SuppressLint("AppCompatCustomView")
open class SafeMarqueeTextView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0,
    defStyleRes: Int = 0
) : TextView(context, attrs, defStyleAttr, defStyleRes) {

    private var safelyIgnoreLayout = false
    private val hasStableWidth
        get() = layoutParams.width != ViewGroup.LayoutParams.WRAP_CONTENT

    override fun requestLayout() {
        if (safelyIgnoreLayout) {
            return
        }
        super.requestLayout()
    }

    override fun startMarquee() {
        val wasIgnoring = safelyIgnoreLayout
        safelyIgnoreLayout = hasStableWidth
        super.startMarquee()
        safelyIgnoreLayout = wasIgnoring
    }

    override fun stopMarquee() {
        val wasIgnoring = safelyIgnoreLayout
        safelyIgnoreLayout = hasStableWidth
        super.stopMarquee()
        safelyIgnoreLayout = wasIgnoring
    }
}
 No newline at end of file