Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.internal.app; |
| 18 | |
Adam Powell | 2c9c9fe | 2010-07-16 10:17:57 -0700 | [diff] [blame] | 19 | import com.android.internal.view.menu.MenuBuilder; |
Adam Powell | 2c9c9fe | 2010-07-16 10:17:57 -0700 | [diff] [blame] | 20 | import com.android.internal.view.menu.MenuPopupHelper; |
| 21 | import com.android.internal.view.menu.SubMenuBuilder; |
Adam Powell | 01feaee | 2011-02-10 15:05:05 -0800 | [diff] [blame] | 22 | import com.android.internal.widget.ActionBarContainer; |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 23 | import com.android.internal.widget.ActionBarContextView; |
| 24 | import com.android.internal.widget.ActionBarView; |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 25 | import com.android.internal.widget.ScrollingTabContainerView; |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 26 | |
Adam Powell | d8b3f2e | 2010-12-02 13:37:03 -0800 | [diff] [blame] | 27 | import android.animation.Animator; |
Adam Powell | d8b3f2e | 2010-12-02 13:37:03 -0800 | [diff] [blame] | 28 | import android.animation.Animator.AnimatorListener; |
Adam Powell | 07e1f98 | 2011-03-24 11:11:15 -0700 | [diff] [blame] | 29 | import android.animation.AnimatorListenerAdapter; |
Adam Powell | d8b3f2e | 2010-12-02 13:37:03 -0800 | [diff] [blame] | 30 | import android.animation.AnimatorSet; |
Adam Powell | e6ec732 | 2010-12-07 15:29:26 -0800 | [diff] [blame] | 31 | import android.animation.ObjectAnimator; |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 32 | import android.app.ActionBar; |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 33 | import android.app.Activity; |
Adam Powell | dec9dfd | 2010-08-09 15:27:54 -0700 | [diff] [blame] | 34 | import android.app.Dialog; |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 35 | import android.app.FragmentTransaction; |
Adam Powell | dec9dfd | 2010-08-09 15:27:54 -0700 | [diff] [blame] | 36 | import android.content.Context; |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 37 | import android.content.res.Configuration; |
Adam Powell | 88ab697 | 2011-07-28 11:25:01 -0700 | [diff] [blame] | 38 | import android.content.res.Resources; |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 39 | import android.graphics.drawable.Drawable; |
Adam Powell | c29f4e5 | 2011-07-13 20:40:52 -0700 | [diff] [blame] | 40 | import android.os.Build; |
Adam Powell | 0e94b51 | 2010-06-29 17:58:20 -0700 | [diff] [blame] | 41 | import android.os.Handler; |
Adam Powell | 88ab697 | 2011-07-28 11:25:01 -0700 | [diff] [blame] | 42 | import android.util.TypedValue; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 43 | import android.view.ActionMode; |
Adam Powell | 88ab697 | 2011-07-28 11:25:01 -0700 | [diff] [blame] | 44 | import android.view.ContextThemeWrapper; |
Adam Powell | 32555f3 | 2010-11-17 13:49:22 -0800 | [diff] [blame] | 45 | import android.view.LayoutInflater; |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 46 | import android.view.Menu; |
Adam Powell | 9168f0b | 2010-08-02 15:46:24 -0700 | [diff] [blame] | 47 | import android.view.MenuInflater; |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 48 | import android.view.MenuItem; |
| 49 | import android.view.View; |
Adam Powell | e6ec732 | 2010-12-07 15:29:26 -0800 | [diff] [blame] | 50 | import android.view.Window; |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 51 | import android.widget.SpinnerAdapter; |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 52 | |
Adam Powell | 29ed757 | 2010-07-14 16:24:56 -0700 | [diff] [blame] | 53 | import java.lang.ref.WeakReference; |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 54 | import java.util.ArrayList; |
| 55 | |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 56 | /** |
| 57 | * ActionBarImpl is the ActionBar implementation used |
| 58 | * by devices of all screen sizes. If it detects a compatible decor, |
| 59 | * it will split contextual modes across both the ActionBarView at |
| 60 | * the top of the screen and a horizontal LinearLayout at the bottom |
| 61 | * which is normally hidden. |
| 62 | */ |
| 63 | public class ActionBarImpl extends ActionBar { |
Adam Powell | d814504 | 2011-03-24 14:18:27 -0700 | [diff] [blame] | 64 | private static final String TAG = "ActionBarImpl"; |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 65 | |
Adam Powell | dec9dfd | 2010-08-09 15:27:54 -0700 | [diff] [blame] | 66 | private Context mContext; |
Adam Powell | 88ab697 | 2011-07-28 11:25:01 -0700 | [diff] [blame] | 67 | private Context mThemedContext; |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 68 | private Activity mActivity; |
Adam Powell | dec9dfd | 2010-08-09 15:27:54 -0700 | [diff] [blame] | 69 | private Dialog mDialog; |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 70 | |
Adam Powell | 01feaee | 2011-02-10 15:05:05 -0800 | [diff] [blame] | 71 | private ActionBarContainer mContainerView; |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 72 | private ActionBarView mActionView; |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 73 | private ActionBarContextView mContextView; |
| 74 | private ActionBarContainer mSplitView; |
Adam Powell | e6ec732 | 2010-12-07 15:29:26 -0800 | [diff] [blame] | 75 | private View mContentView; |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 76 | private ScrollingTabContainerView mTabScrollView; |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 77 | |
| 78 | private ArrayList<TabImpl> mTabs = new ArrayList<TabImpl>(); |
| 79 | |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 80 | private TabImpl mSelectedTab; |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 81 | private int mSavedTabPosition = INVALID_POSITION; |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 82 | |
Adam Powell | 060e3ca | 2011-07-19 20:39:16 -0700 | [diff] [blame] | 83 | ActionModeImpl mActionMode; |
| 84 | ActionMode mDeferredDestroyActionMode; |
| 85 | ActionMode.Callback mDeferredModeDestroyCallback; |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 86 | |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 87 | private boolean mLastMenuVisibility; |
| 88 | private ArrayList<OnMenuVisibilityListener> mMenuVisibilityListeners = |
| 89 | new ArrayList<OnMenuVisibilityListener>(); |
| 90 | |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 91 | private static final int CONTEXT_DISPLAY_NORMAL = 0; |
| 92 | private static final int CONTEXT_DISPLAY_SPLIT = 1; |
| 93 | |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 94 | private static final int INVALID_POSITION = -1; |
| 95 | |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 96 | private int mContextDisplayMode; |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 97 | private boolean mHasEmbeddedTabs; |
Adam Powell | 0e94b51 | 2010-06-29 17:58:20 -0700 | [diff] [blame] | 98 | |
| 99 | final Handler mHandler = new Handler(); |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 100 | Runnable mTabSelector; |
Adam Powell | d8b3f2e | 2010-12-02 13:37:03 -0800 | [diff] [blame] | 101 | |
Adam Powell | 07e1f98 | 2011-03-24 11:11:15 -0700 | [diff] [blame] | 102 | private Animator mCurrentShowAnim; |
| 103 | private Animator mCurrentModeAnim; |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 104 | private boolean mShowHideAnimationEnabled; |
Adam Powell | 07e1f98 | 2011-03-24 11:11:15 -0700 | [diff] [blame] | 105 | boolean mWasHiddenBeforeMode; |
Adam Powell | d8b3f2e | 2010-12-02 13:37:03 -0800 | [diff] [blame] | 106 | |
Adam Powell | 07e1f98 | 2011-03-24 11:11:15 -0700 | [diff] [blame] | 107 | final AnimatorListener mHideListener = new AnimatorListenerAdapter() { |
Adam Powell | e6ec732 | 2010-12-07 15:29:26 -0800 | [diff] [blame] | 108 | @Override |
| 109 | public void onAnimationEnd(Animator animation) { |
| 110 | if (mContentView != null) { |
| 111 | mContentView.setTranslationY(0); |
Adam Powell | 060e3ca | 2011-07-19 20:39:16 -0700 | [diff] [blame] | 112 | mContainerView.setTranslationY(0); |
Adam Powell | e6ec732 | 2010-12-07 15:29:26 -0800 | [diff] [blame] | 113 | } |
| 114 | mContainerView.setVisibility(View.GONE); |
Adam Powell | 01feaee | 2011-02-10 15:05:05 -0800 | [diff] [blame] | 115 | mContainerView.setTransitioning(false); |
Adam Powell | 07e1f98 | 2011-03-24 11:11:15 -0700 | [diff] [blame] | 116 | mCurrentShowAnim = null; |
Adam Powell | 060e3ca | 2011-07-19 20:39:16 -0700 | [diff] [blame] | 117 | completeDeferredDestroyActionMode(); |
Adam Powell | e6ec732 | 2010-12-07 15:29:26 -0800 | [diff] [blame] | 118 | } |
| 119 | }; |
| 120 | |
Adam Powell | 07e1f98 | 2011-03-24 11:11:15 -0700 | [diff] [blame] | 121 | final AnimatorListener mShowListener = new AnimatorListenerAdapter() { |
Adam Powell | e6ec732 | 2010-12-07 15:29:26 -0800 | [diff] [blame] | 122 | @Override |
| 123 | public void onAnimationEnd(Animator animation) { |
Adam Powell | 07e1f98 | 2011-03-24 11:11:15 -0700 | [diff] [blame] | 124 | mCurrentShowAnim = null; |
Adam Powell | 45f1e08 | 2010-12-10 14:20:13 -0800 | [diff] [blame] | 125 | mContainerView.requestLayout(); |
Adam Powell | e6ec732 | 2010-12-07 15:29:26 -0800 | [diff] [blame] | 126 | } |
Adam Powell | e6ec732 | 2010-12-07 15:29:26 -0800 | [diff] [blame] | 127 | }; |
| 128 | |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 129 | public ActionBarImpl(Activity activity) { |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 130 | mActivity = activity; |
Adam Powell | e6ec732 | 2010-12-07 15:29:26 -0800 | [diff] [blame] | 131 | Window window = activity.getWindow(); |
| 132 | View decor = window.getDecorView(); |
| 133 | init(decor); |
| 134 | if (!mActivity.getWindow().hasFeature(Window.FEATURE_ACTION_BAR_OVERLAY)) { |
| 135 | mContentView = decor.findViewById(android.R.id.content); |
| 136 | } |
Adam Powell | dec9dfd | 2010-08-09 15:27:54 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | public ActionBarImpl(Dialog dialog) { |
| 140 | mDialog = dialog; |
| 141 | init(dialog.getWindow().getDecorView()); |
| 142 | } |
| 143 | |
| 144 | private void init(View decor) { |
| 145 | mContext = decor.getContext(); |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 146 | mActionView = (ActionBarView) decor.findViewById(com.android.internal.R.id.action_bar); |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 147 | mContextView = (ActionBarContextView) decor.findViewById( |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 148 | com.android.internal.R.id.action_context_bar); |
Adam Powell | 01feaee | 2011-02-10 15:05:05 -0800 | [diff] [blame] | 149 | mContainerView = (ActionBarContainer) decor.findViewById( |
Adam Powell | d8b3f2e | 2010-12-02 13:37:03 -0800 | [diff] [blame] | 150 | com.android.internal.R.id.action_bar_container); |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 151 | mSplitView = (ActionBarContainer) decor.findViewById( |
| 152 | com.android.internal.R.id.split_action_bar); |
Steve Block | 08f194b | 2010-08-24 18:20:48 +0100 | [diff] [blame] | 153 | |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 154 | if (mActionView == null || mContextView == null || mContainerView == null) { |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 155 | throw new IllegalStateException(getClass().getSimpleName() + " can only be used " + |
| 156 | "with a compatible window decor layout"); |
| 157 | } |
Adam Powell | 0e94b51 | 2010-06-29 17:58:20 -0700 | [diff] [blame] | 158 | |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 159 | mActionView.setContextView(mContextView); |
Adam Powell | 9b4bee0 | 2011-04-27 19:24:47 -0700 | [diff] [blame] | 160 | mContextDisplayMode = mActionView.isSplitActionBar() ? |
| 161 | CONTEXT_DISPLAY_SPLIT : CONTEXT_DISPLAY_NORMAL; |
Adam Powell | dae7824 | 2011-04-25 15:23:41 -0700 | [diff] [blame] | 162 | |
Adam Powell | c29f4e5 | 2011-07-13 20:40:52 -0700 | [diff] [blame] | 163 | // Older apps get the home button interaction enabled by default. |
| 164 | // Newer apps need to enable it explicitly. |
Adam Powell | 28fa07e | 2011-07-15 20:17:25 -0700 | [diff] [blame] | 165 | setHomeButtonEnabled(mContext.getApplicationInfo().targetSdkVersion < |
| 166 | Build.VERSION_CODES.ICE_CREAM_SANDWICH); |
Adam Powell | f5645cb | 2011-08-10 22:49:02 -0700 | [diff] [blame] | 167 | |
| 168 | setHasEmbeddedTabs(mContext.getResources().getBoolean( |
| 169 | com.android.internal.R.bool.action_bar_embed_tabs)); |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | public void onConfigurationChanged(Configuration newConfig) { |
Adam Powell | f5645cb | 2011-08-10 22:49:02 -0700 | [diff] [blame] | 173 | setHasEmbeddedTabs(mContext.getResources().getBoolean( |
| 174 | com.android.internal.R.bool.action_bar_embed_tabs)); |
| 175 | } |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 176 | |
Adam Powell | f5645cb | 2011-08-10 22:49:02 -0700 | [diff] [blame] | 177 | private void setHasEmbeddedTabs(boolean hasEmbeddedTabs) { |
| 178 | mHasEmbeddedTabs = hasEmbeddedTabs; |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 179 | // Switch tab layout configuration if needed |
| 180 | if (!mHasEmbeddedTabs) { |
| 181 | mActionView.setEmbeddedTabView(null); |
| 182 | mContainerView.setTabContainer(mTabScrollView); |
| 183 | } else { |
| 184 | mContainerView.setTabContainer(null); |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 185 | mActionView.setEmbeddedTabView(mTabScrollView); |
| 186 | } |
Adam Powell | f5645cb | 2011-08-10 22:49:02 -0700 | [diff] [blame] | 187 | final boolean isInTabMode = getNavigationMode() == NAVIGATION_MODE_TABS; |
| 188 | if (mTabScrollView != null) { |
| 189 | mTabScrollView.setVisibility(isInTabMode ? View.VISIBLE : View.GONE); |
| 190 | } |
| 191 | mActionView.setCollapsable(!mHasEmbeddedTabs && isInTabMode); |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | private void ensureTabsExist() { |
| 195 | if (mTabScrollView != null) { |
| 196 | return; |
| 197 | } |
| 198 | |
Adam Powell | f5645cb | 2011-08-10 22:49:02 -0700 | [diff] [blame] | 199 | ScrollingTabContainerView tabScroller = new ScrollingTabContainerView(mContext); |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 200 | |
| 201 | if (mHasEmbeddedTabs) { |
| 202 | tabScroller.setVisibility(View.VISIBLE); |
| 203 | mActionView.setEmbeddedTabView(tabScroller); |
| 204 | } else { |
Adam Powell | dae7824 | 2011-04-25 15:23:41 -0700 | [diff] [blame] | 205 | tabScroller.setVisibility(getNavigationMode() == NAVIGATION_MODE_TABS ? |
| 206 | View.VISIBLE : View.GONE); |
Adam Powell | dae7824 | 2011-04-25 15:23:41 -0700 | [diff] [blame] | 207 | mContainerView.setTabContainer(tabScroller); |
Adam Powell | dae7824 | 2011-04-25 15:23:41 -0700 | [diff] [blame] | 208 | } |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 209 | mTabScrollView = tabScroller; |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Adam Powell | 060e3ca | 2011-07-19 20:39:16 -0700 | [diff] [blame] | 212 | void completeDeferredDestroyActionMode() { |
| 213 | if (mDeferredModeDestroyCallback != null) { |
| 214 | mDeferredModeDestroyCallback.onDestroyActionMode(mDeferredDestroyActionMode); |
| 215 | mDeferredDestroyActionMode = null; |
| 216 | mDeferredModeDestroyCallback = null; |
| 217 | } |
| 218 | } |
| 219 | |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 220 | /** |
| 221 | * Enables or disables animation between show/hide states. |
| 222 | * If animation is disabled using this method, animations in progress |
| 223 | * will be finished. |
| 224 | * |
| 225 | * @param enabled true to animate, false to not animate. |
| 226 | */ |
| 227 | public void setShowHideAnimationEnabled(boolean enabled) { |
| 228 | mShowHideAnimationEnabled = enabled; |
Adam Powell | 07e1f98 | 2011-03-24 11:11:15 -0700 | [diff] [blame] | 229 | if (!enabled && mCurrentShowAnim != null) { |
| 230 | mCurrentShowAnim.end(); |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 234 | public void addOnMenuVisibilityListener(OnMenuVisibilityListener listener) { |
| 235 | mMenuVisibilityListeners.add(listener); |
| 236 | } |
| 237 | |
| 238 | public void removeOnMenuVisibilityListener(OnMenuVisibilityListener listener) { |
| 239 | mMenuVisibilityListeners.remove(listener); |
| 240 | } |
| 241 | |
| 242 | public void dispatchMenuVisibilityChanged(boolean isVisible) { |
| 243 | if (isVisible == mLastMenuVisibility) { |
| 244 | return; |
| 245 | } |
| 246 | mLastMenuVisibility = isVisible; |
| 247 | |
| 248 | final int count = mMenuVisibilityListeners.size(); |
| 249 | for (int i = 0; i < count; i++) { |
| 250 | mMenuVisibilityListeners.get(i).onMenuVisibilityChanged(isVisible); |
| 251 | } |
| 252 | } |
| 253 | |
Adam Powell | a66c7b0 | 2010-07-28 15:28:25 -0700 | [diff] [blame] | 254 | @Override |
Adam Powell | 3f476b3 | 2011-01-03 19:25:36 -0800 | [diff] [blame] | 255 | public void setCustomView(int resId) { |
Adam Powell | f242368 | 2011-08-11 14:29:45 -0700 | [diff] [blame^] | 256 | setCustomView(LayoutInflater.from(getThemedContext()).inflate(resId, mActionView, false)); |
Adam Powell | 3f476b3 | 2011-01-03 19:25:36 -0800 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | @Override |
| 260 | public void setDisplayUseLogoEnabled(boolean useLogo) { |
| 261 | setDisplayOptions(useLogo ? DISPLAY_USE_LOGO : 0, DISPLAY_USE_LOGO); |
| 262 | } |
| 263 | |
| 264 | @Override |
| 265 | public void setDisplayShowHomeEnabled(boolean showHome) { |
| 266 | setDisplayOptions(showHome ? DISPLAY_SHOW_HOME : 0, DISPLAY_SHOW_HOME); |
| 267 | } |
| 268 | |
| 269 | @Override |
| 270 | public void setDisplayHomeAsUpEnabled(boolean showHomeAsUp) { |
| 271 | setDisplayOptions(showHomeAsUp ? DISPLAY_HOME_AS_UP : 0, DISPLAY_HOME_AS_UP); |
| 272 | } |
| 273 | |
| 274 | @Override |
| 275 | public void setDisplayShowTitleEnabled(boolean showTitle) { |
| 276 | setDisplayOptions(showTitle ? DISPLAY_SHOW_TITLE : 0, DISPLAY_SHOW_TITLE); |
| 277 | } |
| 278 | |
| 279 | @Override |
| 280 | public void setDisplayShowCustomEnabled(boolean showCustom) { |
| 281 | setDisplayOptions(showCustom ? DISPLAY_SHOW_CUSTOM : 0, DISPLAY_SHOW_CUSTOM); |
| 282 | } |
| 283 | |
| 284 | @Override |
Adam Powell | c29f4e5 | 2011-07-13 20:40:52 -0700 | [diff] [blame] | 285 | public void setHomeButtonEnabled(boolean enable) { |
| 286 | mActionView.setHomeButtonEnabled(enable); |
Adam Powell | dae7824 | 2011-04-25 15:23:41 -0700 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | @Override |
Adam Powell | a66c7b0 | 2010-07-28 15:28:25 -0700 | [diff] [blame] | 290 | public void setTitle(int resId) { |
Adam Powell | dec9dfd | 2010-08-09 15:27:54 -0700 | [diff] [blame] | 291 | setTitle(mContext.getString(resId)); |
Adam Powell | a66c7b0 | 2010-07-28 15:28:25 -0700 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | @Override |
| 295 | public void setSubtitle(int resId) { |
Adam Powell | dec9dfd | 2010-08-09 15:27:54 -0700 | [diff] [blame] | 296 | setSubtitle(mContext.getString(resId)); |
Adam Powell | a66c7b0 | 2010-07-28 15:28:25 -0700 | [diff] [blame] | 297 | } |
| 298 | |
Adam Powell | 1780977 | 2010-07-21 13:25:11 -0700 | [diff] [blame] | 299 | public void setSelectedNavigationItem(int position) { |
| 300 | switch (mActionView.getNavigationMode()) { |
| 301 | case NAVIGATION_MODE_TABS: |
| 302 | selectTab(mTabs.get(position)); |
| 303 | break; |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 304 | case NAVIGATION_MODE_LIST: |
Adam Powell | 1780977 | 2010-07-21 13:25:11 -0700 | [diff] [blame] | 305 | mActionView.setDropdownSelectedPosition(position); |
| 306 | break; |
| 307 | default: |
| 308 | throw new IllegalStateException( |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 309 | "setSelectedNavigationIndex not valid for current navigation mode"); |
Adam Powell | 1780977 | 2010-07-21 13:25:11 -0700 | [diff] [blame] | 310 | } |
| 311 | } |
| 312 | |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 313 | public void removeAllTabs() { |
| 314 | cleanupTabs(); |
Adam Powell | 1780977 | 2010-07-21 13:25:11 -0700 | [diff] [blame] | 315 | } |
| 316 | |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 317 | private void cleanupTabs() { |
| 318 | if (mSelectedTab != null) { |
| 319 | selectTab(null); |
| 320 | } |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 321 | mTabs.clear(); |
Adam Powell | d21aa12 | 2011-05-27 13:09:52 -0700 | [diff] [blame] | 322 | if (mTabScrollView != null) { |
| 323 | mTabScrollView.removeAllTabs(); |
| 324 | } |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 325 | mSavedTabPosition = INVALID_POSITION; |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 326 | } |
| 327 | |
Adam Powell | 0e94b51 | 2010-06-29 17:58:20 -0700 | [diff] [blame] | 328 | public void setTitle(CharSequence title) { |
| 329 | mActionView.setTitle(title); |
| 330 | } |
| 331 | |
| 332 | public void setSubtitle(CharSequence subtitle) { |
| 333 | mActionView.setSubtitle(subtitle); |
| 334 | } |
| 335 | |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 336 | public void setDisplayOptions(int options) { |
| 337 | mActionView.setDisplayOptions(options); |
| 338 | } |
Adam Powell | 0e94b51 | 2010-06-29 17:58:20 -0700 | [diff] [blame] | 339 | |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 340 | public void setDisplayOptions(int options, int mask) { |
| 341 | final int current = mActionView.getDisplayOptions(); |
| 342 | mActionView.setDisplayOptions((options & mask) | (current & ~mask)); |
| 343 | } |
| 344 | |
| 345 | public void setBackgroundDrawable(Drawable d) { |
Adam Powell | e8c1e5c | 2010-12-13 10:49:32 -0800 | [diff] [blame] | 346 | mContainerView.setBackgroundDrawable(d); |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 347 | } |
| 348 | |
Adam Powell | ef70444 | 2010-11-16 14:48:22 -0800 | [diff] [blame] | 349 | public View getCustomView() { |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 350 | return mActionView.getCustomNavigationView(); |
| 351 | } |
| 352 | |
| 353 | public CharSequence getTitle() { |
| 354 | return mActionView.getTitle(); |
| 355 | } |
| 356 | |
| 357 | public CharSequence getSubtitle() { |
| 358 | return mActionView.getSubtitle(); |
| 359 | } |
| 360 | |
| 361 | public int getNavigationMode() { |
| 362 | return mActionView.getNavigationMode(); |
| 363 | } |
| 364 | |
| 365 | public int getDisplayOptions() { |
| 366 | return mActionView.getDisplayOptions(); |
| 367 | } |
| 368 | |
Adam Powell | 5d27977 | 2010-07-27 16:34:07 -0700 | [diff] [blame] | 369 | public ActionMode startActionMode(ActionMode.Callback callback) { |
Adam Powell | 060e3ca | 2011-07-19 20:39:16 -0700 | [diff] [blame] | 370 | boolean wasHidden = false; |
Adam Powell | 5d27977 | 2010-07-27 16:34:07 -0700 | [diff] [blame] | 371 | if (mActionMode != null) { |
Adam Powell | 060e3ca | 2011-07-19 20:39:16 -0700 | [diff] [blame] | 372 | wasHidden = mWasHiddenBeforeMode; |
Adam Powell | 5d27977 | 2010-07-27 16:34:07 -0700 | [diff] [blame] | 373 | mActionMode.finish(); |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 374 | } |
Adam Powell | 3461b32 | 2010-07-14 11:34:43 -0700 | [diff] [blame] | 375 | |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 376 | mContextView.killMode(); |
Adam Powell | 5ee36c4 | 2011-06-02 12:59:43 -0700 | [diff] [blame] | 377 | ActionModeImpl mode = new ActionModeImpl(callback); |
| 378 | if (mode.dispatchOnCreate()) { |
Adam Powell | 060e3ca | 2011-07-19 20:39:16 -0700 | [diff] [blame] | 379 | mWasHiddenBeforeMode = !isShowing() || wasHidden; |
Adam Powell | 2c9c9fe | 2010-07-16 10:17:57 -0700 | [diff] [blame] | 380 | mode.invalidate(); |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 381 | mContextView.initForMode(mode); |
| 382 | animateToMode(true); |
Adam Powell | 1ab418a | 2011-06-09 20:49:49 -0700 | [diff] [blame] | 383 | if (mSplitView != null && mContextDisplayMode == CONTEXT_DISPLAY_SPLIT) { |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 384 | // TODO animate this |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 385 | mSplitView.setVisibility(View.VISIBLE); |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 386 | } |
Adam Powell | 5d27977 | 2010-07-27 16:34:07 -0700 | [diff] [blame] | 387 | mActionMode = mode; |
Adam Powell | ac695c6 | 2010-07-20 18:19:27 -0700 | [diff] [blame] | 388 | return mode; |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 389 | } |
Adam Powell | ac695c6 | 2010-07-20 18:19:27 -0700 | [diff] [blame] | 390 | return null; |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 391 | } |
| 392 | |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 393 | private void configureTab(Tab tab, int position) { |
| 394 | final TabImpl tabi = (TabImpl) tab; |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 395 | final ActionBar.TabListener callback = tabi.getCallback(); |
| 396 | |
| 397 | if (callback == null) { |
| 398 | throw new IllegalStateException("Action Bar Tab must have a Callback"); |
| 399 | } |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 400 | |
| 401 | tabi.setPosition(position); |
| 402 | mTabs.add(position, tabi); |
| 403 | |
Adam Powell | 81b8944 | 2010-11-02 17:58:56 -0700 | [diff] [blame] | 404 | final int count = mTabs.size(); |
| 405 | for (int i = position + 1; i < count; i++) { |
| 406 | mTabs.get(i).setPosition(i); |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 407 | } |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | @Override |
| 411 | public void addTab(Tab tab) { |
Adam Powell | 81b8944 | 2010-11-02 17:58:56 -0700 | [diff] [blame] | 412 | addTab(tab, mTabs.isEmpty()); |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | @Override |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 416 | public void addTab(Tab tab, int position) { |
Adam Powell | 81b8944 | 2010-11-02 17:58:56 -0700 | [diff] [blame] | 417 | addTab(tab, position, mTabs.isEmpty()); |
| 418 | } |
| 419 | |
| 420 | @Override |
| 421 | public void addTab(Tab tab, boolean setSelected) { |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 422 | ensureTabsExist(); |
| 423 | mTabScrollView.addTab(tab, setSelected); |
Adam Powell | 81b8944 | 2010-11-02 17:58:56 -0700 | [diff] [blame] | 424 | configureTab(tab, mTabs.size()); |
| 425 | if (setSelected) { |
| 426 | selectTab(tab); |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | @Override |
| 431 | public void addTab(Tab tab, int position, boolean setSelected) { |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 432 | ensureTabsExist(); |
| 433 | mTabScrollView.addTab(tab, position, setSelected); |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 434 | configureTab(tab, position); |
Adam Powell | 81b8944 | 2010-11-02 17:58:56 -0700 | [diff] [blame] | 435 | if (setSelected) { |
| 436 | selectTab(tab); |
| 437 | } |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | @Override |
| 441 | public Tab newTab() { |
| 442 | return new TabImpl(); |
| 443 | } |
| 444 | |
| 445 | @Override |
| 446 | public void removeTab(Tab tab) { |
| 447 | removeTabAt(tab.getPosition()); |
| 448 | } |
| 449 | |
| 450 | @Override |
| 451 | public void removeTabAt(int position) { |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 452 | if (mTabScrollView == null) { |
| 453 | // No tabs around to remove |
| 454 | return; |
| 455 | } |
| 456 | |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 457 | int selectedTabPosition = mSelectedTab != null |
| 458 | ? mSelectedTab.getPosition() : mSavedTabPosition; |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 459 | mTabScrollView.removeTabAt(position); |
Adam Powell | 0d8ec1d | 2011-05-03 14:49:13 -0700 | [diff] [blame] | 460 | TabImpl removedTab = mTabs.remove(position); |
| 461 | if (removedTab != null) { |
| 462 | removedTab.setPosition(-1); |
| 463 | } |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 464 | |
| 465 | final int newTabCount = mTabs.size(); |
| 466 | for (int i = position; i < newTabCount; i++) { |
| 467 | mTabs.get(i).setPosition(i); |
| 468 | } |
| 469 | |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 470 | if (selectedTabPosition == position) { |
| 471 | selectTab(mTabs.isEmpty() ? null : mTabs.get(Math.max(0, position - 1))); |
| 472 | } |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | @Override |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 476 | public void selectTab(Tab tab) { |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 477 | if (getNavigationMode() != NAVIGATION_MODE_TABS) { |
| 478 | mSavedTabPosition = tab != null ? tab.getPosition() : INVALID_POSITION; |
| 479 | return; |
| 480 | } |
| 481 | |
Dianne Hackborn | 48e7b45 | 2011-01-17 12:28:35 -0800 | [diff] [blame] | 482 | final FragmentTransaction trans = mActivity.getFragmentManager().beginTransaction() |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 483 | .disallowAddToBackStack(); |
Adam Powell | 7f9b905 | 2010-10-19 16:56:07 -0700 | [diff] [blame] | 484 | |
| 485 | if (mSelectedTab == tab) { |
| 486 | if (mSelectedTab != null) { |
| 487 | mSelectedTab.getCallback().onTabReselected(mSelectedTab, trans); |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 488 | mTabScrollView.animateToTab(tab.getPosition()); |
Adam Powell | 7f9b905 | 2010-10-19 16:56:07 -0700 | [diff] [blame] | 489 | } |
| 490 | } else { |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 491 | mTabScrollView.setTabSelected(tab != null ? tab.getPosition() : Tab.INVALID_POSITION); |
Adam Powell | 7f9b905 | 2010-10-19 16:56:07 -0700 | [diff] [blame] | 492 | if (mSelectedTab != null) { |
| 493 | mSelectedTab.getCallback().onTabUnselected(mSelectedTab, trans); |
| 494 | } |
| 495 | mSelectedTab = (TabImpl) tab; |
| 496 | if (mSelectedTab != null) { |
| 497 | mSelectedTab.getCallback().onTabSelected(mSelectedTab, trans); |
| 498 | } |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | if (!trans.isEmpty()) { |
| 502 | trans.commit(); |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | @Override |
| 507 | public Tab getSelectedTab() { |
| 508 | return mSelectedTab; |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 509 | } |
| 510 | |
Adam Powell | 6b336f8 | 2010-08-10 20:13:01 -0700 | [diff] [blame] | 511 | @Override |
| 512 | public int getHeight() { |
Adam Powell | 58c5dc1 | 2011-07-14 21:08:10 -0700 | [diff] [blame] | 513 | return mContainerView.getHeight(); |
Adam Powell | 6b336f8 | 2010-08-10 20:13:01 -0700 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | @Override |
| 517 | public void show() { |
Adam Powell | 07e1f98 | 2011-03-24 11:11:15 -0700 | [diff] [blame] | 518 | show(true); |
| 519 | } |
| 520 | |
| 521 | void show(boolean markHiddenBeforeMode) { |
| 522 | if (mCurrentShowAnim != null) { |
| 523 | mCurrentShowAnim.end(); |
Adam Powell | 45f1e08 | 2010-12-10 14:20:13 -0800 | [diff] [blame] | 524 | } |
Adam Powell | d76cee2 | 2011-01-31 15:05:05 -0800 | [diff] [blame] | 525 | if (mContainerView.getVisibility() == View.VISIBLE) { |
Adam Powell | 07e1f98 | 2011-03-24 11:11:15 -0700 | [diff] [blame] | 526 | if (markHiddenBeforeMode) mWasHiddenBeforeMode = false; |
Adam Powell | d76cee2 | 2011-01-31 15:05:05 -0800 | [diff] [blame] | 527 | return; |
| 528 | } |
Adam Powell | d8b3f2e | 2010-12-02 13:37:03 -0800 | [diff] [blame] | 529 | mContainerView.setVisibility(View.VISIBLE); |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 530 | |
| 531 | if (mShowHideAnimationEnabled) { |
| 532 | mContainerView.setAlpha(0); |
| 533 | AnimatorSet anim = new AnimatorSet(); |
| 534 | AnimatorSet.Builder b = anim.play(ObjectAnimator.ofFloat(mContainerView, "alpha", 1)); |
| 535 | if (mContentView != null) { |
| 536 | b.with(ObjectAnimator.ofFloat(mContentView, "translationY", |
| 537 | -mContainerView.getHeight(), 0)); |
| 538 | mContainerView.setTranslationY(-mContainerView.getHeight()); |
| 539 | b.with(ObjectAnimator.ofFloat(mContainerView, "translationY", 0)); |
| 540 | } |
Adam Powell | 1ab418a | 2011-06-09 20:49:49 -0700 | [diff] [blame] | 541 | if (mSplitView != null && mContextDisplayMode == CONTEXT_DISPLAY_SPLIT) { |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 542 | mSplitView.setAlpha(0); |
| 543 | b.with(ObjectAnimator.ofFloat(mSplitView, "alpha", 1)); |
| 544 | } |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 545 | anim.addListener(mShowListener); |
Adam Powell | 07e1f98 | 2011-03-24 11:11:15 -0700 | [diff] [blame] | 546 | mCurrentShowAnim = anim; |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 547 | anim.start(); |
| 548 | } else { |
Adam Powell | d814504 | 2011-03-24 14:18:27 -0700 | [diff] [blame] | 549 | mContainerView.setAlpha(1); |
| 550 | mContainerView.setTranslationY(0); |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 551 | mShowListener.onAnimationEnd(null); |
Adam Powell | e6ec732 | 2010-12-07 15:29:26 -0800 | [diff] [blame] | 552 | } |
Adam Powell | 6b336f8 | 2010-08-10 20:13:01 -0700 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | @Override |
| 556 | public void hide() { |
Adam Powell | 07e1f98 | 2011-03-24 11:11:15 -0700 | [diff] [blame] | 557 | if (mCurrentShowAnim != null) { |
| 558 | mCurrentShowAnim.end(); |
Adam Powell | e6ec732 | 2010-12-07 15:29:26 -0800 | [diff] [blame] | 559 | } |
| 560 | if (mContainerView.getVisibility() == View.GONE) { |
| 561 | return; |
| 562 | } |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 563 | |
| 564 | if (mShowHideAnimationEnabled) { |
| 565 | mContainerView.setAlpha(1); |
Adam Powell | 01feaee | 2011-02-10 15:05:05 -0800 | [diff] [blame] | 566 | mContainerView.setTransitioning(true); |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 567 | AnimatorSet anim = new AnimatorSet(); |
| 568 | AnimatorSet.Builder b = anim.play(ObjectAnimator.ofFloat(mContainerView, "alpha", 0)); |
| 569 | if (mContentView != null) { |
| 570 | b.with(ObjectAnimator.ofFloat(mContentView, "translationY", |
| 571 | 0, -mContainerView.getHeight())); |
| 572 | b.with(ObjectAnimator.ofFloat(mContainerView, "translationY", |
| 573 | -mContainerView.getHeight())); |
| 574 | } |
Adam Powell | 1ab418a | 2011-06-09 20:49:49 -0700 | [diff] [blame] | 575 | if (mSplitView != null && mSplitView.getVisibility() == View.VISIBLE) { |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 576 | mSplitView.setAlpha(1); |
| 577 | b.with(ObjectAnimator.ofFloat(mSplitView, "alpha", 0)); |
| 578 | } |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 579 | anim.addListener(mHideListener); |
Adam Powell | 07e1f98 | 2011-03-24 11:11:15 -0700 | [diff] [blame] | 580 | mCurrentShowAnim = anim; |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 581 | anim.start(); |
| 582 | } else { |
| 583 | mHideListener.onAnimationEnd(null); |
Adam Powell | e6ec732 | 2010-12-07 15:29:26 -0800 | [diff] [blame] | 584 | } |
Adam Powell | 6b336f8 | 2010-08-10 20:13:01 -0700 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | public boolean isShowing() { |
Adam Powell | d8b3f2e | 2010-12-02 13:37:03 -0800 | [diff] [blame] | 588 | return mContainerView.getVisibility() == View.VISIBLE; |
| 589 | } |
| 590 | |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 591 | void animateToMode(boolean toActionMode) { |
Adam Powell | 060e3ca | 2011-07-19 20:39:16 -0700 | [diff] [blame] | 592 | if (toActionMode) { |
| 593 | show(false); |
| 594 | } |
Adam Powell | 07e1f98 | 2011-03-24 11:11:15 -0700 | [diff] [blame] | 595 | if (mCurrentModeAnim != null) { |
| 596 | mCurrentModeAnim.end(); |
| 597 | } |
Adam Powell | d8b3f2e | 2010-12-02 13:37:03 -0800 | [diff] [blame] | 598 | |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 599 | mActionView.animateToVisibility(toActionMode ? View.GONE : View.VISIBLE); |
| 600 | mContextView.animateToVisibility(toActionMode ? View.VISIBLE : View.GONE); |
Adam Powell | f6ce6a9 | 2011-06-29 10:25:01 -0700 | [diff] [blame] | 601 | if (mTabScrollView != null && !mActionView.hasEmbeddedTabs() && mActionView.isCollapsed()) { |
| 602 | mTabScrollView.animateToVisibility(toActionMode ? View.GONE : View.VISIBLE); |
| 603 | } |
Adam Powell | 6b336f8 | 2010-08-10 20:13:01 -0700 | [diff] [blame] | 604 | } |
| 605 | |
Adam Powell | 88ab697 | 2011-07-28 11:25:01 -0700 | [diff] [blame] | 606 | public Context getThemedContext() { |
| 607 | if (mThemedContext == null) { |
| 608 | TypedValue outValue = new TypedValue(); |
| 609 | Resources.Theme currentTheme = mContext.getTheme(); |
| 610 | currentTheme.resolveAttribute(com.android.internal.R.attr.actionBarWidgetTheme, |
| 611 | outValue, true); |
| 612 | final int targetThemeRes = outValue.resourceId; |
| 613 | |
| 614 | if (targetThemeRes != 0 && mContext.getThemeResId() != targetThemeRes) { |
| 615 | mThemedContext = new ContextThemeWrapper(mContext, targetThemeRes); |
| 616 | } else { |
| 617 | mThemedContext = mContext; |
| 618 | } |
| 619 | } |
| 620 | return mThemedContext; |
| 621 | } |
| 622 | |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 623 | /** |
| 624 | * @hide |
| 625 | */ |
Adam Powell | 5d27977 | 2010-07-27 16:34:07 -0700 | [diff] [blame] | 626 | public class ActionModeImpl extends ActionMode implements MenuBuilder.Callback { |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 627 | private ActionMode.Callback mCallback; |
Adam Powell | 2c9c9fe | 2010-07-16 10:17:57 -0700 | [diff] [blame] | 628 | private MenuBuilder mMenu; |
Adam Powell | 29ed757 | 2010-07-14 16:24:56 -0700 | [diff] [blame] | 629 | private WeakReference<View> mCustomView; |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 630 | |
Adam Powell | 5d27977 | 2010-07-27 16:34:07 -0700 | [diff] [blame] | 631 | public ActionModeImpl(ActionMode.Callback callback) { |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 632 | mCallback = callback; |
Adam Powell | f242368 | 2011-08-11 14:29:45 -0700 | [diff] [blame^] | 633 | mMenu = new MenuBuilder(getThemedContext()) |
Adam Powell | 4d9861e | 2010-08-17 11:14:40 -0700 | [diff] [blame] | 634 | .setDefaultShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); |
Adam Powell | 2c9c9fe | 2010-07-16 10:17:57 -0700 | [diff] [blame] | 635 | mMenu.setCallback(this); |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 636 | } |
Adam Powell | 9168f0b | 2010-08-02 15:46:24 -0700 | [diff] [blame] | 637 | |
| 638 | @Override |
| 639 | public MenuInflater getMenuInflater() { |
Adam Powell | f242368 | 2011-08-11 14:29:45 -0700 | [diff] [blame^] | 640 | return new MenuInflater(getThemedContext()); |
Adam Powell | 9168f0b | 2010-08-02 15:46:24 -0700 | [diff] [blame] | 641 | } |
| 642 | |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 643 | @Override |
| 644 | public Menu getMenu() { |
| 645 | return mMenu; |
| 646 | } |
| 647 | |
| 648 | @Override |
| 649 | public void finish() { |
Adam Powell | 5d27977 | 2010-07-27 16:34:07 -0700 | [diff] [blame] | 650 | if (mActionMode != this) { |
| 651 | // Not the active action mode - no-op |
Adam Powell | 93b6bc3 | 2010-07-22 11:36:35 -0700 | [diff] [blame] | 652 | return; |
| 653 | } |
| 654 | |
Adam Powell | 060e3ca | 2011-07-19 20:39:16 -0700 | [diff] [blame] | 655 | // If we were hidden before the mode was shown, defer the onDestroy |
| 656 | // callback until the animation is finished and associated relayout |
| 657 | // is about to happen. This lets apps better anticipate visibility |
| 658 | // and layout behavior. |
| 659 | if (mWasHiddenBeforeMode) { |
| 660 | mDeferredDestroyActionMode = this; |
| 661 | mDeferredModeDestroyCallback = mCallback; |
| 662 | } else { |
| 663 | mCallback.onDestroyActionMode(this); |
| 664 | } |
Adam Powell | d8b3f2e | 2010-12-02 13:37:03 -0800 | [diff] [blame] | 665 | mCallback = null; |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 666 | animateToMode(false); |
Adam Powell | 0e94b51 | 2010-06-29 17:58:20 -0700 | [diff] [blame] | 667 | |
| 668 | // Clear out the context mode views after the animation finishes |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 669 | mContextView.closeMode(); |
Adam Powell | f6ce6a9 | 2011-06-29 10:25:01 -0700 | [diff] [blame] | 670 | |
Adam Powell | 5d27977 | 2010-07-27 16:34:07 -0700 | [diff] [blame] | 671 | mActionMode = null; |
Adam Powell | 07e1f98 | 2011-03-24 11:11:15 -0700 | [diff] [blame] | 672 | |
| 673 | if (mWasHiddenBeforeMode) { |
| 674 | hide(); |
| 675 | } |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | @Override |
| 679 | public void invalidate() { |
Adam Powell | 5ee36c4 | 2011-06-02 12:59:43 -0700 | [diff] [blame] | 680 | mMenu.stopDispatchingItemsChanged(); |
| 681 | try { |
| 682 | mCallback.onPrepareActionMode(this, mMenu); |
| 683 | } finally { |
| 684 | mMenu.startDispatchingItemsChanged(); |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | public boolean dispatchOnCreate() { |
| 689 | mMenu.stopDispatchingItemsChanged(); |
| 690 | try { |
| 691 | return mCallback.onCreateActionMode(this, mMenu); |
| 692 | } finally { |
| 693 | mMenu.startDispatchingItemsChanged(); |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 694 | } |
| 695 | } |
| 696 | |
| 697 | @Override |
| 698 | public void setCustomView(View view) { |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 699 | mContextView.setCustomView(view); |
Adam Powell | 29ed757 | 2010-07-14 16:24:56 -0700 | [diff] [blame] | 700 | mCustomView = new WeakReference<View>(view); |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | @Override |
| 704 | public void setSubtitle(CharSequence subtitle) { |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 705 | mContextView.setSubtitle(subtitle); |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | @Override |
| 709 | public void setTitle(CharSequence title) { |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 710 | mContextView.setTitle(title); |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 711 | } |
Adam Powell | 29ed757 | 2010-07-14 16:24:56 -0700 | [diff] [blame] | 712 | |
| 713 | @Override |
Adam Powell | c9ae2a2 | 2010-07-28 14:44:21 -0700 | [diff] [blame] | 714 | public void setTitle(int resId) { |
Adam Powell | 48e8ac3 | 2011-01-14 12:10:24 -0800 | [diff] [blame] | 715 | setTitle(mContext.getResources().getString(resId)); |
Adam Powell | c9ae2a2 | 2010-07-28 14:44:21 -0700 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | @Override |
| 719 | public void setSubtitle(int resId) { |
Adam Powell | 48e8ac3 | 2011-01-14 12:10:24 -0800 | [diff] [blame] | 720 | setSubtitle(mContext.getResources().getString(resId)); |
Adam Powell | c9ae2a2 | 2010-07-28 14:44:21 -0700 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | @Override |
Adam Powell | 29ed757 | 2010-07-14 16:24:56 -0700 | [diff] [blame] | 724 | public CharSequence getTitle() { |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 725 | return mContextView.getTitle(); |
Adam Powell | 29ed757 | 2010-07-14 16:24:56 -0700 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | @Override |
| 729 | public CharSequence getSubtitle() { |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 730 | return mContextView.getSubtitle(); |
Adam Powell | 29ed757 | 2010-07-14 16:24:56 -0700 | [diff] [blame] | 731 | } |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 732 | |
Adam Powell | 29ed757 | 2010-07-14 16:24:56 -0700 | [diff] [blame] | 733 | @Override |
| 734 | public View getCustomView() { |
| 735 | return mCustomView != null ? mCustomView.get() : null; |
| 736 | } |
| 737 | |
Adam Powell | 2c9c9fe | 2010-07-16 10:17:57 -0700 | [diff] [blame] | 738 | public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) { |
Adam Powell | d8b3f2e | 2010-12-02 13:37:03 -0800 | [diff] [blame] | 739 | if (mCallback != null) { |
| 740 | return mCallback.onActionItemClicked(this, item); |
| 741 | } else { |
| 742 | return false; |
| 743 | } |
Adam Powell | 2c9c9fe | 2010-07-16 10:17:57 -0700 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) { |
| 747 | } |
| 748 | |
| 749 | public boolean onSubMenuSelected(SubMenuBuilder subMenu) { |
Adam Powell | d8b3f2e | 2010-12-02 13:37:03 -0800 | [diff] [blame] | 750 | if (mCallback == null) { |
| 751 | return false; |
| 752 | } |
| 753 | |
Adam Powell | 2c9c9fe | 2010-07-16 10:17:57 -0700 | [diff] [blame] | 754 | if (!subMenu.hasVisibleItems()) { |
| 755 | return true; |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 756 | } |
Adam Powell | 2c9c9fe | 2010-07-16 10:17:57 -0700 | [diff] [blame] | 757 | |
Adam Powell | f242368 | 2011-08-11 14:29:45 -0700 | [diff] [blame^] | 758 | new MenuPopupHelper(getThemedContext(), subMenu).show(); |
Adam Powell | 2c9c9fe | 2010-07-16 10:17:57 -0700 | [diff] [blame] | 759 | return true; |
| 760 | } |
| 761 | |
| 762 | public void onCloseSubMenu(SubMenuBuilder menu) { |
| 763 | } |
| 764 | |
| 765 | public void onMenuModeChange(MenuBuilder menu) { |
Adam Powell | d8b3f2e | 2010-12-02 13:37:03 -0800 | [diff] [blame] | 766 | if (mCallback == null) { |
| 767 | return; |
| 768 | } |
Adam Powell | f6148c5 | 2010-08-11 21:10:16 -0700 | [diff] [blame] | 769 | invalidate(); |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 770 | mContextView.showOverflowMenu(); |
Adam Powell | 2c9c9fe | 2010-07-16 10:17:57 -0700 | [diff] [blame] | 771 | } |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | /** |
| 775 | * @hide |
| 776 | */ |
| 777 | public class TabImpl extends ActionBar.Tab { |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 778 | private ActionBar.TabListener mCallback; |
| 779 | private Object mTag; |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 780 | private Drawable mIcon; |
| 781 | private CharSequence mText; |
Adam Powell | 0d8ec1d | 2011-05-03 14:49:13 -0700 | [diff] [blame] | 782 | private int mPosition = -1; |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 783 | private View mCustomView; |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 784 | |
| 785 | @Override |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 786 | public Object getTag() { |
| 787 | return mTag; |
| 788 | } |
| 789 | |
| 790 | @Override |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 791 | public Tab setTag(Object tag) { |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 792 | mTag = tag; |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 793 | return this; |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | public ActionBar.TabListener getCallback() { |
| 797 | return mCallback; |
| 798 | } |
| 799 | |
| 800 | @Override |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 801 | public Tab setTabListener(ActionBar.TabListener callback) { |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 802 | mCallback = callback; |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 803 | return this; |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | @Override |
| 807 | public View getCustomView() { |
| 808 | return mCustomView; |
| 809 | } |
| 810 | |
| 811 | @Override |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 812 | public Tab setCustomView(View view) { |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 813 | mCustomView = view; |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 814 | if (mPosition >= 0) { |
| 815 | mTabScrollView.updateTab(mPosition); |
| 816 | } |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 817 | return this; |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | @Override |
Adam Powell | 32555f3 | 2010-11-17 13:49:22 -0800 | [diff] [blame] | 821 | public Tab setCustomView(int layoutResId) { |
Adam Powell | f242368 | 2011-08-11 14:29:45 -0700 | [diff] [blame^] | 822 | return setCustomView(LayoutInflater.from(getThemedContext()) |
| 823 | .inflate(layoutResId, null)); |
Adam Powell | 32555f3 | 2010-11-17 13:49:22 -0800 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | @Override |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 827 | public Drawable getIcon() { |
| 828 | return mIcon; |
| 829 | } |
| 830 | |
| 831 | @Override |
| 832 | public int getPosition() { |
| 833 | return mPosition; |
| 834 | } |
| 835 | |
| 836 | public void setPosition(int position) { |
| 837 | mPosition = position; |
| 838 | } |
| 839 | |
| 840 | @Override |
| 841 | public CharSequence getText() { |
| 842 | return mText; |
| 843 | } |
| 844 | |
| 845 | @Override |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 846 | public Tab setIcon(Drawable icon) { |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 847 | mIcon = icon; |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 848 | if (mPosition >= 0) { |
| 849 | mTabScrollView.updateTab(mPosition); |
| 850 | } |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 851 | return this; |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | @Override |
Adam Powell | 32555f3 | 2010-11-17 13:49:22 -0800 | [diff] [blame] | 855 | public Tab setIcon(int resId) { |
| 856 | return setIcon(mContext.getResources().getDrawable(resId)); |
| 857 | } |
| 858 | |
| 859 | @Override |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 860 | public Tab setText(CharSequence text) { |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 861 | mText = text; |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 862 | if (mPosition >= 0) { |
| 863 | mTabScrollView.updateTab(mPosition); |
| 864 | } |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 865 | return this; |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | @Override |
Adam Powell | 32555f3 | 2010-11-17 13:49:22 -0800 | [diff] [blame] | 869 | public Tab setText(int resId) { |
| 870 | return setText(mContext.getResources().getText(resId)); |
| 871 | } |
| 872 | |
| 873 | @Override |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 874 | public void select() { |
| 875 | selectTab(this); |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 876 | } |
| 877 | } |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 878 | |
| 879 | @Override |
| 880 | public void setCustomView(View view) { |
| 881 | mActionView.setCustomNavigationView(view); |
| 882 | } |
| 883 | |
| 884 | @Override |
| 885 | public void setCustomView(View view, LayoutParams layoutParams) { |
| 886 | view.setLayoutParams(layoutParams); |
| 887 | mActionView.setCustomNavigationView(view); |
| 888 | } |
| 889 | |
| 890 | @Override |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 891 | public void setListNavigationCallbacks(SpinnerAdapter adapter, OnNavigationListener callback) { |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 892 | mActionView.setDropdownAdapter(adapter); |
| 893 | mActionView.setCallback(callback); |
| 894 | } |
| 895 | |
| 896 | @Override |
| 897 | public int getSelectedNavigationIndex() { |
| 898 | switch (mActionView.getNavigationMode()) { |
| 899 | case NAVIGATION_MODE_TABS: |
Adam Powell | 0458796 | 2010-11-11 22:15:07 -0800 | [diff] [blame] | 900 | return mSelectedTab != null ? mSelectedTab.getPosition() : -1; |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 901 | case NAVIGATION_MODE_LIST: |
| 902 | return mActionView.getDropdownSelectedPosition(); |
| 903 | default: |
| 904 | return -1; |
| 905 | } |
| 906 | } |
| 907 | |
| 908 | @Override |
| 909 | public int getNavigationItemCount() { |
| 910 | switch (mActionView.getNavigationMode()) { |
| 911 | case NAVIGATION_MODE_TABS: |
| 912 | return mTabs.size(); |
| 913 | case NAVIGATION_MODE_LIST: |
| 914 | SpinnerAdapter adapter = mActionView.getDropdownAdapter(); |
| 915 | return adapter != null ? adapter.getCount() : 0; |
| 916 | default: |
| 917 | return 0; |
| 918 | } |
| 919 | } |
| 920 | |
| 921 | @Override |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 922 | public int getTabCount() { |
| 923 | return mTabs.size(); |
| 924 | } |
| 925 | |
| 926 | @Override |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 927 | public void setNavigationMode(int mode) { |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 928 | final int oldMode = mActionView.getNavigationMode(); |
| 929 | switch (oldMode) { |
| 930 | case NAVIGATION_MODE_TABS: |
| 931 | mSavedTabPosition = getSelectedNavigationIndex(); |
| 932 | selectTab(null); |
Adam Powell | f5645cb | 2011-08-10 22:49:02 -0700 | [diff] [blame] | 933 | mTabScrollView.setVisibility(View.GONE); |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 934 | break; |
| 935 | } |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 936 | mActionView.setNavigationMode(mode); |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 937 | switch (mode) { |
| 938 | case NAVIGATION_MODE_TABS: |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 939 | ensureTabsExist(); |
Adam Powell | f5645cb | 2011-08-10 22:49:02 -0700 | [diff] [blame] | 940 | mTabScrollView.setVisibility(View.VISIBLE); |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 941 | if (mSavedTabPosition != INVALID_POSITION) { |
| 942 | setSelectedNavigationItem(mSavedTabPosition); |
| 943 | mSavedTabPosition = INVALID_POSITION; |
| 944 | } |
| 945 | break; |
| 946 | } |
Adam Powell | d21aa12 | 2011-05-27 13:09:52 -0700 | [diff] [blame] | 947 | mActionView.setCollapsable(mode == NAVIGATION_MODE_TABS && !mHasEmbeddedTabs); |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | @Override |
| 951 | public Tab getTabAt(int index) { |
| 952 | return mTabs.get(index); |
| 953 | } |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 954 | |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 955 | |
Adam Powell | 1969b87 | 2011-03-22 11:52:48 -0700 | [diff] [blame] | 956 | @Override |
| 957 | public void setIcon(int resId) { |
Adam Powell | 45c515b | 2011-04-21 18:50:20 -0700 | [diff] [blame] | 958 | mActionView.setIcon(resId); |
Adam Powell | 1969b87 | 2011-03-22 11:52:48 -0700 | [diff] [blame] | 959 | } |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 960 | |
Adam Powell | 1969b87 | 2011-03-22 11:52:48 -0700 | [diff] [blame] | 961 | @Override |
| 962 | public void setIcon(Drawable icon) { |
| 963 | mActionView.setIcon(icon); |
| 964 | } |
| 965 | |
| 966 | @Override |
| 967 | public void setLogo(int resId) { |
Adam Powell | 45c515b | 2011-04-21 18:50:20 -0700 | [diff] [blame] | 968 | mActionView.setLogo(resId); |
Adam Powell | 1969b87 | 2011-03-22 11:52:48 -0700 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | @Override |
| 972 | public void setLogo(Drawable logo) { |
| 973 | mActionView.setLogo(logo); |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 974 | } |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 975 | } |