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