Source code
package android.support.v7.internal.app;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Build.VERSION;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPropertyAnimatorCompat;
import android.support.v4.view.ViewPropertyAnimatorListener;
import android.support.v4.view.ViewPropertyAnimatorListenerAdapter;
import android.support.v4.view.ViewPropertyAnimatorUpdateListener;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBar.LayoutParams;
import android.support.v7.app.ActionBar.OnMenuVisibilityListener;
import android.support.v7.app.ActionBar.OnNavigationListener;
import android.support.v7.app.ActionBar.Tab;
import android.support.v7.app.ActionBar.TabListener;
import android.support.v7.appcompat.R;
import android.support.v7.internal.view.ActionBarPolicy;
import android.support.v7.internal.view.SupportMenuInflater;
import android.support.v7.internal.view.ViewPropertyAnimatorCompatSet;
import android.support.v7.internal.view.menu.MenuBuilder;
import android.support.v7.internal.view.menu.MenuPopupHelper;
import android.support.v7.internal.view.menu.SubMenuBuilder;
import android.support.v7.internal.widget.ActionBarContainer;
import android.support.v7.internal.widget.ActionBarContextView;
import android.support.v7.internal.widget.ActionBarOverlayLayout;
import android.support.v7.internal.widget.ActionBarOverlayLayout.ActionBarVisibilityCallback;
import android.support.v7.internal.widget.DecorToolbar;
import android.support.v7.internal.widget.ScrollingTabContainerView;
import android.support.v7.internal.widget.TintManager;
import android.support.v7.view.ActionMode;
import android.support.v7.view.ActionMode.Callback;
import android.support.v7.widget.Toolbar;
import android.util.TypedValue;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.widget.SpinnerAdapter;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
public class WindowDecorActionBar extends ActionBar implements ActionBarVisibilityCallback {
static final /* synthetic */ boolean $assertionsDisabled = (!WindowDecorActionBar.class.desiredAssertionStatus());
private static final boolean ALLOW_SHOW_HIDE_ANIMATIONS;
private static final long FADE_IN_DURATION_MS = 200;
private static final long FADE_OUT_DURATION_MS = 100;
private static final int INVALID_POSITION = -1;
private static final String TAG = "WindowDecorActionBar";
private static final Interpolator sHideInterpolator = new AccelerateInterpolator();
private static final Interpolator sShowInterpolator = new DecelerateInterpolator();
ActionModeImpl mActionMode;
private Activity mActivity;
private ActionBarContainer mContainerView;
private boolean mContentAnimations = true;
private View mContentView;
private Context mContext;
private ActionBarContextView mContextView;
private int mCurWindowVisibility = 0;
private ViewPropertyAnimatorCompatSet mCurrentShowAnim;
private DecorToolbar mDecorToolbar;
ActionMode mDeferredDestroyActionMode;
Callback mDeferredModeDestroyCallback;
private Dialog mDialog;
private boolean mDisplayHomeAsUpSet;
private boolean mHasEmbeddedTabs;
private boolean mHiddenByApp;
private boolean mHiddenBySystem;
final ViewPropertyAnimatorListener mHideListener = new ViewPropertyAnimatorListenerAdapter() {
public void onAnimationEnd(View view) {
if (WindowDecorActionBar.this.mContentAnimations && WindowDecorActionBar.this.mContentView != null) {
ViewCompat.setTranslationY(WindowDecorActionBar.this.mContentView, 0.0f);
ViewCompat.setTranslationY(WindowDecorActionBar.this.mContainerView, 0.0f);
}
WindowDecorActionBar.this.mContainerView.setVisibility(8);
WindowDecorActionBar.this.mContainerView.setTransitioning(false);
WindowDecorActionBar.this.mCurrentShowAnim = null;
WindowDecorActionBar.this.completeDeferredDestroyActionMode();
if (WindowDecorActionBar.this.mOverlayLayout != null) {
ViewCompat.requestApplyInsets(WindowDecorActionBar.this.mOverlayLayout);
}
}
};
boolean mHideOnContentScroll;
private boolean mLastMenuVisibility;
private ArrayList<OnMenuVisibilityListener> mMenuVisibilityListeners = new ArrayList();
private boolean mNowShowing = true;
private ActionBarOverlayLayout mOverlayLayout;
private int mSavedTabPosition = -1;
private TabImpl mSelectedTab;
private boolean mShowHideAnimationEnabled;
final ViewPropertyAnimatorListener mShowListener = new ViewPropertyAnimatorListenerAdapter() {
public void onAnimationEnd(View view) {
WindowDecorActionBar.this.mCurrentShowAnim = null;
WindowDecorActionBar.this.mContainerView.requestLayout();
}
};
private boolean mShowingForMode;
private ScrollingTabContainerView mTabScrollView;
private ArrayList<TabImpl> mTabs = new ArrayList();
private Context mThemedContext;
private TintManager mTintManager;
final ViewPropertyAnimatorUpdateListener mUpdateListener = new ViewPropertyAnimatorUpdateListener() {
public void onAnimationUpdate(View view) {
((View) WindowDecorActionBar.this.mContainerView.getParent()).invalidate();
}
};
public class ActionModeImpl extends ActionMode implements MenuBuilder.Callback {
private final Context mActionModeContext;
private Callback mCallback;
private WeakReference<View> mCustomView;
private final MenuBuilder mMenu;
public ActionModeImpl(Context context, Callback callback) {
this.mActionModeContext = context;
this.mCallback = callback;
this.mMenu = new MenuBuilder(context).setDefaultShowAsAction(1);
this.mMenu.setCallback(this);
}
public MenuInflater getMenuInflater() {
return new SupportMenuInflater(this.mActionModeContext);
}
public Menu getMenu() {
return this.mMenu;
}
public void finish() {
if (WindowDecorActionBar.this.mActionMode == this) {
if (WindowDecorActionBar.checkShowingFlags(WindowDecorActionBar.this.mHiddenByApp, WindowDecorActionBar.this.mHiddenBySystem, false)) {
this.mCallback.onDestroyActionMode(this);
} else {
WindowDecorActionBar.this.mDeferredDestroyActionMode = this;
WindowDecorActionBar.this.mDeferredModeDestroyCallback = this.mCallback;
}
this.mCallback = null;
WindowDecorActionBar.this.animateToMode(false);
WindowDecorActionBar.this.mContextView.closeMode();
WindowDecorActionBar.this.mDecorToolbar.getViewGroup().sendAccessibilityEvent(32);
WindowDecorActionBar.this.mOverlayLayout.setHideOnContentScrollEnabled(WindowDecorActionBar.this.mHideOnContentScroll);
WindowDecorActionBar.this.mActionMode = null;
}
}
public void invalidate() {
if (WindowDecorActionBar.this.mActionMode == this) {
this.mMenu.stopDispatchingItemsChanged();
try {
this.mCallback.onPrepareActionMode(this, this.mMenu);
} finally {
this.mMenu.startDispatchingItemsChanged();
}
}
}
public boolean dispatchOnCreate() {
this.mMenu.stopDispatchingItemsChanged();
try {
boolean onCreateActionMode = this.mCallback.onCreateActionMode(this, this.mMenu);
return onCreateActionMode;
} finally {
this.mMenu.startDispatchingItemsChanged();
}
}
public void setCustomView(View view) {
WindowDecorActionBar.this.mContextView.setCustomView(view);
this.mCustomView = new WeakReference(view);
}
public void setSubtitle(CharSequence subtitle) {
WindowDecorActionBar.this.mContextView.setSubtitle(subtitle);
}
public void setTitle(CharSequence title) {
WindowDecorActionBar.this.mContextView.setTitle(title);
}
public void setTitle(int resId) {
setTitle(WindowDecorActionBar.this.mContext.getResources().getString(resId));
}
public void setSubtitle(int resId) {
setSubtitle(WindowDecorActionBar.this.mContext.getResources().getString(resId));
}
public CharSequence getTitle() {
return WindowDecorActionBar.this.mContextView.getTitle();
}
public CharSequence getSubtitle() {
return WindowDecorActionBar.this.mContextView.getSubtitle();
}
public void setTitleOptionalHint(boolean titleOptional) {
super.setTitleOptionalHint(titleOptional);
WindowDecorActionBar.this.mContextView.setTitleOptional(titleOptional);
}
public boolean isTitleOptional() {
return WindowDecorActionBar.this.mContextView.isTitleOptional();
}
public View getCustomView() {
return this.mCustomView != null ? (View) this.mCustomView.get() : null;
}
public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
if (this.mCallback != null) {
return this.mCallback.onActionItemClicked(this, item);
}
return false;
}
public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) {
}
public boolean onSubMenuSelected(SubMenuBuilder subMenu) {
if (this.mCallback == null) {
return false;
}
if (!subMenu.hasVisibleItems()) {
return true;
}
new MenuPopupHelper(WindowDecorActionBar.this.getThemedContext(), subMenu).show();
return true;
}
public void onCloseSubMenu(SubMenuBuilder menu) {
}
public void onMenuModeChange(MenuBuilder menu) {
if (this.mCallback != null) {
invalidate();
WindowDecorActionBar.this.mContextView.showOverflowMenu();
}
}
}
public class TabImpl extends Tab {
private TabListener mCallback;
private CharSequence mContentDesc;
private View mCustomView;
private Drawable mIcon;
private int mPosition = -1;
private Object mTag;
private CharSequence mText;
public Object getTag() {
return this.mTag;
}
public Tab setTag(Object tag) {
this.mTag = tag;
return this;
}
public TabListener getCallback() {
return this.mCallback;
}
public Tab setTabListener(TabListener callback) {
this.mCallback = callback;
return this;
}
public View getCustomView() {
return this.mCustomView;
}
public Tab setCustomView(View view) {
this.mCustomView = view;
if (this.mPosition >= 0) {
WindowDecorActionBar.this.mTabScrollView.updateTab(this.mPosition);
}
return this;
}
public Tab setCustomView(int layoutResId) {
return setCustomView(LayoutInflater.from(WindowDecorActionBar.this.getThemedContext()).inflate(layoutResId, null));
}
public Drawable getIcon() {
return this.mIcon;
}
public int getPosition() {
return this.mPosition;
}
public void setPosition(int position) {
this.mPosition = position;
}
public CharSequence getText() {
return this.mText;
}
public Tab setIcon(Drawable icon) {
this.mIcon = icon;
if (this.mPosition >= 0) {
WindowDecorActionBar.this.mTabScrollView.updateTab(this.mPosition);
}
return this;
}
public Tab setIcon(int resId) {
return setIcon(WindowDecorActionBar.this.getTintManager().getDrawable(resId));
}
public Tab setText(CharSequence text) {
this.mText = text;
if (this.mPosition >= 0) {
WindowDecorActionBar.this.mTabScrollView.updateTab(this.mPosition);
}
return this;
}
public Tab setText(int resId) {
return setText(WindowDecorActionBar.this.mContext.getResources().getText(resId));
}
public void select() {
WindowDecorActionBar.this.selectTab(this);
}
public Tab setContentDescription(int resId) {
return setContentDescription(WindowDecorActionBar.this.mContext.getResources().getText(resId));
}
public Tab setContentDescription(CharSequence contentDesc) {
this.mContentDesc = contentDesc;
if (this.mPosition >= 0) {
WindowDecorActionBar.this.mTabScrollView.updateTab(this.mPosition);
}
return this;
}
public CharSequence getContentDescription() {
return this.mContentDesc;
}
}
static {
boolean z = true;
if (VERSION.SDK_INT < 14) {
z = false;
}
ALLOW_SHOW_HIDE_ANIMATIONS = z;
}
public WindowDecorActionBar(Activity activity, boolean overlayMode) {
this.mActivity = activity;
View decor = activity.getWindow().getDecorView();
init(decor);
if (!overlayMode) {
this.mContentView = decor.findViewById(16908290);
}
}
public WindowDecorActionBar(Dialog dialog) {
this.mDialog = dialog;
init(dialog.getWindow().getDecorView());
}
public WindowDecorActionBar(View layout) {
if ($assertionsDisabled || layout.isInEditMode()) {
init(layout);
return;
}
throw new AssertionError();
}
private void init(View decor) {
this.mOverlayLayout = (ActionBarOverlayLayout) decor.findViewById(R.id.decor_content_parent);
if (this.mOverlayLayout != null) {
this.mOverlayLayout.setActionBarVisibilityCallback(this);
}
this.mDecorToolbar = getDecorToolbar(decor.findViewById(R.id.action_bar));
this.mContextView = (ActionBarContextView) decor.findViewById(R.id.action_context_bar);
this.mContainerView = (ActionBarContainer) decor.findViewById(R.id.action_bar_container);
if (this.mDecorToolbar == null || this.mContextView == null || this.mContainerView == null) {
throw new IllegalStateException(getClass().getSimpleName() + " can only be used " + "with a compatible window decor layout");
}
boolean homeAsUp;
boolean z;
this.mContext = this.mDecorToolbar.getContext();
if ((this.mDecorToolbar.getDisplayOptions() & 4) != 0) {
homeAsUp = true;
} else {
homeAsUp = false;
}
if (homeAsUp) {
this.mDisplayHomeAsUpSet = true;
}
ActionBarPolicy abp = ActionBarPolicy.get(this.mContext);
if (abp.enableHomeButtonByDefault() || homeAsUp) {
z = true;
} else {
z = false;
}
setHomeButtonEnabled(z);
setHasEmbeddedTabs(abp.hasEmbeddedTabs());
TypedArray a = this.mContext.obtainStyledAttributes(null, R.styleable.ActionBar, R.attr.actionBarStyle, 0);
if (a.getBoolean(R.styleable.ActionBar_hideOnContentScroll, false)) {
setHideOnContentScrollEnabled(true);
}
int elevation = a.getDimensionPixelSize(R.styleable.ActionBar_elevation, 0);
if (elevation != 0) {
setElevation((float) elevation);
}
a.recycle();
}
private DecorToolbar getDecorToolbar(View view) {
if (view instanceof DecorToolbar) {
return (DecorToolbar) view;
}
if (view instanceof Toolbar) {
return ((Toolbar) view).getWrapper();
}
throw new IllegalStateException(new StringBuilder().append("Can't make a decor toolbar out of ").append(view).toString() != null ? view.getClass().getSimpleName() : "null");
}
public void setElevation(float elevation) {
ViewCompat.setElevation(this.mContainerView, elevation);
}
public float getElevation() {
return ViewCompat.getElevation(this.mContainerView);
}
public void onConfigurationChanged(Configuration newConfig) {
setHasEmbeddedTabs(ActionBarPolicy.get(this.mContext).hasEmbeddedTabs());
}
private void setHasEmbeddedTabs(boolean hasEmbeddedTabs) {
boolean isInTabMode;
boolean z;
boolean z2 = true;
this.mHasEmbeddedTabs = hasEmbeddedTabs;
if (this.mHasEmbeddedTabs) {
this.mContainerView.setTabContainer(null);
this.mDecorToolbar.setEmbeddedTabView(this.mTabScrollView);
} else {
this.mDecorToolbar.setEmbeddedTabView(null);
this.mContainerView.setTabContainer(this.mTabScrollView);
}
if (getNavigationMode() == 2) {
isInTabMode = true;
} else {
isInTabMode = false;
}
if (this.mTabScrollView != null) {
if (isInTabMode) {
this.mTabScrollView.setVisibility(0);
if (this.mOverlayLayout != null) {
ViewCompat.requestApplyInsets(this.mOverlayLayout);
}
} else {
this.mTabScrollView.setVisibility(8);
}
}
DecorToolbar decorToolbar = this.mDecorToolbar;
if (this.mHasEmbeddedTabs || !isInTabMode) {
z = false;
} else {
z = true;
}
decorToolbar.setCollapsible(z);
ActionBarOverlayLayout actionBarOverlayLayout = this.mOverlayLayout;
if (this.mHasEmbeddedTabs || !isInTabMode) {
z2 = false;
}
actionBarOverlayLayout.setHasNonEmbeddedTabs(z2);
}
private void ensureTabsExist() {
if (this.mTabScrollView == null) {
ScrollingTabContainerView tabScroller = new ScrollingTabContainerView(this.mContext);
if (this.mHasEmbeddedTabs) {
tabScroller.setVisibility(0);
this.mDecorToolbar.setEmbeddedTabView(tabScroller);
} else {
if (getNavigationMode() == 2) {
tabScroller.setVisibility(0);
if (this.mOverlayLayout != null) {
ViewCompat.requestApplyInsets(this.mOverlayLayout);
}
} else {
tabScroller.setVisibility(8);
}
this.mContainerView.setTabContainer(tabScroller);
}
this.mTabScrollView = tabScroller;
}
}
void completeDeferredDestroyActionMode() {
if (this.mDeferredModeDestroyCallback != null) {
this.mDeferredModeDestroyCallback.onDestroyActionMode(this.mDeferredDestroyActionMode);
this.mDeferredDestroyActionMode = null;
this.mDeferredModeDestroyCallback = null;
}
}
public void onWindowVisibilityChanged(int visibility) {
this.mCurWindowVisibility = visibility;
}
public void setShowHideAnimationEnabled(boolean enabled) {
this.mShowHideAnimationEnabled = enabled;
if (!enabled && this.mCurrentShowAnim != null) {
this.mCurrentShowAnim.cancel();
}
}
public void addOnMenuVisibilityListener(OnMenuVisibilityListener listener) {
this.mMenuVisibilityListeners.add(listener);
}
public void removeOnMenuVisibilityListener(OnMenuVisibilityListener listener) {
this.mMenuVisibilityListeners.remove(listener);
}
public void dispatchMenuVisibilityChanged(boolean isVisible) {
if (isVisible != this.mLastMenuVisibility) {
this.mLastMenuVisibility = isVisible;
int count = this.mMenuVisibilityListeners.size();
for (int i = 0; i < count; i++) {
((OnMenuVisibilityListener) this.mMenuVisibilityListeners.get(i)).onMenuVisibilityChanged(isVisible);
}
}
}
public void setCustomView(int resId) {
setCustomView(LayoutInflater.from(getThemedContext()).inflate(resId, this.mDecorToolbar.getViewGroup(), false));
}
public void setDisplayUseLogoEnabled(boolean useLogo) {
setDisplayOptions(useLogo ? 1 : 0, 1);
}
public void setDisplayShowHomeEnabled(boolean showHome) {
setDisplayOptions(showHome ? 2 : 0, 2);
}
public void setDisplayHomeAsUpEnabled(boolean showHomeAsUp) {
setDisplayOptions(showHomeAsUp ? 4 : 0, 4);
}
public void setDisplayShowTitleEnabled(boolean showTitle) {
setDisplayOptions(showTitle ? 8 : 0, 8);
}
public void setDisplayShowCustomEnabled(boolean showCustom) {
setDisplayOptions(showCustom ? 16 : 0, 16);
}
public void setHomeButtonEnabled(boolean enable) {
this.mDecorToolbar.setHomeButtonEnabled(enable);
}
public void setTitle(int resId) {
setTitle(this.mContext.getString(resId));
}
public void setSubtitle(int resId) {
setSubtitle(this.mContext.getString(resId));
}
public void setSelectedNavigationItem(int position) {
switch (this.mDecorToolbar.getNavigationMode()) {
case 1:
this.mDecorToolbar.setDropdownSelectedPosition(position);
return;
case 2:
selectTab((Tab) this.mTabs.get(position));
return;
default:
throw new IllegalStateException("setSelectedNavigationIndex not valid for current navigation mode");
}
}
public void removeAllTabs() {
cleanupTabs();
}
private void cleanupTabs() {
if (this.mSelectedTab != null) {
selectTab(null);
}
this.mTabs.clear();
if (this.mTabScrollView != null) {
this.mTabScrollView.removeAllTabs();
}
this.mSavedTabPosition = -1;
}
public void setTitle(CharSequence title) {
this.mDecorToolbar.setTitle(title);
}
public void setWindowTitle(CharSequence title) {
this.mDecorToolbar.setWindowTitle(title);
}
public void setSubtitle(CharSequence subtitle) {
this.mDecorToolbar.setSubtitle(subtitle);
}
public void setDisplayOptions(int options) {
if ((options & 4) != 0) {
this.mDisplayHomeAsUpSet = true;
}
this.mDecorToolbar.setDisplayOptions(options);
}
public void setDisplayOptions(int options, int mask) {
int current = this.mDecorToolbar.getDisplayOptions();
if ((mask & 4) != 0) {
this.mDisplayHomeAsUpSet = true;
}
this.mDecorToolbar.setDisplayOptions((options & mask) | ((mask ^ -1) & current));
}
public void setBackgroundDrawable(Drawable d) {
this.mContainerView.setPrimaryBackground(d);
}
public void setStackedBackgroundDrawable(Drawable d) {
this.mContainerView.setStackedBackground(d);
}
public void setSplitBackgroundDrawable(Drawable d) {
}
public View getCustomView() {
return this.mDecorToolbar.getCustomView();
}
public CharSequence getTitle() {
return this.mDecorToolbar.getTitle();
}
public CharSequence getSubtitle() {
return this.mDecorToolbar.getSubtitle();
}
public int getNavigationMode() {
return this.mDecorToolbar.getNavigationMode();
}
public int getDisplayOptions() {
return this.mDecorToolbar.getDisplayOptions();
}
public ActionMode startActionMode(Callback callback) {
if (this.mActionMode != null) {
this.mActionMode.finish();
}
this.mOverlayLayout.setHideOnContentScrollEnabled(false);
this.mContextView.killMode();
ActionModeImpl mode = new ActionModeImpl(this.mContextView.getContext(), callback);
if (!mode.dispatchOnCreate()) {
return null;
}
mode.invalidate();
this.mContextView.initForMode(mode);
animateToMode(true);
this.mContextView.sendAccessibilityEvent(32);
this.mActionMode = mode;
return mode;
}
private void configureTab(Tab tab, int position) {
TabImpl tabi = (TabImpl) tab;
if (tabi.getCallback() == null) {
throw new IllegalStateException("Action Bar Tab must have a Callback");
}
tabi.setPosition(position);
this.mTabs.add(position, tabi);
int count = this.mTabs.size();
for (int i = position + 1; i < count; i++) {
((TabImpl) this.mTabs.get(i)).setPosition(i);
}
}
public void addTab(Tab tab) {
addTab(tab, this.mTabs.isEmpty());
}
public void addTab(Tab tab, int position) {
addTab(tab, position, this.mTabs.isEmpty());
}
public void addTab(Tab tab, boolean setSelected) {
ensureTabsExist();
this.mTabScrollView.addTab(tab, setSelected);
configureTab(tab, this.mTabs.size());
if (setSelected) {
selectTab(tab);
}
}
public void addTab(Tab tab, int position, boolean setSelected) {
ensureTabsExist();
this.mTabScrollView.addTab(tab, position, setSelected);
configureTab(tab, position);
if (setSelected) {
selectTab(tab);
}
}
public Tab newTab() {
return new TabImpl();
}
public void removeTab(Tab tab) {
removeTabAt(tab.getPosition());
}
public void removeTabAt(int position) {
if (this.mTabScrollView != null) {
int selectedTabPosition = this.mSelectedTab != null ? this.mSelectedTab.getPosition() : this.mSavedTabPosition;
this.mTabScrollView.removeTabAt(position);
TabImpl removedTab = (TabImpl) this.mTabs.remove(position);
if (removedTab != null) {
removedTab.setPosition(-1);
}
int newTabCount = this.mTabs.size();
for (int i = position; i < newTabCount; i++) {
((TabImpl) this.mTabs.get(i)).setPosition(i);
}
if (selectedTabPosition == position) {
Tab tab;
if (this.mTabs.isEmpty()) {
tab = null;
} else {
TabImpl tabImpl = (TabImpl) this.mTabs.get(Math.max(0, position - 1));
}
selectTab(tab);
}
}
}
public void selectTab(Tab tab) {
int i = -1;
if (getNavigationMode() != 2) {
this.mSavedTabPosition = tab != null ? tab.getPosition() : -1;
return;
}
FragmentTransaction trans;
if (!(this.mActivity instanceof FragmentActivity) || this.mDecorToolbar.getViewGroup().isInEditMode()) {
trans = null;
} else {
trans = ((FragmentActivity) this.mActivity).getSupportFragmentManager().beginTransaction().disallowAddToBackStack();
}
if (this.mSelectedTab != tab) {
ScrollingTabContainerView scrollingTabContainerView = this.mTabScrollView;
if (tab != null) {
i = tab.getPosition();
}
scrollingTabContainerView.setTabSelected(i);
if (this.mSelectedTab != null) {
this.mSelectedTab.getCallback().onTabUnselected(this.mSelectedTab, trans);
}
this.mSelectedTab = (TabImpl) tab;
if (this.mSelectedTab != null) {
this.mSelectedTab.getCallback().onTabSelected(this.mSelectedTab, trans);
}
} else if (this.mSelectedTab != null) {
this.mSelectedTab.getCallback().onTabReselected(this.mSelectedTab, trans);
this.mTabScrollView.animateToTab(tab.getPosition());
}
if (trans != null && !trans.isEmpty()) {
trans.commit();
}
}
public Tab getSelectedTab() {
return this.mSelectedTab;
}
public int getHeight() {
return this.mContainerView.getHeight();
}
public void enableContentAnimations(boolean enabled) {
this.mContentAnimations = enabled;
}
public void show() {
if (this.mHiddenByApp) {
this.mHiddenByApp = false;
updateVisibility(false);
}
}
private void showForActionMode() {
if (!this.mShowingForMode) {
this.mShowingForMode = true;
if (this.mOverlayLayout != null) {
this.mOverlayLayout.setShowingForActionMode(true);
}
updateVisibility(false);
}
}
public void showForSystem() {
if (this.mHiddenBySystem) {
this.mHiddenBySystem = false;
updateVisibility(true);
}
}
public void hide() {
if (!this.mHiddenByApp) {
this.mHiddenByApp = true;
updateVisibility(false);
}
}
private void hideForActionMode() {
if (this.mShowingForMode) {
this.mShowingForMode = false;
if (this.mOverlayLayout != null) {
this.mOverlayLayout.setShowingForActionMode(false);
}
updateVisibility(false);
}
}
public void hideForSystem() {
if (!this.mHiddenBySystem) {
this.mHiddenBySystem = true;
updateVisibility(true);
}
}
public void setHideOnContentScrollEnabled(boolean hideOnContentScroll) {
if (!hideOnContentScroll || this.mOverlayLayout.isInOverlayMode()) {
this.mHideOnContentScroll = hideOnContentScroll;
this.mOverlayLayout.setHideOnContentScrollEnabled(hideOnContentScroll);
return;
}
throw new IllegalStateException("Action bar must be in overlay mode (Window.FEATURE_OVERLAY_ACTION_BAR) to enable hide on content scroll");
}
public boolean isHideOnContentScrollEnabled() {
return this.mOverlayLayout.isHideOnContentScrollEnabled();
}
public int getHideOffset() {
return this.mOverlayLayout.getActionBarHideOffset();
}
public void setHideOffset(int offset) {
if (offset == 0 || this.mOverlayLayout.isInOverlayMode()) {
this.mOverlayLayout.setActionBarHideOffset(offset);
return;
}
throw new IllegalStateException("Action bar must be in overlay mode (Window.FEATURE_OVERLAY_ACTION_BAR) to set a non-zero hide offset");
}
private static boolean checkShowingFlags(boolean hiddenByApp, boolean hiddenBySystem, boolean showingForMode) {
if (showingForMode) {
return true;
}
if (hiddenByApp || hiddenBySystem) {
return false;
}
return true;
}
private void updateVisibility(boolean fromSystem) {
if (checkShowingFlags(this.mHiddenByApp, this.mHiddenBySystem, this.mShowingForMode)) {
if (!this.mNowShowing) {
this.mNowShowing = true;
doShow(fromSystem);
}
} else if (this.mNowShowing) {
this.mNowShowing = false;
doHide(fromSystem);
}
}
public void doShow(boolean fromSystem) {
if (this.mCurrentShowAnim != null) {
this.mCurrentShowAnim.cancel();
}
this.mContainerView.setVisibility(0);
if (this.mCurWindowVisibility == 0 && ALLOW_SHOW_HIDE_ANIMATIONS && (this.mShowHideAnimationEnabled || fromSystem)) {
ViewCompat.setTranslationY(this.mContainerView, 0.0f);
float startingY = (float) (-this.mContainerView.getHeight());
if (fromSystem) {
int[] topLeft = new int[]{0, 0};
this.mContainerView.getLocationInWindow(topLeft);
startingY -= (float) topLeft[1];
}
ViewCompat.setTranslationY(this.mContainerView, startingY);
ViewPropertyAnimatorCompatSet anim = new ViewPropertyAnimatorCompatSet();
ViewPropertyAnimatorCompat a = ViewCompat.animate(this.mContainerView).translationY(0.0f);
a.setUpdateListener(this.mUpdateListener);
anim.play(a);
if (this.mContentAnimations && this.mContentView != null) {
ViewCompat.setTranslationY(this.mContentView, startingY);
anim.play(ViewCompat.animate(this.mContentView).translationY(0.0f));
}
anim.setInterpolator(sShowInterpolator);
anim.setDuration(250);
anim.setListener(this.mShowListener);
this.mCurrentShowAnim = anim;
anim.start();
} else {
ViewCompat.setAlpha(this.mContainerView, 1.0f);
ViewCompat.setTranslationY(this.mContainerView, 0.0f);
if (this.mContentAnimations && this.mContentView != null) {
ViewCompat.setTranslationY(this.mContentView, 0.0f);
}
this.mShowListener.onAnimationEnd(null);
}
if (this.mOverlayLayout != null) {
ViewCompat.requestApplyInsets(this.mOverlayLayout);
}
}
public void doHide(boolean fromSystem) {
if (this.mCurrentShowAnim != null) {
this.mCurrentShowAnim.cancel();
}
if (this.mCurWindowVisibility == 0 && ALLOW_SHOW_HIDE_ANIMATIONS && (this.mShowHideAnimationEnabled || fromSystem)) {
ViewCompat.setAlpha(this.mContainerView, 1.0f);
this.mContainerView.setTransitioning(true);
ViewPropertyAnimatorCompatSet anim = new ViewPropertyAnimatorCompatSet();
float endingY = (float) (-this.mContainerView.getHeight());
if (fromSystem) {
int[] topLeft = new int[]{0, 0};
this.mContainerView.getLocationInWindow(topLeft);
endingY -= (float) topLeft[1];
}
ViewPropertyAnimatorCompat a = ViewCompat.animate(this.mContainerView).translationY(endingY);
a.setUpdateListener(this.mUpdateListener);
anim.play(a);
if (this.mContentAnimations && this.mContentView != null) {
anim.play(ViewCompat.animate(this.mContentView).translationY(endingY));
}
anim.setInterpolator(sHideInterpolator);
anim.setDuration(250);
anim.setListener(this.mHideListener);
this.mCurrentShowAnim = anim;
anim.start();
return;
}
this.mHideListener.onAnimationEnd(null);
}
public boolean isShowing() {
int height = getHeight();
return this.mNowShowing && (height == 0 || getHideOffset() < height);
}
public void animateToMode(boolean toActionMode) {
ViewPropertyAnimatorCompat fadeOut;
ViewPropertyAnimatorCompat fadeIn;
if (toActionMode) {
showForActionMode();
} else {
hideForActionMode();
}
if (toActionMode) {
fadeOut = this.mDecorToolbar.setupAnimatorToVisibility(4, FADE_OUT_DURATION_MS);
fadeIn = this.mContextView.setupAnimatorToVisibility(0, FADE_IN_DURATION_MS);
} else {
fadeIn = this.mDecorToolbar.setupAnimatorToVisibility(0, FADE_IN_DURATION_MS);
fadeOut = this.mContextView.setupAnimatorToVisibility(8, FADE_OUT_DURATION_MS);
}
ViewPropertyAnimatorCompatSet set = new ViewPropertyAnimatorCompatSet();
set.playSequentially(fadeOut, fadeIn);
set.start();
}
public Context getThemedContext() {
if (this.mThemedContext == null) {
TypedValue outValue = new TypedValue();
this.mContext.getTheme().resolveAttribute(R.attr.actionBarWidgetTheme, outValue, true);
int targetThemeRes = outValue.resourceId;
if (targetThemeRes != 0) {
this.mThemedContext = new ContextThemeWrapper(this.mContext, targetThemeRes);
} else {
this.mThemedContext = this.mContext;
}
}
return this.mThemedContext;
}
public boolean isTitleTruncated() {
return this.mDecorToolbar != null && this.mDecorToolbar.isTitleTruncated();
}
public void setHomeAsUpIndicator(Drawable indicator) {
this.mDecorToolbar.setNavigationIcon(indicator);
}
public void setHomeAsUpIndicator(int resId) {
this.mDecorToolbar.setNavigationIcon(resId);
}
public void setHomeActionContentDescription(CharSequence description) {
this.mDecorToolbar.setNavigationContentDescription(description);
}
public void setHomeActionContentDescription(int resId) {
this.mDecorToolbar.setNavigationContentDescription(resId);
}
public void onContentScrollStarted() {
if (this.mCurrentShowAnim != null) {
this.mCurrentShowAnim.cancel();
this.mCurrentShowAnim = null;
}
}
public void onContentScrollStopped() {
}
public boolean collapseActionView() {
if (this.mDecorToolbar == null || !this.mDecorToolbar.hasExpandedActionView()) {
return false;
}
this.mDecorToolbar.collapseActionView();
return true;
}
public void setCustomView(View view) {
this.mDecorToolbar.setCustomView(view);
}
public void setCustomView(View view, LayoutParams layoutParams) {
view.setLayoutParams(layoutParams);
this.mDecorToolbar.setCustomView(view);
}
public void setListNavigationCallbacks(SpinnerAdapter adapter, OnNavigationListener callback) {
this.mDecorToolbar.setDropdownParams(adapter, new NavItemSelectedListener(callback));
}
public int getSelectedNavigationIndex() {
switch (this.mDecorToolbar.getNavigationMode()) {
case 1:
return this.mDecorToolbar.getDropdownSelectedPosition();
case 2:
if (this.mSelectedTab != null) {
return this.mSelectedTab.getPosition();
}
return -1;
default:
return -1;
}
}
public int getNavigationItemCount() {
switch (this.mDecorToolbar.getNavigationMode()) {
case 1:
return this.mDecorToolbar.getDropdownItemCount();
case 2:
return this.mTabs.size();
default:
return 0;
}
}
public int getTabCount() {
return this.mTabs.size();
}
public void setNavigationMode(int mode) {
boolean z;
boolean z2 = true;
int oldMode = this.mDecorToolbar.getNavigationMode();
switch (oldMode) {
case 2:
this.mSavedTabPosition = getSelectedNavigationIndex();
selectTab(null);
this.mTabScrollView.setVisibility(8);
break;
}
if (!(oldMode == mode || this.mHasEmbeddedTabs || this.mOverlayLayout == null)) {
ViewCompat.requestApplyInsets(this.mOverlayLayout);
}
this.mDecorToolbar.setNavigationMode(mode);
switch (mode) {
case 2:
ensureTabsExist();
this.mTabScrollView.setVisibility(0);
if (this.mSavedTabPosition != -1) {
setSelectedNavigationItem(this.mSavedTabPosition);
this.mSavedTabPosition = -1;
break;
}
break;
}
DecorToolbar decorToolbar = this.mDecorToolbar;
if (mode != 2 || this.mHasEmbeddedTabs) {
z = false;
} else {
z = true;
}
decorToolbar.setCollapsible(z);
ActionBarOverlayLayout actionBarOverlayLayout = this.mOverlayLayout;
if (mode != 2 || this.mHasEmbeddedTabs) {
z2 = false;
}
actionBarOverlayLayout.setHasNonEmbeddedTabs(z2);
}
public Tab getTabAt(int index) {
return (Tab) this.mTabs.get(index);
}
public void setIcon(int resId) {
this.mDecorToolbar.setIcon(resId);
}
public void setIcon(Drawable icon) {
this.mDecorToolbar.setIcon(icon);
}
public boolean hasIcon() {
return this.mDecorToolbar.hasIcon();
}
public void setLogo(int resId) {
this.mDecorToolbar.setLogo(resId);
}
public void setLogo(Drawable logo) {
this.mDecorToolbar.setLogo(logo);
}
public boolean hasLogo() {
return this.mDecorToolbar.hasLogo();
}
public void setDefaultDisplayHomeAsUpEnabled(boolean enable) {
if (!this.mDisplayHomeAsUpSet) {
setDisplayHomeAsUpEnabled(enable);
}
}
TintManager getTintManager() {
if (this.mTintManager == null) {
this.mTintManager = TintManager.get(this.mContext);
}
return this.mTintManager;
}
}