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

Commit 8933efd4 authored by Alan Viverette's avatar Alan Viverette
Browse files

Update ListMenuItemView to use a single RelativeLayout

BUG: 9591217
Change-Id: If5d301f70ac3806ab14e309affa57c625d897c7d
parent 066bdcfe
Loading
Loading
Loading
Loading
+78 −70
Original line number Diff line number Diff line
@@ -26,15 +26,17 @@ import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * The item view for each item in the ListView-based MenuViews.
 */
public class ListMenuItemView extends LinearLayout implements MenuView.ItemView {
    private static final String TAG = "ListMenuItemView";
public class ListMenuItemView extends RelativeLayout implements MenuView.ItemView {
    private final Drawable mBackground;
    private final int mTextAppearance;

    private MenuItemImpl mItemData;

    private ImageView mIconView;
@@ -43,30 +45,21 @@ public class ListMenuItemView extends LinearLayout implements MenuView.ItemView
    private CheckBox mCheckBox;
    private TextView mShortcutView;

    private Drawable mBackground;
    private int mTextAppearance;
    private Context mTextAppearanceContext;
    private boolean mPreserveIconSpacing;
    
    private int mMenuType;
    
    private LayoutInflater mInflater;

    private boolean mPreserveIconSpacing;
    private boolean mForceShowIcon;

    public ListMenuItemView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs);

        TypedArray a =
            context.obtainStyledAttributes(
        final TypedArray a = context.obtainStyledAttributes(
                attrs, com.android.internal.R.styleable.MenuView, defStyle, 0);
        
        mBackground = a.getDrawable(com.android.internal.R.styleable.MenuView_itemBackground);
        mTextAppearance = a.getResourceId(com.android.internal.R.styleable.
                                          MenuView_itemTextAppearance, -1);
        mTextAppearance = a.getResourceId(
                com.android.internal.R.styleable.MenuView_itemTextAppearance, 0);
        mPreserveIconSpacing = a.getBoolean(
                com.android.internal.R.styleable.MenuView_preserveIconSpacing, false);
        mTextAppearanceContext = context;

        a.recycle();
    }
@@ -79,23 +72,21 @@ public class ListMenuItemView extends LinearLayout implements MenuView.ItemView
    protected void onFinishInflate() {
        super.onFinishInflate();

        setBackgroundDrawable(mBackground);
        setBackground(mBackground);

        mTitleView = (TextView) findViewById(com.android.internal.R.id.title);
        if (mTextAppearance != -1) {
            mTitleView.setTextAppearance(mTextAppearanceContext,
                                         mTextAppearance);
        if (mTextAppearance != 0) {
            mTitleView.setTextAppearance(mContext, mTextAppearance);
        }

        mShortcutView = (TextView) findViewById(com.android.internal.R.id.shortcut);
    }

    @Override
    public void initialize(MenuItemImpl itemData, int menuType) {
        mItemData = itemData;
        mMenuType = menuType;

        setVisibility(itemData.isVisible() ? View.VISIBLE : View.GONE);
        
        setTitle(itemData.getTitleForItemView(this));
        setCheckable(itemData.isCheckable());
        setShortcut(itemData.shouldShowShortcut(), itemData.getShortcut());
@@ -107,20 +98,27 @@ public class ListMenuItemView extends LinearLayout implements MenuView.ItemView
        mPreserveIconSpacing = mForceShowIcon = forceShow;
    }

    @Override
    public void setTitle(CharSequence title) {
        if (title != null) {
            mTitleView.setText(title);

            if (mTitleView.getVisibility() != VISIBLE) mTitleView.setVisibility(VISIBLE);
            if (mTitleView.getVisibility() != VISIBLE) {
                mTitleView.setVisibility(VISIBLE);
            }
        } else {
            if (mTitleView.getVisibility() != GONE) mTitleView.setVisibility(GONE);
            if (mTitleView.getVisibility() != GONE) {
                mTitleView.setVisibility(GONE);
            }
        }
    }

    @Override
    public MenuItemImpl getItemData() {
        return mItemData;
    }

    @Override
    public void setCheckable(boolean checkable) {
        if (!checkable && mRadioButton == null && mCheckBox == null) {
            return;
@@ -153,16 +151,24 @@ public class ListMenuItemView extends LinearLayout implements MenuView.ItemView
                compoundButton.setVisibility(newVisibility);
            }

            // Align text to the start of the visible compound button.
            alignTextToStartOf(compoundButton);

            // Make sure the other compound button isn't visible
            if (otherCompoundButton != null && otherCompoundButton.getVisibility() != GONE) {
                otherCompoundButton.setVisibility(GONE);
            }
        } else {
            if (mCheckBox != null) mCheckBox.setVisibility(GONE);
            if (mRadioButton != null) mRadioButton.setVisibility(GONE);
            if (mCheckBox != null) {
                mCheckBox.setVisibility(GONE);
            }
            if (mRadioButton != null) {
                mRadioButton.setVisibility(GONE);
            }
        }
    }

    @Override
    public void setChecked(boolean checked) {
        CompoundButton compoundButton;

@@ -181,9 +187,9 @@ public class ListMenuItemView extends LinearLayout implements MenuView.ItemView
        compoundButton.setChecked(checked);
    }

