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