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