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 6649c78900da0d43140fb602431fb93212bd7f6c70Chris Banes final TypedArray a = context.obtainStyledAttributes( 6749c78900da0d43140fb602431fb93212bd7f6c70Chris Banes attrs, R.styleable.MenuView, defStyle, 0); 68bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 698262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns mBackground = a.getDrawable(R.styleable.MenuView_android_itemBackground); 70ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mTextAppearance = a.getResourceId(R.styleable. 718262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns MenuView_android_itemTextAppearance, -1); 72ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mPreserveIconSpacing = a.getBoolean( 73692b70462703c0c0c9e6c5dec315a9aa783b5f55Chris Banes R.styleable.MenuView_preserveIconSpacing, false); 74ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mTextAppearanceContext = context; 75bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 76ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani a.recycle(); 77ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 78bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 79ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public ListMenuItemView(Context context, AttributeSet attrs) { 80ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani this(context, attrs, 0); 81bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 82bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 83ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani @Override 84ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani protected void onFinishInflate() { 85ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani super.onFinishInflate(); 86bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 87ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani setBackgroundDrawable(mBackground); 88bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 89ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mTitleView = (TextView) findViewById(R.id.title); 90ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mTextAppearance != -1) { 91ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mTitleView.setTextAppearance(mTextAppearanceContext, 9220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns mTextAppearance); 93ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 94bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 95ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mShortcutView = (TextView) findViewById(R.id.shortcut); 96ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 97bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 98ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public void initialize(MenuItemImpl itemData, int menuType) { 99ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mItemData = itemData; 100ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mMenuType = menuType; 101bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 102ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani setVisibility(itemData.isVisible() ? View.VISIBLE : View.GONE); 103bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 104ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani setTitle(itemData.getTitleForItemView(this)); 105ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani setCheckable(itemData.isCheckable()); 106ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani setShortcut(itemData.shouldShowShortcut(), itemData.getShortcut()); 107ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani setIcon(itemData.getIcon()); 108ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani setEnabled(itemData.isEnabled()); 109bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 110bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 111ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public void setForceShowIcon(boolean forceShow) { 112ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mPreserveIconSpacing = mForceShowIcon = forceShow; 113ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 114ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 115ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public void setTitle(CharSequence title) { 116ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (title != null) { 117ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mTitleView.setText(title); 118bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 11949c78900da0d43140fb602431fb93212bd7f6c70Chris Banes if (mTitleView.getVisibility() != VISIBLE) mTitleView.setVisibility(VISIBLE); 120ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } else { 12149c78900da0d43140fb602431fb93212bd7f6c70Chris Banes if (mTitleView.getVisibility() != GONE) mTitleView.setVisibility(GONE); 122ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 123bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 124bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 125ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public MenuItemImpl getItemData() { 126ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return mItemData; 127bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 128bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 129ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public void setCheckable(boolean checkable) { 130ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (!checkable && mRadioButton == null && mCheckBox == null) { 131ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return; 132ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 133ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 134ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani // Depending on whether its exclusive check or not, the checkbox or 135ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani // radio button will be the one in use (and the other will be otherCompoundButton) 136ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani final CompoundButton compoundButton; 137ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani final CompoundButton otherCompoundButton; 138ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 139ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mItemData.isExclusiveCheckable()) { 140ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mRadioButton == null) { 141ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani insertRadioButton(); 142ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 143ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani compoundButton = mRadioButton; 144ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani otherCompoundButton = mCheckBox; 145ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } else { 146ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mCheckBox == null) { 147ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani insertCheckBox(); 148ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 149ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani compoundButton = mCheckBox; 150ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani otherCompoundButton = mRadioButton; 151ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 152ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 153ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (checkable) { 154ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani compoundButton.setChecked(mItemData.isChecked()); 155ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 156ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani final int newVisibility = checkable ? VISIBLE : GONE; 157ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (compoundButton.getVisibility() != newVisibility) { 158ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani compoundButton.setVisibility(newVisibility); 159ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 160ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 161ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani // Make sure the other compound button isn't visible 162ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (otherCompoundButton != null && otherCompoundButton.getVisibility() != GONE) { 163ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani otherCompoundButton.setVisibility(GONE); 164ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 165ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } else { 16620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns if (mCheckBox != null) { 16720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns mCheckBox.setVisibility(GONE); 16820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 16920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns if (mRadioButton != null) { 17020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns mRadioButton.setVisibility(GONE); 17120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 172ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 173bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 174ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 175ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public void setChecked(boolean checked) { 176ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani CompoundButton compoundButton; 177ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 178ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mItemData.isExclusiveCheckable()) { 179ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mRadioButton == null) { 180ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani insertRadioButton(); 181ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 182ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani compoundButton = mRadioButton; 183ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } else { 184ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mCheckBox == null) { 185ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani insertCheckBox(); 186ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 187ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani compoundButton = mCheckBox; 188ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 189ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 190ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani compoundButton.setChecked(checked); 191bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 192bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 193ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public void setShortcut(boolean showShortcut, char shortcutKey) { 194ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani final int newVisibility = (showShortcut && mItemData.shouldShowShortcut()) 19520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns ? VISIBLE : GONE; 196bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 197ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (newVisibility == VISIBLE) { 198ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mShortcutView.setText(mItemData.getShortcutLabel()); 199ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 200bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 201ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mShortcutView.getVisibility() != newVisibility) { 202ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mShortcutView.setVisibility(newVisibility); 203ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 204bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 205bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 206ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public void setIcon(Drawable icon) { 207ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani final boolean showIcon = mItemData.shouldShowIcon() || mForceShowIcon; 208ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (!showIcon && !mPreserveIconSpacing) { 209ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return; 210ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 211ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 212ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mIconView == null && icon == null && !mPreserveIconSpacing) { 213ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return; 214ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 215ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 216ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mIconView == null) { 217ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani insertIconView(); 218ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 219ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 220ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (icon != null || mPreserveIconSpacing) { 221ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mIconView.setImageDrawable(showIcon ? icon : null); 222ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 223ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mIconView.getVisibility() != VISIBLE) { 224ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mIconView.setVisibility(VISIBLE); 225ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 226ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } else { 227ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mIconView.setVisibility(GONE); 228ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 229bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 230bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 231ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani @Override 232ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 233ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mIconView != null && mPreserveIconSpacing) { 234ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani // Enforce minimum icon spacing 235ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani ViewGroup.LayoutParams lp = getLayoutParams(); 236ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani LayoutParams iconLp = (LayoutParams) mIconView.getLayoutParams(); 237ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (lp.height > 0 && iconLp.width <= 0) { 238ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani iconLp.width = lp.height; 239ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 240ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 241ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani super.onMeasure(widthMeasureSpec, heightMeasureSpec); 242bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 243bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 244ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private void insertIconView() { 245ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani LayoutInflater inflater = getInflater(); 246ee7c9fb199e9b9af8d40a1f9e27d85465acf8301Chris Banes mIconView = (ImageView) inflater.inflate(R.layout.abc_list_menu_item_icon, 24720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns this, false); 248ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani addView(mIconView, 0); 249bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 250bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 251ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private void insertRadioButton() { 252ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani LayoutInflater inflater = getInflater(); 253ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mRadioButton = 254ee7c9fb199e9b9af8d40a1f9e27d85465acf8301Chris Banes (RadioButton) inflater.inflate(R.layout.abc_list_menu_item_radio, 25520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns this, false); 256ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani addView(mRadioButton); 257bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 258bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 259ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private void insertCheckBox() { 260ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani LayoutInflater inflater = getInflater(); 261ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mCheckBox = 262ee7c9fb199e9b9af8d40a1f9e27d85465acf8301Chris Banes (CheckBox) inflater.inflate(R.layout.abc_list_menu_item_checkbox, 26320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns this, false); 264ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani addView(mCheckBox); 265bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 266bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 267ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public boolean prefersCondensedTitle() { 268ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return false; 269ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 270bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 271ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani public boolean showsIcon() { 272ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return mForceShowIcon; 273ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 274bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 275ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani private LayoutInflater getInflater() { 276ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani if (mInflater == null) { 277ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani mInflater = LayoutInflater.from(mContext); 278ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani } 279ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani return mInflater; 280bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 281bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell} 282ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani 283