diff options
author | Alan Viverette <alanv@google.com> | 2013-07-15 16:43:58 -0700 |
---|---|---|
committer | Alan Viverette <alanv@google.com> | 2013-07-15 16:43:58 -0700 |
commit | d9ddf52c1281db14d9243ecef6c07bdeed1e6e34 (patch) | |
tree | 2bd74d842b0cc043ae2b8bb3a6f7c20dddb926e1 /core/java/com | |
parent | 06a884671fd966fbbed70638078f62da904595a5 (diff) | |
download | frameworks_base-d9ddf52c1281db14d9243ecef6c07bdeed1e6e34.zip frameworks_base-d9ddf52c1281db14d9243ecef6c07bdeed1e6e34.tar.gz frameworks_base-d9ddf52c1281db14d9243ecef6c07bdeed1e6e34.tar.bz2 |
Revert "Update ListMenuItemView to use a single RelativeLayout"
This reverts commit 8933efd49a0b2c10ddb30b23b57f5676634d0277.
BUG: 9774755
Change-Id: Ib6481e396092da81edd2c69f619f45f61e8fa393
Diffstat (limited to 'core/java/com')
-rw-r--r-- | core/java/com/android/internal/view/menu/ListMenuItemView.java | 147 |
1 files changed, 68 insertions, 79 deletions
diff --git a/core/java/com/android/internal/view/menu/ListMenuItemView.java b/core/java/com/android/internal/view/menu/ListMenuItemView.java index 35b76dd..df579c6 100644 --- a/core/java/com/android/internal/view/menu/ListMenuItemView.java +++ b/core/java/com/android/internal/view/menu/ListMenuItemView.java @@ -26,41 +26,48 @@ 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 RelativeLayout implements MenuView.ItemView { - private final Drawable mBackground; - private final int mTextAppearance; - - private MenuItemImpl mItemData; - +public class ListMenuItemView extends LinearLayout implements MenuView.ItemView { + private static final String TAG = "ListMenuItemView"; + private MenuItemImpl mItemData; + private ImageView mIconView; private RadioButton mRadioButton; private TextView mTitleView; 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); - - final TypedArray a = context.obtainStyledAttributes( + + 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, 0); + mTextAppearance = a.getResourceId(com.android.internal.R.styleable. + MenuView_itemTextAppearance, -1); mPreserveIconSpacing = a.getBoolean( com.android.internal.R.styleable.MenuView_preserveIconSpacing, false); - + mTextAppearanceContext = context; + a.recycle(); } @@ -71,22 +78,24 @@ public class ListMenuItemView extends RelativeLayout implements MenuView.ItemVie @Override protected void onFinishInflate() { super.onFinishInflate(); - - setBackground(mBackground); - + + setBackgroundDrawable(mBackground); + mTitleView = (TextView) findViewById(com.android.internal.R.id.title); - if (mTextAppearance != 0) { - mTitleView.setTextAppearance(mContext, mTextAppearance); + if (mTextAppearance != -1) { + mTitleView.setTextAppearance(mTextAppearanceContext, + 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()); @@ -98,36 +107,29 @@ public class ListMenuItemView extends RelativeLayout implements MenuView.ItemVie 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; } - + // Depending on whether its exclusive check or not, the checkbox or // radio button will be the one in use (and the other will be otherCompoundButton) final CompoundButton compoundButton; - final CompoundButton otherCompoundButton; + final CompoundButton otherCompoundButton; if (mItemData.isExclusiveCheckable()) { if (mRadioButton == null) { @@ -142,36 +144,28 @@ public class ListMenuItemView extends RelativeLayout implements MenuView.ItemVie compoundButton = mCheckBox; otherCompoundButton = mRadioButton; } - + if (checkable) { compoundButton.setChecked(mItemData.isChecked()); - + final int newVisibility = checkable ? VISIBLE : GONE; if (compoundButton.getVisibility() != 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 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; - + if (mItemData.isExclusiveCheckable()) { if (mRadioButton == null) { insertRadioButton(); @@ -183,13 +177,13 @@ public class ListMenuItemView extends RelativeLayout implements MenuView.ItemVie } compoundButton = mCheckBox; } - + 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()); @@ -199,22 +193,21 @@ public class ListMenuItemView extends RelativeLayout implements MenuView.ItemVie mShortcutView.setVisibility(newVisibility); } } - - @Override + public void setIcon(Drawable icon) { final boolean showIcon = mItemData.shouldShowIcon() || mForceShowIcon; if (!showIcon && !mPreserveIconSpacing) { return; } - + if (mIconView == null && icon == null && !mPreserveIconSpacing) { return; } - + if (mIconView == null) { insertIconView(); } - + if (icon != null || mPreserveIconSpacing) { mIconView.setImageDrawable(showIcon ? icon : null); @@ -225,55 +218,51 @@ public class ListMenuItemView extends RelativeLayout implements MenuView.ItemVie mIconView.setVisibility(GONE); } } - + @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (mIconView != null && mPreserveIconSpacing) { // Enforce minimum icon spacing - final ViewGroup.LayoutParams lp = getLayoutParams(); - final LayoutParams iconLp = (LayoutParams) mIconView.getLayoutParams(); + ViewGroup.LayoutParams lp = getLayoutParams(); + LayoutParams iconLp = (LayoutParams) mIconView.getLayoutParams(); if (lp.height > 0 && iconLp.width <= 0) { iconLp.width = lp.height; } } - super.onMeasure(widthMeasureSpec, heightMeasureSpec); } private void insertIconView() { - mIconView = (ImageView) getInflater() - .inflate(com.android.internal.R.layout.list_menu_item_icon, this, false); - addView(mIconView); + LayoutInflater inflater = getInflater(); + mIconView = (ImageView) inflater.inflate(com.android.internal.R.layout.list_menu_item_icon, + this, false); + addView(mIconView, 0); } - + private void insertRadioButton() { - mRadioButton = (RadioButton) getInflater() - .inflate(com.android.internal.R.layout.list_menu_item_radio, this, false); + LayoutInflater inflater = getInflater(); + mRadioButton = + (RadioButton) inflater.inflate(com.android.internal.R.layout.list_menu_item_radio, + this, false); addView(mRadioButton); } - + private void insertCheckBox() { - mCheckBox = (CheckBox) getInflater() - .inflate(com.android.internal.R.layout.list_menu_item_checkbox, this, false); + LayoutInflater inflater = getInflater(); + mCheckBox = + (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() { return false; } - @Override public boolean showsIcon() { return mForceShowIcon; } - + private LayoutInflater getInflater() { if (mInflater == null) { mInflater = LayoutInflater.from(mContext); |