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