blob: 104835283b21e30330a4d309a054596496589dd3 [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;
55
Adam Powell661c9082010-07-02 10:09:44 -070056 private static final int TAB_SWITCH_SHOW_HIDE = 0;
57 private static final int TAB_SWITCH_ADD_REMOVE = 1;
58
Adam Powelldec9dfd2010-08-09 15:27:54 -070059 private Context mContext;
Adam Powell661c9082010-07-02 10:09:44 -070060 private Activity mActivity;
Adam Powelldec9dfd2010-08-09 15:27:54 -070061 private Dialog mDialog;
Adam Powell661c9082010-07-02 10:09:44 -070062
Adam Powell89e06452010-06-23 20:24:52 -070063 private ViewAnimator mAnimatorView;
64 private ActionBarView mActionView;
65 private ActionBarContextView mUpperContextView;
66 private LinearLayout mLowerContextView;
Adam Powell661c9082010-07-02 10:09:44 -070067
68 private ArrayList<TabImpl> mTabs = new ArrayList<TabImpl>();
69
70 private int mTabContainerViewId = android.R.id.content;
71 private TabImpl mSelectedTab;
72 private int mTabSwitchMode = TAB_SWITCH_ADD_REMOVE;
Adam Powell89e06452010-06-23 20:24:52 -070073
Adam Powell5d279772010-07-27 16:34:07 -070074 private ActionMode mActionMode;
Adam Powell89e06452010-06-23 20:24:52 -070075
76 private static final int CONTEXT_DISPLAY_NORMAL = 0;
77 private static final int CONTEXT_DISPLAY_SPLIT = 1;
78
79 private int mContextDisplayMode;
Adam Powell0e94b512010-06-29 17:58:20 -070080
Adam Powell3461b322010-07-14 11:34:43 -070081 private boolean mClosingContext;
82
Adam Powell0e94b512010-06-29 17:58:20 -070083 final Handler mHandler = new Handler();
84 final Runnable mCloseContext = new Runnable() {
85 public void run() {
86 mUpperContextView.closeMode();
87 if (mLowerContextView != null) {
88 mLowerContextView.removeAllViews();
89 }
Adam Powell3461b322010-07-14 11:34:43 -070090 mClosingContext = false;
Adam Powell0e94b512010-06-29 17:58:20 -070091 }
92 };
93
Adam Powell661c9082010-07-02 10:09:44 -070094 public ActionBarImpl(Activity activity) {
Adam Powell661c9082010-07-02 10:09:44 -070095 mActivity = activity;
Adam Powelldec9dfd2010-08-09 15:27:54 -070096 init(activity.getWindow().getDecorView());
97 }
98
99 public ActionBarImpl(Dialog dialog) {
100 mDialog = dialog;
101 init(dialog.getWindow().getDecorView());
102 }
103
104 private void init(View decor) {
105 mContext = decor.getContext();
Adam Powell89e06452010-06-23 20:24:52 -0700106 mActionView = (ActionBarView) decor.findViewById(com.android.internal.R.id.action_bar);
107 mUpperContextView = (ActionBarContextView) decor.findViewById(
108 com.android.internal.R.id.action_context_bar);
109 mLowerContextView = (LinearLayout) decor.findViewById(
110 com.android.internal.R.id.lower_action_context_bar);
111 mAnimatorView = (ViewAnimator) decor.findViewById(
112 com.android.internal.R.id.action_bar_animator);
Steve Block08f194b2010-08-24 18:20:48 +0100113
Adam Powell89e06452010-06-23 20:24:52 -0700114 if (mActionView == null || mUpperContextView == null || mAnimatorView == null) {
115 throw new IllegalStateException(getClass().getSimpleName() + " can only be used " +
116 "with a compatible window decor layout");
117 }
Adam Powell0e94b512010-06-29 17:58:20 -0700118
Steve Block08f194b2010-08-24 18:20:48 +0100119 mActionView.setContextView(mUpperContextView);
Adam Powell89e06452010-06-23 20:24:52 -0700120 mContextDisplayMode = mLowerContextView == null ?
121 CONTEXT_DISPLAY_NORMAL : CONTEXT_DISPLAY_SPLIT;
122 }
123
Adam Powella66c7b02010-07-28 15:28:25 -0700124 @Override
125 public void setStandardNavigationMode(int titleResId, int subtitleResId) {
Adam Powelldec9dfd2010-08-09 15:27:54 -0700126 setStandardNavigationMode(mContext.getString(titleResId),
127 mContext.getString(subtitleResId));
Adam Powella66c7b02010-07-28 15:28:25 -0700128 }
129
130 @Override
131 public void setStandardNavigationMode(int titleResId) {
Adam Powelldec9dfd2010-08-09 15:27:54 -0700132 setStandardNavigationMode(mContext.getString(titleResId));
Adam Powella66c7b02010-07-28 15:28:25 -0700133 }
134
135 @Override
136 public void setTitle(int resId) {
Adam Powelldec9dfd2010-08-09 15:27:54 -0700137 setTitle(mContext.getString(resId));
Adam Powella66c7b02010-07-28 15:28:25 -0700138 }
139
140 @Override
141 public void setSubtitle(int resId) {
Adam Powelldec9dfd2010-08-09 15:27:54 -0700142 setSubtitle(mContext.getString(resId));
Adam Powella66c7b02010-07-28 15:28:25 -0700143 }
144
Adam Powell89e06452010-06-23 20:24:52 -0700145 public void setCustomNavigationMode(View view) {
Adam Powell661c9082010-07-02 10:09:44 -0700146 cleanupTabs();
Adam Powell89e06452010-06-23 20:24:52 -0700147 mActionView.setCustomNavigationView(view);
148 mActionView.setCallback(null);
149 }
Adam Powell0e94b512010-06-29 17:58:20 -0700150
Adam Powell89e06452010-06-23 20:24:52 -0700151 public void setDropdownNavigationMode(SpinnerAdapter adapter, NavigationCallback callback) {
Adam Powell17809772010-07-21 13:25:11 -0700152 setDropdownNavigationMode(adapter, callback, -1);
153 }
154
155 public void setDropdownNavigationMode(SpinnerAdapter adapter, NavigationCallback callback,
156 int defaultSelectedPosition) {
Adam Powell661c9082010-07-02 10:09:44 -0700157 cleanupTabs();
Adam Powell89e06452010-06-23 20:24:52 -0700158 mActionView.setNavigationMode(NAVIGATION_MODE_DROPDOWN_LIST);
159 mActionView.setDropdownAdapter(adapter);
Adam Powell17809772010-07-21 13:25:11 -0700160 if (defaultSelectedPosition >= 0) {
161 mActionView.setDropdownSelectedPosition(defaultSelectedPosition);
162 }
163 mActionView.setCallback(callback);
Adam Powell89e06452010-06-23 20:24:52 -0700164 }
Adam Powell0e94b512010-06-29 17:58:20 -0700165
166 public void setStandardNavigationMode() {
Adam Powell661c9082010-07-02 10:09:44 -0700167 cleanupTabs();
Adam Powell0e94b512010-06-29 17:58:20 -0700168 mActionView.setNavigationMode(NAVIGATION_MODE_STANDARD);
169 mActionView.setCallback(null);
170 }
171
Adam Powell89e06452010-06-23 20:24:52 -0700172 public void setStandardNavigationMode(CharSequence title) {
Adam Powell661c9082010-07-02 10:09:44 -0700173 cleanupTabs();
Adam Powell89e06452010-06-23 20:24:52 -0700174 setStandardNavigationMode(title, null);
175 }
Adam Powell0e94b512010-06-29 17:58:20 -0700176
Adam Powell89e06452010-06-23 20:24:52 -0700177 public void setStandardNavigationMode(CharSequence title, CharSequence subtitle) {
Adam Powell661c9082010-07-02 10:09:44 -0700178 cleanupTabs();
Adam Powell89e06452010-06-23 20:24:52 -0700179 mActionView.setNavigationMode(NAVIGATION_MODE_STANDARD);
180 mActionView.setTitle(title);
181 mActionView.setSubtitle(subtitle);
182 mActionView.setCallback(null);
183 }
184
Adam Powell17809772010-07-21 13:25:11 -0700185 public void setSelectedNavigationItem(int position) {
186 switch (mActionView.getNavigationMode()) {
187 case NAVIGATION_MODE_TABS:
188 selectTab(mTabs.get(position));
189 break;
190 case NAVIGATION_MODE_DROPDOWN_LIST:
191 mActionView.setDropdownSelectedPosition(position);
192 break;
193 default:
194 throw new IllegalStateException(
195 "setSelectedNavigationItem not valid for current navigation mode");
196 }
197 }
198
199 public int getSelectedNavigationItem() {
200 switch (mActionView.getNavigationMode()) {
201 case NAVIGATION_MODE_TABS:
202 return mSelectedTab.getPosition();
203 case NAVIGATION_MODE_DROPDOWN_LIST:
204 return mActionView.getDropdownSelectedPosition();
205 default:
206 return -1;
207 }
208 }
209
Adam Powell661c9082010-07-02 10:09:44 -0700210 private void cleanupTabs() {
211 if (mSelectedTab != null) {
212 selectTab(null);
213 }
214 if (!mTabs.isEmpty()) {
215 if (mTabSwitchMode == TAB_SWITCH_SHOW_HIDE) {
216 final FragmentTransaction trans = mActivity.openFragmentTransaction();
217 final int tabCount = mTabs.size();
218 for (int i = 0; i < tabCount; i++) {
219 trans.remove(mTabs.get(i).getFragment());
220 }
221 trans.commit();
222 }
223 mTabs.clear();
224 }
225 }
226
Adam Powell0e94b512010-06-29 17:58:20 -0700227 public void setTitle(CharSequence title) {
228 mActionView.setTitle(title);
229 }
230
231 public void setSubtitle(CharSequence subtitle) {
232 mActionView.setSubtitle(subtitle);
233 }
234
Adam Powell89e06452010-06-23 20:24:52 -0700235 public void setDisplayOptions(int options) {
236 mActionView.setDisplayOptions(options);
237 }
Adam Powell0e94b512010-06-29 17:58:20 -0700238
Adam Powell89e06452010-06-23 20:24:52 -0700239 public void setDisplayOptions(int options, int mask) {
240 final int current = mActionView.getDisplayOptions();
241 mActionView.setDisplayOptions((options & mask) | (current & ~mask));
242 }
243
244 public void setBackgroundDrawable(Drawable d) {
245 mActionView.setBackgroundDrawable(d);
246 }
247
248 public View getCustomNavigationView() {
249 return mActionView.getCustomNavigationView();
250 }
251
252 public CharSequence getTitle() {
253 return mActionView.getTitle();
254 }
255
256 public CharSequence getSubtitle() {
257 return mActionView.getSubtitle();
258 }
259
260 public int getNavigationMode() {
261 return mActionView.getNavigationMode();
262 }
263
264 public int getDisplayOptions() {
265 return mActionView.getDisplayOptions();
266 }
267
Adam Powell5d279772010-07-27 16:34:07 -0700268 public ActionMode startActionMode(ActionMode.Callback callback) {
269 if (mActionMode != null) {
270 mActionMode.finish();
Adam Powell6e346362010-07-23 10:18:23 -0700271 }
Adam Powell3461b322010-07-14 11:34:43 -0700272
273 // Don't wait for the close context mode animation to finish.
274 if (mClosingContext) {
275 mAnimatorView.clearAnimation();
276 mHandler.removeCallbacks(mCloseContext);
277 mCloseContext.run();
278 }
279
Adam Powell5d279772010-07-27 16:34:07 -0700280 ActionMode mode = new ActionModeImpl(callback);
Adam Powell6e346362010-07-23 10:18:23 -0700281 if (callback.onCreateActionMode(mode, mode.getMenu())) {
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700282 mode.invalidate();
283 mUpperContextView.initForMode(mode);
Adam Powell89e06452010-06-23 20:24:52 -0700284 mAnimatorView.setDisplayedChild(CONTEXT_VIEW);
285 if (mLowerContextView != null) {
286 // TODO animate this
287 mLowerContextView.setVisibility(View.VISIBLE);
288 }
Adam Powell5d279772010-07-27 16:34:07 -0700289 mActionMode = mode;
Adam Powellac695c62010-07-20 18:19:27 -0700290 return mode;
Adam Powell89e06452010-06-23 20:24:52 -0700291 }
Adam Powellac695c62010-07-20 18:19:27 -0700292 return null;
Adam Powell89e06452010-06-23 20:24:52 -0700293 }
294
Adam Powell661c9082010-07-02 10:09:44 -0700295 private void configureTab(Tab tab, int position) {
296 final TabImpl tabi = (TabImpl) tab;
297 final boolean isFirstTab = mTabs.isEmpty();
298 final FragmentTransaction trans = mActivity.openFragmentTransaction();
299 final Fragment frag = tabi.getFragment();
300
301 tabi.setPosition(position);
302 mTabs.add(position, tabi);
303
304 if (mTabSwitchMode == TAB_SWITCH_SHOW_HIDE) {
305 if (!frag.isAdded()) {
306 trans.add(mTabContainerViewId, frag);
307 }
308 }
309
310 if (isFirstTab) {
311 if (mTabSwitchMode == TAB_SWITCH_SHOW_HIDE) {
312 trans.show(frag);
313 } else if (mTabSwitchMode == TAB_SWITCH_ADD_REMOVE) {
314 trans.add(mTabContainerViewId, frag);
315 }
316 mSelectedTab = tabi;
317 } else {
318 if (mTabSwitchMode == TAB_SWITCH_SHOW_HIDE) {
319 trans.hide(frag);
320 }
321 }
322 trans.commit();
323 }
324
325 @Override
326 public void addTab(Tab tab) {
327 mActionView.addTab(tab);
328 configureTab(tab, mTabs.size());
329 }
330
331 @Override
332 public void insertTab(Tab tab, int position) {
333 mActionView.insertTab(tab, position);
334 configureTab(tab, position);
335 }
336
337 @Override
338 public Tab newTab() {
339 return new TabImpl();
340 }
341
342 @Override
343 public void removeTab(Tab tab) {
344 removeTabAt(tab.getPosition());
345 }
346
347 @Override
348 public void removeTabAt(int position) {
349 mActionView.removeTabAt(position);
350 mTabs.remove(position);
351
352 final int newTabCount = mTabs.size();
353 for (int i = position; i < newTabCount; i++) {
354 mTabs.get(i).setPosition(i);
355 }
356
357 selectTab(mTabs.isEmpty() ? null : mTabs.get(Math.max(0, position - 1)));
358 }
359
360 @Override
361 public void setTabNavigationMode() {
Adam Powelldec9dfd2010-08-09 15:27:54 -0700362 if (mActivity == null) {
363 throw new IllegalStateException(
364 "Tab navigation mode cannot be used outside of an Activity");
365 }
Adam Powell661c9082010-07-02 10:09:44 -0700366 mActionView.setNavigationMode(NAVIGATION_MODE_TABS);
367 }
368
369 @Override
370 public void setTabNavigationMode(int containerViewId) {
371 mTabContainerViewId = containerViewId;
372 setTabNavigationMode();
373 }
374
375 @Override
376 public void selectTab(Tab tab) {
377 if (mSelectedTab == tab) {
378 return;
379 }
380
381 mActionView.setTabSelected(tab != null ? tab.getPosition() : Tab.INVALID_POSITION);
382 final FragmentTransaction trans = mActivity.openFragmentTransaction();
383 if (mSelectedTab != null) {
384 if (mTabSwitchMode == TAB_SWITCH_SHOW_HIDE) {
385 trans.hide(mSelectedTab.getFragment());
386 } else if (mTabSwitchMode == TAB_SWITCH_ADD_REMOVE) {
387 trans.remove(mSelectedTab.getFragment());
388 }
389 }
390 if (tab != null) {
391 if (mTabSwitchMode == TAB_SWITCH_SHOW_HIDE) {
392 trans.show(tab.getFragment());
393 } else if (mTabSwitchMode == TAB_SWITCH_ADD_REMOVE) {
394 trans.add(mTabContainerViewId, tab.getFragment());
395 }
396 }
397 mSelectedTab = (TabImpl) tab;
398 trans.commit();
399 }
400
Adam Powell6b336f82010-08-10 20:13:01 -0700401 @Override
402 public int getHeight() {
403 return mActionView.getHeight();
404 }
405
406 @Override
407 public void show() {
408 // TODO animate!
409 mAnimatorView.setVisibility(View.VISIBLE);
410 }
411
412 @Override
413 public void hide() {
414 // TODO animate!
415 mAnimatorView.setVisibility(View.GONE);
416 }
417
418 public boolean isShowing() {
419 return mAnimatorView.getVisibility() == View.VISIBLE;
420 }
421
Adam Powell89e06452010-06-23 20:24:52 -0700422 /**
423 * @hide
424 */
Adam Powell5d279772010-07-27 16:34:07 -0700425 public class ActionModeImpl extends ActionMode implements MenuBuilder.Callback {
Adam Powell6e346362010-07-23 10:18:23 -0700426 private ActionMode.Callback mCallback;
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700427 private MenuBuilder mMenu;
Adam Powell29ed7572010-07-14 16:24:56 -0700428 private WeakReference<View> mCustomView;
Adam Powell89e06452010-06-23 20:24:52 -0700429
Adam Powell5d279772010-07-27 16:34:07 -0700430 public ActionModeImpl(ActionMode.Callback callback) {
Adam Powell89e06452010-06-23 20:24:52 -0700431 mCallback = callback;
Adam Powell4d9861e2010-08-17 11:14:40 -0700432 mMenu = new MenuBuilder(mActionView.getContext())
433 .setDefaultShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700434 mMenu.setCallback(this);
Adam Powell89e06452010-06-23 20:24:52 -0700435 }
Adam Powell9168f0b2010-08-02 15:46:24 -0700436
437 @Override
438 public MenuInflater getMenuInflater() {
Adam Powell4d9861e2010-08-17 11:14:40 -0700439 return new MenuInflater(mContext);
Adam Powell9168f0b2010-08-02 15:46:24 -0700440 }
441
Adam Powell89e06452010-06-23 20:24:52 -0700442 @Override
443 public Menu getMenu() {
444 return mMenu;
445 }
446
447 @Override
448 public void finish() {
Adam Powell5d279772010-07-27 16:34:07 -0700449 if (mActionMode != this) {
450 // Not the active action mode - no-op
Adam Powell93b6bc32010-07-22 11:36:35 -0700451 return;
452 }
453
Adam Powell6e346362010-07-23 10:18:23 -0700454 mCallback.onDestroyActionMode(this);
Adam Powell89e06452010-06-23 20:24:52 -0700455 mAnimatorView.setDisplayedChild(NORMAL_VIEW);
Adam Powell0e94b512010-06-29 17:58:20 -0700456
457 // Clear out the context mode views after the animation finishes
Adam Powell3461b322010-07-14 11:34:43 -0700458 mClosingContext = true;
Adam Powell0e94b512010-06-29 17:58:20 -0700459 mHandler.postDelayed(mCloseContext, mAnimatorView.getOutAnimation().getDuration());
460
Adam Powell89e06452010-06-23 20:24:52 -0700461 if (mLowerContextView != null && mLowerContextView.getVisibility() != View.GONE) {
462 // TODO Animate this
463 mLowerContextView.setVisibility(View.GONE);
464 }
Adam Powell5d279772010-07-27 16:34:07 -0700465 mActionMode = null;
Adam Powell89e06452010-06-23 20:24:52 -0700466 }
467
468 @Override
469 public void invalidate() {
Adam Powell6e346362010-07-23 10:18:23 -0700470 if (mCallback.onPrepareActionMode(this, mMenu)) {
Adam Powell89e06452010-06-23 20:24:52 -0700471 // Refresh content in both context views
472 }
473 }
474
475 @Override
476 public void setCustomView(View view) {
477 mUpperContextView.setCustomView(view);
Adam Powell29ed7572010-07-14 16:24:56 -0700478 mCustomView = new WeakReference<View>(view);
Adam Powell89e06452010-06-23 20:24:52 -0700479 }
480
481 @Override
482 public void setSubtitle(CharSequence subtitle) {
483 mUpperContextView.setSubtitle(subtitle);
484 }
485
486 @Override
487 public void setTitle(CharSequence title) {
488 mUpperContextView.setTitle(title);
489 }
Adam Powell29ed7572010-07-14 16:24:56 -0700490
491 @Override
Adam Powellc9ae2a22010-07-28 14:44:21 -0700492 public void setTitle(int resId) {
493 setTitle(mActivity.getString(resId));
494 }
495
496 @Override
497 public void setSubtitle(int resId) {
498 setSubtitle(mActivity.getString(resId));
499 }
500
501 @Override
Adam Powell29ed7572010-07-14 16:24:56 -0700502 public CharSequence getTitle() {
503 return mUpperContextView.getTitle();
504 }
505
506 @Override
507 public CharSequence getSubtitle() {
508 return mUpperContextView.getSubtitle();
509 }
Adam Powell89e06452010-06-23 20:24:52 -0700510
Adam Powell29ed7572010-07-14 16:24:56 -0700511 @Override
512 public View getCustomView() {
513 return mCustomView != null ? mCustomView.get() : null;
514 }
515
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700516 public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
Adam Powell6e346362010-07-23 10:18:23 -0700517 return mCallback.onActionItemClicked(this, item);
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700518 }
519
520 public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) {
521 }
522
523 public boolean onSubMenuSelected(SubMenuBuilder subMenu) {
524 if (!subMenu.hasVisibleItems()) {
525 return true;
Adam Powell89e06452010-06-23 20:24:52 -0700526 }
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700527
Adam Powelldec9dfd2010-08-09 15:27:54 -0700528 new MenuPopupHelper(mContext, subMenu).show();
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700529 return true;
530 }
531
532 public void onCloseSubMenu(SubMenuBuilder menu) {
533 }
534
535 public void onMenuModeChange(MenuBuilder menu) {
Adam Powellf6148c52010-08-11 21:10:16 -0700536 invalidate();
537 mUpperContextView.showOverflowMenu();
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700538 }
Adam Powell661c9082010-07-02 10:09:44 -0700539 }
540
541 /**
542 * @hide
543 */
544 public class TabImpl extends ActionBar.Tab {
545 private Fragment mFragment;
546 private Drawable mIcon;
547 private CharSequence mText;
548 private int mPosition;
549
550 @Override
551 public Fragment getFragment() {
552 return mFragment;
553 }
554
555 @Override
556 public Drawable getIcon() {
557 return mIcon;
558 }
559
560 @Override
561 public int getPosition() {
562 return mPosition;
563 }
564
565 public void setPosition(int position) {
566 mPosition = position;
567 }
568
569 @Override
570 public CharSequence getText() {
571 return mText;
572 }
573
574 @Override
575 public void setFragment(Fragment fragment) {
576 mFragment = fragment;
577 }
578
579 @Override
580 public void setIcon(Drawable icon) {
581 mIcon = icon;
582 }
583
584 @Override
585 public void setText(CharSequence text) {
586 mText = text;
587 }
588
589 @Override
590 public void select() {
591 selectTab(this);
Adam Powell89e06452010-06-23 20:24:52 -0700592 }
593 }
594}