Fix bug 5122319 - When action bar tabs run out of space they should
collapse in to a spinner.
When tabs are not given the option of dropping to their own row,
collapse them into a spinner when they would measure too large to be
visible all at once.
Fix bug 5095167 - zombie tabs return when they shouldn't when activity
handles its own orientation changes
Change-Id: I074419d99a22aa5dd1cbc00a66e600ec5cb0b54a
diff --git a/core/java/com/android/internal/app/ActionBarImpl.java b/core/java/com/android/internal/app/ActionBarImpl.java
index 008f400..0df7bcc 100644
--- a/core/java/com/android/internal/app/ActionBarImpl.java
+++ b/core/java/com/android/internal/app/ActionBarImpl.java
@@ -156,8 +156,6 @@
"with a compatible window decor layout");
}
- mHasEmbeddedTabs = mContext.getResources().getBoolean(
- com.android.internal.R.bool.action_bar_embed_tabs);
mActionView.setContextView(mContextView);
mContextDisplayMode = mActionView.isSplitActionBar() ?
CONTEXT_DISPLAY_SPLIT : CONTEXT_DISPLAY_NORMAL;
@@ -166,25 +164,31 @@
// Newer apps need to enable it explicitly.
setHomeButtonEnabled(mContext.getApplicationInfo().targetSdkVersion <
Build.VERSION_CODES.ICE_CREAM_SANDWICH);
+
+ setHasEmbeddedTabs(mContext.getResources().getBoolean(
+ com.android.internal.R.bool.action_bar_embed_tabs));
}
public void onConfigurationChanged(Configuration newConfig) {
- mHasEmbeddedTabs = mContext.getResources().getBoolean(
- com.android.internal.R.bool.action_bar_embed_tabs);
+ setHasEmbeddedTabs(mContext.getResources().getBoolean(
+ com.android.internal.R.bool.action_bar_embed_tabs));
+ }
+ private void setHasEmbeddedTabs(boolean hasEmbeddedTabs) {
+ mHasEmbeddedTabs = hasEmbeddedTabs;
// Switch tab layout configuration if needed
if (!mHasEmbeddedTabs) {
mActionView.setEmbeddedTabView(null);
mContainerView.setTabContainer(mTabScrollView);
} else {
mContainerView.setTabContainer(null);
- if (mTabScrollView != null) {
- mTabScrollView.setVisibility(View.VISIBLE);
- }
mActionView.setEmbeddedTabView(mTabScrollView);
}
- mActionView.setCollapsable(!mHasEmbeddedTabs &&
- getNavigationMode() == NAVIGATION_MODE_TABS);
+ final boolean isInTabMode = getNavigationMode() == NAVIGATION_MODE_TABS;
+ if (mTabScrollView != null) {
+ mTabScrollView.setVisibility(isInTabMode ? View.VISIBLE : View.GONE);
+ }
+ mActionView.setCollapsable(!mHasEmbeddedTabs && isInTabMode);
}
private void ensureTabsExist() {
@@ -192,7 +196,7 @@
return;
}
- ScrollingTabContainerView tabScroller = mActionView.createTabContainer();
+ ScrollingTabContainerView tabScroller = new ScrollingTabContainerView(mContext);
if (mHasEmbeddedTabs) {
tabScroller.setVisibility(View.VISIBLE);
@@ -925,18 +929,14 @@
case NAVIGATION_MODE_TABS:
mSavedTabPosition = getSelectedNavigationIndex();
selectTab(null);
- if (!mActionView.hasEmbeddedTabs()) {
- mTabScrollView.setVisibility(View.GONE);
- }
+ mTabScrollView.setVisibility(View.GONE);
break;
}
mActionView.setNavigationMode(mode);
switch (mode) {
case NAVIGATION_MODE_TABS:
ensureTabsExist();
- if (!mActionView.hasEmbeddedTabs()) {
- mTabScrollView.setVisibility(View.VISIBLE);
- }
+ mTabScrollView.setVisibility(View.VISIBLE);
if (mSavedTabPosition != INVALID_POSITION) {
setSelectedNavigationItem(mSavedTabPosition);
mSavedTabPosition = INVALID_POSITION;