blob: d95f0e591e0e2612ba40c7fae424b74515c84483 [file] [log] [blame]
Adam Powell89e06452010-06-23 20:24:52 -07001/*
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
17package com.android.internal.app;
18
Adam Powell9b0dc282013-07-31 13:58:43 -070019import android.animation.ValueAnimator;
Adam Powellb36e4f92014-05-01 10:23:33 -070020import android.content.res.TypedArray;
Adam Powell9b0dc282013-07-31 13:58:43 -070021import android.view.ViewParent;
Adam Powelle021e6e2014-05-23 17:27:24 -070022import android.widget.Toolbar;
Adam Powellb36e4f92014-05-01 10:23:33 -070023import com.android.internal.R;
Adam Powellb8139af2012-04-19 13:52:46 -070024import com.android.internal.view.ActionBarPolicy;
Adam Powell2c9c9fe2010-07-16 10:17:57 -070025import com.android.internal.view.menu.MenuBuilder;
Adam Powell2c9c9fe2010-07-16 10:17:57 -070026import com.android.internal.view.menu.MenuPopupHelper;
27import com.android.internal.view.menu.SubMenuBuilder;
Adam Powell01feaee2011-02-10 15:05:05 -080028import com.android.internal.widget.ActionBarContainer;
Adam Powell89e06452010-06-23 20:24:52 -070029import com.android.internal.widget.ActionBarContextView;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -070030import com.android.internal.widget.ActionBarOverlayLayout;
Adam Powelle021e6e2014-05-23 17:27:24 -070031import com.android.internal.widget.DecorToolbar;
Adam Powellf8ac6b72011-05-23 18:14:09 -070032import com.android.internal.widget.ScrollingTabContainerView;
Adam Powell89e06452010-06-23 20:24:52 -070033
Adam Powelld8b3f2e2010-12-02 13:37:03 -080034import android.animation.Animator;
Adam Powelld8b3f2e2010-12-02 13:37:03 -080035import android.animation.Animator.AnimatorListener;
Adam Powell07e1f982011-03-24 11:11:15 -070036import android.animation.AnimatorListenerAdapter;
Adam Powelld8b3f2e2010-12-02 13:37:03 -080037import android.animation.AnimatorSet;
Adam Powelle6ec7322010-12-07 15:29:26 -080038import android.animation.ObjectAnimator;
Adam Powell89e06452010-06-23 20:24:52 -070039import android.app.ActionBar;
Adam Powell661c9082010-07-02 10:09:44 -070040import android.app.Activity;
Adam Powelldec9dfd2010-08-09 15:27:54 -070041import android.app.Dialog;
Adam Powell661c9082010-07-02 10:09:44 -070042import android.app.FragmentTransaction;
Adam Powelldec9dfd2010-08-09 15:27:54 -070043import android.content.Context;
Adam Powellf8ac6b72011-05-23 18:14:09 -070044import android.content.res.Configuration;
Adam Powell88ab6972011-07-28 11:25:01 -070045import android.content.res.Resources;
Adam Powell89e06452010-06-23 20:24:52 -070046import android.graphics.drawable.Drawable;
Adam Powell88ab6972011-07-28 11:25:01 -070047import android.util.TypedValue;
Adam Powell6e346362010-07-23 10:18:23 -070048import android.view.ActionMode;
Adam Powell88ab6972011-07-28 11:25:01 -070049import android.view.ContextThemeWrapper;
Adam Powell32555f32010-11-17 13:49:22 -080050import android.view.LayoutInflater;
Adam Powell89e06452010-06-23 20:24:52 -070051import android.view.Menu;
Adam Powell9168f0b2010-08-02 15:46:24 -070052import android.view.MenuInflater;
Adam Powell89e06452010-06-23 20:24:52 -070053import android.view.MenuItem;
54import android.view.View;
Adam Powelle6ec7322010-12-07 15:29:26 -080055import android.view.Window;
Adam Powell86ed4362011-09-14 16:18:53 -070056import android.view.accessibility.AccessibilityEvent;
Dianne Hackborn8eedb8b2012-04-16 19:31:58 -070057import android.view.animation.AnimationUtils;
Adam Powell89e06452010-06-23 20:24:52 -070058import android.widget.SpinnerAdapter;
Adam Powell89e06452010-06-23 20:24:52 -070059
Adam Powell29ed7572010-07-14 16:24:56 -070060import java.lang.ref.WeakReference;
Adam Powell661c9082010-07-02 10:09:44 -070061import java.util.ArrayList;
62
Adam Powell89e06452010-06-23 20:24:52 -070063/**
Adam Powelle43340c2014-03-17 19:10:43 -070064 * 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 Powell89e06452010-06-23 20:24:52 -070069 */
Adam Powellb36e4f92014-05-01 10:23:33 -070070public class WindowDecorActionBar extends ActionBar implements
71 ActionBarOverlayLayout.ActionBarVisibilityCallback {
Adam Powelle43340c2014-03-17 19:10:43 -070072 private static final String TAG = "WindowDecorActionBar";
Adam Powell661c9082010-07-02 10:09:44 -070073
Adam Powelldec9dfd2010-08-09 15:27:54 -070074 private Context mContext;
Adam Powell88ab6972011-07-28 11:25:01 -070075 private Context mThemedContext;
Adam Powell661c9082010-07-02 10:09:44 -070076 private Activity mActivity;
Adam Powelldec9dfd2010-08-09 15:27:54 -070077 private Dialog mDialog;
Adam Powell661c9082010-07-02 10:09:44 -070078
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -070079 private ActionBarOverlayLayout mOverlayLayout;
Adam Powell01feaee2011-02-10 15:05:05 -080080 private ActionBarContainer mContainerView;
Adam Powelle021e6e2014-05-23 17:27:24 -070081 private DecorToolbar mDecorToolbar;
Adam Powell640a66e2011-04-29 10:18:53 -070082 private ActionBarContextView mContextView;
83 private ActionBarContainer mSplitView;
Adam Powelle6ec7322010-12-07 15:29:26 -080084 private View mContentView;
Adam Powellf8ac6b72011-05-23 18:14:09 -070085 private ScrollingTabContainerView mTabScrollView;
Adam Powell661c9082010-07-02 10:09:44 -070086
87 private ArrayList<TabImpl> mTabs = new ArrayList<TabImpl>();
88
Adam Powell661c9082010-07-02 10:09:44 -070089 private TabImpl mSelectedTab;
Adam Powell0c24a552010-11-03 16:44:11 -070090 private int mSavedTabPosition = INVALID_POSITION;
Adam Powell89e06452010-06-23 20:24:52 -070091
Adam Powelldd8fab22012-03-22 17:47:27 -070092 private boolean mDisplayHomeAsUpSet;
93
Adam Powell060e3ca2011-07-19 20:39:16 -070094 ActionModeImpl mActionMode;
95 ActionMode mDeferredDestroyActionMode;
96 ActionMode.Callback mDeferredModeDestroyCallback;
Adam Powell89e06452010-06-23 20:24:52 -070097
Adam Powell8515ee82010-11-30 14:09:55 -080098 private boolean mLastMenuVisibility;
99 private ArrayList<OnMenuVisibilityListener> mMenuVisibilityListeners =
100 new ArrayList<OnMenuVisibilityListener>();
101
Adam Powell89e06452010-06-23 20:24:52 -0700102 private static final int CONTEXT_DISPLAY_NORMAL = 0;
103 private static final int CONTEXT_DISPLAY_SPLIT = 1;
104
Adam Powell0c24a552010-11-03 16:44:11 -0700105 private static final int INVALID_POSITION = -1;
106
Adam Powell89e06452010-06-23 20:24:52 -0700107 private int mContextDisplayMode;
Adam Powellf8ac6b72011-05-23 18:14:09 -0700108 private boolean mHasEmbeddedTabs;
Adam Powell0e94b512010-06-29 17:58:20 -0700109
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700110 private int mCurWindowVisibility = View.VISIBLE;
111
Dianne Hackborndf7221c2013-02-26 14:53:55 -0800112 private boolean mContentAnimations = true;
Dianne Hackborn139e5aa2012-05-05 20:36:38 -0700113 private boolean mHiddenByApp;
114 private boolean mHiddenBySystem;
115 private boolean mShowingForMode;
116
117 private boolean mNowShowing = true;
118
Adam Powell07e1f982011-03-24 11:11:15 -0700119 private Animator mCurrentShowAnim;
Adam Powell50efbed2011-02-08 16:20:15 -0800120 private boolean mShowHideAnimationEnabled;
Adam Powellb36e4f92014-05-01 10:23:33 -0700121 boolean mHideOnContentScroll;
Adam Powelld8b3f2e2010-12-02 13:37:03 -0800122
Adam Powell07e1f982011-03-24 11:11:15 -0700123 final AnimatorListener mHideListener = new AnimatorListenerAdapter() {
Adam Powelle6ec7322010-12-07 15:29:26 -0800124 @Override
125 public void onAnimationEnd(Animator animation) {
Dianne Hackborndf7221c2013-02-26 14:53:55 -0800126 if (mContentAnimations && mContentView != null) {
Adam Powelle6ec7322010-12-07 15:29:26 -0800127 mContentView.setTranslationY(0);
Adam Powell9b0dc282013-07-31 13:58:43 -0700128 mContainerView.setTranslationY(0);
Adam Powelle6ec7322010-12-07 15:29:26 -0800129 }
Adam Powell993a63a2011-08-18 16:35:53 -0700130 if (mSplitView != null && mContextDisplayMode == CONTEXT_DISPLAY_SPLIT) {
131 mSplitView.setVisibility(View.GONE);
132 }
Adam Powell9b0dc282013-07-31 13:58:43 -0700133 mContainerView.setVisibility(View.GONE);
Adam Powell01feaee2011-02-10 15:05:05 -0800134 mContainerView.setTransitioning(false);
Adam Powell07e1f982011-03-24 11:11:15 -0700135 mCurrentShowAnim = null;
Adam Powell060e3ca2011-07-19 20:39:16 -0700136 completeDeferredDestroyActionMode();
Dianne Hackborn139e5aa2012-05-05 20:36:38 -0700137 if (mOverlayLayout != null) {
Adam Powellb36e4f92014-05-01 10:23:33 -0700138 mOverlayLayout.requestApplyInsets();
Dianne Hackborn139e5aa2012-05-05 20:36:38 -0700139 }
Adam Powelle6ec7322010-12-07 15:29:26 -0800140 }
141 };
142
Adam Powell07e1f982011-03-24 11:11:15 -0700143 final AnimatorListener mShowListener = new AnimatorListenerAdapter() {
Adam Powelle6ec7322010-12-07 15:29:26 -0800144 @Override
145 public void onAnimationEnd(Animator animation) {
Adam Powell07e1f982011-03-24 11:11:15 -0700146 mCurrentShowAnim = null;
Adam Powell9b0dc282013-07-31 13:58:43 -0700147 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 Powelle6ec7322010-12-07 15:29:26 -0800157 }
Adam Powelle6ec7322010-12-07 15:29:26 -0800158 };
159
Adam Powelle43340c2014-03-17 19:10:43 -0700160 public WindowDecorActionBar(Activity activity) {
Adam Powell661c9082010-07-02 10:09:44 -0700161 mActivity = activity;
Adam Powelle6ec7322010-12-07 15:29:26 -0800162 Window window = activity.getWindow();
163 View decor = window.getDecorView();
Dianne Hackborndf7221c2013-02-26 14:53:55 -0800164 boolean overlayMode = mActivity.getWindow().hasFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
Adam Powell9b0dc282013-07-31 13:58:43 -0700165 init(decor);
Dianne Hackborndf7221c2013-02-26 14:53:55 -0800166 if (!overlayMode) {
Adam Powelle6ec7322010-12-07 15:29:26 -0800167 mContentView = decor.findViewById(android.R.id.content);
168 }
Adam Powelldec9dfd2010-08-09 15:27:54 -0700169 }
170
Adam Powelle43340c2014-03-17 19:10:43 -0700171 public WindowDecorActionBar(Dialog dialog) {
Adam Powelldec9dfd2010-08-09 15:27:54 -0700172 mDialog = dialog;
Adam Powell9b0dc282013-07-31 13:58:43 -0700173 init(dialog.getWindow().getDecorView());
Adam Powelldec9dfd2010-08-09 15:27:54 -0700174 }
175
Deepanshu Gupta14bf0ce2013-12-12 12:16:24 -0800176 /**
177 * Only for edit mode.
178 * @hide
179 */
180 public WindowDecorActionBar(View layout) {
181 assert layout.isInEditMode();
182 init(layout);
183 }
184
Adam Powell9b0dc282013-07-31 13:58:43 -0700185 private void init(View decor) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700186 mOverlayLayout = (ActionBarOverlayLayout) decor.findViewById(
Adam Powell4369e7d2014-05-17 14:16:08 -0700187 com.android.internal.R.id.decor_content_parent);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700188 if (mOverlayLayout != null) {
Adam Powellb36e4f92014-05-01 10:23:33 -0700189 mOverlayLayout.setActionBarVisibilityCallback(this);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700190 }
Adam Powelle021e6e2014-05-23 17:27:24 -0700191 mDecorToolbar = getDecorToolbar(decor.findViewById(com.android.internal.R.id.action_bar));
Adam Powell640a66e2011-04-29 10:18:53 -0700192 mContextView = (ActionBarContextView) decor.findViewById(
Adam Powell89e06452010-06-23 20:24:52 -0700193 com.android.internal.R.id.action_context_bar);
Adam Powell01feaee2011-02-10 15:05:05 -0800194 mContainerView = (ActionBarContainer) decor.findViewById(
Adam Powelld8b3f2e2010-12-02 13:37:03 -0800195 com.android.internal.R.id.action_bar_container);
Adam Powell640a66e2011-04-29 10:18:53 -0700196 mSplitView = (ActionBarContainer) decor.findViewById(
197 com.android.internal.R.id.split_action_bar);
Steve Block08f194b2010-08-24 18:20:48 +0100198
Adam Powelle021e6e2014-05-23 17:27:24 -0700199 if (mDecorToolbar == null || mContextView == null || mContainerView == null) {
Adam Powell89e06452010-06-23 20:24:52 -0700200 throw new IllegalStateException(getClass().getSimpleName() + " can only be used " +
201 "with a compatible window decor layout");
202 }
Adam Powell0e94b512010-06-29 17:58:20 -0700203
Adam Powelle021e6e2014-05-23 17:27:24 -0700204 mContext = mDecorToolbar.getContext();
205 mContextDisplayMode = mDecorToolbar.isSplit() ?
Adam Powell9b4bee02011-04-27 19:24:47 -0700206 CONTEXT_DISPLAY_SPLIT : CONTEXT_DISPLAY_NORMAL;
Adam Powelldae78242011-04-25 15:23:41 -0700207
Adam Powelld40423a2012-05-02 14:06:03 -0700208 // This was initially read from the action bar style
Adam Powelle021e6e2014-05-23 17:27:24 -0700209 final int current = mDecorToolbar.getDisplayOptions();
Adam Powelld40423a2012-05-02 14:06:03 -0700210 final boolean homeAsUp = (current & DISPLAY_HOME_AS_UP) != 0;
211 if (homeAsUp) {
212 mDisplayHomeAsUpSet = true;
213 }
214
Adam Powellb8139af2012-04-19 13:52:46 -0700215 ActionBarPolicy abp = ActionBarPolicy.get(mContext);
Adam Powelld40423a2012-05-02 14:06:03 -0700216 setHomeButtonEnabled(abp.enableHomeButtonByDefault() || homeAsUp);
Adam Powellb8139af2012-04-19 13:52:46 -0700217 setHasEmbeddedTabs(abp.hasEmbeddedTabs());
Adam Powellb36e4f92014-05-01 10:23:33 -0700218
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 Powell14d1fa42014-07-10 16:23:39 -0700225 final int elevation = a.getDimensionPixelSize(R.styleable.ActionBar_elevation, 0);
226 if (elevation != 0) {
227 setElevation(elevation);
228 }
Adam Powellb36e4f92014-05-01 10:23:33 -0700229 a.recycle();
Adam Powellf8ac6b72011-05-23 18:14:09 -0700230 }
231
Adam Powelle021e6e2014-05-23 17:27:24 -0700232 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 Powell14d1fa42014-07-10 16:23:39 -0700243 @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 Powellf8ac6b72011-05-23 18:14:09 -0700256 public void onConfigurationChanged(Configuration newConfig) {
Adam Powellb8139af2012-04-19 13:52:46 -0700257 setHasEmbeddedTabs(ActionBarPolicy.get(mContext).hasEmbeddedTabs());
Adam Powellf5645cb2011-08-10 22:49:02 -0700258 }
Adam Powellf8ac6b72011-05-23 18:14:09 -0700259
Adam Powellf5645cb2011-08-10 22:49:02 -0700260 private void setHasEmbeddedTabs(boolean hasEmbeddedTabs) {
261 mHasEmbeddedTabs = hasEmbeddedTabs;
Adam Powellf8ac6b72011-05-23 18:14:09 -0700262 // Switch tab layout configuration if needed
263 if (!mHasEmbeddedTabs) {
Adam Powelle021e6e2014-05-23 17:27:24 -0700264 mDecorToolbar.setEmbeddedTabView(null);
Adam Powellf8ac6b72011-05-23 18:14:09 -0700265 mContainerView.setTabContainer(mTabScrollView);
266 } else {
267 mContainerView.setTabContainer(null);
Adam Powelle021e6e2014-05-23 17:27:24 -0700268 mDecorToolbar.setEmbeddedTabView(mTabScrollView);
Adam Powellf8ac6b72011-05-23 18:14:09 -0700269 }
Adam Powellf5645cb2011-08-10 22:49:02 -0700270 final boolean isInTabMode = getNavigationMode() == NAVIGATION_MODE_TABS;
271 if (mTabScrollView != null) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700272 if (isInTabMode) {
273 mTabScrollView.setVisibility(View.VISIBLE);
274 if (mOverlayLayout != null) {
Adam Powellb36e4f92014-05-01 10:23:33 -0700275 mOverlayLayout.requestApplyInsets();
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700276 }
277 } else {
278 mTabScrollView.setVisibility(View.GONE);
279 }
Adam Powellf5645cb2011-08-10 22:49:02 -0700280 }
Adam Powelle021e6e2014-05-23 17:27:24 -0700281 mDecorToolbar.setCollapsible(!mHasEmbeddedTabs && isInTabMode);
Adam Powellb36e4f92014-05-01 10:23:33 -0700282 mOverlayLayout.setHasNonEmbeddedTabs(!mHasEmbeddedTabs && isInTabMode);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700283 }
284
Adam Powellf8ac6b72011-05-23 18:14:09 -0700285 private void ensureTabsExist() {
286 if (mTabScrollView != null) {
287 return;
288 }
289
Adam Powellf5645cb2011-08-10 22:49:02 -0700290 ScrollingTabContainerView tabScroller = new ScrollingTabContainerView(mContext);
Adam Powellf8ac6b72011-05-23 18:14:09 -0700291
292 if (mHasEmbeddedTabs) {
293 tabScroller.setVisibility(View.VISIBLE);
Adam Powelle021e6e2014-05-23 17:27:24 -0700294 mDecorToolbar.setEmbeddedTabView(tabScroller);
Adam Powellf8ac6b72011-05-23 18:14:09 -0700295 } else {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700296 if (getNavigationMode() == NAVIGATION_MODE_TABS) {
297 tabScroller.setVisibility(View.VISIBLE);
298 if (mOverlayLayout != null) {
Adam Powell76d8f962014-05-14 20:13:47 -0700299 mOverlayLayout.requestApplyInsets();
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700300 }
301 } else {
302 tabScroller.setVisibility(View.GONE);
303 }
Adam Powelldae78242011-04-25 15:23:41 -0700304 mContainerView.setTabContainer(tabScroller);
Adam Powelldae78242011-04-25 15:23:41 -0700305 }
Adam Powellf8ac6b72011-05-23 18:14:09 -0700306 mTabScrollView = tabScroller;
Adam Powell89e06452010-06-23 20:24:52 -0700307 }
308
Adam Powell060e3ca2011-07-19 20:39:16 -0700309 void completeDeferredDestroyActionMode() {
310 if (mDeferredModeDestroyCallback != null) {
311 mDeferredModeDestroyCallback.onDestroyActionMode(mDeferredDestroyActionMode);
312 mDeferredDestroyActionMode = null;
313 mDeferredModeDestroyCallback = null;
314 }
315 }
316
Adam Powellb36e4f92014-05-01 10:23:33 -0700317 public void onWindowVisibilityChanged(int visibility) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700318 mCurWindowVisibility = visibility;
319 }
320
Adam Powell50efbed2011-02-08 16:20:15 -0800321 /**
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 Powell07e1f982011-03-24 11:11:15 -0700330 if (!enabled && mCurrentShowAnim != null) {
331 mCurrentShowAnim.end();
Adam Powell50efbed2011-02-08 16:20:15 -0800332 }
333 }
334
Adam Powell8515ee82010-11-30 14:09:55 -0800335 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 Powella66c7b02010-07-28 15:28:25 -0700355 @Override
Adam Powell3f476b32011-01-03 19:25:36 -0800356 public void setCustomView(int resId) {
Adam Powelle021e6e2014-05-23 17:27:24 -0700357 setCustomView(LayoutInflater.from(getThemedContext()).inflate(resId,
Dan Sandler6fdeeb32014-05-29 11:02:41 -0400358 mDecorToolbar.getViewGroup(), false));
Adam Powell3f476b32011-01-03 19:25:36 -0800359 }
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 Powellc29f4e52011-07-13 20:40:52 -0700387 public void setHomeButtonEnabled(boolean enable) {
Adam Powelle021e6e2014-05-23 17:27:24 -0700388 mDecorToolbar.setHomeButtonEnabled(enable);
Adam Powelldae78242011-04-25 15:23:41 -0700389 }
390
391 @Override
Adam Powella66c7b02010-07-28 15:28:25 -0700392 public void setTitle(int resId) {
Adam Powelldec9dfd2010-08-09 15:27:54 -0700393 setTitle(mContext.getString(resId));
Adam Powella66c7b02010-07-28 15:28:25 -0700394 }
395
396 @Override
397 public void setSubtitle(int resId) {
Adam Powelldec9dfd2010-08-09 15:27:54 -0700398 setSubtitle(mContext.getString(resId));
Adam Powella66c7b02010-07-28 15:28:25 -0700399 }
400
Adam Powell17809772010-07-21 13:25:11 -0700401 public void setSelectedNavigationItem(int position) {
Adam Powelle021e6e2014-05-23 17:27:24 -0700402 switch (mDecorToolbar.getNavigationMode()) {
Adam Powell17809772010-07-21 13:25:11 -0700403 case NAVIGATION_MODE_TABS:
404 selectTab(mTabs.get(position));
405 break;
Adam Powell9ab97872010-10-26 21:47:29 -0700406 case NAVIGATION_MODE_LIST:
Adam Powelle021e6e2014-05-23 17:27:24 -0700407 mDecorToolbar.setDropdownSelectedPosition(position);
Adam Powell17809772010-07-21 13:25:11 -0700408 break;
409 default:
410 throw new IllegalStateException(
Adam Powell9ab97872010-10-26 21:47:29 -0700411 "setSelectedNavigationIndex not valid for current navigation mode");
Adam Powell17809772010-07-21 13:25:11 -0700412 }
413 }
414
Adam Powell9ab97872010-10-26 21:47:29 -0700415 public void removeAllTabs() {
416 cleanupTabs();
Adam Powell17809772010-07-21 13:25:11 -0700417 }
418
Adam Powell661c9082010-07-02 10:09:44 -0700419 private void cleanupTabs() {
420 if (mSelectedTab != null) {
421 selectTab(null);
422 }
Adam Powell2b6230e2010-09-07 17:55:25 -0700423 mTabs.clear();
Adam Powelld21aa122011-05-27 13:09:52 -0700424 if (mTabScrollView != null) {
425 mTabScrollView.removeAllTabs();
426 }
Adam Powell0c24a552010-11-03 16:44:11 -0700427 mSavedTabPosition = INVALID_POSITION;
Adam Powell661c9082010-07-02 10:09:44 -0700428 }
429
Adam Powell0e94b512010-06-29 17:58:20 -0700430 public void setTitle(CharSequence title) {
Adam Powelle021e6e2014-05-23 17:27:24 -0700431 mDecorToolbar.setTitle(title);
Adam Powell0e94b512010-06-29 17:58:20 -0700432 }
433
Adam Powellaf2d8592014-08-26 18:06:40 -0700434 @Override
435 public void setWindowTitle(CharSequence title) {
436 mDecorToolbar.setWindowTitle(title);
437 }
438
Adam Powell0e94b512010-06-29 17:58:20 -0700439 public void setSubtitle(CharSequence subtitle) {
Adam Powelle021e6e2014-05-23 17:27:24 -0700440 mDecorToolbar.setSubtitle(subtitle);
Adam Powell0e94b512010-06-29 17:58:20 -0700441 }
442
Adam Powell89e06452010-06-23 20:24:52 -0700443 public void setDisplayOptions(int options) {
Adam Powelldd8fab22012-03-22 17:47:27 -0700444 if ((options & DISPLAY_HOME_AS_UP) != 0) {
445 mDisplayHomeAsUpSet = true;
446 }
Adam Powelle021e6e2014-05-23 17:27:24 -0700447 mDecorToolbar.setDisplayOptions(options);
Adam Powell89e06452010-06-23 20:24:52 -0700448 }
Adam Powell0e94b512010-06-29 17:58:20 -0700449
Adam Powell89e06452010-06-23 20:24:52 -0700450 public void setDisplayOptions(int options, int mask) {
Adam Powelle021e6e2014-05-23 17:27:24 -0700451 final int current = mDecorToolbar.getDisplayOptions();
Adam Powelldd8fab22012-03-22 17:47:27 -0700452 if ((mask & DISPLAY_HOME_AS_UP) != 0) {
453 mDisplayHomeAsUpSet = true;
454 }
Adam Powelle021e6e2014-05-23 17:27:24 -0700455 mDecorToolbar.setDisplayOptions((options & mask) | (current & ~mask));
Adam Powell89e06452010-06-23 20:24:52 -0700456 }
457
458 public void setBackgroundDrawable(Drawable d) {
Adam Powellf88b9152011-09-07 14:54:32 -0700459 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 Powell89e06452010-06-23 20:24:52 -0700470 }
471
Adam Powellef704442010-11-16 14:48:22 -0800472 public View getCustomView() {
Adam Powelle021e6e2014-05-23 17:27:24 -0700473 return mDecorToolbar.getCustomView();
Adam Powell89e06452010-06-23 20:24:52 -0700474 }
475
476 public CharSequence getTitle() {
Adam Powelle021e6e2014-05-23 17:27:24 -0700477 return mDecorToolbar.getTitle();
Adam Powell89e06452010-06-23 20:24:52 -0700478 }
479
480 public CharSequence getSubtitle() {
Adam Powelle021e6e2014-05-23 17:27:24 -0700481 return mDecorToolbar.getSubtitle();
Adam Powell89e06452010-06-23 20:24:52 -0700482 }
483
484 public int getNavigationMode() {
Adam Powelle021e6e2014-05-23 17:27:24 -0700485 return mDecorToolbar.getNavigationMode();
Adam Powell89e06452010-06-23 20:24:52 -0700486 }
487
488 public int getDisplayOptions() {
Adam Powelle021e6e2014-05-23 17:27:24 -0700489 return mDecorToolbar.getDisplayOptions();
Adam Powell89e06452010-06-23 20:24:52 -0700490 }
491
Adam Powell5d279772010-07-27 16:34:07 -0700492 public ActionMode startActionMode(ActionMode.Callback callback) {
493 if (mActionMode != null) {
494 mActionMode.finish();
Adam Powell6e346362010-07-23 10:18:23 -0700495 }
Adam Powell3461b322010-07-14 11:34:43 -0700496
Adam Powellb36e4f92014-05-01 10:23:33 -0700497 mOverlayLayout.setHideOnContentScrollEnabled(false);
Adam Powell640a66e2011-04-29 10:18:53 -0700498 mContextView.killMode();
Alan Viverettef6a36e92014-10-28 17:50:59 -0700499 ActionModeImpl mode = new ActionModeImpl(mContextView.getContext(), callback);
Adam Powell5ee36c42011-06-02 12:59:43 -0700500 if (mode.dispatchOnCreate()) {
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700501 mode.invalidate();
Adam Powell640a66e2011-04-29 10:18:53 -0700502 mContextView.initForMode(mode);
503 animateToMode(true);
Adam Powell1ab418a2011-06-09 20:49:49 -0700504 if (mSplitView != null && mContextDisplayMode == CONTEXT_DISPLAY_SPLIT) {
Adam Powell89e06452010-06-23 20:24:52 -0700505 // TODO animate this
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700506 if (mSplitView.getVisibility() != View.VISIBLE) {
507 mSplitView.setVisibility(View.VISIBLE);
508 if (mOverlayLayout != null) {
Adam Powellb36e4f92014-05-01 10:23:33 -0700509 mOverlayLayout.requestApplyInsets();
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700510 }
511 }
Adam Powell89e06452010-06-23 20:24:52 -0700512 }
Adam Powell86ed4362011-09-14 16:18:53 -0700513 mContextView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Adam Powell5d279772010-07-27 16:34:07 -0700514 mActionMode = mode;
Adam Powellac695c62010-07-20 18:19:27 -0700515 return mode;
Adam Powell89e06452010-06-23 20:24:52 -0700516 }
Adam Powellac695c62010-07-20 18:19:27 -0700517 return null;
Adam Powell89e06452010-06-23 20:24:52 -0700518 }
519
Adam Powell661c9082010-07-02 10:09:44 -0700520 private void configureTab(Tab tab, int position) {
521 final TabImpl tabi = (TabImpl) tab;
Adam Powell2b6230e2010-09-07 17:55:25 -0700522 final ActionBar.TabListener callback = tabi.getCallback();
523
524 if (callback == null) {
525 throw new IllegalStateException("Action Bar Tab must have a Callback");
526 }
Adam Powell661c9082010-07-02 10:09:44 -0700527
528 tabi.setPosition(position);
529 mTabs.add(position, tabi);
530
Adam Powell81b89442010-11-02 17:58:56 -0700531 final int count = mTabs.size();
532 for (int i = position + 1; i < count; i++) {
533 mTabs.get(i).setPosition(i);
Adam Powell661c9082010-07-02 10:09:44 -0700534 }
Adam Powell661c9082010-07-02 10:09:44 -0700535 }
536
537 @Override
538 public void addTab(Tab tab) {
Adam Powell81b89442010-11-02 17:58:56 -0700539 addTab(tab, mTabs.isEmpty());
Adam Powell661c9082010-07-02 10:09:44 -0700540 }
541
542 @Override
Adam Powell2b6230e2010-09-07 17:55:25 -0700543 public void addTab(Tab tab, int position) {
Adam Powell81b89442010-11-02 17:58:56 -0700544 addTab(tab, position, mTabs.isEmpty());
545 }
546
547 @Override
548 public void addTab(Tab tab, boolean setSelected) {
Adam Powellf8ac6b72011-05-23 18:14:09 -0700549 ensureTabsExist();
550 mTabScrollView.addTab(tab, setSelected);
Adam Powell81b89442010-11-02 17:58:56 -0700551 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 Powellf8ac6b72011-05-23 18:14:09 -0700559 ensureTabsExist();
560 mTabScrollView.addTab(tab, position, setSelected);
Adam Powell661c9082010-07-02 10:09:44 -0700561 configureTab(tab, position);
Adam Powell81b89442010-11-02 17:58:56 -0700562 if (setSelected) {
563 selectTab(tab);
564 }
Adam Powell661c9082010-07-02 10:09:44 -0700565 }
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 Powellf8ac6b72011-05-23 18:14:09 -0700579 if (mTabScrollView == null) {
580 // No tabs around to remove
581 return;
582 }
583
Adam Powell0c24a552010-11-03 16:44:11 -0700584 int selectedTabPosition = mSelectedTab != null
585 ? mSelectedTab.getPosition() : mSavedTabPosition;
Adam Powellf8ac6b72011-05-23 18:14:09 -0700586 mTabScrollView.removeTabAt(position);
Adam Powell0d8ec1d2011-05-03 14:49:13 -0700587 TabImpl removedTab = mTabs.remove(position);
588 if (removedTab != null) {
589 removedTab.setPosition(-1);
590 }
Adam Powell661c9082010-07-02 10:09:44 -0700591
592 final int newTabCount = mTabs.size();
593 for (int i = position; i < newTabCount; i++) {
594 mTabs.get(i).setPosition(i);
595 }
596
Adam Powell0c24a552010-11-03 16:44:11 -0700597 if (selectedTabPosition == position) {
598 selectTab(mTabs.isEmpty() ? null : mTabs.get(Math.max(0, position - 1)));
599 }
Adam Powell661c9082010-07-02 10:09:44 -0700600 }
601
602 @Override
Adam Powell661c9082010-07-02 10:09:44 -0700603 public void selectTab(Tab tab) {
Adam Powell0c24a552010-11-03 16:44:11 -0700604 if (getNavigationMode() != NAVIGATION_MODE_TABS) {
605 mSavedTabPosition = tab != null ? tab.getPosition() : INVALID_POSITION;
606 return;
607 }
608
Adam Powell76d14662014-05-30 10:28:14 -0700609 final FragmentTransaction trans = mDecorToolbar.getViewGroup().isInEditMode() ? null :
Deepanshu Gupta14bf0ce2013-12-12 12:16:24 -0800610 mActivity.getFragmentManager().beginTransaction().disallowAddToBackStack();
Adam Powell7f9b9052010-10-19 16:56:07 -0700611
612 if (mSelectedTab == tab) {
613 if (mSelectedTab != null) {
614 mSelectedTab.getCallback().onTabReselected(mSelectedTab, trans);
Adam Powellf8ac6b72011-05-23 18:14:09 -0700615 mTabScrollView.animateToTab(tab.getPosition());
Adam Powell7f9b9052010-10-19 16:56:07 -0700616 }
617 } else {
Adam Powellf8ac6b72011-05-23 18:14:09 -0700618 mTabScrollView.setTabSelected(tab != null ? tab.getPosition() : Tab.INVALID_POSITION);
Adam Powell7f9b9052010-10-19 16:56:07 -0700619 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 Powell2b6230e2010-09-07 17:55:25 -0700626 }
627
Deepanshu Gupta14bf0ce2013-12-12 12:16:24 -0800628 if (trans != null && !trans.isEmpty()) {
Adam Powell2b6230e2010-09-07 17:55:25 -0700629 trans.commit();
630 }
631 }
632
633 @Override
634 public Tab getSelectedTab() {
635 return mSelectedTab;
Adam Powell661c9082010-07-02 10:09:44 -0700636 }
637
Adam Powell6b336f82010-08-10 20:13:01 -0700638 @Override
639 public int getHeight() {
Adam Powell58c5dc12011-07-14 21:08:10 -0700640 return mContainerView.getHeight();
Adam Powell6b336f82010-08-10 20:13:01 -0700641 }
642
Dianne Hackborndf7221c2013-02-26 14:53:55 -0800643 public void enableContentAnimations(boolean enabled) {
644 mContentAnimations = enabled;
645 }
646
Adam Powell6b336f82010-08-10 20:13:01 -0700647 @Override
648 public void show() {
Dianne Hackborn139e5aa2012-05-05 20:36:38 -0700649 if (mHiddenByApp) {
650 mHiddenByApp = false;
651 updateVisibility(false);
652 }
Adam Powell07e1f982011-03-24 11:11:15 -0700653 }
654
Dianne Hackborn139e5aa2012-05-05 20:36:38 -0700655 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 Powellb36e4f92014-05-01 10:23:33 -0700697 @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 Hackborn139e5aa2012-05-05 20:36:38 -0700726 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 Powell07e1f982011-03-24 11:11:15 -0700756 if (mCurrentShowAnim != null) {
757 mCurrentShowAnim.end();
Adam Powell45f1e082010-12-10 14:20:13 -0800758 }
Adam Powell9b0dc282013-07-31 13:58:43 -0700759 mContainerView.setVisibility(View.VISIBLE);
Adam Powell50efbed2011-02-08 16:20:15 -0800760
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700761 if (mCurWindowVisibility == View.VISIBLE && (mShowHideAnimationEnabled
Dianne Hackborn139e5aa2012-05-05 20:36:38 -0700762 || fromSystem)) {
Adam Powell9b0dc282013-07-31 13:58:43 -0700763 mContainerView.setTranslationY(0); // because we're about to ask its window loc
764 float startingY = -mContainerView.getHeight();
Chet Haasee8118e12012-05-30 14:19:02 -0700765 if (fromSystem) {
766 int topLeft[] = {0, 0};
Adam Powell9b0dc282013-07-31 13:58:43 -0700767 mContainerView.getLocationInWindow(topLeft);
Chet Haasee8118e12012-05-30 14:19:02 -0700768 startingY -= topLeft[1];
769 }
Adam Powell9b0dc282013-07-31 13:58:43 -0700770 mContainerView.setTranslationY(startingY);
Adam Powell50efbed2011-02-08 16:20:15 -0800771 AnimatorSet anim = new AnimatorSet();
Adam Powell9b0dc282013-07-31 13:58:43 -0700772 ObjectAnimator a = ObjectAnimator.ofFloat(mContainerView, View.TRANSLATION_Y, 0);
773 a.addUpdateListener(mUpdateListener);
774 AnimatorSet.Builder b = anim.play(a);
Dianne Hackborndf7221c2013-02-26 14:53:55 -0800775 if (mContentAnimations && mContentView != null) {
Adam Powell9b0dc282013-07-31 13:58:43 -0700776 b.with(ObjectAnimator.ofFloat(mContentView, View.TRANSLATION_Y,
Chet Haasee8118e12012-05-30 14:19:02 -0700777 startingY, 0));
Adam Powell50efbed2011-02-08 16:20:15 -0800778 }
Adam Powell1ab418a2011-06-09 20:49:49 -0700779 if (mSplitView != null && mContextDisplayMode == CONTEXT_DISPLAY_SPLIT) {
Dianne Hackborn8eedb8b2012-04-16 19:31:58 -0700780 mSplitView.setTranslationY(mSplitView.getHeight());
Adam Powell993a63a2011-08-18 16:35:53 -0700781 mSplitView.setVisibility(View.VISIBLE);
Adam Powell9b0dc282013-07-31 13:58:43 -0700782 b.with(ObjectAnimator.ofFloat(mSplitView, View.TRANSLATION_Y, 0));
Adam Powell640a66e2011-04-29 10:18:53 -0700783 }
Dianne Hackborn8eedb8b2012-04-16 19:31:58 -0700784 anim.setInterpolator(AnimationUtils.loadInterpolator(mContext,
Chet Haasee8118e12012-05-30 14:19:02 -0700785 com.android.internal.R.interpolator.decelerate_cubic));
786 anim.setDuration(250);
Dianne Hackborn139e5aa2012-05-05 20:36:38 -0700787 // 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 Powell50efbed2011-02-08 16:20:15 -0800794 anim.addListener(mShowListener);
Adam Powell07e1f982011-03-24 11:11:15 -0700795 mCurrentShowAnim = anim;
Adam Powell50efbed2011-02-08 16:20:15 -0800796 anim.start();
797 } else {
Adam Powell9b0dc282013-07-31 13:58:43 -0700798 mContainerView.setAlpha(1);
799 mContainerView.setTranslationY(0);
Dianne Hackborndf7221c2013-02-26 14:53:55 -0800800 if (mContentAnimations && mContentView != null) {
Dianne Hackborn80d55062012-05-22 18:03:20 -0700801 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 Powell50efbed2011-02-08 16:20:15 -0800808 mShowListener.onAnimationEnd(null);
Adam Powelle6ec7322010-12-07 15:29:26 -0800809 }
Dianne Hackborn139e5aa2012-05-05 20:36:38 -0700810 if (mOverlayLayout != null) {
Adam Powellb36e4f92014-05-01 10:23:33 -0700811 mOverlayLayout.requestApplyInsets();
Dianne Hackborn139e5aa2012-05-05 20:36:38 -0700812 }
Adam Powell6b336f82010-08-10 20:13:01 -0700813 }
814
Dianne Hackborn139e5aa2012-05-05 20:36:38 -0700815 public void doHide(boolean fromSystem) {
Adam Powell07e1f982011-03-24 11:11:15 -0700816 if (mCurrentShowAnim != null) {
817 mCurrentShowAnim.end();
Adam Powelle6ec7322010-12-07 15:29:26 -0800818 }
Adam Powell50efbed2011-02-08 16:20:15 -0800819
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700820 if (mCurWindowVisibility == View.VISIBLE && (mShowHideAnimationEnabled
Dianne Hackborn139e5aa2012-05-05 20:36:38 -0700821 || fromSystem)) {
Adam Powell9b0dc282013-07-31 13:58:43 -0700822 mContainerView.setAlpha(1);
Adam Powell01feaee2011-02-10 15:05:05 -0800823 mContainerView.setTransitioning(true);
Adam Powell50efbed2011-02-08 16:20:15 -0800824 AnimatorSet anim = new AnimatorSet();
Adam Powell9b0dc282013-07-31 13:58:43 -0700825 float endingY = -mContainerView.getHeight();
Chet Haasee8118e12012-05-30 14:19:02 -0700826 if (fromSystem) {
827 int topLeft[] = {0, 0};
Adam Powell9b0dc282013-07-31 13:58:43 -0700828 mContainerView.getLocationInWindow(topLeft);
Chet Haasee8118e12012-05-30 14:19:02 -0700829 endingY -= topLeft[1];
830 }
Adam Powell9b0dc282013-07-31 13:58:43 -0700831 ObjectAnimator a = ObjectAnimator.ofFloat(mContainerView, View.TRANSLATION_Y, endingY);
832 a.addUpdateListener(mUpdateListener);
833 AnimatorSet.Builder b = anim.play(a);
Dianne Hackborndf7221c2013-02-26 14:53:55 -0800834 if (mContentAnimations && mContentView != null) {
Adam Powell9b0dc282013-07-31 13:58:43 -0700835 b.with(ObjectAnimator.ofFloat(mContentView, View.TRANSLATION_Y,
Chet Haasee8118e12012-05-30 14:19:02 -0700836 0, endingY));
Adam Powell50efbed2011-02-08 16:20:15 -0800837 }
Adam Powell1ab418a2011-06-09 20:49:49 -0700838 if (mSplitView != null && mSplitView.getVisibility() == View.VISIBLE) {
Adam Powell640a66e2011-04-29 10:18:53 -0700839 mSplitView.setAlpha(1);
Adam Powell9b0dc282013-07-31 13:58:43 -0700840 b.with(ObjectAnimator.ofFloat(mSplitView, View.TRANSLATION_Y,
Dianne Hackborn8eedb8b2012-04-16 19:31:58 -0700841 mSplitView.getHeight()));
Adam Powell640a66e2011-04-29 10:18:53 -0700842 }
Dianne Hackborn8eedb8b2012-04-16 19:31:58 -0700843 anim.setInterpolator(AnimationUtils.loadInterpolator(mContext,
Chet Haasee8118e12012-05-30 14:19:02 -0700844 com.android.internal.R.interpolator.accelerate_cubic));
845 anim.setDuration(250);
Adam Powell50efbed2011-02-08 16:20:15 -0800846 anim.addListener(mHideListener);
Adam Powell07e1f982011-03-24 11:11:15 -0700847 mCurrentShowAnim = anim;
Adam Powell50efbed2011-02-08 16:20:15 -0800848 anim.start();
849 } else {
850 mHideListener.onAnimationEnd(null);
Adam Powelle6ec7322010-12-07 15:29:26 -0800851 }
Adam Powell6b336f82010-08-10 20:13:01 -0700852 }
853
854 public boolean isShowing() {
Adam Powellf65bfb72014-06-19 10:55:28 -0700855 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 Powelld8b3f2e2010-12-02 13:37:03 -0800858 }
859
Adam Powell640a66e2011-04-29 10:18:53 -0700860 void animateToMode(boolean toActionMode) {
Adam Powell060e3ca2011-07-19 20:39:16 -0700861 if (toActionMode) {
Dianne Hackborn139e5aa2012-05-05 20:36:38 -0700862 showForActionMode();
863 } else {
864 hideForActionMode();
Adam Powell07e1f982011-03-24 11:11:15 -0700865 }
Adam Powelld8b3f2e2010-12-02 13:37:03 -0800866
Adam Powelle021e6e2014-05-23 17:27:24 -0700867 mDecorToolbar.animateToVisibility(toActionMode ? View.GONE : View.VISIBLE);
Adam Powell640a66e2011-04-29 10:18:53 -0700868 mContextView.animateToVisibility(toActionMode ? View.VISIBLE : View.GONE);
Yigit Boyar2bbad0c2014-09-16 18:28:03 -0700869 // mTabScrollView's visibility is not affected by action mode.
Adam Powelle021e6e2014-05-23 17:27:24 -0700870 }
871
Adam Powell88ab6972011-07-28 11:25:01 -0700872 public Context getThemedContext() {
873 if (mThemedContext == null) {
874 TypedValue outValue = new TypedValue();
875 Resources.Theme currentTheme = mContext.getTheme();
876 currentTheme.resolveAttribute(com.android.internal.R.attr.actionBarWidgetTheme,
877 outValue, true);
878 final int targetThemeRes = outValue.resourceId;
Alan Viverette3abf5c42014-10-29 11:03:35 -0700879
Adam Powell88ab6972011-07-28 11:25:01 -0700880 if (targetThemeRes != 0 && mContext.getThemeResId() != targetThemeRes) {
881 mThemedContext = new ContextThemeWrapper(mContext, targetThemeRes);
882 } else {
883 mThemedContext = mContext;
884 }
885 }
886 return mThemedContext;
887 }
Alan Viverette3abf5c42014-10-29 11:03:35 -0700888
Adam Powell27cba382013-01-22 18:55:20 -0800889 @Override
890 public boolean isTitleTruncated() {
Adam Powelle021e6e2014-05-23 17:27:24 -0700891 return mDecorToolbar != null && mDecorToolbar.isTitleTruncated();
Adam Powell27cba382013-01-22 18:55:20 -0800892 }
893
Adam Powelle0e2f4f2013-04-05 16:27:35 -0700894 @Override
895 public void setHomeAsUpIndicator(Drawable indicator) {
Adam Powelle021e6e2014-05-23 17:27:24 -0700896 mDecorToolbar.setNavigationIcon(indicator);
Adam Powelle0e2f4f2013-04-05 16:27:35 -0700897 }
898
899 @Override
900 public void setHomeAsUpIndicator(int resId) {
Adam Powelle021e6e2014-05-23 17:27:24 -0700901 mDecorToolbar.setNavigationIcon(resId);
Adam Powelle0e2f4f2013-04-05 16:27:35 -0700902 }
903
904 @Override
905 public void setHomeActionContentDescription(CharSequence description) {
Adam Powelle021e6e2014-05-23 17:27:24 -0700906 mDecorToolbar.setNavigationContentDescription(description);
Adam Powelle0e2f4f2013-04-05 16:27:35 -0700907 }
908
909 @Override
910 public void setHomeActionContentDescription(int resId) {
Adam Powelle021e6e2014-05-23 17:27:24 -0700911 mDecorToolbar.setNavigationContentDescription(resId);
Adam Powelle0e2f4f2013-04-05 16:27:35 -0700912 }
913
Adam Powellb36e4f92014-05-01 10:23:33 -0700914 @Override
915 public void onContentScrollStarted() {
916 if (mCurrentShowAnim != null) {
917 mCurrentShowAnim.cancel();
918 mCurrentShowAnim = null;
919 }
920 }
921
922 @Override
923 public void onContentScrollStopped() {
924 }
925
Adam Powell5352a892014-08-20 17:33:24 -0700926 @Override
927 public boolean collapseActionView() {
928 if (mDecorToolbar != null && mDecorToolbar.hasExpandedActionView()) {
929 mDecorToolbar.collapseActionView();
930 return true;
931 }
932 return false;
933 }
934
Adam Powell89e06452010-06-23 20:24:52 -0700935 /**
Alan Viverette3abf5c42014-10-29 11:03:35 -0700936 * @hide
Adam Powell89e06452010-06-23 20:24:52 -0700937 */
Adam Powell5d279772010-07-27 16:34:07 -0700938 public class ActionModeImpl extends ActionMode implements MenuBuilder.Callback {
Alan Viverette3abf5c42014-10-29 11:03:35 -0700939 private final Context mActionModeContext;
940 private final MenuBuilder mMenu;
941
Adam Powell6e346362010-07-23 10:18:23 -0700942 private ActionMode.Callback mCallback;
Adam Powell29ed7572010-07-14 16:24:56 -0700943 private WeakReference<View> mCustomView;
Alan Viverette3abf5c42014-10-29 11:03:35 -0700944
Alan Viverettef6a36e92014-10-28 17:50:59 -0700945 public ActionModeImpl(Context context, ActionMode.Callback callback) {
Alan Viverette3abf5c42014-10-29 11:03:35 -0700946 mActionModeContext = context;
Adam Powell89e06452010-06-23 20:24:52 -0700947 mCallback = callback;
Alan Viverettef6a36e92014-10-28 17:50:59 -0700948 mMenu = new MenuBuilder(context)
Adam Powell4d9861e2010-08-17 11:14:40 -0700949 .setDefaultShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700950 mMenu.setCallback(this);
Adam Powell89e06452010-06-23 20:24:52 -0700951 }
Adam Powell9168f0b2010-08-02 15:46:24 -0700952
953 @Override
954 public MenuInflater getMenuInflater() {
Alan Viverette3abf5c42014-10-29 11:03:35 -0700955 return new MenuInflater(mActionModeContext);
Adam Powell9168f0b2010-08-02 15:46:24 -0700956 }
957
Adam Powell89e06452010-06-23 20:24:52 -0700958 @Override
959 public Menu getMenu() {
960 return mMenu;
961 }
962
963 @Override
964 public void finish() {
Adam Powell5d279772010-07-27 16:34:07 -0700965 if (mActionMode != this) {
966 // Not the active action mode - no-op
Adam Powell93b6bc32010-07-22 11:36:35 -0700967 return;
968 }
969
Dianne Hackborn139e5aa2012-05-05 20:36:38 -0700970 // If this change in state is going to cause the action bar
971 // to be hidden, defer the onDestroy callback until the animation
972 // is finished and associated relayout is about to happen. This lets
973 // apps better anticipate visibility and layout behavior.
974 if (!checkShowingFlags(mHiddenByApp, mHiddenBySystem, false)) {
975 // With the current state but the action bar hidden, our
976 // overall showing state is going to be false.
Adam Powell060e3ca2011-07-19 20:39:16 -0700977 mDeferredDestroyActionMode = this;
978 mDeferredModeDestroyCallback = mCallback;
979 } else {
980 mCallback.onDestroyActionMode(this);
981 }
Adam Powelld8b3f2e2010-12-02 13:37:03 -0800982 mCallback = null;
Adam Powell640a66e2011-04-29 10:18:53 -0700983 animateToMode(false);
Adam Powell0e94b512010-06-29 17:58:20 -0700984
985 // Clear out the context mode views after the animation finishes
Adam Powell640a66e2011-04-29 10:18:53 -0700986 mContextView.closeMode();
Adam Powell76d14662014-05-30 10:28:14 -0700987 mDecorToolbar.getViewGroup().sendAccessibilityEvent(
Adam Powelle021e6e2014-05-23 17:27:24 -0700988 AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Adam Powellb36e4f92014-05-01 10:23:33 -0700989 mOverlayLayout.setHideOnContentScrollEnabled(mHideOnContentScroll);
Adam Powellf6ce6a92011-06-29 10:25:01 -0700990
Adam Powell5d279772010-07-27 16:34:07 -0700991 mActionMode = null;
Adam Powell89e06452010-06-23 20:24:52 -0700992 }
993
994 @Override
995 public void invalidate() {
Adam Powell5ee36c42011-06-02 12:59:43 -0700996 mMenu.stopDispatchingItemsChanged();
997 try {
998 mCallback.onPrepareActionMode(this, mMenu);
999 } finally {
1000 mMenu.startDispatchingItemsChanged();
1001 }
1002 }
1003
1004 public boolean dispatchOnCreate() {
1005 mMenu.stopDispatchingItemsChanged();
1006 try {
1007 return mCallback.onCreateActionMode(this, mMenu);
1008 } finally {
1009 mMenu.startDispatchingItemsChanged();
Adam Powell89e06452010-06-23 20:24:52 -07001010 }
1011 }
1012
1013 @Override
1014 public void setCustomView(View view) {
Adam Powell640a66e2011-04-29 10:18:53 -07001015 mContextView.setCustomView(view);
Adam Powell29ed7572010-07-14 16:24:56 -07001016 mCustomView = new WeakReference<View>(view);
Adam Powell89e06452010-06-23 20:24:52 -07001017 }
1018
1019 @Override
1020 public void setSubtitle(CharSequence subtitle) {
Adam Powell640a66e2011-04-29 10:18:53 -07001021 mContextView.setSubtitle(subtitle);
Adam Powell89e06452010-06-23 20:24:52 -07001022 }
1023
1024 @Override
1025 public void setTitle(CharSequence title) {
Adam Powell640a66e2011-04-29 10:18:53 -07001026 mContextView.setTitle(title);
Adam Powell89e06452010-06-23 20:24:52 -07001027 }
Adam Powell29ed7572010-07-14 16:24:56 -07001028
1029 @Override
Adam Powellc9ae2a22010-07-28 14:44:21 -07001030 public void setTitle(int resId) {
Adam Powell48e8ac32011-01-14 12:10:24 -08001031 setTitle(mContext.getResources().getString(resId));
Adam Powellc9ae2a22010-07-28 14:44:21 -07001032 }
1033
1034 @Override
1035 public void setSubtitle(int resId) {
Adam Powell48e8ac32011-01-14 12:10:24 -08001036 setSubtitle(mContext.getResources().getString(resId));
Adam Powellc9ae2a22010-07-28 14:44:21 -07001037 }
1038
1039 @Override
Adam Powell29ed7572010-07-14 16:24:56 -07001040 public CharSequence getTitle() {
Adam Powell640a66e2011-04-29 10:18:53 -07001041 return mContextView.getTitle();
Adam Powell29ed7572010-07-14 16:24:56 -07001042 }
1043
1044 @Override
1045 public CharSequence getSubtitle() {
Adam Powell640a66e2011-04-29 10:18:53 -07001046 return mContextView.getSubtitle();
Adam Powell29ed7572010-07-14 16:24:56 -07001047 }
Alan Viverette3abf5c42014-10-29 11:03:35 -07001048
Adam Powell29ed7572010-07-14 16:24:56 -07001049 @Override
Adam Powellb98a81f2012-02-24 11:09:07 -08001050 public void setTitleOptionalHint(boolean titleOptional) {
Adam Powell785c4472012-05-02 21:25:39 -07001051 super.setTitleOptionalHint(titleOptional);
Adam Powellb98a81f2012-02-24 11:09:07 -08001052 mContextView.setTitleOptional(titleOptional);
1053 }
1054
1055 @Override
1056 public boolean isTitleOptional() {
1057 return mContextView.isTitleOptional();
1058 }
1059
1060 @Override
Adam Powell29ed7572010-07-14 16:24:56 -07001061 public View getCustomView() {
1062 return mCustomView != null ? mCustomView.get() : null;
1063 }
1064
Adam Powell2c9c9fe2010-07-16 10:17:57 -07001065 public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
Adam Powelld8b3f2e2010-12-02 13:37:03 -08001066 if (mCallback != null) {
1067 return mCallback.onActionItemClicked(this, item);
1068 } else {
1069 return false;
1070 }
Adam Powell2c9c9fe2010-07-16 10:17:57 -07001071 }
1072
1073 public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) {
1074 }
1075
1076 public boolean onSubMenuSelected(SubMenuBuilder subMenu) {
Adam Powelld8b3f2e2010-12-02 13:37:03 -08001077 if (mCallback == null) {
1078 return false;
1079 }
1080
Adam Powell2c9c9fe2010-07-16 10:17:57 -07001081 if (!subMenu.hasVisibleItems()) {
1082 return true;
Adam Powell89e06452010-06-23 20:24:52 -07001083 }
Adam Powell2c9c9fe2010-07-16 10:17:57 -07001084
Adam Powellf2423682011-08-11 14:29:45 -07001085 new MenuPopupHelper(getThemedContext(), subMenu).show();
Adam Powell2c9c9fe2010-07-16 10:17:57 -07001086 return true;
1087 }
1088
1089 public void onCloseSubMenu(SubMenuBuilder menu) {
1090 }
1091
1092 public void onMenuModeChange(MenuBuilder menu) {
Adam Powelld8b3f2e2010-12-02 13:37:03 -08001093 if (mCallback == null) {
1094 return;
1095 }
Adam Powellf6148c52010-08-11 21:10:16 -07001096 invalidate();
Adam Powell640a66e2011-04-29 10:18:53 -07001097 mContextView.showOverflowMenu();
Adam Powell2c9c9fe2010-07-16 10:17:57 -07001098 }
Adam Powell661c9082010-07-02 10:09:44 -07001099 }
1100
1101 /**
1102 * @hide
1103 */
1104 public class TabImpl extends ActionBar.Tab {
Adam Powell2b6230e2010-09-07 17:55:25 -07001105 private ActionBar.TabListener mCallback;
1106 private Object mTag;
Adam Powell661c9082010-07-02 10:09:44 -07001107 private Drawable mIcon;
1108 private CharSequence mText;
Adam Powell94e56ef2011-09-06 21:22:22 -07001109 private CharSequence mContentDesc;
Adam Powell0d8ec1d2011-05-03 14:49:13 -07001110 private int mPosition = -1;
Adam Powell2b6230e2010-09-07 17:55:25 -07001111 private View mCustomView;
Adam Powell661c9082010-07-02 10:09:44 -07001112
1113 @Override
Adam Powell2b6230e2010-09-07 17:55:25 -07001114 public Object getTag() {
1115 return mTag;
1116 }
1117
1118 @Override
Adam Powell9ab97872010-10-26 21:47:29 -07001119 public Tab setTag(Object tag) {
Adam Powell2b6230e2010-09-07 17:55:25 -07001120 mTag = tag;
Adam Powell9ab97872010-10-26 21:47:29 -07001121 return this;
Adam Powell2b6230e2010-09-07 17:55:25 -07001122 }
1123
1124 public ActionBar.TabListener getCallback() {
1125 return mCallback;
1126 }
1127
1128 @Override
Adam Powell9ab97872010-10-26 21:47:29 -07001129 public Tab setTabListener(ActionBar.TabListener callback) {
Adam Powell2b6230e2010-09-07 17:55:25 -07001130 mCallback = callback;
Adam Powell9ab97872010-10-26 21:47:29 -07001131 return this;
Adam Powell2b6230e2010-09-07 17:55:25 -07001132 }
1133
1134 @Override
1135 public View getCustomView() {
1136 return mCustomView;
1137 }
1138
1139 @Override
Adam Powell9ab97872010-10-26 21:47:29 -07001140 public Tab setCustomView(View view) {
Adam Powell2b6230e2010-09-07 17:55:25 -07001141 mCustomView = view;
Adam Powellf8ac6b72011-05-23 18:14:09 -07001142 if (mPosition >= 0) {
1143 mTabScrollView.updateTab(mPosition);
1144 }
Adam Powell9ab97872010-10-26 21:47:29 -07001145 return this;
Adam Powell661c9082010-07-02 10:09:44 -07001146 }
1147
1148 @Override
Adam Powell32555f32010-11-17 13:49:22 -08001149 public Tab setCustomView(int layoutResId) {
Adam Powellf2423682011-08-11 14:29:45 -07001150 return setCustomView(LayoutInflater.from(getThemedContext())
1151 .inflate(layoutResId, null));
Adam Powell32555f32010-11-17 13:49:22 -08001152 }
1153
1154 @Override
Adam Powell661c9082010-07-02 10:09:44 -07001155 public Drawable getIcon() {
1156 return mIcon;
1157 }
1158
1159 @Override
1160 public int getPosition() {
1161 return mPosition;
1162 }
1163
1164 public void setPosition(int position) {
1165 mPosition = position;
1166 }
1167
1168 @Override
1169 public CharSequence getText() {
1170 return mText;
1171 }
1172
1173 @Override
Adam Powell9ab97872010-10-26 21:47:29 -07001174 public Tab setIcon(Drawable icon) {
Adam Powell661c9082010-07-02 10:09:44 -07001175 mIcon = icon;
Adam Powellf8ac6b72011-05-23 18:14:09 -07001176 if (mPosition >= 0) {
1177 mTabScrollView.updateTab(mPosition);
1178 }
Adam Powell9ab97872010-10-26 21:47:29 -07001179 return this;
Adam Powell661c9082010-07-02 10:09:44 -07001180 }
1181
1182 @Override
Adam Powell32555f32010-11-17 13:49:22 -08001183 public Tab setIcon(int resId) {
Alan Viverette8eea3ea2014-02-03 18:40:20 -08001184 return setIcon(mContext.getDrawable(resId));
Adam Powell32555f32010-11-17 13:49:22 -08001185 }
1186
1187 @Override
Adam Powell9ab97872010-10-26 21:47:29 -07001188 public Tab setText(CharSequence text) {
Adam Powell661c9082010-07-02 10:09:44 -07001189 mText = text;
Adam Powellf8ac6b72011-05-23 18:14:09 -07001190 if (mPosition >= 0) {
1191 mTabScrollView.updateTab(mPosition);
1192 }
Adam Powell9ab97872010-10-26 21:47:29 -07001193 return this;
Adam Powell661c9082010-07-02 10:09:44 -07001194 }
1195
1196 @Override
Adam Powell32555f32010-11-17 13:49:22 -08001197 public Tab setText(int resId) {
1198 return setText(mContext.getResources().getText(resId));
1199 }
1200
1201 @Override
Adam Powell661c9082010-07-02 10:09:44 -07001202 public void select() {
1203 selectTab(this);
Adam Powell89e06452010-06-23 20:24:52 -07001204 }
Adam Powell94e56ef2011-09-06 21:22:22 -07001205
1206 @Override
1207 public Tab setContentDescription(int resId) {
1208 return setContentDescription(mContext.getResources().getText(resId));
1209 }
1210
1211 @Override
1212 public Tab setContentDescription(CharSequence contentDesc) {
1213 mContentDesc = contentDesc;
1214 if (mPosition >= 0) {
1215 mTabScrollView.updateTab(mPosition);
1216 }
1217 return this;
1218 }
1219
1220 @Override
1221 public CharSequence getContentDescription() {
1222 return mContentDesc;
1223 }
Adam Powell89e06452010-06-23 20:24:52 -07001224 }
Adam Powell9ab97872010-10-26 21:47:29 -07001225
1226 @Override
1227 public void setCustomView(View view) {
Adam Powelle021e6e2014-05-23 17:27:24 -07001228 mDecorToolbar.setCustomView(view);
Adam Powell9ab97872010-10-26 21:47:29 -07001229 }
1230
1231 @Override
1232 public void setCustomView(View view, LayoutParams layoutParams) {
1233 view.setLayoutParams(layoutParams);
Adam Powelle021e6e2014-05-23 17:27:24 -07001234 mDecorToolbar.setCustomView(view);
Adam Powell9ab97872010-10-26 21:47:29 -07001235 }
1236
1237 @Override
Adam Powell8515ee82010-11-30 14:09:55 -08001238 public void setListNavigationCallbacks(SpinnerAdapter adapter, OnNavigationListener callback) {
Adam Powelle021e6e2014-05-23 17:27:24 -07001239 mDecorToolbar.setDropdownParams(adapter, new NavItemSelectedListener(callback));
Adam Powell9ab97872010-10-26 21:47:29 -07001240 }
1241
1242 @Override
1243 public int getSelectedNavigationIndex() {
Adam Powelle021e6e2014-05-23 17:27:24 -07001244 switch (mDecorToolbar.getNavigationMode()) {
Adam Powell9ab97872010-10-26 21:47:29 -07001245 case NAVIGATION_MODE_TABS:
Adam Powell04587962010-11-11 22:15:07 -08001246 return mSelectedTab != null ? mSelectedTab.getPosition() : -1;
Adam Powell9ab97872010-10-26 21:47:29 -07001247 case NAVIGATION_MODE_LIST:
Adam Powelle021e6e2014-05-23 17:27:24 -07001248 return mDecorToolbar.getDropdownSelectedPosition();
Adam Powell9ab97872010-10-26 21:47:29 -07001249 default:
1250 return -1;
1251 }
1252 }
1253
1254 @Override
1255 public int getNavigationItemCount() {
Adam Powelle021e6e2014-05-23 17:27:24 -07001256 switch (mDecorToolbar.getNavigationMode()) {
Adam Powell9ab97872010-10-26 21:47:29 -07001257 case NAVIGATION_MODE_TABS:
1258 return mTabs.size();
1259 case NAVIGATION_MODE_LIST:
Adam Powelle021e6e2014-05-23 17:27:24 -07001260 return mDecorToolbar.getDropdownItemCount();
Adam Powell9ab97872010-10-26 21:47:29 -07001261 default:
1262 return 0;
1263 }
1264 }
1265
1266 @Override
Adam Powell0c24a552010-11-03 16:44:11 -07001267 public int getTabCount() {
1268 return mTabs.size();
1269 }
1270
1271 @Override
Adam Powell9ab97872010-10-26 21:47:29 -07001272 public void setNavigationMode(int mode) {
Adam Powelle021e6e2014-05-23 17:27:24 -07001273 final int oldMode = mDecorToolbar.getNavigationMode();
Adam Powell0c24a552010-11-03 16:44:11 -07001274 switch (oldMode) {
1275 case NAVIGATION_MODE_TABS:
1276 mSavedTabPosition = getSelectedNavigationIndex();
1277 selectTab(null);
Adam Powellf5645cb2011-08-10 22:49:02 -07001278 mTabScrollView.setVisibility(View.GONE);
Adam Powell0c24a552010-11-03 16:44:11 -07001279 break;
1280 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07001281 if (oldMode != mode && !mHasEmbeddedTabs) {
1282 if (mOverlayLayout != null) {
1283 mOverlayLayout.requestFitSystemWindows();
1284 }
1285 }
Adam Powelle021e6e2014-05-23 17:27:24 -07001286 mDecorToolbar.setNavigationMode(mode);
Adam Powell0c24a552010-11-03 16:44:11 -07001287 switch (mode) {
1288 case NAVIGATION_MODE_TABS:
Adam Powellf8ac6b72011-05-23 18:14:09 -07001289 ensureTabsExist();
Adam Powellf5645cb2011-08-10 22:49:02 -07001290 mTabScrollView.setVisibility(View.VISIBLE);
Adam Powell0c24a552010-11-03 16:44:11 -07001291 if (mSavedTabPosition != INVALID_POSITION) {
1292 setSelectedNavigationItem(mSavedTabPosition);
1293 mSavedTabPosition = INVALID_POSITION;
1294 }
1295 break;
1296 }
Adam Powelle021e6e2014-05-23 17:27:24 -07001297 mDecorToolbar.setCollapsible(mode == NAVIGATION_MODE_TABS && !mHasEmbeddedTabs);
Adam Powellb36e4f92014-05-01 10:23:33 -07001298 mOverlayLayout.setHasNonEmbeddedTabs(mode == NAVIGATION_MODE_TABS && !mHasEmbeddedTabs);
Adam Powell9ab97872010-10-26 21:47:29 -07001299 }
1300
1301 @Override
1302 public Tab getTabAt(int index) {
1303 return mTabs.get(index);
1304 }
Adam Powell0c24a552010-11-03 16:44:11 -07001305
Adam Powell0c24a552010-11-03 16:44:11 -07001306
Adam Powell1969b872011-03-22 11:52:48 -07001307 @Override
1308 public void setIcon(int resId) {
Adam Powelle021e6e2014-05-23 17:27:24 -07001309 mDecorToolbar.setIcon(resId);
Adam Powell1969b872011-03-22 11:52:48 -07001310 }
Adam Powell0c24a552010-11-03 16:44:11 -07001311
Adam Powell1969b872011-03-22 11:52:48 -07001312 @Override
1313 public void setIcon(Drawable icon) {
Adam Powelle021e6e2014-05-23 17:27:24 -07001314 mDecorToolbar.setIcon(icon);
Adam Powell1969b872011-03-22 11:52:48 -07001315 }
1316
Adam Powell04fe6eb2013-05-31 14:39:48 -07001317 public boolean hasIcon() {
Adam Powelle021e6e2014-05-23 17:27:24 -07001318 return mDecorToolbar.hasIcon();
Adam Powell04fe6eb2013-05-31 14:39:48 -07001319 }
1320
Adam Powell1969b872011-03-22 11:52:48 -07001321 @Override
1322 public void setLogo(int resId) {
Adam Powelle021e6e2014-05-23 17:27:24 -07001323 mDecorToolbar.setLogo(resId);
Adam Powell1969b872011-03-22 11:52:48 -07001324 }
1325
1326 @Override
1327 public void setLogo(Drawable logo) {
Adam Powelle021e6e2014-05-23 17:27:24 -07001328 mDecorToolbar.setLogo(logo);
Adam Powell0c24a552010-11-03 16:44:11 -07001329 }
Adam Powelldd8fab22012-03-22 17:47:27 -07001330
Adam Powell04fe6eb2013-05-31 14:39:48 -07001331 public boolean hasLogo() {
Adam Powelle021e6e2014-05-23 17:27:24 -07001332 return mDecorToolbar.hasLogo();
Adam Powell04fe6eb2013-05-31 14:39:48 -07001333 }
1334
Adam Powelldd8fab22012-03-22 17:47:27 -07001335 public void setDefaultDisplayHomeAsUpEnabled(boolean enable) {
1336 if (!mDisplayHomeAsUpSet) {
1337 setDisplayHomeAsUpEnabled(enable);
1338 }
1339 }
Adam Powelle021e6e2014-05-23 17:27:24 -07001340
Adam Powell89e06452010-06-23 20:24:52 -07001341}