blob: 7bd316f315194a843eda5616274c5848c2d2450d [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 }
225 a.recycle();
Adam Powellf8ac6b72011-05-23 18:14:09 -0700226 }
227
Adam Powelle021e6e2014-05-23 17:27:24 -0700228 private DecorToolbar getDecorToolbar(View view) {
229 if (view instanceof DecorToolbar) {
230 return (DecorToolbar) view;
231 } else if (view instanceof Toolbar) {
232 return ((Toolbar) view).getWrapper();
233 } else {
234 throw new IllegalStateException("Can't make a decor toolbar out of " +
235 view.getClass().getSimpleName());
236 }
237 }
238
Adam Powellf8ac6b72011-05-23 18:14:09 -0700239 public void onConfigurationChanged(Configuration newConfig) {
Adam Powellb8139af2012-04-19 13:52:46 -0700240 setHasEmbeddedTabs(ActionBarPolicy.get(mContext).hasEmbeddedTabs());
Adam Powellf5645cb2011-08-10 22:49:02 -0700241 }
Adam Powellf8ac6b72011-05-23 18:14:09 -0700242
Adam Powellf5645cb2011-08-10 22:49:02 -0700243 private void setHasEmbeddedTabs(boolean hasEmbeddedTabs) {
244 mHasEmbeddedTabs = hasEmbeddedTabs;
Adam Powellf8ac6b72011-05-23 18:14:09 -0700245 // Switch tab layout configuration if needed
246 if (!mHasEmbeddedTabs) {
Adam Powelle021e6e2014-05-23 17:27:24 -0700247 mDecorToolbar.setEmbeddedTabView(null);
Adam Powellf8ac6b72011-05-23 18:14:09 -0700248 mContainerView.setTabContainer(mTabScrollView);
249 } else {
250 mContainerView.setTabContainer(null);
Adam Powelle021e6e2014-05-23 17:27:24 -0700251 mDecorToolbar.setEmbeddedTabView(mTabScrollView);
Adam Powellf8ac6b72011-05-23 18:14:09 -0700252 }
Adam Powellf5645cb2011-08-10 22:49:02 -0700253 final boolean isInTabMode = getNavigationMode() == NAVIGATION_MODE_TABS;
254 if (mTabScrollView != null) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700255 if (isInTabMode) {
256 mTabScrollView.setVisibility(View.VISIBLE);
257 if (mOverlayLayout != null) {
Adam Powellb36e4f92014-05-01 10:23:33 -0700258 mOverlayLayout.requestApplyInsets();
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700259 }
260 } else {
261 mTabScrollView.setVisibility(View.GONE);
262 }
Adam Powellf5645cb2011-08-10 22:49:02 -0700263 }
Adam Powelle021e6e2014-05-23 17:27:24 -0700264 mDecorToolbar.setCollapsible(!mHasEmbeddedTabs && isInTabMode);
Adam Powellb36e4f92014-05-01 10:23:33 -0700265 mOverlayLayout.setHasNonEmbeddedTabs(!mHasEmbeddedTabs && isInTabMode);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700266 }
267
Adam Powellf8ac6b72011-05-23 18:14:09 -0700268 private void ensureTabsExist() {
269 if (mTabScrollView != null) {
270 return;
271 }
272
Adam Powellf5645cb2011-08-10 22:49:02 -0700273 ScrollingTabContainerView tabScroller = new ScrollingTabContainerView(mContext);
Adam Powellf8ac6b72011-05-23 18:14:09 -0700274
275 if (mHasEmbeddedTabs) {
276 tabScroller.setVisibility(View.VISIBLE);
Adam Powelle021e6e2014-05-23 17:27:24 -0700277 mDecorToolbar.setEmbeddedTabView(tabScroller);
Adam Powellf8ac6b72011-05-23 18:14:09 -0700278 } else {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700279 if (getNavigationMode() == NAVIGATION_MODE_TABS) {
280 tabScroller.setVisibility(View.VISIBLE);
281 if (mOverlayLayout != null) {
Adam Powell76d8f962014-05-14 20:13:47 -0700282 mOverlayLayout.requestApplyInsets();
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700283 }
284 } else {
285 tabScroller.setVisibility(View.GONE);
286 }
Adam Powelldae78242011-04-25 15:23:41 -0700287 mContainerView.setTabContainer(tabScroller);
Adam Powelldae78242011-04-25 15:23:41 -0700288 }
Adam Powellf8ac6b72011-05-23 18:14:09 -0700289 mTabScrollView = tabScroller;
Adam Powell89e06452010-06-23 20:24:52 -0700290 }
291
Adam Powell060e3ca2011-07-19 20:39:16 -0700292 void completeDeferredDestroyActionMode() {
293 if (mDeferredModeDestroyCallback != null) {
294 mDeferredModeDestroyCallback.onDestroyActionMode(mDeferredDestroyActionMode);
295 mDeferredDestroyActionMode = null;
296 mDeferredModeDestroyCallback = null;
297 }
298 }
299
Adam Powellb36e4f92014-05-01 10:23:33 -0700300 public void onWindowVisibilityChanged(int visibility) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700301 mCurWindowVisibility = visibility;
302 }
303
Adam Powell50efbed2011-02-08 16:20:15 -0800304 /**
305 * Enables or disables animation between show/hide states.
306 * If animation is disabled using this method, animations in progress
307 * will be finished.
308 *
309 * @param enabled true to animate, false to not animate.
310 */
311 public void setShowHideAnimationEnabled(boolean enabled) {
312 mShowHideAnimationEnabled = enabled;
Adam Powell07e1f982011-03-24 11:11:15 -0700313 if (!enabled && mCurrentShowAnim != null) {
314 mCurrentShowAnim.end();
Adam Powell50efbed2011-02-08 16:20:15 -0800315 }
316 }
317
Adam Powell8515ee82010-11-30 14:09:55 -0800318 public void addOnMenuVisibilityListener(OnMenuVisibilityListener listener) {
319 mMenuVisibilityListeners.add(listener);
320 }
321
322 public void removeOnMenuVisibilityListener(OnMenuVisibilityListener listener) {
323 mMenuVisibilityListeners.remove(listener);
324 }
325
326 public void dispatchMenuVisibilityChanged(boolean isVisible) {
327 if (isVisible == mLastMenuVisibility) {
328 return;
329 }
330 mLastMenuVisibility = isVisible;
331
332 final int count = mMenuVisibilityListeners.size();
333 for (int i = 0; i < count; i++) {
334 mMenuVisibilityListeners.get(i).onMenuVisibilityChanged(isVisible);
335 }
336 }
337
Adam Powella66c7b02010-07-28 15:28:25 -0700338 @Override
Adam Powell3f476b32011-01-03 19:25:36 -0800339 public void setCustomView(int resId) {
Adam Powelle021e6e2014-05-23 17:27:24 -0700340 setCustomView(LayoutInflater.from(getThemedContext()).inflate(resId,
Dan Sandler6fdeeb32014-05-29 11:02:41 -0400341 mDecorToolbar.getViewGroup(), false));
Adam Powell3f476b32011-01-03 19:25:36 -0800342 }
343
344 @Override
345 public void setDisplayUseLogoEnabled(boolean useLogo) {
346 setDisplayOptions(useLogo ? DISPLAY_USE_LOGO : 0, DISPLAY_USE_LOGO);
347 }
348
349 @Override
350 public void setDisplayShowHomeEnabled(boolean showHome) {
351 setDisplayOptions(showHome ? DISPLAY_SHOW_HOME : 0, DISPLAY_SHOW_HOME);
352 }
353
354 @Override
355 public void setDisplayHomeAsUpEnabled(boolean showHomeAsUp) {
356 setDisplayOptions(showHomeAsUp ? DISPLAY_HOME_AS_UP : 0, DISPLAY_HOME_AS_UP);
357 }
358
359 @Override
360 public void setDisplayShowTitleEnabled(boolean showTitle) {
361 setDisplayOptions(showTitle ? DISPLAY_SHOW_TITLE : 0, DISPLAY_SHOW_TITLE);
362 }
363
364 @Override
365 public void setDisplayShowCustomEnabled(boolean showCustom) {
366 setDisplayOptions(showCustom ? DISPLAY_SHOW_CUSTOM : 0, DISPLAY_SHOW_CUSTOM);
367 }
368
369 @Override
Adam Powellc29f4e52011-07-13 20:40:52 -0700370 public void setHomeButtonEnabled(boolean enable) {
Adam Powelle021e6e2014-05-23 17:27:24 -0700371 mDecorToolbar.setHomeButtonEnabled(enable);
Adam Powelldae78242011-04-25 15:23:41 -0700372 }
373
374 @Override
Adam Powella66c7b02010-07-28 15:28:25 -0700375 public void setTitle(int resId) {
Adam Powelldec9dfd2010-08-09 15:27:54 -0700376 setTitle(mContext.getString(resId));
Adam Powella66c7b02010-07-28 15:28:25 -0700377 }
378
379 @Override
380 public void setSubtitle(int resId) {
Adam Powelldec9dfd2010-08-09 15:27:54 -0700381 setSubtitle(mContext.getString(resId));
Adam Powella66c7b02010-07-28 15:28:25 -0700382 }
383
Adam Powell17809772010-07-21 13:25:11 -0700384 public void setSelectedNavigationItem(int position) {
Adam Powelle021e6e2014-05-23 17:27:24 -0700385 switch (mDecorToolbar.getNavigationMode()) {
Adam Powell17809772010-07-21 13:25:11 -0700386 case NAVIGATION_MODE_TABS:
387 selectTab(mTabs.get(position));
388 break;
Adam Powell9ab97872010-10-26 21:47:29 -0700389 case NAVIGATION_MODE_LIST:
Adam Powelle021e6e2014-05-23 17:27:24 -0700390 mDecorToolbar.setDropdownSelectedPosition(position);
Adam Powell17809772010-07-21 13:25:11 -0700391 break;
392 default:
393 throw new IllegalStateException(
Adam Powell9ab97872010-10-26 21:47:29 -0700394 "setSelectedNavigationIndex not valid for current navigation mode");
Adam Powell17809772010-07-21 13:25:11 -0700395 }
396 }
397
Adam Powell9ab97872010-10-26 21:47:29 -0700398 public void removeAllTabs() {
399 cleanupTabs();
Adam Powell17809772010-07-21 13:25:11 -0700400 }
401
Adam Powell661c9082010-07-02 10:09:44 -0700402 private void cleanupTabs() {
403 if (mSelectedTab != null) {
404 selectTab(null);
405 }
Adam Powell2b6230e2010-09-07 17:55:25 -0700406 mTabs.clear();
Adam Powelld21aa122011-05-27 13:09:52 -0700407 if (mTabScrollView != null) {
408 mTabScrollView.removeAllTabs();
409 }
Adam Powell0c24a552010-11-03 16:44:11 -0700410 mSavedTabPosition = INVALID_POSITION;
Adam Powell661c9082010-07-02 10:09:44 -0700411 }
412
Adam Powell0e94b512010-06-29 17:58:20 -0700413 public void setTitle(CharSequence title) {
Adam Powelle021e6e2014-05-23 17:27:24 -0700414 mDecorToolbar.setTitle(title);
Adam Powell0e94b512010-06-29 17:58:20 -0700415 }
416
417 public void setSubtitle(CharSequence subtitle) {
Adam Powelle021e6e2014-05-23 17:27:24 -0700418 mDecorToolbar.setSubtitle(subtitle);
Adam Powell0e94b512010-06-29 17:58:20 -0700419 }
420
Adam Powell89e06452010-06-23 20:24:52 -0700421 public void setDisplayOptions(int options) {
Adam Powelldd8fab22012-03-22 17:47:27 -0700422 if ((options & DISPLAY_HOME_AS_UP) != 0) {
423 mDisplayHomeAsUpSet = true;
424 }
Adam Powelle021e6e2014-05-23 17:27:24 -0700425 mDecorToolbar.setDisplayOptions(options);
Adam Powell89e06452010-06-23 20:24:52 -0700426 }
Adam Powell0e94b512010-06-29 17:58:20 -0700427
Adam Powell89e06452010-06-23 20:24:52 -0700428 public void setDisplayOptions(int options, int mask) {
Adam Powelle021e6e2014-05-23 17:27:24 -0700429 final int current = mDecorToolbar.getDisplayOptions();
Adam Powelldd8fab22012-03-22 17:47:27 -0700430 if ((mask & DISPLAY_HOME_AS_UP) != 0) {
431 mDisplayHomeAsUpSet = true;
432 }
Adam Powelle021e6e2014-05-23 17:27:24 -0700433 mDecorToolbar.setDisplayOptions((options & mask) | (current & ~mask));
Adam Powell89e06452010-06-23 20:24:52 -0700434 }
435
436 public void setBackgroundDrawable(Drawable d) {
Adam Powellf88b9152011-09-07 14:54:32 -0700437 mContainerView.setPrimaryBackground(d);
438 }
439
440 public void setStackedBackgroundDrawable(Drawable d) {
441 mContainerView.setStackedBackground(d);
442 }
443
444 public void setSplitBackgroundDrawable(Drawable d) {
445 if (mSplitView != null) {
446 mSplitView.setSplitBackground(d);
447 }
Adam Powell89e06452010-06-23 20:24:52 -0700448 }
449
Adam Powellef704442010-11-16 14:48:22 -0800450 public View getCustomView() {
Adam Powelle021e6e2014-05-23 17:27:24 -0700451 return mDecorToolbar.getCustomView();
Adam Powell89e06452010-06-23 20:24:52 -0700452 }
453
454 public CharSequence getTitle() {
Adam Powelle021e6e2014-05-23 17:27:24 -0700455 return mDecorToolbar.getTitle();
Adam Powell89e06452010-06-23 20:24:52 -0700456 }
457
458 public CharSequence getSubtitle() {
Adam Powelle021e6e2014-05-23 17:27:24 -0700459 return mDecorToolbar.getSubtitle();
Adam Powell89e06452010-06-23 20:24:52 -0700460 }
461
462 public int getNavigationMode() {
Adam Powelle021e6e2014-05-23 17:27:24 -0700463 return mDecorToolbar.getNavigationMode();
Adam Powell89e06452010-06-23 20:24:52 -0700464 }
465
466 public int getDisplayOptions() {
Adam Powelle021e6e2014-05-23 17:27:24 -0700467 return mDecorToolbar.getDisplayOptions();
Adam Powell89e06452010-06-23 20:24:52 -0700468 }
469
Adam Powell5d279772010-07-27 16:34:07 -0700470 public ActionMode startActionMode(ActionMode.Callback callback) {
471 if (mActionMode != null) {
472 mActionMode.finish();
Adam Powell6e346362010-07-23 10:18:23 -0700473 }
Adam Powell3461b322010-07-14 11:34:43 -0700474
Adam Powellb36e4f92014-05-01 10:23:33 -0700475 mOverlayLayout.setHideOnContentScrollEnabled(false);
Adam Powell640a66e2011-04-29 10:18:53 -0700476 mContextView.killMode();
Adam Powell5ee36c42011-06-02 12:59:43 -0700477 ActionModeImpl mode = new ActionModeImpl(callback);
478 if (mode.dispatchOnCreate()) {
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700479 mode.invalidate();
Adam Powell640a66e2011-04-29 10:18:53 -0700480 mContextView.initForMode(mode);
481 animateToMode(true);
Adam Powell1ab418a2011-06-09 20:49:49 -0700482 if (mSplitView != null && mContextDisplayMode == CONTEXT_DISPLAY_SPLIT) {
Adam Powell89e06452010-06-23 20:24:52 -0700483 // TODO animate this
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700484 if (mSplitView.getVisibility() != View.VISIBLE) {
485 mSplitView.setVisibility(View.VISIBLE);
486 if (mOverlayLayout != null) {
Adam Powellb36e4f92014-05-01 10:23:33 -0700487 mOverlayLayout.requestApplyInsets();
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700488 }
489 }
Adam Powell89e06452010-06-23 20:24:52 -0700490 }
Adam Powell86ed4362011-09-14 16:18:53 -0700491 mContextView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Adam Powell5d279772010-07-27 16:34:07 -0700492 mActionMode = mode;
Adam Powellac695c62010-07-20 18:19:27 -0700493 return mode;
Adam Powell89e06452010-06-23 20:24:52 -0700494 }
Adam Powellac695c62010-07-20 18:19:27 -0700495 return null;
Adam Powell89e06452010-06-23 20:24:52 -0700496 }
497
Adam Powell661c9082010-07-02 10:09:44 -0700498 private void configureTab(Tab tab, int position) {
499 final TabImpl tabi = (TabImpl) tab;
Adam Powell2b6230e2010-09-07 17:55:25 -0700500 final ActionBar.TabListener callback = tabi.getCallback();
501
502 if (callback == null) {
503 throw new IllegalStateException("Action Bar Tab must have a Callback");
504 }
Adam Powell661c9082010-07-02 10:09:44 -0700505
506 tabi.setPosition(position);
507 mTabs.add(position, tabi);
508
Adam Powell81b89442010-11-02 17:58:56 -0700509 final int count = mTabs.size();
510 for (int i = position + 1; i < count; i++) {
511 mTabs.get(i).setPosition(i);
Adam Powell661c9082010-07-02 10:09:44 -0700512 }
Adam Powell661c9082010-07-02 10:09:44 -0700513 }
514
515 @Override
516 public void addTab(Tab tab) {
Adam Powell81b89442010-11-02 17:58:56 -0700517 addTab(tab, mTabs.isEmpty());
Adam Powell661c9082010-07-02 10:09:44 -0700518 }
519
520 @Override
Adam Powell2b6230e2010-09-07 17:55:25 -0700521 public void addTab(Tab tab, int position) {
Adam Powell81b89442010-11-02 17:58:56 -0700522 addTab(tab, position, mTabs.isEmpty());
523 }
524
525 @Override
526 public void addTab(Tab tab, boolean setSelected) {
Adam Powellf8ac6b72011-05-23 18:14:09 -0700527 ensureTabsExist();
528 mTabScrollView.addTab(tab, setSelected);
Adam Powell81b89442010-11-02 17:58:56 -0700529 configureTab(tab, mTabs.size());
530 if (setSelected) {
531 selectTab(tab);
532 }
533 }
534
535 @Override
536 public void addTab(Tab tab, int position, boolean setSelected) {
Adam Powellf8ac6b72011-05-23 18:14:09 -0700537 ensureTabsExist();
538 mTabScrollView.addTab(tab, position, setSelected);
Adam Powell661c9082010-07-02 10:09:44 -0700539 configureTab(tab, position);
Adam Powell81b89442010-11-02 17:58:56 -0700540 if (setSelected) {
541 selectTab(tab);
542 }
Adam Powell661c9082010-07-02 10:09:44 -0700543 }
544
545 @Override
546 public Tab newTab() {
547 return new TabImpl();
548 }
549
550 @Override
551 public void removeTab(Tab tab) {
552 removeTabAt(tab.getPosition());
553 }
554
555 @Override
556 public void removeTabAt(int position) {
Adam Powellf8ac6b72011-05-23 18:14:09 -0700557 if (mTabScrollView == null) {
558 // No tabs around to remove
559 return;
560 }
561
Adam Powell0c24a552010-11-03 16:44:11 -0700562 int selectedTabPosition = mSelectedTab != null
563 ? mSelectedTab.getPosition() : mSavedTabPosition;
Adam Powellf8ac6b72011-05-23 18:14:09 -0700564 mTabScrollView.removeTabAt(position);
Adam Powell0d8ec1d2011-05-03 14:49:13 -0700565 TabImpl removedTab = mTabs.remove(position);
566 if (removedTab != null) {
567 removedTab.setPosition(-1);
568 }
Adam Powell661c9082010-07-02 10:09:44 -0700569
570 final int newTabCount = mTabs.size();
571 for (int i = position; i < newTabCount; i++) {
572 mTabs.get(i).setPosition(i);
573 }
574
Adam Powell0c24a552010-11-03 16:44:11 -0700575 if (selectedTabPosition == position) {
576 selectTab(mTabs.isEmpty() ? null : mTabs.get(Math.max(0, position - 1)));
577 }
Adam Powell661c9082010-07-02 10:09:44 -0700578 }
579
580 @Override
Adam Powell661c9082010-07-02 10:09:44 -0700581 public void selectTab(Tab tab) {
Adam Powell0c24a552010-11-03 16:44:11 -0700582 if (getNavigationMode() != NAVIGATION_MODE_TABS) {
583 mSavedTabPosition = tab != null ? tab.getPosition() : INVALID_POSITION;
584 return;
585 }
586
Adam Powell76d14662014-05-30 10:28:14 -0700587 final FragmentTransaction trans = mDecorToolbar.getViewGroup().isInEditMode() ? null :
Deepanshu Gupta14bf0ce2013-12-12 12:16:24 -0800588 mActivity.getFragmentManager().beginTransaction().disallowAddToBackStack();
Adam Powell7f9b9052010-10-19 16:56:07 -0700589
590 if (mSelectedTab == tab) {
591 if (mSelectedTab != null) {
592 mSelectedTab.getCallback().onTabReselected(mSelectedTab, trans);
Adam Powellf8ac6b72011-05-23 18:14:09 -0700593 mTabScrollView.animateToTab(tab.getPosition());
Adam Powell7f9b9052010-10-19 16:56:07 -0700594 }
595 } else {
Adam Powellf8ac6b72011-05-23 18:14:09 -0700596 mTabScrollView.setTabSelected(tab != null ? tab.getPosition() : Tab.INVALID_POSITION);
Adam Powell7f9b9052010-10-19 16:56:07 -0700597 if (mSelectedTab != null) {
598 mSelectedTab.getCallback().onTabUnselected(mSelectedTab, trans);
599 }
600 mSelectedTab = (TabImpl) tab;
601 if (mSelectedTab != null) {
602 mSelectedTab.getCallback().onTabSelected(mSelectedTab, trans);
603 }
Adam Powell2b6230e2010-09-07 17:55:25 -0700604 }
605
Deepanshu Gupta14bf0ce2013-12-12 12:16:24 -0800606 if (trans != null && !trans.isEmpty()) {
Adam Powell2b6230e2010-09-07 17:55:25 -0700607 trans.commit();
608 }
609 }
610
611 @Override
612 public Tab getSelectedTab() {
613 return mSelectedTab;
Adam Powell661c9082010-07-02 10:09:44 -0700614 }
615
Adam Powell6b336f82010-08-10 20:13:01 -0700616 @Override
617 public int getHeight() {
Adam Powell58c5dc12011-07-14 21:08:10 -0700618 return mContainerView.getHeight();
Adam Powell6b336f82010-08-10 20:13:01 -0700619 }
620
Dianne Hackborndf7221c2013-02-26 14:53:55 -0800621 public void enableContentAnimations(boolean enabled) {
622 mContentAnimations = enabled;
623 }
624
Adam Powell6b336f82010-08-10 20:13:01 -0700625 @Override
626 public void show() {
Dianne Hackborn139e5aa2012-05-05 20:36:38 -0700627 if (mHiddenByApp) {
628 mHiddenByApp = false;
629 updateVisibility(false);
630 }
Adam Powell07e1f982011-03-24 11:11:15 -0700631 }
632
Dianne Hackborn139e5aa2012-05-05 20:36:38 -0700633 private void showForActionMode() {
634 if (!mShowingForMode) {
635 mShowingForMode = true;
636 if (mOverlayLayout != null) {
637 mOverlayLayout.setShowingForActionMode(true);
638 }
639 updateVisibility(false);
640 }
641 }
642
643 public void showForSystem() {
644 if (mHiddenBySystem) {
645 mHiddenBySystem = false;
646 updateVisibility(true);
647 }
648 }
649
650 @Override
651 public void hide() {
652 if (!mHiddenByApp) {
653 mHiddenByApp = true;
654 updateVisibility(false);
655 }
656 }
657
658 private void hideForActionMode() {
659 if (mShowingForMode) {
660 mShowingForMode = false;
661 if (mOverlayLayout != null) {
662 mOverlayLayout.setShowingForActionMode(false);
663 }
664 updateVisibility(false);
665 }
666 }
667
668 public void hideForSystem() {
669 if (!mHiddenBySystem) {
670 mHiddenBySystem = true;
671 updateVisibility(true);
672 }
673 }
674
Adam Powellb36e4f92014-05-01 10:23:33 -0700675 @Override
676 public void setHideOnContentScrollEnabled(boolean hideOnContentScroll) {
677 if (hideOnContentScroll && !mOverlayLayout.isInOverlayMode()) {
678 throw new IllegalStateException("Action bar must be in overlay mode " +
679 "(Window.FEATURE_OVERLAY_ACTION_BAR) to enable hide on content scroll");
680 }
681 mHideOnContentScroll = hideOnContentScroll;
682 mOverlayLayout.setHideOnContentScrollEnabled(hideOnContentScroll);
683 }
684
685 @Override
686 public boolean isHideOnContentScrollEnabled() {
687 return mOverlayLayout.isHideOnContentScrollEnabled();
688 }
689
690 @Override
691 public int getHideOffset() {
692 return mOverlayLayout.getActionBarHideOffset();
693 }
694
695 @Override
696 public void setHideOffset(int offset) {
697 if (offset != 0 && !mOverlayLayout.isInOverlayMode()) {
698 throw new IllegalStateException("Action bar must be in overlay mode " +
699 "(Window.FEATURE_OVERLAY_ACTION_BAR) to set a non-zero hide offset");
700 }
701 mOverlayLayout.setActionBarHideOffset(offset);
702 }
703
Dianne Hackborn139e5aa2012-05-05 20:36:38 -0700704 private static boolean checkShowingFlags(boolean hiddenByApp, boolean hiddenBySystem,
705 boolean showingForMode) {
706 if (showingForMode) {
707 return true;
708 } else if (hiddenByApp || hiddenBySystem) {
709 return false;
710 } else {
711 return true;
712 }
713 }
714
715 private void updateVisibility(boolean fromSystem) {
716 // Based on the current state, should we be hidden or shown?
717 final boolean shown = checkShowingFlags(mHiddenByApp, mHiddenBySystem,
718 mShowingForMode);
719
720 if (shown) {
721 if (!mNowShowing) {
722 mNowShowing = true;
723 doShow(fromSystem);
724 }
725 } else {
726 if (mNowShowing) {
727 mNowShowing = false;
728 doHide(fromSystem);
729 }
730 }
731 }
732
733 public void doShow(boolean fromSystem) {
Adam Powell07e1f982011-03-24 11:11:15 -0700734 if (mCurrentShowAnim != null) {
735 mCurrentShowAnim.end();
Adam Powell45f1e082010-12-10 14:20:13 -0800736 }
Adam Powell9b0dc282013-07-31 13:58:43 -0700737 mContainerView.setVisibility(View.VISIBLE);
Adam Powell50efbed2011-02-08 16:20:15 -0800738
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700739 if (mCurWindowVisibility == View.VISIBLE && (mShowHideAnimationEnabled
Dianne Hackborn139e5aa2012-05-05 20:36:38 -0700740 || fromSystem)) {
Adam Powell9b0dc282013-07-31 13:58:43 -0700741 mContainerView.setTranslationY(0); // because we're about to ask its window loc
742 float startingY = -mContainerView.getHeight();
Chet Haasee8118e12012-05-30 14:19:02 -0700743 if (fromSystem) {
744 int topLeft[] = {0, 0};
Adam Powell9b0dc282013-07-31 13:58:43 -0700745 mContainerView.getLocationInWindow(topLeft);
Chet Haasee8118e12012-05-30 14:19:02 -0700746 startingY -= topLeft[1];
747 }
Adam Powell9b0dc282013-07-31 13:58:43 -0700748 mContainerView.setTranslationY(startingY);
Adam Powell50efbed2011-02-08 16:20:15 -0800749 AnimatorSet anim = new AnimatorSet();
Adam Powell9b0dc282013-07-31 13:58:43 -0700750 ObjectAnimator a = ObjectAnimator.ofFloat(mContainerView, View.TRANSLATION_Y, 0);
751 a.addUpdateListener(mUpdateListener);
752 AnimatorSet.Builder b = anim.play(a);
Dianne Hackborndf7221c2013-02-26 14:53:55 -0800753 if (mContentAnimations && mContentView != null) {
Adam Powell9b0dc282013-07-31 13:58:43 -0700754 b.with(ObjectAnimator.ofFloat(mContentView, View.TRANSLATION_Y,
Chet Haasee8118e12012-05-30 14:19:02 -0700755 startingY, 0));
Adam Powell50efbed2011-02-08 16:20:15 -0800756 }
Adam Powell1ab418a2011-06-09 20:49:49 -0700757 if (mSplitView != null && mContextDisplayMode == CONTEXT_DISPLAY_SPLIT) {
Dianne Hackborn8eedb8b2012-04-16 19:31:58 -0700758 mSplitView.setTranslationY(mSplitView.getHeight());
Adam Powell993a63a2011-08-18 16:35:53 -0700759 mSplitView.setVisibility(View.VISIBLE);
Adam Powell9b0dc282013-07-31 13:58:43 -0700760 b.with(ObjectAnimator.ofFloat(mSplitView, View.TRANSLATION_Y, 0));
Adam Powell640a66e2011-04-29 10:18:53 -0700761 }
Dianne Hackborn8eedb8b2012-04-16 19:31:58 -0700762 anim.setInterpolator(AnimationUtils.loadInterpolator(mContext,
Chet Haasee8118e12012-05-30 14:19:02 -0700763 com.android.internal.R.interpolator.decelerate_cubic));
764 anim.setDuration(250);
Dianne Hackborn139e5aa2012-05-05 20:36:38 -0700765 // If this is being shown from the system, add a small delay.
766 // This is because we will also be animating in the status bar,
767 // and these two elements can't be done in lock-step. So we give
768 // a little time for the status bar to start its animation before
769 // the action bar animates. (This corresponds to the corresponding
770 // case when hiding, where the status bar has a small delay before
771 // starting.)
Adam Powell50efbed2011-02-08 16:20:15 -0800772 anim.addListener(mShowListener);
Adam Powell07e1f982011-03-24 11:11:15 -0700773 mCurrentShowAnim = anim;
Adam Powell50efbed2011-02-08 16:20:15 -0800774 anim.start();
775 } else {
Adam Powell9b0dc282013-07-31 13:58:43 -0700776 mContainerView.setAlpha(1);
777 mContainerView.setTranslationY(0);
Dianne Hackborndf7221c2013-02-26 14:53:55 -0800778 if (mContentAnimations && mContentView != null) {
Dianne Hackborn80d55062012-05-22 18:03:20 -0700779 mContentView.setTranslationY(0);
780 }
781 if (mSplitView != null && mContextDisplayMode == CONTEXT_DISPLAY_SPLIT) {
782 mSplitView.setAlpha(1);
783 mSplitView.setTranslationY(0);
784 mSplitView.setVisibility(View.VISIBLE);
785 }
Adam Powell50efbed2011-02-08 16:20:15 -0800786 mShowListener.onAnimationEnd(null);
Adam Powelle6ec7322010-12-07 15:29:26 -0800787 }
Dianne Hackborn139e5aa2012-05-05 20:36:38 -0700788 if (mOverlayLayout != null) {
Adam Powellb36e4f92014-05-01 10:23:33 -0700789 mOverlayLayout.requestApplyInsets();
Dianne Hackborn139e5aa2012-05-05 20:36:38 -0700790 }
Adam Powell6b336f82010-08-10 20:13:01 -0700791 }
792
Dianne Hackborn139e5aa2012-05-05 20:36:38 -0700793 public void doHide(boolean fromSystem) {
Adam Powell07e1f982011-03-24 11:11:15 -0700794 if (mCurrentShowAnim != null) {
795 mCurrentShowAnim.end();
Adam Powelle6ec7322010-12-07 15:29:26 -0800796 }
Adam Powell50efbed2011-02-08 16:20:15 -0800797
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700798 if (mCurWindowVisibility == View.VISIBLE && (mShowHideAnimationEnabled
Dianne Hackborn139e5aa2012-05-05 20:36:38 -0700799 || fromSystem)) {
Adam Powell9b0dc282013-07-31 13:58:43 -0700800 mContainerView.setAlpha(1);
Adam Powell01feaee2011-02-10 15:05:05 -0800801 mContainerView.setTransitioning(true);
Adam Powell50efbed2011-02-08 16:20:15 -0800802 AnimatorSet anim = new AnimatorSet();
Adam Powell9b0dc282013-07-31 13:58:43 -0700803 float endingY = -mContainerView.getHeight();
Chet Haasee8118e12012-05-30 14:19:02 -0700804 if (fromSystem) {
805 int topLeft[] = {0, 0};
Adam Powell9b0dc282013-07-31 13:58:43 -0700806 mContainerView.getLocationInWindow(topLeft);
Chet Haasee8118e12012-05-30 14:19:02 -0700807 endingY -= topLeft[1];
808 }
Adam Powell9b0dc282013-07-31 13:58:43 -0700809 ObjectAnimator a = ObjectAnimator.ofFloat(mContainerView, View.TRANSLATION_Y, endingY);
810 a.addUpdateListener(mUpdateListener);
811 AnimatorSet.Builder b = anim.play(a);
Dianne Hackborndf7221c2013-02-26 14:53:55 -0800812 if (mContentAnimations && mContentView != null) {
Adam Powell9b0dc282013-07-31 13:58:43 -0700813 b.with(ObjectAnimator.ofFloat(mContentView, View.TRANSLATION_Y,
Chet Haasee8118e12012-05-30 14:19:02 -0700814 0, endingY));
Adam Powell50efbed2011-02-08 16:20:15 -0800815 }
Adam Powell1ab418a2011-06-09 20:49:49 -0700816 if (mSplitView != null && mSplitView.getVisibility() == View.VISIBLE) {
Adam Powell640a66e2011-04-29 10:18:53 -0700817 mSplitView.setAlpha(1);
Adam Powell9b0dc282013-07-31 13:58:43 -0700818 b.with(ObjectAnimator.ofFloat(mSplitView, View.TRANSLATION_Y,
Dianne Hackborn8eedb8b2012-04-16 19:31:58 -0700819 mSplitView.getHeight()));
Adam Powell640a66e2011-04-29 10:18:53 -0700820 }
Dianne Hackborn8eedb8b2012-04-16 19:31:58 -0700821 anim.setInterpolator(AnimationUtils.loadInterpolator(mContext,
Chet Haasee8118e12012-05-30 14:19:02 -0700822 com.android.internal.R.interpolator.accelerate_cubic));
823 anim.setDuration(250);
Adam Powell50efbed2011-02-08 16:20:15 -0800824 anim.addListener(mHideListener);
Adam Powell07e1f982011-03-24 11:11:15 -0700825 mCurrentShowAnim = anim;
Adam Powell50efbed2011-02-08 16:20:15 -0800826 anim.start();
827 } else {
828 mHideListener.onAnimationEnd(null);
Adam Powelle6ec7322010-12-07 15:29:26 -0800829 }
Adam Powell6b336f82010-08-10 20:13:01 -0700830 }
831
832 public boolean isShowing() {
Adam Powellf65bfb72014-06-19 10:55:28 -0700833 final int height = getHeight();
834 // Take into account the case where the bar has a 0 height due to not being measured yet.
835 return mNowShowing && (height == 0 || getHideOffset() < height);
Adam Powelld8b3f2e2010-12-02 13:37:03 -0800836 }
837
Adam Powell640a66e2011-04-29 10:18:53 -0700838 void animateToMode(boolean toActionMode) {
Adam Powell060e3ca2011-07-19 20:39:16 -0700839 if (toActionMode) {
Dianne Hackborn139e5aa2012-05-05 20:36:38 -0700840 showForActionMode();
841 } else {
842 hideForActionMode();
Adam Powell07e1f982011-03-24 11:11:15 -0700843 }
Adam Powelld8b3f2e2010-12-02 13:37:03 -0800844
Adam Powelle021e6e2014-05-23 17:27:24 -0700845 mDecorToolbar.animateToVisibility(toActionMode ? View.GONE : View.VISIBLE);
Adam Powell640a66e2011-04-29 10:18:53 -0700846 mContextView.animateToVisibility(toActionMode ? View.VISIBLE : View.GONE);
Adam Powelle021e6e2014-05-23 17:27:24 -0700847 if (mTabScrollView != null && !mDecorToolbar.hasEmbeddedTabs() &&
Adam Powell76d14662014-05-30 10:28:14 -0700848 isCollapsed(mDecorToolbar.getViewGroup())) {
Adam Powellf6ce6a92011-06-29 10:25:01 -0700849 mTabScrollView.animateToVisibility(toActionMode ? View.GONE : View.VISIBLE);
850 }
Adam Powell6b336f82010-08-10 20:13:01 -0700851 }
852
Adam Powelle021e6e2014-05-23 17:27:24 -0700853 private boolean isCollapsed(View view) {
854 return view == null || view.getVisibility() == View.GONE || view.getMeasuredHeight() == 0;
855 }
856
Adam Powell88ab6972011-07-28 11:25:01 -0700857 public Context getThemedContext() {
858 if (mThemedContext == null) {
859 TypedValue outValue = new TypedValue();
860 Resources.Theme currentTheme = mContext.getTheme();
861 currentTheme.resolveAttribute(com.android.internal.R.attr.actionBarWidgetTheme,
862 outValue, true);
863 final int targetThemeRes = outValue.resourceId;
864
865 if (targetThemeRes != 0 && mContext.getThemeResId() != targetThemeRes) {
866 mThemedContext = new ContextThemeWrapper(mContext, targetThemeRes);
867 } else {
868 mThemedContext = mContext;
869 }
870 }
871 return mThemedContext;
872 }
873
Adam Powell27cba382013-01-22 18:55:20 -0800874 @Override
875 public boolean isTitleTruncated() {
Adam Powelle021e6e2014-05-23 17:27:24 -0700876 return mDecorToolbar != null && mDecorToolbar.isTitleTruncated();
Adam Powell27cba382013-01-22 18:55:20 -0800877 }
878
Adam Powelle0e2f4f2013-04-05 16:27:35 -0700879 @Override
880 public void setHomeAsUpIndicator(Drawable indicator) {
Adam Powelle021e6e2014-05-23 17:27:24 -0700881 mDecorToolbar.setNavigationIcon(indicator);
Adam Powelle0e2f4f2013-04-05 16:27:35 -0700882 }
883
884 @Override
885 public void setHomeAsUpIndicator(int resId) {
Adam Powelle021e6e2014-05-23 17:27:24 -0700886 mDecorToolbar.setNavigationIcon(resId);
Adam Powelle0e2f4f2013-04-05 16:27:35 -0700887 }
888
889 @Override
890 public void setHomeActionContentDescription(CharSequence description) {
Adam Powelle021e6e2014-05-23 17:27:24 -0700891 mDecorToolbar.setNavigationContentDescription(description);
Adam Powelle0e2f4f2013-04-05 16:27:35 -0700892 }
893
894 @Override
895 public void setHomeActionContentDescription(int resId) {
Adam Powelle021e6e2014-05-23 17:27:24 -0700896 mDecorToolbar.setNavigationContentDescription(resId);
Adam Powelle0e2f4f2013-04-05 16:27:35 -0700897 }
898
Adam Powellb36e4f92014-05-01 10:23:33 -0700899 @Override
900 public void onContentScrollStarted() {
901 if (mCurrentShowAnim != null) {
902 mCurrentShowAnim.cancel();
903 mCurrentShowAnim = null;
904 }
905 }
906
907 @Override
908 public void onContentScrollStopped() {
909 }
910
Adam Powell89e06452010-06-23 20:24:52 -0700911 /**
912 * @hide
913 */
Adam Powell5d279772010-07-27 16:34:07 -0700914 public class ActionModeImpl extends ActionMode implements MenuBuilder.Callback {
Adam Powell6e346362010-07-23 10:18:23 -0700915 private ActionMode.Callback mCallback;
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700916 private MenuBuilder mMenu;
Adam Powell29ed7572010-07-14 16:24:56 -0700917 private WeakReference<View> mCustomView;
Adam Powell89e06452010-06-23 20:24:52 -0700918
Adam Powell5d279772010-07-27 16:34:07 -0700919 public ActionModeImpl(ActionMode.Callback callback) {
Adam Powell89e06452010-06-23 20:24:52 -0700920 mCallback = callback;
Adam Powellf2423682011-08-11 14:29:45 -0700921 mMenu = new MenuBuilder(getThemedContext())
Adam Powell4d9861e2010-08-17 11:14:40 -0700922 .setDefaultShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
Adam Powell2c9c9fe2010-07-16 10:17:57 -0700923 mMenu.setCallback(this);
Adam Powell89e06452010-06-23 20:24:52 -0700924 }
Adam Powell9168f0b2010-08-02 15:46:24 -0700925
926 @Override
927 public MenuInflater getMenuInflater() {
Adam Powellf2423682011-08-11 14:29:45 -0700928 return new MenuInflater(getThemedContext());
Adam Powell9168f0b2010-08-02 15:46:24 -0700929 }
930
Adam Powell89e06452010-06-23 20:24:52 -0700931 @Override
932 public Menu getMenu() {
933 return mMenu;
934 }
935
936 @Override
937 public void finish() {
Adam Powell5d279772010-07-27 16:34:07 -0700938 if (mActionMode != this) {
939 // Not the active action mode - no-op
Adam Powell93b6bc32010-07-22 11:36:35 -0700940 return;
941 }
942
Dianne Hackborn139e5aa2012-05-05 20:36:38 -0700943 // If this change in state is going to cause the action bar
944 // to be hidden, defer the onDestroy callback until the animation
945 // is finished and associated relayout is about to happen. This lets
946 // apps better anticipate visibility and layout behavior.
947 if (!checkShowingFlags(mHiddenByApp, mHiddenBySystem, false)) {
948 // With the current state but the action bar hidden, our
949 // overall showing state is going to be false.
Adam Powell060e3ca2011-07-19 20:39:16 -0700950 mDeferredDestroyActionMode = this;
951 mDeferredModeDestroyCallback = mCallback;
952 } else {
953 mCallback.onDestroyActionMode(this);
954 }
Adam Powelld8b3f2e2010-12-02 13:37:03 -0800955 mCallback = null;
Adam Powell640a66e2011-04-29 10:18:53 -0700956 animateToMode(false);
Adam Powell0e94b512010-06-29 17:58:20 -0700957
958 // Clear out the context mode views after the animation finishes
Adam Powell640a66e2011-04-29 10:18:53 -0700959 mContextView.closeMode();
Adam Powell76d14662014-05-30 10:28:14 -0700960 mDecorToolbar.getViewGroup().sendAccessibilityEvent(
Adam Powelle021e6e2014-05-23 17:27:24 -0700961 AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Adam Powellb36e4f92014-05-01 10:23:33 -0700962 mOverlayLayout.setHideOnContentScrollEnabled(mHideOnContentScroll);
Adam Powellf6ce6a92011-06-29 10:25:01 -0700963
Adam Powell5d279772010-07-27 16:34:07 -0700964 mActionMode = null;
Adam Powell89e06452010-06-23 20:24:52 -0700965 }
966
967 @Override
968 public void invalidate() {
Adam Powell5ee36c42011-06-02 12:59:43 -0700969 mMenu.stopDispatchingItemsChanged();
970 try {
971 mCallback.onPrepareActionMode(this, mMenu);
972 } finally {
973 mMenu.startDispatchingItemsChanged();
974 }
975 }
976
977 public boolean dispatchOnCreate() {
978 mMenu.stopDispatchingItemsChanged();
979 try {
980 return mCallback.onCreateActionMode(this, mMenu);
981 } finally {
982 mMenu.startDispatchingItemsChanged();
Adam Powell89e06452010-06-23 20:24:52 -0700983 }
984 }
985
986 @Override
987 public void setCustomView(View view) {
Adam Powell640a66e2011-04-29 10:18:53 -0700988 mContextView.setCustomView(view);
Adam Powell29ed7572010-07-14 16:24:56 -0700989 mCustomView = new WeakReference<View>(view);
Adam Powell89e06452010-06-23 20:24:52 -0700990 }
991
992 @Override
993 public void setSubtitle(CharSequence subtitle) {
Adam Powell640a66e2011-04-29 10:18:53 -0700994 mContextView.setSubtitle(subtitle);
Adam Powell89e06452010-06-23 20:24:52 -0700995 }
996
997 @Override
998 public void setTitle(CharSequence title) {
Adam Powell640a66e2011-04-29 10:18:53 -0700999 mContextView.setTitle(title);
Adam Powell89e06452010-06-23 20:24:52 -07001000 }
Adam Powell29ed7572010-07-14 16:24:56 -07001001
1002 @Override
Adam Powellc9ae2a22010-07-28 14:44:21 -07001003 public void setTitle(int resId) {
Adam Powell48e8ac32011-01-14 12:10:24 -08001004 setTitle(mContext.getResources().getString(resId));
Adam Powellc9ae2a22010-07-28 14:44:21 -07001005 }
1006
1007 @Override
1008 public void setSubtitle(int resId) {
Adam Powell48e8ac32011-01-14 12:10:24 -08001009 setSubtitle(mContext.getResources().getString(resId));
Adam Powellc9ae2a22010-07-28 14:44:21 -07001010 }
1011
1012 @Override
Adam Powell29ed7572010-07-14 16:24:56 -07001013 public CharSequence getTitle() {
Adam Powell640a66e2011-04-29 10:18:53 -07001014 return mContextView.getTitle();
Adam Powell29ed7572010-07-14 16:24:56 -07001015 }
1016
1017 @Override
1018 public CharSequence getSubtitle() {
Adam Powell640a66e2011-04-29 10:18:53 -07001019 return mContextView.getSubtitle();
Adam Powell29ed7572010-07-14 16:24:56 -07001020 }
Adam Powell89e06452010-06-23 20:24:52 -07001021
Adam Powell29ed7572010-07-14 16:24:56 -07001022 @Override
Adam Powellb98a81f2012-02-24 11:09:07 -08001023 public void setTitleOptionalHint(boolean titleOptional) {
Adam Powell785c4472012-05-02 21:25:39 -07001024 super.setTitleOptionalHint(titleOptional);
Adam Powellb98a81f2012-02-24 11:09:07 -08001025 mContextView.setTitleOptional(titleOptional);
1026 }
1027
1028 @Override
1029 public boolean isTitleOptional() {
1030 return mContextView.isTitleOptional();
1031 }
1032
1033 @Override
Adam Powell29ed7572010-07-14 16:24:56 -07001034 public View getCustomView() {
1035 return mCustomView != null ? mCustomView.get() : null;
1036 }
1037
Adam Powell2c9c9fe2010-07-16 10:17:57 -07001038 public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
Adam Powelld8b3f2e2010-12-02 13:37:03 -08001039 if (mCallback != null) {
1040 return mCallback.onActionItemClicked(this, item);
1041 } else {
1042 return false;
1043 }
Adam Powell2c9c9fe2010-07-16 10:17:57 -07001044 }
1045
1046 public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) {
1047 }
1048
1049 public boolean onSubMenuSelected(SubMenuBuilder subMenu) {
Adam Powelld8b3f2e2010-12-02 13:37:03 -08001050 if (mCallback == null) {
1051 return false;
1052 }
1053
Adam Powell2c9c9fe2010-07-16 10:17:57 -07001054 if (!subMenu.hasVisibleItems()) {
1055 return true;
Adam Powell89e06452010-06-23 20:24:52 -07001056 }
Adam Powell2c9c9fe2010-07-16 10:17:57 -07001057
Adam Powellf2423682011-08-11 14:29:45 -07001058 new MenuPopupHelper(getThemedContext(), subMenu).show();
Adam Powell2c9c9fe2010-07-16 10:17:57 -07001059 return true;
1060 }
1061
1062 public void onCloseSubMenu(SubMenuBuilder menu) {
1063 }
1064
1065 public void onMenuModeChange(MenuBuilder menu) {
Adam Powelld8b3f2e2010-12-02 13:37:03 -08001066 if (mCallback == null) {
1067 return;
1068 }
Adam Powellf6148c52010-08-11 21:10:16 -07001069 invalidate();
Adam Powell640a66e2011-04-29 10:18:53 -07001070 mContextView.showOverflowMenu();
Adam Powell2c9c9fe2010-07-16 10:17:57 -07001071 }
Adam Powell661c9082010-07-02 10:09:44 -07001072 }
1073
1074 /**
1075 * @hide
1076 */
1077 public class TabImpl extends ActionBar.Tab {
Adam Powell2b6230e2010-09-07 17:55:25 -07001078 private ActionBar.TabListener mCallback;
1079 private Object mTag;
Adam Powell661c9082010-07-02 10:09:44 -07001080 private Drawable mIcon;
1081 private CharSequence mText;
Adam Powell94e56ef2011-09-06 21:22:22 -07001082 private CharSequence mContentDesc;
Adam Powell0d8ec1d2011-05-03 14:49:13 -07001083 private int mPosition = -1;
Adam Powell2b6230e2010-09-07 17:55:25 -07001084 private View mCustomView;
Adam Powell661c9082010-07-02 10:09:44 -07001085
1086 @Override
Adam Powell2b6230e2010-09-07 17:55:25 -07001087 public Object getTag() {
1088 return mTag;
1089 }
1090
1091 @Override
Adam Powell9ab97872010-10-26 21:47:29 -07001092 public Tab setTag(Object tag) {
Adam Powell2b6230e2010-09-07 17:55:25 -07001093 mTag = tag;
Adam Powell9ab97872010-10-26 21:47:29 -07001094 return this;
Adam Powell2b6230e2010-09-07 17:55:25 -07001095 }
1096
1097 public ActionBar.TabListener getCallback() {
1098 return mCallback;
1099 }
1100
1101 @Override
Adam Powell9ab97872010-10-26 21:47:29 -07001102 public Tab setTabListener(ActionBar.TabListener callback) {
Adam Powell2b6230e2010-09-07 17:55:25 -07001103 mCallback = callback;
Adam Powell9ab97872010-10-26 21:47:29 -07001104 return this;
Adam Powell2b6230e2010-09-07 17:55:25 -07001105 }
1106
1107 @Override
1108 public View getCustomView() {
1109 return mCustomView;
1110 }
1111
1112 @Override
Adam Powell9ab97872010-10-26 21:47:29 -07001113 public Tab setCustomView(View view) {
Adam Powell2b6230e2010-09-07 17:55:25 -07001114 mCustomView = view;
Adam Powellf8ac6b72011-05-23 18:14:09 -07001115 if (mPosition >= 0) {
1116 mTabScrollView.updateTab(mPosition);
1117 }
Adam Powell9ab97872010-10-26 21:47:29 -07001118 return this;
Adam Powell661c9082010-07-02 10:09:44 -07001119 }
1120
1121 @Override
Adam Powell32555f32010-11-17 13:49:22 -08001122 public Tab setCustomView(int layoutResId) {
Adam Powellf2423682011-08-11 14:29:45 -07001123 return setCustomView(LayoutInflater.from(getThemedContext())
1124 .inflate(layoutResId, null));
Adam Powell32555f32010-11-17 13:49:22 -08001125 }
1126
1127 @Override
Adam Powell661c9082010-07-02 10:09:44 -07001128 public Drawable getIcon() {
1129 return mIcon;
1130 }
1131
1132 @Override
1133 public int getPosition() {
1134 return mPosition;
1135 }
1136
1137 public void setPosition(int position) {
1138 mPosition = position;
1139 }
1140
1141 @Override
1142 public CharSequence getText() {
1143 return mText;
1144 }
1145
1146 @Override
Adam Powell9ab97872010-10-26 21:47:29 -07001147 public Tab setIcon(Drawable icon) {
Adam Powell661c9082010-07-02 10:09:44 -07001148 mIcon = icon;
Adam Powellf8ac6b72011-05-23 18:14:09 -07001149 if (mPosition >= 0) {
1150 mTabScrollView.updateTab(mPosition);
1151 }
Adam Powell9ab97872010-10-26 21:47:29 -07001152 return this;
Adam Powell661c9082010-07-02 10:09:44 -07001153 }
1154
1155 @Override
Adam Powell32555f32010-11-17 13:49:22 -08001156 public Tab setIcon(int resId) {
Alan Viverette8eea3ea2014-02-03 18:40:20 -08001157 return setIcon(mContext.getDrawable(resId));
Adam Powell32555f32010-11-17 13:49:22 -08001158 }
1159
1160 @Override
Adam Powell9ab97872010-10-26 21:47:29 -07001161 public Tab setText(CharSequence text) {
Adam Powell661c9082010-07-02 10:09:44 -07001162 mText = text;
Adam Powellf8ac6b72011-05-23 18:14:09 -07001163 if (mPosition >= 0) {
1164 mTabScrollView.updateTab(mPosition);
1165 }
Adam Powell9ab97872010-10-26 21:47:29 -07001166 return this;
Adam Powell661c9082010-07-02 10:09:44 -07001167 }
1168
1169 @Override
Adam Powell32555f32010-11-17 13:49:22 -08001170 public Tab setText(int resId) {
1171 return setText(mContext.getResources().getText(resId));
1172 }
1173
1174 @Override
Adam Powell661c9082010-07-02 10:09:44 -07001175 public void select() {
1176 selectTab(this);
Adam Powell89e06452010-06-23 20:24:52 -07001177 }
Adam Powell94e56ef2011-09-06 21:22:22 -07001178
1179 @Override
1180 public Tab setContentDescription(int resId) {
1181 return setContentDescription(mContext.getResources().getText(resId));
1182 }
1183
1184 @Override
1185 public Tab setContentDescription(CharSequence contentDesc) {
1186 mContentDesc = contentDesc;
1187 if (mPosition >= 0) {
1188 mTabScrollView.updateTab(mPosition);
1189 }
1190 return this;
1191 }
1192
1193 @Override
1194 public CharSequence getContentDescription() {
1195 return mContentDesc;
1196 }
Adam Powell89e06452010-06-23 20:24:52 -07001197 }
Adam Powell9ab97872010-10-26 21:47:29 -07001198
1199 @Override
1200 public void setCustomView(View view) {
Adam Powelle021e6e2014-05-23 17:27:24 -07001201 mDecorToolbar.setCustomView(view);
Adam Powell9ab97872010-10-26 21:47:29 -07001202 }
1203
1204 @Override
1205 public void setCustomView(View view, LayoutParams layoutParams) {
1206 view.setLayoutParams(layoutParams);
Adam Powelle021e6e2014-05-23 17:27:24 -07001207 mDecorToolbar.setCustomView(view);
Adam Powell9ab97872010-10-26 21:47:29 -07001208 }
1209
1210 @Override
Adam Powell8515ee82010-11-30 14:09:55 -08001211 public void setListNavigationCallbacks(SpinnerAdapter adapter, OnNavigationListener callback) {
Adam Powelle021e6e2014-05-23 17:27:24 -07001212 mDecorToolbar.setDropdownParams(adapter, new NavItemSelectedListener(callback));
Adam Powell9ab97872010-10-26 21:47:29 -07001213 }
1214
1215 @Override
1216 public int getSelectedNavigationIndex() {
Adam Powelle021e6e2014-05-23 17:27:24 -07001217 switch (mDecorToolbar.getNavigationMode()) {
Adam Powell9ab97872010-10-26 21:47:29 -07001218 case NAVIGATION_MODE_TABS:
Adam Powell04587962010-11-11 22:15:07 -08001219 return mSelectedTab != null ? mSelectedTab.getPosition() : -1;
Adam Powell9ab97872010-10-26 21:47:29 -07001220 case NAVIGATION_MODE_LIST:
Adam Powelle021e6e2014-05-23 17:27:24 -07001221 return mDecorToolbar.getDropdownSelectedPosition();
Adam Powell9ab97872010-10-26 21:47:29 -07001222 default:
1223 return -1;
1224 }
1225 }
1226
1227 @Override
1228 public int getNavigationItemCount() {
Adam Powelle021e6e2014-05-23 17:27:24 -07001229 switch (mDecorToolbar.getNavigationMode()) {
Adam Powell9ab97872010-10-26 21:47:29 -07001230 case NAVIGATION_MODE_TABS:
1231 return mTabs.size();
1232 case NAVIGATION_MODE_LIST:
Adam Powelle021e6e2014-05-23 17:27:24 -07001233 return mDecorToolbar.getDropdownItemCount();
Adam Powell9ab97872010-10-26 21:47:29 -07001234 default:
1235 return 0;
1236 }
1237 }
1238
1239 @Override
Adam Powell0c24a552010-11-03 16:44:11 -07001240 public int getTabCount() {
1241 return mTabs.size();
1242 }
1243
1244 @Override
Adam Powell9ab97872010-10-26 21:47:29 -07001245 public void setNavigationMode(int mode) {
Adam Powelle021e6e2014-05-23 17:27:24 -07001246 final int oldMode = mDecorToolbar.getNavigationMode();
Adam Powell0c24a552010-11-03 16:44:11 -07001247 switch (oldMode) {
1248 case NAVIGATION_MODE_TABS:
1249 mSavedTabPosition = getSelectedNavigationIndex();
1250 selectTab(null);
Adam Powellf5645cb2011-08-10 22:49:02 -07001251 mTabScrollView.setVisibility(View.GONE);
Adam Powell0c24a552010-11-03 16:44:11 -07001252 break;
1253 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07001254 if (oldMode != mode && !mHasEmbeddedTabs) {
1255 if (mOverlayLayout != null) {
1256 mOverlayLayout.requestFitSystemWindows();
1257 }
1258 }
Adam Powelle021e6e2014-05-23 17:27:24 -07001259 mDecorToolbar.setNavigationMode(mode);
Adam Powell0c24a552010-11-03 16:44:11 -07001260 switch (mode) {
1261 case NAVIGATION_MODE_TABS:
Adam Powellf8ac6b72011-05-23 18:14:09 -07001262 ensureTabsExist();
Adam Powellf5645cb2011-08-10 22:49:02 -07001263 mTabScrollView.setVisibility(View.VISIBLE);
Adam Powell0c24a552010-11-03 16:44:11 -07001264 if (mSavedTabPosition != INVALID_POSITION) {
1265 setSelectedNavigationItem(mSavedTabPosition);
1266 mSavedTabPosition = INVALID_POSITION;
1267 }
1268 break;
1269 }
Adam Powelle021e6e2014-05-23 17:27:24 -07001270 mDecorToolbar.setCollapsible(mode == NAVIGATION_MODE_TABS && !mHasEmbeddedTabs);
Adam Powellb36e4f92014-05-01 10:23:33 -07001271 mOverlayLayout.setHasNonEmbeddedTabs(mode == NAVIGATION_MODE_TABS && !mHasEmbeddedTabs);
Adam Powell9ab97872010-10-26 21:47:29 -07001272 }
1273
1274 @Override
1275 public Tab getTabAt(int index) {
1276 return mTabs.get(index);
1277 }
Adam Powell0c24a552010-11-03 16:44:11 -07001278
Adam Powell0c24a552010-11-03 16:44:11 -07001279
Adam Powell1969b872011-03-22 11:52:48 -07001280 @Override
1281 public void setIcon(int resId) {
Adam Powelle021e6e2014-05-23 17:27:24 -07001282 mDecorToolbar.setIcon(resId);
Adam Powell1969b872011-03-22 11:52:48 -07001283 }
Adam Powell0c24a552010-11-03 16:44:11 -07001284
Adam Powell1969b872011-03-22 11:52:48 -07001285 @Override
1286 public void setIcon(Drawable icon) {
Adam Powelle021e6e2014-05-23 17:27:24 -07001287 mDecorToolbar.setIcon(icon);
Adam Powell1969b872011-03-22 11:52:48 -07001288 }
1289
Adam Powell04fe6eb2013-05-31 14:39:48 -07001290 public boolean hasIcon() {
Adam Powelle021e6e2014-05-23 17:27:24 -07001291 return mDecorToolbar.hasIcon();
Adam Powell04fe6eb2013-05-31 14:39:48 -07001292 }
1293
Adam Powell1969b872011-03-22 11:52:48 -07001294 @Override
1295 public void setLogo(int resId) {
Adam Powelle021e6e2014-05-23 17:27:24 -07001296 mDecorToolbar.setLogo(resId);
Adam Powell1969b872011-03-22 11:52:48 -07001297 }
1298
1299 @Override
1300 public void setLogo(Drawable logo) {
Adam Powelle021e6e2014-05-23 17:27:24 -07001301 mDecorToolbar.setLogo(logo);
Adam Powell0c24a552010-11-03 16:44:11 -07001302 }
Adam Powelldd8fab22012-03-22 17:47:27 -07001303
Adam Powell04fe6eb2013-05-31 14:39:48 -07001304 public boolean hasLogo() {
Adam Powelle021e6e2014-05-23 17:27:24 -07001305 return mDecorToolbar.hasLogo();
Adam Powell04fe6eb2013-05-31 14:39:48 -07001306 }
1307
Adam Powelldd8fab22012-03-22 17:47:27 -07001308 public void setDefaultDisplayHomeAsUpEnabled(boolean enable) {
1309 if (!mDisplayHomeAsUpSet) {
1310 setDisplayHomeAsUpEnabled(enable);
1311 }
1312 }
Adam Powelle021e6e2014-05-23 17:27:24 -07001313
Adam Powell89e06452010-06-23 20:24:52 -07001314}