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

Commit 5f323f5a authored by Priyanka Advani's avatar Priyanka Advani Committed by Android (Google) Code Review
Browse files

Merge "Revert "Improve ImageFloatingTextView Tracing"" into main

parents 9467e331 f691fa27
Loading
Loading
Loading
Loading
+5 −58
Original line number Diff line number Diff line
@@ -18,11 +18,9 @@ package com.android.internal.widget;

import android.annotation.Nullable;
import android.content.Context;
import android.os.Build;
import android.os.Trace;
import android.text.BoringLayout;
import android.text.Layout;
import android.text.PrecomputedText;
import android.text.StaticLayout;
import android.text.TextUtils;
import android.text.method.TransformationMethod;
@@ -50,10 +48,6 @@ public class ImageFloatingTextView extends TextView {
    private int mLayoutMaxLines = -1;
    private int mImageEndMargin;

    private int mStaticLayoutCreationCountInOnMeasure = 0;

    private static final boolean TRACE_ONMEASURE = Build.isDebuggable();

    public ImageFloatingTextView(Context context) {
        this(context, null);
    }
@@ -77,10 +71,7 @@ public class ImageFloatingTextView extends TextView {
    protected Layout makeSingleLayout(int wantWidth, BoringLayout.Metrics boring, int ellipsisWidth,
            Layout.Alignment alignment, boolean shouldEllipsize,
            TextUtils.TruncateAt effectiveEllipsize, boolean useSaved) {
        if (TRACE_ONMEASURE) {
        Trace.beginSection("ImageFloatingTextView#makeSingleLayout");
            mStaticLayoutCreationCountInOnMeasure++;
        }
        TransformationMethod transformationMethod = getTransformationMethod();
        CharSequence text = getText();
        if (transformationMethod != null) {
@@ -124,10 +115,7 @@ public class ImageFloatingTextView extends TextView {
        }

        final StaticLayout result = builder.build();
        if (TRACE_ONMEASURE) {
            trackMaxLines();
        Trace.endSection();
        }
        return result;
    }

@@ -153,10 +141,7 @@ public class ImageFloatingTextView extends TextView {

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        if (TRACE_ONMEASURE) {
        Trace.beginSection("ImageFloatingTextView#onMeasure");
        }
        mStaticLayoutCreationCountInOnMeasure = 0;
        int availableHeight = MeasureSpec.getSize(heightMeasureSpec) - mPaddingTop - mPaddingBottom;
        if (getLayout() != null && getLayout().getHeight() != availableHeight) {
            // We've been measured before and the new size is different than before, lets make sure
@@ -183,13 +168,8 @@ public class ImageFloatingTextView extends TextView {
                super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            }
        }


        if (TRACE_ONMEASURE) {
            trackParameters();
        Trace.endSection();
    }
    }

    @Override
    public void onRtlPropertiesChanged(int layoutDirection) {
@@ -236,37 +216,4 @@ public class ImageFloatingTextView extends TextView {
            requestLayout();
        }
    }

    private void trackParameters() {
        if (!TRACE_ONMEASURE) {
            return;
        }
        Trace.setCounter("ImageFloatingView#staticLayoutCreationCount",
                mStaticLayoutCreationCountInOnMeasure);
        Trace.setCounter("ImageFloatingView#isPrecomputedText",
                isTextAPrecomputedText());
    }
    /**
     * @return 1 if {@link TextView#getText()} is PrecomputedText, else 0
     */
    private int isTextAPrecomputedText() {
        final CharSequence text = getText();
        if (text == null || text.isEmpty()) {
            return 0;
        }

        if (text instanceof PrecomputedText) {
            return 1;
        }

        return 0;
    }

    private void trackMaxLines() {
        if (!TRACE_ONMEASURE) {
            return;
        }

        Trace.setCounter("ImageFloatingView#layoutMaxLines", mLayoutMaxLines);
    }
}