    @Override
    public void setShortcut(boolean showShortcut, char shortcutKey) {
        final int newVisibility = (showShortcut && mItemData.shouldShowShortcut())
                ? VISIBLE : GONE;
        final int newVisibility = (showShortcut && mItemData.shouldShowShortcut()) ? VISIBLE : GONE;

        if (newVisibility == VISIBLE) {
            mShortcutView.setText(mItemData.getShortcutLabel());
@@ -194,6 +200,7 @@ public class ListMenuItemView extends LinearLayout implements MenuView.ItemView
        }
    }

    @Override
    public void setIcon(Drawable icon) {
        final boolean showIcon = mItemData.shouldShowIcon() || mForceShowIcon;
        if (!showIcon && !mPreserveIconSpacing) {
@@ -223,42 +230,43 @@ public class ListMenuItemView extends LinearLayout implements MenuView.ItemView
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        if (mIconView != null && mPreserveIconSpacing) {
            // Enforce minimum icon spacing
            ViewGroup.LayoutParams lp = getLayoutParams();
            LayoutParams iconLp = (LayoutParams) mIconView.getLayoutParams();
            final ViewGroup.LayoutParams lp = getLayoutParams();
            final LayoutParams iconLp = (LayoutParams) mIconView.getLayoutParams();
            if (lp.height > 0 && iconLp.width <= 0) {
                iconLp.width = lp.height;
            }
        }

        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    private void insertIconView() {
        LayoutInflater inflater = getInflater();
        mIconView = (ImageView) inflater.inflate(com.android.internal.R.layout.list_menu_item_icon,
                this, false);
        addView(mIconView, 0);
        mIconView = (ImageView) getInflater()
                .inflate(com.android.internal.R.layout.list_menu_item_icon, this, true);
    }

    private void insertRadioButton() {
        LayoutInflater inflater = getInflater();
        mRadioButton =
                (RadioButton) inflater.inflate(com.android.internal.R.layout.list_menu_item_radio,
                this, false);
        addView(mRadioButton);
        mRadioButton = (RadioButton) getInflater()
                .inflate(com.android.internal.R.layout.list_menu_item_radio, this, true);
    }

    private void insertCheckBox() {
        LayoutInflater inflater = getInflater();
        mCheckBox =
                (CheckBox) inflater.inflate(com.android.internal.R.layout.list_menu_item_checkbox,
                this, false);
        addView(mCheckBox);
        mCheckBox = (CheckBox) getInflater()
                .inflate(com.android.internal.R.layout.list_menu_item_checkbox, this, true);
    }

    private void alignTextToStartOf(View v) {
        final LayoutParams params = (LayoutParams) mTitleView.getLayoutParams();
        params.addRule(RelativeLayout.START_OF, v.getId());
        mTitleView.setLayoutParams(params);
    }

    @Override
    public boolean prefersCondensedTitle() {
        return false;
    }

    @Override
    public boolean showsIcon() {
        return mForceShowIcon;
    }
+4 −5
Original line number Diff line number Diff line
@@ -18,9 +18,8 @@
    android:id="@+id/checkbox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:layout_alignParentEnd="true"
    android:layout_centerVertical="true"
    android:focusable="false"
    android:clickable="false"
    android:duplicateParentState="true" />

+6 −5
Original line number Diff line number Diff line
@@ -18,11 +18,12 @@
    android:id="@+id/icon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:layout_centerVertical="true"
    android:layout_alignParentStart="true"
    android:layout_marginStart="8dip"
    android:layout_marginEnd="-8dip"
    android:layout_marginTop="8dip"
    android:layout_marginBottom="8dip"
    android:scaleType="centerInside"
    android:duplicateParentState="true" />
    android:duplicateParentState="true"
    android:contentDescription="@null" />
+30 −38
Original line number Diff line number Diff line
@@ -16,26 +16,19 @@

<com.android.internal.view.menu.ListMenuItemView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/listPreferredItemHeightSmall">
    android:layout_height="?android:attr/listPreferredItemHeightSmall"
    android:gravity="start|center_vertical">

    <!-- Icon will be inserted here. -->

    <!-- The title and summary have some gap between them, and this 'group' should be centered vertically. -->
    <RelativeLayout
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_marginStart="?android:attr/listPreferredItemPaddingStart"
        android:layout_marginEnd="?android:attr/listPreferredItemPaddingEnd"
        android:duplicateParentState="true">
        
    <TextView
        android:id="@+id/title"
            android:layout_width="match_parent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_alignParentStart="true"
        android:layout_alignWithParentIfMissing="true"
        android:layout_marginStart="?android:attr/listPreferredItemPaddingStart"
        android:layout_marginEnd="?android:attr/listPreferredItemPaddingEnd"
        android:layout_toEndOf="@id/icon"
        android:textAppearance="?android:attr/textAppearanceListItemSmall"
        android:singleLine="true"
        android:duplicateParentState="true"
@@ -48,14 +41,13 @@
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/title"
            android:layout_alignParentStart="true"
        android:layout_alignStart="@id/title"
        android:layout_alignWithParentIfMissing="true"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:singleLine="true"
        android:duplicateParentState="true"
        android:textAlignment="viewStart" />

    </RelativeLayout>

    <!-- Checkbox, and/or radio button will be inserted here. -->

</com.android.internal.view.menu.ListMenuItemView>
+4 −3
Original line number Diff line number Diff line
@@ -18,7 +18,8 @@
    android:id="@+id/radio"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:layout_alignParentEnd="true"
    android:layout_centerVertical="true"
    android:focusable="false"
    android:clickable="false"
    android:duplicateParentState="true" />
Loading