Merge "Allow showing tabs while in subpages" into pi-car-dev am: 535364d1d9
Change-Id: I4e19596335207ff6278294aa0e9c2bdbb5f80860
diff --git a/car-ui-lib/res/values/attrs.xml b/car-ui-lib/res/values/attrs.xml
index 71ad091..d8e2e00 100644
--- a/car-ui-lib/res/values/attrs.xml
+++ b/car-ui-lib/res/values/attrs.xml
@@ -39,6 +39,8 @@
</attr>
<!-- XML resource of MenuItems. See Toolbar.setMenuItems(int) for more information. -->
<attr name="menuItems" format="reference"/>
+ <!-- Whether or not to show tabs in the SUBPAGE state. Default false -->
+ <attr name="showTabsInSubpage" format="boolean"/>
</declare-styleable>
<declare-styleable name="CarUiToolbarMenuItem">
diff --git a/car-ui-lib/src/com/android/car/ui/toolbar/Toolbar.java b/car-ui-lib/src/com/android/car/ui/toolbar/Toolbar.java
index 2a9b3b7..3ad5704 100644
--- a/car-ui-lib/src/com/android/car/ui/toolbar/Toolbar.java
+++ b/car-ui-lib/src/com/android/car/ui/toolbar/Toolbar.java
@@ -162,6 +162,7 @@
private boolean mShowMenuItemsWhileSearching;
private State mState = State.HOME;
private NavButtonMode mNavButtonMode = NavButtonMode.BACK;
+ private boolean mShowTabsInSubpage = false;
@NonNull
private List<MenuItem> mMenuItems = Collections.emptyList();
private List<MenuItem> mOverflowItems = new ArrayList<>();
@@ -238,6 +239,7 @@
mSearchViewContainer = requireViewById(R.id.car_ui_toolbar_search_view_container);
mProgressBar = requireViewById(R.id.car_ui_toolbar_progress_bar);
+ setShowTabsInSubpage(a.getBoolean(R.styleable.CarUiToolbar_showTabsInSubpage, false));
mTitle.setText(a.getString(R.styleable.CarUiToolbar_title));
setLogo(a.getResourceId(R.styleable.CarUiToolbar_logo, 0));
setBackgroundShown(a.getBoolean(R.styleable.CarUiToolbar_showBackground, true));
@@ -408,6 +410,23 @@
}
/**
+ * Sets whether or not tabs should also be shown in the SUBPAGE {@link State}.
+ */
+ public void setShowTabsInSubpage(boolean showTabs) {
+ if (mShowTabsInSubpage != showTabs) {
+ mShowTabsInSubpage = showTabs;
+ setState(getState());
+ }
+ }
+
+ /**
+ * Gets whether or not tabs should also be shown in the SUBPAGE {@link State}.
+ */
+ public boolean getShowTabsInSubpage() {
+ return mShowTabsInSubpage;
+ }
+
+ /**
* Sets the logo to display in this toolbar. If navigation icon is being displayed, this logo
* will be displayed next to the title.
*/
@@ -804,13 +823,14 @@
mNavIconContainer.setOnClickListener(state != State.HOME ? backClickListener : null);
mNavIconContainer.setClickable(state != State.HOME);
- boolean hasTabs = mTabLayout.getTabCount() > 0;
+ boolean hasTabs = mTabLayout.getTabCount() > 0
+ && (state == State.HOME || (state == State.SUBPAGE && mShowTabsInSubpage));
// Show the title if we're in the subpage state, or in the home state with no tabs or tabs
// on the second row
- mTitle.setVisibility(state == State.SUBPAGE
- || (state == State.HOME && (!hasTabs || mIsTabsInSecondRow))
+ mTitle.setVisibility((state == State.SUBPAGE || state == State.HOME)
+ && (!hasTabs || mIsTabsInSecondRow)
? VISIBLE : GONE);
- mTabLayout.setVisibility(state == State.HOME && hasTabs ? VISIBLE : GONE);
+ mTabLayout.setVisibility(hasTabs ? VISIBLE : GONE);
if (mSearchView != null) {
if (state == State.SEARCH || state == State.EDIT) {
diff --git a/car-ui-lib/tests/paintbooth/res/values/strings.xml b/car-ui-lib/tests/paintbooth/res/values/strings.xml
index 8132ef3..1022731 100644
--- a/car-ui-lib/tests/paintbooth/res/values/strings.xml
+++ b/car-ui-lib/tests/paintbooth/res/values/strings.xml
@@ -209,6 +209,9 @@
<!-- Text for add tab with custom text button [CHAR_LIMIT=40]-->
<string name="toolbar_add_tab_with_custom_text">Add tab with custom text</string>
+ <!-- Text for showing tabs in subpages [CHAR_LIMIT=50]-->
+ <string name="toolbar_show_tabs_in_subpage">Toggle showing tabs in subpages</string>
+
<!-- Text for toggle search icon button [CHAR_LIMIT=30]-->
<string name="toolbar_toggle_search_icon">Toggle search icon</string>
diff --git a/car-ui-lib/tests/paintbooth/src/com/android/car/ui/paintbooth/toolbar/ToolbarActivity.java b/car-ui-lib/tests/paintbooth/src/com/android/car/ui/paintbooth/toolbar/ToolbarActivity.java
index 04649f8..f71b5ac 100644
--- a/car-ui-lib/tests/paintbooth/src/com/android/car/ui/paintbooth/toolbar/ToolbarActivity.java
+++ b/car-ui-lib/tests/paintbooth/src/com/android/car/ui/paintbooth/toolbar/ToolbarActivity.java
@@ -270,6 +270,9 @@
.show();
}));
+ mButtons.add(Pair.create(getString(R.string.toolbar_show_tabs_in_subpage), v ->
+ toolbar.setShowTabsInSubpage(!toolbar.getShowTabsInSubpage())));
+
Mutable<Boolean> showingLauncherIcon = new Mutable<>(false);
mButtons.add(Pair.create(getString(R.string.toolbar_toggle_search_icon), v -> {
if (showingLauncherIcon.value) {