blob: cf5666c467a9eabeb277a37a522e1d84a9d5b351 [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 Powell5d279772010-07-27 16:34:07 -070079 private ActionMode mActionMode;
Adam Powell89e06452010-06-23 20:24:52 -070080
Adam Powell8515ee82010-11-30 14:09:55 -080081 private boolean mLastMenuVisibility;
82 private ArrayList<OnMenuVisibilityListener> mMenuVisibilityListeners =
83 new ArrayList<OnMenuVisibilityListener>();
84
Adam Powell89e06452010-06-23 20:24:52 -070085 private static final int CONTEXT_DISPLAY_NORMAL = 0;
86 private static final int CONTEXT_DISPLAY_SPLIT = 1;
87
Adam Powell0c24a552010-11-03 16:44:11 -070088 private static final int INVALID_POSITION = -1;
89
Adam Powell89e06452010-06-23 20:24:52 -070090 private int mContextDisplayMode;
Adam Powellf8ac6b72011-05-23 18:14:09 -070091 private boolean mHasEmbeddedTabs;
92 private int mContentHeight;
Adam Powell0e94b512010-06-29 17:58:20 -070093
94 final Handler mHandler = new Handler();
Adam Powellf8ac6b72011-05-23 18:14:09 -070095 Runnable mTabSelector;
Adam Powelld8b3f2e2010-12-02 13:37:03 -080096
Adam Powell07e1f982011-03-24 11:11:15 -070097 private Animator mCurrentShowAnim;
98 private Animator mCurrentModeAnim;
Adam Powell50efbed2011-02-08 16:20:15 -080099 private boolean mShowHideAnimationEnabled;
Adam Powell07e1f982011-03-24 11:11:15 -0700100 boolean mWasHiddenBeforeMode;
Adam Powelld8b3f2e2010-12-02 13:37:03 -0800101
Adam Powell07e1f982011-03-24 11:11:15 -0700102 final AnimatorListener mHideListener = new AnimatorListenerAdapter() {
Adam Powelle6ec7322010-12-07 15:29:26 -0800103 @Override
104 public void onAnimationEnd(Animator animation) {
105 if (mContentView != null) {
106 mContentView.setTranslationY(0);
107 }
108 mContainerView.setVisibility(View.GONE);
Adam Powell01feaee2011-02-10 15:05:05 -0800109 mContainerView.setTransitioning(false);
Adam Powell07e1f982011-03-24 11:11:15 -0700110 mCurrentShowAnim = null;
Adam Powelle6ec7322010-12-07 15:29:26 -0800111 }
112 };
113
Adam Powell07e1f982011-03-24 11:11:15 -0700114 final AnimatorListener mShowListener = new AnimatorListenerAdapter() {
Adam Powelle6ec7322010-12-07 15:29:26 -0800115 @Override
116 public void onAnimationEnd(Animator animation) {
Adam Powell07e1f982011-03-24 11:11:15 -0700117 mCurrentShowAnim = null;
Adam Powell45f1e082010-12-10 14:20:13 -0800118 mContainerView.requestLayout();
Adam Powelle6ec7322010-12-07 15:29:26 -0800119 }
Adam Powelle6ec7322010-12-07 15:29:26 -0800120 };
121
Adam Powell661c9082010-07-02 10:09:44 -0700122 public ActionBarImpl(Activity activity) {
Adam Powell661c9082010-07-02 10:09:44 -0700123 mActivity = activity;
Adam Powelle6ec7322010-12-07 15:29:26 -0800124 Window window = activity.getWindow();
125 View decor = window.getDecorView();
126 init(decor);
127 if (!mActivity.getWindow().hasFeature(Window.FEATURE_ACTION_BAR_OVERLAY)) {
128 mContentView = decor.findViewById(android.R.id.content);
129 }
Adam Powelldec9dfd2010-08-09 15:27:54 -0700130 }
131
132 public ActionBarImpl(Dialog dialog) {
133 mDialog = dialog;
134 init(dialog.getWindow().getDecorView());
135 }
136
137 private void init(View decor) {
138 mContext = decor.getContext();
Adam Powell89e06452010-06-23 20:24:52 -0700139 mActionView = (ActionBarView) decor.findViewById(com.android.internal.R.id.action_bar);
Adam Powell640a66e2011-04-29 10:18:53 -0700140 mContextView = (ActionBarContextView) decor.findViewById(
Adam Powell89e06452010-06-23 20:24:52 -0700141 com.android.internal.R.id.action_context_bar);
Adam Powell01feaee2011-02-10 15:05:05 -0800142 mContainerView = (ActionBarContainer) decor.findViewById(
Adam Powelld8b3f2e2010-12-02 13:37:03 -0800143 com.android.internal.R.id.action_bar_container);
Adam Powell640a66e2011-04-29 10:18:53 -0700144 mSplitView = (ActionBarContainer) decor.findViewById(
145 com.android.internal.R.id.split_action_bar);
Steve Block08f194b2010-08-24 18:20:48 +0100146
Adam Powell640a66e2011-04-29 10:18:53 -0700147 if (mActionView == null || mContextView == null || mContainerView == null) {
Adam Powell89e06452010-06-23 20:24:52 -0700148 throw new IllegalStateException(getClass().getSimpleName() + " can only be used " +
149 "with a compatible window decor layout");
150 }
Adam Powell0e94b512010-06-29 17:58:20 -0700151
Adam Powellf8ac6b72011-05-23 18:14:09 -0700152 mHasEmbeddedTabs = mContext.getResources().getBoolean(
153 com.android.internal.R.bool.action_bar_embed_tabs);
Adam Powell640a66e2011-04-29 10:18:53 -0700154 mActionView.setContextView(mContextView);
Adam Powell9b4bee02011-04-27 19:24:47 -0700155 mContextDisplayMode = mActionView.isSplitActionBar() ?
156 CONTEXT_DISPLAY_SPLIT : CONTEXT_DISPLAY_NORMAL;
Adam Powelldae78242011-04-25 15:23:41 -0700157
Adam Powellcc2e5be2011-06-10 11:55:06 -0700158 mContentHeight = mActionView.getContentHeight();
Adam Powellc29f4e52011-07-13 20:40:52 -0700159
160 // Older apps get the home button interaction enabled by default.
161 // Newer apps need to enable it explicitly.
162 if (mContext.getApplicationInfo().targetSdkVersion <
163 Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
164 setHomeButtonEnabled(true);
165 }
Adam Powellf8ac6b72011-05-23 18:14:09 -0700166 }
167
168 public void onConfigurationChanged(Configuration newConfig) {
169 mHasEmbeddedTabs = mContext.getResources().getBoolean(
170 com.android.internal.R.bool.action_bar_embed_tabs);
171
172 // Switch tab layout configuration if needed
173 if (!mHasEmbeddedTabs) {
174 mActionView.setEmbeddedTabView(null);
175 mContainerView.setTabContainer(mTabScrollView);
176 } else {
177 mContainerView.setTabContainer(null);
178 if (mTabScrollView != null) {
179 mTabScrollView.setVisibility(View.VISIBLE);
180 }
181 mActionView.setEmbeddedTabView(mTabScrollView);
182 }
Adam Powelld21aa122011-05-27 13:09:52 -0700183 mActionView.setCollapsable(!mHasEmbeddedTabs &&
184 getNavigationMode() == NAVIGATION_MODE_TABS);
Adam Powellf8ac6b72011-05-23 18:14:09 -0700185
Adam Powellcc2e5be2011-06-10 11:55:06 -0700186 mContentHeight = mActionView.getContentHeight();
Adam Powellf8ac6b72011-05-23 18:14:09 -0700187
188 if (mTabScrollView != null) {
189 mTabScrollView.getLayoutParams().height = mContentHeight;
190 mTabScrollView.requestLayout();
191 }
192 }
193
194 private void ensureTabsExist() {
195 if (mTabScrollView != null) {
196 return;
197 }
198
199 ScrollingTabContainerView tabScroller = mActionView.createTabContainer();
200
201 if (mHasEmbeddedTabs) {
202 tabScroller.setVisibility(View.VISIBLE);
203 mActionView.setEmbeddedTabView(tabScroller);
204 } else {
Adam Powelldae78242011-04-25 15:23:41 -0700205 tabScroller.setVisibility(getNavigationMode() == NAVIGATION_MODE_TABS ?
206 View.VISIBLE : View.GONE);
Adam Powelldae78242011-04-25 15:23:41 -0700207 mContainerView.setTabContainer(tabScroller);
Adam Powelldae78242011-04-25 15:23:41 -0700208 }
Adam Powellf8ac6b72011-05-23 18:14:09 -0700209 mTabScrollView = tabScroller;
Adam Powell89e06452010-06-23 20:24:52 -0700210 }
211
Adam Powell50efbed2011-02-08 16:20:15 -0800212 /**
213 * Enables or disables animation between show/hide states.
214 * If animation is disabled using this method, animations in progress
215 * will be finished.
216 *
217 * @param enabled true to animate, false to not animate.
218 */
219 public void setShowHideAnimationEnabled(boolean enabled) {
220 mShowHideAnimationEnabled = enabled;
Adam Powell07e1f982011-03-24 11:11:15 -0700221 if (!enabled && mCurrentShowAnim != null) {
222 mCurrentShowAnim.end();
Adam Powell50efbed2011-02-08 16:20:15 -0800223 }
224 }
225
Adam Powell8515ee82010-11-30 14:09:55 -0800226 public void addOnMenuVisibilityListener(OnMenuVisibilityListener listener) {
227 mMenuVisibilityListeners.add(listener);
228 }
229
230 public void removeOnMenuVisibilityListener(OnMenuVisibilityListener listener) {
231 mMenuVisibilityListeners.remove(listener);
232 }
233
234 public void dispatchMenuVisibilityChanged(boolean isVisible) {
235 if (isVisible == mLastMenuVisibility) {
236 return;
237 }
238 mLastMenuVisibility = isVisible;
239
240 final int count = mMenuVisibilityListeners.size();
241 for (int i = 0; i < count; i++) {
242 mMenuVisibilityListeners.get(i).onMenuVisibilityChanged(isVisible);
243 }
244 }
245
Adam Powella66c7b02010-07-28 15:28:25 -0700246 @Override
Adam Powell3f476b32011-01-03 19:25:36 -0800247 public void setCustomView(int resId) {
248 setCustomView(LayoutInflater.from(mContext).inflate(resId, mActionView, false));
249 }
250
251 @Override
252 public void setDisplayUseLogoEnabled(boolean useLogo) {
253 setDisplayOptions(useLogo ? DISPLAY_USE_LOGO : 0, DISPLAY_USE_LOGO);
254 }
255
256 @Override
257 public void setDisplayShowHomeEnabled(boolean showHome) {
258 setDisplayOptions(showHome ? DISPLAY_SHOW_HOME : 0, DISPLAY_SHOW_HOME);
259 }
260
261 @Override
262 public void setDisplayHomeAsUpEnabled(boolean showHomeAsUp) {
263 setDisplayOptions(showHomeAsUp ? DISPLAY_HOME_AS_UP : 0, DISPLAY_HOME_AS_UP);
264 }
265
266 @Override
267 public void setDisplayShowTitleEnabled(boolean showTitle) {
268 setDisplayOptions(showTitle ? DISPLAY_SHOW_TITLE : 0, DISPLAY_SHOW_TITLE);
269 }
270
271 @Override
272 public void setDisplayShowCustomEnabled(boolean showCustom) {
273 setDisplayOptions(showCustom ? DISPLAY_SHOW_CUSTOM : 0, DISPLAY_SHOW_CUSTOM);
274 }
275
276 @Override
Adam Powellc29f4e52011-07-13 20:40:52 -0700277 public void setHomeButtonEnabled(boolean enable) {
278 mActionView.setHomeButtonEnabled(enable);
Adam Powelldae78242011-04-25 15:23:41 -0700279 }
280
281 @Override
Adam Powella66c7b02010-07-28 15:28:25 -0700282 public void setTitle(int resId) {
Adam Powelldec9dfd2010-08-09 15:27:54 -0700283 setTitle(mContext.getString(resId));
Adam Powella66c7b02010-07-28 15:28:25 -0700284 }
285
286 @Override
287 public void setSubtitle(int resId) {
Adam Powelldec9dfd2010-08-09 15:27:54 -0700288 setSubtitle(mContext.getString(resId));
Adam Powella66c7b02010-07-28 15:28:25 -0700289 }
290
Adam Powell17809772010-07-21 13:25:11 -0700291 public void setSelectedNavigationItem(int position) {
292 switch (mActionView.getNavigationMode()) {
293 case NAVIGATION_MODE_TABS:
294 selectTab(mTabs.get(position));
295 break;
Adam Powell9ab97872010-10-26 21:47:29 -0700296 case NAVIGATION_MODE_LIST:
Adam Powell17809772010-07-21 13:25:11 -0700297 mActionView.setDropdownSelectedPosition(position);
298 break;
299 default:
300 throw new IllegalStateException(
Adam Powell9ab97872010-10-26 21:47:29 -0700301 "setSelectedNavigationIndex not valid for current navigation mode");
Adam Powell17809772010-07-21 13:25:11 -0700302 }
303 }
304
Adam Powell9ab97872010-10-26 21:47:29 -0700305 public void removeAllTabs() {
306 cleanupTabs();
Adam Powell17809772010-07-21 13:25:11 -0700307 }
308
Adam Powell661c9082010-07-02 10:09:44 -0700309 private void cleanupTabs() {
310 if (mSelectedTab != null) {
311 selectTab(null);
312 }
Adam Powell2b6230e2010-09-07 17:55:25 -0700313 mTabs.clear();
Adam Powelld21aa122011-05-27 13:09:52 -0700314 if (mTabScrollView != null) {
315 mTabScrollView.removeAllTabs();
316 }
Adam Powell0c24a552010-11-03 16:44:11 -0700317 mSavedTabPosition = INVALID_POSITION;
Adam Powell661c9082010-07-02 10:09:44 -0700318 }
319
Adam Powell0e94b512010-06-29 17:58:20 -0700320 public void setTitle(CharSequence title) {
321 mActionView.setTitle(title);
322 }
323
324 public void setSubtitle(CharSequence subtitle) {
325 mActionView.setSubtitle(subtitle);
326 }
327
Adam Powell89e06452010-06-23 20:24:52 -0700328 public void setDisplayOptions(int options) {
329 mActionView.setDisplayOptions(options);
330 }
Adam Powell0e94b512010-06-29 17:58:20 -0700331
Adam Powell89e06452010-06-23 20:24:52 -0700332 public void setDisplayOptions(int options, int mask) {
333 final int current = mActionView.getDisplayOptions();
334 mActionView.setDisplayOptions((options & mask) | (current & ~mask));
335 }
336
337 public void setBackgroundDrawable(Drawable d) {
Adam Powelle8c1e5c2010-12-13 10:49:32 -0800338 mContainerView.setBackgroundDrawable(d);
Adam Powell89e06452010-06-23 20:24:52 -0700339 }
340
Adam Powellef704442010-11-16 14:48:22 -0800341 public View getCustomView() {
Adam Powell89e06452010-06-23 20:24:52 -0700342 return mActionView.getCustomNavigationView();
343 }
344
345 public CharSequence getTitle() {
346 return mActionView.getTitle();
347 }
348
349 public CharSequence getSubtitle() {
350 return mActionView.getSubtitle();
351 }
352
353 public int getNavigationMode() {
354 return mActionView.getNavigationMode();
355 }
356
357 public int getDisplayOptions() {
358 return mActionView.getDisplayOptions();
359 }
360
Adam Powell5d279772010-07-27 16:34:07 -0700361 public ActionMode startActionMode(ActionMode.Callback callback) {
362 if (mActionMode != null) {
363 mActionMode.finish();
Adam Powell6e346362010-07-23 10:18:23 -0700364 }
Adam Powell3461b322010-07-14 11:34:43 -0700365
Adam Powell640a66e2011-04-29 10:18:53 -0700366 mContextView.killMode();
Adam Powell5ee36c42011-06-02 12:59:43 -0700367 ActionModeImpl mode = new ActionModeImpl(callback);
368 if (mode.dispatchOnCreate()) {
Adam Powell07e1f982011-03-24 11:11:15 -0700369 mWasHiddenBeforeMode = !isShowing();
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700370 mode.invalidate();
Adam Powell640a66e2011-04-29 10:18:53 -0700371 mContextView.initForMode(mode);
372 animateToMode(true);
Adam Powell1ab418a2011-06-09 20:49:49 -0700373 if (mSplitView != null && mContextDisplayMode == CONTEXT_DISPLAY_SPLIT) {
Adam Powell89e06452010-06-23 20:24:52 -0700374 // TODO animate this
Adam Powell640a66e2011-04-29 10:18:53 -0700375 mSplitView.setVisibility(View.VISIBLE);
Adam Powell89e06452010-06-23 20:24:52 -0700376 }
Adam Powell5d279772010-07-27 16:34:07 -0700377 mActionMode = mode;
Adam Powellac695c62010-07-20 18:19:27 -0700378 return mode;
Adam Powell89e06452010-06-23 20:24:52 -0700379 }
Adam Powellac695c62010-07-20 18:19:27 -0700380 return null;
Adam Powell89e06452010-06-23 20:24:52 -0700381 }
382
Adam Powell661c9082010-07-02 10:09:44 -0700383 private void configureTab(Tab tab, int position) {
384 final TabImpl tabi = (TabImpl) tab;
Adam Powell2b6230e2010-09-07 17:55:25 -0700385 final ActionBar.TabListener callback = tabi.getCallback();
386
387 if (callback == null) {
388 throw new IllegalStateException("Action Bar Tab must have a Callback");
389 }
Adam Powell661c9082010-07-02 10:09:44 -0700390
391 tabi.setPosition(position);
392 mTabs.add(position, tabi);
393
Adam Powell81b89442010-11-02 17:58:56 -0700394 final int count = mTabs.size();
395 for (int i = position + 1; i < count; i++) {
396 mTabs.get(i).setPosition(i);
Adam Powell661c9082010-07-02 10:09:44 -0700397 }
Adam Powell661c9082010-07-02 10:09:44 -0700398 }
399
400 @Override
401 public void addTab(Tab tab) {
Adam Powell81b89442010-11-02 17:58:56 -0700402 addTab(tab, mTabs.isEmpty());
Adam Powell661c9082010-07-02 10:09:44 -0700403 }
404
405 @Override
Adam Powell2b6230e2010-09-07 17:55:25 -0700406 public void addTab(Tab tab, int position) {
Adam Powell81b89442010-11-02 17:58:56 -0700407 addTab(tab, position, mTabs.isEmpty());
408 }
409
410 @Override
411 public void addTab(Tab tab, boolean setSelected) {
Adam Powellf8ac6b72011-05-23 18:14:09 -0700412 ensureTabsExist();
413 mTabScrollView.addTab(tab, setSelected);
Adam Powell81b89442010-11-02 17:58:56 -0700414 configureTab(tab, mTabs.size());
415 if (setSelected) {
416 selectTab(tab);
417 }
418 }
419
420 @Override
421 public void addTab(Tab tab, int position, boolean setSelected) {
Adam Powellf8ac6b72011-05-23 18:14:09 -0700422 ensureTabsExist();
423 mTabScrollView.addTab(tab, position, setSelected);
Adam Powell661c9082010-07-02 10:09:44 -0700424 configureTab(tab, position);
Adam Powell81b89442010-11-02 17:58:56 -0700425 if (setSelected) {
426 selectTab(tab);
427 }
Adam Powell661c9082010-07-02 10:09:44 -0700428 }
429
430 @Override
431 public Tab newTab() {
432 return new TabImpl();
433 }
434
435 @Override
436 public void removeTab(Tab tab) {
437 removeTabAt(tab.getPosition());
438 }
439
440 @Override
441 public void removeTabAt(int position) {
Adam Powellf8ac6b72011-05-23 18:14:09 -0700442 if (mTabScrollView == null) {
443 // No tabs around to remove
444 return;
445 }
446
Adam Powell0c24a552010-11-03 16:44:11 -0700447 int selectedTabPosition = mSelectedTab != null
448 ? mSelectedTab.getPosition() : mSavedTabPosition;
Adam Powellf8ac6b72011-05-23 18:14:09 -0700449 mTabScrollView.removeTabAt(position);
Adam Powell0d8ec1d2011-05-03 14:49:13 -0700450 TabImpl removedTab = mTabs.remove(position);
451 if (removedTab != null) {
452 removedTab.setPosition(-1);
453 }
Adam Powell661c9082010-07-02 10:09:44 -0700454
455 final int newTabCount = mTabs.size();
456 for (int i = position; i < newTabCount; i++) {
457 mTabs.get(i).setPosition(i);
458 }
459
Adam Powell0c24a552010-11-03 16:44:11 -0700460 if (selectedTabPosition == position) {
461 selectTab(mTabs.isEmpty() ? null : mTabs.get(Math.max(0, position - 1)));
462 }
Adam Powell661c9082010-07-02 10:09:44 -0700463 }
464
465 @Override
Adam Powell661c9082010-07-02 10:09:44 -0700466 public void selectTab(Tab tab) {
Adam Powell0c24a552010-11-03 16:44:11 -0700467 if (getNavigationMode() != NAVIGATION_MODE_TABS) {
468 mSavedTabPosition = tab != null ? tab.getPosition() : INVALID_POSITION;
469 return;
470 }
471
Dianne Hackborn48e7b452011-01-17 12:28:35 -0800472 final FragmentTransaction trans = mActivity.getFragmentManager().beginTransaction()
Adam Powell0c24a552010-11-03 16:44:11 -0700473 .disallowAddToBackStack();
Adam Powell7f9b9052010-10-19 16:56:07 -0700474
475 if (mSelectedTab == tab) {
476 if (mSelectedTab != null) {
477 mSelectedTab.getCallback().onTabReselected(mSelectedTab, trans);
Adam Powellf8ac6b72011-05-23 18:14:09 -0700478 mTabScrollView.animateToTab(tab.getPosition());
Adam Powell7f9b9052010-10-19 16:56:07 -0700479 }
480 } else {
Adam Powellf8ac6b72011-05-23 18:14:09 -0700481 mTabScrollView.setTabSelected(tab != null ? tab.getPosition() : Tab.INVALID_POSITION);
Adam Powell7f9b9052010-10-19 16:56:07 -0700482 if (mSelectedTab != null) {
483 mSelectedTab.getCallback().onTabUnselected(mSelectedTab, trans);
484 }
485 mSelectedTab = (TabImpl) tab;
486 if (mSelectedTab != null) {
487 mSelectedTab.getCallback().onTabSelected(mSelectedTab, trans);
488 }
Adam Powell2b6230e2010-09-07 17:55:25 -0700489 }
490
491 if (!trans.isEmpty()) {
492 trans.commit();
493 }
494 }
495
496 @Override
497 public Tab getSelectedTab() {
498 return mSelectedTab;
Adam Powell661c9082010-07-02 10:09:44 -0700499 }
500
Adam Powell6b336f82010-08-10 20:13:01 -0700501 @Override
502 public int getHeight() {
Adam Powell58c5dc12011-07-14 21:08:10 -0700503 return mContainerView.getHeight();
Adam Powell6b336f82010-08-10 20:13:01 -0700504 }
505
506 @Override
507 public void show() {
Adam Powell07e1f982011-03-24 11:11:15 -0700508 show(true);
509 }
510
511 void show(boolean markHiddenBeforeMode) {
512 if (mCurrentShowAnim != null) {
513 mCurrentShowAnim.end();
Adam Powell45f1e082010-12-10 14:20:13 -0800514 }
Adam Powelld76cee22011-01-31 15:05:05 -0800515 if (mContainerView.getVisibility() == View.VISIBLE) {
Adam Powell07e1f982011-03-24 11:11:15 -0700516 if (markHiddenBeforeMode) mWasHiddenBeforeMode = false;
Adam Powelld76cee22011-01-31 15:05:05 -0800517 return;
518 }
Adam Powelld8b3f2e2010-12-02 13:37:03 -0800519 mContainerView.setVisibility(View.VISIBLE);
Adam Powell50efbed2011-02-08 16:20:15 -0800520
521 if (mShowHideAnimationEnabled) {
522 mContainerView.setAlpha(0);
523 AnimatorSet anim = new AnimatorSet();
524 AnimatorSet.Builder b = anim.play(ObjectAnimator.ofFloat(mContainerView, "alpha", 1));
525 if (mContentView != null) {
526 b.with(ObjectAnimator.ofFloat(mContentView, "translationY",
527 -mContainerView.getHeight(), 0));
528 mContainerView.setTranslationY(-mContainerView.getHeight());
529 b.with(ObjectAnimator.ofFloat(mContainerView, "translationY", 0));
530 }
Adam Powell1ab418a2011-06-09 20:49:49 -0700531 if (mSplitView != null && mContextDisplayMode == CONTEXT_DISPLAY_SPLIT) {
Adam Powell640a66e2011-04-29 10:18:53 -0700532 mSplitView.setAlpha(0);
533 b.with(ObjectAnimator.ofFloat(mSplitView, "alpha", 1));
534 }
Adam Powell50efbed2011-02-08 16:20:15 -0800535 anim.addListener(mShowListener);
Adam Powell07e1f982011-03-24 11:11:15 -0700536 mCurrentShowAnim = anim;
Adam Powell50efbed2011-02-08 16:20:15 -0800537 anim.start();
538 } else {
Adam Powelld8145042011-03-24 14:18:27 -0700539 mContainerView.setAlpha(1);
540 mContainerView.setTranslationY(0);
Adam Powell50efbed2011-02-08 16:20:15 -0800541 mShowListener.onAnimationEnd(null);
Adam Powelle6ec7322010-12-07 15:29:26 -0800542 }
Adam Powell6b336f82010-08-10 20:13:01 -0700543 }
544
545 @Override
546 public void hide() {
Adam Powell07e1f982011-03-24 11:11:15 -0700547 if (mCurrentShowAnim != null) {
548 mCurrentShowAnim.end();
Adam Powelle6ec7322010-12-07 15:29:26 -0800549 }
550 if (mContainerView.getVisibility() == View.GONE) {
551 return;
552 }
Adam Powell50efbed2011-02-08 16:20:15 -0800553
554 if (mShowHideAnimationEnabled) {
555 mContainerView.setAlpha(1);
Adam Powell01feaee2011-02-10 15:05:05 -0800556 mContainerView.setTransitioning(true);
Adam Powell50efbed2011-02-08 16:20:15 -0800557 AnimatorSet anim = new AnimatorSet();
558 AnimatorSet.Builder b = anim.play(ObjectAnimator.ofFloat(mContainerView, "alpha", 0));
559 if (mContentView != null) {
560 b.with(ObjectAnimator.ofFloat(mContentView, "translationY",
561 0, -mContainerView.getHeight()));
562 b.with(ObjectAnimator.ofFloat(mContainerView, "translationY",
563 -mContainerView.getHeight()));
564 }
Adam Powell1ab418a2011-06-09 20:49:49 -0700565 if (mSplitView != null && mSplitView.getVisibility() == View.VISIBLE) {
Adam Powell640a66e2011-04-29 10:18:53 -0700566 mSplitView.setAlpha(1);
567 b.with(ObjectAnimator.ofFloat(mSplitView, "alpha", 0));
568 }
Adam Powell50efbed2011-02-08 16:20:15 -0800569 anim.addListener(mHideListener);
Adam Powell07e1f982011-03-24 11:11:15 -0700570 mCurrentShowAnim = anim;
Adam Powell50efbed2011-02-08 16:20:15 -0800571 anim.start();
572 } else {
573 mHideListener.onAnimationEnd(null);
Adam Powelle6ec7322010-12-07 15:29:26 -0800574 }
Adam Powell6b336f82010-08-10 20:13:01 -0700575 }
576
577 public boolean isShowing() {
Adam Powelld8b3f2e2010-12-02 13:37:03 -0800578 return mContainerView.getVisibility() == View.VISIBLE;
579 }
580
Adam Powell640a66e2011-04-29 10:18:53 -0700581 void animateToMode(boolean toActionMode) {
Adam Powell07e1f982011-03-24 11:11:15 -0700582 show(false);
583 if (mCurrentModeAnim != null) {
584 mCurrentModeAnim.end();
585 }
Adam Powelld8b3f2e2010-12-02 13:37:03 -0800586
Adam Powell640a66e2011-04-29 10:18:53 -0700587 mActionView.animateToVisibility(toActionMode ? View.GONE : View.VISIBLE);
588 mContextView.animateToVisibility(toActionMode ? View.VISIBLE : View.GONE);
Adam Powellf6ce6a92011-06-29 10:25:01 -0700589 if (mTabScrollView != null && !mActionView.hasEmbeddedTabs() && mActionView.isCollapsed()) {
590 mTabScrollView.animateToVisibility(toActionMode ? View.GONE : View.VISIBLE);
591 }
Adam Powell6b336f82010-08-10 20:13:01 -0700592 }
593
Adam Powell89e06452010-06-23 20:24:52 -0700594 /**
595 * @hide
596 */
Adam Powell5d279772010-07-27 16:34:07 -0700597 public class ActionModeImpl extends ActionMode implements MenuBuilder.Callback {
Adam Powell6e346362010-07-23 10:18:23 -0700598 private ActionMode.Callback mCallback;
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700599 private MenuBuilder mMenu;
Adam Powell29ed7572010-07-14 16:24:56 -0700600 private WeakReference<View> mCustomView;
Adam Powell89e06452010-06-23 20:24:52 -0700601
Adam Powell5d279772010-07-27 16:34:07 -0700602 public ActionModeImpl(ActionMode.Callback callback) {
Adam Powell89e06452010-06-23 20:24:52 -0700603 mCallback = callback;
Adam Powell4d9861e2010-08-17 11:14:40 -0700604 mMenu = new MenuBuilder(mActionView.getContext())
605 .setDefaultShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700606 mMenu.setCallback(this);
Adam Powell89e06452010-06-23 20:24:52 -0700607 }
Adam Powell9168f0b2010-08-02 15:46:24 -0700608
609 @Override
610 public MenuInflater getMenuInflater() {
Adam Powell4d9861e2010-08-17 11:14:40 -0700611 return new MenuInflater(mContext);
Adam Powell9168f0b2010-08-02 15:46:24 -0700612 }
613
Adam Powell89e06452010-06-23 20:24:52 -0700614 @Override
615 public Menu getMenu() {
616 return mMenu;
617 }
618
619 @Override
620 public void finish() {
Adam Powell5d279772010-07-27 16:34:07 -0700621 if (mActionMode != this) {
622 // Not the active action mode - no-op
Adam Powell93b6bc32010-07-22 11:36:35 -0700623 return;
624 }
625
Adam Powell6e346362010-07-23 10:18:23 -0700626 mCallback.onDestroyActionMode(this);
Adam Powelld8b3f2e2010-12-02 13:37:03 -0800627 mCallback = null;
Adam Powell640a66e2011-04-29 10:18:53 -0700628 animateToMode(false);
Adam Powell0e94b512010-06-29 17:58:20 -0700629
630 // Clear out the context mode views after the animation finishes
Adam Powell640a66e2011-04-29 10:18:53 -0700631 mContextView.closeMode();
Adam Powellf6ce6a92011-06-29 10:25:01 -0700632
Adam Powell5d279772010-07-27 16:34:07 -0700633 mActionMode = null;
Adam Powell07e1f982011-03-24 11:11:15 -0700634
635 if (mWasHiddenBeforeMode) {
636 hide();
637 }
Adam Powell89e06452010-06-23 20:24:52 -0700638 }
639
640 @Override
641 public void invalidate() {
Adam Powell5ee36c42011-06-02 12:59:43 -0700642 mMenu.stopDispatchingItemsChanged();
643 try {
644 mCallback.onPrepareActionMode(this, mMenu);
645 } finally {
646 mMenu.startDispatchingItemsChanged();
647 }
648 }
649
650 public boolean dispatchOnCreate() {
651 mMenu.stopDispatchingItemsChanged();
652 try {
653 return mCallback.onCreateActionMode(this, mMenu);
654 } finally {
655 mMenu.startDispatchingItemsChanged();
Adam Powell89e06452010-06-23 20:24:52 -0700656 }
657 }
658
659 @Override
660 public void setCustomView(View view) {
Adam Powell640a66e2011-04-29 10:18:53 -0700661 mContextView.setCustomView(view);
Adam Powell29ed7572010-07-14 16:24:56 -0700662 mCustomView = new WeakReference<View>(view);
Adam Powell89e06452010-06-23 20:24:52 -0700663 }
664
665 @Override
666 public void setSubtitle(CharSequence subtitle) {
Adam Powell640a66e2011-04-29 10:18:53 -0700667 mContextView.setSubtitle(subtitle);
Adam Powell89e06452010-06-23 20:24:52 -0700668 }
669
670 @Override
671 public void setTitle(CharSequence title) {
Adam Powell640a66e2011-04-29 10:18:53 -0700672 mContextView.setTitle(title);
Adam Powell89e06452010-06-23 20:24:52 -0700673 }
Adam Powell29ed7572010-07-14 16:24:56 -0700674
675 @Override
Adam Powellc9ae2a22010-07-28 14:44:21 -0700676 public void setTitle(int resId) {
Adam Powell48e8ac32011-01-14 12:10:24 -0800677 setTitle(mContext.getResources().getString(resId));
Adam Powellc9ae2a22010-07-28 14:44:21 -0700678 }
679
680 @Override
681 public void setSubtitle(int resId) {
Adam Powell48e8ac32011-01-14 12:10:24 -0800682 setSubtitle(mContext.getResources().getString(resId));
Adam Powellc9ae2a22010-07-28 14:44:21 -0700683 }
684
685 @Override
Adam Powell29ed7572010-07-14 16:24:56 -0700686 public CharSequence getTitle() {
Adam Powell640a66e2011-04-29 10:18:53 -0700687 return mContextView.getTitle();
Adam Powell29ed7572010-07-14 16:24:56 -0700688 }
689
690 @Override
691 public CharSequence getSubtitle() {
Adam Powell640a66e2011-04-29 10:18:53 -0700692 return mContextView.getSubtitle();
Adam Powell29ed7572010-07-14 16:24:56 -0700693 }
Adam Powell89e06452010-06-23 20:24:52 -0700694
Adam Powell29ed7572010-07-14 16:24:56 -0700695 @Override
696 public View getCustomView() {
697 return mCustomView != null ? mCustomView.get() : null;
698 }
699
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700700 public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
Adam Powelld8b3f2e2010-12-02 13:37:03 -0800701 if (mCallback != null) {
702 return mCallback.onActionItemClicked(this, item);
703 } else {
704 return false;
705 }
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700706 }
707
708 public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) {
709 }
710
711 public boolean onSubMenuSelected(SubMenuBuilder subMenu) {
Adam Powelld8b3f2e2010-12-02 13:37:03 -0800712 if (mCallback == null) {
713 return false;
714 }
715
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700716 if (!subMenu.hasVisibleItems()) {
717 return true;
Adam Powell89e06452010-06-23 20:24:52 -0700718 }
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700719
Adam Powelldec9dfd2010-08-09 15:27:54 -0700720 new MenuPopupHelper(mContext, subMenu).show();
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700721 return true;
722 }
723
724 public void onCloseSubMenu(SubMenuBuilder menu) {
725 }
726
727 public void onMenuModeChange(MenuBuilder menu) {
Adam Powelld8b3f2e2010-12-02 13:37:03 -0800728 if (mCallback == null) {
729 return;
730 }
Adam Powellf6148c52010-08-11 21:10:16 -0700731 invalidate();
Adam Powell640a66e2011-04-29 10:18:53 -0700732 mContextView.showOverflowMenu();
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700733 }
Adam Powell661c9082010-07-02 10:09:44 -0700734 }
735
736 /**
737 * @hide
738 */
739 public class TabImpl extends ActionBar.Tab {
Adam Powell2b6230e2010-09-07 17:55:25 -0700740 private ActionBar.TabListener mCallback;
741 private Object mTag;
Adam Powell661c9082010-07-02 10:09:44 -0700742 private Drawable mIcon;
743 private CharSequence mText;
Adam Powell0d8ec1d2011-05-03 14:49:13 -0700744 private int mPosition = -1;
Adam Powell2b6230e2010-09-07 17:55:25 -0700745 private View mCustomView;
Adam Powell661c9082010-07-02 10:09:44 -0700746
747 @Override
Adam Powell2b6230e2010-09-07 17:55:25 -0700748 public Object getTag() {
749 return mTag;
750 }
751
752 @Override
Adam Powell9ab97872010-10-26 21:47:29 -0700753 public Tab setTag(Object tag) {
Adam Powell2b6230e2010-09-07 17:55:25 -0700754 mTag = tag;
Adam Powell9ab97872010-10-26 21:47:29 -0700755 return this;
Adam Powell2b6230e2010-09-07 17:55:25 -0700756 }
757
758 public ActionBar.TabListener getCallback() {
759 return mCallback;
760 }
761
762 @Override
Adam Powell9ab97872010-10-26 21:47:29 -0700763 public Tab setTabListener(ActionBar.TabListener callback) {
Adam Powell2b6230e2010-09-07 17:55:25 -0700764 mCallback = callback;
Adam Powell9ab97872010-10-26 21:47:29 -0700765 return this;
Adam Powell2b6230e2010-09-07 17:55:25 -0700766 }
767
768 @Override
769 public View getCustomView() {
770 return mCustomView;
771 }
772
773 @Override
Adam Powell9ab97872010-10-26 21:47:29 -0700774 public Tab setCustomView(View view) {
Adam Powell2b6230e2010-09-07 17:55:25 -0700775 mCustomView = view;
Adam Powellf8ac6b72011-05-23 18:14:09 -0700776 if (mPosition >= 0) {
777 mTabScrollView.updateTab(mPosition);
778 }
Adam Powell9ab97872010-10-26 21:47:29 -0700779 return this;
Adam Powell661c9082010-07-02 10:09:44 -0700780 }
781
782 @Override
Adam Powell32555f32010-11-17 13:49:22 -0800783 public Tab setCustomView(int layoutResId) {
784 return setCustomView(LayoutInflater.from(mContext).inflate(layoutResId, null));
785 }
786
787 @Override
Adam Powell661c9082010-07-02 10:09:44 -0700788 public Drawable getIcon() {
789 return mIcon;
790 }
791
792 @Override
793 public int getPosition() {
794 return mPosition;
795 }
796
797 public void setPosition(int position) {
798 mPosition = position;
799 }
800
801 @Override
802 public CharSequence getText() {
803 return mText;
804 }
805
806 @Override
Adam Powell9ab97872010-10-26 21:47:29 -0700807 public Tab setIcon(Drawable icon) {
Adam Powell661c9082010-07-02 10:09:44 -0700808 mIcon = icon;
Adam Powellf8ac6b72011-05-23 18:14:09 -0700809 if (mPosition >= 0) {
810 mTabScrollView.updateTab(mPosition);
811 }
Adam Powell9ab97872010-10-26 21:47:29 -0700812 return this;
Adam Powell661c9082010-07-02 10:09:44 -0700813 }
814
815 @Override
Adam Powell32555f32010-11-17 13:49:22 -0800816 public Tab setIcon(int resId) {
817 return setIcon(mContext.getResources().getDrawable(resId));
818 }
819
820 @Override
Adam Powell9ab97872010-10-26 21:47:29 -0700821 public Tab setText(CharSequence text) {
Adam Powell661c9082010-07-02 10:09:44 -0700822 mText = text;
Adam Powellf8ac6b72011-05-23 18:14:09 -0700823 if (mPosition >= 0) {
824 mTabScrollView.updateTab(mPosition);
825 }
Adam Powell9ab97872010-10-26 21:47:29 -0700826 return this;
Adam Powell661c9082010-07-02 10:09:44 -0700827 }
828
829 @Override
Adam Powell32555f32010-11-17 13:49:22 -0800830 public Tab setText(int resId) {
831 return setText(mContext.getResources().getText(resId));
832 }
833
834 @Override
Adam Powell661c9082010-07-02 10:09:44 -0700835 public void select() {
836 selectTab(this);
Adam Powell89e06452010-06-23 20:24:52 -0700837 }
838 }
Adam Powell9ab97872010-10-26 21:47:29 -0700839
840 @Override
841 public void setCustomView(View view) {
842 mActionView.setCustomNavigationView(view);
843 }
844
845 @Override
846 public void setCustomView(View view, LayoutParams layoutParams) {
847 view.setLayoutParams(layoutParams);
848 mActionView.setCustomNavigationView(view);
849 }
850
851 @Override
Adam Powell8515ee82010-11-30 14:09:55 -0800852 public void setListNavigationCallbacks(SpinnerAdapter adapter, OnNavigationListener callback) {
Adam Powell9ab97872010-10-26 21:47:29 -0700853 mActionView.setDropdownAdapter(adapter);
854 mActionView.setCallback(callback);
855 }
856
857 @Override
858 public int getSelectedNavigationIndex() {
859 switch (mActionView.getNavigationMode()) {
860 case NAVIGATION_MODE_TABS:
Adam Powell04587962010-11-11 22:15:07 -0800861 return mSelectedTab != null ? mSelectedTab.getPosition() : -1;
Adam Powell9ab97872010-10-26 21:47:29 -0700862 case NAVIGATION_MODE_LIST:
863 return mActionView.getDropdownSelectedPosition();
864 default:
865 return -1;
866 }
867 }
868
869 @Override
870 public int getNavigationItemCount() {
871 switch (mActionView.getNavigationMode()) {
872 case NAVIGATION_MODE_TABS:
873 return mTabs.size();
874 case NAVIGATION_MODE_LIST:
875 SpinnerAdapter adapter = mActionView.getDropdownAdapter();
876 return adapter != null ? adapter.getCount() : 0;
877 default:
878 return 0;
879 }
880 }
881
882 @Override
Adam Powell0c24a552010-11-03 16:44:11 -0700883 public int getTabCount() {
884 return mTabs.size();
885 }
886
887 @Override
Adam Powell9ab97872010-10-26 21:47:29 -0700888 public void setNavigationMode(int mode) {
Adam Powell0c24a552010-11-03 16:44:11 -0700889 final int oldMode = mActionView.getNavigationMode();
890 switch (oldMode) {
891 case NAVIGATION_MODE_TABS:
892 mSavedTabPosition = getSelectedNavigationIndex();
893 selectTab(null);
Adam Powelldae78242011-04-25 15:23:41 -0700894 if (!mActionView.hasEmbeddedTabs()) {
Adam Powellf8ac6b72011-05-23 18:14:09 -0700895 mTabScrollView.setVisibility(View.GONE);
Adam Powelldae78242011-04-25 15:23:41 -0700896 }
Adam Powell0c24a552010-11-03 16:44:11 -0700897 break;
898 }
Adam Powell9ab97872010-10-26 21:47:29 -0700899 mActionView.setNavigationMode(mode);
Adam Powell0c24a552010-11-03 16:44:11 -0700900 switch (mode) {
901 case NAVIGATION_MODE_TABS:
Adam Powellf8ac6b72011-05-23 18:14:09 -0700902 ensureTabsExist();
Adam Powelldae78242011-04-25 15:23:41 -0700903 if (!mActionView.hasEmbeddedTabs()) {
Adam Powellf8ac6b72011-05-23 18:14:09 -0700904 mTabScrollView.setVisibility(View.VISIBLE);
Adam Powelldae78242011-04-25 15:23:41 -0700905 }
Adam Powell0c24a552010-11-03 16:44:11 -0700906 if (mSavedTabPosition != INVALID_POSITION) {
907 setSelectedNavigationItem(mSavedTabPosition);
908 mSavedTabPosition = INVALID_POSITION;
909 }
910 break;
911 }
Adam Powelld21aa122011-05-27 13:09:52 -0700912 mActionView.setCollapsable(mode == NAVIGATION_MODE_TABS && !mHasEmbeddedTabs);
Adam Powell9ab97872010-10-26 21:47:29 -0700913 }
914
915 @Override
916 public Tab getTabAt(int index) {
917 return mTabs.get(index);
918 }
Adam Powell0c24a552010-11-03 16:44:11 -0700919
Adam Powell0c24a552010-11-03 16:44:11 -0700920
Adam Powell1969b872011-03-22 11:52:48 -0700921 @Override
922 public void setIcon(int resId) {
Adam Powell45c515b2011-04-21 18:50:20 -0700923 mActionView.setIcon(resId);
Adam Powell1969b872011-03-22 11:52:48 -0700924 }
Adam Powell0c24a552010-11-03 16:44:11 -0700925
Adam Powell1969b872011-03-22 11:52:48 -0700926 @Override
927 public void setIcon(Drawable icon) {
928 mActionView.setIcon(icon);
929 }
930
931 @Override
932 public void setLogo(int resId) {
Adam Powell45c515b2011-04-21 18:50:20 -0700933 mActionView.setLogo(resId);
Adam Powell1969b872011-03-22 11:52:48 -0700934 }
935
936 @Override
937 public void setLogo(Drawable logo) {
938 mActionView.setLogo(logo);
Adam Powell0c24a552010-11-03 16:44:11 -0700939 }
Adam Powell89e06452010-06-23 20:24:52 -0700940}