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