189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell/*
289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell * Copyright (C) 2010 The Android Open Source Project
389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell *
489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell * Licensed under the Apache License, Version 2.0 (the "License");
589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell * you may not use this file except in compliance with the License.
689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell * You may obtain a copy of the License at
789e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell *
889e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell *      http://www.apache.org/licenses/LICENSE-2.0
989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell *
1089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell * Unless required by applicable law or agreed to in writing, software
1189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell * distributed under the License is distributed on an "AS IS" BASIS,
1289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell * See the License for the specific language governing permissions and
1489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell * limitations under the License.
1589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell */
1689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powellpackage com.android.internal.widget;
1789e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
189ca705e323cb737a07a667c1e86bac702f11a29cAdam Powellimport com.android.internal.R;
193d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette
20fa18d182a3f37505940e73ae6cd76c2e939f7f7cAdam Powellimport android.widget.ActionMenuPresenter;
21fa18d182a3f37505940e73ae6cd76c2e939f7f7cAdam Powellimport android.widget.ActionMenuView;
229ca705e323cb737a07a667c1e86bac702f11a29cAdam Powellimport com.android.internal.view.menu.MenuBuilder;
239ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell
2489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powellimport android.content.Context;
2589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powellimport android.content.res.TypedArray;
269ca705e323cb737a07a667c1e86bac702f11a29cAdam Powellimport android.graphics.drawable.Drawable;
27c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunneimport android.text.TextUtils;
2889e0645b4157961e8c465eb9c819f965fdb453d8Adam Powellimport android.util.AttributeSet;
296e34636749217654f43221885afb7a29bb5ca96aAdam Powellimport android.view.ActionMode;
3089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powellimport android.view.LayoutInflater;
3189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powellimport android.view.View;
329a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powellimport android.view.ViewGroup;
3386ed436b83d6b71ff00d1c3db910f2952018489eAdam Powellimport android.view.accessibility.AccessibilityEvent;
340e94b5151d817e600a888448a662208b29b5ef46Adam Powellimport android.widget.LinearLayout;
3589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powellimport android.widget.TextView;
3689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
3789e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell/**
3889e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell * @hide
3989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell */
4094283533aba1b8c895728feb40462250a1ebecceDoris Liupublic class ActionBarContextView extends AbsActionBarView {
4177769c7a9130afa48e46dbd79da8271c271ab1e9Adam Powell    private static final String TAG = "ActionBarContextView";
4277769c7a9130afa48e46dbd79da8271c271ab1e9Adam Powell
4389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    private CharSequence mTitle;
4489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    private CharSequence mSubtitle;
45f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell
46f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell    private View mClose;
4789e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    private View mCustomView;
480e94b5151d817e600a888448a662208b29b5ef46Adam Powell    private LinearLayout mTitleLayout;
4989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    private TextView mTitleView;
500e94b5151d817e600a888448a662208b29b5ef46Adam Powell    private TextView mSubtitleView;
51bc234a19f4c74116454e2c77f4739290e761995aAdam Powell    private int mTitleStyleRes;
52bc234a19f4c74116454e2c77f4739290e761995aAdam Powell    private int mSubtitleStyleRes;
539ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell    private Drawable mSplitBackground;
54b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell    private boolean mTitleOptional;
55b2536cf473a6fc386eea75ab8c97edf3a1ad323bAdam Powell    private int mCloseItemLayout;
56d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell
5789e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    public ActionBarContextView(Context context) {
58bc234a19f4c74116454e2c77f4739290e761995aAdam Powell        this(context, null);
5989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    }
6089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
6189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    public ActionBarContextView(Context context, AttributeSet attrs) {
62bc234a19f4c74116454e2c77f4739290e761995aAdam Powell        this(context, attrs, com.android.internal.R.attr.actionModeStyle);
6389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    }
6489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
65617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette    public ActionBarContextView(Context context, AttributeSet attrs, int defStyleAttr) {
66617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette        this(context, attrs, defStyleAttr, 0);
67617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette    }
68617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette
69617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette    public ActionBarContextView(
70617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette            Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
71617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette        super(context, attrs, defStyleAttr, defStyleRes);
72617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette
73617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette        final TypedArray a = context.obtainStyledAttributes(
74617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette                attrs, R.styleable.ActionMode, defStyleAttr, defStyleRes);
75e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell        setBackground(a.getDrawable(
76bc234a19f4c74116454e2c77f4739290e761995aAdam Powell                com.android.internal.R.styleable.ActionMode_background));
77bc234a19f4c74116454e2c77f4739290e761995aAdam Powell        mTitleStyleRes = a.getResourceId(
78bc234a19f4c74116454e2c77f4739290e761995aAdam Powell                com.android.internal.R.styleable.ActionMode_titleTextStyle, 0);
79bc234a19f4c74116454e2c77f4739290e761995aAdam Powell        mSubtitleStyleRes = a.getResourceId(
80bc234a19f4c74116454e2c77f4739290e761995aAdam Powell                com.android.internal.R.styleable.ActionMode_subtitleTextStyle, 0);
81dcdefbbff2bfecbfeb7b6459de130f376595c590Adam Powell
82e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell        mContentHeight = a.getLayoutDimension(
83bc234a19f4c74116454e2c77f4739290e761995aAdam Powell                com.android.internal.R.styleable.ActionMode_height, 0);
849ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell
859ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell        mSplitBackground = a.getDrawable(
869ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell                com.android.internal.R.styleable.ActionMode_backgroundSplit);
879ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell
88b2536cf473a6fc386eea75ab8c97edf3a1ad323bAdam Powell        mCloseItemLayout = a.getResourceId(
89b2536cf473a6fc386eea75ab8c97edf3a1ad323bAdam Powell                com.android.internal.R.styleable.ActionMode_closeItemLayout,
90b2536cf473a6fc386eea75ab8c97edf3a1ad323bAdam Powell                R.layout.action_mode_close_item);
91b2536cf473a6fc386eea75ab8c97edf3a1ad323bAdam Powell
9289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        a.recycle();
9389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    }
949146ac706265cd8cce66907e617bc8572152eb97Adam Powell
95a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell    @Override
9697e1836e1b07d91f18de9669c46b0c941b643a72Adam Powell    public void onDetachedFromWindow() {
9797e1836e1b07d91f18de9669c46b0c941b643a72Adam Powell        super.onDetachedFromWindow();
9897e1836e1b07d91f18de9669c46b0c941b643a72Adam Powell        if (mActionMenuPresenter != null) {
9997e1836e1b07d91f18de9669c46b0c941b643a72Adam Powell            mActionMenuPresenter.hideOverflowMenu();
10097e1836e1b07d91f18de9669c46b0c941b643a72Adam Powell            mActionMenuPresenter.hideSubMenus();
10197e1836e1b07d91f18de9669c46b0c941b643a72Adam Powell        }
10297e1836e1b07d91f18de9669c46b0c941b643a72Adam Powell    }
10397e1836e1b07d91f18de9669c46b0c941b643a72Adam Powell
10497e1836e1b07d91f18de9669c46b0c941b643a72Adam Powell    @Override
105e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell    public void setSplitToolbar(boolean split) {
106a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell        if (mSplitActionBar != split) {
107a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell            if (mActionMenuPresenter != null) {
108a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                // Mode is already active; move everything over and adjust the menu itself.
109a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
110a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                        LayoutParams.MATCH_PARENT);
111a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                if (!split) {
112a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
113b2536cf473a6fc386eea75ab8c97edf3a1ad323bAdam Powell                    mMenuView.setBackground(null);
114a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    final ViewGroup oldParent = (ViewGroup) mMenuView.getParent();
115a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    if (oldParent != null) oldParent.removeView(mMenuView);
116a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    addView(mMenuView, layoutParams);
117a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                } else {
118a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    // Allow full screen width in split mode.
119a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    mActionMenuPresenter.setWidthLimit(
120a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                            getContext().getResources().getDisplayMetrics().widthPixels, true);
121a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    // No limit to the item count; use whatever will fit.
122a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE);
123a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    // Span the whole width
124a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    layoutParams.width = LayoutParams.MATCH_PARENT;
125a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    layoutParams.height = mContentHeight;
126a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
127b2536cf473a6fc386eea75ab8c97edf3a1ad323bAdam Powell                    mMenuView.setBackground(mSplitBackground);
128a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    final ViewGroup oldParent = (ViewGroup) mMenuView.getParent();
129a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    if (oldParent != null) oldParent.removeView(mMenuView);
130a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    mSplitView.addView(mMenuView, layoutParams);
131a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                }
132a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell            }
133e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell            super.setSplitToolbar(split);
134a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell        }
135a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell    }
136a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell
137425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell    public void setContentHeight(int height) {
138e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell        mContentHeight = height;
139e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell    }
140e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell
14189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    public void setCustomView(View view) {
14289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        if (mCustomView != null) {
14389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell            removeView(mCustomView);
14489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        }
14589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        mCustomView = view;
146ed2a54cfd336bb935f281c04509ecd48c8cf116dClara Bayarri        if (view != null && mTitleLayout != null) {
1470e94b5151d817e600a888448a662208b29b5ef46Adam Powell            removeView(mTitleLayout);
1480e94b5151d817e600a888448a662208b29b5ef46Adam Powell            mTitleLayout = null;
14989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        }
15089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        if (view != null) {
15189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell            addView(view);
15289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        }
15389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        requestLayout();
15489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    }
1550e94b5151d817e600a888448a662208b29b5ef46Adam Powell
15689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    public void setTitle(CharSequence title) {
15789e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        mTitle = title;
1580e94b5151d817e600a888448a662208b29b5ef46Adam Powell        initTitle();
1590e94b5151d817e600a888448a662208b29b5ef46Adam Powell    }
1600e94b5151d817e600a888448a662208b29b5ef46Adam Powell
1610e94b5151d817e600a888448a662208b29b5ef46Adam Powell    public void setSubtitle(CharSequence subtitle) {
1620e94b5151d817e600a888448a662208b29b5ef46Adam Powell        mSubtitle = subtitle;
1630e94b5151d817e600a888448a662208b29b5ef46Adam Powell        initTitle();
1640e94b5151d817e600a888448a662208b29b5ef46Adam Powell    }
1650e94b5151d817e600a888448a662208b29b5ef46Adam Powell
16629ed7575c2129974a57ad77b3531bc5995940c6cAdam Powell    public CharSequence getTitle() {
16729ed7575c2129974a57ad77b3531bc5995940c6cAdam Powell        return mTitle;
16829ed7575c2129974a57ad77b3531bc5995940c6cAdam Powell    }
16929ed7575c2129974a57ad77b3531bc5995940c6cAdam Powell
17029ed7575c2129974a57ad77b3531bc5995940c6cAdam Powell    public CharSequence getSubtitle() {
17129ed7575c2129974a57ad77b3531bc5995940c6cAdam Powell        return mSubtitle;
17229ed7575c2129974a57ad77b3531bc5995940c6cAdam Powell    }
17329ed7575c2129974a57ad77b3531bc5995940c6cAdam Powell
1740e94b5151d817e600a888448a662208b29b5ef46Adam Powell    private void initTitle() {
1750e94b5151d817e600a888448a662208b29b5ef46Adam Powell        if (mTitleLayout == null) {
17689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell            LayoutInflater inflater = LayoutInflater.from(getContext());
177f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell            inflater.inflate(R.layout.action_bar_title_item, this);
178f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell            mTitleLayout = (LinearLayout) getChildAt(getChildCount() - 1);
1790e94b5151d817e600a888448a662208b29b5ef46Adam Powell            mTitleView = (TextView) mTitleLayout.findViewById(R.id.action_bar_title);
1800e94b5151d817e600a888448a662208b29b5ef46Adam Powell            mSubtitleView = (TextView) mTitleLayout.findViewById(R.id.action_bar_subtitle);
181c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne            if (mTitleStyleRes != 0) {
182bb98ebd6b15f4cf942b156892988801c95601f2fAlan Viverette                mTitleView.setTextAppearance(mTitleStyleRes);
18389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell            }
184c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne            if (mSubtitleStyleRes != 0) {
185bb98ebd6b15f4cf942b156892988801c95601f2fAlan Viverette                mSubtitleView.setTextAppearance(mSubtitleStyleRes);
18689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell            }
18789e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        }
188c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne
189c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne        mTitleView.setText(mTitle);
190c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne        mSubtitleView.setText(mSubtitle);
191c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne
192c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne        final boolean hasTitle = !TextUtils.isEmpty(mTitle);
193c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne        final boolean hasSubtitle = !TextUtils.isEmpty(mSubtitle);
194c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne        mSubtitleView.setVisibility(hasSubtitle ? VISIBLE : GONE);
195c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne        mTitleLayout.setVisibility(hasTitle || hasSubtitle ? VISIBLE : GONE);
196c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne        if (mTitleLayout.getParent() == null) {
197c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne            addView(mTitleLayout);
198c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne        }
19989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    }
2000e94b5151d817e600a888448a662208b29b5ef46Adam Powell
2016e34636749217654f43221885afb7a29bb5ca96aAdam Powell    public void initForMode(final ActionMode mode) {
202f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell        if (mClose == null) {
203f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell            LayoutInflater inflater = LayoutInflater.from(mContext);
204b2536cf473a6fc386eea75ab8c97edf3a1ad323bAdam Powell            mClose = inflater.inflate(mCloseItemLayout, this, false);
205d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell            addView(mClose);
20645f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell        } else if (mClose.getParent() == null) {
207f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell            addView(mClose);
20889e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        }
209f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell
210f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell        View closeButton = mClose.findViewById(R.id.action_mode_close_button);
211f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell        closeButton.setOnClickListener(new OnClickListener() {
212269b8bb0cbd78969450ea9ab255232d047580210Adam Powell            public void onClick(View v) {
213269b8bb0cbd78969450ea9ab255232d047580210Adam Powell                mode.finish();
214269b8bb0cbd78969450ea9ab255232d047580210Adam Powell            }
215269b8bb0cbd78969450ea9ab255232d047580210Adam Powell        });
21689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
2172c9c9fe806e51f29276e66b8ba40cb4b7a80c3f4Adam Powell        final MenuBuilder menu = (MenuBuilder) mode.getMenu();
218678ed0c5a32bac1ea18a5ac99b0b814421ea79b4Adam Powell        if (mActionMenuPresenter != null) {
219678ed0c5a32bac1ea18a5ac99b0b814421ea79b4Adam Powell            mActionMenuPresenter.dismissPopupMenus();
220678ed0c5a32bac1ea18a5ac99b0b814421ea79b4Adam Powell        }
221538e565c06e915b91e7e3a901f872ccdd9bccdd3Adam Powell        mActionMenuPresenter = new ActionMenuPresenter(mContext);
2221ab418a222e1834c4b1312fde355e41a1947af0dAdam Powell        mActionMenuPresenter.setReserveOverflow(true);
223640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
224640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
225640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell                LayoutParams.MATCH_PARENT);
226a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell        if (!mSplitActionBar) {
2273d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette            menu.addMenuPresenter(mActionMenuPresenter, mPopupContext);
2281ab418a222e1834c4b1312fde355e41a1947af0dAdam Powell            mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
229f6a36e9cf347a851bc3b717e4c39b484fce4e9c2Alan Viverette            mMenuView.setBackground(null);
2301ab418a222e1834c4b1312fde355e41a1947af0dAdam Powell            addView(mMenuView, layoutParams);
231640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        } else {
232640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            // Allow full screen width in split mode.
2338d02deabac62c4a68a335a7b3141795466362b89Adam Powell            mActionMenuPresenter.setWidthLimit(
234640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell                    getContext().getResources().getDisplayMetrics().widthPixels, true);
235640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            // No limit to the item count; use whatever will fit.
2368d02deabac62c4a68a335a7b3141795466362b89Adam Powell            mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE);
237640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            // Span the whole width
238640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            layoutParams.width = LayoutParams.MATCH_PARENT;
2391ab418a222e1834c4b1312fde355e41a1947af0dAdam Powell            layoutParams.height = mContentHeight;
2403d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette            menu.addMenuPresenter(mActionMenuPresenter, mPopupContext);
2411ab418a222e1834c4b1312fde355e41a1947af0dAdam Powell            mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
2429ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell            mMenuView.setBackgroundDrawable(mSplitBackground);
2431ab418a222e1834c4b1312fde355e41a1947af0dAdam Powell            mSplitView.addView(mMenuView, layoutParams);
244640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        }
24589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    }
2460e94b5151d817e600a888448a662208b29b5ef46Adam Powell
24789e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    public void closeMode() {
248d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell        if (mClose == null) {
249d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell            killMode();
250d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell            return;
251d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell        }
252d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell
253d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell    }
254d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell
255d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell    public void killMode() {
25689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        removeAllViews();
257640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        if (mSplitView != null) {
258640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            mSplitView.removeView(mMenuView);
259640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        }
26089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        mCustomView = null;
2612c9c9fe806e51f29276e66b8ba40cb4b7a80c3f4Adam Powell        mMenuView = null;
26289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    }
2630e94b5151d817e600a888448a662208b29b5ef46Adam Powell
264c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne    @Override
265f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell    public boolean showOverflowMenu() {
2668d02deabac62c4a68a335a7b3141795466362b89Adam Powell        if (mActionMenuPresenter != null) {
2678d02deabac62c4a68a335a7b3141795466362b89Adam Powell            return mActionMenuPresenter.showOverflowMenu();
268f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell        }
269f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell        return false;
270f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell    }
271f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell
272c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne    @Override
273f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell    public boolean hideOverflowMenu() {
2748d02deabac62c4a68a335a7b3141795466362b89Adam Powell        if (mActionMenuPresenter != null) {
2758d02deabac62c4a68a335a7b3141795466362b89Adam Powell            return mActionMenuPresenter.hideOverflowMenu();
276f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell        }
277f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell        return false;
278f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell    }
279f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell
280c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne    @Override
281f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell    public boolean isOverflowMenuShowing() {
2828d02deabac62c4a68a335a7b3141795466362b89Adam Powell        if (mActionMenuPresenter != null) {
2838d02deabac62c4a68a335a7b3141795466362b89Adam Powell            return mActionMenuPresenter.isOverflowMenuShowing();
284f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell        }
285f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell        return false;
286f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell    }
287f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell
28889e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    @Override
2899a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell    protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
290a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell        // Used by custom views if they don't supply layout params. Everything else
291a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell        // added to an ActionBarContextView should have them already.
2929ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell        return new MarginLayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
2939ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell    }
2949ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell
2959ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell    @Override
2969a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell    public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
2979ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell        return new MarginLayoutParams(getContext(), attrs);
298a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell    }
299a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell
300a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell    @Override
30189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
30289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
30389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        if (widthMode != MeasureSpec.EXACTLY) {
30489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell            throw new IllegalStateException(getClass().getSimpleName() + " can only be used " +
30589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell                    "with android:layout_width=\"match_parent\" (or fill_parent)");
30689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        }
30789e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
30889e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
30985446e95afa480cee2247bb96795fccc8cf812afAdam Powell        if (heightMode == MeasureSpec.UNSPECIFIED) {
31089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell            throw new IllegalStateException(getClass().getSimpleName() + " can only be used " +
31189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell                    "with android:layout_height=\"wrap_content\"");
31289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        }
31394283533aba1b8c895728feb40462250a1ebecceDoris Liu
31489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        final int contentWidth = MeasureSpec.getSize(widthMeasureSpec);
31589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
316e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell        int maxHeight = mContentHeight > 0 ?
317e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell                mContentHeight : MeasureSpec.getSize(heightMeasureSpec);
318e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell
319e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell        final int verticalPadding = getPaddingTop() + getPaddingBottom();
32089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        int availableWidth = contentWidth - getPaddingLeft() - getPaddingRight();
321e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell        final int height = maxHeight - verticalPadding;
32289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        final int childSpecHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST);
32394283533aba1b8c895728feb40462250a1ebecceDoris Liu
324f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell        if (mClose != null) {
325f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell            availableWidth = measureChildView(mClose, availableWidth, childSpecHeight, 0);
3269ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell            MarginLayoutParams lp = (MarginLayoutParams) mClose.getLayoutParams();
3279ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell            availableWidth -= lp.leftMargin + lp.rightMargin;
32889e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        }
32989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
330f6ce6a9bacbb220c6ea7b552c481237f23e64ae7Adam Powell        if (mMenuView != null && mMenuView.getParent() == this) {
331b0ff6f995553a5deb1f22e43e44715b316d33a88Adam Powell            availableWidth = measureChildView(mMenuView, availableWidth,
332b0ff6f995553a5deb1f22e43e44715b316d33a88Adam Powell                    childSpecHeight, 0);
33389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        }
33489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
335b0ff6f995553a5deb1f22e43e44715b316d33a88Adam Powell        if (mTitleLayout != null && mCustomView == null) {
336b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell            if (mTitleOptional) {
337d5dbf4b2a09c9cf2d17fa6af3fdf75d1fb774056Adam Powell                final int titleWidthSpec = MeasureSpec.makeSafeMeasureSpec(contentWidth,
338b6824bf58a0cd34395993fa204217e8e246de6fbFilip Gruszczynski                        MeasureSpec.UNSPECIFIED);
339b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell                mTitleLayout.measure(titleWidthSpec, childSpecHeight);
340b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell                final int titleWidth = mTitleLayout.getMeasuredWidth();
341b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell                final boolean titleFits = titleWidth <= availableWidth;
342b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell                if (titleFits) {
343b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell                    availableWidth -= titleWidth;
344b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell                }
345b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell                mTitleLayout.setVisibility(titleFits ? VISIBLE : GONE);
346b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell            } else {
347b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell                availableWidth = measureChildView(mTitleLayout, availableWidth, childSpecHeight, 0);
348b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell            }
34989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        }
35089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
35189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        if (mCustomView != null) {
3529a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell            ViewGroup.LayoutParams lp = mCustomView.getLayoutParams();
353a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell            final int customWidthMode = lp.width != LayoutParams.WRAP_CONTENT ?
354a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell                    MeasureSpec.EXACTLY : MeasureSpec.AT_MOST;
355a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell            final int customWidth = lp.width >= 0 ?
356a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell                    Math.min(lp.width, availableWidth) : availableWidth;
357a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell            final int customHeightMode = lp.height != LayoutParams.WRAP_CONTENT ?
358a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell                    MeasureSpec.EXACTLY : MeasureSpec.AT_MOST;
359a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell            final int customHeight = lp.height >= 0 ?
360a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell                    Math.min(lp.height, height) : height;
361a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell            mCustomView.measure(MeasureSpec.makeMeasureSpec(customWidth, customWidthMode),
362a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell                    MeasureSpec.makeMeasureSpec(customHeight, customHeightMode));
36389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        }
36489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
365e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell        if (mContentHeight <= 0) {
366e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell            int measuredHeight = 0;
367e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell            final int count = getChildCount();
368e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell            for (int i = 0; i < count; i++) {
369e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell                View v = getChildAt(i);
370e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell                int paddedViewHeight = v.getMeasuredHeight() + verticalPadding;
371e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell                if (paddedViewHeight > measuredHeight) {
372e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell                    measuredHeight = paddedViewHeight;
373e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell                }
374e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell            }
375e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell            setMeasuredDimension(contentWidth, measuredHeight);
376e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell        } else {
377e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell            setMeasuredDimension(contentWidth, maxHeight);
378e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell        }
37989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    }
38089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
38189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    @Override
38289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    protected void onLayout(boolean changed, int l, int t, int r, int b) {
383cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio        final boolean isLayoutRtl = isLayoutRtl();
384cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio        int x = isLayoutRtl ? r - l - getPaddingRight() : getPaddingLeft();
38589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        final int y = getPaddingTop();
38689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        final int contentHeight = b - t - getPaddingTop() - getPaddingBottom();
38794283533aba1b8c895728feb40462250a1ebecceDoris Liu
388f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell        if (mClose != null && mClose.getVisibility() != GONE) {
3899ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell            MarginLayoutParams lp = (MarginLayoutParams) mClose.getLayoutParams();
390cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio            final int startMargin = (isLayoutRtl ? lp.rightMargin : lp.leftMargin);
391cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio            final int endMargin = (isLayoutRtl ? lp.leftMargin : lp.rightMargin);
392cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio            x = next(x, startMargin, isLayoutRtl);
393cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio            x += positionChild(mClose, x, y, contentHeight, isLayoutRtl);
394cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio            x = next(x, endMargin, isLayoutRtl);
395d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell
39689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        }
397640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
398b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell        if (mTitleLayout != null && mCustomView == null && mTitleLayout.getVisibility() != GONE) {
399cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio            x += positionChild(mTitleLayout, x, y, contentHeight, isLayoutRtl);
40089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        }
40189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
40289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        if (mCustomView != null) {
403cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio            x += positionChild(mCustomView, x, y, contentHeight, isLayoutRtl);
40489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        }
405cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio
406cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio        x = isLayoutRtl ? getPaddingLeft() : r - l - getPaddingRight();
40789e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
4082c9c9fe806e51f29276e66b8ba40cb4b7a80c3f4Adam Powell        if (mMenuView != null) {
409cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio            x += positionChild(mMenuView, x, y, contentHeight, !isLayoutRtl);
41089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        }
41189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    }
41289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
413d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell    @Override
414e0a799a2ac1ca78e30fbac9e4e12a063425c08d3Patrick Dubroy    public boolean shouldDelayChildPressedState() {
415e0a799a2ac1ca78e30fbac9e4e12a063425c08d3Patrick Dubroy        return false;
416e0a799a2ac1ca78e30fbac9e4e12a063425c08d3Patrick Dubroy    }
41786ed436b83d6b71ff00d1c3db910f2952018489eAdam Powell
41886ed436b83d6b71ff00d1c3db910f2952018489eAdam Powell    @Override
419a54956a0bc611b1e9b3914edc7a604b59688f6b7Alan Viverette    public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
42086ed436b83d6b71ff00d1c3db910f2952018489eAdam Powell        if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
42186ed436b83d6b71ff00d1c3db910f2952018489eAdam Powell            // Action mode started
42286ed436b83d6b71ff00d1c3db910f2952018489eAdam Powell            event.setSource(this);
42386ed436b83d6b71ff00d1c3db910f2952018489eAdam Powell            event.setClassName(getClass().getName());
42486ed436b83d6b71ff00d1c3db910f2952018489eAdam Powell            event.setPackageName(getContext().getPackageName());
42586ed436b83d6b71ff00d1c3db910f2952018489eAdam Powell            event.setContentDescription(mTitle);
42686ed436b83d6b71ff00d1c3db910f2952018489eAdam Powell        } else {
427a54956a0bc611b1e9b3914edc7a604b59688f6b7Alan Viverette            super.onInitializeAccessibilityEventInternal(event);
42886ed436b83d6b71ff00d1c3db910f2952018489eAdam Powell        }
42986ed436b83d6b71ff00d1c3db910f2952018489eAdam Powell    }
430b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell
431b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell    public void setTitleOptional(boolean titleOptional) {
432b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell        if (titleOptional != mTitleOptional) {
433b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell            requestLayout();
434b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell        }
435b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell        mTitleOptional = titleOptional;
436b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell    }
437b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell
438b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell    public boolean isTitleOptional() {
439b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell        return mTitleOptional;
440b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell    }
44189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell}
442