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

Commit 62339911 authored by Alan Viverette's avatar Alan Viverette Committed by Android (Google) Code Review
Browse files

Merge "Update ListMenuItemView to use a single RelativeLayout"

parents 5729b81a 8933efd4
Loading
Loading
Loading
Loading
+78 −70
Original line number Original line Diff line number Diff line
@@ -26,15 +26,17 @@ import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.TextView;


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

    private MenuItemImpl mItemData;
    private MenuItemImpl mItemData;


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


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


    private boolean mPreserveIconSpacing;
    private boolean mForceShowIcon;
    private boolean mForceShowIcon;


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


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


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


        setBackgroundDrawable(mBackground);
        setBackground(mBackground);


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


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


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


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


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


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


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


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


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

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


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


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


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


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


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

        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
    }


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


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


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

        addView(mCheckBox);
    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() {
    public boolean prefersCondensedTitle() {
        return false;
        return false;
    }
    }


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

+6 −5
Original line number Original line Diff line number Diff line
@@ -18,11 +18,12 @@
    android:id="@+id/icon"
    android:id="@+id/icon"
    android:layout_width="wrap_content"
    android:layout_width="wrap_content"
    android:layout_height="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_marginStart="8dip"
    android:layout_marginEnd="-8dip"
    android:layout_marginEnd="-8dip"
    android:layout_marginTop="8dip"
    android:layout_marginTop="8dip"
    android:layout_marginBottom="8dip"
    android:layout_marginBottom="8dip"
    android:scaleType="centerInside"
    android:scaleType="centerInside"
    android:duplicateParentState="true" />
    android:duplicateParentState="true"
    android:contentDescription="@null" />
+30 −38
Original line number Original line Diff line number Diff line
@@ -16,26 +16,19 @@


<com.android.internal.view.menu.ListMenuItemView xmlns:android="http://schemas.android.com/apk/res/android"
<com.android.internal.view.menu.ListMenuItemView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    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. -->
    <!-- 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
    <TextView
        android:id="@+id/title"
        android:id="@+id/title"
            android:layout_width="match_parent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
        android:layout_alignWithParentIfMissing="true"
            android:layout_alignParentStart="true"
        android:layout_marginStart="?android:attr/listPreferredItemPaddingStart"
        android:layout_marginEnd="?android:attr/listPreferredItemPaddingEnd"
        android:layout_toEndOf="@id/icon"
        android:textAppearance="?android:attr/textAppearanceListItemSmall"
        android:textAppearance="?android:attr/textAppearanceListItemSmall"
        android:singleLine="true"
        android:singleLine="true"
        android:duplicateParentState="true"
        android:duplicateParentState="true"
@@ -48,14 +41,13 @@
        android:layout_width="wrap_content"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/title"
        android:layout_below="@id/title"
            android:layout_alignParentStart="true"
        android:layout_alignStart="@id/title"
        android:layout_alignWithParentIfMissing="true"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:singleLine="true"
        android:singleLine="true"
        android:duplicateParentState="true"
        android:duplicateParentState="true"
        android:textAlignment="viewStart" />
        android:textAlignment="viewStart" />


    </RelativeLayout>

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


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