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 | |
George Mount | e180337 | 2014-02-26 19:00:52 +0000 | [diff] [blame] | 365 | public void captureSharedElements(Map<String, View> sharedElements) { |
| 366 | mContainerView.findSharedElements(sharedElements); |
| 367 | } |
| 368 | |
Adam Powell | 1780977 | 2010-07-21 13:25:11 -0700 | [diff] [blame] | 369 | public void setSelectedNavigationItem(int position) { |
| 370 | switch (mActionView.getNavigationMode()) { |
| 371 | case NAVIGATION_MODE_TABS: |
| 372 | selectTab(mTabs.get(position)); |
| 373 | break; |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 374 | case NAVIGATION_MODE_LIST: |
Adam Powell | 1780977 | 2010-07-21 13:25:11 -0700 | [diff] [blame] | 375 | mActionView.setDropdownSelectedPosition(position); |
| 376 | break; |
| 377 | default: |
| 378 | throw new IllegalStateException( |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 379 | "setSelectedNavigationIndex not valid for current navigation mode"); |
Adam Powell | 1780977 | 2010-07-21 13:25:11 -0700 | [diff] [blame] | 380 | } |
| 381 | } |
| 382 | |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 383 | public void removeAllTabs() { |
| 384 | cleanupTabs(); |
Adam Powell | 1780977 | 2010-07-21 13:25:11 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 387 | private void cleanupTabs() { |
| 388 | if (mSelectedTab != null) { |
| 389 | selectTab(null); |
| 390 | } |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 391 | mTabs.clear(); |
Adam Powell | d21aa12 | 2011-05-27 13:09:52 -0700 | [diff] [blame] | 392 | if (mTabScrollView != null) { |
| 393 | mTabScrollView.removeAllTabs(); |
| 394 | } |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 395 | mSavedTabPosition = INVALID_POSITION; |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 396 | } |
| 397 | |
Adam Powell | 0e94b51 | 2010-06-29 17:58:20 -0700 | [diff] [blame] | 398 | public void setTitle(CharSequence title) { |
| 399 | mActionView.setTitle(title); |
| 400 | } |
| 401 | |
| 402 | public void setSubtitle(CharSequence subtitle) { |
| 403 | mActionView.setSubtitle(subtitle); |
| 404 | } |
| 405 | |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 406 | public void setDisplayOptions(int options) { |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 407 | if ((options & DISPLAY_HOME_AS_UP) != 0) { |
| 408 | mDisplayHomeAsUpSet = true; |
| 409 | } |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 410 | mActionView.setDisplayOptions(options); |
| 411 | } |
Adam Powell | 0e94b51 | 2010-06-29 17:58:20 -0700 | [diff] [blame] | 412 | |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 413 | public void setDisplayOptions(int options, int mask) { |
| 414 | final int current = mActionView.getDisplayOptions(); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 415 | if ((mask & DISPLAY_HOME_AS_UP) != 0) { |
| 416 | mDisplayHomeAsUpSet = true; |
| 417 | } |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 418 | mActionView.setDisplayOptions((options & mask) | (current & ~mask)); |
| 419 | } |
| 420 | |
| 421 | public void setBackgroundDrawable(Drawable d) { |
Adam Powell | f88b915 | 2011-09-07 14:54:32 -0700 | [diff] [blame] | 422 | mContainerView.setPrimaryBackground(d); |
| 423 | } |
| 424 | |
| 425 | public void setStackedBackgroundDrawable(Drawable d) { |
| 426 | mContainerView.setStackedBackground(d); |
| 427 | } |
| 428 | |
| 429 | public void setSplitBackgroundDrawable(Drawable d) { |
| 430 | if (mSplitView != null) { |
| 431 | mSplitView.setSplitBackground(d); |
| 432 | } |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 433 | } |
| 434 | |
Adam Powell | ef70444 | 2010-11-16 14:48:22 -0800 | [diff] [blame] | 435 | public View getCustomView() { |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 436 | return mActionView.getCustomNavigationView(); |
| 437 | } |
| 438 | |
| 439 | public CharSequence getTitle() { |
| 440 | return mActionView.getTitle(); |
| 441 | } |
| 442 | |
| 443 | public CharSequence getSubtitle() { |
| 444 | return mActionView.getSubtitle(); |
| 445 | } |
| 446 | |
| 447 | public int getNavigationMode() { |
| 448 | return mActionView.getNavigationMode(); |
| 449 | } |
| 450 | |
| 451 | public int getDisplayOptions() { |
| 452 | return mActionView.getDisplayOptions(); |
| 453 | } |
| 454 | |
Adam Powell | 5d27977 | 2010-07-27 16:34:07 -0700 | [diff] [blame] | 455 | public ActionMode startActionMode(ActionMode.Callback callback) { |
| 456 | if (mActionMode != null) { |
| 457 | mActionMode.finish(); |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 458 | } |
Adam Powell | 3461b32 | 2010-07-14 11:34:43 -0700 | [diff] [blame] | 459 | |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 460 | mContextView.killMode(); |
Adam Powell | 5ee36c4 | 2011-06-02 12:59:43 -0700 | [diff] [blame] | 461 | ActionModeImpl mode = new ActionModeImpl(callback); |
| 462 | if (mode.dispatchOnCreate()) { |
Adam Powell | 2c9c9fe | 2010-07-16 10:17:57 -0700 | [diff] [blame] | 463 | mode.invalidate(); |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 464 | mContextView.initForMode(mode); |
| 465 | animateToMode(true); |
Adam Powell | 1ab418a | 2011-06-09 20:49:49 -0700 | [diff] [blame] | 466 | if (mSplitView != null && mContextDisplayMode == CONTEXT_DISPLAY_SPLIT) { |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 467 | // TODO animate this |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 468 | if (mSplitView.getVisibility() != View.VISIBLE) { |
| 469 | mSplitView.setVisibility(View.VISIBLE); |
| 470 | if (mOverlayLayout != null) { |
| 471 | mOverlayLayout.requestFitSystemWindows(); |
| 472 | } |
| 473 | } |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 474 | } |
Adam Powell | 86ed436 | 2011-09-14 16:18:53 -0700 | [diff] [blame] | 475 | mContextView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
Adam Powell | 5d27977 | 2010-07-27 16:34:07 -0700 | [diff] [blame] | 476 | mActionMode = mode; |
Adam Powell | ac695c6 | 2010-07-20 18:19:27 -0700 | [diff] [blame] | 477 | return mode; |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 478 | } |
Adam Powell | ac695c6 | 2010-07-20 18:19:27 -0700 | [diff] [blame] | 479 | return null; |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 480 | } |
| 481 | |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 482 | private void configureTab(Tab tab, int position) { |
| 483 | final TabImpl tabi = (TabImpl) tab; |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 484 | final ActionBar.TabListener callback = tabi.getCallback(); |
| 485 | |
| 486 | if (callback == null) { |
| 487 | throw new IllegalStateException("Action Bar Tab must have a Callback"); |
| 488 | } |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 489 | |
| 490 | tabi.setPosition(position); |
| 491 | mTabs.add(position, tabi); |
| 492 | |
Adam Powell | 81b8944 | 2010-11-02 17:58:56 -0700 | [diff] [blame] | 493 | final int count = mTabs.size(); |
| 494 | for (int i = position + 1; i < count; i++) { |
| 495 | mTabs.get(i).setPosition(i); |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 496 | } |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | @Override |
| 500 | public void addTab(Tab tab) { |
Adam Powell | 81b8944 | 2010-11-02 17:58:56 -0700 | [diff] [blame] | 501 | addTab(tab, mTabs.isEmpty()); |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | @Override |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 505 | public void addTab(Tab tab, int position) { |
Adam Powell | 81b8944 | 2010-11-02 17:58:56 -0700 | [diff] [blame] | 506 | addTab(tab, position, mTabs.isEmpty()); |
| 507 | } |
| 508 | |
| 509 | @Override |
| 510 | public void addTab(Tab tab, boolean setSelected) { |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 511 | ensureTabsExist(); |
| 512 | mTabScrollView.addTab(tab, setSelected); |
Adam Powell | 81b8944 | 2010-11-02 17:58:56 -0700 | [diff] [blame] | 513 | configureTab(tab, mTabs.size()); |
| 514 | if (setSelected) { |
| 515 | selectTab(tab); |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | @Override |
| 520 | public void addTab(Tab tab, int position, boolean setSelected) { |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 521 | ensureTabsExist(); |
| 522 | mTabScrollView.addTab(tab, position, setSelected); |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 523 | configureTab(tab, position); |
Adam Powell | 81b8944 | 2010-11-02 17:58:56 -0700 | [diff] [blame] | 524 | if (setSelected) { |
| 525 | selectTab(tab); |
| 526 | } |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | @Override |
| 530 | public Tab newTab() { |
| 531 | return new TabImpl(); |
| 532 | } |
| 533 | |
| 534 | @Override |
| 535 | public void removeTab(Tab tab) { |
| 536 | removeTabAt(tab.getPosition()); |
| 537 | } |
| 538 | |
| 539 | @Override |
| 540 | public void removeTabAt(int position) { |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 541 | if (mTabScrollView == null) { |
| 542 | // No tabs around to remove |
| 543 | return; |
| 544 | } |
| 545 | |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 546 | int selectedTabPosition = mSelectedTab != null |
| 547 | ? mSelectedTab.getPosition() : mSavedTabPosition; |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 548 | mTabScrollView.removeTabAt(position); |
Adam Powell | 0d8ec1d | 2011-05-03 14:49:13 -0700 | [diff] [blame] | 549 | TabImpl removedTab = mTabs.remove(position); |
| 550 | if (removedTab != null) { |
| 551 | removedTab.setPosition(-1); |
| 552 | } |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 553 | |
| 554 | final int newTabCount = mTabs.size(); |
| 555 | for (int i = position; i < newTabCount; i++) { |
| 556 | mTabs.get(i).setPosition(i); |
| 557 | } |
| 558 | |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 559 | if (selectedTabPosition == position) { |
| 560 | selectTab(mTabs.isEmpty() ? null : mTabs.get(Math.max(0, position - 1))); |
| 561 | } |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | @Override |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 565 | public void selectTab(Tab tab) { |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 566 | if (getNavigationMode() != NAVIGATION_MODE_TABS) { |
| 567 | mSavedTabPosition = tab != null ? tab.getPosition() : INVALID_POSITION; |
| 568 | return; |
| 569 | } |
| 570 | |
Deepanshu Gupta | 14bf0ce | 2013-12-12 12:16:24 -0800 | [diff] [blame^] | 571 | final FragmentTransaction trans = mActionView.isInEditMode() ? null : |
| 572 | mActivity.getFragmentManager().beginTransaction().disallowAddToBackStack(); |
Adam Powell | 7f9b905 | 2010-10-19 16:56:07 -0700 | [diff] [blame] | 573 | |
| 574 | if (mSelectedTab == tab) { |
| 575 | if (mSelectedTab != null) { |
| 576 | mSelectedTab.getCallback().onTabReselected(mSelectedTab, trans); |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 577 | mTabScrollView.animateToTab(tab.getPosition()); |
Adam Powell | 7f9b905 | 2010-10-19 16:56:07 -0700 | [diff] [blame] | 578 | } |
| 579 | } else { |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 580 | mTabScrollView.setTabSelected(tab != null ? tab.getPosition() : Tab.INVALID_POSITION); |
Adam Powell | 7f9b905 | 2010-10-19 16:56:07 -0700 | [diff] [blame] | 581 | if (mSelectedTab != null) { |
| 582 | mSelectedTab.getCallback().onTabUnselected(mSelectedTab, trans); |
| 583 | } |
| 584 | mSelectedTab = (TabImpl) tab; |
| 585 | if (mSelectedTab != null) { |
| 586 | mSelectedTab.getCallback().onTabSelected(mSelectedTab, trans); |
| 587 | } |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 588 | } |
| 589 | |
Deepanshu Gupta | 14bf0ce | 2013-12-12 12:16:24 -0800 | [diff] [blame^] | 590 | if (trans != null && !trans.isEmpty()) { |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 591 | trans.commit(); |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | @Override |
| 596 | public Tab getSelectedTab() { |
| 597 | return mSelectedTab; |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 598 | } |
| 599 | |
Adam Powell | 6b336f8 | 2010-08-10 20:13:01 -0700 | [diff] [blame] | 600 | @Override |
| 601 | public int getHeight() { |
Adam Powell | 58c5dc1 | 2011-07-14 21:08:10 -0700 | [diff] [blame] | 602 | return mContainerView.getHeight(); |
Adam Powell | 6b336f8 | 2010-08-10 20:13:01 -0700 | [diff] [blame] | 603 | } |
| 604 | |
Dianne Hackborn | df7221c | 2013-02-26 14:53:55 -0800 | [diff] [blame] | 605 | public void enableContentAnimations(boolean enabled) { |
| 606 | mContentAnimations = enabled; |
| 607 | } |
| 608 | |
Adam Powell | 6b336f8 | 2010-08-10 20:13:01 -0700 | [diff] [blame] | 609 | @Override |
| 610 | public void show() { |
Dianne Hackborn | 139e5aa | 2012-05-05 20:36:38 -0700 | [diff] [blame] | 611 | if (mHiddenByApp) { |
| 612 | mHiddenByApp = false; |
| 613 | updateVisibility(false); |
| 614 | } |
Adam Powell | 07e1f98 | 2011-03-24 11:11:15 -0700 | [diff] [blame] | 615 | } |
| 616 | |
Dianne Hackborn | 139e5aa | 2012-05-05 20:36:38 -0700 | [diff] [blame] | 617 | private void showForActionMode() { |
| 618 | if (!mShowingForMode) { |
| 619 | mShowingForMode = true; |
| 620 | if (mOverlayLayout != null) { |
| 621 | mOverlayLayout.setShowingForActionMode(true); |
| 622 | } |
| 623 | updateVisibility(false); |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | public void showForSystem() { |
| 628 | if (mHiddenBySystem) { |
| 629 | mHiddenBySystem = false; |
| 630 | updateVisibility(true); |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | @Override |
| 635 | public void hide() { |
| 636 | if (!mHiddenByApp) { |
| 637 | mHiddenByApp = true; |
| 638 | updateVisibility(false); |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | private void hideForActionMode() { |
| 643 | if (mShowingForMode) { |
| 644 | mShowingForMode = false; |
| 645 | if (mOverlayLayout != null) { |
| 646 | mOverlayLayout.setShowingForActionMode(false); |
| 647 | } |
| 648 | updateVisibility(false); |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | public void hideForSystem() { |
| 653 | if (!mHiddenBySystem) { |
| 654 | mHiddenBySystem = true; |
| 655 | updateVisibility(true); |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | private static boolean checkShowingFlags(boolean hiddenByApp, boolean hiddenBySystem, |
| 660 | boolean showingForMode) { |
| 661 | if (showingForMode) { |
| 662 | return true; |
| 663 | } else if (hiddenByApp || hiddenBySystem) { |
| 664 | return false; |
| 665 | } else { |
| 666 | return true; |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | private void updateVisibility(boolean fromSystem) { |
| 671 | // Based on the current state, should we be hidden or shown? |
| 672 | final boolean shown = checkShowingFlags(mHiddenByApp, mHiddenBySystem, |
| 673 | mShowingForMode); |
| 674 | |
| 675 | if (shown) { |
| 676 | if (!mNowShowing) { |
| 677 | mNowShowing = true; |
| 678 | doShow(fromSystem); |
| 679 | } |
| 680 | } else { |
| 681 | if (mNowShowing) { |
| 682 | mNowShowing = false; |
| 683 | doHide(fromSystem); |
| 684 | } |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | public void doShow(boolean fromSystem) { |
Adam Powell | 07e1f98 | 2011-03-24 11:11:15 -0700 | [diff] [blame] | 689 | if (mCurrentShowAnim != null) { |
| 690 | mCurrentShowAnim.end(); |
Adam Powell | 45f1e08 | 2010-12-10 14:20:13 -0800 | [diff] [blame] | 691 | } |
Adam Powell | 9b0dc28 | 2013-07-31 13:58:43 -0700 | [diff] [blame] | 692 | mContainerView.setVisibility(View.VISIBLE); |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 693 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 694 | if (mCurWindowVisibility == View.VISIBLE && (mShowHideAnimationEnabled |
Dianne Hackborn | 139e5aa | 2012-05-05 20:36:38 -0700 | [diff] [blame] | 695 | || fromSystem)) { |
Adam Powell | 9b0dc28 | 2013-07-31 13:58:43 -0700 | [diff] [blame] | 696 | mContainerView.setTranslationY(0); // because we're about to ask its window loc |
| 697 | float startingY = -mContainerView.getHeight(); |
Chet Haase | e8118e1 | 2012-05-30 14:19:02 -0700 | [diff] [blame] | 698 | if (fromSystem) { |
| 699 | int topLeft[] = {0, 0}; |
Adam Powell | 9b0dc28 | 2013-07-31 13:58:43 -0700 | [diff] [blame] | 700 | mContainerView.getLocationInWindow(topLeft); |
Chet Haase | e8118e1 | 2012-05-30 14:19:02 -0700 | [diff] [blame] | 701 | startingY -= topLeft[1]; |
| 702 | } |
Adam Powell | 9b0dc28 | 2013-07-31 13:58:43 -0700 | [diff] [blame] | 703 | mContainerView.setTranslationY(startingY); |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 704 | AnimatorSet anim = new AnimatorSet(); |
Adam Powell | 9b0dc28 | 2013-07-31 13:58:43 -0700 | [diff] [blame] | 705 | ObjectAnimator a = ObjectAnimator.ofFloat(mContainerView, View.TRANSLATION_Y, 0); |
| 706 | a.addUpdateListener(mUpdateListener); |
| 707 | AnimatorSet.Builder b = anim.play(a); |
Dianne Hackborn | df7221c | 2013-02-26 14:53:55 -0800 | [diff] [blame] | 708 | if (mContentAnimations && mContentView != null) { |
Adam Powell | 9b0dc28 | 2013-07-31 13:58:43 -0700 | [diff] [blame] | 709 | b.with(ObjectAnimator.ofFloat(mContentView, View.TRANSLATION_Y, |
Chet Haase | e8118e1 | 2012-05-30 14:19:02 -0700 | [diff] [blame] | 710 | startingY, 0)); |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 711 | } |
Adam Powell | 1ab418a | 2011-06-09 20:49:49 -0700 | [diff] [blame] | 712 | if (mSplitView != null && mContextDisplayMode == CONTEXT_DISPLAY_SPLIT) { |
Dianne Hackborn | 8eedb8b | 2012-04-16 19:31:58 -0700 | [diff] [blame] | 713 | mSplitView.setTranslationY(mSplitView.getHeight()); |
Adam Powell | 993a63a | 2011-08-18 16:35:53 -0700 | [diff] [blame] | 714 | mSplitView.setVisibility(View.VISIBLE); |
Adam Powell | 9b0dc28 | 2013-07-31 13:58:43 -0700 | [diff] [blame] | 715 | b.with(ObjectAnimator.ofFloat(mSplitView, View.TRANSLATION_Y, 0)); |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 716 | } |
Dianne Hackborn | 8eedb8b | 2012-04-16 19:31:58 -0700 | [diff] [blame] | 717 | anim.setInterpolator(AnimationUtils.loadInterpolator(mContext, |
Chet Haase | e8118e1 | 2012-05-30 14:19:02 -0700 | [diff] [blame] | 718 | com.android.internal.R.interpolator.decelerate_cubic)); |
| 719 | anim.setDuration(250); |
Dianne Hackborn | 139e5aa | 2012-05-05 20:36:38 -0700 | [diff] [blame] | 720 | // If this is being shown from the system, add a small delay. |
| 721 | // This is because we will also be animating in the status bar, |
| 722 | // and these two elements can't be done in lock-step. So we give |
| 723 | // a little time for the status bar to start its animation before |
| 724 | // the action bar animates. (This corresponds to the corresponding |
| 725 | // case when hiding, where the status bar has a small delay before |
| 726 | // starting.) |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 727 | anim.addListener(mShowListener); |
Adam Powell | 07e1f98 | 2011-03-24 11:11:15 -0700 | [diff] [blame] | 728 | mCurrentShowAnim = anim; |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 729 | anim.start(); |
| 730 | } else { |
Adam Powell | 9b0dc28 | 2013-07-31 13:58:43 -0700 | [diff] [blame] | 731 | mContainerView.setAlpha(1); |
| 732 | mContainerView.setTranslationY(0); |
Dianne Hackborn | df7221c | 2013-02-26 14:53:55 -0800 | [diff] [blame] | 733 | if (mContentAnimations && mContentView != null) { |
Dianne Hackborn | 80d5506 | 2012-05-22 18:03:20 -0700 | [diff] [blame] | 734 | mContentView.setTranslationY(0); |
| 735 | } |
| 736 | if (mSplitView != null && mContextDisplayMode == CONTEXT_DISPLAY_SPLIT) { |
| 737 | mSplitView.setAlpha(1); |
| 738 | mSplitView.setTranslationY(0); |
| 739 | mSplitView.setVisibility(View.VISIBLE); |
| 740 | } |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 741 | mShowListener.onAnimationEnd(null); |
Adam Powell | e6ec732 | 2010-12-07 15:29:26 -0800 | [diff] [blame] | 742 | } |
Dianne Hackborn | 139e5aa | 2012-05-05 20:36:38 -0700 | [diff] [blame] | 743 | if (mOverlayLayout != null) { |
| 744 | mOverlayLayout.requestFitSystemWindows(); |
| 745 | } |
Adam Powell | 6b336f8 | 2010-08-10 20:13:01 -0700 | [diff] [blame] | 746 | } |
| 747 | |
Dianne Hackborn | 139e5aa | 2012-05-05 20:36:38 -0700 | [diff] [blame] | 748 | public void doHide(boolean fromSystem) { |
Adam Powell | 07e1f98 | 2011-03-24 11:11:15 -0700 | [diff] [blame] | 749 | if (mCurrentShowAnim != null) { |
| 750 | mCurrentShowAnim.end(); |
Adam Powell | e6ec732 | 2010-12-07 15:29:26 -0800 | [diff] [blame] | 751 | } |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 752 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 753 | if (mCurWindowVisibility == View.VISIBLE && (mShowHideAnimationEnabled |
Dianne Hackborn | 139e5aa | 2012-05-05 20:36:38 -0700 | [diff] [blame] | 754 | || fromSystem)) { |
Adam Powell | 9b0dc28 | 2013-07-31 13:58:43 -0700 | [diff] [blame] | 755 | mContainerView.setAlpha(1); |
Adam Powell | 01feaee | 2011-02-10 15:05:05 -0800 | [diff] [blame] | 756 | mContainerView.setTransitioning(true); |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 757 | AnimatorSet anim = new AnimatorSet(); |
Adam Powell | 9b0dc28 | 2013-07-31 13:58:43 -0700 | [diff] [blame] | 758 | float endingY = -mContainerView.getHeight(); |
Chet Haase | e8118e1 | 2012-05-30 14:19:02 -0700 | [diff] [blame] | 759 | if (fromSystem) { |
| 760 | int topLeft[] = {0, 0}; |
Adam Powell | 9b0dc28 | 2013-07-31 13:58:43 -0700 | [diff] [blame] | 761 | mContainerView.getLocationInWindow(topLeft); |
Chet Haase | e8118e1 | 2012-05-30 14:19:02 -0700 | [diff] [blame] | 762 | endingY -= topLeft[1]; |
| 763 | } |
Adam Powell | 9b0dc28 | 2013-07-31 13:58:43 -0700 | [diff] [blame] | 764 | ObjectAnimator a = ObjectAnimator.ofFloat(mContainerView, View.TRANSLATION_Y, endingY); |
| 765 | a.addUpdateListener(mUpdateListener); |
| 766 | AnimatorSet.Builder b = anim.play(a); |
Dianne Hackborn | df7221c | 2013-02-26 14:53:55 -0800 | [diff] [blame] | 767 | if (mContentAnimations && mContentView != null) { |
Adam Powell | 9b0dc28 | 2013-07-31 13:58:43 -0700 | [diff] [blame] | 768 | b.with(ObjectAnimator.ofFloat(mContentView, View.TRANSLATION_Y, |
Chet Haase | e8118e1 | 2012-05-30 14:19:02 -0700 | [diff] [blame] | 769 | 0, endingY)); |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 770 | } |
Adam Powell | 1ab418a | 2011-06-09 20:49:49 -0700 | [diff] [blame] | 771 | if (mSplitView != null && mSplitView.getVisibility() == View.VISIBLE) { |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 772 | mSplitView.setAlpha(1); |
Adam Powell | 9b0dc28 | 2013-07-31 13:58:43 -0700 | [diff] [blame] | 773 | b.with(ObjectAnimator.ofFloat(mSplitView, View.TRANSLATION_Y, |
Dianne Hackborn | 8eedb8b | 2012-04-16 19:31:58 -0700 | [diff] [blame] | 774 | mSplitView.getHeight())); |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 775 | } |
Dianne Hackborn | 8eedb8b | 2012-04-16 19:31:58 -0700 | [diff] [blame] | 776 | anim.setInterpolator(AnimationUtils.loadInterpolator(mContext, |
Chet Haase | e8118e1 | 2012-05-30 14:19:02 -0700 | [diff] [blame] | 777 | com.android.internal.R.interpolator.accelerate_cubic)); |
| 778 | anim.setDuration(250); |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 779 | anim.addListener(mHideListener); |
Adam Powell | 07e1f98 | 2011-03-24 11:11:15 -0700 | [diff] [blame] | 780 | mCurrentShowAnim = anim; |
Adam Powell | 50efbed | 2011-02-08 16:20:15 -0800 | [diff] [blame] | 781 | anim.start(); |
| 782 | } else { |
| 783 | mHideListener.onAnimationEnd(null); |
Adam Powell | e6ec732 | 2010-12-07 15:29:26 -0800 | [diff] [blame] | 784 | } |
Adam Powell | 6b336f8 | 2010-08-10 20:13:01 -0700 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | public boolean isShowing() { |
Dianne Hackborn | 139e5aa | 2012-05-05 20:36:38 -0700 | [diff] [blame] | 788 | return mNowShowing; |
| 789 | } |
| 790 | |
| 791 | public boolean isSystemShowing() { |
| 792 | return !mHiddenBySystem; |
Adam Powell | d8b3f2e | 2010-12-02 13:37:03 -0800 | [diff] [blame] | 793 | } |
| 794 | |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 795 | void animateToMode(boolean toActionMode) { |
Adam Powell | 060e3ca | 2011-07-19 20:39:16 -0700 | [diff] [blame] | 796 | if (toActionMode) { |
Dianne Hackborn | 139e5aa | 2012-05-05 20:36:38 -0700 | [diff] [blame] | 797 | showForActionMode(); |
| 798 | } else { |
| 799 | hideForActionMode(); |
Adam Powell | 07e1f98 | 2011-03-24 11:11:15 -0700 | [diff] [blame] | 800 | } |
Adam Powell | d8b3f2e | 2010-12-02 13:37:03 -0800 | [diff] [blame] | 801 | |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 802 | mActionView.animateToVisibility(toActionMode ? View.GONE : View.VISIBLE); |
| 803 | mContextView.animateToVisibility(toActionMode ? View.VISIBLE : View.GONE); |
Adam Powell | f6ce6a9 | 2011-06-29 10:25:01 -0700 | [diff] [blame] | 804 | if (mTabScrollView != null && !mActionView.hasEmbeddedTabs() && mActionView.isCollapsed()) { |
| 805 | mTabScrollView.animateToVisibility(toActionMode ? View.GONE : View.VISIBLE); |
| 806 | } |
Adam Powell | 6b336f8 | 2010-08-10 20:13:01 -0700 | [diff] [blame] | 807 | } |
| 808 | |
Adam Powell | 88ab697 | 2011-07-28 11:25:01 -0700 | [diff] [blame] | 809 | public Context getThemedContext() { |
| 810 | if (mThemedContext == null) { |
| 811 | TypedValue outValue = new TypedValue(); |
| 812 | Resources.Theme currentTheme = mContext.getTheme(); |
| 813 | currentTheme.resolveAttribute(com.android.internal.R.attr.actionBarWidgetTheme, |
| 814 | outValue, true); |
| 815 | final int targetThemeRes = outValue.resourceId; |
| 816 | |
| 817 | if (targetThemeRes != 0 && mContext.getThemeResId() != targetThemeRes) { |
| 818 | mThemedContext = new ContextThemeWrapper(mContext, targetThemeRes); |
| 819 | } else { |
| 820 | mThemedContext = mContext; |
| 821 | } |
| 822 | } |
| 823 | return mThemedContext; |
| 824 | } |
| 825 | |
Adam Powell | 27cba38 | 2013-01-22 18:55:20 -0800 | [diff] [blame] | 826 | @Override |
| 827 | public boolean isTitleTruncated() { |
| 828 | return mActionView != null && mActionView.isTitleTruncated(); |
| 829 | } |
| 830 | |
Adam Powell | e0e2f4f | 2013-04-05 16:27:35 -0700 | [diff] [blame] | 831 | @Override |
| 832 | public void setHomeAsUpIndicator(Drawable indicator) { |
| 833 | mActionView.setHomeAsUpIndicator(indicator); |
| 834 | } |
| 835 | |
| 836 | @Override |
| 837 | public void setHomeAsUpIndicator(int resId) { |
| 838 | mActionView.setHomeAsUpIndicator(resId); |
| 839 | } |
| 840 | |
| 841 | @Override |
| 842 | public void setHomeActionContentDescription(CharSequence description) { |
| 843 | mActionView.setHomeActionContentDescription(description); |
| 844 | } |
| 845 | |
| 846 | @Override |
| 847 | public void setHomeActionContentDescription(int resId) { |
| 848 | mActionView.setHomeActionContentDescription(resId); |
| 849 | } |
| 850 | |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 851 | /** |
| 852 | * @hide |
| 853 | */ |
Adam Powell | 5d27977 | 2010-07-27 16:34:07 -0700 | [diff] [blame] | 854 | public class ActionModeImpl extends ActionMode implements MenuBuilder.Callback { |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 855 | private ActionMode.Callback mCallback; |
Adam Powell | 2c9c9fe | 2010-07-16 10:17:57 -0700 | [diff] [blame] | 856 | private MenuBuilder mMenu; |
Adam Powell | 29ed757 | 2010-07-14 16:24:56 -0700 | [diff] [blame] | 857 | private WeakReference<View> mCustomView; |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 858 | |
Adam Powell | 5d27977 | 2010-07-27 16:34:07 -0700 | [diff] [blame] | 859 | public ActionModeImpl(ActionMode.Callback callback) { |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 860 | mCallback = callback; |
Adam Powell | f242368 | 2011-08-11 14:29:45 -0700 | [diff] [blame] | 861 | mMenu = new MenuBuilder(getThemedContext()) |
Adam Powell | 4d9861e | 2010-08-17 11:14:40 -0700 | [diff] [blame] | 862 | .setDefaultShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); |
Adam Powell | 2c9c9fe | 2010-07-16 10:17:57 -0700 | [diff] [blame] | 863 | mMenu.setCallback(this); |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 864 | } |
Adam Powell | 9168f0b | 2010-08-02 15:46:24 -0700 | [diff] [blame] | 865 | |
| 866 | @Override |
| 867 | public MenuInflater getMenuInflater() { |
Adam Powell | f242368 | 2011-08-11 14:29:45 -0700 | [diff] [blame] | 868 | return new MenuInflater(getThemedContext()); |
Adam Powell | 9168f0b | 2010-08-02 15:46:24 -0700 | [diff] [blame] | 869 | } |
| 870 | |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 871 | @Override |
| 872 | public Menu getMenu() { |
| 873 | return mMenu; |
| 874 | } |
| 875 | |
| 876 | @Override |
| 877 | public void finish() { |
Adam Powell | 5d27977 | 2010-07-27 16:34:07 -0700 | [diff] [blame] | 878 | if (mActionMode != this) { |
| 879 | // Not the active action mode - no-op |
Adam Powell | 93b6bc3 | 2010-07-22 11:36:35 -0700 | [diff] [blame] | 880 | return; |
| 881 | } |
| 882 | |
Dianne Hackborn | 139e5aa | 2012-05-05 20:36:38 -0700 | [diff] [blame] | 883 | // If this change in state is going to cause the action bar |
| 884 | // to be hidden, defer the onDestroy callback until the animation |
| 885 | // is finished and associated relayout is about to happen. This lets |
| 886 | // apps better anticipate visibility and layout behavior. |
| 887 | if (!checkShowingFlags(mHiddenByApp, mHiddenBySystem, false)) { |
| 888 | // With the current state but the action bar hidden, our |
| 889 | // overall showing state is going to be false. |
Adam Powell | 060e3ca | 2011-07-19 20:39:16 -0700 | [diff] [blame] | 890 | mDeferredDestroyActionMode = this; |
| 891 | mDeferredModeDestroyCallback = mCallback; |
| 892 | } else { |
| 893 | mCallback.onDestroyActionMode(this); |
| 894 | } |
Adam Powell | d8b3f2e | 2010-12-02 13:37:03 -0800 | [diff] [blame] | 895 | mCallback = null; |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 896 | animateToMode(false); |
Adam Powell | 0e94b51 | 2010-06-29 17:58:20 -0700 | [diff] [blame] | 897 | |
| 898 | // Clear out the context mode views after the animation finishes |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 899 | mContextView.closeMode(); |
Adam Powell | 86ed436 | 2011-09-14 16:18:53 -0700 | [diff] [blame] | 900 | mActionView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
Adam Powell | f6ce6a9 | 2011-06-29 10:25:01 -0700 | [diff] [blame] | 901 | |
Adam Powell | 5d27977 | 2010-07-27 16:34:07 -0700 | [diff] [blame] | 902 | mActionMode = null; |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | @Override |
| 906 | public void invalidate() { |
Adam Powell | 5ee36c4 | 2011-06-02 12:59:43 -0700 | [diff] [blame] | 907 | mMenu.stopDispatchingItemsChanged(); |
| 908 | try { |
| 909 | mCallback.onPrepareActionMode(this, mMenu); |
| 910 | } finally { |
| 911 | mMenu.startDispatchingItemsChanged(); |
| 912 | } |
| 913 | } |
| 914 | |
| 915 | public boolean dispatchOnCreate() { |
| 916 | mMenu.stopDispatchingItemsChanged(); |
| 917 | try { |
| 918 | return mCallback.onCreateActionMode(this, mMenu); |
| 919 | } finally { |
| 920 | mMenu.startDispatchingItemsChanged(); |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 921 | } |
| 922 | } |
| 923 | |
| 924 | @Override |
| 925 | public void setCustomView(View view) { |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 926 | mContextView.setCustomView(view); |
Adam Powell | 29ed757 | 2010-07-14 16:24:56 -0700 | [diff] [blame] | 927 | mCustomView = new WeakReference<View>(view); |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | @Override |
| 931 | public void setSubtitle(CharSequence subtitle) { |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 932 | mContextView.setSubtitle(subtitle); |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | @Override |
| 936 | public void setTitle(CharSequence title) { |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 937 | mContextView.setTitle(title); |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 938 | } |
Adam Powell | 29ed757 | 2010-07-14 16:24:56 -0700 | [diff] [blame] | 939 | |
| 940 | @Override |
Adam Powell | c9ae2a2 | 2010-07-28 14:44:21 -0700 | [diff] [blame] | 941 | public void setTitle(int resId) { |
Adam Powell | 48e8ac3 | 2011-01-14 12:10:24 -0800 | [diff] [blame] | 942 | setTitle(mContext.getResources().getString(resId)); |
Adam Powell | c9ae2a2 | 2010-07-28 14:44:21 -0700 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | @Override |
| 946 | public void setSubtitle(int resId) { |
Adam Powell | 48e8ac3 | 2011-01-14 12:10:24 -0800 | [diff] [blame] | 947 | setSubtitle(mContext.getResources().getString(resId)); |
Adam Powell | c9ae2a2 | 2010-07-28 14:44:21 -0700 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | @Override |
Adam Powell | 29ed757 | 2010-07-14 16:24:56 -0700 | [diff] [blame] | 951 | public CharSequence getTitle() { |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 952 | return mContextView.getTitle(); |
Adam Powell | 29ed757 | 2010-07-14 16:24:56 -0700 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | @Override |
| 956 | public CharSequence getSubtitle() { |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 957 | return mContextView.getSubtitle(); |
Adam Powell | 29ed757 | 2010-07-14 16:24:56 -0700 | [diff] [blame] | 958 | } |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 959 | |
Adam Powell | 29ed757 | 2010-07-14 16:24:56 -0700 | [diff] [blame] | 960 | @Override |
Adam Powell | b98a81f | 2012-02-24 11:09:07 -0800 | [diff] [blame] | 961 | public void setTitleOptionalHint(boolean titleOptional) { |
Adam Powell | 785c447 | 2012-05-02 21:25:39 -0700 | [diff] [blame] | 962 | super.setTitleOptionalHint(titleOptional); |
Adam Powell | b98a81f | 2012-02-24 11:09:07 -0800 | [diff] [blame] | 963 | mContextView.setTitleOptional(titleOptional); |
| 964 | } |
| 965 | |
| 966 | @Override |
| 967 | public boolean isTitleOptional() { |
| 968 | return mContextView.isTitleOptional(); |
| 969 | } |
| 970 | |
| 971 | @Override |
Adam Powell | 29ed757 | 2010-07-14 16:24:56 -0700 | [diff] [blame] | 972 | public View getCustomView() { |
| 973 | return mCustomView != null ? mCustomView.get() : null; |
| 974 | } |
| 975 | |
Adam Powell | 2c9c9fe | 2010-07-16 10:17:57 -0700 | [diff] [blame] | 976 | public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) { |
Adam Powell | d8b3f2e | 2010-12-02 13:37:03 -0800 | [diff] [blame] | 977 | if (mCallback != null) { |
| 978 | return mCallback.onActionItemClicked(this, item); |
| 979 | } else { |
| 980 | return false; |
| 981 | } |
Adam Powell | 2c9c9fe | 2010-07-16 10:17:57 -0700 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) { |
| 985 | } |
| 986 | |
| 987 | public boolean onSubMenuSelected(SubMenuBuilder subMenu) { |
Adam Powell | d8b3f2e | 2010-12-02 13:37:03 -0800 | [diff] [blame] | 988 | if (mCallback == null) { |
| 989 | return false; |
| 990 | } |
| 991 | |
Adam Powell | 2c9c9fe | 2010-07-16 10:17:57 -0700 | [diff] [blame] | 992 | if (!subMenu.hasVisibleItems()) { |
| 993 | return true; |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 994 | } |
Adam Powell | 2c9c9fe | 2010-07-16 10:17:57 -0700 | [diff] [blame] | 995 | |
Adam Powell | f242368 | 2011-08-11 14:29:45 -0700 | [diff] [blame] | 996 | new MenuPopupHelper(getThemedContext(), subMenu).show(); |
Adam Powell | 2c9c9fe | 2010-07-16 10:17:57 -0700 | [diff] [blame] | 997 | return true; |
| 998 | } |
| 999 | |
| 1000 | public void onCloseSubMenu(SubMenuBuilder menu) { |
| 1001 | } |
| 1002 | |
| 1003 | public void onMenuModeChange(MenuBuilder menu) { |
Adam Powell | d8b3f2e | 2010-12-02 13:37:03 -0800 | [diff] [blame] | 1004 | if (mCallback == null) { |
| 1005 | return; |
| 1006 | } |
Adam Powell | f6148c5 | 2010-08-11 21:10:16 -0700 | [diff] [blame] | 1007 | invalidate(); |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 1008 | mContextView.showOverflowMenu(); |
Adam Powell | 2c9c9fe | 2010-07-16 10:17:57 -0700 | [diff] [blame] | 1009 | } |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | /** |
| 1013 | * @hide |
| 1014 | */ |
| 1015 | public class TabImpl extends ActionBar.Tab { |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 1016 | private ActionBar.TabListener mCallback; |
| 1017 | private Object mTag; |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 1018 | private Drawable mIcon; |
| 1019 | private CharSequence mText; |
Adam Powell | 94e56ef | 2011-09-06 21:22:22 -0700 | [diff] [blame] | 1020 | private CharSequence mContentDesc; |
Adam Powell | 0d8ec1d | 2011-05-03 14:49:13 -0700 | [diff] [blame] | 1021 | private int mPosition = -1; |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 1022 | private View mCustomView; |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 1023 | |
| 1024 | @Override |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 1025 | public Object getTag() { |
| 1026 | return mTag; |
| 1027 | } |
| 1028 | |
| 1029 | @Override |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1030 | public Tab setTag(Object tag) { |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 1031 | mTag = tag; |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1032 | return this; |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | public ActionBar.TabListener getCallback() { |
| 1036 | return mCallback; |
| 1037 | } |
| 1038 | |
| 1039 | @Override |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1040 | public Tab setTabListener(ActionBar.TabListener callback) { |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 1041 | mCallback = callback; |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1042 | return this; |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | @Override |
| 1046 | public View getCustomView() { |
| 1047 | return mCustomView; |
| 1048 | } |
| 1049 | |
| 1050 | @Override |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1051 | public Tab setCustomView(View view) { |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 1052 | mCustomView = view; |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 1053 | if (mPosition >= 0) { |
| 1054 | mTabScrollView.updateTab(mPosition); |
| 1055 | } |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1056 | return this; |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | @Override |
Adam Powell | 32555f3 | 2010-11-17 13:49:22 -0800 | [diff] [blame] | 1060 | public Tab setCustomView(int layoutResId) { |
Adam Powell | f242368 | 2011-08-11 14:29:45 -0700 | [diff] [blame] | 1061 | return setCustomView(LayoutInflater.from(getThemedContext()) |
| 1062 | .inflate(layoutResId, null)); |
Adam Powell | 32555f3 | 2010-11-17 13:49:22 -0800 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | @Override |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 1066 | public Drawable getIcon() { |
| 1067 | return mIcon; |
| 1068 | } |
| 1069 | |
| 1070 | @Override |
| 1071 | public int getPosition() { |
| 1072 | return mPosition; |
| 1073 | } |
| 1074 | |
| 1075 | public void setPosition(int position) { |
| 1076 | mPosition = position; |
| 1077 | } |
| 1078 | |
| 1079 | @Override |
| 1080 | public CharSequence getText() { |
| 1081 | return mText; |
| 1082 | } |
| 1083 | |
| 1084 | @Override |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1085 | public Tab setIcon(Drawable icon) { |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 1086 | mIcon = icon; |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 1087 | if (mPosition >= 0) { |
| 1088 | mTabScrollView.updateTab(mPosition); |
| 1089 | } |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1090 | return this; |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | @Override |
Adam Powell | 32555f3 | 2010-11-17 13:49:22 -0800 | [diff] [blame] | 1094 | public Tab setIcon(int resId) { |
Alan Viverette | 8eea3ea | 2014-02-03 18:40:20 -0800 | [diff] [blame] | 1095 | return setIcon(mContext.getDrawable(resId)); |
Adam Powell | 32555f3 | 2010-11-17 13:49:22 -0800 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | @Override |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1099 | public Tab setText(CharSequence text) { |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 1100 | mText = text; |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 1101 | if (mPosition >= 0) { |
| 1102 | mTabScrollView.updateTab(mPosition); |
| 1103 | } |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1104 | return this; |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | @Override |
Adam Powell | 32555f3 | 2010-11-17 13:49:22 -0800 | [diff] [blame] | 1108 | public Tab setText(int resId) { |
| 1109 | return setText(mContext.getResources().getText(resId)); |
| 1110 | } |
| 1111 | |
| 1112 | @Override |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 1113 | public void select() { |
| 1114 | selectTab(this); |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 1115 | } |
Adam Powell | 94e56ef | 2011-09-06 21:22:22 -0700 | [diff] [blame] | 1116 | |
| 1117 | @Override |
| 1118 | public Tab setContentDescription(int resId) { |
| 1119 | return setContentDescription(mContext.getResources().getText(resId)); |
| 1120 | } |
| 1121 | |
| 1122 | @Override |
| 1123 | public Tab setContentDescription(CharSequence contentDesc) { |
| 1124 | mContentDesc = contentDesc; |
| 1125 | if (mPosition >= 0) { |
| 1126 | mTabScrollView.updateTab(mPosition); |
| 1127 | } |
| 1128 | return this; |
| 1129 | } |
| 1130 | |
| 1131 | @Override |
| 1132 | public CharSequence getContentDescription() { |
| 1133 | return mContentDesc; |
| 1134 | } |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 1135 | } |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1136 | |
| 1137 | @Override |
| 1138 | public void setCustomView(View view) { |
| 1139 | mActionView.setCustomNavigationView(view); |
| 1140 | } |
| 1141 | |
| 1142 | @Override |
| 1143 | public void setCustomView(View view, LayoutParams layoutParams) { |
| 1144 | view.setLayoutParams(layoutParams); |
| 1145 | mActionView.setCustomNavigationView(view); |
| 1146 | } |
| 1147 | |
| 1148 | @Override |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 1149 | public void setListNavigationCallbacks(SpinnerAdapter adapter, OnNavigationListener callback) { |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1150 | mActionView.setDropdownAdapter(adapter); |
| 1151 | mActionView.setCallback(callback); |
| 1152 | } |
| 1153 | |
| 1154 | @Override |
| 1155 | public int getSelectedNavigationIndex() { |
| 1156 | switch (mActionView.getNavigationMode()) { |
| 1157 | case NAVIGATION_MODE_TABS: |
Adam Powell | 0458796 | 2010-11-11 22:15:07 -0800 | [diff] [blame] | 1158 | return mSelectedTab != null ? mSelectedTab.getPosition() : -1; |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1159 | case NAVIGATION_MODE_LIST: |
| 1160 | return mActionView.getDropdownSelectedPosition(); |
| 1161 | default: |
| 1162 | return -1; |
| 1163 | } |
| 1164 | } |
| 1165 | |
| 1166 | @Override |
| 1167 | public int getNavigationItemCount() { |
| 1168 | switch (mActionView.getNavigationMode()) { |
| 1169 | case NAVIGATION_MODE_TABS: |
| 1170 | return mTabs.size(); |
| 1171 | case NAVIGATION_MODE_LIST: |
| 1172 | SpinnerAdapter adapter = mActionView.getDropdownAdapter(); |
| 1173 | return adapter != null ? adapter.getCount() : 0; |
| 1174 | default: |
| 1175 | return 0; |
| 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | @Override |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 1180 | public int getTabCount() { |
| 1181 | return mTabs.size(); |
| 1182 | } |
| 1183 | |
| 1184 | @Override |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1185 | public void setNavigationMode(int mode) { |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 1186 | final int oldMode = mActionView.getNavigationMode(); |
| 1187 | switch (oldMode) { |
| 1188 | case NAVIGATION_MODE_TABS: |
| 1189 | mSavedTabPosition = getSelectedNavigationIndex(); |
| 1190 | selectTab(null); |
Adam Powell | f5645cb | 2011-08-10 22:49:02 -0700 | [diff] [blame] | 1191 | mTabScrollView.setVisibility(View.GONE); |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 1192 | break; |
| 1193 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1194 | if (oldMode != mode && !mHasEmbeddedTabs) { |
| 1195 | if (mOverlayLayout != null) { |
| 1196 | mOverlayLayout.requestFitSystemWindows(); |
| 1197 | } |
| 1198 | } |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1199 | mActionView.setNavigationMode(mode); |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 1200 | switch (mode) { |
| 1201 | case NAVIGATION_MODE_TABS: |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 1202 | ensureTabsExist(); |
Adam Powell | f5645cb | 2011-08-10 22:49:02 -0700 | [diff] [blame] | 1203 | mTabScrollView.setVisibility(View.VISIBLE); |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 1204 | if (mSavedTabPosition != INVALID_POSITION) { |
| 1205 | setSelectedNavigationItem(mSavedTabPosition); |
| 1206 | mSavedTabPosition = INVALID_POSITION; |
| 1207 | } |
| 1208 | break; |
| 1209 | } |
Adam Powell | d21aa12 | 2011-05-27 13:09:52 -0700 | [diff] [blame] | 1210 | mActionView.setCollapsable(mode == NAVIGATION_MODE_TABS && !mHasEmbeddedTabs); |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | @Override |
| 1214 | public Tab getTabAt(int index) { |
| 1215 | return mTabs.get(index); |
| 1216 | } |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 1217 | |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 1218 | |
Adam Powell | 1969b87 | 2011-03-22 11:52:48 -0700 | [diff] [blame] | 1219 | @Override |
| 1220 | public void setIcon(int resId) { |
Adam Powell | 45c515b | 2011-04-21 18:50:20 -0700 | [diff] [blame] | 1221 | mActionView.setIcon(resId); |
Adam Powell | 1969b87 | 2011-03-22 11:52:48 -0700 | [diff] [blame] | 1222 | } |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 1223 | |
Adam Powell | 1969b87 | 2011-03-22 11:52:48 -0700 | [diff] [blame] | 1224 | @Override |
| 1225 | public void setIcon(Drawable icon) { |
| 1226 | mActionView.setIcon(icon); |
| 1227 | } |
| 1228 | |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 1229 | public boolean hasIcon() { |
| 1230 | return mActionView.hasIcon(); |
| 1231 | } |
| 1232 | |
Adam Powell | 1969b87 | 2011-03-22 11:52:48 -0700 | [diff] [blame] | 1233 | @Override |
| 1234 | public void setLogo(int resId) { |
Adam Powell | 45c515b | 2011-04-21 18:50:20 -0700 | [diff] [blame] | 1235 | mActionView.setLogo(resId); |
Adam Powell | 1969b87 | 2011-03-22 11:52:48 -0700 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | @Override |
| 1239 | public void setLogo(Drawable logo) { |
| 1240 | mActionView.setLogo(logo); |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 1241 | } |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 1242 | |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 1243 | public boolean hasLogo() { |
| 1244 | return mActionView.hasLogo(); |
| 1245 | } |
| 1246 | |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 1247 | public void setDefaultDisplayHomeAsUpEnabled(boolean enable) { |
| 1248 | if (!mDisplayHomeAsUpSet) { |
| 1249 | setDisplayHomeAsUpEnabled(enable); |
| 1250 | } |
| 1251 | } |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 1252 | } |