blob: 95f1f98f847f9703ae978d86bda8d47699a551ef [file] [log] [blame]
Adam Powell89e06452010-06-23 20:24:52 -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
17package com.android.internal.app;
18
Adam Powell2c9c9fe2010-07-16 10:17:57 -070019import com.android.internal.view.menu.MenuBuilder;
Adam Powell2c9c9fe2010-07-16 10:17:57 -070020import com.android.internal.view.menu.MenuPopupHelper;
21import com.android.internal.view.menu.SubMenuBuilder;
Adam Powell01feaee2011-02-10 15:05:05 -080022import com.android.internal.widget.ActionBarContainer;
Adam Powell89e06452010-06-23 20:24:52 -070023import com.android.internal.widget.ActionBarContextView;
24import com.android.internal.widget.ActionBarView;
Adam Powellf8ac6b72011-05-23 18:14:09 -070025import com.android.internal.widget.ScrollingTabContainerView;
Adam Powell89e06452010-06-23 20:24:52 -070026
Adam Powelld8b3f2e2010-12-02 13:37:03 -080027import android.animation.Animator;
Adam Powelld8b3f2e2010-12-02 13:37:03 -080028import android.animation.Animator.AnimatorListener;
Adam Powell07e1f982011-03-24 11:11:15 -070029import android.animation.AnimatorListenerAdapter;
Adam Powelld8b3f2e2010-12-02 13:37:03 -080030import android.animation.AnimatorSet;
Adam Powelle6ec7322010-12-07 15:29:26 -080031import android.animation.ObjectAnimator;
Adam Powell89e06452010-06-23 20:24:52 -070032import android.app.ActionBar;
Adam Powell661c9082010-07-02 10:09:44 -070033import android.app.Activity;
Adam Powelldec9dfd2010-08-09 15:27:54 -070034import android.app.Dialog;
Adam Powell661c9082010-07-02 10:09:44 -070035import android.app.FragmentTransaction;
Adam Powelldec9dfd2010-08-09 15:27:54 -070036import android.content.Context;
Adam Powellf8ac6b72011-05-23 18:14:09 -070037import android.content.res.Configuration;
Adam Powell89e06452010-06-23 20:24:52 -070038import android.graphics.drawable.Drawable;
Adam Powellc29f4e52011-07-13 20:40:52 -070039import android.os.Build;
Adam Powell0e94b512010-06-29 17:58:20 -070040import android.os.Handler;
Adam Powell6e346362010-07-23 10:18:23 -070041import android.view.ActionMode;
Adam Powell32555f32010-11-17 13:49:22 -080042import android.view.LayoutInflater;
Adam Powell89e06452010-06-23 20:24:52 -070043import android.view.Menu;
Adam Powell9168f0b2010-08-02 15:46:24 -070044import android.view.MenuInflater;
Adam Powell89e06452010-06-23 20:24:52 -070045import android.view.MenuItem;
46import android.view.View;
Adam Powelle6ec7322010-12-07 15:29:26 -080047import android.view.Window;
Adam Powell89e06452010-06-23 20:24:52 -070048import android.widget.SpinnerAdapter;
Adam Powell89e06452010-06-23 20:24:52 -070049
Adam Powell29ed7572010-07-14 16:24:56 -070050import java.lang.ref.WeakReference;
Adam Powell661c9082010-07-02 10:09:44 -070051import java.util.ArrayList;
52
Adam Powell89e06452010-06-23 20:24:52 -070053/**
54 * ActionBarImpl is the ActionBar implementation used
55 * by devices of all screen sizes. If it detects a compatible decor,
56 * it will split contextual modes across both the ActionBarView at
57 * the top of the screen and a horizontal LinearLayout at the bottom
58 * which is normally hidden.
59 */
60public class ActionBarImpl extends ActionBar {
Adam Powelld8145042011-03-24 14:18:27 -070061 private static final String TAG = "ActionBarImpl";
Adam Powell661c9082010-07-02 10:09:44 -070062
Adam Powelldec9dfd2010-08-09 15:27:54 -070063 private Context mContext;
Adam Powell661c9082010-07-02 10:09:44 -070064 private Activity mActivity;
Adam Powelldec9dfd2010-08-09 15:27:54 -070065 private Dialog mDialog;
Adam Powell661c9082010-07-02 10:09:44 -070066
Adam Powell01feaee2011-02-10 15:05:05 -080067 private ActionBarContainer mContainerView;
Adam Powell89e06452010-06-23 20:24:52 -070068 private ActionBarView mActionView;
Adam Powell640a66e2011-04-29 10:18:53 -070069 private ActionBarContextView mContextView;
70 private ActionBarContainer mSplitView;
Adam Powelle6ec7322010-12-07 15:29:26 -080071 private View mContentView;
Adam Powellf8ac6b72011-05-23 18:14:09 -070072 private ScrollingTabContainerView mTabScrollView;
Adam Powell661c9082010-07-02 10:09:44 -070073
74 private ArrayList<TabImpl> mTabs = new ArrayList<TabImpl>();
75
Adam Powell661c9082010-07-02 10:09:44 -070076 private TabImpl mSelectedTab;
Adam Powell0c24a552010-11-03 16:44:11 -070077 private int mSavedTabPosition = INVALID_POSITION;
Adam Powell89e06452010-06-23 20:24:52 -070078
Adam Powell060e3ca2011-07-19 20:39:16 -070079 ActionModeImpl mActionMode;
80 ActionMode mDeferredDestroyActionMode;
81 ActionMode.Callback mDeferredModeDestroyCallback;
Adam Powell89e06452010-06-23 20:24:52 -070082
Adam Powell8515ee82010-11-30 14:09:55 -080083 private boolean mLastMenuVisibility;
84 private ArrayList<OnMenuVisibilityListener> mMenuVisibilityListeners =
85 new ArrayList<OnMenuVisibilityListener>();
86
Adam Powell89e06452010-06-23 20:24:52 -070087 private static final int CONTEXT_DISPLAY_NORMAL = 0;
88 private static final int CONTEXT_DISPLAY_SPLIT = 1;
89
Adam Powell0c24a552010-11-03 16:44:11 -070090 private static final int INVALID_POSITION = -1;
91
Adam Powell89e06452010-06-23 20:24:52 -070092 private int mContextDisplayMode;
Adam Powellf8ac6b72011-05-23 18:14:09 -070093 private boolean mHasEmbeddedTabs;
94 private int mContentHeight;
Adam Powell0e94b512010-06-29 17:58:20 -070095
96 final Handler mHandler = new Handler();
Adam Powellf8ac6b72011-05-23 18:14:09 -070097 Runnable mTabSelector;
Adam Powelld8b3f2e2010-12-02 13:37:03 -080098
Adam Powell07e1f982011-03-24 11:11:15 -070099 private Animator mCurrentShowAnim;
100 private Animator mCurrentModeAnim;
Adam Powell50efbed2011-02-08 16:20:15 -0800101 private boolean mShowHideAnimationEnabled;
Adam Powell07e1f982011-03-24 11:11:15 -0700102 boolean mWasHiddenBeforeMode;
Adam Powelld8b3f2e2010-12-02 13:37:03 -0800103
Adam Powell07e1f982011-03-24 11:11:15 -0700104 final AnimatorListener mHideListener = new AnimatorListenerAdapter() {
Adam Powelle6ec7322010-12-07 15:29:26 -0800105 @Override
106 public void onAnimationEnd(Animator animation) {
107 if (mContentView != null) {
108 mContentView.setTranslationY(0);
Adam Powell060e3ca2011-07-19 20:39:16 -0700109 mContainerView.setTranslationY(0);
Adam Powelle6ec7322010-12-07 15:29:26 -0800110 }
111 mContainerView.setVisibility(View.GONE);
Adam Powell01feaee2011-02-10 15:05:05 -0800112 mContainerView.setTransitioning(false);
Adam Powell07e1f982011-03-24 11:11:15 -0700113 mCurrentShowAnim = null;
Adam Powell060e3ca2011-07-19 20:39:16 -0700114 completeDeferredDestroyActionMode();
Adam Powelle6ec7322010-12-07 15:29:26 -0800115 }
116 };
117
Adam Powell07e1f982011-03-24 11:11:15 -0700118 final AnimatorListener mShowListener = new AnimatorListenerAdapter() {
Adam Powelle6ec7322010-12-07 15:29:26 -0800119 @Override
120 public void onAnimationEnd(Animator animation) {
Adam Powell07e1f982011-03-24 11:11:15 -0700121 mCurrentShowAnim = null;
Adam Powell45f1e082010-12-10 14:20:13 -0800122 mContainerView.requestLayout();
Adam Powelle6ec7322010-12-07 15:29:26 -0800123 }
Adam Powelle6ec7322010-12-07 15:29:26 -0800124 };
125
Adam Powell661c9082010-07-02 10:09:44 -0700126 public ActionBarImpl(Activity activity) {
Adam Powell661c9082010-07-02 10:09:44 -0700127 mActivity = activity;
Adam Powelle6ec7322010-12-07 15:29:26 -0800128 Window window = activity.getWindow();
129 View decor = window.getDecorView();
130 init(decor);
131 if (!mActivity.getWindow().hasFeature(Window.FEATURE_ACTION_BAR_OVERLAY)) {
132 mContentView = decor.findViewById(android.R.id.content);
133 }
Adam Powelldec9dfd2010-08-09 15:27:54 -0700134 }
135
136 public ActionBarImpl(Dialog dialog) {
137 mDialog = dialog;
138 init(dialog.getWindow().getDecorView());
139 }
140
141 private void init(View decor) {
142 mContext = decor.getContext();
Adam Powell89e06452010-06-23 20:24:52 -0700143 mActionView = (ActionBarView) decor.findViewById(com.android.internal.R.id.action_bar);
Adam Powell640a66e2011-04-29 10:18:53 -0700144 mContextView = (ActionBarContextView) decor.findViewById(
Adam Powell89e06452010-06-23 20:24:52 -0700145 com.android.internal.R.id.action_context_bar);
Adam Powell01feaee2011-02-10 15:05:05 -0800146 mContainerView = (ActionBarContainer) decor.findViewById(
Adam Powelld8b3f2e2010-12-02 13:37:03 -0800147 com.android.internal.R.id.action_bar_container);
Adam Powell640a66e2011-04-29 10:18:53 -0700148 mSplitView = (ActionBarContainer) decor.findViewById(
149 com.android.internal.R.id.split_action_bar);
Steve Block08f194b2010-08-24 18:20:48 +0100150
Adam Powell640a66e2011-04-29 10:18:53 -0700151 if (mActionView == null || mContextView == null || mContainerView == null) {
Adam Powell89e06452010-06-23 20:24:52 -0700152 throw new IllegalStateException(getClass().getSimpleName() + " can only be used " +
153 "with a compatible window decor layout");
154 }
Adam Powell0e94b512010-06-29 17:58:20 -0700155
Adam Powellf8ac6b72011-05-23 18:14:09 -0700156 mHasEmbeddedTabs = mContext.getResources().getBoolean(
157 com.android.internal.R.bool.action_bar_embed_tabs);
Adam Powell640a66e2011-04-29 10:18:53 -0700158 mActionView.setContextView(mContextView);
Adam Powell9b4bee02011-04-27 19:24:47 -0700159 mContextDisplayMode = mActionView.isSplitActionBar() ?
160 CONTEXT_DISPLAY_SPLIT : CONTEXT_DISPLAY_NORMAL;
Adam Powelldae78242011-04-25 15:23:41 -0700161
Adam Powellcc2e5be2011-06-10 11:55:06 -0700162 mContentHeight = mActionView.getContentHeight();
Adam Powellc29f4e52011-07-13 20:40:52 -0700163
164 // Older apps get the home button interaction enabled by default.
165 // Newer apps need to enable it explicitly.
Adam Powell28fa07e2011-07-15 20:17:25 -0700166 setHomeButtonEnabled(mContext.getApplicationInfo().targetSdkVersion <
167 Build.VERSION_CODES.ICE_CREAM_SANDWICH);
Adam Powellf8ac6b72011-05-23 18:14:09 -0700168 }
169
170 public void onConfigurationChanged(Configuration newConfig) {
171 mHasEmbeddedTabs = mContext.getResources().getBoolean(
172 com.android.internal.R.bool.action_bar_embed_tabs);
173
174 // Switch tab layout configuration if needed
175 if (!mHasEmbeddedTabs) {
176 mActionView.setEmbeddedTabView(null);
177 mContainerView.setTabContainer(mTabScrollView);
178 } else {
179 mContainerView.setTabContainer(null);
180 if (mTabScrollView != null) {
181 mTabScrollView.setVisibility(View.VISIBLE);
182 }
183 mActionView.setEmbeddedTabView(mTabScrollView);
184 }
Adam Powelld21aa122011-05-27 13:09:52 -0700185 mActionView.setCollapsable(!mHasEmbeddedTabs &&
186 getNavigationMode() == NAVIGATION_MODE_TABS);
Adam Powellf8ac6b72011-05-23 18:14:09 -0700187
Adam Powellcc2e5be2011-06-10 11:55:06 -0700188 mContentHeight = mActionView.getContentHeight();
Adam Powellf8ac6b72011-05-23 18:14:09 -0700189
190 if (mTabScrollView != null) {
191 mTabScrollView.getLayoutParams().height = mContentHeight;
192 mTabScrollView.requestLayout();
193 }
194 }
195
196 private void ensureTabsExist() {
197 if (mTabScrollView != null) {
198 return;
199 }
200
201 ScrollingTabContainerView tabScroller = mActionView.createTabContainer();
202
203 if (mHasEmbeddedTabs) {
204 tabScroller.setVisibility(View.VISIBLE);
205 mActionView.setEmbeddedTabView(tabScroller);
206 } else {
Adam Powelldae78242011-04-25 15:23:41 -0700207 tabScroller.setVisibility(getNavigationMode() == NAVIGATION_MODE_TABS ?
208 View.VISIBLE : View.GONE);
Adam Powelldae78242011-04-25 15:23:41 -0700209 mContainerView.setTabContainer(tabScroller);
Adam Powelldae78242011-04-25 15:23:41 -0700210 }
Adam Powellf8ac6b72011-05-23 18:14:09 -0700211 mTabScrollView = tabScroller;
Adam Powell89e06452010-06-23 20:24:52 -0700212 }
213
Adam Powell060e3ca2011-07-19 20:39:16 -0700214 void completeDeferredDestroyActionMode() {
215 if (mDeferredModeDestroyCallback != null) {
216 mDeferredModeDestroyCallback.onDestroyActionMode(mDeferredDestroyActionMode);
217 mDeferredDestroyActionMode = null;
218 mDeferredModeDestroyCallback = null;
219 }
220 }
221
Adam Powell50efbed2011-02-08 16:20:15 -0800222 /**
223 * Enables or disables animation between show/hide states.
224 * If animation is disabled using this method, animations in progress
225 * will be finished.
226 *
227 * @param enabled true to animate, false to not animate.
228 */
229 public void setShowHideAnimationEnabled(boolean enabled) {
230 mShowHideAnimationEnabled = enabled;
Adam Powell07e1f982011-03-24 11:11:15 -0700231 if (!enabled && mCurrentShowAnim != null) {
232 mCurrentShowAnim.end();
Adam Powell50efbed2011-02-08 16:20:15 -0800233 }
234 }
235
Adam Powell8515ee82010-11-30 14:09:55 -0800236 public void addOnMenuVisibilityListener(OnMenuVisibilityListener listener) {
237 mMenuVisibilityListeners.add(listener);
238 }
239
240 public void removeOnMenuVisibilityListener(OnMenuVisibilityListener listener) {
241 mMenuVisibilityListeners.remove(listener);
242 }
243
244 public void dispatchMenuVisibilityChanged(boolean isVisible) {
245 if (isVisible == mLastMenuVisibility) {
246 return;
247 }
248 mLastMenuVisibility = isVisible;
249
250 final int count = mMenuVisibilityListeners.size();
251 for (int i = 0; i < count; i++) {
252 mMenuVisibilityListeners.get(i).onMenuVisibilityChanged(isVisible);
253 }
254 }
255
Adam Powella66c7b02010-07-28 15:28:25 -0700256 @Override
Adam Powell3f476b32011-01-03 19:25:36 -0800257 public void setCustomView(int resId) {
258 setCustomView(LayoutInflater.from(mContext).inflate(resId, mActionView, false));
259 }
260
261 @Override
262 public void setDisplayUseLogoEnabled(boolean useLogo) {
263 setDisplayOptions(useLogo ? DISPLAY_USE_LOGO : 0, DISPLAY_USE_LOGO);
264 }
265
266 @Override
267 public void setDisplayShowHomeEnabled(boolean showHome) {
268 setDisplayOptions(showHome ? DISPLAY_SHOW_HOME : 0, DISPLAY_SHOW_HOME);
269 }
270
271 @Override
272 public void setDisplayHomeAsUpEnabled(boolean showHomeAsUp) {
273 setDisplayOptions(showHomeAsUp ? DISPLAY_HOME_AS_UP : 0, DISPLAY_HOME_AS_UP);
274 }
275
276 @Override
277 public void setDisplayShowTitleEnabled(boolean showTitle) {
278 setDisplayOptions(showTitle ? DISPLAY_SHOW_TITLE : 0, DISPLAY_SHOW_TITLE);
279 }
280
281 @Override
282 public void setDisplayShowCustomEnabled(boolean showCustom) {
283 setDisplayOptions(showCustom ? DISPLAY_SHOW_CUSTOM : 0, DISPLAY_SHOW_CUSTOM);
284 }
285
286 @Override
Adam Powellc29f4e52011-07-13 20:40:52 -0700287 public void setHomeButtonEnabled(boolean enable) {
288 mActionView.setHomeButtonEnabled(enable);
Adam Powelldae78242011-04-25 15:23:41 -0700289 }
290
291 @Override
Adam Powella66c7b02010-07-28 15:28:25 -0700292 public void setTitle(int resId) {
Adam Powelldec9dfd2010-08-09 15:27:54 -0700293 setTitle(mContext.getString(resId));
Adam Powella66c7b02010-07-28 15:28:25 -0700294 }
295
296 @Override
297 public void setSubtitle(int resId) {
Adam Powelldec9dfd2010-08-09 15:27:54 -0700298 setSubtitle(mContext.getString(resId));
Adam Powella66c7b02010-07-28 15:28:25 -0700299 }
300
Adam Powell17809772010-07-21 13:25:11 -0700301 public void setSelectedNavigationItem(int position) {
302 switch (mActionView.getNavigationMode()) {
303 case NAVIGATION_MODE_TABS:
304 selectTab(mTabs.get(position));
305 break;
Adam Powell9ab97872010-10-26 21:47:29 -0700306 case NAVIGATION_MODE_LIST:
Adam Powell17809772010-07-21 13:25:11 -0700307 mActionView.setDropdownSelectedPosition(position);
308 break;
309 default:
310 throw new IllegalStateException(
Adam Powell9ab97872010-10-26 21:47:29 -0700311 "setSelectedNavigationIndex not valid for current navigation mode");
Adam Powell17809772010-07-21 13:25:11 -0700312 }
313 }
314
Adam Powell9ab97872010-10-26 21:47:29 -0700315 public void removeAllTabs() {
316 cleanupTabs();
Adam Powell17809772010-07-21 13:25:11 -0700317 }
318
Adam Powell661c9082010-07-02 10:09:44 -0700319 private void cleanupTabs() {
320 if (mSelectedTab != null) {
321 selectTab(null);
322 }
Adam Powell2b6230e2010-09-07 17:55:25 -0700323 mTabs.clear();
Adam Powelld21aa122011-05-27 13:09:52 -0700324 if (mTabScrollView != null) {
325 mTabScrollView.removeAllTabs();
326 }
Adam Powell0c24a552010-11-03 16:44:11 -0700327 mSavedTabPosition = INVALID_POSITION;
Adam Powell661c9082010-07-02 10:09:44 -0700328 }
329
Adam Powell0e94b512010-06-29 17:58:20 -0700330 public void setTitle(CharSequence title) {
331 mActionView.setTitle(title);
332 }
333
334 public void setSubtitle(CharSequence subtitle) {
335 mActionView.setSubtitle(subtitle);
336 }
337
Adam Powell89e06452010-06-23 20:24:52 -0700338 public void setDisplayOptions(int options) {
339 mActionView.setDisplayOptions(options);
340 }
Adam Powell0e94b512010-06-29 17:58:20 -0700341
Adam Powell89e06452010-06-23 20:24:52 -0700342 public void setDisplayOptions(int options, int mask) {
343 final int current = mActionView.getDisplayOptions();
344 mActionView.setDisplayOptions((options & mask) | (current & ~mask));
345 }
346
347 public void setBackgroundDrawable(Drawable d) {
Adam Powelle8c1e5c2010-12-13 10:49:32 -0800348 mContainerView.setBackgroundDrawable(d);
Adam Powell89e06452010-06-23 20:24:52 -0700349 }
350
Adam Powellef704442010-11-16 14:48:22 -0800351 public View getCustomView() {
Adam Powell89e06452010-06-23 20:24:52 -0700352 return mActionView.getCustomNavigationView();
353 }
354
355 public CharSequence getTitle() {
356 return mActionView.getTitle();
357 }
358
359 public CharSequence getSubtitle() {
360 return mActionView.getSubtitle();
361 }
362
363 public int getNavigationMode() {
364 return mActionView.getNavigationMode();
365 }
366
367 public int getDisplayOptions() {
368 return mActionView.getDisplayOptions();
369 }
370
Adam Powell5d279772010-07-27 16:34:07 -0700371 public ActionMode startActionMode(ActionMode.Callback callback) {
Adam Powell060e3ca2011-07-19 20:39:16 -0700372 boolean wasHidden = false;
Adam Powell5d279772010-07-27 16:34:07 -0700373 if (mActionMode != null) {
Adam Powell060e3ca2011-07-19 20:39:16 -0700374 wasHidden = mWasHiddenBeforeMode;
Adam Powell5d279772010-07-27 16:34:07 -0700375 mActionMode.finish();
Adam Powell6e346362010-07-23 10:18:23 -0700376 }
Adam Powell3461b322010-07-14 11:34:43 -0700377
Adam Powell640a66e2011-04-29 10:18:53 -0700378 mContextView.killMode();
Adam Powell5ee36c42011-06-02 12:59:43 -0700379 ActionModeImpl mode = new ActionModeImpl(callback);
380 if (mode.dispatchOnCreate()) {
Adam Powell060e3ca2011-07-19 20:39:16 -0700381 mWasHiddenBeforeMode = !isShowing() || wasHidden;
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700382 mode.invalidate();
Adam Powell640a66e2011-04-29 10:18:53 -0700383 mContextView.initForMode(mode);
384 animateToMode(true);
Adam Powell1ab418a2011-06-09 20:49:49 -0700385 if (mSplitView != null && mContextDisplayMode == CONTEXT_DISPLAY_SPLIT) {
Adam Powell89e06452010-06-23 20:24:52 -0700386 // TODO animate this
Adam Powell640a66e2011-04-29 10:18:53 -0700387 mSplitView.setVisibility(View.VISIBLE);
Adam Powell89e06452010-06-23 20:24:52 -0700388 }
Adam Powell5d279772010-07-27 16:34:07 -0700389 mActionMode = mode;
Adam Powellac695c62010-07-20 18:19:27 -0700390 return mode;
Adam Powell89e06452010-06-23 20:24:52 -0700391 }
Adam Powellac695c62010-07-20 18:19:27 -0700392 return null;
Adam Powell89e06452010-06-23 20:24:52 -0700393 }
394
Adam Powell661c9082010-07-02 10:09:44 -0700395 private void configureTab(Tab tab, int position) {
396 final TabImpl tabi = (TabImpl) tab;
Adam Powell2b6230e2010-09-07 17:55:25 -0700397 final ActionBar.TabListener callback = tabi.getCallback();
398
399 if (callback == null) {
400 throw new IllegalStateException("Action Bar Tab must have a Callback");
401 }
Adam Powell661c9082010-07-02 10:09:44 -0700402
403 tabi.setPosition(position);
404 mTabs.add(position, tabi);
405
Adam Powell81b89442010-11-02 17:58:56 -0700406 final int count = mTabs.size();
407 for (int i = position + 1; i < count; i++) {
408 mTabs.get(i).setPosition(i);
Adam Powell661c9082010-07-02 10:09:44 -0700409 }
Adam Powell661c9082010-07-02 10:09:44 -0700410 }
411
412 @Override
413 public void addTab(Tab tab) {
Adam Powell81b89442010-11-02 17:58:56 -0700414 addTab(tab, mTabs.isEmpty());
Adam Powell661c9082010-07-02 10:09:44 -0700415 }
416
417 @Override
Adam Powell2b6230e2010-09-07 17:55:25 -0700418 public void addTab(Tab tab, int position) {
Adam Powell81b89442010-11-02 17:58:56 -0700419 addTab(tab, position, mTabs.isEmpty());
420 }
421
422 @Override
423 public void addTab(Tab tab, boolean setSelected) {
Adam Powellf8ac6b72011-05-23 18:14:09 -0700424 ensureTabsExist();
425 mTabScrollView.addTab(tab, setSelected);
Adam Powell81b89442010-11-02 17:58:56 -0700426 configureTab(tab, mTabs.size());
427 if (setSelected) {
428 selectTab(tab);
429 }
430 }
431
432 @Override
433 public void addTab(Tab tab, int position, boolean setSelected) {
Adam Powellf8ac6b72011-05-23 18:14:09 -0700434 ensureTabsExist();
435 mTabScrollView.addTab(tab, position, setSelected);
Adam Powell661c9082010-07-02 10:09:44 -0700436 configureTab(tab, position);
Adam Powell81b89442010-11-02 17:58:56 -0700437 if (setSelected) {
438 selectTab(tab);
439 }
Adam Powell661c9082010-07-02 10:09:44 -0700440 }
441
442 @Override
443 public Tab newTab() {
444 return new TabImpl();
445 }
446
447 @Override
448 public void removeTab(Tab tab) {
449 removeTabAt(tab.getPosition());
450 }
451
452 @Override
453 public void removeTabAt(int position) {
Adam Powellf8ac6b72011-05-23 18:14:09 -0700454 if (mTabScrollView == null) {
455 // No tabs around to remove
456 return;
457 }
458
Adam Powell0c24a552010-11-03 16:44:11 -0700459 int selectedTabPosition = mSelectedTab != null
460 ? mSelectedTab.getPosition() : mSavedTabPosition;
Adam Powellf8ac6b72011-05-23 18:14:09 -0700461 mTabScrollView.removeTabAt(position);
Adam Powell0d8ec1d2011-05-03 14:49:13 -0700462 TabImpl removedTab = mTabs.remove(position);
463 if (removedTab != null) {
464 removedTab.setPosition(-1);
465 }
Adam Powell661c9082010-07-02 10:09:44 -0700466
467 final int newTabCount = mTabs.size();
468 for (int i = position; i < newTabCount; i++) {
469 mTabs.get(i).setPosition(i);
470 }
471
Adam Powell0c24a552010-11-03 16:44:11 -0700472 if (selectedTabPosition == position) {
473 selectTab(mTabs.isEmpty() ? null : mTabs.get(Math.max(0, position - 1)));
474 }
Adam Powell661c9082010-07-02 10:09:44 -0700475 }
476
477 @Override
Adam Powell661c9082010-07-02 10:09:44 -0700478 public void selectTab(Tab tab) {
Adam Powell0c24a552010-11-03 16:44:11 -0700479 if (getNavigationMode() != NAVIGATION_MODE_TABS) {
480 mSavedTabPosition = tab != null ? tab.getPosition() : INVALID_POSITION;
481 return;
482 }
483
Dianne Hackborn48e7b452011-01-17 12:28:35 -0800484 final FragmentTransaction trans = mActivity.getFragmentManager().beginTransaction()
Adam Powell0c24a552010-11-03 16:44:11 -0700485 .disallowAddToBackStack();
Adam Powell7f9b9052010-10-19 16:56:07 -0700486
487 if (mSelectedTab == tab) {
488 if (mSelectedTab != null) {
489 mSelectedTab.getCallback().onTabReselected(mSelectedTab, trans);
Adam Powellf8ac6b72011-05-23 18:14:09 -0700490 mTabScrollView.animateToTab(tab.getPosition());
Adam Powell7f9b9052010-10-19 16:56:07 -0700491 }
492 } else {
Adam Powellf8ac6b72011-05-23 18:14:09 -0700493 mTabScrollView.setTabSelected(tab != null ? tab.getPosition() : Tab.INVALID_POSITION);
Adam Powell7f9b9052010-10-19 16:56:07 -0700494 if (mSelectedTab != null) {
495 mSelectedTab.getCallback().onTabUnselected(mSelectedTab, trans);
496 }
497 mSelectedTab = (TabImpl) tab;
498 if (mSelectedTab != null) {
499 mSelectedTab.getCallback().onTabSelected(mSelectedTab, trans);
500 }
Adam Powell2b6230e2010-09-07 17:55:25 -0700501 }
502
503 if (!trans.isEmpty()) {
504 trans.commit();
505 }
506 }
507
508 @Override
509 public Tab getSelectedTab() {
510 return mSelectedTab;
Adam Powell661c9082010-07-02 10:09:44 -0700511 }
512
Adam Powell6b336f82010-08-10 20:13:01 -0700513 @Override
514 public int getHeight() {
Adam Powell58c5dc12011-07-14 21:08:10 -0700515 return mContainerView.getHeight();
Adam Powell6b336f82010-08-10 20:13:01 -0700516 }
517
518 @Override
519 public void show() {
Adam Powell07e1f982011-03-24 11:11:15 -0700520 show(true);
521 }
522
523 void show(boolean markHiddenBeforeMode) {
524 if (mCurrentShowAnim != null) {
525 mCurrentShowAnim.end();
Adam Powell45f1e082010-12-10 14:20:13 -0800526 }
Adam Powelld76cee22011-01-31 15:05:05 -0800527 if (mContainerView.getVisibility() == View.VISIBLE) {
Adam Powell07e1f982011-03-24 11:11:15 -0700528 if (markHiddenBeforeMode) mWasHiddenBeforeMode = false;
Adam Powelld76cee22011-01-31 15:05:05 -0800529 return;
530 }
Adam Powelld8b3f2e2010-12-02 13:37:03 -0800531 mContainerView.setVisibility(View.VISIBLE);
Adam Powell50efbed2011-02-08 16:20:15 -0800532
533 if (mShowHideAnimationEnabled) {
534 mContainerView.setAlpha(0);
535 AnimatorSet anim = new AnimatorSet();
536 AnimatorSet.Builder b = anim.play(ObjectAnimator.ofFloat(mContainerView, "alpha", 1));
537 if (mContentView != null) {
538 b.with(ObjectAnimator.ofFloat(mContentView, "translationY",
539 -mContainerView.getHeight(), 0));
540 mContainerView.setTranslationY(-mContainerView.getHeight());
541 b.with(ObjectAnimator.ofFloat(mContainerView, "translationY", 0));
542 }
Adam Powell1ab418a2011-06-09 20:49:49 -0700543 if (mSplitView != null && mContextDisplayMode == CONTEXT_DISPLAY_SPLIT) {
Adam Powell640a66e2011-04-29 10:18:53 -0700544 mSplitView.setAlpha(0);
545 b.with(ObjectAnimator.ofFloat(mSplitView, "alpha", 1));
546 }
Adam Powell50efbed2011-02-08 16:20:15 -0800547 anim.addListener(mShowListener);
Adam Powell07e1f982011-03-24 11:11:15 -0700548 mCurrentShowAnim = anim;
Adam Powell50efbed2011-02-08 16:20:15 -0800549 anim.start();
550 } else {
Adam Powelld8145042011-03-24 14:18:27 -0700551 mContainerView.setAlpha(1);
552 mContainerView.setTranslationY(0);
Adam Powell50efbed2011-02-08 16:20:15 -0800553 mShowListener.onAnimationEnd(null);
Adam Powelle6ec7322010-12-07 15:29:26 -0800554 }
Adam Powell6b336f82010-08-10 20:13:01 -0700555 }
556
557 @Override
558 public void hide() {
Adam Powell07e1f982011-03-24 11:11:15 -0700559 if (mCurrentShowAnim != null) {
560 mCurrentShowAnim.end();
Adam Powelle6ec7322010-12-07 15:29:26 -0800561 }
562 if (mContainerView.getVisibility() == View.GONE) {
563 return;
564 }
Adam Powell50efbed2011-02-08 16:20:15 -0800565
566 if (mShowHideAnimationEnabled) {
567 mContainerView.setAlpha(1);
Adam Powell01feaee2011-02-10 15:05:05 -0800568 mContainerView.setTransitioning(true);
Adam Powell50efbed2011-02-08 16:20:15 -0800569 AnimatorSet anim = new AnimatorSet();
570 AnimatorSet.Builder b = anim.play(ObjectAnimator.ofFloat(mContainerView, "alpha", 0));
571 if (mContentView != null) {
572 b.with(ObjectAnimator.ofFloat(mContentView, "translationY",
573 0, -mContainerView.getHeight()));
574 b.with(ObjectAnimator.ofFloat(mContainerView, "translationY",
575 -mContainerView.getHeight()));
576 }
Adam Powell1ab418a2011-06-09 20:49:49 -0700577 if (mSplitView != null && mSplitView.getVisibility() == View.VISIBLE) {
Adam Powell640a66e2011-04-29 10:18:53 -0700578 mSplitView.setAlpha(1);
579 b.with(ObjectAnimator.ofFloat(mSplitView, "alpha", 0));
580 }
Adam Powell50efbed2011-02-08 16:20:15 -0800581 anim.addListener(mHideListener);
Adam Powell07e1f982011-03-24 11:11:15 -0700582 mCurrentShowAnim = anim;
Adam Powell50efbed2011-02-08 16:20:15 -0800583 anim.start();
584 } else {
585 mHideListener.onAnimationEnd(null);
Adam Powelle6ec7322010-12-07 15:29:26 -0800586 }
Adam Powell6b336f82010-08-10 20:13:01 -0700587 }
588
589 public boolean isShowing() {
Adam Powelld8b3f2e2010-12-02 13:37:03 -0800590 return mContainerView.getVisibility() == View.VISIBLE;
591 }
592
Adam Powell640a66e2011-04-29 10:18:53 -0700593 void animateToMode(boolean toActionMode) {
Adam Powell060e3ca2011-07-19 20:39:16 -0700594 if (toActionMode) {
595 show(false);
596 }
Adam Powell07e1f982011-03-24 11:11:15 -0700597 if (mCurrentModeAnim != null) {
598 mCurrentModeAnim.end();
599 }
Adam Powelld8b3f2e2010-12-02 13:37:03 -0800600
Adam Powell640a66e2011-04-29 10:18:53 -0700601 mActionView.animateToVisibility(toActionMode ? View.GONE : View.VISIBLE);
602 mContextView.animateToVisibility(toActionMode ? View.VISIBLE : View.GONE);
Adam Powellf6ce6a92011-06-29 10:25:01 -0700603 if (mTabScrollView != null && !mActionView.hasEmbeddedTabs() && mActionView.isCollapsed()) {
604 mTabScrollView.animateToVisibility(toActionMode ? View.GONE : View.VISIBLE);
605 }
Adam Powell6b336f82010-08-10 20:13:01 -0700606 }
607
Adam Powell89e06452010-06-23 20:24:52 -0700608 /**
609 * @hide
610 */
Adam Powell5d279772010-07-27 16:34:07 -0700611 public class ActionModeImpl extends ActionMode implements MenuBuilder.Callback {
Adam Powell6e346362010-07-23 10:18:23 -0700612 private ActionMode.Callback mCallback;
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700613 private MenuBuilder mMenu;
Adam Powell29ed7572010-07-14 16:24:56 -0700614 private WeakReference<View> mCustomView;
Adam Powell89e06452010-06-23 20:24:52 -0700615
Adam Powell5d279772010-07-27 16:34:07 -0700616 public ActionModeImpl(ActionMode.Callback callback) {
Adam Powell89e06452010-06-23 20:24:52 -0700617 mCallback = callback;
Adam Powell4d9861e2010-08-17 11:14:40 -0700618 mMenu = new MenuBuilder(mActionView.getContext())
619 .setDefaultShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700620 mMenu.setCallback(this);
Adam Powell89e06452010-06-23 20:24:52 -0700621 }
Adam Powell9168f0b2010-08-02 15:46:24 -0700622
623 @Override
624 public MenuInflater getMenuInflater() {
Adam Powell4d9861e2010-08-17 11:14:40 -0700625 return new MenuInflater(mContext);
Adam Powell9168f0b2010-08-02 15:46:24 -0700626 }
627
Adam Powell89e06452010-06-23 20:24:52 -0700628 @Override
629 public Menu getMenu() {
630 return mMenu;
631 }
632
633 @Override
634 public void finish() {
Adam Powell5d279772010-07-27 16:34:07 -0700635 if (mActionMode != this) {
636 // Not the active action mode - no-op
Adam Powell93b6bc32010-07-22 11:36:35 -0700637 return;
638 }
639
Adam Powell060e3ca2011-07-19 20:39:16 -0700640 // If we were hidden before the mode was shown, defer the onDestroy
641 // callback until the animation is finished and associated relayout
642 // is about to happen. This lets apps better anticipate visibility
643 // and layout behavior.
644 if (mWasHiddenBeforeMode) {
645 mDeferredDestroyActionMode = this;
646 mDeferredModeDestroyCallback = mCallback;
647 } else {
648 mCallback.onDestroyActionMode(this);
649 }
Adam Powelld8b3f2e2010-12-02 13:37:03 -0800650 mCallback = null;
Adam Powell640a66e2011-04-29 10:18:53 -0700651 animateToMode(false);
Adam Powell0e94b512010-06-29 17:58:20 -0700652
653 // Clear out the context mode views after the animation finishes
Adam Powell640a66e2011-04-29 10:18:53 -0700654 mContextView.closeMode();
Adam Powellf6ce6a92011-06-29 10:25:01 -0700655
Adam Powell5d279772010-07-27 16:34:07 -0700656 mActionMode = null;
Adam Powell07e1f982011-03-24 11:11:15 -0700657
658 if (mWasHiddenBeforeMode) {
659 hide();
660 }
Adam Powell89e06452010-06-23 20:24:52 -0700661 }
662
663 @Override
664 public void invalidate() {
Adam Powell5ee36c42011-06-02 12:59:43 -0700665 mMenu.stopDispatchingItemsChanged();
666 try {
667 mCallback.onPrepareActionMode(this, mMenu);
668 } finally {
669 mMenu.startDispatchingItemsChanged();
670 }
671 }
672
673 public boolean dispatchOnCreate() {
674 mMenu.stopDispatchingItemsChanged();
675 try {
676 return mCallback.onCreateActionMode(this, mMenu);
677 } finally {
678 mMenu.startDispatchingItemsChanged();
Adam Powell89e06452010-06-23 20:24:52 -0700679 }
680 }
681
682 @Override
683 public void setCustomView(View view) {
Adam Powell640a66e2011-04-29 10:18:53 -0700684 mContextView.setCustomView(view);
Adam Powell29ed7572010-07-14 16:24:56 -0700685 mCustomView = new WeakReference<View>(view);
Adam Powell89e06452010-06-23 20:24:52 -0700686 }
687
688 @Override
689 public void setSubtitle(CharSequence subtitle) {
Adam Powell640a66e2011-04-29 10:18:53 -0700690 mContextView.setSubtitle(subtitle);
Adam Powell89e06452010-06-23 20:24:52 -0700691 }
692
693 @Override
694 public void setTitle(CharSequence title) {
Adam Powell640a66e2011-04-29 10:18:53 -0700695 mContextView.setTitle(title);
Adam Powell89e06452010-06-23 20:24:52 -0700696 }
Adam Powell29ed7572010-07-14 16:24:56 -0700697
698 @Override
Adam Powellc9ae2a22010-07-28 14:44:21 -0700699 public void setTitle(int resId) {
Adam Powell48e8ac32011-01-14 12:10:24 -0800700 setTitle(mContext.getResources().getString(resId));
Adam Powellc9ae2a22010-07-28 14:44:21 -0700701 }
702
703 @Override
704 public void setSubtitle(int resId) {
Adam Powell48e8ac32011-01-14 12:10:24 -0800705 setSubtitle(mContext.getResources().getString(resId));
Adam Powellc9ae2a22010-07-28 14:44:21 -0700706 }
707
708 @Override
Adam Powell29ed7572010-07-14 16:24:56 -0700709 public CharSequence getTitle() {
Adam Powell640a66e2011-04-29 10:18:53 -0700710 return mContextView.getTitle();
Adam Powell29ed7572010-07-14 16:24:56 -0700711 }
712
713 @Override
714 public CharSequence getSubtitle() {
Adam Powell640a66e2011-04-29 10:18:53 -0700715 return mContextView.getSubtitle();
Adam Powell29ed7572010-07-14 16:24:56 -0700716 }
Adam Powell89e06452010-06-23 20:24:52 -0700717
Adam Powell29ed7572010-07-14 16:24:56 -0700718 @Override
719 public View getCustomView() {
720 return mCustomView != null ? mCustomView.get() : null;
721 }
722
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700723 public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
Adam Powelld8b3f2e2010-12-02 13:37:03 -0800724 if (mCallback != null) {
725 return mCallback.onActionItemClicked(this, item);
726 } else {
727 return false;
728 }
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700729 }
730
731 public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) {
732 }
733
734 public boolean onSubMenuSelected(SubMenuBuilder subMenu) {
Adam Powelld8b3f2e2010-12-02 13:37:03 -0800735 if (mCallback == null) {
736 return false;
737 }
738
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700739 if (!subMenu.hasVisibleItems()) {
740 return true;
Adam Powell89e06452010-06-23 20:24:52 -0700741 }
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700742
Adam Powelldec9dfd2010-08-09 15:27:54 -0700743 new MenuPopupHelper(mContext, subMenu).show();
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700744 return true;
745 }
746
747 public void onCloseSubMenu(SubMenuBuilder menu) {
748 }
749
750 public void onMenuModeChange(MenuBuilder menu) {
Adam Powelld8b3f2e2010-12-02 13:37:03 -0800751 if (mCallback == null) {
752 return;
753 }
Adam Powellf6148c52010-08-11 21:10:16 -0700754 invalidate();
Adam Powell640a66e2011-04-29 10:18:53 -0700755 mContextView.showOverflowMenu();
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700756 }
Adam Powell661c9082010-07-02 10:09:44 -0700757 }
758
759 /**
760 * @hide
761 */
762 public class TabImpl extends ActionBar.Tab {
Adam Powell2b6230e2010-09-07 17:55:25 -0700763 private ActionBar.TabListener mCallback;
764 private Object mTag;
Adam Powell661c9082010-07-02 10:09:44 -0700765 private Drawable mIcon;
766 private CharSequence mText;
Adam Powell0d8ec1d2011-05-03 14:49:13 -0700767 private int mPosition = -1;
Adam Powell2b6230e2010-09-07 17:55:25 -0700768 private View mCustomView;
Adam Powell661c9082010-07-02 10:09:44 -0700769
770 @Override
Adam Powell2b6230e2010-09-07 17:55:25 -0700771 public Object getTag() {
772 return mTag;
773 }
774
775 @Override
Adam Powell9ab97872010-10-26 21:47:29 -0700776 public Tab setTag(Object tag) {
Adam Powell2b6230e2010-09-07 17:55:25 -0700777 mTag = tag;
Adam Powell9ab97872010-10-26 21:47:29 -0700778 return this;
Adam Powell2b6230e2010-09-07 17:55:25 -0700779 }
780
781 public ActionBar.TabListener getCallback() {
782 return mCallback;
783 }
784
785 @Override
Adam Powell9ab97872010-10-26 21:47:29 -0700786 public Tab setTabListener(ActionBar.TabListener callback) {
Adam Powell2b6230e2010-09-07 17:55:25 -0700787 mCallback = callback;
Adam Powell9ab97872010-10-26 21:47:29 -0700788 return this;
Adam Powell2b6230e2010-09-07 17:55:25 -0700789 }
790
791 @Override
792 public View getCustomView() {
793 return mCustomView;
794 }
795
796 @Override
Adam Powell9ab97872010-10-26 21:47:29 -0700797 public Tab setCustomView(View view) {
Adam Powell2b6230e2010-09-07 17:55:25 -0700798 mCustomView = view;
Adam Powellf8ac6b72011-05-23 18:14:09 -0700799 if (mPosition >= 0) {
800 mTabScrollView.updateTab(mPosition);
801 }
Adam Powell9ab97872010-10-26 21:47:29 -0700802 return this;
Adam Powell661c9082010-07-02 10:09:44 -0700803 }
804
805 @Override
Adam Powell32555f32010-11-17 13:49:22 -0800806 public Tab setCustomView(int layoutResId) {
807 return setCustomView(LayoutInflater.from(mContext).inflate(layoutResId, null));
808 }
809
810 @Override
Adam Powell661c9082010-07-02 10:09:44 -0700811 public Drawable getIcon() {
812 return mIcon;
813 }
814
815 @Override
816 public int getPosition() {
817 return mPosition;
818 }
819
820 public void setPosition(int position) {
821 mPosition = position;
822 }
823
824 @Override
825 public CharSequence getText() {
826 return mText;
827 }
828
829 @Override
Adam Powell9ab97872010-10-26 21:47:29 -0700830 public Tab setIcon(Drawable icon) {
Adam Powell661c9082010-07-02 10:09:44 -0700831 mIcon = icon;
Adam Powellf8ac6b72011-05-23 18:14:09 -0700832 if (mPosition >= 0) {
833 mTabScrollView.updateTab(mPosition);
834 }
Adam Powell9ab97872010-10-26 21:47:29 -0700835 return this;
Adam Powell661c9082010-07-02 10:09:44 -0700836 }
837
838 @Override
Adam Powell32555f32010-11-17 13:49:22 -0800839 public Tab setIcon(int resId) {
840 return setIcon(mContext.getResources().getDrawable(resId));
841 }
842
843 @Override
Adam Powell9ab97872010-10-26 21:47:29 -0700844 public Tab setText(CharSequence text) {
Adam Powell661c9082010-07-02 10:09:44 -0700845 mText = text;
Adam Powellf8ac6b72011-05-23 18:14:09 -0700846 if (mPosition >= 0) {
847 mTabScrollView.updateTab(mPosition);
848 }
Adam Powell9ab97872010-10-26 21:47:29 -0700849 return this;
Adam Powell661c9082010-07-02 10:09:44 -0700850 }
851
852 @Override
Adam Powell32555f32010-11-17 13:49:22 -0800853 public Tab setText(int resId) {
854 return setText(mContext.getResources().getText(resId));
855 }
856
857 @Override
Adam Powell661c9082010-07-02 10:09:44 -0700858 public void select() {
859 selectTab(this);
Adam Powell89e06452010-06-23 20:24:52 -0700860 }
861 }
Adam Powell9ab97872010-10-26 21:47:29 -0700862
863 @Override
864 public void setCustomView(View view) {
865 mActionView.setCustomNavigationView(view);
866 }
867
868 @Override
869 public void setCustomView(View view, LayoutParams layoutParams) {
870 view.setLayoutParams(layoutParams);
871 mActionView.setCustomNavigationView(view);
872 }
873
874 @Override
Adam Powell8515ee82010-11-30 14:09:55 -0800875 public void setListNavigationCallbacks(SpinnerAdapter adapter, OnNavigationListener callback) {
Adam Powell9ab97872010-10-26 21:47:29 -0700876 mActionView.setDropdownAdapter(adapter);
877 mActionView.setCallback(callback);
878 }
879
880 @Override
881 public int getSelectedNavigationIndex() {
882 switch (mActionView.getNavigationMode()) {
883 case NAVIGATION_MODE_TABS:
Adam Powell04587962010-11-11 22:15:07 -0800884 return mSelectedTab != null ? mSelectedTab.getPosition() : -1;
Adam Powell9ab97872010-10-26 21:47:29 -0700885 case NAVIGATION_MODE_LIST:
886 return mActionView.getDropdownSelectedPosition();
887 default:
888 return -1;
889 }
890 }
891
892 @Override
893 public int getNavigationItemCount() {
894 switch (mActionView.getNavigationMode()) {
895 case NAVIGATION_MODE_TABS:
896 return mTabs.size();
897 case NAVIGATION_MODE_LIST:
898 SpinnerAdapter adapter = mActionView.getDropdownAdapter();
899 return adapter != null ? adapter.getCount() : 0;
900 default:
901 return 0;
902 }
903 }
904
905 @Override
Adam Powell0c24a552010-11-03 16:44:11 -0700906 public int getTabCount() {
907 return mTabs.size();
908 }
909
910 @Override
Adam Powell9ab97872010-10-26 21:47:29 -0700911 public void setNavigationMode(int mode) {
Adam Powell0c24a552010-11-03 16:44:11 -0700912 final int oldMode = mActionView.getNavigationMode();
913 switch (oldMode) {
914 case NAVIGATION_MODE_TABS:
915 mSavedTabPosition = getSelectedNavigationIndex();
916 selectTab(null);
Adam Powelldae78242011-04-25 15:23:41 -0700917 if (!mActionView.hasEmbeddedTabs()) {
Adam Powellf8ac6b72011-05-23 18:14:09 -0700918 mTabScrollView.setVisibility(View.GONE);
Adam Powelldae78242011-04-25 15:23:41 -0700919 }
Adam Powell0c24a552010-11-03 16:44:11 -0700920 break;
921 }
Adam Powell9ab97872010-10-26 21:47:29 -0700922 mActionView.setNavigationMode(mode);
Adam Powell0c24a552010-11-03 16:44:11 -0700923 switch (mode) {
924 case NAVIGATION_MODE_TABS:
Adam Powellf8ac6b72011-05-23 18:14:09 -0700925 ensureTabsExist();
Adam Powelldae78242011-04-25 15:23:41 -0700926 if (!mActionView.hasEmbeddedTabs()) {
Adam Powellf8ac6b72011-05-23 18:14:09 -0700927 mTabScrollView.setVisibility(View.VISIBLE);
Adam Powelldae78242011-04-25 15:23:41 -0700928 }
Adam Powell0c24a552010-11-03 16:44:11 -0700929 if (mSavedTabPosition != INVALID_POSITION) {
930 setSelectedNavigationItem(mSavedTabPosition);
931 mSavedTabPosition = INVALID_POSITION;
932 }
933 break;
934 }
Adam Powelld21aa122011-05-27 13:09:52 -0700935 mActionView.setCollapsable(mode == NAVIGATION_MODE_TABS && !mHasEmbeddedTabs);
Adam Powell9ab97872010-10-26 21:47:29 -0700936 }
937
938 @Override
939 public Tab getTabAt(int index) {
940 return mTabs.get(index);
941 }
Adam Powell0c24a552010-11-03 16:44:11 -0700942
Adam Powell0c24a552010-11-03 16:44:11 -0700943
Adam Powell1969b872011-03-22 11:52:48 -0700944 @Override
945 public void setIcon(int resId) {
Adam Powell45c515b2011-04-21 18:50:20 -0700946 mActionView.setIcon(resId);
Adam Powell1969b872011-03-22 11:52:48 -0700947 }
Adam Powell0c24a552010-11-03 16:44:11 -0700948
Adam Powell1969b872011-03-22 11:52:48 -0700949 @Override
950 public void setIcon(Drawable icon) {
951 mActionView.setIcon(icon);
952 }
953
954 @Override
955 public void setLogo(int resId) {
Adam Powell45c515b2011-04-21 18:50:20 -0700956 mActionView.setLogo(resId);
Adam Powell1969b872011-03-22 11:52:48 -0700957 }
958
959 @Override
960 public void setLogo(Drawable logo) {
961 mActionView.setLogo(logo);
Adam Powell0c24a552010-11-03 16:44:11 -0700962 }
Adam Powell89e06452010-06-23 20:24:52 -0700963}