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

Commit e6dad690 authored by Ibrahim Yilmaz's avatar Ibrahim Yilmaz
Browse files

Improve ImageFloatingTextView Tracing

Bug: 316110233
Test: presubmit
Flag: None
Change-Id: Ib35a97f80023201f5b04d1ba19eea5c6e6932379
parent 60dc8407
Loading
Loading
Loading
Loading
+58 −5
Original line number Diff line number Diff line
@@ -18,9 +18,11 @@ 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;
@@ -48,6 +50,10 @@ 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);
    }
@@ -71,7 +77,10 @@ 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) {
@@ -115,7 +124,10 @@ public class ImageFloatingTextView extends TextView {
        }

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

@@ -141,7 +153,10 @@ 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
@@ -168,8 +183,13 @@ public class ImageFloatingTextView extends TextView {
                super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            }
        }


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

    @Override
    public void onRtlPropertiesChanged(int layoutDirection) {
@@ -216,4 +236,37 @@ 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);
    }
}