blob: f4a041cf2e886ac3d6569540b967b03f32447dd8 [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 Powell89e06452010-06-23 20:24:52 -070022import com.android.internal.widget.ActionBarContextView;
23import com.android.internal.widget.ActionBarView;
24
25import android.app.ActionBar;
Adam Powell661c9082010-07-02 10:09:44 -070026import android.app.Activity;
Adam Powelldec9dfd2010-08-09 15:27:54 -070027import android.app.Dialog;
Adam Powell661c9082010-07-02 10:09:44 -070028import android.app.Fragment;
29import android.app.FragmentTransaction;
Adam Powelldec9dfd2010-08-09 15:27:54 -070030import android.content.Context;
Adam Powell89e06452010-06-23 20:24:52 -070031import android.graphics.drawable.Drawable;
Adam Powell0e94b512010-06-29 17:58:20 -070032import android.os.Handler;
Adam Powell6e346362010-07-23 10:18:23 -070033import android.view.ActionMode;
Adam Powell89e06452010-06-23 20:24:52 -070034import android.view.Menu;
Adam Powell9168f0b2010-08-02 15:46:24 -070035import android.view.MenuInflater;
Adam Powell89e06452010-06-23 20:24:52 -070036import android.view.MenuItem;
37import android.view.View;
38import android.widget.LinearLayout;
39import android.widget.SpinnerAdapter;
40import android.widget.ViewAnimator;
41
Adam Powell29ed7572010-07-14 16:24:56 -070042import java.lang.ref.WeakReference;
Adam Powell661c9082010-07-02 10:09:44 -070043import java.util.ArrayList;
44
Adam Powell89e06452010-06-23 20:24:52 -070045/**
46 * ActionBarImpl is the ActionBar implementation used
47 * by devices of all screen sizes. If it detects a compatible decor,
48 * it will split contextual modes across both the ActionBarView at
49 * the top of the screen and a horizontal LinearLayout at the bottom
50 * which is normally hidden.
51 */
52public class ActionBarImpl extends ActionBar {
53 private static final int NORMAL_VIEW = 0;
54 private static final int CONTEXT_VIEW = 1;
Adam Powell661c9082010-07-02 10:09:44 -070055
Adam Powelldec9dfd2010-08-09 15:27:54 -070056 private Context mContext;
Adam Powell661c9082010-07-02 10:09:44 -070057 private Activity mActivity;
Adam Powelldec9dfd2010-08-09 15:27:54 -070058 private Dialog mDialog;
Adam Powell661c9082010-07-02 10:09:44 -070059
Adam Powell89e06452010-06-23 20:24:52 -070060 private ViewAnimator mAnimatorView;
61 private ActionBarView mActionView;
62 private ActionBarContextView mUpperContextView;
63 private LinearLayout mLowerContextView;
Adam Powell661c9082010-07-02 10:09:44 -070064
65 private ArrayList<TabImpl> mTabs = new ArrayList<TabImpl>();
66
Adam Powell661c9082010-07-02 10:09:44 -070067 private TabImpl mSelectedTab;
Adam Powell89e06452010-06-23 20:24:52 -070068
Adam Powell5d279772010-07-27 16:34:07 -070069 private ActionMode mActionMode;
Adam Powell89e06452010-06-23 20:24:52 -070070
71 private static final int CONTEXT_DISPLAY_NORMAL = 0;
72 private static final int CONTEXT_DISPLAY_SPLIT = 1;
73
74 private int mContextDisplayMode;
Adam Powell0e94b512010-06-29 17:58:20 -070075
Adam Powell3461b322010-07-14 11:34:43 -070076 private boolean mClosingContext;
77
Adam Powell0e94b512010-06-29 17:58:20 -070078 final Handler mHandler = new Handler();
79 final Runnable mCloseContext = new Runnable() {
80 public void run() {
81 mUpperContextView.closeMode();
82 if (mLowerContextView != null) {
83 mLowerContextView.removeAllViews();
84 }
Adam Powell3461b322010-07-14 11:34:43 -070085 mClosingContext = false;
Adam Powell0e94b512010-06-29 17:58:20 -070086 }
87 };
88
Adam Powell661c9082010-07-02 10:09:44 -070089 public ActionBarImpl(Activity activity) {
Adam Powell661c9082010-07-02 10:09:44 -070090 mActivity = activity;
Adam Powelldec9dfd2010-08-09 15:27:54 -070091 init(activity.getWindow().getDecorView());
92 }
93
94 public ActionBarImpl(Dialog dialog) {
95 mDialog = dialog;
96 init(dialog.getWindow().getDecorView());
97 }
98
99 private void init(View decor) {
100 mContext = decor.getContext();
Adam Powell89e06452010-06-23 20:24:52 -0700101 mActionView = (ActionBarView) decor.findViewById(com.android.internal.R.id.action_bar);
102 mUpperContextView = (ActionBarContextView) decor.findViewById(
103 com.android.internal.R.id.action_context_bar);
104 mLowerContextView = (LinearLayout) decor.findViewById(
105 com.android.internal.R.id.lower_action_context_bar);
106 mAnimatorView = (ViewAnimator) decor.findViewById(
107 com.android.internal.R.id.action_bar_animator);
Steve Block08f194b2010-08-24 18:20:48 +0100108
Adam Powell89e06452010-06-23 20:24:52 -0700109 if (mActionView == null || mUpperContextView == null || mAnimatorView == null) {
110 throw new IllegalStateException(getClass().getSimpleName() + " can only be used " +
111 "with a compatible window decor layout");
112 }
Adam Powell0e94b512010-06-29 17:58:20 -0700113
Steve Block08f194b2010-08-24 18:20:48 +0100114 mActionView.setContextView(mUpperContextView);
Adam Powell89e06452010-06-23 20:24:52 -0700115 mContextDisplayMode = mLowerContextView == null ?
116 CONTEXT_DISPLAY_NORMAL : CONTEXT_DISPLAY_SPLIT;
117 }
118
Adam Powella66c7b02010-07-28 15:28:25 -0700119 @Override
Adam Powella66c7b02010-07-28 15:28:25 -0700120 public void setTitle(int resId) {
Adam Powelldec9dfd2010-08-09 15:27:54 -0700121 setTitle(mContext.getString(resId));
Adam Powella66c7b02010-07-28 15:28:25 -0700122 }
123
124 @Override
125 public void setSubtitle(int resId) {
Adam Powelldec9dfd2010-08-09 15:27:54 -0700126 setSubtitle(mContext.getString(resId));
Adam Powella66c7b02010-07-28 15:28:25 -0700127 }
128
Adam Powell89e06452010-06-23 20:24:52 -0700129 public void setCustomNavigationMode(View view) {
Adam Powell661c9082010-07-02 10:09:44 -0700130 cleanupTabs();
Adam Powell9ab97872010-10-26 21:47:29 -0700131 setCustomView(view);
132 setDisplayOptions(DISPLAY_SHOW_CUSTOM, DISPLAY_SHOW_CUSTOM | DISPLAY_SHOW_TITLE);
133 mActionView.setNavigationMode(NAVIGATION_MODE_STANDARD);
Adam Powell89e06452010-06-23 20:24:52 -0700134 mActionView.setCallback(null);
135 }
Adam Powell0e94b512010-06-29 17:58:20 -0700136
Adam Powell89e06452010-06-23 20:24:52 -0700137 public void setDropdownNavigationMode(SpinnerAdapter adapter, NavigationCallback callback) {
Adam Powell17809772010-07-21 13:25:11 -0700138 setDropdownNavigationMode(adapter, callback, -1);
139 }
140
141 public void setDropdownNavigationMode(SpinnerAdapter adapter, NavigationCallback callback,
142 int defaultSelectedPosition) {
Adam Powell661c9082010-07-02 10:09:44 -0700143 cleanupTabs();
Adam Powell9ab97872010-10-26 21:47:29 -0700144 setDisplayOptions(0, DISPLAY_SHOW_CUSTOM | DISPLAY_SHOW_TITLE);
145 mActionView.setNavigationMode(NAVIGATION_MODE_LIST);
146 setListNavigationCallbacks(adapter, callback);
Adam Powell17809772010-07-21 13:25:11 -0700147 if (defaultSelectedPosition >= 0) {
148 mActionView.setDropdownSelectedPosition(defaultSelectedPosition);
149 }
Adam Powell89e06452010-06-23 20:24:52 -0700150 }
Adam Powell0e94b512010-06-29 17:58:20 -0700151
152 public void setStandardNavigationMode() {
Adam Powell661c9082010-07-02 10:09:44 -0700153 cleanupTabs();
Adam Powell9ab97872010-10-26 21:47:29 -0700154 setDisplayOptions(DISPLAY_SHOW_TITLE, DISPLAY_SHOW_TITLE | DISPLAY_SHOW_CUSTOM);
Adam Powell0e94b512010-06-29 17:58:20 -0700155 mActionView.setNavigationMode(NAVIGATION_MODE_STANDARD);
156 mActionView.setCallback(null);
157 }
158
Adam Powell17809772010-07-21 13:25:11 -0700159 public void setSelectedNavigationItem(int position) {
160 switch (mActionView.getNavigationMode()) {
161 case NAVIGATION_MODE_TABS:
162 selectTab(mTabs.get(position));
163 break;
Adam Powell9ab97872010-10-26 21:47:29 -0700164 case NAVIGATION_MODE_LIST:
Adam Powell17809772010-07-21 13:25:11 -0700165 mActionView.setDropdownSelectedPosition(position);
166 break;
167 default:
168 throw new IllegalStateException(
Adam Powell9ab97872010-10-26 21:47:29 -0700169 "setSelectedNavigationIndex not valid for current navigation mode");
Adam Powell17809772010-07-21 13:25:11 -0700170 }
171 }
172
173 public int getSelectedNavigationItem() {
Adam Powell9ab97872010-10-26 21:47:29 -0700174 return getSelectedNavigationIndex();
175 }
176
177 public void removeAllTabs() {
178 cleanupTabs();
Adam Powell17809772010-07-21 13:25:11 -0700179 }
180
Adam Powell661c9082010-07-02 10:09:44 -0700181 private void cleanupTabs() {
182 if (mSelectedTab != null) {
183 selectTab(null);
184 }
Adam Powell2b6230e2010-09-07 17:55:25 -0700185 mTabs.clear();
Adam Powell661c9082010-07-02 10:09:44 -0700186 }
187
Adam Powell0e94b512010-06-29 17:58:20 -0700188 public void setTitle(CharSequence title) {
189 mActionView.setTitle(title);
190 }
191
192 public void setSubtitle(CharSequence subtitle) {
193 mActionView.setSubtitle(subtitle);
194 }
195
Adam Powell89e06452010-06-23 20:24:52 -0700196 public void setDisplayOptions(int options) {
197 mActionView.setDisplayOptions(options);
198 }
Adam Powell0e94b512010-06-29 17:58:20 -0700199
Adam Powell89e06452010-06-23 20:24:52 -0700200 public void setDisplayOptions(int options, int mask) {
201 final int current = mActionView.getDisplayOptions();
202 mActionView.setDisplayOptions((options & mask) | (current & ~mask));
203 }
204
205 public void setBackgroundDrawable(Drawable d) {
206 mActionView.setBackgroundDrawable(d);
207 }
208
209 public View getCustomNavigationView() {
210 return mActionView.getCustomNavigationView();
211 }
212
213 public CharSequence getTitle() {
214 return mActionView.getTitle();
215 }
216
217 public CharSequence getSubtitle() {
218 return mActionView.getSubtitle();
219 }
220
221 public int getNavigationMode() {
222 return mActionView.getNavigationMode();
223 }
224
225 public int getDisplayOptions() {
226 return mActionView.getDisplayOptions();
227 }
228
Adam Powell5d279772010-07-27 16:34:07 -0700229 public ActionMode startActionMode(ActionMode.Callback callback) {
230 if (mActionMode != null) {
231 mActionMode.finish();
Adam Powell6e346362010-07-23 10:18:23 -0700232 }
Adam Powell3461b322010-07-14 11:34:43 -0700233
234 // Don't wait for the close context mode animation to finish.
235 if (mClosingContext) {
236 mAnimatorView.clearAnimation();
237 mHandler.removeCallbacks(mCloseContext);
238 mCloseContext.run();
239 }
240
Adam Powell5d279772010-07-27 16:34:07 -0700241 ActionMode mode = new ActionModeImpl(callback);
Adam Powell6e346362010-07-23 10:18:23 -0700242 if (callback.onCreateActionMode(mode, mode.getMenu())) {
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700243 mode.invalidate();
244 mUpperContextView.initForMode(mode);
Adam Powell89e06452010-06-23 20:24:52 -0700245 mAnimatorView.setDisplayedChild(CONTEXT_VIEW);
246 if (mLowerContextView != null) {
247 // TODO animate this
248 mLowerContextView.setVisibility(View.VISIBLE);
249 }
Adam Powell5d279772010-07-27 16:34:07 -0700250 mActionMode = mode;
Adam Powellac695c62010-07-20 18:19:27 -0700251 return mode;
Adam Powell89e06452010-06-23 20:24:52 -0700252 }
Adam Powellac695c62010-07-20 18:19:27 -0700253 return null;
Adam Powell89e06452010-06-23 20:24:52 -0700254 }
255
Adam Powell661c9082010-07-02 10:09:44 -0700256 private void configureTab(Tab tab, int position) {
257 final TabImpl tabi = (TabImpl) tab;
258 final boolean isFirstTab = mTabs.isEmpty();
Adam Powell2b6230e2010-09-07 17:55:25 -0700259 final ActionBar.TabListener callback = tabi.getCallback();
260
261 if (callback == null) {
262 throw new IllegalStateException("Action Bar Tab must have a Callback");
263 }
Adam Powell661c9082010-07-02 10:09:44 -0700264
265 tabi.setPosition(position);
266 mTabs.add(position, tabi);
267
Adam Powell661c9082010-07-02 10:09:44 -0700268 if (isFirstTab) {
Adam Powell2b6230e2010-09-07 17:55:25 -0700269 final FragmentTransaction trans = mActivity.getFragmentManager().openTransaction();
Adam Powell661c9082010-07-02 10:09:44 -0700270 mSelectedTab = tabi;
Adam Powell2b6230e2010-09-07 17:55:25 -0700271 callback.onTabSelected(tab, trans);
272 if (!trans.isEmpty()) {
273 trans.commit();
Adam Powell661c9082010-07-02 10:09:44 -0700274 }
275 }
Adam Powell661c9082010-07-02 10:09:44 -0700276 }
277
278 @Override
279 public void addTab(Tab tab) {
280 mActionView.addTab(tab);
281 configureTab(tab, mTabs.size());
282 }
283
284 @Override
Adam Powell2b6230e2010-09-07 17:55:25 -0700285 public void addTab(Tab tab, int position) {
286 mActionView.addTab(tab, position);
Adam Powell661c9082010-07-02 10:09:44 -0700287 configureTab(tab, position);
288 }
289
290 @Override
291 public Tab newTab() {
292 return new TabImpl();
293 }
294
295 @Override
296 public void removeTab(Tab tab) {
297 removeTabAt(tab.getPosition());
298 }
299
300 @Override
301 public void removeTabAt(int position) {
302 mActionView.removeTabAt(position);
303 mTabs.remove(position);
304
305 final int newTabCount = mTabs.size();
306 for (int i = position; i < newTabCount; i++) {
307 mTabs.get(i).setPosition(i);
308 }
309
310 selectTab(mTabs.isEmpty() ? null : mTabs.get(Math.max(0, position - 1)));
311 }
312
313 @Override
314 public void setTabNavigationMode() {
Adam Powelldec9dfd2010-08-09 15:27:54 -0700315 if (mActivity == null) {
316 throw new IllegalStateException(
317 "Tab navigation mode cannot be used outside of an Activity");
318 }
Adam Powell9ab97872010-10-26 21:47:29 -0700319 setDisplayOptions(0, DISPLAY_SHOW_TITLE | DISPLAY_SHOW_CUSTOM);
Adam Powell661c9082010-07-02 10:09:44 -0700320 mActionView.setNavigationMode(NAVIGATION_MODE_TABS);
321 }
322
323 @Override
Adam Powell661c9082010-07-02 10:09:44 -0700324 public void selectTab(Tab tab) {
Adam Powell2b6230e2010-09-07 17:55:25 -0700325 final FragmentTransaction trans = mActivity.getFragmentManager().openTransaction();
Adam Powell7f9b9052010-10-19 16:56:07 -0700326
327 if (mSelectedTab == tab) {
328 if (mSelectedTab != null) {
329 mSelectedTab.getCallback().onTabReselected(mSelectedTab, trans);
330 }
331 } else {
332 mActionView.setTabSelected(tab != null ? tab.getPosition() : Tab.INVALID_POSITION);
333 if (mSelectedTab != null) {
334 mSelectedTab.getCallback().onTabUnselected(mSelectedTab, trans);
335 }
336 mSelectedTab = (TabImpl) tab;
337 if (mSelectedTab != null) {
338 mSelectedTab.getCallback().onTabSelected(mSelectedTab, trans);
339 }
Adam Powell2b6230e2010-09-07 17:55:25 -0700340 }
341
342 if (!trans.isEmpty()) {
343 trans.commit();
344 }
345 }
346
347 @Override
348 public Tab getSelectedTab() {
349 return mSelectedTab;
Adam Powell661c9082010-07-02 10:09:44 -0700350 }
351
Adam Powell6b336f82010-08-10 20:13:01 -0700352 @Override
353 public int getHeight() {
354 return mActionView.getHeight();
355 }
356
357 @Override
358 public void show() {
359 // TODO animate!
360 mAnimatorView.setVisibility(View.VISIBLE);
361 }
362
363 @Override
364 public void hide() {
365 // TODO animate!
366 mAnimatorView.setVisibility(View.GONE);
367 }
368
369 public boolean isShowing() {
370 return mAnimatorView.getVisibility() == View.VISIBLE;
371 }
372
Adam Powell89e06452010-06-23 20:24:52 -0700373 /**
374 * @hide
375 */
Adam Powell5d279772010-07-27 16:34:07 -0700376 public class ActionModeImpl extends ActionMode implements MenuBuilder.Callback {
Adam Powell6e346362010-07-23 10:18:23 -0700377 private ActionMode.Callback mCallback;
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700378 private MenuBuilder mMenu;
Adam Powell29ed7572010-07-14 16:24:56 -0700379 private WeakReference<View> mCustomView;
Adam Powell89e06452010-06-23 20:24:52 -0700380
Adam Powell5d279772010-07-27 16:34:07 -0700381 public ActionModeImpl(ActionMode.Callback callback) {
Adam Powell89e06452010-06-23 20:24:52 -0700382 mCallback = callback;
Adam Powell4d9861e2010-08-17 11:14:40 -0700383 mMenu = new MenuBuilder(mActionView.getContext())
384 .setDefaultShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700385 mMenu.setCallback(this);
Adam Powell89e06452010-06-23 20:24:52 -0700386 }
Adam Powell9168f0b2010-08-02 15:46:24 -0700387
388 @Override
389 public MenuInflater getMenuInflater() {
Adam Powell4d9861e2010-08-17 11:14:40 -0700390 return new MenuInflater(mContext);
Adam Powell9168f0b2010-08-02 15:46:24 -0700391 }
392
Adam Powell89e06452010-06-23 20:24:52 -0700393 @Override
394 public Menu getMenu() {
395 return mMenu;
396 }
397
398 @Override
399 public void finish() {
Adam Powell5d279772010-07-27 16:34:07 -0700400 if (mActionMode != this) {
401 // Not the active action mode - no-op
Adam Powell93b6bc32010-07-22 11:36:35 -0700402 return;
403 }
404
Adam Powell6e346362010-07-23 10:18:23 -0700405 mCallback.onDestroyActionMode(this);
Adam Powell89e06452010-06-23 20:24:52 -0700406 mAnimatorView.setDisplayedChild(NORMAL_VIEW);
Adam Powell0e94b512010-06-29 17:58:20 -0700407
408 // Clear out the context mode views after the animation finishes
Adam Powell3461b322010-07-14 11:34:43 -0700409 mClosingContext = true;
Adam Powell0e94b512010-06-29 17:58:20 -0700410 mHandler.postDelayed(mCloseContext, mAnimatorView.getOutAnimation().getDuration());
411
Adam Powell89e06452010-06-23 20:24:52 -0700412 if (mLowerContextView != null && mLowerContextView.getVisibility() != View.GONE) {
413 // TODO Animate this
414 mLowerContextView.setVisibility(View.GONE);
415 }
Adam Powell5d279772010-07-27 16:34:07 -0700416 mActionMode = null;
Adam Powell89e06452010-06-23 20:24:52 -0700417 }
418
419 @Override
420 public void invalidate() {
Adam Powell6e346362010-07-23 10:18:23 -0700421 if (mCallback.onPrepareActionMode(this, mMenu)) {
Adam Powell89e06452010-06-23 20:24:52 -0700422 // Refresh content in both context views
423 }
424 }
425
426 @Override
427 public void setCustomView(View view) {
428 mUpperContextView.setCustomView(view);
Adam Powell29ed7572010-07-14 16:24:56 -0700429 mCustomView = new WeakReference<View>(view);
Adam Powell89e06452010-06-23 20:24:52 -0700430 }
431
432 @Override
433 public void setSubtitle(CharSequence subtitle) {
434 mUpperContextView.setSubtitle(subtitle);
435 }
436
437 @Override
438 public void setTitle(CharSequence title) {
439 mUpperContextView.setTitle(title);
440 }
Adam Powell29ed7572010-07-14 16:24:56 -0700441
442 @Override
Adam Powellc9ae2a22010-07-28 14:44:21 -0700443 public void setTitle(int resId) {
444 setTitle(mActivity.getString(resId));
445 }
446
447 @Override
448 public void setSubtitle(int resId) {
449 setSubtitle(mActivity.getString(resId));
450 }
451
452 @Override
Adam Powell29ed7572010-07-14 16:24:56 -0700453 public CharSequence getTitle() {
454 return mUpperContextView.getTitle();
455 }
456
457 @Override
458 public CharSequence getSubtitle() {
459 return mUpperContextView.getSubtitle();
460 }
Adam Powell89e06452010-06-23 20:24:52 -0700461
Adam Powell29ed7572010-07-14 16:24:56 -0700462 @Override
463 public View getCustomView() {
464 return mCustomView != null ? mCustomView.get() : null;
465 }
466
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700467 public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
Adam Powell6e346362010-07-23 10:18:23 -0700468 return mCallback.onActionItemClicked(this, item);
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700469 }
470
471 public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) {
472 }
473
474 public boolean onSubMenuSelected(SubMenuBuilder subMenu) {
475 if (!subMenu.hasVisibleItems()) {
476 return true;
Adam Powell89e06452010-06-23 20:24:52 -0700477 }
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700478
Adam Powelldec9dfd2010-08-09 15:27:54 -0700479 new MenuPopupHelper(mContext, subMenu).show();
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700480 return true;
481 }
482
483 public void onCloseSubMenu(SubMenuBuilder menu) {
484 }
485
486 public void onMenuModeChange(MenuBuilder menu) {
Adam Powellf6148c52010-08-11 21:10:16 -0700487 invalidate();
488 mUpperContextView.showOverflowMenu();
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700489 }
Adam Powell661c9082010-07-02 10:09:44 -0700490 }
491
492 /**
493 * @hide
494 */
495 public class TabImpl extends ActionBar.Tab {
Adam Powell2b6230e2010-09-07 17:55:25 -0700496 private ActionBar.TabListener mCallback;
497 private Object mTag;
Adam Powell661c9082010-07-02 10:09:44 -0700498 private Drawable mIcon;
499 private CharSequence mText;
500 private int mPosition;
Adam Powell2b6230e2010-09-07 17:55:25 -0700501 private View mCustomView;
Adam Powell661c9082010-07-02 10:09:44 -0700502
503 @Override
Adam Powell2b6230e2010-09-07 17:55:25 -0700504 public Object getTag() {
505 return mTag;
506 }
507
508 @Override
Adam Powell9ab97872010-10-26 21:47:29 -0700509 public Tab setTag(Object tag) {
Adam Powell2b6230e2010-09-07 17:55:25 -0700510 mTag = tag;
Adam Powell9ab97872010-10-26 21:47:29 -0700511 return this;
Adam Powell2b6230e2010-09-07 17:55:25 -0700512 }
513
514 public ActionBar.TabListener getCallback() {
515 return mCallback;
516 }
517
518 @Override
Adam Powell9ab97872010-10-26 21:47:29 -0700519 public Tab setTabListener(ActionBar.TabListener callback) {
Adam Powell2b6230e2010-09-07 17:55:25 -0700520 mCallback = callback;
Adam Powell9ab97872010-10-26 21:47:29 -0700521 return this;
Adam Powell2b6230e2010-09-07 17:55:25 -0700522 }
523
524 @Override
525 public View getCustomView() {
526 return mCustomView;
527 }
528
529 @Override
Adam Powell9ab97872010-10-26 21:47:29 -0700530 public Tab setCustomView(View view) {
Adam Powell2b6230e2010-09-07 17:55:25 -0700531 mCustomView = view;
Adam Powell9ab97872010-10-26 21:47:29 -0700532 return this;
Adam Powell661c9082010-07-02 10:09:44 -0700533 }
534
535 @Override
536 public Drawable getIcon() {
537 return mIcon;
538 }
539
540 @Override
541 public int getPosition() {
542 return mPosition;
543 }
544
545 public void setPosition(int position) {
546 mPosition = position;
547 }
548
549 @Override
550 public CharSequence getText() {
551 return mText;
552 }
553
554 @Override
Adam Powell9ab97872010-10-26 21:47:29 -0700555 public Tab setIcon(Drawable icon) {
Adam Powell661c9082010-07-02 10:09:44 -0700556 mIcon = icon;
Adam Powell9ab97872010-10-26 21:47:29 -0700557 return this;
Adam Powell661c9082010-07-02 10:09:44 -0700558 }
559
560 @Override
Adam Powell9ab97872010-10-26 21:47:29 -0700561 public Tab setText(CharSequence text) {
Adam Powell661c9082010-07-02 10:09:44 -0700562 mText = text;
Adam Powell9ab97872010-10-26 21:47:29 -0700563 return this;
Adam Powell661c9082010-07-02 10:09:44 -0700564 }
565
566 @Override
567 public void select() {
568 selectTab(this);
Adam Powell89e06452010-06-23 20:24:52 -0700569 }
570 }
Adam Powell9ab97872010-10-26 21:47:29 -0700571
572 @Override
573 public void setCustomView(View view) {
574 mActionView.setCustomNavigationView(view);
575 }
576
577 @Override
578 public void setCustomView(View view, LayoutParams layoutParams) {
579 view.setLayoutParams(layoutParams);
580 mActionView.setCustomNavigationView(view);
581 }
582
583 @Override
584 public void setListNavigationCallbacks(SpinnerAdapter adapter, NavigationCallback callback) {
585 mActionView.setDropdownAdapter(adapter);
586 mActionView.setCallback(callback);
587 }
588
589 @Override
590 public int getSelectedNavigationIndex() {
591 switch (mActionView.getNavigationMode()) {
592 case NAVIGATION_MODE_TABS:
593 return mSelectedTab.getPosition();
594 case NAVIGATION_MODE_LIST:
595 return mActionView.getDropdownSelectedPosition();
596 default:
597 return -1;
598 }
599 }
600
601 @Override
602 public int getNavigationItemCount() {
603 switch (mActionView.getNavigationMode()) {
604 case NAVIGATION_MODE_TABS:
605 return mTabs.size();
606 case NAVIGATION_MODE_LIST:
607 SpinnerAdapter adapter = mActionView.getDropdownAdapter();
608 return adapter != null ? adapter.getCount() : 0;
609 default:
610 return 0;
611 }
612 }
613
614 @Override
615 public void setNavigationMode(int mode) {
616 mActionView.setNavigationMode(mode);
617 }
618
619 @Override
620 public Tab getTabAt(int index) {
621 return mTabs.get(index);
622 }
Adam Powell89e06452010-06-23 20:24:52 -0700623}