Merge "Allow initial toolbar state to be set in XML" into pi-car-dev
diff --git a/car-chassis-lib/res/values/attrs.xml b/car-chassis-lib/res/values/attrs.xml
index 5a49a20..3491748 100644
--- a/car-chassis-lib/res/values/attrs.xml
+++ b/car-chassis-lib/res/values/attrs.xml
@@ -15,16 +15,23 @@
-->
<resources>
<declare-styleable name="ChassisToolbar">
- <!-- The title of the toolbar, only displayed in certain conditions -->
+ <!-- Title of the toolbar, only displayed in certain conditions -->
<attr name="title" format="string"/>
- <!-- The logo drawable for the toolbar. Appears when there's no back/close button shown -->
+ <!-- Logo drawable for the toolbar. Appears when there's no back/close button shown -->
<attr name="logo" format="reference"/>
- <!-- The hint for the search bar in the toolbar -->
+ <!-- Hint for the search bar in the toolbar -->
<attr name="searchHint" format="string"/>
- <!-- The buttons to display, as an array of layout ids. Use @layout/chassis_toolbar_search_button and @layout/chassis_toolbar_settings_button for the search and settings buttons -->
+ <!-- Buttons to display, as an array of layout ids. Use @layout/chassis_toolbar_search_button and @layout/chassis_toolbar_settings_button for the search and settings buttons -->
<attr name="buttons" format="reference"/>
<!-- Whether or not to show the custom buttons while searching. If using chassis_toolbar_search_button, or any other layout with a view with the id of "search", it will always be hidden. -->
<attr name="showButtonsWhileSearching" format="boolean"/>
+ <!-- Initial state of the toolbar. See the Toolbar.State enum for more information -->
+ <attr name="state" format="enum">
+ <enum name="home" value="0"/>
+ <enum name="subpage" value="1"/>
+ <enum name="subpage_custom" value="2"/>
+ <enum name="search" value="3"/>
+ </attr>
</declare-styleable>
<!-- Theme attribute to specifying a default style for all chassisToolbars -->
diff --git a/car-chassis-lib/src/com/android/car/chassis/Toolbar.java b/car-chassis-lib/src/com/android/car/chassis/Toolbar.java
index 6048c30..ae51e92 100644
--- a/car-chassis-lib/src/com/android/car/chassis/Toolbar.java
+++ b/car-chassis-lib/src/com/android/car/chassis/Toolbar.java
@@ -18,6 +18,7 @@
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
+import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
@@ -47,6 +48,8 @@
*/
public class Toolbar extends FrameLayout {
+ private static final String TAG = "ChassisToolbar";
+
/** Enum of states the toolbar can be in. Controls what elements of the toolbar are displayed */
public enum State {
/**
@@ -135,6 +138,26 @@
setSearchHint(searchHint);
}
+ switch (a.getInt(R.styleable.ChassisToolbar_state, 0)) {
+ case 0:
+ setState(State.HOME);
+ break;
+ case 1:
+ setState(State.SUBPAGE);
+ break;
+ case 2:
+ setState(State.SUBPAGE_CUSTOM);
+ break;
+ case 3:
+ setState(State.SEARCH);
+ break;
+ default:
+ if (Log.isLoggable(TAG, Log.WARN)) {
+ Log.w(TAG, "Unknown initial state");
+ }
+ break;
+ }
+
a.recycle();
mTabLayout.addListener(new TabLayout.Listener() {