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
1766698bb15ba0f873aa1c2290cc50d6bb839a474aChris Banespackage android.support.v7.view.menu;
18bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
198e10080c914d1ad0784394fa3026b85535535847Aurimas Liutikasimport static android.support.annotation.RestrictTo.Scope.LIBRARY_GROUP;
208e10080c914d1ad0784394fa3026b85535535847Aurimas Liutikas
21bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.content.Context;
22bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.graphics.drawable.Drawable;
23c39d9c75590eca86a5e7e32a8824ba04a0d42e9bAlan Viveretteimport android.support.annotation.RestrictTo;
2447082c30c630c34829439a9eecd1cf7e8d255a86Aurimas Liutikasimport android.support.v4.view.ViewCompat;
25da10fdd1400ecfd8d7f2e55651dd528d0614dfc5Jeff Brownimport android.support.v7.appcompat.R;
266142a54baae3289f734947c6b5375b12eb0fb722Chris Banesimport android.support.v7.widget.TintTypedArray;
27bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.util.AttributeSet;
28bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.view.LayoutInflater;
29bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.view.View;
30bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.view.ViewGroup;
31bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.widget.CheckBox;
32bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.widget.CompoundButton;
33bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.widget.ImageView;
34bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.widget.LinearLayout;
35bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.widget.RadioButton;
36bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.widget.TextView;
37bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
38bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell/**
39bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * The item view for each item in the ListView-based MenuViews.
4089208232f3b5d1451408d787872504a190bc7ee0Chris Banes *
4189208232f3b5d1451408d787872504a190bc7ee0Chris Banes * @hide
42bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell */
438e10080c914d1ad0784394fa3026b85535535847Aurimas Liutikas@RestrictTo(LIBRARY_GROUP)
44bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellpublic class ListMenuItemView extends LinearLayout implements MenuView.ItemView {
45ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    private static final String TAG = "ListMenuItemView";
46ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    private MenuItemImpl mItemData;
47bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
48ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    private ImageView mIconView;
49ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    private RadioButton mRadioButton;
50ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    private TextView mTitleView;
51ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    private CheckBox mCheckBox;
52ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    private TextView mShortcutView;
536142a54baae3289f734947c6b5375b12eb0fb722Chris Banes    private ImageView mSubMenuArrowView;
54bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
55ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    private Drawable mBackground;
56ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    private int mTextAppearance;
57ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    private Context mTextAppearanceContext;
58ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    private boolean mPreserveIconSpacing;
596142a54baae3289f734947c6b5375b12eb0fb722Chris Banes    private Drawable mSubMenuArrow;
60bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
61ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    private int mMenuType;
62bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
63ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    private LayoutInflater mInflater;
64bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
65ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    private boolean mForceShowIcon;
66bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
676142a54baae3289f734947c6b5375b12eb0fb722Chris Banes    public ListMenuItemView(Context context, AttributeSet attrs) {
686142a54baae3289f734947c6b5375b12eb0fb722Chris Banes        this(context, attrs, R.attr.listMenuViewStyle);
696142a54baae3289f734947c6b5375b12eb0fb722Chris Banes    }
706142a54baae3289f734947c6b5375b12eb0fb722Chris Banes
716142a54baae3289f734947c6b5375b12eb0fb722Chris Banes    public ListMenuItemView(Context context, AttributeSet attrs, int defStyleAttr) {
72ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        super(context, attrs);
73bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
746142a54baae3289f734947c6b5375b12eb0fb722Chris Banes        final TintTypedArray a = TintTypedArray.obtainStyledAttributes(getContext(),
756142a54baae3289f734947c6b5375b12eb0fb722Chris Banes                attrs, R.styleable.MenuView, defStyleAttr, 0);
76bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
778262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns        mBackground = a.getDrawable(R.styleable.MenuView_android_itemBackground);
78ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        mTextAppearance = a.getResourceId(R.styleable.
798262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns                MenuView_android_itemTextAppearance, -1);
80ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        mPreserveIconSpacing = a.getBoolean(
81692b70462703c0c0c9e6c5dec315a9aa783b5f55Chris Banes                R.styleable.MenuView_preserveIconSpacing, false);
82ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        mTextAppearanceContext = context;
836142a54baae3289f734947c6b5375b12eb0fb722Chris Banes        mSubMenuArrow = a.getDrawable(R.styleable.MenuView_subMenuArrow);
84bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
85ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        a.recycle();
86ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    }
87bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
88ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    @Override
89ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    protected void onFinishInflate() {
90ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        super.onFinishInflate();
91bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
9247082c30c630c34829439a9eecd1cf7e8d255a86Aurimas Liutikas        ViewCompat.setBackground(this, mBackground);
93bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
94fa2e2acf79d791a90410025daad438968550d18cAlan Viverette        mTitleView = findViewById(R.id.title);
95ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        if (mTextAppearance != -1) {
96ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            mTitleView.setTextAppearance(mTextAppearanceContext,
9720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                    mTextAppearance);
98ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        }
99bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
100fa2e2acf79d791a90410025daad438968550d18cAlan Viverette        mShortcutView = findViewById(R.id.shortcut);
101fa2e2acf79d791a90410025daad438968550d18cAlan Viverette        mSubMenuArrowView = findViewById(R.id.submenuarrow);
1026142a54baae3289f734947c6b5375b12eb0fb722Chris Banes        if (mSubMenuArrowView != null) {
1036142a54baae3289f734947c6b5375b12eb0fb722Chris Banes            mSubMenuArrowView.setImageDrawable(mSubMenuArrow);
1046142a54baae3289f734947c6b5375b12eb0fb722Chris Banes        }
105ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    }
106bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
107e2104f4b5c8e3ad63570306a25e61502dfe4c418Aurimas Liutikas    @Override
108ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    public void initialize(MenuItemImpl itemData, int menuType) {
109ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        mItemData = itemData;
110ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        mMenuType = menuType;
111bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
112ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        setVisibility(itemData.isVisible() ? View.VISIBLE : View.GONE);
113bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
114ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        setTitle(itemData.getTitleForItemView(this));
115ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        setCheckable(itemData.isCheckable());
116ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        setShortcut(itemData.shouldShowShortcut(), itemData.getShortcut());
117ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        setIcon(itemData.getIcon());
118ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        setEnabled(itemData.isEnabled());
1196142a54baae3289f734947c6b5375b12eb0fb722Chris Banes        setSubMenuArrowVisible(itemData.hasSubMenu());
120fd3c4560bf2348f6a06272a9f02105c9e1bf927eVladislav Kaznacheev        setContentDescription(itemData.getContentDescription());
121bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
122bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
123ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    public void setForceShowIcon(boolean forceShow) {
124ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        mPreserveIconSpacing = mForceShowIcon = forceShow;
125ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    }
126ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani
127e2104f4b5c8e3ad63570306a25e61502dfe4c418Aurimas Liutikas    @Override
128ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    public void setTitle(CharSequence title) {
129ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        if (title != null) {
130ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            mTitleView.setText(title);
131bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
13249c78900da0d43140fb602431fb93212bd7f6c70Chris Banes            if (mTitleView.getVisibility() != VISIBLE) mTitleView.setVisibility(VISIBLE);
133ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        } else {
13449c78900da0d43140fb602431fb93212bd7f6c70Chris Banes            if (mTitleView.getVisibility() != GONE) mTitleView.setVisibility(GONE);
135ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        }
136bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
137bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
138e2104f4b5c8e3ad63570306a25e61502dfe4c418Aurimas Liutikas    @Override
139ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    public MenuItemImpl getItemData() {
140ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        return mItemData;
141bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
142bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
143e2104f4b5c8e3ad63570306a25e61502dfe4c418Aurimas Liutikas    @Override
144ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    public void setCheckable(boolean checkable) {
145ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        if (!checkable && mRadioButton == null && mCheckBox == null) {
146ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            return;
147ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        }
148ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani
149ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        // Depending on whether its exclusive check or not, the checkbox or
150ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        // radio button will be the one in use (and the other will be otherCompoundButton)
151ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        final CompoundButton compoundButton;
152ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        final CompoundButton otherCompoundButton;
153ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani
154ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        if (mItemData.isExclusiveCheckable()) {
155ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            if (mRadioButton == null) {
156ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani                insertRadioButton();
157ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            }
158ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            compoundButton = mRadioButton;
159ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            otherCompoundButton = mCheckBox;
160ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        } else {
161ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            if (mCheckBox == null) {
162ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani                insertCheckBox();
163ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            }
164ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            compoundButton = mCheckBox;
165ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            otherCompoundButton = mRadioButton;
166ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        }
167ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani
168ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        if (checkable) {
169ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            compoundButton.setChecked(mItemData.isChecked());
170ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani
171ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            final int newVisibility = checkable ? VISIBLE : GONE;
172ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            if (compoundButton.getVisibility() != newVisibility) {
173ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani                compoundButton.setVisibility(newVisibility);
174ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            }
175ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani
176ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            // Make sure the other compound button isn't visible
177ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            if (otherCompoundButton != null && otherCompoundButton.getVisibility() != GONE) {
178ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani                otherCompoundButton.setVisibility(GONE);
179ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            }
180ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        } else {
18120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns            if (mCheckBox != null) {
18220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                mCheckBox.setVisibility(GONE);
18320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns            }
18420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns            if (mRadioButton != null) {
18520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                mRadioButton.setVisibility(GONE);
18620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns            }
187ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        }
188bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
189ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani
190e2104f4b5c8e3ad63570306a25e61502dfe4c418Aurimas Liutikas    @Override
191ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    public void setChecked(boolean checked) {
192ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        CompoundButton compoundButton;
193ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani
194ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        if (mItemData.isExclusiveCheckable()) {
195ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            if (mRadioButton == null) {
196ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani                insertRadioButton();
197ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            }
198ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            compoundButton = mRadioButton;
199ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        } else {
200ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            if (mCheckBox == null) {
201ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani                insertCheckBox();
202ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            }
203ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            compoundButton = mCheckBox;
204ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        }
205ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani
206ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        compoundButton.setChecked(checked);
207bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
208bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
2096142a54baae3289f734947c6b5375b12eb0fb722Chris Banes    private void setSubMenuArrowVisible(boolean hasSubmenu) {
2106142a54baae3289f734947c6b5375b12eb0fb722Chris Banes        if (mSubMenuArrowView != null) {
2116142a54baae3289f734947c6b5375b12eb0fb722Chris Banes            mSubMenuArrowView.setVisibility(hasSubmenu ? View.VISIBLE : View.GONE);
2126142a54baae3289f734947c6b5375b12eb0fb722Chris Banes        }
2136142a54baae3289f734947c6b5375b12eb0fb722Chris Banes    }
2146142a54baae3289f734947c6b5375b12eb0fb722Chris Banes
215e2104f4b5c8e3ad63570306a25e61502dfe4c418Aurimas Liutikas    @Override
216ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    public void setShortcut(boolean showShortcut, char shortcutKey) {
217ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        final int newVisibility = (showShortcut && mItemData.shouldShowShortcut())
21820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                ? VISIBLE : GONE;
219bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
220ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        if (newVisibility == VISIBLE) {
221ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            mShortcutView.setText(mItemData.getShortcutLabel());
222ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        }
223bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
224ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        if (mShortcutView.getVisibility() != newVisibility) {
225ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            mShortcutView.setVisibility(newVisibility);
226ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        }
227bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
228bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
229e2104f4b5c8e3ad63570306a25e61502dfe4c418Aurimas Liutikas    @Override
230ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    public void setIcon(Drawable icon) {
231ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        final boolean showIcon = mItemData.shouldShowIcon() || mForceShowIcon;
232ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        if (!showIcon && !mPreserveIconSpacing) {
233ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            return;
234ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        }
235ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani
236ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        if (mIconView == null && icon == null && !mPreserveIconSpacing) {
237ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            return;
238ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        }
239ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani
240ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        if (mIconView == null) {
241ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            insertIconView();
242ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        }
243ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani
244ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        if (icon != null || mPreserveIconSpacing) {
245ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            mIconView.setImageDrawable(showIcon ? icon : null);
246ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani
247ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            if (mIconView.getVisibility() != VISIBLE) {
248ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani                mIconView.setVisibility(VISIBLE);
249ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            }
250ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        } else {
251ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            mIconView.setVisibility(GONE);
252ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        }
253bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
254bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
255ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    @Override
256ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
257ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        if (mIconView != null && mPreserveIconSpacing) {
258ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            // Enforce minimum icon spacing
259ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            ViewGroup.LayoutParams lp = getLayoutParams();
260ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            LayoutParams iconLp = (LayoutParams) mIconView.getLayoutParams();
261ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            if (lp.height > 0 && iconLp.width <= 0) {
262ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani                iconLp.width = lp.height;
263ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani            }
264ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        }
265ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
266bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
267bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
268ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    private void insertIconView() {
269ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        LayoutInflater inflater = getInflater();
270ee7c9fb199e9b9af8d40a1f9e27d85465acf8301Chris Banes        mIconView = (ImageView) inflater.inflate(R.layout.abc_list_menu_item_icon,
27120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                this, false);
272ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        addView(mIconView, 0);
273bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
274bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
275ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    private void insertRadioButton() {
276ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        LayoutInflater inflater = getInflater();
277ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        mRadioButton =
278ee7c9fb199e9b9af8d40a1f9e27d85465acf8301Chris Banes                (RadioButton) inflater.inflate(R.layout.abc_list_menu_item_radio,
27920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                        this, false);
280ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        addView(mRadioButton);
281bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
282bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
283ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    private void insertCheckBox() {
284ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        LayoutInflater inflater = getInflater();
285ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        mCheckBox =
286ee7c9fb199e9b9af8d40a1f9e27d85465acf8301Chris Banes                (CheckBox) inflater.inflate(R.layout.abc_list_menu_item_checkbox,
28720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                        this, false);
288ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        addView(mCheckBox);
289bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
290bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
291e2104f4b5c8e3ad63570306a25e61502dfe4c418Aurimas Liutikas    @Override
292ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    public boolean prefersCondensedTitle() {
293ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        return false;
294ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    }
295bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
296e2104f4b5c8e3ad63570306a25e61502dfe4c418Aurimas Liutikas    @Override
297ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    public boolean showsIcon() {
298ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        return mForceShowIcon;
299ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    }
300bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
301ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    private LayoutInflater getInflater() {
302ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        if (mInflater == null) {
3036142a54baae3289f734947c6b5375b12eb0fb722Chris Banes            mInflater = LayoutInflater.from(getContext());
304ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        }
305ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani        return mInflater;
306bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
307bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell}
308ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani
309