blob: f2bd5224ffcfc9716af6dc864d5df373cbcecfab [file] [log] [blame]
Adam Powell33b97432010-04-20 10:01:14 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Adam Powell89e06452010-06-23 20:24:52 -070017package com.android.internal.widget;
Adam Powell33b97432010-04-20 10:01:14 -070018
Adam Powellfd75eef2012-08-02 10:27:31 -070019import android.animation.LayoutTransition;
Adam Powell33b97432010-04-20 10:01:14 -070020import android.app.ActionBar;
Adam Powell8515ee82010-11-30 14:09:55 -080021import android.app.ActionBar.OnNavigationListener;
Adam Powell33b97432010-04-20 10:01:14 -070022import android.content.Context;
23import android.content.pm.ApplicationInfo;
24import android.content.pm.PackageManager;
Adam Powell45c0b192011-07-28 15:11:57 -070025import android.content.res.Configuration;
Adam Powell33b97432010-04-20 10:01:14 -070026import android.content.res.TypedArray;
Adam Powell33b97432010-04-20 10:01:14 -070027import android.graphics.drawable.Drawable;
Adam Powell8d02dea2011-05-31 21:35:13 -070028import android.os.Parcel;
29import android.os.Parcelable;
Adam Powell27cba382013-01-22 18:55:20 -080030import android.text.Layout;
Adam Powell2a7ea672011-01-23 20:25:15 -080031import android.text.TextUtils;
Adam Powell33b97432010-04-20 10:01:14 -070032import android.util.AttributeSet;
Adam Powell038f1c82011-07-21 14:28:10 -070033import android.view.CollapsibleActionView;
Adam Powell661c9082010-07-02 10:09:44 -070034import android.view.Gravity;
Adam Powell89e06452010-06-23 20:24:52 -070035import android.view.LayoutInflater;
36import android.view.Menu;
Adam Powell8d02dea2011-05-31 21:35:13 -070037import android.view.MenuItem;
Adam Powell7bc3ca02011-08-26 18:29:58 -070038import android.view.MotionEvent;
Adam Powell89e06452010-06-23 20:24:52 -070039import android.view.View;
40import android.view.ViewGroup;
Adam Powell9ab97872010-10-26 21:47:29 -070041import android.view.ViewParent;
Adam Powell8d12e202010-11-15 16:44:17 -080042import android.view.Window;
Adam Powell7bc3ca02011-08-26 18:29:58 -070043import android.view.accessibility.AccessibilityEvent;
Adam Powella4082912010-06-04 18:34:02 -070044import android.widget.AdapterView;
Adam Powell2b0952b2011-03-09 00:15:38 -080045import android.widget.FrameLayout;
Adam Powell33b97432010-04-20 10:01:14 -070046import android.widget.ImageView;
Adam Powell0e94b512010-06-29 17:58:20 -070047import android.widget.LinearLayout;
Adam Powell6af97e12010-11-11 21:11:53 -080048import android.widget.ProgressBar;
Adam Powella4082912010-06-04 18:34:02 -070049import android.widget.Spinner;
50import android.widget.SpinnerAdapter;
Adam Powell33b97432010-04-20 10:01:14 -070051import android.widget.TextView;
Adam Powell04fe6eb2013-05-31 14:39:48 -070052import com.android.internal.R;
53import com.android.internal.view.menu.ActionMenuItem;
54import com.android.internal.view.menu.ActionMenuPresenter;
55import com.android.internal.view.menu.ActionMenuView;
56import com.android.internal.view.menu.MenuBuilder;
57import com.android.internal.view.menu.MenuItemImpl;
58import com.android.internal.view.menu.MenuPresenter;
59import com.android.internal.view.menu.MenuView;
60import com.android.internal.view.menu.SubMenuBuilder;
Adam Powell33b97432010-04-20 10:01:14 -070061
Adam Powell33b97432010-04-20 10:01:14 -070062/**
63 * @hide
64 */
Adam Powell640a66e2011-04-29 10:18:53 -070065public class ActionBarView extends AbsActionBarView {
Adam Powell33b97432010-04-20 10:01:14 -070066 private static final String TAG = "ActionBarView";
Adam Powellbe4d68e2010-10-08 18:16:34 -070067
Adam Powell33b97432010-04-20 10:01:14 -070068 /**
69 * Display options applied by default
70 */
71 public static final int DISPLAY_DEFAULT = 0;
72
73 /**
74 * Display options that require re-layout as opposed to a simple invalidate
75 */
Adam Powella1700782010-05-13 13:27:35 -070076 private static final int DISPLAY_RELAYOUT_MASK =
Adam Powell9ab97872010-10-26 21:47:29 -070077 ActionBar.DISPLAY_SHOW_HOME |
78 ActionBar.DISPLAY_USE_LOGO |
79 ActionBar.DISPLAY_HOME_AS_UP |
80 ActionBar.DISPLAY_SHOW_CUSTOM |
Adam Powell27cba382013-01-22 18:55:20 -080081 ActionBar.DISPLAY_SHOW_TITLE |
82 ActionBar.DISPLAY_TITLE_MULTIPLE_LINES;
Adam Powell9ab97872010-10-26 21:47:29 -070083
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -070084 private static final int DEFAULT_CUSTOM_GRAVITY = Gravity.START | Gravity.CENTER_VERTICAL;
Casey Burkhardt8452a7f2013-04-30 15:56:41 -070085
Adam Powell33b97432010-04-20 10:01:14 -070086 private int mNavigationMode;
Adam Powell82f24e82011-08-18 20:15:20 -070087 private int mDisplayOptions = -1;
Adam Powell33b97432010-04-20 10:01:14 -070088 private CharSequence mTitle;
89 private CharSequence mSubtitle;
90 private Drawable mIcon;
91 private Drawable mLogo;
Adam Powelle0e2f4f2013-04-05 16:27:35 -070092 private CharSequence mHomeDescription;
93 private int mHomeDescriptionRes;
Adam Powell33b97432010-04-20 10:01:14 -070094
Adam Powell8d02dea2011-05-31 21:35:13 -070095 private HomeView mHomeLayout;
96 private HomeView mExpandedHomeLayout;
Adam Powell0e94b512010-06-29 17:58:20 -070097 private LinearLayout mTitleLayout;
Adam Powell33b97432010-04-20 10:01:14 -070098 private TextView mTitleView;
99 private TextView mSubtitleView;
Adam Powell54c7d7e2011-06-17 20:30:13 -0700100 private View mTitleUpView;
Adam Powell27cba382013-01-22 18:55:20 -0800101 private ViewGroup mUpGoerFive;
Adam Powell54c7d7e2011-06-17 20:30:13 -0700102
Adam Powella4082912010-06-04 18:34:02 -0700103 private Spinner mSpinner;
Adam Powell3f7f7ac2010-12-05 16:44:38 -0800104 private LinearLayout mListNavLayout;
Adam Powellf8ac6b72011-05-23 18:14:09 -0700105 private ScrollingTabContainerView mTabScrollView;
Adam Powella4082912010-06-04 18:34:02 -0700106 private View mCustomNavView;
Adam Powell6af97e12010-11-11 21:11:53 -0800107 private ProgressBar mProgressView;
108 private ProgressBar mIndeterminateProgressView;
109
110 private int mProgressBarPadding;
Adam Powell3f7f7ac2010-12-05 16:44:38 -0800111 private int mItemPadding;
Casey Burkhardt8452a7f2013-04-30 15:56:41 -0700112
Adam Powelle2194442010-08-12 18:13:03 -0700113 private int mTitleStyleRes;
114 private int mSubtitleStyleRes;
Adam Powell6af97e12010-11-11 21:11:53 -0800115 private int mProgressStyle;
116 private int mIndeterminateProgressStyle;
Adam Powelle2194442010-08-12 18:13:03 -0700117
Adam Powelle92ea342010-07-14 14:45:50 -0700118 private boolean mUserTitle;
Adam Powelldae78242011-04-25 15:23:41 -0700119 private boolean mIncludeTabs;
Adam Powelld21aa122011-05-27 13:09:52 -0700120 private boolean mIsCollapsable;
Adam Powellf6ce6a92011-06-29 10:25:01 -0700121 private boolean mIsCollapsed;
Adam Powell62f33032013-02-04 12:44:34 -0800122 private boolean mWasHomeEnabled; // Was it enabled before action view expansion?
Adam Powell33b97432010-04-20 10:01:14 -0700123
Adam Powell96675b12010-06-10 18:58:59 -0700124 private MenuBuilder mOptionsMenu;
Adam Powell8c16aa92013-04-04 10:47:52 -0700125 private boolean mMenuPrepared;
Casey Burkhardt8452a7f2013-04-30 15:56:41 -0700126
Adam Powelle2194442010-08-12 18:13:03 -0700127 private ActionBarContextView mContextView;
128
Adam Powell33b97432010-04-20 10:01:14 -0700129 private ActionMenuItem mLogoNavItem;
Adam Powell9ab97872010-10-26 21:47:29 -0700130
131 private SpinnerAdapter mSpinnerAdapter;
Adam Powell8515ee82010-11-30 14:09:55 -0800132 private OnNavigationListener mCallback;
Adam Powell33b97432010-04-20 10:01:14 -0700133
Adam Powellf8ac6b72011-05-23 18:14:09 -0700134 private Runnable mTabSelector;
135
Adam Powell8d02dea2011-05-31 21:35:13 -0700136 private ExpandedActionViewMenuPresenter mExpandedMenuPresenter;
137 View mExpandedActionView;
138
Adam Powell915ce0d2011-09-28 15:52:57 -0700139 Window.Callback mWindowCallback;
140
Adam Powella4082912010-06-04 18:34:02 -0700141 private final AdapterView.OnItemSelectedListener mNavItemSelectedListener =
142 new AdapterView.OnItemSelectedListener() {
143 public void onItemSelected(AdapterView parent, View view, int position, long id) {
144 if (mCallback != null) {
145 mCallback.onNavigationItemSelected(position, id);
146 }
147 }
148 public void onNothingSelected(AdapterView parent) {
149 // Do nothing
150 }
151 };
152
Adam Powell8d02dea2011-05-31 21:35:13 -0700153 private final OnClickListener mExpandedActionViewUpListener = new OnClickListener() {
154 @Override
155 public void onClick(View v) {
156 final MenuItemImpl item = mExpandedMenuPresenter.mCurrentExpandedItem;
157 if (item != null) {
158 item.collapseActionView();
159 }
160 }
161 };
Adam Powell2b6230e2010-09-07 17:55:25 -0700162
Adam Powell54c7d7e2011-06-17 20:30:13 -0700163 private final OnClickListener mUpClickListener = new OnClickListener() {
164 public void onClick(View v) {
Adam Powell8c16aa92013-04-04 10:47:52 -0700165 if (mMenuPrepared) {
166 // Only invoke the window callback if the options menu has been initialized.
167 mWindowCallback.onMenuItemSelected(Window.FEATURE_OPTIONS_PANEL, mLogoNavItem);
168 }
Adam Powell54c7d7e2011-06-17 20:30:13 -0700169 }
170 };
171
Adam Powell33b97432010-04-20 10:01:14 -0700172 public ActionBarView(Context context, AttributeSet attrs) {
173 super(context, attrs);
174
Adam Powell654e4e42011-01-03 16:33:50 -0800175 // Background is always provided by the container.
176 setBackgroundResource(0);
177
Adam Powell45c0b192011-07-28 15:11:57 -0700178 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ActionBar,
179 com.android.internal.R.attr.actionBarStyle, 0);
Adam Powell33b97432010-04-20 10:01:14 -0700180
Adam Powell9ab97872010-10-26 21:47:29 -0700181 ApplicationInfo appInfo = context.getApplicationInfo();
Adam Powell33b97432010-04-20 10:01:14 -0700182 PackageManager pm = context.getPackageManager();
Adam Powell661c9082010-07-02 10:09:44 -0700183 mNavigationMode = a.getInt(R.styleable.ActionBar_navigationMode,
184 ActionBar.NAVIGATION_MODE_STANDARD);
Adam Powell33b97432010-04-20 10:01:14 -0700185 mTitle = a.getText(R.styleable.ActionBar_title);
186 mSubtitle = a.getText(R.styleable.ActionBar_subtitle);
Adam Powell33b97432010-04-20 10:01:14 -0700187 mLogo = a.getDrawable(R.styleable.ActionBar_logo);
Adam Powell33b97432010-04-20 10:01:14 -0700188 mIcon = a.getDrawable(R.styleable.ActionBar_icon);
Adam Powell9ab97872010-10-26 21:47:29 -0700189
Ed Heyl1c603002010-11-18 12:18:23 -0800190 final LayoutInflater inflater = LayoutInflater.from(context);
Adam Powell9ab97872010-10-26 21:47:29 -0700191
Ed Heyl1c603002010-11-18 12:18:23 -0800192 final int homeResId = a.getResourceId(
Adam Powellb33be1c2010-11-18 12:11:40 -0800193 com.android.internal.R.styleable.ActionBar_homeLayout,
194 com.android.internal.R.layout.action_bar_home);
Adam Powell9ab97872010-10-26 21:47:29 -0700195
Adam Powell27cba382013-01-22 18:55:20 -0800196 mUpGoerFive = (ViewGroup) inflater.inflate(
197 com.android.internal.R.layout.action_bar_up_container, this, false);
198 mHomeLayout = (HomeView) inflater.inflate(homeResId, mUpGoerFive, false);
Ed Heyl1c603002010-11-18 12:18:23 -0800199
Adam Powell27cba382013-01-22 18:55:20 -0800200 mExpandedHomeLayout = (HomeView) inflater.inflate(homeResId, mUpGoerFive, false);
Adam Powell8d02dea2011-05-31 21:35:13 -0700201 mExpandedHomeLayout.setUp(true);
202 mExpandedHomeLayout.setOnClickListener(mExpandedActionViewUpListener);
Adam Powell7bc3ca02011-08-26 18:29:58 -0700203 mExpandedHomeLayout.setContentDescription(getResources().getText(
204 R.string.action_bar_up_description));
Casey Burkhardt8452a7f2013-04-30 15:56:41 -0700205
Adam Powell62f33032013-02-04 12:44:34 -0800206 // This needs to highlight/be focusable on its own.
207 // TODO: Clean up the handoff between expanded/normal.
208 final Drawable upBackground = mUpGoerFive.getBackground();
209 if (upBackground != null) {
210 mExpandedHomeLayout.setBackground(upBackground.getConstantState().newDrawable());
211 }
212 mExpandedHomeLayout.setEnabled(true);
213 mExpandedHomeLayout.setFocusable(true);
214
Adam Powelle2194442010-08-12 18:13:03 -0700215 mTitleStyleRes = a.getResourceId(R.styleable.ActionBar_titleTextStyle, 0);
216 mSubtitleStyleRes = a.getResourceId(R.styleable.ActionBar_subtitleTextStyle, 0);
Adam Powell6af97e12010-11-11 21:11:53 -0800217 mProgressStyle = a.getResourceId(R.styleable.ActionBar_progressBarStyle, 0);
218 mIndeterminateProgressStyle = a.getResourceId(
219 R.styleable.ActionBar_indeterminateProgressStyle, 0);
220
221 mProgressBarPadding = a.getDimensionPixelOffset(R.styleable.ActionBar_progressBarPadding, 0);
Adam Powell3f7f7ac2010-12-05 16:44:38 -0800222 mItemPadding = a.getDimensionPixelOffset(R.styleable.ActionBar_itemPadding, 0);
Adam Powelle2194442010-08-12 18:13:03 -0700223
Adam Powell9ab97872010-10-26 21:47:29 -0700224 setDisplayOptions(a.getInt(R.styleable.ActionBar_displayOptions, DISPLAY_DEFAULT));
225
Adam Powell33b97432010-04-20 10:01:14 -0700226 final int customNavId = a.getResourceId(R.styleable.ActionBar_customNavigationLayout, 0);
227 if (customNavId != 0) {
Ed Heyl1c603002010-11-18 12:18:23 -0800228 mCustomNavView = (View) inflater.inflate(customNavId, this, false);
Adam Powell9ab97872010-10-26 21:47:29 -0700229 mNavigationMode = ActionBar.NAVIGATION_MODE_STANDARD;
230 setDisplayOptions(mDisplayOptions | ActionBar.DISPLAY_SHOW_CUSTOM);
Adam Powell33b97432010-04-20 10:01:14 -0700231 }
232
Adam Powelle2194442010-08-12 18:13:03 -0700233 mContentHeight = a.getLayoutDimension(R.styleable.ActionBar_height, 0);
Casey Burkhardt8452a7f2013-04-30 15:56:41 -0700234
Adam Powell33b97432010-04-20 10:01:14 -0700235 a.recycle();
Casey Burkhardt8452a7f2013-04-30 15:56:41 -0700236
Ben Komaload199ec2010-11-01 12:24:16 -0700237 mLogoNavItem = new ActionMenuItem(context, 0, android.R.id.home, 0, 0, mTitle);
Adam Powell27cba382013-01-22 18:55:20 -0800238
239 mUpGoerFive.setOnClickListener(mUpClickListener);
240 mUpGoerFive.setClickable(true);
241 mUpGoerFive.setFocusable(true);
Svetoslav Ganov42138042012-03-20 11:51:39 -0700242
243 if (getImportantForAccessibility() == View.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
244 setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
245 }
Adam Powell33b97432010-04-20 10:01:14 -0700246 }
Adam Powella7db0372010-06-30 17:08:47 -0700247
Patrick Dubroye0a799a2011-05-04 16:19:22 -0700248 @Override
Adam Powell45c0b192011-07-28 15:11:57 -0700249 protected void onConfigurationChanged(Configuration newConfig) {
250 super.onConfigurationChanged(newConfig);
251
Adam Powell07a047f2011-08-31 10:33:20 -0700252 mTitleView = null;
253 mSubtitleView = null;
254 mTitleUpView = null;
Adam Powell27cba382013-01-22 18:55:20 -0800255 if (mTitleLayout != null && mTitleLayout.getParent() == mUpGoerFive) {
256 mUpGoerFive.removeView(mTitleLayout);
Adam Powell07a047f2011-08-31 10:33:20 -0700257 }
258 mTitleLayout = null;
259 if ((mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0) {
260 initTitle();
261 }
Adam Powell425689e2011-09-08 18:09:33 -0700262
Adam Powelle0e2f4f2013-04-05 16:27:35 -0700263 if (mHomeDescriptionRes != 0) {
264 setHomeActionContentDescription(mHomeDescriptionRes);
265 }
266
Adam Powell425689e2011-09-08 18:09:33 -0700267 if (mTabScrollView != null && mIncludeTabs) {
268 ViewGroup.LayoutParams lp = mTabScrollView.getLayoutParams();
Adam Powellb8440112011-09-12 19:14:11 -0700269 if (lp != null) {
270 lp.width = LayoutParams.WRAP_CONTENT;
271 lp.height = LayoutParams.MATCH_PARENT;
272 }
Adam Powell425689e2011-09-08 18:09:33 -0700273 mTabScrollView.setAllowCollapse(true);
274 }
Adam Powell45c0b192011-07-28 15:11:57 -0700275 }
276
Adam Powell915ce0d2011-09-28 15:52:57 -0700277 /**
278 * Set the window callback used to invoke menu items; used for dispatching home button presses.
279 * @param cb Window callback to dispatch to
280 */
281 public void setWindowCallback(Window.Callback cb) {
282 mWindowCallback = cb;
283 }
284
Adam Powell45c0b192011-07-28 15:11:57 -0700285 @Override
Adam Powellf8ac6b72011-05-23 18:14:09 -0700286 public void onDetachedFromWindow() {
287 super.onDetachedFromWindow();
288 removeCallbacks(mTabSelector);
Adam Powell97e18362011-10-20 15:37:18 -0700289 if (mActionMenuPresenter != null) {
290 mActionMenuPresenter.hideOverflowMenu();
291 mActionMenuPresenter.hideSubMenus();
292 }
Adam Powellf8ac6b72011-05-23 18:14:09 -0700293 }
294
295 @Override
Patrick Dubroye0a799a2011-05-04 16:19:22 -0700296 public boolean shouldDelayChildPressedState() {
297 return false;
298 }
299
Adam Powell6af97e12010-11-11 21:11:53 -0800300 public void initProgress() {
301 mProgressView = new ProgressBar(mContext, null, 0, mProgressStyle);
302 mProgressView.setId(R.id.progress_horizontal);
303 mProgressView.setMax(10000);
Adam Powell45b075d2012-01-09 15:41:40 -0800304 mProgressView.setVisibility(GONE);
Adam Powell6af97e12010-11-11 21:11:53 -0800305 addView(mProgressView);
306 }
307
308 public void initIndeterminateProgress() {
309 mIndeterminateProgressView = new ProgressBar(mContext, null, 0,
310 mIndeterminateProgressStyle);
311 mIndeterminateProgressView.setId(R.id.progress_circular);
Adam Powell45b075d2012-01-09 15:41:40 -0800312 mIndeterminateProgressView.setVisibility(GONE);
Adam Powell6af97e12010-11-11 21:11:53 -0800313 addView(mIndeterminateProgressView);
314 }
315
Adam Powella05aba92011-09-23 14:22:49 -0700316 @Override
Adam Powell9b4bee02011-04-27 19:24:47 -0700317 public void setSplitActionBar(boolean splitActionBar) {
318 if (mSplitActionBar != splitActionBar) {
319 if (mMenuView != null) {
Adam Powell894bf542011-07-22 13:39:08 -0700320 final ViewGroup oldParent = (ViewGroup) mMenuView.getParent();
321 if (oldParent != null) {
322 oldParent.removeView(mMenuView);
323 }
Adam Powell9b4bee02011-04-27 19:24:47 -0700324 if (splitActionBar) {
Adam Powell9b4bee02011-04-27 19:24:47 -0700325 if (mSplitView != null) {
326 mSplitView.addView(mMenuView);
327 }
Adam Powellf203e0a2012-03-06 17:40:12 -0800328 mMenuView.getLayoutParams().width = LayoutParams.MATCH_PARENT;
Adam Powell9b4bee02011-04-27 19:24:47 -0700329 } else {
330 addView(mMenuView);
Adam Powellf203e0a2012-03-06 17:40:12 -0800331 mMenuView.getLayoutParams().width = LayoutParams.WRAP_CONTENT;
Adam Powell9b4bee02011-04-27 19:24:47 -0700332 }
Adam Powellf203e0a2012-03-06 17:40:12 -0800333 mMenuView.requestLayout();
Adam Powell9b4bee02011-04-27 19:24:47 -0700334 }
Adam Powella05aba92011-09-23 14:22:49 -0700335 if (mSplitView != null) {
336 mSplitView.setVisibility(splitActionBar ? VISIBLE : GONE);
337 }
Adam Powellf203e0a2012-03-06 17:40:12 -0800338
339 if (mActionMenuPresenter != null) {
340 if (!splitActionBar) {
341 mActionMenuPresenter.setExpandedActionViewsExclusive(
342 getResources().getBoolean(
343 com.android.internal.R.bool.action_bar_expanded_action_views_exclusive));
344 } else {
345 mActionMenuPresenter.setExpandedActionViewsExclusive(false);
346 // Allow full screen width in split mode.
347 mActionMenuPresenter.setWidthLimit(
348 getContext().getResources().getDisplayMetrics().widthPixels, true);
349 // No limit to the item count; use whatever will fit.
350 mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE);
351 }
352 }
Adam Powella05aba92011-09-23 14:22:49 -0700353 super.setSplitActionBar(splitActionBar);
Adam Powell9b4bee02011-04-27 19:24:47 -0700354 }
355 }
356
357 public boolean isSplitActionBar() {
358 return mSplitActionBar;
359 }
360
Adam Powelldae78242011-04-25 15:23:41 -0700361 public boolean hasEmbeddedTabs() {
362 return mIncludeTabs;
363 }
364
Adam Powellf8ac6b72011-05-23 18:14:09 -0700365 public void setEmbeddedTabView(ScrollingTabContainerView tabs) {
Adam Powelle0adac02011-06-14 13:46:30 -0700366 if (mTabScrollView != null) {
367 removeView(mTabScrollView);
368 }
Adam Powellf8ac6b72011-05-23 18:14:09 -0700369 mTabScrollView = tabs;
370 mIncludeTabs = tabs != null;
Adam Powellc3076422011-06-01 18:19:04 -0700371 if (mIncludeTabs && mNavigationMode == ActionBar.NAVIGATION_MODE_TABS) {
Adam Powell39a8dc42011-05-27 18:44:00 -0700372 addView(mTabScrollView);
Adam Powellf5645cb2011-08-10 22:49:02 -0700373 ViewGroup.LayoutParams lp = mTabScrollView.getLayoutParams();
374 lp.width = LayoutParams.WRAP_CONTENT;
375 lp.height = LayoutParams.MATCH_PARENT;
376 tabs.setAllowCollapse(true);
Adam Powell39a8dc42011-05-27 18:44:00 -0700377 }
Adam Powelldae78242011-04-25 15:23:41 -0700378 }
379
Adam Powell8515ee82010-11-30 14:09:55 -0800380 public void setCallback(OnNavigationListener callback) {
Adam Powell96675b12010-06-10 18:58:59 -0700381 mCallback = callback;
Adam Powell33b97432010-04-20 10:01:14 -0700382 }
Adam Powella7db0372010-06-30 17:08:47 -0700383
Adam Powell8c16aa92013-04-04 10:47:52 -0700384 public void setMenuPrepared() {
385 mMenuPrepared = true;
386 }
387
Adam Powell696cba52011-03-29 10:38:16 -0700388 public void setMenu(Menu menu, MenuPresenter.Callback cb) {
Adam Powellf2d7a5d2011-02-07 18:05:24 -0800389 if (menu == mOptionsMenu) return;
390
Adam Powell696cba52011-03-29 10:38:16 -0700391 if (mOptionsMenu != null) {
Adam Powell8d02dea2011-05-31 21:35:13 -0700392 mOptionsMenu.removeMenuPresenter(mActionMenuPresenter);
393 mOptionsMenu.removeMenuPresenter(mExpandedMenuPresenter);
Adam Powell696cba52011-03-29 10:38:16 -0700394 }
395
Adam Powell96675b12010-06-10 18:58:59 -0700396 MenuBuilder builder = (MenuBuilder) menu;
397 mOptionsMenu = builder;
398 if (mMenuView != null) {
Adam Powell894bf542011-07-22 13:39:08 -0700399 final ViewGroup oldParent = (ViewGroup) mMenuView.getParent();
400 if (oldParent != null) {
401 oldParent.removeView(mMenuView);
402 }
Adam Powell33b97432010-04-20 10:01:14 -0700403 }
Adam Powell8d02dea2011-05-31 21:35:13 -0700404 if (mActionMenuPresenter == null) {
Adam Powell538e5652011-10-11 13:47:08 -0700405 mActionMenuPresenter = new ActionMenuPresenter(mContext);
Adam Powell8d02dea2011-05-31 21:35:13 -0700406 mActionMenuPresenter.setCallback(cb);
Adam Powell11ed1d62011-07-11 21:19:59 -0700407 mActionMenuPresenter.setId(com.android.internal.R.id.action_menu_presenter);
Adam Powell8d02dea2011-05-31 21:35:13 -0700408 mExpandedMenuPresenter = new ExpandedActionViewMenuPresenter();
Adam Powell696cba52011-03-29 10:38:16 -0700409 }
Adam Powell35265562011-05-27 15:29:41 -0700410
Adam Powell1ab418a2011-06-09 20:49:49 -0700411 ActionMenuView menuView;
Adam Powell96675b12010-06-10 18:58:59 -0700412 final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
413 LayoutParams.MATCH_PARENT);
Adam Powell9b4bee02011-04-27 19:24:47 -0700414 if (!mSplitActionBar) {
Adam Powellb187cd92011-07-20 14:17:56 -0700415 mActionMenuPresenter.setExpandedActionViewsExclusive(
416 getResources().getBoolean(
417 com.android.internal.R.bool.action_bar_expanded_action_views_exclusive));
Adam Powellf35d0492011-08-17 13:56:47 -0700418 configPresenters(builder);
Adam Powell1ab418a2011-06-09 20:49:49 -0700419 menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
Adam Powell894bf542011-07-22 13:39:08 -0700420 final ViewGroup oldParent = (ViewGroup) menuView.getParent();
421 if (oldParent != null && oldParent != this) {
422 oldParent.removeView(menuView);
423 }
Adam Powell1ab418a2011-06-09 20:49:49 -0700424 addView(menuView, layoutParams);
Adam Powell9b4bee02011-04-27 19:24:47 -0700425 } else {
Adam Powellb187cd92011-07-20 14:17:56 -0700426 mActionMenuPresenter.setExpandedActionViewsExclusive(false);
Adam Powell9b4bee02011-04-27 19:24:47 -0700427 // Allow full screen width in split mode.
Adam Powell8d02dea2011-05-31 21:35:13 -0700428 mActionMenuPresenter.setWidthLimit(
Adam Powell640a66e2011-04-29 10:18:53 -0700429 getContext().getResources().getDisplayMetrics().widthPixels, true);
Adam Powell9b4bee02011-04-27 19:24:47 -0700430 // No limit to the item count; use whatever will fit.
Adam Powell8d02dea2011-05-31 21:35:13 -0700431 mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE);
Adam Powell640a66e2011-04-29 10:18:53 -0700432 // Span the whole width
433 layoutParams.width = LayoutParams.MATCH_PARENT;
Adam Powellf35d0492011-08-17 13:56:47 -0700434 configPresenters(builder);
Adam Powell1ab418a2011-06-09 20:49:49 -0700435 menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
Adam Powell9b4bee02011-04-27 19:24:47 -0700436 if (mSplitView != null) {
Adam Powell894bf542011-07-22 13:39:08 -0700437 final ViewGroup oldParent = (ViewGroup) menuView.getParent();
438 if (oldParent != null && oldParent != mSplitView) {
439 oldParent.removeView(menuView);
440 }
Adam Powell9a5cc282011-08-28 16:18:16 -0700441 menuView.setVisibility(getAnimatedVisibility());
Adam Powell1ab418a2011-06-09 20:49:49 -0700442 mSplitView.addView(menuView, layoutParams);
443 } else {
444 // We'll add this later if we missed it this time.
445 menuView.setLayoutParams(layoutParams);
446 }
Adam Powell9b4bee02011-04-27 19:24:47 -0700447 }
Adam Powell96675b12010-06-10 18:58:59 -0700448 mMenuView = menuView;
Adam Powell33b97432010-04-20 10:01:14 -0700449 }
Adam Powella7db0372010-06-30 17:08:47 -0700450
Adam Powellf35d0492011-08-17 13:56:47 -0700451 private void configPresenters(MenuBuilder builder) {
452 if (builder != null) {
453 builder.addMenuPresenter(mActionMenuPresenter);
454 builder.addMenuPresenter(mExpandedMenuPresenter);
455 } else {
456 mActionMenuPresenter.initForMenu(mContext, null);
457 mExpandedMenuPresenter.initForMenu(mContext, null);
458 mActionMenuPresenter.updateMenuView(true);
459 mExpandedMenuPresenter.updateMenuView(true);
460 }
461 }
462
Adam Powellb80d3322011-07-15 21:33:11 -0700463 public boolean hasExpandedActionView() {
464 return mExpandedMenuPresenter != null &&
465 mExpandedMenuPresenter.mCurrentExpandedItem != null;
466 }
467
468 public void collapseActionView() {
469 final MenuItemImpl item = mExpandedMenuPresenter == null ? null :
470 mExpandedMenuPresenter.mCurrentExpandedItem;
471 if (item != null) {
472 item.collapseActionView();
473 }
474 }
475
Adam Powell33b97432010-04-20 10:01:14 -0700476 public void setCustomNavigationView(View view) {
Adam Powell9ab97872010-10-26 21:47:29 -0700477 final boolean showCustom = (mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0;
478 if (mCustomNavView != null && showCustom) {
479 removeView(mCustomNavView);
480 }
Adam Powella4082912010-06-04 18:34:02 -0700481 mCustomNavView = view;
Adam Powell9ab97872010-10-26 21:47:29 -0700482 if (mCustomNavView != null && showCustom) {
483 addView(mCustomNavView);
Adam Powell33b97432010-04-20 10:01:14 -0700484 }
Adam Powell33b97432010-04-20 10:01:14 -0700485 }
Adam Powella7db0372010-06-30 17:08:47 -0700486
Adam Powell33b97432010-04-20 10:01:14 -0700487 public CharSequence getTitle() {
488 return mTitle;
489 }
Adam Powella7db0372010-06-30 17:08:47 -0700490
Adam Powelle92ea342010-07-14 14:45:50 -0700491 /**
492 * Set the action bar title. This will always replace or override window titles.
493 * @param title Title to set
494 *
495 * @see #setWindowTitle(CharSequence)
496 */
Adam Powell33b97432010-04-20 10:01:14 -0700497 public void setTitle(CharSequence title) {
Adam Powelle92ea342010-07-14 14:45:50 -0700498 mUserTitle = true;
499 setTitleImpl(title);
500 }
501
502 /**
503 * Set the window title. A window title will always be replaced or overridden by a user title.
504 * @param title Title to set
505 *
506 * @see #setTitle(CharSequence)
507 */
508 public void setWindowTitle(CharSequence title) {
509 if (!mUserTitle) {
510 setTitleImpl(title);
511 }
512 }
513
514 private void setTitleImpl(CharSequence title) {
Adam Powell33b97432010-04-20 10:01:14 -0700515 mTitle = title;
516 if (mTitleView != null) {
517 mTitleView.setText(title);
Adam Powellb0e217e2011-08-12 11:36:51 -0700518 final boolean visible = mExpandedActionView == null &&
Adam Powell71f34172011-08-11 20:07:11 -0700519 (mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0 &&
Adam Powellb0e217e2011-08-12 11:36:51 -0700520 (!TextUtils.isEmpty(mTitle) || !TextUtils.isEmpty(mSubtitle));
521 mTitleLayout.setVisibility(visible ? VISIBLE : GONE);
Adam Powell33b97432010-04-20 10:01:14 -0700522 }
523 if (mLogoNavItem != null) {
524 mLogoNavItem.setTitle(title);
525 }
Casey Burkhardt8452a7f2013-04-30 15:56:41 -0700526 mUpGoerFive.setContentDescription(buildHomeContentDescription());
Adam Powell33b97432010-04-20 10:01:14 -0700527 }
Adam Powella7db0372010-06-30 17:08:47 -0700528
Adam Powell33b97432010-04-20 10:01:14 -0700529 public CharSequence getSubtitle() {
530 return mSubtitle;
531 }
Adam Powella7db0372010-06-30 17:08:47 -0700532
Adam Powell33b97432010-04-20 10:01:14 -0700533 public void setSubtitle(CharSequence subtitle) {
534 mSubtitle = subtitle;
535 if (mSubtitleView != null) {
536 mSubtitleView.setText(subtitle);
Adam Powell04587962010-11-11 22:15:07 -0800537 mSubtitleView.setVisibility(subtitle != null ? VISIBLE : GONE);
Adam Powellb0e217e2011-08-12 11:36:51 -0700538 final boolean visible = mExpandedActionView == null &&
Adam Powell71f34172011-08-11 20:07:11 -0700539 (mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0 &&
Adam Powellb0e217e2011-08-12 11:36:51 -0700540 (!TextUtils.isEmpty(mTitle) || !TextUtils.isEmpty(mSubtitle));
541 mTitleLayout.setVisibility(visible ? VISIBLE : GONE);
Adam Powell33b97432010-04-20 10:01:14 -0700542 }
Casey Burkhardt8452a7f2013-04-30 15:56:41 -0700543 mUpGoerFive.setContentDescription(buildHomeContentDescription());
Adam Powell33b97432010-04-20 10:01:14 -0700544 }
Adam Powella7db0372010-06-30 17:08:47 -0700545
Adam Powellc29f4e52011-07-13 20:40:52 -0700546 public void setHomeButtonEnabled(boolean enable) {
Adam Powell07cf9712013-02-05 16:13:57 -0800547 setHomeButtonEnabled(enable, true);
548 }
549
550 private void setHomeButtonEnabled(boolean enable, boolean recordState) {
551 if (recordState) {
552 mWasHomeEnabled = enable;
553 }
554
555 if (mExpandedActionView != null) {
556 // There's an action view currently showing and we want to keep the state
557 // configured for the action view at the moment. If we needed to record the
558 // new state for later we will have done so above.
559 return;
560 }
561
Adam Powell27cba382013-01-22 18:55:20 -0800562 mUpGoerFive.setEnabled(enable);
563 mUpGoerFive.setFocusable(enable);
Adam Powellc29f4e52011-07-13 20:40:52 -0700564 // Make sure the home button has an accurate content description for accessibility.
565 if (!enable) {
Adam Powell27cba382013-01-22 18:55:20 -0800566 mUpGoerFive.setContentDescription(null);
567 mUpGoerFive.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
Adam Powellc29f4e52011-07-13 20:40:52 -0700568 } else {
Adam Powell27cba382013-01-22 18:55:20 -0800569 mUpGoerFive.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_AUTO);
Adam Powelle0e2f4f2013-04-05 16:27:35 -0700570 mUpGoerFive.setContentDescription(buildHomeContentDescription());
571 }
572 }
573
574 /**
575 * Compose a content description for the Home/Up affordance.
576 *
577 * <p>As this encompasses the icon/logo, title and subtitle all in one, we need
578 * a description for the whole wad of stuff that can be localized properly.</p>
579 */
580 private CharSequence buildHomeContentDescription() {
581 final CharSequence homeDesc;
582 if (mHomeDescription != null) {
583 homeDesc = mHomeDescription;
584 } else {
Casey Burkhardt4aeb9612012-10-01 14:13:41 -0700585 if ((mDisplayOptions & ActionBar.DISPLAY_HOME_AS_UP) != 0) {
Adam Powelle0e2f4f2013-04-05 16:27:35 -0700586 homeDesc = mContext.getResources().getText(R.string.action_bar_up_description);
Casey Burkhardt4aeb9612012-10-01 14:13:41 -0700587 } else {
Adam Powelle0e2f4f2013-04-05 16:27:35 -0700588 homeDesc = mContext.getResources().getText(R.string.action_bar_home_description);
Casey Burkhardt4aeb9612012-10-01 14:13:41 -0700589 }
Adam Powellc29f4e52011-07-13 20:40:52 -0700590 }
Adam Powelle0e2f4f2013-04-05 16:27:35 -0700591
592 final CharSequence title = getTitle();
593 final CharSequence subtitle = getSubtitle();
594 if (!TextUtils.isEmpty(title)) {
595 final String result;
596 if (!TextUtils.isEmpty(subtitle)) {
597 result = getResources().getString(
598 R.string.action_bar_home_subtitle_description_format,
599 title, subtitle, homeDesc);
600 } else {
601 result = getResources().getString(R.string.action_bar_home_description_format,
602 title, homeDesc);
603 }
604 return result;
605 }
606 return homeDesc;
Adam Powellc29f4e52011-07-13 20:40:52 -0700607 }
608
Adam Powell33b97432010-04-20 10:01:14 -0700609 public void setDisplayOptions(int options) {
Adam Powell82f24e82011-08-18 20:15:20 -0700610 final int flagsChanged = mDisplayOptions == -1 ? -1 : options ^ mDisplayOptions;
Adam Powell33b97432010-04-20 10:01:14 -0700611 mDisplayOptions = options;
Adam Powelldae78242011-04-25 15:23:41 -0700612
Adam Powell33b97432010-04-20 10:01:14 -0700613 if ((flagsChanged & DISPLAY_RELAYOUT_MASK) != 0) {
Adam Powell54c7d7e2011-06-17 20:30:13 -0700614 final boolean showHome = (options & ActionBar.DISPLAY_SHOW_HOME) != 0;
Adam Powella8743f12011-11-11 18:35:53 -0800615 final int vis = showHome && mExpandedActionView == null ? VISIBLE : GONE;
Adam Powell9ab97872010-10-26 21:47:29 -0700616 mHomeLayout.setVisibility(vis);
617
618 if ((flagsChanged & ActionBar.DISPLAY_HOME_AS_UP) != 0) {
Adam Powellc29f4e52011-07-13 20:40:52 -0700619 final boolean setUp = (options & ActionBar.DISPLAY_HOME_AS_UP) != 0;
620 mHomeLayout.setUp(setUp);
621
622 // Showing home as up implicitly enables interaction with it.
623 // In honeycomb it was always enabled, so make this transition
624 // a bit easier for developers in the common case.
625 // (It would be silly to show it as up without responding to it.)
626 if (setUp) {
627 setHomeButtonEnabled(true);
628 }
Adam Powella1700782010-05-13 13:27:35 -0700629 }
Adam Powell9ab97872010-10-26 21:47:29 -0700630
Ed Heyl1c603002010-11-18 12:18:23 -0800631 if ((flagsChanged & ActionBar.DISPLAY_USE_LOGO) != 0) {
632 final boolean logoVis = mLogo != null && (options & ActionBar.DISPLAY_USE_LOGO) != 0;
Adam Powell8d02dea2011-05-31 21:35:13 -0700633 mHomeLayout.setIcon(logoVis ? mLogo : mIcon);
Adam Powell9ab97872010-10-26 21:47:29 -0700634 }
635
636 if ((flagsChanged & ActionBar.DISPLAY_SHOW_TITLE) != 0) {
637 if ((options & ActionBar.DISPLAY_SHOW_TITLE) != 0) {
638 initTitle();
639 } else {
Adam Powell27cba382013-01-22 18:55:20 -0800640 mUpGoerFive.removeView(mTitleLayout);
Adam Powell9ab97872010-10-26 21:47:29 -0700641 }
642 }
643
Adam Powell15a16a82011-06-20 10:35:27 -0700644 if (mTitleLayout != null && (flagsChanged &
Adam Powell54c7d7e2011-06-17 20:30:13 -0700645 (ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME)) != 0) {
Adam Powellb1e2f252011-08-22 17:42:12 -0700646 final boolean homeAsUp = (mDisplayOptions & ActionBar.DISPLAY_HOME_AS_UP) != 0;
647 mTitleUpView.setVisibility(!showHome ? (homeAsUp ? VISIBLE : INVISIBLE) : GONE);
Adam Powell54c7d7e2011-06-17 20:30:13 -0700648 }
649
Adam Powell9ab97872010-10-26 21:47:29 -0700650 if ((flagsChanged & ActionBar.DISPLAY_SHOW_CUSTOM) != 0 && mCustomNavView != null) {
651 if ((options & ActionBar.DISPLAY_SHOW_CUSTOM) != 0) {
652 addView(mCustomNavView);
653 } else {
654 removeView(mCustomNavView);
655 }
Adam Powella1700782010-05-13 13:27:35 -0700656 }
Casey Burkhardt8452a7f2013-04-30 15:56:41 -0700657
Adam Powell27cba382013-01-22 18:55:20 -0800658 if (mTitleLayout != null &&
659 (flagsChanged & ActionBar.DISPLAY_TITLE_MULTIPLE_LINES) != 0) {
660 if ((options & ActionBar.DISPLAY_TITLE_MULTIPLE_LINES) != 0) {
661 mTitleView.setSingleLine(false);
662 mTitleView.setMaxLines(2);
663 } else {
664 mTitleView.setMaxLines(1);
665 mTitleView.setSingleLine(true);
666 }
667 }
668
Adam Powell33b97432010-04-20 10:01:14 -0700669 requestLayout();
670 } else {
671 invalidate();
672 }
Adam Powellf3cd1d92011-04-26 17:31:52 -0700673
674 // Make sure the home button has an accurate content description for accessibility.
Adam Powellc29f4e52011-07-13 20:40:52 -0700675 if (!mHomeLayout.isEnabled()) {
Adam Powellf3cd1d92011-04-26 17:31:52 -0700676 mHomeLayout.setContentDescription(null);
Casey Burkhardt4aeb9612012-10-01 14:13:41 -0700677 mHomeLayout.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
Adam Powellf3cd1d92011-04-26 17:31:52 -0700678 } else {
Casey Burkhardt4aeb9612012-10-01 14:13:41 -0700679 mHomeLayout.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_AUTO);
680 if ((options & ActionBar.DISPLAY_HOME_AS_UP) != 0) {
681 mHomeLayout.setContentDescription(mContext.getResources().getText(
682 R.string.action_bar_up_description));
683 } else {
684 mHomeLayout.setContentDescription(mContext.getResources().getText(
685 R.string.action_bar_home_description));
686 }
Adam Powellf3cd1d92011-04-26 17:31:52 -0700687 }
Adam Powell33b97432010-04-20 10:01:14 -0700688 }
689
Adam Powell1969b872011-03-22 11:52:48 -0700690 public void setIcon(Drawable icon) {
691 mIcon = icon;
692 if (icon != null &&
693 ((mDisplayOptions & ActionBar.DISPLAY_USE_LOGO) == 0 || mLogo == null)) {
Adam Powell8d02dea2011-05-31 21:35:13 -0700694 mHomeLayout.setIcon(icon);
Adam Powell1969b872011-03-22 11:52:48 -0700695 }
Adam Powellf8218192012-02-21 17:10:10 -0800696 if (mExpandedActionView != null) {
697 mExpandedHomeLayout.setIcon(mIcon.getConstantState().newDrawable(getResources()));
698 }
Adam Powell1969b872011-03-22 11:52:48 -0700699 }
700
Adam Powell45c515b2011-04-21 18:50:20 -0700701 public void setIcon(int resId) {
Adam Powell04fe6eb2013-05-31 14:39:48 -0700702 setIcon(resId != 0 ? mContext.getResources().getDrawable(resId) : null);
703 }
704
705 public boolean hasIcon() {
706 return mIcon != null;
Adam Powell45c515b2011-04-21 18:50:20 -0700707 }
708
Adam Powell1969b872011-03-22 11:52:48 -0700709 public void setLogo(Drawable logo) {
710 mLogo = logo;
711 if (logo != null && (mDisplayOptions & ActionBar.DISPLAY_USE_LOGO) != 0) {
Adam Powell8d02dea2011-05-31 21:35:13 -0700712 mHomeLayout.setIcon(logo);
Adam Powell1969b872011-03-22 11:52:48 -0700713 }
714 }
715
Adam Powell45c515b2011-04-21 18:50:20 -0700716 public void setLogo(int resId) {
Adam Powell04fe6eb2013-05-31 14:39:48 -0700717 setLogo(resId != 0 ? mContext.getResources().getDrawable(resId) : null);
718 }
719
720 public boolean hasLogo() {
721 return mLogo != null;
Adam Powell45c515b2011-04-21 18:50:20 -0700722 }
723
Adam Powell33b97432010-04-20 10:01:14 -0700724 public void setNavigationMode(int mode) {
Adam Powella1700782010-05-13 13:27:35 -0700725 final int oldMode = mNavigationMode;
726 if (mode != oldMode) {
727 switch (oldMode) {
Adam Powell9ab97872010-10-26 21:47:29 -0700728 case ActionBar.NAVIGATION_MODE_LIST:
Adam Powellc3076422011-06-01 18:19:04 -0700729 if (mListNavLayout != null) {
Adam Powell3f7f7ac2010-12-05 16:44:38 -0800730 removeView(mListNavLayout);
Adam Powella4082912010-06-04 18:34:02 -0700731 }
732 break;
Adam Powell661c9082010-07-02 10:09:44 -0700733 case ActionBar.NAVIGATION_MODE_TABS:
Adam Powellf8ac6b72011-05-23 18:14:09 -0700734 if (mTabScrollView != null && mIncludeTabs) {
Adam Powell2b6230e2010-09-07 17:55:25 -0700735 removeView(mTabScrollView);
Adam Powell661c9082010-07-02 10:09:44 -0700736 }
Adam Powella1700782010-05-13 13:27:35 -0700737 }
Casey Burkhardt8452a7f2013-04-30 15:56:41 -0700738
Adam Powella1700782010-05-13 13:27:35 -0700739 switch (mode) {
Adam Powell9ab97872010-10-26 21:47:29 -0700740 case ActionBar.NAVIGATION_MODE_LIST:
Adam Powell3f7f7ac2010-12-05 16:44:38 -0800741 if (mSpinner == null) {
742 mSpinner = new Spinner(mContext, null,
743 com.android.internal.R.attr.actionDropDownStyle);
Adam Powell29c04ef2012-12-10 15:42:22 -0800744 mSpinner.setId(com.android.internal.R.id.action_bar_spinner);
Adam Powell3f7f7ac2010-12-05 16:44:38 -0800745 mListNavLayout = new LinearLayout(mContext, null,
746 com.android.internal.R.attr.actionBarTabBarStyle);
747 LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
Adam Powelle7d46842011-01-13 21:36:09 -0800748 LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
Adam Powell3f7f7ac2010-12-05 16:44:38 -0800749 params.gravity = Gravity.CENTER;
750 mListNavLayout.addView(mSpinner, params);
751 }
752 if (mSpinner.getAdapter() != mSpinnerAdapter) {
753 mSpinner.setAdapter(mSpinnerAdapter);
754 }
Adam Powella4082912010-06-04 18:34:02 -0700755 mSpinner.setOnItemSelectedListener(mNavItemSelectedListener);
Adam Powell3f7f7ac2010-12-05 16:44:38 -0800756 addView(mListNavLayout);
Adam Powella4082912010-06-04 18:34:02 -0700757 break;
Adam Powell661c9082010-07-02 10:09:44 -0700758 case ActionBar.NAVIGATION_MODE_TABS:
Adam Powellf8ac6b72011-05-23 18:14:09 -0700759 if (mTabScrollView != null && mIncludeTabs) {
Adam Powelldae78242011-04-25 15:23:41 -0700760 addView(mTabScrollView);
761 }
Adam Powell661c9082010-07-02 10:09:44 -0700762 break;
Adam Powella1700782010-05-13 13:27:35 -0700763 }
Adam Powell33b97432010-04-20 10:01:14 -0700764 mNavigationMode = mode;
765 requestLayout();
766 }
767 }
Adam Powelldae78242011-04-25 15:23:41 -0700768
Adam Powella4082912010-06-04 18:34:02 -0700769 public void setDropdownAdapter(SpinnerAdapter adapter) {
Adam Powell9ab97872010-10-26 21:47:29 -0700770 mSpinnerAdapter = adapter;
771 if (mSpinner != null) {
772 mSpinner.setAdapter(adapter);
773 }
774 }
775
776 public SpinnerAdapter getDropdownAdapter() {
777 return mSpinnerAdapter;
Adam Powella4082912010-06-04 18:34:02 -0700778 }
Adam Powell17809772010-07-21 13:25:11 -0700779
780 public void setDropdownSelectedPosition(int position) {
781 mSpinner.setSelection(position);
782 }
783
784 public int getDropdownSelectedPosition() {
785 return mSpinner.getSelectedItemPosition();
786 }
787
Adam Powell33b97432010-04-20 10:01:14 -0700788 public View getCustomNavigationView() {
Adam Powella4082912010-06-04 18:34:02 -0700789 return mCustomNavView;
Adam Powell33b97432010-04-20 10:01:14 -0700790 }
Casey Burkhardt8452a7f2013-04-30 15:56:41 -0700791
Adam Powell33b97432010-04-20 10:01:14 -0700792 public int getNavigationMode() {
793 return mNavigationMode;
794 }
Casey Burkhardt8452a7f2013-04-30 15:56:41 -0700795
Adam Powell33b97432010-04-20 10:01:14 -0700796 public int getDisplayOptions() {
797 return mDisplayOptions;
798 }
Adam Powella7db0372010-06-30 17:08:47 -0700799
800 @Override
Adam Powell9a5cc282011-08-28 16:18:16 -0700801 protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
Adam Powella7db0372010-06-30 17:08:47 -0700802 // Used by custom nav views if they don't supply layout params. Everything else
803 // added to an ActionBarView should have them already.
Adam Powell9ab97872010-10-26 21:47:29 -0700804 return new ActionBar.LayoutParams(DEFAULT_CUSTOM_GRAVITY);
Adam Powella7db0372010-06-30 17:08:47 -0700805 }
806
Adam Powell33b97432010-04-20 10:01:14 -0700807 @Override
808 protected void onFinishInflate() {
809 super.onFinishInflate();
810
Adam Powell27cba382013-01-22 18:55:20 -0800811 mUpGoerFive.addView(mHomeLayout, 0);
812 addView(mUpGoerFive);
Adam Powell9ab97872010-10-26 21:47:29 -0700813
Adam Powell9ab97872010-10-26 21:47:29 -0700814 if (mCustomNavView != null && (mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0) {
815 final ViewParent parent = mCustomNavView.getParent();
816 if (parent != this) {
817 if (parent instanceof ViewGroup) {
818 ((ViewGroup) parent).removeView(mCustomNavView);
819 }
Adam Powella4082912010-06-04 18:34:02 -0700820 addView(mCustomNavView);
Adam Powell33b97432010-04-20 10:01:14 -0700821 }
Adam Powell33b97432010-04-20 10:01:14 -0700822 }
823 }
Adam Powellc8b0b002011-06-23 14:39:05 -0700824
Adam Powella1700782010-05-13 13:27:35 -0700825 private void initTitle() {
Adam Powell15a16a82011-06-20 10:35:27 -0700826 if (mTitleLayout == null) {
827 LayoutInflater inflater = LayoutInflater.from(getContext());
Adam Powell9e58df52011-08-15 17:06:49 -0700828 mTitleLayout = (LinearLayout) inflater.inflate(R.layout.action_bar_title_item,
829 this, false);
Adam Powell15a16a82011-06-20 10:35:27 -0700830 mTitleView = (TextView) mTitleLayout.findViewById(R.id.action_bar_title);
831 mSubtitleView = (TextView) mTitleLayout.findViewById(R.id.action_bar_subtitle);
832 mTitleUpView = (View) mTitleLayout.findViewById(R.id.up);
Adam Powell54c7d7e2011-06-17 20:30:13 -0700833
Adam Powell15a16a82011-06-20 10:35:27 -0700834 if (mTitleStyleRes != 0) {
835 mTitleView.setTextAppearance(mContext, mTitleStyleRes);
836 }
837 if (mTitle != null) {
838 mTitleView.setText(mTitle);
839 }
Adam Powelle2194442010-08-12 18:13:03 -0700840
Adam Powell15a16a82011-06-20 10:35:27 -0700841 if (mSubtitleStyleRes != 0) {
842 mSubtitleView.setTextAppearance(mContext, mSubtitleStyleRes);
843 }
844 if (mSubtitle != null) {
845 mSubtitleView.setText(mSubtitle);
846 mSubtitleView.setVisibility(VISIBLE);
847 }
848
849 final boolean homeAsUp = (mDisplayOptions & ActionBar.DISPLAY_HOME_AS_UP) != 0;
Adam Powellb1e2f252011-08-22 17:42:12 -0700850 final boolean showHome = (mDisplayOptions & ActionBar.DISPLAY_SHOW_HOME) != 0;
Adam Powell6231ab82012-06-22 14:08:11 -0700851 final boolean showTitleUp = !showHome;
852 mTitleUpView.setVisibility(showTitleUp ? (homeAsUp ? VISIBLE : INVISIBLE) : GONE);
Adam Powell0e94b512010-06-29 17:58:20 -0700853 }
Adam Powelle2194442010-08-12 18:13:03 -0700854
Adam Powell27cba382013-01-22 18:55:20 -0800855 mUpGoerFive.addView(mTitleLayout);
Adam Powell82f24e82011-08-18 20:15:20 -0700856 if (mExpandedActionView != null ||
857 (TextUtils.isEmpty(mTitle) && TextUtils.isEmpty(mSubtitle))) {
858 // Don't show while in expanded mode or with empty text
Adam Powell71f34172011-08-11 20:07:11 -0700859 mTitleLayout.setVisibility(GONE);
Adam Powell6684e922013-03-26 15:38:26 -0700860 } else {
861 mTitleLayout.setVisibility(VISIBLE);
Adam Powell71f34172011-08-11 20:07:11 -0700862 }
Adam Powella1700782010-05-13 13:27:35 -0700863 }
Adam Powell33b97432010-04-20 10:01:14 -0700864
Adam Powelle2194442010-08-12 18:13:03 -0700865 public void setContextView(ActionBarContextView view) {
866 mContextView = view;
867 }
868
Adam Powelld21aa122011-05-27 13:09:52 -0700869 public void setCollapsable(boolean collapsable) {
870 mIsCollapsable = collapsable;
871 }
872
Adam Powellf6ce6a92011-06-29 10:25:01 -0700873 public boolean isCollapsed() {
874 return mIsCollapsed;
875 }
876
Adam Powell27cba382013-01-22 18:55:20 -0800877 /**
878 * @return True if any characters in the title were truncated
879 */
880 public boolean isTitleTruncated() {
881 if (mTitleView == null) {
882 return false;
883 }
884
885 final Layout titleLayout = mTitleView.getLayout();
886 if (titleLayout == null) {
887 return false;
888 }
889
890 final int lineCount = titleLayout.getLineCount();
891 for (int i = 0; i < lineCount; i++) {
892 if (titleLayout.getEllipsisCount(i) > 0) {
893 return true;
894 }
895 }
896 return false;
897 }
898
Adam Powell33b97432010-04-20 10:01:14 -0700899 @Override
900 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Adam Powelld21aa122011-05-27 13:09:52 -0700901 final int childCount = getChildCount();
902 if (mIsCollapsable) {
903 int visibleChildren = 0;
904 for (int i = 0; i < childCount; i++) {
905 final View child = getChildAt(i);
906 if (child.getVisibility() != GONE &&
Adam Powell27cba382013-01-22 18:55:20 -0800907 !(child == mMenuView && mMenuView.getChildCount() == 0) &&
908 child != mUpGoerFive) {
909 visibleChildren++;
910 }
911 }
912
913 final int upChildCount = mUpGoerFive.getChildCount();
914 for (int i = 0; i < upChildCount; i++) {
915 final View child = mUpGoerFive.getChildAt(i);
916 if (child.getVisibility() != GONE) {
Adam Powelld21aa122011-05-27 13:09:52 -0700917 visibleChildren++;
918 }
919 }
920
921 if (visibleChildren == 0) {
922 // No size for an empty action bar when collapsable.
923 setMeasuredDimension(0, 0);
Adam Powellf6ce6a92011-06-29 10:25:01 -0700924 mIsCollapsed = true;
Adam Powelld21aa122011-05-27 13:09:52 -0700925 return;
926 }
927 }
Adam Powellf6ce6a92011-06-29 10:25:01 -0700928 mIsCollapsed = false;
Adam Powelld21aa122011-05-27 13:09:52 -0700929
Adam Powell33b97432010-04-20 10:01:14 -0700930 int widthMode = MeasureSpec.getMode(widthMeasureSpec);
931 if (widthMode != MeasureSpec.EXACTLY) {
932 throw new IllegalStateException(getClass().getSimpleName() + " can only be used " +
933 "with android:layout_width=\"match_parent\" (or fill_parent)");
934 }
Casey Burkhardt8452a7f2013-04-30 15:56:41 -0700935
Adam Powell33b97432010-04-20 10:01:14 -0700936 int heightMode = MeasureSpec.getMode(heightMeasureSpec);
937 if (heightMode != MeasureSpec.AT_MOST) {
938 throw new IllegalStateException(getClass().getSimpleName() + " can only be used " +
939 "with android:layout_height=\"wrap_content\"");
940 }
941
942 int contentWidth = MeasureSpec.getSize(widthMeasureSpec);
Adam Powelle2194442010-08-12 18:13:03 -0700943
Adam Powell570470a2012-08-06 17:00:17 -0700944 int maxHeight = mContentHeight >= 0 ?
Adam Powelle2194442010-08-12 18:13:03 -0700945 mContentHeight : MeasureSpec.getSize(heightMeasureSpec);
Casey Burkhardt8452a7f2013-04-30 15:56:41 -0700946
Adam Powelle2194442010-08-12 18:13:03 -0700947 final int verticalPadding = getPaddingTop() + getPaddingBottom();
Adam Powell9ab97872010-10-26 21:47:29 -0700948 final int paddingLeft = getPaddingLeft();
949 final int paddingRight = getPaddingRight();
Adam Powelle2194442010-08-12 18:13:03 -0700950 final int height = maxHeight - verticalPadding;
Adam Powella1700782010-05-13 13:27:35 -0700951 final int childSpecHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST);
Adam Powell6322af52012-08-08 15:59:12 -0700952 final int exactHeightSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
Adam Powell33b97432010-04-20 10:01:14 -0700953
Adam Powell9ab97872010-10-26 21:47:29 -0700954 int availableWidth = contentWidth - paddingLeft - paddingRight;
955 int leftOfCenter = availableWidth / 2;
956 int rightOfCenter = leftOfCenter;
957
Adam Powellb1e2f252011-08-22 17:42:12 -0700958 HomeView homeLayout = mExpandedActionView != null ? mExpandedHomeLayout : mHomeLayout;
Adam Powell8d02dea2011-05-31 21:35:13 -0700959
Adam Powell27cba382013-01-22 18:55:20 -0800960 int homeWidth = 0;
961 if (homeLayout.getVisibility() != GONE && homeLayout.getParent() == mUpGoerFive) {
Adam Powell9a5cc282011-08-28 16:18:16 -0700962 final ViewGroup.LayoutParams lp = homeLayout.getLayoutParams();
Adam Powell0d5d1b7e2011-06-22 17:40:40 -0700963 int homeWidthSpec;
964 if (lp.width < 0) {
965 homeWidthSpec = MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST);
966 } else {
967 homeWidthSpec = MeasureSpec.makeMeasureSpec(lp.width, MeasureSpec.EXACTLY);
968 }
Adam Powell27cba382013-01-22 18:55:20 -0800969
970 /*
971 * This is a little weird.
972 * We're only measuring the *home* affordance within the Up container here
973 * on purpose, because we want to give the available space to all other views before
974 * the title text. We'll remeasure the whole up container again later.
975 */
Adam Powell6322af52012-08-08 15:59:12 -0700976 homeLayout.measure(homeWidthSpec, exactHeightSpec);
Adam Powell27cba382013-01-22 18:55:20 -0800977 homeWidth = homeLayout.getMeasuredWidth();
978 final int homeOffsetWidth = homeWidth + homeLayout.getStartOffset();
979 availableWidth = Math.max(0, availableWidth - homeOffsetWidth);
980 leftOfCenter = Math.max(0, availableWidth - homeOffsetWidth);
Adam Powell33b97432010-04-20 10:01:14 -0700981 }
Casey Burkhardt8452a7f2013-04-30 15:56:41 -0700982
Adam Powell9b4bee02011-04-27 19:24:47 -0700983 if (mMenuView != null && mMenuView.getParent() == this) {
Adam Powell6322af52012-08-08 15:59:12 -0700984 availableWidth = measureChildView(mMenuView, availableWidth, exactHeightSpec, 0);
Adam Powell1b4a1622011-05-17 12:13:13 -0700985 rightOfCenter = Math.max(0, rightOfCenter - mMenuView.getMeasuredWidth());
Adam Powell33b97432010-04-20 10:01:14 -0700986 }
Adam Powell9ab97872010-10-26 21:47:29 -0700987
Adam Powellaa8e509b2011-08-25 09:29:21 -0700988 if (mIndeterminateProgressView != null &&
989 mIndeterminateProgressView.getVisibility() != GONE) {
990 availableWidth = measureChildView(mIndeterminateProgressView, availableWidth,
991 childSpecHeight, 0);
992 rightOfCenter = Math.max(0,
993 rightOfCenter - mIndeterminateProgressView.getMeasuredWidth());
994 }
Adam Powell9ab97872010-10-26 21:47:29 -0700995
Adam Powellaa8e509b2011-08-25 09:29:21 -0700996 final boolean showTitle = mTitleLayout != null && mTitleLayout.getVisibility() != GONE &&
997 (mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0;
998
999 if (mExpandedActionView == null) {
Adam Powell8d02dea2011-05-31 21:35:13 -07001000 switch (mNavigationMode) {
1001 case ActionBar.NAVIGATION_MODE_LIST:
1002 if (mListNavLayout != null) {
1003 final int itemPaddingSize = showTitle ? mItemPadding * 2 : mItemPadding;
1004 availableWidth = Math.max(0, availableWidth - itemPaddingSize);
1005 leftOfCenter = Math.max(0, leftOfCenter - itemPaddingSize);
1006 mListNavLayout.measure(
1007 MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST),
1008 MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
1009 final int listNavWidth = mListNavLayout.getMeasuredWidth();
1010 availableWidth = Math.max(0, availableWidth - listNavWidth);
1011 leftOfCenter = Math.max(0, leftOfCenter - listNavWidth);
1012 }
1013 break;
1014 case ActionBar.NAVIGATION_MODE_TABS:
1015 if (mTabScrollView != null) {
1016 final int itemPaddingSize = showTitle ? mItemPadding * 2 : mItemPadding;
1017 availableWidth = Math.max(0, availableWidth - itemPaddingSize);
1018 leftOfCenter = Math.max(0, leftOfCenter - itemPaddingSize);
1019 mTabScrollView.measure(
1020 MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST),
1021 MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
1022 final int tabWidth = mTabScrollView.getMeasuredWidth();
1023 availableWidth = Math.max(0, availableWidth - tabWidth);
1024 leftOfCenter = Math.max(0, leftOfCenter - tabWidth);
1025 }
1026 break;
Adam Powell33b97432010-04-20 10:01:14 -07001027 }
Adam Powell33b97432010-04-20 10:01:14 -07001028 }
1029
Adam Powell8d02dea2011-05-31 21:35:13 -07001030 View customView = null;
1031 if (mExpandedActionView != null) {
1032 customView = mExpandedActionView;
1033 } else if ((mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0 &&
1034 mCustomNavView != null) {
1035 customView = mCustomNavView;
1036 }
1037
1038 if (customView != null) {
Adam Powell9a5cc282011-08-28 16:18:16 -07001039 final ViewGroup.LayoutParams lp = generateLayoutParams(customView.getLayoutParams());
Adam Powell9ab97872010-10-26 21:47:29 -07001040 final ActionBar.LayoutParams ablp = lp instanceof ActionBar.LayoutParams ?
1041 (ActionBar.LayoutParams) lp : null;
1042
1043 int horizontalMargin = 0;
1044 int verticalMargin = 0;
1045 if (ablp != null) {
1046 horizontalMargin = ablp.leftMargin + ablp.rightMargin;
1047 verticalMargin = ablp.topMargin + ablp.bottomMargin;
1048 }
1049
1050 // If the action bar is wrapping to its content height, don't allow a custom
1051 // view to MATCH_PARENT.
1052 int customNavHeightMode;
1053 if (mContentHeight <= 0) {
1054 customNavHeightMode = MeasureSpec.AT_MOST;
1055 } else {
1056 customNavHeightMode = lp.height != LayoutParams.WRAP_CONTENT ?
1057 MeasureSpec.EXACTLY : MeasureSpec.AT_MOST;
1058 }
1059 final int customNavHeight = Math.max(0,
1060 (lp.height >= 0 ? Math.min(lp.height, height) : height) - verticalMargin);
1061
1062 final int customNavWidthMode = lp.width != LayoutParams.WRAP_CONTENT ?
1063 MeasureSpec.EXACTLY : MeasureSpec.AT_MOST;
1064 int customNavWidth = Math.max(0,
1065 (lp.width >= 0 ? Math.min(lp.width, availableWidth) : availableWidth)
1066 - horizontalMargin);
1067 final int hgrav = (ablp != null ? ablp.gravity : DEFAULT_CUSTOM_GRAVITY) &
1068 Gravity.HORIZONTAL_GRAVITY_MASK;
1069
1070 // Centering a custom view is treated specially; we try to center within the whole
1071 // action bar rather than in the available space.
1072 if (hgrav == Gravity.CENTER_HORIZONTAL && lp.width == LayoutParams.MATCH_PARENT) {
1073 customNavWidth = Math.min(leftOfCenter, rightOfCenter) * 2;
1074 }
1075
Adam Powell8d02dea2011-05-31 21:35:13 -07001076 customView.measure(
Adam Powell9ab97872010-10-26 21:47:29 -07001077 MeasureSpec.makeMeasureSpec(customNavWidth, customNavWidthMode),
1078 MeasureSpec.makeMeasureSpec(customNavHeight, customNavHeightMode));
Adam Powellaa8e509b2011-08-25 09:29:21 -07001079 availableWidth -= horizontalMargin + customView.getMeasuredWidth();
1080 }
1081
Adam Powell27cba382013-01-22 18:55:20 -08001082 /*
1083 * Measure the whole up container now, allowing for the full home+title sections.
1084 * (This will re-measure the home view.)
1085 */
1086 availableWidth = measureChildView(mUpGoerFive, availableWidth + homeWidth,
1087 MeasureSpec.makeMeasureSpec(mContentHeight, MeasureSpec.EXACTLY), 0);
1088 if (mTitleLayout != null) {
Adam Powellaa8e509b2011-08-25 09:29:21 -07001089 leftOfCenter = Math.max(0, leftOfCenter - mTitleLayout.getMeasuredWidth());
Adam Powell9ab97872010-10-26 21:47:29 -07001090 }
1091
Adam Powelle2194442010-08-12 18:13:03 -07001092 if (mContentHeight <= 0) {
1093 int measuredHeight = 0;
Adam Powelld21aa122011-05-27 13:09:52 -07001094 for (int i = 0; i < childCount; i++) {
Adam Powelle2194442010-08-12 18:13:03 -07001095 View v = getChildAt(i);
1096 int paddedViewHeight = v.getMeasuredHeight() + verticalPadding;
1097 if (paddedViewHeight > measuredHeight) {
1098 measuredHeight = paddedViewHeight;
1099 }
1100 }
1101 setMeasuredDimension(contentWidth, measuredHeight);
1102 } else {
1103 setMeasuredDimension(contentWidth, maxHeight);
1104 }
1105
1106 if (mContextView != null) {
Adam Powell425689e2011-09-08 18:09:33 -07001107 mContextView.setContentHeight(getMeasuredHeight());
Adam Powelle2194442010-08-12 18:13:03 -07001108 }
Adam Powell6af97e12010-11-11 21:11:53 -08001109
1110 if (mProgressView != null && mProgressView.getVisibility() != GONE) {
1111 mProgressView.measure(MeasureSpec.makeMeasureSpec(
1112 contentWidth - mProgressBarPadding * 2, MeasureSpec.EXACTLY),
1113 MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.AT_MOST));
1114 }
Adam Powell33b97432010-04-20 10:01:14 -07001115 }
1116
Adam Powell33b97432010-04-20 10:01:14 -07001117 @Override
1118 protected void onLayout(boolean changed, int l, int t, int r, int b) {
Adam Powell33b97432010-04-20 10:01:14 -07001119 final int contentHeight = b - t - getPaddingTop() - getPaddingBottom();
1120
Adam Powelld21aa122011-05-27 13:09:52 -07001121 if (contentHeight <= 0) {
1122 // Nothing to do if we can't see anything.
1123 return;
1124 }
1125
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001126 final boolean isLayoutRtl = isLayoutRtl();
1127 final int direction = isLayoutRtl ? +1 : -1;
1128 int menuStart = isLayoutRtl ? getPaddingLeft() : r - l - getPaddingRight();
1129 // In LTR mode, we start from left padding and go to the right; in RTL mode, we start
1130 // from the padding right and go to the left (in reverse way)
1131 int x = isLayoutRtl ? r - l - getPaddingRight() : getPaddingLeft();
1132 final int y = getPaddingTop();
1133
Adam Powellb1e2f252011-08-22 17:42:12 -07001134 HomeView homeLayout = mExpandedActionView != null ? mExpandedHomeLayout : mHomeLayout;
Adam Powell27cba382013-01-22 18:55:20 -08001135 final int startOffset = homeLayout.getVisibility() != GONE &&
1136 homeLayout.getParent() == mUpGoerFive ? homeLayout.getStartOffset() : 0;
1137
1138 // Position the up container based on where the edge of the home layout should go.
1139 x += positionChild(mUpGoerFive,
1140 next(x, startOffset, isLayoutRtl), y, contentHeight, isLayoutRtl);
1141 x = next(x, startOffset, isLayoutRtl);
Adam Powell9ab97872010-10-26 21:47:29 -07001142
Adam Powell8d02dea2011-05-31 21:35:13 -07001143 if (mExpandedActionView == null) {
1144 final boolean showTitle = mTitleLayout != null && mTitleLayout.getVisibility() != GONE &&
Adam Powell15a16a82011-06-20 10:35:27 -07001145 (mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0;
Adam Powell8d02dea2011-05-31 21:35:13 -07001146
1147 switch (mNavigationMode) {
1148 case ActionBar.NAVIGATION_MODE_STANDARD:
1149 break;
1150 case ActionBar.NAVIGATION_MODE_LIST:
1151 if (mListNavLayout != null) {
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001152 if (showTitle) {
1153 x = next(x, mItemPadding, isLayoutRtl);
1154 }
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001155 x += positionChild(mListNavLayout, x, y, contentHeight, isLayoutRtl);
1156 x = next(x, mItemPadding, isLayoutRtl);
Adam Powell8d02dea2011-05-31 21:35:13 -07001157 }
1158 break;
1159 case ActionBar.NAVIGATION_MODE_TABS:
1160 if (mTabScrollView != null) {
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001161 if (showTitle) x = next(x, mItemPadding, isLayoutRtl);
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001162 x += positionChild(mTabScrollView, x, y, contentHeight, isLayoutRtl);
1163 x = next(x, mItemPadding, isLayoutRtl);
Adam Powell8d02dea2011-05-31 21:35:13 -07001164 }
1165 break;
Adam Powell661c9082010-07-02 10:09:44 -07001166 }
Adam Powell33b97432010-04-20 10:01:14 -07001167 }
1168
Adam Powell9b4bee02011-04-27 19:24:47 -07001169 if (mMenuView != null && mMenuView.getParent() == this) {
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001170 positionChild(mMenuView, menuStart, y, contentHeight, !isLayoutRtl);
1171 menuStart += direction * mMenuView.getMeasuredWidth();
Adam Powell9ab97872010-10-26 21:47:29 -07001172 }
1173
Adam Powell6af97e12010-11-11 21:11:53 -08001174 if (mIndeterminateProgressView != null &&
1175 mIndeterminateProgressView.getVisibility() != GONE) {
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001176 positionChild(mIndeterminateProgressView, menuStart, y, contentHeight, !isLayoutRtl);
1177 menuStart += direction * mIndeterminateProgressView.getMeasuredWidth();
Adam Powell6af97e12010-11-11 21:11:53 -08001178 }
1179
Adam Powell8d02dea2011-05-31 21:35:13 -07001180 View customView = null;
1181 if (mExpandedActionView != null) {
1182 customView = mExpandedActionView;
1183 } else if ((mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0 &&
1184 mCustomNavView != null) {
1185 customView = mCustomNavView;
1186 }
1187 if (customView != null) {
Fabrice Di Meglio6bf6eb72012-10-10 15:30:28 -07001188 final int layoutDirection = getLayoutDirection();
Fabrice Di Megliobb4b6012012-10-26 16:27:55 -07001189 ViewGroup.LayoutParams lp = customView.getLayoutParams();
Adam Powell9ab97872010-10-26 21:47:29 -07001190 final ActionBar.LayoutParams ablp = lp instanceof ActionBar.LayoutParams ?
1191 (ActionBar.LayoutParams) lp : null;
Adam Powell9ab97872010-10-26 21:47:29 -07001192 final int gravity = ablp != null ? ablp.gravity : DEFAULT_CUSTOM_GRAVITY;
Adam Powell8d02dea2011-05-31 21:35:13 -07001193 final int navWidth = customView.getMeasuredWidth();
Adam Powell9ab97872010-10-26 21:47:29 -07001194
1195 int topMargin = 0;
1196 int bottomMargin = 0;
1197 if (ablp != null) {
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001198 x = next(x, ablp.getMarginStart(), isLayoutRtl);
1199 menuStart += direction * ablp.getMarginEnd();
Adam Powell9ab97872010-10-26 21:47:29 -07001200 topMargin = ablp.topMargin;
1201 bottomMargin = ablp.bottomMargin;
1202 }
1203
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001204 int hgravity = gravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK;
Adam Powell9ab97872010-10-26 21:47:29 -07001205 // See if we actually have room to truly center; if not push against left or right.
1206 if (hgravity == Gravity.CENTER_HORIZONTAL) {
1207 final int centeredLeft = ((mRight - mLeft) - navWidth) / 2;
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001208 if (isLayoutRtl) {
1209 final int centeredStart = centeredLeft + navWidth;
1210 final int centeredEnd = centeredLeft;
1211 if (centeredStart > x) {
1212 hgravity = Gravity.RIGHT;
1213 } else if (centeredEnd < menuStart) {
1214 hgravity = Gravity.LEFT;
1215 }
1216 } else {
1217 final int centeredStart = centeredLeft;
1218 final int centeredEnd = centeredLeft + navWidth;
1219 if (centeredStart < x) {
1220 hgravity = Gravity.LEFT;
1221 } else if (centeredEnd > menuStart) {
1222 hgravity = Gravity.RIGHT;
1223 }
Adam Powell9ab97872010-10-26 21:47:29 -07001224 }
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001225 } else if (gravity == Gravity.NO_GRAVITY) {
1226 hgravity = Gravity.START;
Adam Powell9ab97872010-10-26 21:47:29 -07001227 }
1228
1229 int xpos = 0;
Fabrice Di Meglio6bf6eb72012-10-10 15:30:28 -07001230 switch (Gravity.getAbsoluteGravity(hgravity, layoutDirection)) {
Adam Powell9ab97872010-10-26 21:47:29 -07001231 case Gravity.CENTER_HORIZONTAL:
1232 xpos = ((mRight - mLeft) - navWidth) / 2;
1233 break;
1234 case Gravity.LEFT:
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001235 xpos = isLayoutRtl ? menuStart : x;
Adam Powell9ab97872010-10-26 21:47:29 -07001236 break;
1237 case Gravity.RIGHT:
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001238 xpos = isLayoutRtl ? x - navWidth : menuStart - navWidth;
Adam Powell9ab97872010-10-26 21:47:29 -07001239 break;
1240 }
1241
Adam Powell7a2424d2011-08-18 11:59:11 -07001242 int vgravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
1243
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001244 if (gravity == Gravity.NO_GRAVITY) {
Adam Powell7a2424d2011-08-18 11:59:11 -07001245 vgravity = Gravity.CENTER_VERTICAL;
1246 }
1247
Adam Powell9ab97872010-10-26 21:47:29 -07001248 int ypos = 0;
Adam Powell7a2424d2011-08-18 11:59:11 -07001249 switch (vgravity) {
Adam Powell9ab97872010-10-26 21:47:29 -07001250 case Gravity.CENTER_VERTICAL:
Adam Powell6556c072011-06-24 17:16:57 -07001251 final int paddedTop = getPaddingTop();
1252 final int paddedBottom = mBottom - mTop - getPaddingBottom();
Adam Powell8d02dea2011-05-31 21:35:13 -07001253 ypos = ((paddedBottom - paddedTop) - customView.getMeasuredHeight()) / 2;
Adam Powell9ab97872010-10-26 21:47:29 -07001254 break;
1255 case Gravity.TOP:
1256 ypos = getPaddingTop() + topMargin;
1257 break;
1258 case Gravity.BOTTOM:
Adam Powell8d02dea2011-05-31 21:35:13 -07001259 ypos = getHeight() - getPaddingBottom() - customView.getMeasuredHeight()
Adam Powell9ab97872010-10-26 21:47:29 -07001260 - bottomMargin;
1261 break;
1262 }
Adam Powell6556c072011-06-24 17:16:57 -07001263 final int customWidth = customView.getMeasuredWidth();
1264 customView.layout(xpos, ypos, xpos + customWidth,
1265 ypos + customView.getMeasuredHeight());
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001266 x = next(x, customWidth, isLayoutRtl);
Adam Powell33b97432010-04-20 10:01:14 -07001267 }
Adam Powell6af97e12010-11-11 21:11:53 -08001268
1269 if (mProgressView != null) {
1270 mProgressView.bringToFront();
1271 final int halfProgressHeight = mProgressView.getMeasuredHeight() / 2;
1272 mProgressView.layout(mProgressBarPadding, -halfProgressHeight,
1273 mProgressBarPadding + mProgressView.getMeasuredWidth(), halfProgressHeight);
1274 }
Adam Powell33b97432010-04-20 10:01:14 -07001275 }
1276
Adam Powell8d02dea2011-05-31 21:35:13 -07001277 @Override
Adam Powell9a5cc282011-08-28 16:18:16 -07001278 public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
Adam Powellaad47fd2011-08-17 17:33:33 -07001279 return new ActionBar.LayoutParams(getContext(), attrs);
1280 }
1281
1282 @Override
Adam Powell9a5cc282011-08-28 16:18:16 -07001283 public ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp) {
Adam Powell8d02dea2011-05-31 21:35:13 -07001284 if (lp == null) {
1285 lp = generateDefaultLayoutParams();
1286 }
1287 return lp;
1288 }
1289
1290 @Override
1291 public Parcelable onSaveInstanceState() {
1292 Parcelable superState = super.onSaveInstanceState();
1293 SavedState state = new SavedState(superState);
1294
1295 if (mExpandedMenuPresenter != null && mExpandedMenuPresenter.mCurrentExpandedItem != null) {
1296 state.expandedMenuItemId = mExpandedMenuPresenter.mCurrentExpandedItem.getItemId();
1297 }
1298
1299 state.isOverflowOpen = isOverflowMenuShowing();
1300
1301 return state;
1302 }
1303
1304 @Override
1305 public void onRestoreInstanceState(Parcelable p) {
1306 SavedState state = (SavedState) p;
1307
1308 super.onRestoreInstanceState(state.getSuperState());
1309
1310 if (state.expandedMenuItemId != 0 &&
1311 mExpandedMenuPresenter != null && mOptionsMenu != null) {
1312 final MenuItem item = mOptionsMenu.findItem(state.expandedMenuItemId);
1313 if (item != null) {
1314 item.expandActionView();
1315 }
1316 }
1317
1318 if (state.isOverflowOpen) {
1319 postShowOverflowMenu();
1320 }
1321 }
1322
Adam Powelle0e2f4f2013-04-05 16:27:35 -07001323 public void setHomeAsUpIndicator(Drawable indicator) {
1324 mHomeLayout.setUpIndicator(indicator);
1325 }
1326
1327 public void setHomeAsUpIndicator(int resId) {
1328 mHomeLayout.setUpIndicator(resId);
1329 }
1330
1331 public void setHomeActionContentDescription(CharSequence description) {
1332 mHomeDescription = description;
1333 }
1334
1335 public void setHomeActionContentDescription(int resId) {
1336 mHomeDescriptionRes = resId;
Adam Powell2eeb4192013-04-18 13:53:27 -07001337 mHomeDescription = resId != 0 ? getResources().getText(resId) : null;
Adam Powelle0e2f4f2013-04-05 16:27:35 -07001338 }
1339
Adam Powell8d02dea2011-05-31 21:35:13 -07001340 static class SavedState extends BaseSavedState {
1341 int expandedMenuItemId;
1342 boolean isOverflowOpen;
1343
1344 SavedState(Parcelable superState) {
1345 super(superState);
1346 }
1347
1348 private SavedState(Parcel in) {
1349 super(in);
1350 expandedMenuItemId = in.readInt();
1351 isOverflowOpen = in.readInt() != 0;
1352 }
1353
1354 @Override
1355 public void writeToParcel(Parcel out, int flags) {
1356 super.writeToParcel(out, flags);
1357 out.writeInt(expandedMenuItemId);
1358 out.writeInt(isOverflowOpen ? 1 : 0);
1359 }
1360
1361 public static final Parcelable.Creator<SavedState> CREATOR =
1362 new Parcelable.Creator<SavedState>() {
1363 public SavedState createFromParcel(Parcel in) {
1364 return new SavedState(in);
1365 }
1366
1367 public SavedState[] newArray(int size) {
1368 return new SavedState[size];
1369 }
1370 };
1371 }
1372
Adam Powell2b0952b2011-03-09 00:15:38 -08001373 private static class HomeView extends FrameLayout {
Adam Powelle0e2f4f2013-04-05 16:27:35 -07001374 private ImageView mUpView;
Adam Powell8d02dea2011-05-31 21:35:13 -07001375 private ImageView mIconView;
Adam Powellb1e2f252011-08-22 17:42:12 -07001376 private int mUpWidth;
Adam Powelle0e2f4f2013-04-05 16:27:35 -07001377 private int mUpIndicatorRes;
1378 private Drawable mDefaultUpIndicator;
Adam Powell2b0952b2011-03-09 00:15:38 -08001379
Adam Powellfd75eef2012-08-02 10:27:31 -07001380 private static final long DEFAULT_TRANSITION_DURATION = 150;
1381
Adam Powell2b0952b2011-03-09 00:15:38 -08001382 public HomeView(Context context) {
1383 this(context, null);
1384 }
1385
1386 public HomeView(Context context, AttributeSet attrs) {
1387 super(context, attrs);
Adam Powellfd75eef2012-08-02 10:27:31 -07001388 LayoutTransition t = getLayoutTransition();
1389 if (t != null) {
1390 // Set a lower duration than the default
1391 t.setDuration(DEFAULT_TRANSITION_DURATION);
1392 }
Adam Powell2b0952b2011-03-09 00:15:38 -08001393 }
1394
Adam Powell8d02dea2011-05-31 21:35:13 -07001395 public void setUp(boolean isUp) {
1396 mUpView.setVisibility(isUp ? VISIBLE : GONE);
1397 }
1398
1399 public void setIcon(Drawable icon) {
1400 mIconView.setImageDrawable(icon);
1401 }
1402
Adam Powelle0e2f4f2013-04-05 16:27:35 -07001403 public void setUpIndicator(Drawable d) {
1404 mUpView.setImageDrawable(d != null ? d : mDefaultUpIndicator);
1405 mUpIndicatorRes = 0;
1406 }
1407
1408 public void setUpIndicator(int resId) {
1409 mUpIndicatorRes = resId;
1410 mUpView.setImageDrawable(resId != 0 ? getResources().getDrawable(resId) : null);
1411 }
1412
1413 @Override
1414 protected void onConfigurationChanged(Configuration newConfig) {
1415 super.onConfigurationChanged(newConfig);
1416 if (mUpIndicatorRes != 0) {
1417 // Reload for config change
1418 setUpIndicator(mUpIndicatorRes);
1419 }
1420 }
1421
Adam Powell2b0952b2011-03-09 00:15:38 -08001422 @Override
Adam Powell7bc3ca02011-08-26 18:29:58 -07001423 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
1424 onPopulateAccessibilityEvent(event);
1425 return true;
1426 }
1427
1428 @Override
1429 public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
1430 super.onPopulateAccessibilityEvent(event);
1431 final CharSequence cdesc = getContentDescription();
1432 if (!TextUtils.isEmpty(cdesc)) {
1433 event.getText().add(cdesc);
1434 }
1435 }
1436
1437 @Override
1438 public boolean dispatchHoverEvent(MotionEvent event) {
1439 // Don't allow children to hover; we want this to be treated as a single component.
1440 return onHoverEvent(event);
1441 }
1442
1443 @Override
Adam Powell2b0952b2011-03-09 00:15:38 -08001444 protected void onFinishInflate() {
Adam Powelle0e2f4f2013-04-05 16:27:35 -07001445 mUpView = (ImageView) findViewById(com.android.internal.R.id.up);
Adam Powell2b0952b2011-03-09 00:15:38 -08001446 mIconView = (ImageView) findViewById(com.android.internal.R.id.home);
Adam Powelle0e2f4f2013-04-05 16:27:35 -07001447 mDefaultUpIndicator = mUpView.getDrawable();
Adam Powell2b0952b2011-03-09 00:15:38 -08001448 }
1449
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001450 public int getStartOffset() {
Adam Powellb1e2f252011-08-22 17:42:12 -07001451 return mUpView.getVisibility() == GONE ? mUpWidth : 0;
Adam Powell8d02dea2011-05-31 21:35:13 -07001452 }
1453
Adam Powell2b0952b2011-03-09 00:15:38 -08001454 @Override
1455 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
1456 measureChildWithMargins(mUpView, widthMeasureSpec, 0, heightMeasureSpec, 0);
1457 final LayoutParams upLp = (LayoutParams) mUpView.getLayoutParams();
Adam Powellb1e2f252011-08-22 17:42:12 -07001458 mUpWidth = upLp.leftMargin + mUpView.getMeasuredWidth() + upLp.rightMargin;
1459 int width = mUpView.getVisibility() == GONE ? 0 : mUpWidth;
Adam Powell2b0952b2011-03-09 00:15:38 -08001460 int height = upLp.topMargin + mUpView.getMeasuredHeight() + upLp.bottomMargin;
1461 measureChildWithMargins(mIconView, widthMeasureSpec, width, heightMeasureSpec, 0);
1462 final LayoutParams iconLp = (LayoutParams) mIconView.getLayoutParams();
1463 width += iconLp.leftMargin + mIconView.getMeasuredWidth() + iconLp.rightMargin;
1464 height = Math.max(height,
1465 iconLp.topMargin + mIconView.getMeasuredHeight() + iconLp.bottomMargin);
Adam Powell0d5d1b7e2011-06-22 17:40:40 -07001466
1467 final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
1468 final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
1469 final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
1470 final int heightSize = MeasureSpec.getSize(heightMeasureSpec);
1471
1472 switch (widthMode) {
1473 case MeasureSpec.AT_MOST:
1474 width = Math.min(width, widthSize);
1475 break;
1476 case MeasureSpec.EXACTLY:
1477 width = widthSize;
1478 break;
1479 case MeasureSpec.UNSPECIFIED:
1480 default:
1481 break;
1482 }
1483 switch (heightMode) {
1484 case MeasureSpec.AT_MOST:
1485 height = Math.min(height, heightSize);
1486 break;
1487 case MeasureSpec.EXACTLY:
1488 height = heightSize;
1489 break;
1490 case MeasureSpec.UNSPECIFIED:
1491 default:
1492 break;
1493 }
Adam Powell2b0952b2011-03-09 00:15:38 -08001494 setMeasuredDimension(width, height);
1495 }
1496
1497 @Override
1498 protected void onLayout(boolean changed, int l, int t, int r, int b) {
1499 final int vCenter = (b - t) / 2;
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001500 final boolean isLayoutRtl = isLayoutRtl();
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001501 final int width = getWidth();
Adam Powellc8b0b002011-06-23 14:39:05 -07001502 int upOffset = 0;
Adam Powell2b0952b2011-03-09 00:15:38 -08001503 if (mUpView.getVisibility() != GONE) {
1504 final LayoutParams upLp = (LayoutParams) mUpView.getLayoutParams();
1505 final int upHeight = mUpView.getMeasuredHeight();
1506 final int upWidth = mUpView.getMeasuredWidth();
Adam Powellc8b0b002011-06-23 14:39:05 -07001507 upOffset = upLp.leftMargin + upWidth + upLp.rightMargin;
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001508 final int upTop = vCenter - upHeight / 2;
1509 final int upBottom = upTop + upHeight;
1510 final int upRight;
1511 final int upLeft;
1512 if (isLayoutRtl) {
1513 upRight = width;
1514 upLeft = upRight - upWidth;
1515 r -= upOffset;
1516 } else {
1517 upRight = upWidth;
1518 upLeft = 0;
1519 l += upOffset;
1520 }
1521 mUpView.layout(upLeft, upTop, upRight, upBottom);
Adam Powell2b0952b2011-03-09 00:15:38 -08001522 }
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001523
Adam Powell2b0952b2011-03-09 00:15:38 -08001524 final LayoutParams iconLp = (LayoutParams) mIconView.getLayoutParams();
1525 final int iconHeight = mIconView.getMeasuredHeight();
1526 final int iconWidth = mIconView.getMeasuredWidth();
1527 final int hCenter = (r - l) / 2;
Adam Powellc8b0b002011-06-23 14:39:05 -07001528 final int iconTop = Math.max(iconLp.topMargin, vCenter - iconHeight / 2);
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001529 final int iconBottom = iconTop + iconHeight;
1530 final int iconLeft;
1531 final int iconRight;
1532 int marginStart = iconLp.getMarginStart();
1533 final int delta = Math.max(marginStart, hCenter - iconWidth / 2);
1534 if (isLayoutRtl) {
1535 iconRight = width - upOffset - delta;
1536 iconLeft = iconRight - iconWidth;
1537 } else {
1538 iconLeft = upOffset + delta;
1539 iconRight = iconLeft + iconWidth;
1540 }
1541 mIconView.layout(iconLeft, iconTop, iconRight, iconBottom);
Adam Powell2b0952b2011-03-09 00:15:38 -08001542 }
1543 }
Adam Powell8d02dea2011-05-31 21:35:13 -07001544
1545 private class ExpandedActionViewMenuPresenter implements MenuPresenter {
1546 MenuBuilder mMenu;
1547 MenuItemImpl mCurrentExpandedItem;
1548
1549 @Override
1550 public void initForMenu(Context context, MenuBuilder menu) {
1551 // Clear the expanded action view when menus change.
Adam Powell6b0e97c2011-08-03 12:06:32 -07001552 if (mMenu != null && mCurrentExpandedItem != null) {
1553 mMenu.collapseItemActionView(mCurrentExpandedItem);
Adam Powell8d02dea2011-05-31 21:35:13 -07001554 }
1555 mMenu = menu;
1556 }
1557
1558 @Override
1559 public MenuView getMenuView(ViewGroup root) {
1560 return null;
1561 }
1562
1563 @Override
1564 public void updateMenuView(boolean cleared) {
1565 // Make sure the expanded item we have is still there.
1566 if (mCurrentExpandedItem != null) {
1567 boolean found = false;
Adam Powellf35d0492011-08-17 13:56:47 -07001568
1569 if (mMenu != null) {
1570 final int count = mMenu.size();
1571 for (int i = 0; i < count; i++) {
1572 final MenuItem item = mMenu.getItem(i);
1573 if (item == mCurrentExpandedItem) {
1574 found = true;
1575 break;
1576 }
Adam Powell8d02dea2011-05-31 21:35:13 -07001577 }
1578 }
1579
1580 if (!found) {
1581 // The item we had expanded disappeared. Collapse.
1582 collapseItemActionView(mMenu, mCurrentExpandedItem);
1583 }
1584 }
1585 }
1586
1587 @Override
1588 public void setCallback(Callback cb) {
1589 }
1590
1591 @Override
1592 public boolean onSubMenuSelected(SubMenuBuilder subMenu) {
1593 return false;
1594 }
1595
1596 @Override
1597 public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) {
1598 }
1599
1600 @Override
1601 public boolean flagActionItems() {
1602 return false;
1603 }
1604
1605 @Override
1606 public boolean expandItemActionView(MenuBuilder menu, MenuItemImpl item) {
1607 mExpandedActionView = item.getActionView();
Adam Powell28fa07e2011-07-15 20:17:25 -07001608 mExpandedHomeLayout.setIcon(mIcon.getConstantState().newDrawable(getResources()));
Adam Powell8d02dea2011-05-31 21:35:13 -07001609 mCurrentExpandedItem = item;
1610 if (mExpandedActionView.getParent() != ActionBarView.this) {
1611 addView(mExpandedActionView);
1612 }
Adam Powell27cba382013-01-22 18:55:20 -08001613 if (mExpandedHomeLayout.getParent() != mUpGoerFive) {
1614 mUpGoerFive.addView(mExpandedHomeLayout);
Adam Powell8d02dea2011-05-31 21:35:13 -07001615 }
1616 mHomeLayout.setVisibility(GONE);
Adam Powell15a16a82011-06-20 10:35:27 -07001617 if (mTitleLayout != null) mTitleLayout.setVisibility(GONE);
Adam Powell8d02dea2011-05-31 21:35:13 -07001618 if (mTabScrollView != null) mTabScrollView.setVisibility(GONE);
1619 if (mSpinner != null) mSpinner.setVisibility(GONE);
1620 if (mCustomNavView != null) mCustomNavView.setVisibility(GONE);
Adam Powell07cf9712013-02-05 16:13:57 -08001621 setHomeButtonEnabled(false, false);
Adam Powell8d02dea2011-05-31 21:35:13 -07001622 requestLayout();
1623 item.setActionViewExpanded(true);
Adam Powell038f1c82011-07-21 14:28:10 -07001624
1625 if (mExpandedActionView instanceof CollapsibleActionView) {
1626 ((CollapsibleActionView) mExpandedActionView).onActionViewExpanded();
1627 }
Amith Yamasani10da5902011-07-26 16:14:26 -07001628
Adam Powell8d02dea2011-05-31 21:35:13 -07001629 return true;
1630 }
1631
1632 @Override
1633 public boolean collapseItemActionView(MenuBuilder menu, MenuItemImpl item) {
Amith Yamasani10da5902011-07-26 16:14:26 -07001634 // Do this before detaching the actionview from the hierarchy, in case
1635 // it needs to dismiss the soft keyboard, etc.
1636 if (mExpandedActionView instanceof CollapsibleActionView) {
1637 ((CollapsibleActionView) mExpandedActionView).onActionViewCollapsed();
1638 }
1639
Adam Powell8d02dea2011-05-31 21:35:13 -07001640 removeView(mExpandedActionView);
Adam Powell27cba382013-01-22 18:55:20 -08001641 mUpGoerFive.removeView(mExpandedHomeLayout);
Adam Powellb0e217e2011-08-12 11:36:51 -07001642 mExpandedActionView = null;
Adam Powell8d02dea2011-05-31 21:35:13 -07001643 if ((mDisplayOptions & ActionBar.DISPLAY_SHOW_HOME) != 0) {
1644 mHomeLayout.setVisibility(VISIBLE);
1645 }
1646 if ((mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0) {
Adam Powell15a16a82011-06-20 10:35:27 -07001647 if (mTitleLayout == null) {
1648 initTitle();
1649 } else {
1650 mTitleLayout.setVisibility(VISIBLE);
1651 }
Adam Powell8d02dea2011-05-31 21:35:13 -07001652 }
Adam Powell6684e922013-03-26 15:38:26 -07001653 if (mTabScrollView != null) mTabScrollView.setVisibility(VISIBLE);
1654 if (mSpinner != null) mSpinner.setVisibility(VISIBLE);
1655 if (mCustomNavView != null) mCustomNavView.setVisibility(VISIBLE);
1656
Adam Powell8d02dea2011-05-31 21:35:13 -07001657 mExpandedHomeLayout.setIcon(null);
1658 mCurrentExpandedItem = null;
Adam Powell62f33032013-02-04 12:44:34 -08001659 setHomeButtonEnabled(mWasHomeEnabled); // Set by expandItemActionView above
Adam Powell8d02dea2011-05-31 21:35:13 -07001660 requestLayout();
1661 item.setActionViewExpanded(false);
Adam Powell038f1c82011-07-21 14:28:10 -07001662
Adam Powell8d02dea2011-05-31 21:35:13 -07001663 return true;
1664 }
Adam Powell11ed1d62011-07-11 21:19:59 -07001665
1666 @Override
1667 public int getId() {
1668 return 0;
1669 }
1670
1671 @Override
1672 public Parcelable onSaveInstanceState() {
1673 return null;
1674 }
1675
1676 @Override
1677 public void onRestoreInstanceState(Parcelable state) {
1678 }
Adam Powell8d02dea2011-05-31 21:35:13 -07001679 }
Adam Powell33b97432010-04-20 10:01:14 -07001680}