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

Commit 66dccad6 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Disabling unnecessary requestLayout calls in BubbleTextView

> Disabling layout change when updating icon, if previously set
> Setting the ellipsis behavior to end, to disable relayouts when
  changing text

Change-Id: Ic00c207c0372724daebd8ee1d748f5cf5aa56457
parent a7c28940
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@
        android:layout_height="@dimen/widget_section_height"
        android:background="?android:attr/colorPrimary"
        android:drawablePadding="@dimen/widget_section_horizontal_padding"
        android:ellipsize="end"
        android:focusable="true"
        android:gravity="start|center_vertical"
        android:paddingBottom="@dimen/widget_section_vertical_padding"
+0 −1
Original line number Diff line number Diff line
@@ -112,7 +112,6 @@
        <item name="android:focusable">true</item>
        <item name="android:gravity">center_horizontal</item>
        <item name="android:singleLine">true</item>
        <item name="android:ellipsize">marquee</item>
        <item name="android:textColor">?android:attr/textColorSecondary</item>
        <item name="android:fontFamily">sans-serif-condensed</item>

+18 −10
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.support.v4.graphics.ColorUtils;
import android.text.TextUtils.TruncateAt;
import android.util.AttributeSet;
import android.util.Property;
import android.util.TypedValue;
@@ -163,10 +164,18 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
        mLongPressHelper = new CheckLongPressHelper(this);
        mStylusEventHelper = new StylusEventHelper(new SimpleOnStylusPressListener(this), this);

        setEllipsize(TruncateAt.END);
        setAccessibilityDelegate(mActivity.getAccessibilityDelegate());

    }

    @Override
    protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
        // Disable marques when not focused to that, so that updating text does not cause relayout.
        setEllipsize(focused ? TruncateAt.MARQUEE : TruncateAt.END);
        super.onFocusChanged(focused, direction, previouslyFocusedRect);
    }

    /**
     * Resets the view so it can be recycled.
     */
@@ -521,31 +530,30 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
     * Sets the icon for this view based on the layout direction.
     */
    private void setIcon(Drawable icon) {
        mIcon = icon;
        mIcon.setBounds(0, 0, mIconSize, mIconSize);
        if (mIsIconVisible) {
            applyCompoundDrawables(mIcon);
            applyCompoundDrawables(icon);
        }
        mIcon = icon;
    }

    public void setIconVisible(boolean visible) {
        mIsIconVisible = visible;
        mDisableRelayout = true;
        Drawable icon = mIcon;
        if (!visible) {
            icon = new ColorDrawable(Color.TRANSPARENT);
            icon.setBounds(0, 0, mIconSize, mIconSize);
        }
        Drawable icon = visible ? mIcon : new ColorDrawable(Color.TRANSPARENT);
        applyCompoundDrawables(icon);
        mDisableRelayout = false;
    }

    protected void applyCompoundDrawables(Drawable icon) {
        // If we had already set an icon before, disable relayout as the icon size is the
        // same as before.
        mDisableRelayout = mIcon != null;

        icon.setBounds(0, 0, mIconSize, mIconSize);
        if (mLayoutHorizontal) {
            setCompoundDrawablesRelative(icon, null, null, null);
        } else {
            setCompoundDrawables(null, icon, null, null);
        }
        mDisableRelayout = false;
    }

    @Override
+0 −1
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Region;
import android.support.v4.graphics.ColorUtils;
import android.util.AttributeSet;
import android.widget.TextView;