1bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell/* 2bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * Copyright (C) 2006 The Android Open Source Project 3bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * 4bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * Licensed under the Apache License, Version 2.0 (the "License"); 5bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * you may not use this file except in compliance with the License. 6bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * You may obtain a copy of the License at 7bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * 8bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * http://www.apache.org/licenses/LICENSE-2.0 9bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * 10bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * Unless required by applicable law or agreed to in writing, software 11bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * distributed under the License is distributed on an "AS IS" BASIS, 12bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * See the License for the specific language governing permissions and 14bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * limitations under the License. 15bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell */ 16bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 17da10fdd1400ecfd8d7f2e55651dd528d0614dfc5Jeff Brownpackage android.support.v7.internal.view.menu; 18bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 19bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.content.Context; 20bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.content.res.TypedArray; 21bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.graphics.drawable.Drawable; 22da10fdd1400ecfd8d7f2e55651dd528d0614dfc5Jeff Brownimport android.support.v7.appcompat.R; 23bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.util.AttributeSet; 24bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.view.LayoutInflater; 25bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.view.View; 26bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.view.ViewGroup; 27bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.widget.CheckBox; 28bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.widget.CompoundButton; 29bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.widget.ImageView; 30bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.widget.LinearLayout; 31bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.widget.RadioButton; 32bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.widget.TextView; 33bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 34bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell/** 35bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * The item view for each item in the ListView-based MenuViews. 3689208232f3b5d1451408d787872504a190bc7ee0Chris Banes * 3789208232f3b5d1451408d787872504a190bc7ee0Chris Banes * @hide 38bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell */ 39bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellpublic class ListMenuItemView extends LinearLayout implements MenuView.ItemView { 4020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns 41ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private static final String TAG = "ListMenuItemView"; 42ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private MenuItemImpl mItemData; 43bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 44ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private ImageView mIconView; 45ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private RadioButton mRadioButton; 46ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private TextView mTitleView; 47ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private CheckBox mCheckBox; 48ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private TextView mShortcutView; 49bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 50ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private Drawable mBackground; 51ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private int mTextAppearance; 52ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private Context mTextAppearanceContext; 53ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private boolean mPreserveIconSpacing; 54bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 55ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private int mMenuType; 56bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 57ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private Context mContext; 58ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private LayoutInflater mInflater; 59bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 60ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private boolean mForceShowIcon; 61bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 62ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public ListMenuItemView(Context context, AttributeSet attrs, int defStyle) { 63ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani super(context, attrs); 64ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mContext = context; 65bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 66ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani TypedArray a = 6720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns context.obtainStyledAttributes( 6820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns attrs, R.styleable.MenuView, defStyle, 0); 69bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 708262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns mBackground = a.getDrawable(R.styleable.MenuView_android_itemBackground); 71ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mTextAppearance = a.getResourceId(R.styleable. 728262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns MenuView_android_itemTextAppearance, -1); 73ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mPreserveIconSpacing = a.getBoolean( 748262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns R.styleable.MenuView_android_preserveIconSpacing, false); 75ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mTextAppearanceContext = context; 76bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 77ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani a.recycle(); 78ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 79bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 80ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public ListMenuItemView(Context context, AttributeSet attrs) { 81ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani this(context, attrs, 0); 82bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 83bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 84ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani @Override 85ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani protected void onFinishInflate() { 86ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani super.onFinishInflate(); 87bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 88ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani setBackgroundDrawable(mBackground); 89bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 90ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mTitleView = (TextView) findViewById(R.id.title); 91ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mTextAppearance != -1) { 92ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mTitleView.setTextAppearance(mTextAppearanceContext, 9320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns mTextAppearance); 94ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 95bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 96ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mShortcutView = (TextView) findViewById(R.id.shortcut); 97ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 98bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 99ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public void initialize(MenuItemImpl itemData, int menuType) { 100ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mItemData = itemData; 101ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mMenuType = menuType; 102bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 103ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani setVisibility(itemData.isVisible() ? View.VISIBLE : View.GONE); 104bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 105ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani setTitle(itemData.getTitleForItemView(this)); 106ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani setCheckable(itemData.isCheckable()); 107ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani setShortcut(itemData.shouldShowShortcut(), itemData.getShortcut()); 108ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani setIcon(itemData.getIcon()); 109ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani setEnabled(itemData.isEnabled()); 110bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 111bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 112ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public void setForceShowIcon(boolean forceShow) { 113ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mPreserveIconSpacing = mForceShowIcon = forceShow; 114ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 115ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 116ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public void setTitle(CharSequence title) { 117ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (title != null) { 118ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mTitleView.setText(title); 119bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 12020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns if (mTitleView.getVisibility() != VISIBLE) { 12120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns mTitleView.setVisibility(VISIBLE); 12220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 123ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } else { 12420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns if (mTitleView.getVisibility() != GONE) { 12520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns mTitleView.setVisibility(GONE); 12620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 127ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 128bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 129bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 130ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public MenuItemImpl getItemData() { 131ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return mItemData; 132bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 133bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 134ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public void setCheckable(boolean checkable) { 135ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (!checkable && mRadioButton == null && mCheckBox == null) { 136ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return; 137ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 138ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 139ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani // Depending on whether its exclusive check or not, the checkbox or 140ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani // radio button will be the one in use (and the other will be otherCompoundButton) 141ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani final CompoundButton compoundButton; 142ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani final CompoundButton otherCompoundButton; 143ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 144ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mItemData.isExclusiveCheckable()) { 145ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mRadioButton == null) { 146ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani insertRadioButton(); 147ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 148ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani compoundButton = mRadioButton; 149ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani otherCompoundButton = mCheckBox; 150ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } else { 151ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mCheckBox == null) { 152ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani insertCheckBox(); 153ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 154ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani compoundButton = mCheckBox; 155ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani otherCompoundButton = mRadioButton; 156ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 157ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 158ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (checkable) { 159ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani compoundButton.setChecked(mItemData.isChecked()); 160ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 161ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani final int newVisibility = checkable ? VISIBLE : GONE; 162ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (compoundButton.getVisibility() != newVisibility) { 163ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani compoundButton.setVisibility(newVisibility); 164ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 165ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 166ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani // Make sure the other compound button isn't visible 167ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (otherCompoundButton != null && otherCompoundButton.getVisibility() != GONE) { 168ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani otherCompoundButton.setVisibility(GONE); 169ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 170ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } else { 17120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns if (mCheckBox != null) { 17220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns mCheckBox.setVisibility(GONE); 17320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 17420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns if (mRadioButton != null) { 17520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns mRadioButton.setVisibility(GONE); 17620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 177ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 178bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 179ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 180ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public void setChecked(boolean checked) { 181ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani CompoundButton compoundButton; 182ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 183ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mItemData.isExclusiveCheckable()) { 184ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mRadioButton == null) { 185ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani insertRadioButton(); 186ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 187ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani compoundButton = mRadioButton; 188ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } else { 189ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mCheckBox == null) { 190ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani insertCheckBox(); 191ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 192ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani compoundButton = mCheckBox; 193ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 194ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 195ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani compoundButton.setChecked(checked); 196bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 197bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 198ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public void setShortcut(boolean showShortcut, char shortcutKey) { 199ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani final int newVisibility = (showShortcut && mItemData.shouldShowShortcut()) 20020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns ? VISIBLE : GONE; 201bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 202ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (newVisibility == VISIBLE) { 203ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mShortcutView.setText(mItemData.getShortcutLabel()); 204ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 205bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 206ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mShortcutView.getVisibility() != newVisibility) { 207ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mShortcutView.setVisibility(newVisibility); 208ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 209bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 210bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 211ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public void setIcon(Drawable icon) { 212ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani final boolean showIcon = mItemData.shouldShowIcon() || mForceShowIcon; 213ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (!showIcon && !mPreserveIconSpacing) { 214ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return; 215ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 216ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 217ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mIconView == null && icon == null && !mPreserveIconSpacing) { 218ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return; 219ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 220ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 221ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mIconView == null) { 222ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani insertIconView(); 223ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 224ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 225ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (icon != null || mPreserveIconSpacing) { 226ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mIconView.setImageDrawable(showIcon ? icon : null); 227ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 228ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mIconView.getVisibility() != VISIBLE) { 229ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mIconView.setVisibility(VISIBLE); 230ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 231ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } else { 232ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mIconView.setVisibility(GONE); 233ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 234bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 235bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 236ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani @Override 237ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 238ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mIconView != null && mPreserveIconSpacing) { 239ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani // Enforce minimum icon spacing 240ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani ViewGroup.LayoutParams lp = getLayoutParams(); 241ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani LayoutParams iconLp = (LayoutParams) mIconView.getLayoutParams(); 242ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (lp.height > 0 && iconLp.width <= 0) { 243ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani iconLp.width = lp.height; 244ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 245ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 246ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani super.onMeasure(widthMeasureSpec, heightMeasureSpec); 247bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 248bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 249ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private void insertIconView() { 250ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani LayoutInflater inflater = getInflater(); 251ee7c9fb199e9b9af8d40a1f9e27d85465acf8301Chris Banes mIconView = (ImageView) inflater.inflate(R.layout.abc_list_menu_item_icon, 25220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns this, false); 253ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani addView(mIconView, 0); 254bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 255bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 256ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private void insertRadioButton() { 257ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani LayoutInflater inflater = getInflater(); 258ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mRadioButton = 259ee7c9fb199e9b9af8d40a1f9e27d85465acf8301Chris Banes (RadioButton) inflater.inflate(R.layout.abc_list_menu_item_radio, 26020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns this, false); 261ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani addView(mRadioButton); 262bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 263bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 264ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private void insertCheckBox() { 265ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani LayoutInflater inflater = getInflater(); 266ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mCheckBox = 267ee7c9fb199e9b9af8d40a1f9e27d85465acf8301Chris Banes (CheckBox) inflater.inflate(R.layout.abc_list_menu_item_checkbox, 26820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns this, false); 269ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani addView(mCheckBox); 270bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 271bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 272ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public boolean prefersCondensedTitle() { 273ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return false; 274ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 275bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 276ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public boolean showsIcon() { 277ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return mForceShowIcon; 278ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 279bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 280ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private LayoutInflater getInflater() { 281ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mInflater == null) { 282ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mInflater = LayoutInflater.from(mContext); 283ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 284ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return mInflater; 285bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 286bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell} 287ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 288