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