1bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell/*
2bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * Copyright (C) 2010 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.widget;
18bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
19bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.app.Activity;
20bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.content.Context;
21bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.content.pm.ApplicationInfo;
22bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.content.pm.PackageManager;
23bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.content.pm.PackageManager.NameNotFoundException;
24bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.content.res.Configuration;
25bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.content.res.TypedArray;
26bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.graphics.drawable.Drawable;
272334427b64cc2562c6d8fe47f1bdbc3c2dab187eTrevor Johnsimport android.os.Build;
28bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.os.Parcel;
29bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.os.Parcelable;
30da10fdd1400ecfd8d7f2e55651dd528d0614dfc5Jeff Brownimport android.support.v7.app.ActionBar;
31da10fdd1400ecfd8d7f2e55651dd528d0614dfc5Jeff Brownimport android.support.v7.app.ActionBar.OnNavigationListener;
32da10fdd1400ecfd8d7f2e55651dd528d0614dfc5Jeff Brownimport android.support.v7.appcompat.R;
332e21b5e22c320fd7e6af86a7cc05b4b11d7a0f64Chris Banesimport android.support.v7.view.CollapsibleActionView;
34da10fdd1400ecfd8d7f2e55651dd528d0614dfc5Jeff Brownimport android.support.v7.internal.view.menu.ActionMenuItem;
35da10fdd1400ecfd8d7f2e55651dd528d0614dfc5Jeff Brownimport android.support.v7.internal.view.menu.ActionMenuPresenter;
36da10fdd1400ecfd8d7f2e55651dd528d0614dfc5Jeff Brownimport android.support.v7.internal.view.menu.ActionMenuView;
37da10fdd1400ecfd8d7f2e55651dd528d0614dfc5Jeff Brownimport android.support.v7.internal.view.menu.MenuBuilder;
38da10fdd1400ecfd8d7f2e55651dd528d0614dfc5Jeff Brownimport android.support.v7.internal.view.menu.MenuItemImpl;
39da10fdd1400ecfd8d7f2e55651dd528d0614dfc5Jeff Brownimport android.support.v7.internal.view.menu.MenuPresenter;
40da10fdd1400ecfd8d7f2e55651dd528d0614dfc5Jeff Brownimport android.support.v7.internal.view.menu.MenuView;
41da10fdd1400ecfd8d7f2e55651dd528d0614dfc5Jeff Brownimport android.support.v7.internal.view.menu.SubMenuBuilder;
4230837f1095c803f332f4a1c3f0917c8afdd50156Adam Powellimport android.support.v4.internal.view.SupportMenu;
4330837f1095c803f332f4a1c3f0917c8afdd50156Adam Powellimport android.support.v4.internal.view.SupportMenuItem;
44bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.text.TextUtils;
45bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.util.AttributeSet;
46bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.util.Log;
47bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.view.Gravity;
48bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.view.LayoutInflater;
49bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.view.View;
50bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.view.ViewGroup;
51bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.view.ViewParent;
52bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.view.Window;
53bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.view.accessibility.AccessibilityEvent;
54bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.widget.FrameLayout;
55bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.widget.ImageView;
56bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.widget.LinearLayout;
57bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.widget.SpinnerAdapter;
58bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.widget.TextView;
59bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
60bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell/**
61bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * @hide
62bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell */
632334427b64cc2562c6d8fe47f1bdbc3c2dab187eTrevor Johnspublic class ActionBarView extends AbsActionBarView {
6420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns
65bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private static final String TAG = "ActionBarView";
66bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
67bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    /**
68bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell     * Display options applied by default
69bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell     */
70bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public static final int DISPLAY_DEFAULT = 0;
71bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
72bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    /**
73bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell     * Display options that require re-layout as opposed to a simple invalidate
74bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell     */
75bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private static final int DISPLAY_RELAYOUT_MASK =
76bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            ActionBar.DISPLAY_SHOW_HOME |
7720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                    ActionBar.DISPLAY_USE_LOGO |
7820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                    ActionBar.DISPLAY_HOME_AS_UP |
7920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                    ActionBar.DISPLAY_SHOW_CUSTOM |
8020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                    ActionBar.DISPLAY_SHOW_TITLE;
81bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
82bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private static final int DEFAULT_CUSTOM_GRAVITY = Gravity.LEFT | Gravity.CENTER_VERTICAL;
8320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns
84bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private int mNavigationMode;
85bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private int mDisplayOptions = -1;
86bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private CharSequence mTitle;
87bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private CharSequence mSubtitle;
88bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private Drawable mIcon;
89bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private Drawable mLogo;
90bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
91bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private Context mContext;
92bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private HomeView mHomeLayout;
93bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private HomeView mExpandedHomeLayout;
94bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private LinearLayout mTitleLayout;
95bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private TextView mTitleView;
96bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private TextView mSubtitleView;
97bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private View mTitleUpView;
98bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
9979e7a9ef79920c7daa10c90339db126a4c3c592eChris Banes    private SpinnerICS mSpinner;
100bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private LinearLayout mListNavLayout;
101bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private ScrollingTabContainerView mTabScrollView;
102bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private View mCustomNavView;
103ed34e2dffd0ce7da89063d06fd3b25687ca367a2Chris Banes    private ProgressBarICS mProgressView;
104ed34e2dffd0ce7da89063d06fd3b25687ca367a2Chris Banes    private ProgressBarICS mIndeterminateProgressView;
105bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
106bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private int mProgressBarPadding;
107bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private int mItemPadding;
108ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani
109bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private int mTitleStyleRes;
110bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private int mSubtitleStyleRes;
111bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private int mProgressStyle;
112bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private int mIndeterminateProgressStyle;
113bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
114bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private boolean mUserTitle;
115bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private boolean mIncludeTabs;
116bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private boolean mIsCollapsable;
117bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private boolean mIsCollapsed;
118bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
119ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani    private MenuBuilder mOptionsMenu;
120ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani
121bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private ActionBarContextView mContextView;
122bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
123bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private ActionMenuItem mLogoNavItem;
124bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
125bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private SpinnerAdapter mSpinnerAdapter;
126bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private OnNavigationListener mCallback;
127bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
128bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private Runnable mTabSelector;
129bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
130bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private ExpandedActionViewMenuPresenter mExpandedMenuPresenter;
131bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    View mExpandedActionView;
132bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
13330837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell    Window.Callback mWindowCallback;
134bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
13579e7a9ef79920c7daa10c90339db126a4c3c592eChris Banes    private final AdapterViewICS.OnItemSelectedListener mNavItemSelectedListener =
13679e7a9ef79920c7daa10c90339db126a4c3c592eChris Banes            new AdapterViewICS.OnItemSelectedListener() {
13779e7a9ef79920c7daa10c90339db126a4c3c592eChris Banes                public void onItemSelected(AdapterViewICS<?> parent, View view, int position,
13879e7a9ef79920c7daa10c90339db126a4c3c592eChris Banes                        long id) {
13920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                    if (mCallback != null) {
14020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                        mCallback.onNavigationItemSelected(position, id);
14120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                    }
14220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                }
14320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns
14479e7a9ef79920c7daa10c90339db126a4c3c592eChris Banes                public void onNothingSelected(AdapterViewICS<?> parent) {
14520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                    // Do nothing
14620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                }
14720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns            };
148bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
149bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private final OnClickListener mExpandedActionViewUpListener = new OnClickListener() {
150bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        @Override
151bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        public void onClick(View v) {
152bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final MenuItemImpl item = mExpandedMenuPresenter.mCurrentExpandedItem;
153bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (item != null) {
154bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                item.collapseActionView();
155bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
156bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
157bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    };
158bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
159bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private final OnClickListener mUpClickListener = new OnClickListener() {
160bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        public void onClick(View v) {
16130837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell            mWindowCallback.onMenuItemSelected(Window.FEATURE_OPTIONS_PANEL, mLogoNavItem);
162bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
163bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    };
164bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
165bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public ActionBarView(Context context, AttributeSet attrs) {
166bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        super(context, attrs);
167bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mContext = context;
168bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
169bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        // Background is always provided by the container.
170bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        setBackgroundResource(0);
171bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
172bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ActionBar,
173bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                R.attr.actionBarStyle, 0);
174bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
175bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        ApplicationInfo appInfo = context.getApplicationInfo();
176bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        PackageManager pm = context.getPackageManager();
177bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mNavigationMode = a.getInt(R.styleable.ActionBar_navigationMode,
178bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                ActionBar.NAVIGATION_MODE_STANDARD);
179bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mTitle = a.getText(R.styleable.ActionBar_title);
180bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mSubtitle = a.getText(R.styleable.ActionBar_subtitle);
181bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mLogo = a.getDrawable(R.styleable.ActionBar_logo);
182bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mLogo == null) {
1832334427b64cc2562c6d8fe47f1bdbc3c2dab187eTrevor Johns            if (Build.VERSION.SDK_INT >= 9) {
1842334427b64cc2562c6d8fe47f1bdbc3c2dab187eTrevor Johns                if (context instanceof Activity) {
1852334427b64cc2562c6d8fe47f1bdbc3c2dab187eTrevor Johns                    try {
1862334427b64cc2562c6d8fe47f1bdbc3c2dab187eTrevor Johns                        mLogo = pm.getActivityLogo(((Activity) context).getComponentName());
1872334427b64cc2562c6d8fe47f1bdbc3c2dab187eTrevor Johns                    } catch (NameNotFoundException e) {
1882334427b64cc2562c6d8fe47f1bdbc3c2dab187eTrevor Johns                        Log.e(TAG, "Activity component name not found!", e);
1892334427b64cc2562c6d8fe47f1bdbc3c2dab187eTrevor Johns                    }
1902334427b64cc2562c6d8fe47f1bdbc3c2dab187eTrevor Johns                }
1912334427b64cc2562c6d8fe47f1bdbc3c2dab187eTrevor Johns                if (mLogo == null) {
1922334427b64cc2562c6d8fe47f1bdbc3c2dab187eTrevor Johns                    mLogo = appInfo.loadLogo(pm);
193bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                }
194bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
195bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
196bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
19720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        // TODO(trevorjohns): Should these use the android namespace
19820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        mIcon = a.getDrawable(R.styleable.ActionBar_icon);
199bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mIcon == null) {
200bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (context instanceof Activity) {
201bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                try {
202bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    mIcon = pm.getActivityIcon(((Activity) context).getComponentName());
203bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                } catch (NameNotFoundException e) {
204bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    Log.e(TAG, "Activity component name not found!", e);
205bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                }
206bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
207bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (mIcon == null) {
208bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                mIcon = appInfo.loadIcon(pm);
209bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
210bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
211bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
212bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        final LayoutInflater inflater = LayoutInflater.from(context);
213bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
214bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        final int homeResId = a.getResourceId(
215bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                R.styleable.ActionBar_homeLayout,
216ee7c9fb199e9b9af8d40a1f9e27d85465acf8301Chris Banes                R.layout.abc_action_bar_home);
217bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
218bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mHomeLayout = (HomeView) inflater.inflate(homeResId, this, false);
219bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
220bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mExpandedHomeLayout = (HomeView) inflater.inflate(homeResId, this, false);
221bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mExpandedHomeLayout.setUp(true);
222bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mExpandedHomeLayout.setOnClickListener(mExpandedActionViewUpListener);
223bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mExpandedHomeLayout.setContentDescription(getResources().getText(
22407a07ce59efb770e9fb9ca53a0133e5e64a63bbcChris Banes                R.string.abc_action_bar_up_description));
22520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns
226bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mTitleStyleRes = a.getResourceId(R.styleable.ActionBar_titleTextStyle, 0);
227bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mSubtitleStyleRes = a.getResourceId(R.styleable.ActionBar_subtitleTextStyle, 0);
228bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mProgressStyle = a.getResourceId(R.styleable.ActionBar_progressBarStyle, 0);
229bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mIndeterminateProgressStyle = a.getResourceId(
230bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                R.styleable.ActionBar_indeterminateProgressStyle, 0);
231bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
23220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        mProgressBarPadding = a
23320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                .getDimensionPixelOffset(R.styleable.ActionBar_progressBarPadding, 0);
234bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mItemPadding = a.getDimensionPixelOffset(R.styleable.ActionBar_itemPadding, 0);
235bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
236bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        setDisplayOptions(a.getInt(R.styleable.ActionBar_displayOptions, DISPLAY_DEFAULT));
237bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
238bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        final int customNavId = a.getResourceId(R.styleable.ActionBar_customNavigationLayout, 0);
239bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (customNavId != 0) {
240bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mCustomNavView = (View) inflater.inflate(customNavId, this, false);
241bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mNavigationMode = ActionBar.NAVIGATION_MODE_STANDARD;
242bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            setDisplayOptions(mDisplayOptions | ActionBar.DISPLAY_SHOW_CUSTOM);
243bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
244bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
245bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mContentHeight = a.getLayoutDimension(R.styleable.ActionBar_height, 0);
246bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        a.recycle();
24797b0db12faafe07b5f1d981c1a1c1f8e02773c8dChris Banes        mLogoNavItem = new ActionMenuItem(context, 0, android.R.id.home, 0, 0, mTitle);
248bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mHomeLayout.setOnClickListener(mUpClickListener);
249bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mHomeLayout.setClickable(true);
250bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mHomeLayout.setFocusable(true);
251bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
252bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
253bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
254bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    @Override
255bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    protected void onConfigurationChanged(Configuration newConfig) {
256bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        super.onConfigurationChanged(newConfig);
257bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
258bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mTitleView = null;
259bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mSubtitleView = null;
260bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mTitleUpView = null;
261bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mTitleLayout != null && mTitleLayout.getParent() == this) {
262bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            removeView(mTitleLayout);
263bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
264bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mTitleLayout = null;
265bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if ((mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0) {
266bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            initTitle();
267bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
268bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
269bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mTabScrollView != null && mIncludeTabs) {
270bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            ViewGroup.LayoutParams lp = mTabScrollView.getLayoutParams();
271bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (lp != null) {
272bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                lp.width = LayoutParams.WRAP_CONTENT;
2733565bf7048dfa3c5b5593d0df2259bd856f3b987Anirudh Dewani                lp.height = LayoutParams.FILL_PARENT;
274bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
275bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mTabScrollView.setAllowCollapse(true);
276bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
277b43f265584900a8627cfb224f0291f3b5be3a99eChris Banes
278b43f265584900a8627cfb224f0291f3b5be3a99eChris Banes        if (mProgressView != null) {
279b43f265584900a8627cfb224f0291f3b5be3a99eChris Banes            removeView(mProgressView);
280b43f265584900a8627cfb224f0291f3b5be3a99eChris Banes            initProgress();
281b43f265584900a8627cfb224f0291f3b5be3a99eChris Banes        }
282b43f265584900a8627cfb224f0291f3b5be3a99eChris Banes        if (mIndeterminateProgressView != null) {
283b43f265584900a8627cfb224f0291f3b5be3a99eChris Banes            removeView(mIndeterminateProgressView);
284b43f265584900a8627cfb224f0291f3b5be3a99eChris Banes            initIndeterminateProgress();
285b43f265584900a8627cfb224f0291f3b5be3a99eChris Banes        }
286bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
287bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
288bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    /**
28997b0db12faafe07b5f1d981c1a1c1f8e02773c8dChris Banes     * Set the view callback used to invoke menu items; used for dispatching home button presses.
29020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
29197b0db12faafe07b5f1d981c1a1c1f8e02773c8dChris Banes     * @param cb View callback to dispatch to
292bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell     */
29330837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell    public void setWindowCallback(Window.Callback cb) {
29430837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell        mWindowCallback = cb;
295bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
296bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
297bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    @Override
298bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public void onDetachedFromWindow() {
299bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        super.onDetachedFromWindow();
300bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        removeCallbacks(mTabSelector);
301bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mActionMenuPresenter != null) {
302bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mActionMenuPresenter.hideOverflowMenu();
303bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mActionMenuPresenter.hideSubMenus();
304bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
305bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
306bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
307bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public boolean shouldDelayChildPressedState() {
308bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        return false;
309bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
310bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
311bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public void initProgress() {
312ed34e2dffd0ce7da89063d06fd3b25687ca367a2Chris Banes        mProgressView = new ProgressBarICS(mContext, null, 0, mProgressStyle);
313bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mProgressView.setId(R.id.progress_horizontal);
314bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mProgressView.setMax(10000);
315bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mProgressView.setVisibility(GONE);
316bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        addView(mProgressView);
317bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
318bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
319bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public void initIndeterminateProgress() {
320ed34e2dffd0ce7da89063d06fd3b25687ca367a2Chris Banes        mIndeterminateProgressView = new ProgressBarICS(mContext, null, 0,
321ed34e2dffd0ce7da89063d06fd3b25687ca367a2Chris Banes                mIndeterminateProgressStyle);
322bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mIndeterminateProgressView.setId(R.id.progress_circular);
323bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mIndeterminateProgressView.setVisibility(GONE);
324bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        addView(mIndeterminateProgressView);
325bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
326bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
327bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    @Override
328bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public void setSplitActionBar(boolean splitActionBar) {
329bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mSplitActionBar != splitActionBar) {
330bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (mMenuView != null) {
331bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                final ViewGroup oldParent = (ViewGroup) mMenuView.getParent();
332bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                if (oldParent != null) {
333bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    oldParent.removeView(mMenuView);
334bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                }
335bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                if (splitActionBar) {
336bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    if (mSplitView != null) {
337bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                        mSplitView.addView(mMenuView);
338bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    }
3393565bf7048dfa3c5b5593d0df2259bd856f3b987Anirudh Dewani                    mMenuView.getLayoutParams().width = LayoutParams.FILL_PARENT;
340bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                } else {
341bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    addView(mMenuView);
342bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    mMenuView.getLayoutParams().width = LayoutParams.WRAP_CONTENT;
343bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                }
344bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                mMenuView.requestLayout();
345bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
346bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (mSplitView != null) {
347bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                mSplitView.setVisibility(splitActionBar ? VISIBLE : GONE);
348bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
349bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
350bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (mActionMenuPresenter != null) {
351bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                if (!splitActionBar) {
352bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    mActionMenuPresenter.setExpandedActionViewsExclusive(
353bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                            getResources().getBoolean(
35407a07ce59efb770e9fb9ca53a0133e5e64a63bbcChris Banes                                    R.bool.abc_action_bar_expanded_action_views_exclusive));
355bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                } else {
356bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    mActionMenuPresenter.setExpandedActionViewsExclusive(false);
357bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    // Allow full screen width in split mode.
358bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    mActionMenuPresenter.setWidthLimit(
359bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                            getContext().getResources().getDisplayMetrics().widthPixels, true);
360bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    // No limit to the item count; use whatever will fit.
361bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE);
362bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                }
363bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
364bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            super.setSplitActionBar(splitActionBar);
365bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
366bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
367bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
368bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public boolean isSplitActionBar() {
369bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        return mSplitActionBar;
370bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
371bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
372bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public boolean hasEmbeddedTabs() {
373bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        return mIncludeTabs;
374bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
375bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
376bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public void setEmbeddedTabView(ScrollingTabContainerView tabs) {
377bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mTabScrollView != null) {
378bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            removeView(mTabScrollView);
379bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
380bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mTabScrollView = tabs;
381bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mIncludeTabs = tabs != null;
382bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mIncludeTabs && mNavigationMode == ActionBar.NAVIGATION_MODE_TABS) {
383bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            addView(mTabScrollView);
384bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            ViewGroup.LayoutParams lp = mTabScrollView.getLayoutParams();
385bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            lp.width = LayoutParams.WRAP_CONTENT;
3863565bf7048dfa3c5b5593d0df2259bd856f3b987Anirudh Dewani            lp.height = LayoutParams.FILL_PARENT;
387bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            tabs.setAllowCollapse(true);
388bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
389bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
390bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
391bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public void setCallback(OnNavigationListener callback) {
392bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mCallback = callback;
393bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
394bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
39530837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell    public void setMenu(SupportMenu menu, MenuPresenter.Callback cb) {
39620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        if (menu == mOptionsMenu) {
39720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns            return;
39820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        }
399bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
400bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mOptionsMenu != null) {
401bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mOptionsMenu.removeMenuPresenter(mActionMenuPresenter);
402bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mOptionsMenu.removeMenuPresenter(mExpandedMenuPresenter);
403bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
404bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
405bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        MenuBuilder builder = (MenuBuilder) menu;
406bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mOptionsMenu = builder;
407bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mMenuView != null) {
408bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final ViewGroup oldParent = (ViewGroup) mMenuView.getParent();
409bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (oldParent != null) {
410bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                oldParent.removeView(mMenuView);
411bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
412bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
413bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mActionMenuPresenter == null) {
414bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mActionMenuPresenter = new ActionMenuPresenter(mContext);
415bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mActionMenuPresenter.setCallback(cb);
416bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mActionMenuPresenter.setId(R.id.action_menu_presenter);
417bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mExpandedMenuPresenter = new ExpandedActionViewMenuPresenter();
418bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
419bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
420bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        ActionMenuView menuView;
421bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
4223565bf7048dfa3c5b5593d0df2259bd856f3b987Anirudh Dewani                LayoutParams.FILL_PARENT);
423bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (!mSplitActionBar) {
424bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mActionMenuPresenter.setExpandedActionViewsExclusive(
425bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    getResources().getBoolean(
42607a07ce59efb770e9fb9ca53a0133e5e64a63bbcChris Banes                            R.bool.abc_action_bar_expanded_action_views_exclusive));
427bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            configPresenters(builder);
428bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
429e59411910a07bff1602045e93760ffc6f0804f43Chris Banes            menuView.initialize(builder);
430bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final ViewGroup oldParent = (ViewGroup) menuView.getParent();
431bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (oldParent != null && oldParent != this) {
432bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                oldParent.removeView(menuView);
433bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
434bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            addView(menuView, layoutParams);
435bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        } else {
436bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mActionMenuPresenter.setExpandedActionViewsExclusive(false);
437bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            // Allow full screen width in split mode.
438bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mActionMenuPresenter.setWidthLimit(
439bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    getContext().getResources().getDisplayMetrics().widthPixels, true);
440bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            // No limit to the item count; use whatever will fit.
441bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE);
442bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            // Span the whole width
4433565bf7048dfa3c5b5593d0df2259bd856f3b987Anirudh Dewani            layoutParams.width = LayoutParams.FILL_PARENT;
444bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            configPresenters(builder);
445bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
446bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (mSplitView != null) {
447bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                final ViewGroup oldParent = (ViewGroup) menuView.getParent();
448bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                if (oldParent != null && oldParent != mSplitView) {
449bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    oldParent.removeView(menuView);
450bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                }
451bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                menuView.setVisibility(getAnimatedVisibility());
452bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                mSplitView.addView(menuView, layoutParams);
453bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            } else {
454bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                // We'll add this later if we missed it this time.
455bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                menuView.setLayoutParams(layoutParams);
456bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
457bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
458bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mMenuView = menuView;
459bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
460bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
461bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private void configPresenters(MenuBuilder builder) {
462bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (builder != null) {
463bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            builder.addMenuPresenter(mActionMenuPresenter);
464bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            builder.addMenuPresenter(mExpandedMenuPresenter);
465bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        } else {
466bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mActionMenuPresenter.initForMenu(mContext, null);
467bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mExpandedMenuPresenter.initForMenu(mContext, null);
468bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
469176a17e30644b1d5a4206cc462268d151e43949bChris Banes
470176a17e30644b1d5a4206cc462268d151e43949bChris Banes        // Make sure the Presenter's View is updated
471176a17e30644b1d5a4206cc462268d151e43949bChris Banes        mActionMenuPresenter.updateMenuView(true);
472176a17e30644b1d5a4206cc462268d151e43949bChris Banes        mExpandedMenuPresenter.updateMenuView(true);
473bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
474bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
475bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public boolean hasExpandedActionView() {
476bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        return mExpandedMenuPresenter != null &&
477bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                mExpandedMenuPresenter.mCurrentExpandedItem != null;
478bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
479bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
480bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public void collapseActionView() {
481bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        final MenuItemImpl item = mExpandedMenuPresenter == null ? null :
482bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                mExpandedMenuPresenter.mCurrentExpandedItem;
483bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (item != null) {
484bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            item.collapseActionView();
485bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
486bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
487bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
488bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public void setCustomNavigationView(View view) {
489bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        final boolean showCustom = (mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0;
490bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mCustomNavView != null && showCustom) {
491bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            removeView(mCustomNavView);
492bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
493bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mCustomNavView = view;
494bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mCustomNavView != null && showCustom) {
495bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            addView(mCustomNavView);
496bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
497bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
498bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
499bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public CharSequence getTitle() {
500bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        return mTitle;
501bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
502bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
503bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    /**
504bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell     * Set the action bar title. This will always replace or override window titles.
505bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell     *
50620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @param title Title to set
507bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell     * @see #setWindowTitle(CharSequence)
508bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell     */
509bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public void setTitle(CharSequence title) {
510bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mUserTitle = true;
511bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        setTitleImpl(title);
512bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
513bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
514bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    /**
515bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell     * Set the window title. A window title will always be replaced or overridden by a user title.
516bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell     *
51720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @param title Title to set
518bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell     * @see #setTitle(CharSequence)
519bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell     */
520bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public void setWindowTitle(CharSequence title) {
521bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (!mUserTitle) {
522bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            setTitleImpl(title);
523bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
524bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
525bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
526bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private void setTitleImpl(CharSequence title) {
527bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mTitle = title;
528bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mTitleView != null) {
529bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mTitleView.setText(title);
530bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final boolean visible = mExpandedActionView == null &&
531bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    (mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0 &&
532bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    (!TextUtils.isEmpty(mTitle) || !TextUtils.isEmpty(mSubtitle));
533bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mTitleLayout.setVisibility(visible ? VISIBLE : GONE);
534bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
535bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mLogoNavItem != null) {
536bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mLogoNavItem.setTitle(title);
537bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
538bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
539bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
540bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public CharSequence getSubtitle() {
541bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        return mSubtitle;
542bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
543bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
544bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public void setSubtitle(CharSequence subtitle) {
545bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mSubtitle = subtitle;
546bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mSubtitleView != null) {
547bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mSubtitleView.setText(subtitle);
548bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mSubtitleView.setVisibility(subtitle != null ? VISIBLE : GONE);
549bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final boolean visible = mExpandedActionView == null &&
550bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    (mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0 &&
551bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    (!TextUtils.isEmpty(mTitle) || !TextUtils.isEmpty(mSubtitle));
552bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mTitleLayout.setVisibility(visible ? VISIBLE : GONE);
553bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
554bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
555bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
556bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public void setHomeButtonEnabled(boolean enable) {
557bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mHomeLayout.setEnabled(enable);
558bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mHomeLayout.setFocusable(enable);
559bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        // Make sure the home button has an accurate content description for accessibility.
560bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (!enable) {
561bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mHomeLayout.setContentDescription(null);
562bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        } else if ((mDisplayOptions & ActionBar.DISPLAY_HOME_AS_UP) != 0) {
563bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mHomeLayout.setContentDescription(mContext.getResources().getText(
56407a07ce59efb770e9fb9ca53a0133e5e64a63bbcChris Banes                    R.string.abc_action_bar_up_description));
565bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        } else {
566bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mHomeLayout.setContentDescription(mContext.getResources().getText(
56707a07ce59efb770e9fb9ca53a0133e5e64a63bbcChris Banes                    R.string.abc_action_bar_home_description));
568bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
569bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
570bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
571bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public void setDisplayOptions(int options) {
572bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        final int flagsChanged = mDisplayOptions == -1 ? -1 : options ^ mDisplayOptions;
573bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mDisplayOptions = options;
574bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
575bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if ((flagsChanged & DISPLAY_RELAYOUT_MASK) != 0) {
576bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final boolean showHome = (options & ActionBar.DISPLAY_SHOW_HOME) != 0;
577bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final int vis = showHome && mExpandedActionView == null ? VISIBLE : GONE;
578bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mHomeLayout.setVisibility(vis);
579bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
580bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if ((flagsChanged & ActionBar.DISPLAY_HOME_AS_UP) != 0) {
581bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                final boolean setUp = (options & ActionBar.DISPLAY_HOME_AS_UP) != 0;
582bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                mHomeLayout.setUp(setUp);
583bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
584bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                // Showing home as up implicitly enables interaction with it.
585bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                // In honeycomb it was always enabled, so make this transition
586bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                // a bit easier for developers in the common case.
587bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                // (It would be silly to show it as up without responding to it.)
588bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                if (setUp) {
589bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    setHomeButtonEnabled(true);
590bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                }
591bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
592bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
593bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if ((flagsChanged & ActionBar.DISPLAY_USE_LOGO) != 0) {
59420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                final boolean logoVis = mLogo != null
59520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                        && (options & ActionBar.DISPLAY_USE_LOGO) != 0;
596bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                mHomeLayout.setIcon(logoVis ? mLogo : mIcon);
597bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
598bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
599bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if ((flagsChanged & ActionBar.DISPLAY_SHOW_TITLE) != 0) {
600bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                if ((options & ActionBar.DISPLAY_SHOW_TITLE) != 0) {
601bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    initTitle();
602bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                } else {
603bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    removeView(mTitleLayout);
604bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                }
605bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
606bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
607bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (mTitleLayout != null && (flagsChanged &
608bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    (ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME)) != 0) {
609bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                final boolean homeAsUp = (mDisplayOptions & ActionBar.DISPLAY_HOME_AS_UP) != 0;
610bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                mTitleUpView.setVisibility(!showHome ? (homeAsUp ? VISIBLE : INVISIBLE) : GONE);
611bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                mTitleLayout.setEnabled(!showHome && homeAsUp);
612bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
613bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
614bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if ((flagsChanged & ActionBar.DISPLAY_SHOW_CUSTOM) != 0 && mCustomNavView != null) {
615bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                if ((options & ActionBar.DISPLAY_SHOW_CUSTOM) != 0) {
616bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    addView(mCustomNavView);
617bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                } else {
618bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    removeView(mCustomNavView);
619bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                }
620bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
62120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns
622bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            requestLayout();
623bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        } else {
624bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            invalidate();
625bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
626bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
627bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        // Make sure the home button has an accurate content description for accessibility.
628bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (!mHomeLayout.isEnabled()) {
629bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mHomeLayout.setContentDescription(null);
630bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        } else if ((options & ActionBar.DISPLAY_HOME_AS_UP) != 0) {
631bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mHomeLayout.setContentDescription(mContext.getResources().getText(
63207a07ce59efb770e9fb9ca53a0133e5e64a63bbcChris Banes                    R.string.abc_action_bar_up_description));
633bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        } else {
634bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mHomeLayout.setContentDescription(mContext.getResources().getText(
63507a07ce59efb770e9fb9ca53a0133e5e64a63bbcChris Banes                    R.string.abc_action_bar_home_description));
636bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
637bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
638bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
639bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public void setIcon(Drawable icon) {
640bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mIcon = icon;
641bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (icon != null &&
642bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                ((mDisplayOptions & ActionBar.DISPLAY_USE_LOGO) == 0 || mLogo == null)) {
643bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mHomeLayout.setIcon(icon);
644bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
645bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mExpandedActionView != null) {
646bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mExpandedHomeLayout.setIcon(mIcon.getConstantState().newDrawable(getResources()));
647bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
648bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
649bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
650bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public void setIcon(int resId) {
651bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        setIcon(mContext.getResources().getDrawable(resId));
652bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
653bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
654bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public void setLogo(Drawable logo) {
655bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mLogo = logo;
656bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (logo != null && (mDisplayOptions & ActionBar.DISPLAY_USE_LOGO) != 0) {
657bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mHomeLayout.setIcon(logo);
658bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
659bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
660bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
661bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public void setLogo(int resId) {
662bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        setLogo(mContext.getResources().getDrawable(resId));
663bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
664bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
665bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public void setNavigationMode(int mode) {
666bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        final int oldMode = mNavigationMode;
667bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mode != oldMode) {
668bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            switch (oldMode) {
66920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                case ActionBar.NAVIGATION_MODE_LIST:
67020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                    if (mListNavLayout != null) {
67120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                        removeView(mListNavLayout);
67220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                    }
67320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                    break;
67420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                case ActionBar.NAVIGATION_MODE_TABS:
67520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                    if (mTabScrollView != null && mIncludeTabs) {
67620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                        removeView(mTabScrollView);
67720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                    }
678bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
67920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns
680bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            switch (mode) {
68120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                case ActionBar.NAVIGATION_MODE_LIST:
68220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                    if (mSpinner == null) {
68379e7a9ef79920c7daa10c90339db126a4c3c592eChris Banes                        mSpinner = new SpinnerICS(mContext, null,
68420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                                R.attr.actionDropDownStyle);
68520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                        mListNavLayout = (LinearLayout) LayoutInflater.from(mContext).inflate(
686ee7c9fb199e9b9af8d40a1f9e27d85465acf8301Chris Banes                                R.layout.abc_action_bar_view_list_nav_layout, null);
68720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
68820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                                LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
68920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                        params.gravity = Gravity.CENTER;
69020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                        mListNavLayout.addView(mSpinner, params);
69120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                    }
69220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                    if (mSpinner.getAdapter() != mSpinnerAdapter) {
69320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                        mSpinner.setAdapter(mSpinnerAdapter);
69420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                    }
69520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                    mSpinner.setOnItemSelectedListener(mNavItemSelectedListener);
69620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                    addView(mListNavLayout);
69720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                    break;
69820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                case ActionBar.NAVIGATION_MODE_TABS:
69920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                    if (mTabScrollView != null && mIncludeTabs) {
70020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                        addView(mTabScrollView);
70120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                    }
70220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                    break;
703bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
704bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mNavigationMode = mode;
705bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            requestLayout();
706bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
707bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
708bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
709bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public void setDropdownAdapter(SpinnerAdapter adapter) {
710bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mSpinnerAdapter = adapter;
711bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mSpinner != null) {
712bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mSpinner.setAdapter(adapter);
713bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
714bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
715bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
716bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public SpinnerAdapter getDropdownAdapter() {
717bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        return mSpinnerAdapter;
718bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
719bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
720bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public void setDropdownSelectedPosition(int position) {
721bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mSpinner.setSelection(position);
722bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
723bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
724bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public int getDropdownSelectedPosition() {
725bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        return mSpinner.getSelectedItemPosition();
726bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
727bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
728bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public View getCustomNavigationView() {
729bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        return mCustomNavView;
730bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
73120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns
732bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public int getNavigationMode() {
733bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        return mNavigationMode;
734bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
73520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns
736bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public int getDisplayOptions() {
737bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        return mDisplayOptions;
738bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
739bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
740bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    @Override
741bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
742bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        // Used by custom nav views if they don't supply layout params. Everything else
743bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        // added to an ActionBarView should have them already.
744bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        return new ActionBar.LayoutParams(DEFAULT_CUSTOM_GRAVITY);
745bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
746bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
747bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    @Override
748bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    protected void onFinishInflate() {
749bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        super.onFinishInflate();
750bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
751bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        addView(mHomeLayout);
752bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
753bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mCustomNavView != null && (mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0) {
754bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final ViewParent parent = mCustomNavView.getParent();
755bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (parent != this) {
756bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                if (parent instanceof ViewGroup) {
757bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    ((ViewGroup) parent).removeView(mCustomNavView);
758bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                }
759bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                addView(mCustomNavView);
760bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
761bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
762bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
763bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
764bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private void initTitle() {
765bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mTitleLayout == null) {
766bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            LayoutInflater inflater = LayoutInflater.from(getContext());
767ee7c9fb199e9b9af8d40a1f9e27d85465acf8301Chris Banes            mTitleLayout = (LinearLayout) inflater.inflate(R.layout.abc_action_bar_title_item,
768bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    this, false);
769bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mTitleView = (TextView) mTitleLayout.findViewById(R.id.action_bar_title);
770bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mSubtitleView = (TextView) mTitleLayout.findViewById(R.id.action_bar_subtitle);
771bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mTitleUpView = (View) mTitleLayout.findViewById(R.id.up);
772bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
773bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mTitleLayout.setOnClickListener(mUpClickListener);
774bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
775bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (mTitleStyleRes != 0) {
776bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                mTitleView.setTextAppearance(mContext, mTitleStyleRes);
777bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
778bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (mTitle != null) {
779bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                mTitleView.setText(mTitle);
780bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
781bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
782bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (mSubtitleStyleRes != 0) {
783bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                mSubtitleView.setTextAppearance(mContext, mSubtitleStyleRes);
784bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
785bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (mSubtitle != null) {
786bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                mSubtitleView.setText(mSubtitle);
787bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                mSubtitleView.setVisibility(VISIBLE);
788bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
789bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
790bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final boolean homeAsUp = (mDisplayOptions & ActionBar.DISPLAY_HOME_AS_UP) != 0;
791bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final boolean showHome = (mDisplayOptions & ActionBar.DISPLAY_SHOW_HOME) != 0;
792bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mTitleUpView.setVisibility(!showHome ? (homeAsUp ? VISIBLE : INVISIBLE) : GONE);
793bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mTitleLayout.setEnabled(homeAsUp && !showHome);
794bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
795bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
796bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        addView(mTitleLayout);
797bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mExpandedActionView != null ||
798bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                (TextUtils.isEmpty(mTitle) && TextUtils.isEmpty(mSubtitle))) {
799bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            // Don't show while in expanded mode or with empty text
800bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mTitleLayout.setVisibility(GONE);
801bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
802bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
803bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
804bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public void setContextView(ActionBarContextView view) {
805bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mContextView = view;
806bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
807bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
808bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public void setCollapsable(boolean collapsable) {
809bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mIsCollapsable = collapsable;
810bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
811bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
812bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public boolean isCollapsed() {
813bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        return mIsCollapsed;
814bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
815bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
816bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    @Override
817bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
818bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        final int childCount = getChildCount();
819bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mIsCollapsable) {
820bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            int visibleChildren = 0;
821bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            for (int i = 0; i < childCount; i++) {
822bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                final View child = getChildAt(i);
823bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                if (child.getVisibility() != GONE &&
824bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                        !(child == mMenuView && mMenuView.getChildCount() == 0)) {
825bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    visibleChildren++;
826bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                }
827bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
828bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
829bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (visibleChildren == 0) {
830bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                // No size for an empty action bar when collapsable.
831bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                setMeasuredDimension(0, 0);
832bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                mIsCollapsed = true;
833bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                return;
834bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
835bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
836bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        mIsCollapsed = false;
837bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
838bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        int widthMode = MeasureSpec.getMode(widthMeasureSpec);
839bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (widthMode != MeasureSpec.EXACTLY) {
840bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            throw new IllegalStateException(getClass().getSimpleName() + " can only be used " +
8413565bf7048dfa3c5b5593d0df2259bd856f3b987Anirudh Dewani                    "with android:layout_width=\"MATCH_PARENT\" (or fill_parent)");
842bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
84320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns
844bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        int heightMode = MeasureSpec.getMode(heightMeasureSpec);
845bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (heightMode != MeasureSpec.AT_MOST) {
846bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            throw new IllegalStateException(getClass().getSimpleName() + " can only be used " +
847bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    "with android:layout_height=\"wrap_content\"");
848bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
849bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
850bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        int contentWidth = MeasureSpec.getSize(widthMeasureSpec);
851bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
852bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        int maxHeight = mContentHeight > 0 ?
853bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                mContentHeight : MeasureSpec.getSize(heightMeasureSpec);
85420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns
855bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        final int verticalPadding = getPaddingTop() + getPaddingBottom();
856bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        final int paddingLeft = getPaddingLeft();
857bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        final int paddingRight = getPaddingRight();
858bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        final int height = maxHeight - verticalPadding;
859bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        final int childSpecHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST);
860bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
861bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        int availableWidth = contentWidth - paddingLeft - paddingRight;
862bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        int leftOfCenter = availableWidth / 2;
863bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        int rightOfCenter = leftOfCenter;
864bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
865bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        HomeView homeLayout = mExpandedActionView != null ? mExpandedHomeLayout : mHomeLayout;
866bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
867bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (homeLayout.getVisibility() != GONE) {
868bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final ViewGroup.LayoutParams lp = homeLayout.getLayoutParams();
869bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            int homeWidthSpec;
870bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (lp.width < 0) {
871bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                homeWidthSpec = MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST);
872bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            } else {
873bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                homeWidthSpec = MeasureSpec.makeMeasureSpec(lp.width, MeasureSpec.EXACTLY);
874bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
875bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            homeLayout.measure(homeWidthSpec,
876bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
877bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final int homeWidth = homeLayout.getMeasuredWidth() + homeLayout.getLeftOffset();
878bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            availableWidth = Math.max(0, availableWidth - homeWidth);
879bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            leftOfCenter = Math.max(0, availableWidth - homeWidth);
880bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
88120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns
882bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mMenuView != null && mMenuView.getParent() == this) {
883bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            availableWidth = measureChildView(mMenuView, availableWidth,
884bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    childSpecHeight, 0);
885bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            rightOfCenter = Math.max(0, rightOfCenter - mMenuView.getMeasuredWidth());
886bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
887bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
888bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mIndeterminateProgressView != null &&
889bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                mIndeterminateProgressView.getVisibility() != GONE) {
890bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            availableWidth = measureChildView(mIndeterminateProgressView, availableWidth,
891bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    childSpecHeight, 0);
892bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            rightOfCenter = Math.max(0,
893bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    rightOfCenter - mIndeterminateProgressView.getMeasuredWidth());
894bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
895bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
896bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        final boolean showTitle = mTitleLayout != null && mTitleLayout.getVisibility() != GONE &&
897bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                (mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0;
898bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
899bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mExpandedActionView == null) {
900bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            switch (mNavigationMode) {
901bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                case ActionBar.NAVIGATION_MODE_LIST:
902bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    if (mListNavLayout != null) {
903bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                        final int itemPaddingSize = showTitle ? mItemPadding * 2 : mItemPadding;
904bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                        availableWidth = Math.max(0, availableWidth - itemPaddingSize);
905bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                        leftOfCenter = Math.max(0, leftOfCenter - itemPaddingSize);
906bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                        mListNavLayout.measure(
907bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                                MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST),
908bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                                MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
909bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                        final int listNavWidth = mListNavLayout.getMeasuredWidth();
910bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                        availableWidth = Math.max(0, availableWidth - listNavWidth);
911bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                        leftOfCenter = Math.max(0, leftOfCenter - listNavWidth);
912bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    }
913bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    break;
914bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                case ActionBar.NAVIGATION_MODE_TABS:
915bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    if (mTabScrollView != null) {
916bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                        final int itemPaddingSize = showTitle ? mItemPadding * 2 : mItemPadding;
917bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                        availableWidth = Math.max(0, availableWidth - itemPaddingSize);
918bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                        leftOfCenter = Math.max(0, leftOfCenter - itemPaddingSize);
919bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                        mTabScrollView.measure(
920bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                                MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST),
921bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                                MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
922bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                        final int tabWidth = mTabScrollView.getMeasuredWidth();
923bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                        availableWidth = Math.max(0, availableWidth - tabWidth);
924bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                        leftOfCenter = Math.max(0, leftOfCenter - tabWidth);
925bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    }
926bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    break;
927bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
928bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
929bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
930bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        View customView = null;
931bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mExpandedActionView != null) {
932bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            customView = mExpandedActionView;
933bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        } else if ((mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0 &&
934bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                mCustomNavView != null) {
935bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            customView = mCustomNavView;
936bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
937bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
938bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (customView != null) {
939bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final ViewGroup.LayoutParams lp = generateLayoutParams(customView.getLayoutParams());
940bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final ActionBar.LayoutParams ablp = lp instanceof ActionBar.LayoutParams ?
941bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    (ActionBar.LayoutParams) lp : null;
942bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
943bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            int horizontalMargin = 0;
944bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            int verticalMargin = 0;
945bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (ablp != null) {
946bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                horizontalMargin = ablp.leftMargin + ablp.rightMargin;
947bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                verticalMargin = ablp.topMargin + ablp.bottomMargin;
948bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
949bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
950bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            // If the action bar is wrapping to its content height, don't allow a custom
9513565bf7048dfa3c5b5593d0df2259bd856f3b987Anirudh Dewani            // view to FILL_PARENT.
952bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            int customNavHeightMode;
953bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (mContentHeight <= 0) {
954bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                customNavHeightMode = MeasureSpec.AT_MOST;
955bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            } else {
956bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                customNavHeightMode = lp.height != LayoutParams.WRAP_CONTENT ?
957bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                        MeasureSpec.EXACTLY : MeasureSpec.AT_MOST;
958bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
959bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final int customNavHeight = Math.max(0,
960bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    (lp.height >= 0 ? Math.min(lp.height, height) : height) - verticalMargin);
961bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
962bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final int customNavWidthMode = lp.width != LayoutParams.WRAP_CONTENT ?
963bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    MeasureSpec.EXACTLY : MeasureSpec.AT_MOST;
964bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            int customNavWidth = Math.max(0,
965bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    (lp.width >= 0 ? Math.min(lp.width, availableWidth) : availableWidth)
96620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                            - horizontalMargin);
967bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final int hgrav = (ablp != null ? ablp.gravity : DEFAULT_CUSTOM_GRAVITY) &
968bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    Gravity.HORIZONTAL_GRAVITY_MASK;
969bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
970bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            // Centering a custom view is treated specially; we try to center within the whole
971bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            // action bar rather than in the available space.
9723565bf7048dfa3c5b5593d0df2259bd856f3b987Anirudh Dewani            if (hgrav == Gravity.CENTER_HORIZONTAL && lp.width == LayoutParams.FILL_PARENT) {
973bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                customNavWidth = Math.min(leftOfCenter, rightOfCenter) * 2;
974bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
975bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
976bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            customView.measure(
977bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    MeasureSpec.makeMeasureSpec(customNavWidth, customNavWidthMode),
978bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    MeasureSpec.makeMeasureSpec(customNavHeight, customNavHeightMode));
979bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            availableWidth -= horizontalMargin + customView.getMeasuredWidth();
980bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
981bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
982bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mExpandedActionView == null && showTitle) {
983bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            availableWidth = measureChildView(mTitleLayout, availableWidth,
984bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    MeasureSpec.makeMeasureSpec(mContentHeight, MeasureSpec.EXACTLY), 0);
985bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            leftOfCenter = Math.max(0, leftOfCenter - mTitleLayout.getMeasuredWidth());
986bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
987bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
988bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mContentHeight <= 0) {
989bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            int measuredHeight = 0;
990bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            for (int i = 0; i < childCount; i++) {
991bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                View v = getChildAt(i);
992bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                int paddedViewHeight = v.getMeasuredHeight() + verticalPadding;
993bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                if (paddedViewHeight > measuredHeight) {
994bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    measuredHeight = paddedViewHeight;
995bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                }
996bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
997bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            setMeasuredDimension(contentWidth, measuredHeight);
998bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        } else {
999bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            setMeasuredDimension(contentWidth, maxHeight);
1000bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1001bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1002bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mContextView != null) {
1003bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mContextView.setContentHeight(getMeasuredHeight());
1004bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1005bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1006bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mProgressView != null && mProgressView.getVisibility() != GONE) {
1007bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mProgressView.measure(MeasureSpec.makeMeasureSpec(
1008bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    contentWidth - mProgressBarPadding * 2, MeasureSpec.EXACTLY),
1009bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.AT_MOST));
1010bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1011bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
1012bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1013bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    @Override
1014bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    protected void onLayout(boolean changed, int l, int t, int r, int b) {
1015bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        int x = getPaddingLeft();
1016bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        final int y = getPaddingTop();
1017bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        final int contentHeight = b - t - getPaddingTop() - getPaddingBottom();
1018bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1019bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (contentHeight <= 0) {
1020bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            // Nothing to do if we can't see anything.
1021bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            return;
1022bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1023bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1024bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        HomeView homeLayout = mExpandedActionView != null ? mExpandedHomeLayout : mHomeLayout;
1025bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (homeLayout.getVisibility() != GONE) {
1026bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final int leftOffset = homeLayout.getLeftOffset();
1027bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            x += positionChild(homeLayout, x + leftOffset, y, contentHeight) + leftOffset;
1028bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1029bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1030bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mExpandedActionView == null) {
103120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns            final boolean showTitle = mTitleLayout != null && mTitleLayout.getVisibility() != GONE
103220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                    &&
1033bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    (mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0;
1034bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (showTitle) {
1035bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                x += positionChild(mTitleLayout, x, y, contentHeight);
1036bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
1037bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1038bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            switch (mNavigationMode) {
1039bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                case ActionBar.NAVIGATION_MODE_STANDARD:
1040bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    break;
1041bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                case ActionBar.NAVIGATION_MODE_LIST:
1042bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    if (mListNavLayout != null) {
104320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                        if (showTitle) {
104420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                            x += mItemPadding;
104520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                        }
1046bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                        x += positionChild(mListNavLayout, x, y, contentHeight) + mItemPadding;
1047bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    }
1048bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    break;
1049bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                case ActionBar.NAVIGATION_MODE_TABS:
1050bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    if (mTabScrollView != null) {
105120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                        if (showTitle) {
105220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                            x += mItemPadding;
105320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                        }
1054bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                        x += positionChild(mTabScrollView, x, y, contentHeight) + mItemPadding;
1055bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    }
1056bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    break;
1057bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
1058bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1059bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1060bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        int menuLeft = r - l - getPaddingRight();
1061bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mMenuView != null && mMenuView.getParent() == this) {
1062bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            positionChildInverse(mMenuView, menuLeft, y, contentHeight);
1063bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            menuLeft -= mMenuView.getMeasuredWidth();
1064bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1065bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1066bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mIndeterminateProgressView != null &&
1067bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                mIndeterminateProgressView.getVisibility() != GONE) {
1068bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            positionChildInverse(mIndeterminateProgressView, menuLeft, y, contentHeight);
1069bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            menuLeft -= mIndeterminateProgressView.getMeasuredWidth();
1070bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1071bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1072bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        View customView = null;
1073bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mExpandedActionView != null) {
1074bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            customView = mExpandedActionView;
1075bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        } else if ((mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0 &&
1076bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                mCustomNavView != null) {
1077bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            customView = mCustomNavView;
1078bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1079bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (customView != null) {
1080bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            ViewGroup.LayoutParams lp = customView.getLayoutParams();
1081bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final ActionBar.LayoutParams ablp = lp instanceof ActionBar.LayoutParams ?
1082bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    (ActionBar.LayoutParams) lp : null;
1083bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1084bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final int gravity = ablp != null ? ablp.gravity : DEFAULT_CUSTOM_GRAVITY;
1085bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final int navWidth = customView.getMeasuredWidth();
1086bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1087bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            int topMargin = 0;
1088bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            int bottomMargin = 0;
1089bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (ablp != null) {
1090bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                x += ablp.leftMargin;
1091bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                menuLeft -= ablp.rightMargin;
1092bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                topMargin = ablp.topMargin;
1093bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                bottomMargin = ablp.bottomMargin;
1094bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
1095bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1096bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            int hgravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
1097bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            // See if we actually have room to truly center; if not push against left or right.
1098bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (hgravity == Gravity.CENTER_HORIZONTAL) {
1099bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                final int centeredLeft = (getWidth() - navWidth) / 2;
1100bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                if (centeredLeft < x) {
1101bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    hgravity = Gravity.LEFT;
1102bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                } else if (centeredLeft + navWidth > menuLeft) {
1103bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    hgravity = Gravity.RIGHT;
1104bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                }
1105bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            } else if (gravity == -1) {
1106bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                hgravity = Gravity.LEFT;
1107bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
1108bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1109bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            int xpos = 0;
1110bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            switch (hgravity) {
1111bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                case Gravity.CENTER_HORIZONTAL:
1112bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    xpos = (getWidth() - navWidth) / 2;
1113bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    break;
1114bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                case Gravity.LEFT:
1115bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    xpos = x;
1116bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    break;
1117bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                case Gravity.RIGHT:
1118bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    xpos = menuLeft - navWidth;
1119bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    break;
1120bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
1121bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1122bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            int vgravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
1123bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1124bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (gravity == -1) {
1125bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                vgravity = Gravity.CENTER_VERTICAL;
1126bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
1127bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1128bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            int ypos = 0;
1129bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            switch (vgravity) {
1130bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                case Gravity.CENTER_VERTICAL:
1131bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    final int paddedTop = getPaddingTop();
1132bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    final int paddedBottom = getHeight() - getPaddingBottom();
1133bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    ypos = ((paddedBottom - paddedTop) - customView.getMeasuredHeight()) / 2;
1134bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    break;
1135bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                case Gravity.TOP:
1136bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    ypos = getPaddingTop() + topMargin;
1137bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    break;
1138bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                case Gravity.BOTTOM:
1139bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    ypos = getHeight() - getPaddingBottom() - customView.getMeasuredHeight()
1140bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                            - bottomMargin;
1141bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    break;
1142bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
1143bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final int customWidth = customView.getMeasuredWidth();
1144bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            customView.layout(xpos, ypos, xpos + customWidth,
1145bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    ypos + customView.getMeasuredHeight());
1146bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            x += customWidth;
1147bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1148bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1149bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mProgressView != null) {
1150bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mProgressView.bringToFront();
1151bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final int halfProgressHeight = mProgressView.getMeasuredHeight() / 2;
1152bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mProgressView.layout(mProgressBarPadding, -halfProgressHeight,
1153bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    mProgressBarPadding + mProgressView.getMeasuredWidth(), halfProgressHeight);
1154bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1155bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
1156bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1157bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    @Override
1158bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
1159bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        return new ActionBar.LayoutParams(getContext(), attrs);
1160bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
1161bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1162bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    @Override
1163bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp) {
1164bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (lp == null) {
1165bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            lp = generateDefaultLayoutParams();
1166bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1167bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        return lp;
1168bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
1169bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1170bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    @Override
1171bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public Parcelable onSaveInstanceState() {
1172bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        Parcelable superState = super.onSaveInstanceState();
1173bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        SavedState state = new SavedState(superState);
1174bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1175bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (mExpandedMenuPresenter != null && mExpandedMenuPresenter.mCurrentExpandedItem != null) {
1176bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            state.expandedMenuItemId = mExpandedMenuPresenter.mCurrentExpandedItem.getItemId();
1177bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1178bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1179bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        state.isOverflowOpen = isOverflowMenuShowing();
1180bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1181bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        return state;
1182bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
1183bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1184bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    @Override
1185bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    public void onRestoreInstanceState(Parcelable p) {
1186bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        SavedState state = (SavedState) p;
1187bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1188bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        super.onRestoreInstanceState(state.getSuperState());
1189bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1190bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (state.expandedMenuItemId != 0 &&
1191bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                mExpandedMenuPresenter != null && mOptionsMenu != null) {
119230837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell            final SupportMenuItem item =
119330837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell                    (SupportMenuItem) mOptionsMenu.findItem(state.expandedMenuItemId);
1194bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (item != null) {
1195bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                item.expandActionView();
1196bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
1197bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1198bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1199bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        if (state.isOverflowOpen) {
1200bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            postShowOverflowMenu();
1201bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1202bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
1203bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
120445d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes    public void setHomeAsUpIndicator(Drawable indicator) {
120545d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes        mHomeLayout.setUpIndicator(indicator);
120645d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes    }
120745d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes
120845d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes    public void setHomeAsUpIndicator(int resId) {
120945d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes        mHomeLayout.setUpIndicator(resId);
121045d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes    }
121145d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes
1212bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    static class SavedState extends BaseSavedState {
121320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns
1214bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        int expandedMenuItemId;
1215bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        boolean isOverflowOpen;
1216bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1217bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        SavedState(Parcelable superState) {
1218bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            super(superState);
1219bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1220bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1221bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        private SavedState(Parcel in) {
1222bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            super(in);
1223bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            expandedMenuItemId = in.readInt();
1224bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            isOverflowOpen = in.readInt() != 0;
1225bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1226bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1227bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        @Override
1228bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        public void writeToParcel(Parcel out, int flags) {
1229bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            super.writeToParcel(out, flags);
1230bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            out.writeInt(expandedMenuItemId);
1231bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            out.writeInt(isOverflowOpen ? 1 : 0);
1232bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1233bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1234bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        public static final Parcelable.Creator<SavedState> CREATOR =
1235bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                new Parcelable.Creator<SavedState>() {
123620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                    public SavedState createFromParcel(Parcel in) {
123720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                        return new SavedState(in);
123820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                    }
1239bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
124020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                    public SavedState[] newArray(int size) {
124120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                        return new SavedState[size];
124220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                    }
124320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                };
1244bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
1245bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1246bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private static class HomeView extends FrameLayout {
124745d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes        private ImageView mUpView;
1248bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        private ImageView mIconView;
1249bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        private int mUpWidth;
125045d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes        private int mUpIndicatorRes;
125145d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes        private Drawable mDefaultUpIndicator;
1252bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1253bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        public HomeView(Context context) {
1254bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            this(context, null);
1255bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1256bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1257bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        public HomeView(Context context, AttributeSet attrs) {
1258bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            super(context, attrs);
1259bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1260bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1261bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        public void setUp(boolean isUp) {
1262bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mUpView.setVisibility(isUp ? VISIBLE : GONE);
1263bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1264bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1265bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        public void setIcon(Drawable icon) {
1266bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mIconView.setImageDrawable(icon);
1267bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1268bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
126945d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes        public void setUpIndicator(Drawable d) {
127045d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes            mUpView.setImageDrawable(d != null ? d : mDefaultUpIndicator);
127145d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes            mUpIndicatorRes = 0;
127245d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes        }
127345d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes
127445d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes        public void setUpIndicator(int resId) {
127545d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes            mUpIndicatorRes = resId;
127645d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes            mUpView.setImageDrawable(resId != 0 ? getResources().getDrawable(resId) : null);
127745d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes        }
127845d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes
127945d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes        @Override
128045d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes        protected void onConfigurationChanged(Configuration newConfig) {
128145d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes            super.onConfigurationChanged(newConfig);
128245d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes            if (mUpIndicatorRes != 0) {
128345d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes                // Reload for config change
128445d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes                setUpIndicator(mUpIndicatorRes);
128545d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes            }
128645d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes        }
128745d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes
1288bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        @Override
1289bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
1290bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final CharSequence cdesc = getContentDescription();
1291bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (!TextUtils.isEmpty(cdesc)) {
1292bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                event.getText().add(cdesc);
1293bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
12942334427b64cc2562c6d8fe47f1bdbc3c2dab187eTrevor Johns            return true;
1295bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1296bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1297bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        @Override
1298bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        protected void onFinishInflate() {
129945d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes            mUpView = (ImageView) findViewById(R.id.up);
1300bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mIconView = (ImageView) findViewById(R.id.home);
130145d973fcc4c43f5ea00cddd3d9b947d9e8d8fc4eChris Banes            mDefaultUpIndicator = mUpView.getDrawable();
1302bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1303bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1304bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        public int getLeftOffset() {
1305bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            return mUpView.getVisibility() == GONE ? mUpWidth : 0;
1306bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1307bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1308bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        @Override
1309bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
1310bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            measureChildWithMargins(mUpView, widthMeasureSpec, 0, heightMeasureSpec, 0);
1311bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final LayoutParams upLp = (LayoutParams) mUpView.getLayoutParams();
1312bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mUpWidth = upLp.leftMargin + mUpView.getMeasuredWidth() + upLp.rightMargin;
1313bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            int width = mUpView.getVisibility() == GONE ? 0 : mUpWidth;
1314bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            int height = upLp.topMargin + mUpView.getMeasuredHeight() + upLp.bottomMargin;
1315bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            measureChildWithMargins(mIconView, widthMeasureSpec, width, heightMeasureSpec, 0);
1316bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final LayoutParams iconLp = (LayoutParams) mIconView.getLayoutParams();
1317bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            width += iconLp.leftMargin + mIconView.getMeasuredWidth() + iconLp.rightMargin;
1318bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            height = Math.max(height,
1319bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    iconLp.topMargin + mIconView.getMeasuredHeight() + iconLp.bottomMargin);
1320bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1321bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
1322bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
1323bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
1324bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final int heightSize = MeasureSpec.getSize(heightMeasureSpec);
1325bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1326bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            switch (widthMode) {
1327bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                case MeasureSpec.AT_MOST:
1328bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    width = Math.min(width, widthSize);
1329bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    break;
1330bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                case MeasureSpec.EXACTLY:
1331bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    width = widthSize;
1332bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    break;
1333bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                case MeasureSpec.UNSPECIFIED:
1334bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                default:
1335bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    break;
1336bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
1337bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            switch (heightMode) {
1338bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                case MeasureSpec.AT_MOST:
1339bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    height = Math.min(height, heightSize);
1340bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    break;
1341bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                case MeasureSpec.EXACTLY:
1342bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    height = heightSize;
1343bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    break;
1344bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                case MeasureSpec.UNSPECIFIED:
1345bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                default:
1346bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    break;
1347bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
1348bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            setMeasuredDimension(width, height);
1349bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1350bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1351bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        @Override
1352bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        protected void onLayout(boolean changed, int l, int t, int r, int b) {
1353bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final int vCenter = (b - t) / 2;
1354bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            int width = r - l;
1355bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            int upOffset = 0;
1356bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (mUpView.getVisibility() != GONE) {
1357bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                final LayoutParams upLp = (LayoutParams) mUpView.getLayoutParams();
1358bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                final int upHeight = mUpView.getMeasuredHeight();
1359bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                final int upWidth = mUpView.getMeasuredWidth();
1360bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                final int upTop = vCenter - upHeight / 2;
1361bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                mUpView.layout(0, upTop, upWidth, upTop + upHeight);
1362bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                upOffset = upLp.leftMargin + upWidth + upLp.rightMargin;
1363bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                width -= upOffset;
1364bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                l += upOffset;
1365bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
1366bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final LayoutParams iconLp = (LayoutParams) mIconView.getLayoutParams();
1367bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final int iconHeight = mIconView.getMeasuredHeight();
1368bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final int iconWidth = mIconView.getMeasuredWidth();
1369bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final int hCenter = (r - l) / 2;
1370bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final int iconLeft = upOffset + Math.max(iconLp.leftMargin, hCenter - iconWidth / 2);
1371bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            final int iconTop = Math.max(iconLp.topMargin, vCenter - iconHeight / 2);
1372bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mIconView.layout(iconLeft, iconTop, iconLeft + iconWidth, iconTop + iconHeight);
1373bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1374bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
1375bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1376bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    private class ExpandedActionViewMenuPresenter implements MenuPresenter {
137720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns
1378bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        MenuBuilder mMenu;
1379bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        MenuItemImpl mCurrentExpandedItem;
1380bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1381bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        @Override
1382bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        public void initForMenu(Context context, MenuBuilder menu) {
1383bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            // Clear the expanded action view when menus change.
1384bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (mMenu != null && mCurrentExpandedItem != null) {
1385bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                mMenu.collapseItemActionView(mCurrentExpandedItem);
1386bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
1387bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mMenu = menu;
1388bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1389bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1390bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        @Override
1391bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        public MenuView getMenuView(ViewGroup root) {
1392bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            return null;
1393bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1394bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1395bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        @Override
1396bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        public void updateMenuView(boolean cleared) {
1397bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            // Make sure the expanded item we have is still there.
1398bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (mCurrentExpandedItem != null) {
1399bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                boolean found = false;
1400bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1401bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                if (mMenu != null) {
1402bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    final int count = mMenu.size();
1403bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    for (int i = 0; i < count; i++) {
140430837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell                        final SupportMenuItem item = (SupportMenuItem) mMenu.getItem(i);
1405bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                        if (item == mCurrentExpandedItem) {
1406bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                            found = true;
1407bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                            break;
1408bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                        }
1409bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    }
1410bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                }
1411bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1412bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                if (!found) {
1413bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    // The item we had expanded disappeared. Collapse.
1414bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    collapseItemActionView(mMenu, mCurrentExpandedItem);
1415bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                }
1416bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
1417bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1418bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1419bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        @Override
1420bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        public void setCallback(Callback cb) {
1421bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1422bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1423bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        @Override
1424bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        public boolean onSubMenuSelected(SubMenuBuilder subMenu) {
1425bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            return false;
1426bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1427bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1428bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        @Override
1429bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) {
1430bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1431bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1432bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        @Override
1433bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        public boolean flagActionItems() {
1434bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            return false;
1435bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1436bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1437bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        @Override
1438bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        public boolean expandItemActionView(MenuBuilder menu, MenuItemImpl item) {
1439bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mExpandedActionView = item.getActionView();
1440bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mExpandedHomeLayout.setIcon(mIcon.getConstantState().newDrawable(getResources()));
1441bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mCurrentExpandedItem = item;
1442bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (mExpandedActionView.getParent() != ActionBarView.this) {
1443bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                addView(mExpandedActionView);
1444bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
1445bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (mExpandedHomeLayout.getParent() != ActionBarView.this) {
1446bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                addView(mExpandedHomeLayout);
1447bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
1448bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mHomeLayout.setVisibility(GONE);
144920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns            if (mTitleLayout != null) {
145020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                mTitleLayout.setVisibility(GONE);
145120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns            }
145220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns            if (mTabScrollView != null) {
145320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                mTabScrollView.setVisibility(GONE);
145420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns            }
145520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns            if (mSpinner != null) {
145620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                mSpinner.setVisibility(GONE);
145720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns            }
145820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns            if (mCustomNavView != null) {
145920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns                mCustomNavView.setVisibility(GONE);
146020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns            }
1461bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            requestLayout();
1462bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            item.setActionViewExpanded(true);
1463bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1464bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (mExpandedActionView instanceof CollapsibleActionView) {
1465bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                ((CollapsibleActionView) mExpandedActionView).onActionViewExpanded();
1466bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
1467bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1468bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            return true;
1469bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1470bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1471bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        @Override
1472bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        public boolean collapseItemActionView(MenuBuilder menu, MenuItemImpl item) {
1473bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            // Do this before detaching the actionview from the hierarchy, in case
1474bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            // it needs to dismiss the soft keyboard, etc.
1475bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (mExpandedActionView instanceof CollapsibleActionView) {
1476bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                ((CollapsibleActionView) mExpandedActionView).onActionViewCollapsed();
1477bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
1478bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1479bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            removeView(mExpandedActionView);
1480bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            removeView(mExpandedHomeLayout);
1481bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mExpandedActionView = null;
1482bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if ((mDisplayOptions & ActionBar.DISPLAY_SHOW_HOME) != 0) {
1483bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                mHomeLayout.setVisibility(VISIBLE);
1484bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
1485bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if ((mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0) {
1486bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                if (mTitleLayout == null) {
1487bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    initTitle();
1488bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                } else {
1489bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                    mTitleLayout.setVisibility(VISIBLE);
1490bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                }
1491bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
1492bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (mTabScrollView != null && mNavigationMode == ActionBar.NAVIGATION_MODE_TABS) {
1493bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                mTabScrollView.setVisibility(VISIBLE);
1494bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
1495bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (mSpinner != null && mNavigationMode == ActionBar.NAVIGATION_MODE_LIST) {
1496bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                mSpinner.setVisibility(VISIBLE);
1497bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
1498bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            if (mCustomNavView != null && (mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0) {
1499bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell                mCustomNavView.setVisibility(VISIBLE);
1500bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            }
1501bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mExpandedHomeLayout.setIcon(null);
1502bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            mCurrentExpandedItem = null;
1503bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            requestLayout();
1504bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            item.setActionViewExpanded(false);
1505bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1506bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            return true;
1507bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1508bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1509bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        @Override
1510bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        public int getId() {
1511bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            return 0;
1512bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1513bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1514bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        @Override
1515bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        public Parcelable onSaveInstanceState() {
1516bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell            return null;
1517bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1518bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
1519bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        @Override
1520bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        public void onRestoreInstanceState(Parcelable state) {
1521bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell        }
1522bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    }
1523bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell}
1524ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani
1525