Refactor our colors to rely on the Theme more

We should try to use Theme.DeviceDefault wherever possible, to
allow easier customization.

One artifact that this fixes is the Preference Categories being blue
on the polestar bench while the switches are orange.

Fixes: 143958063
Test: Manually
Change-Id: Ia8f127eba1b94bd93da7f24a845f2eb1e6aa0ea6
diff --git a/car-ui-lib/res/color/car_ui_primary_text_color.xml b/car-ui-lib/res/color/car_ui_color_accent.xml
similarity index 75%
copy from car-ui-lib/res/color/car_ui_primary_text_color.xml
copy to car-ui-lib/res/color/car_ui_color_accent.xml
index f238428..9c227cf 100644
--- a/car-ui-lib/res/color/car_ui_primary_text_color.xml
+++ b/car-ui-lib/res/color/car_ui_color_accent.xml
@@ -14,10 +14,8 @@
     See the License for the specific language governing permissions and
     limitations under the License.
 -->
-<!-- Default text colors for car buttons when enabled/disabled. -->
+<!-- We need this to be a selector instead of a straight reference or else the
+     app will crash when using it as a TextView's text color -->
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
-    <item android:state_enabled="false"
-        android:alpha="0.50"
-        android:color="@android:color/white" />
-    <item android:color="@android:color/white" />
-</selector>
\ No newline at end of file
+    <item android:color="?android:attr/colorAccent"/>
+</selector>
diff --git a/car-ui-lib/res/color/car_ui_secondary_text_color.xml b/car-ui-lib/res/color/car_ui_secondary_text_color.xml
deleted file mode 100644
index f0c6f45..0000000
--- a/car-ui-lib/res/color/car_ui_secondary_text_color.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-    Copyright (C) 2019 The Android Open Source Project
-
-    Licensed under the Apache License, Version 2.0 (the "License");
-    you may not use this file except in compliance with the License.
-    You may obtain a copy of the License at
-
-      http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing, software
-    distributed under the License is distributed on an "AS IS" BASIS,
-    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-    See the License for the specific language governing permissions and
-    limitations under the License.
--->
-<!-- Default text colors for car buttons when enabled/disabled. -->
-<selector xmlns:android="http://schemas.android.com/apk/res/android">
-    <item android:state_enabled="false"
-        android:alpha="0.36"
-        android:color="@android:color/white"/>
-    <item android:color="@android:color/white"
-        android:alpha="0.72" />
-</selector>
\ No newline at end of file
diff --git a/car-ui-lib/res/color/car_ui_primary_text_color.xml b/car-ui-lib/res/color/car_ui_text_color_hint.xml
similarity index 75%
rename from car-ui-lib/res/color/car_ui_primary_text_color.xml
rename to car-ui-lib/res/color/car_ui_text_color_hint.xml
index f238428..5292699 100644
--- a/car-ui-lib/res/color/car_ui_primary_text_color.xml
+++ b/car-ui-lib/res/color/car_ui_text_color_hint.xml
@@ -14,10 +14,8 @@
     See the License for the specific language governing permissions and
     limitations under the License.
 -->
-<!-- Default text colors for car buttons when enabled/disabled. -->
+<!-- We need this to be a selector instead of a straight reference or else the
+     app will crash when using it as a TextView's text color -->
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
-    <item android:state_enabled="false"
-        android:alpha="0.50"
-        android:color="@android:color/white" />
-    <item android:color="@android:color/white" />
-</selector>
\ No newline at end of file
+    <item android:color="?android:attr/textColorHint"/>
+</selector>
diff --git a/car-ui-lib/res/color/car_ui_text_color_primary.xml b/car-ui-lib/res/color/car_ui_text_color_primary.xml
new file mode 100644
index 0000000..d310838
--- /dev/null
+++ b/car-ui-lib/res/color/car_ui_text_color_primary.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright (C) 2019 The Android Open Source Project
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<!-- Copy of ?android:attr/textColorPrimary (frameworks/base/res/res/color/text_color_primary.xml)
+     but with a ux restricted state. -->
+<selector xmlns:android="http://schemas.android.com/apk/res/android"
+          xmlns:app="http://schemas.android.com/apk/res-auto">
+    <item android:state_enabled="false"
+          android:alpha="?android:attr/disabledAlpha"
+          android:color="?android:attr/colorForeground"/>
+    <item app:state_ux_restricted="true"
+          android:alpha="?android:attr/disabledAlpha"
+          android:color="?android:attr/colorForeground"/>
+    <item android:color="?android:attr/colorForeground"/>
+</selector>
diff --git a/car-ui-lib/res/color/car_ui_text_color_secondary.xml b/car-ui-lib/res/color/car_ui_text_color_secondary.xml
new file mode 100644
index 0000000..4c9f267
--- /dev/null
+++ b/car-ui-lib/res/color/car_ui_text_color_secondary.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright (C) 2019 The Android Open Source Project
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<!-- Copy of ?android:attr/textColorSecondary (frameworks/base/res/res/color/text_color_secondary.xml)
+     but with a ux restricted state. -->
+<selector xmlns:android="http://schemas.android.com/apk/res/android"
+          xmlns:app="http://schemas.android.com/apk/res-auto">
+    <item android:state_enabled="false"
+          android:alpha="?android:attr/disabledAlpha"
+          android:color="?android:attr/colorForeground"/>
+    <item app:state_ux_restricted="true"
+          android:alpha="?android:attr/disabledAlpha"
+          android:color="?android:attr/colorForeground"/>
+    <item android:alpha="?android:attr/secondaryContentAlpha"
+          android:color="?android:attr/colorForeground"/>
+</selector>
diff --git a/car-ui-lib/res/color/car_ui_toolbar_menu_item_icon_background_color.xml b/car-ui-lib/res/color/car_ui_toolbar_menu_item_icon_background_color.xml
index 85a9a53..5a8e81e 100644
--- a/car-ui-lib/res/color/car_ui_toolbar_menu_item_icon_background_color.xml
+++ b/car-ui-lib/res/color/car_ui_toolbar_menu_item_icon_background_color.xml
@@ -14,11 +14,18 @@
   See the License for the specific language governing permissions and
   limitations under the License.
   -->
-
+<!-- The same as @color/car_ui_text_color_primary but with an activated state.
+     ColorStateLists don't support switching to complex colors, so we have to repeat
+     car_ui_text_color_primary here. -->
 <selector xmlns:android="http://schemas.android.com/apk/res/android"
           xmlns:app="http://schemas.android.com/apk/res-auto">
-    <item android:color="@color/car_ui_toolbar_menu_item_icon_background_deactivated_color" android:state_activated="false"/>
-    <item android:color="@color/car_ui_toolbar_menu_item_icon_background_disabled_color" android:state_enabled="false"/>
-    <item android:color="@color/car_ui_toolbar_menu_item_icon_background_restricted_color" app:state_ux_restricted="true"/>
-    <item android:color="@color/car_ui_toolbar_menu_item_icon_background_activated_color"/>
+    <item android:state_activated="false"
+          android:color="@android:color/transparent"/>
+    <item android:state_enabled="false"
+          android:alpha="?android:attr/disabledAlpha"
+          android:color="?android:attr/colorForeground"/>
+    <item app:state_ux_restricted="true"
+          android:alpha="?android:attr/disabledAlpha"
+          android:color="?android:attr/colorForeground"/>
+    <item android:color="?android:attr/colorForeground" />
 </selector>
diff --git a/car-ui-lib/res/color/car_ui_toolbar_menu_item_icon_color.xml b/car-ui-lib/res/color/car_ui_toolbar_menu_item_icon_color.xml
index f730c5a..d6e5dea 100644
--- a/car-ui-lib/res/color/car_ui_toolbar_menu_item_icon_color.xml
+++ b/car-ui-lib/res/color/car_ui_toolbar_menu_item_icon_color.xml
@@ -14,11 +14,18 @@
   See the License for the specific language governing permissions and
   limitations under the License.
   -->
-
+<!-- The same as @color/car_ui_text_color_primary but with an activated state.
+     ColorStateLists don't support switching to complex colors, so we have to repeat
+     car_ui_text_color_primary here. -->
 <selector xmlns:android="http://schemas.android.com/apk/res/android"
           xmlns:app="http://schemas.android.com/apk/res-auto">
-    <item android:color="@color/car_ui_toolbar_menu_item_icon_activated_color" android:state_activated="true"/>
-    <item android:color="@color/car_ui_toolbar_menu_item_icon_disabled_color" android:state_enabled="false"/>
-    <item android:color="@color/car_ui_toolbar_menu_item_icon_restricted_color" app:state_ux_restricted="true"/>
-    <item android:color="@color/car_ui_toolbar_menu_item_icon_deactivated_color"/>
+    <item android:state_activated="true"
+          android:color="?android:attr/colorBackground"/>
+    <item android:state_enabled="false"
+          android:alpha="?android:attr/disabledAlpha"
+          android:color="?android:attr/colorForeground"/>
+    <item app:state_ux_restricted="true"
+          android:alpha="?android:attr/disabledAlpha"
+          android:color="?android:attr/colorForeground"/>
+    <item android:color="?android:attr/colorForeground" />
 </selector>
diff --git a/car-ui-lib/res/values/colors.xml b/car-ui-lib/res/values/colors.xml
index ae35ba5..0cca026 100644
--- a/car-ui-lib/res/values/colors.xml
+++ b/car-ui-lib/res/values/colors.xml
@@ -24,23 +24,13 @@
     <!-- Toolbar -->
 
     <!-- Color used on the navigation icon -->
-    <color name="car_ui_toolbar_nav_icon_color">@color/car_ui_primary_text_color</color>
+    <color name="car_ui_toolbar_nav_icon_color">@color/car_ui_text_color_primary</color>
     <!-- Text color applied to the hint displayed inside the search box -->
-    <color name="car_ui_toolbar_search_hint_text_color">#33FFFFFF</color>
-    <!-- Menu item colors -->
-    <color name="car_ui_toolbar_menu_item_icon_deactivated_color">@color/car_ui_primary_text_color</color>
-    <color name="car_ui_toolbar_menu_item_icon_disabled_color">@color/car_ui_secondary_text_color</color>
-    <color name="car_ui_toolbar_menu_item_icon_restricted_color">@color/car_ui_secondary_text_color</color>
-    <color name="car_ui_toolbar_menu_item_icon_activated_color">#FF000000</color>
-    <!-- Menu item background colors -->
-    <color name="car_ui_toolbar_menu_item_icon_background_deactivated_color">@android:color/transparent</color>
-    <color name="car_ui_toolbar_menu_item_icon_background_disabled_color">@color/car_ui_toolbar_menu_item_icon_disabled_color</color>
-    <color name="car_ui_toolbar_menu_item_icon_background_restricted_color">@color/car_ui_toolbar_menu_item_icon_restricted_color</color>
-    <color name="car_ui_toolbar_menu_item_icon_background_activated_color">@color/car_ui_primary_text_color</color>
+    <color name="car_ui_toolbar_search_hint_text_color">@color/car_ui_text_color_hint</color>
     <!-- Tab selected color -->
-    <color name="car_ui_toolbar_tab_selected_color">@color/car_ui_primary_text_color</color>
+    <color name="car_ui_toolbar_tab_selected_color">@color/car_ui_text_color_primary</color>
     <!-- Tab normal color -->
-    <color name="car_ui_toolbar_tab_unselected_color">@color/car_ui_secondary_text_color</color>
+    <color name="car_ui_toolbar_tab_unselected_color">@color/car_ui_text_color_secondary</color>
 
     <!-- Recycler View  -->
 
@@ -51,10 +41,10 @@
 
     <!-- Preferences -->
 
-    <color name="car_ui_preference_category_title_text_color">#ff60a8f0</color>
-    <color name="car_ui_preference_summary_text_color">@color/car_ui_secondary_text_color</color>
-    <color name="car_ui_preference_title_text_color">@color/car_ui_primary_text_color</color>
-    <color name="car_ui_preference_edit_text_dialog_message_text_color">#ffdadce0</color>
-    <color name="car_ui_preference_icon_color">@android:color/white</color>
-    <color name="car_ui_preference_switch_track_text_color">@android:color/white</color>
+    <color name="car_ui_preference_category_title_text_color">@color/car_ui_color_accent</color>
+    <color name="car_ui_preference_summary_text_color">@color/car_ui_text_color_secondary</color>
+    <color name="car_ui_preference_title_text_color">@color/car_ui_text_color_primary</color>
+    <color name="car_ui_preference_edit_text_dialog_message_text_color">@color/car_ui_text_color_primary</color>
+    <color name="car_ui_preference_icon_color">@color/car_ui_text_color_primary</color>
+    <color name="car_ui_preference_switch_track_text_color">@color/car_ui_text_color_primary</color>
 </resources>
diff --git a/car-ui-lib/src/com/android/car/ui/drawable/CarUiTextDrawable.java b/car-ui-lib/src/com/android/car/ui/drawable/CarUiTextDrawable.java
index e9c1818..167dfd3 100644
--- a/car-ui-lib/src/com/android/car/ui/drawable/CarUiTextDrawable.java
+++ b/car-ui-lib/src/com/android/car/ui/drawable/CarUiTextDrawable.java
@@ -215,7 +215,7 @@
                 Typeface.NORMAL);
         mTextSize = a.getDimension(R.styleable.CarUiTextDrawable_textSize, 10);
         mTextColor = a.getColor(R.styleable.CarUiTextDrawable_textColor,
-                r.getColor(R.color.car_ui_primary_text_color, theme));
+                r.getColor(R.color.car_ui_text_color_primary, theme));
         a.recycle();
         refreshTextBoundsAndInvalidate();
         super.inflate(r, parser, attrs, theme);
diff --git a/car-ui-lib/tests/apitest/current.xml b/car-ui-lib/tests/apitest/current.xml
index 934aff1..b2c2e7d 100644
--- a/car-ui-lib/tests/apitest/current.xml
+++ b/car-ui-lib/tests/apitest/current.xml
@@ -14,27 +14,21 @@
     <public name="car_ui_toolbar_tab_flexible_layout" type="bool"/>
     <public name="car_ui_toolbar_tabs_on_second_row" type="bool"/>
     <public name="car_ui_activity_background_color" type="color"/>
+    <public name="car_ui_color_accent" type="color"/>
     <public name="car_ui_preference_category_title_text_color" type="color"/>
     <public name="car_ui_preference_edit_text_dialog_message_text_color" type="color"/>
     <public name="car_ui_preference_icon_color" type="color"/>
     <public name="car_ui_preference_summary_text_color" type="color"/>
     <public name="car_ui_preference_switch_track_text_color" type="color"/>
     <public name="car_ui_preference_title_text_color" type="color"/>
-    <public name="car_ui_primary_text_color" type="color"/>
     <public name="car_ui_recyclerview_divider_color" type="color"/>
     <public name="car_ui_ripple_color" type="color"/>
     <public name="car_ui_scrollbar_thumb" type="color"/>
-    <public name="car_ui_secondary_text_color" type="color"/>
-    <public name="car_ui_toolbar_menu_item_icon_activated_color" type="color"/>
-    <public name="car_ui_toolbar_menu_item_icon_background_activated_color" type="color"/>
+    <public name="car_ui_text_color_hint" type="color"/>
+    <public name="car_ui_text_color_primary" type="color"/>
+    <public name="car_ui_text_color_secondary" type="color"/>
     <public name="car_ui_toolbar_menu_item_icon_background_color" type="color"/>
-    <public name="car_ui_toolbar_menu_item_icon_background_deactivated_color" type="color"/>
-    <public name="car_ui_toolbar_menu_item_icon_background_disabled_color" type="color"/>
-    <public name="car_ui_toolbar_menu_item_icon_background_restricted_color" type="color"/>
     <public name="car_ui_toolbar_menu_item_icon_color" type="color"/>
-    <public name="car_ui_toolbar_menu_item_icon_deactivated_color" type="color"/>
-    <public name="car_ui_toolbar_menu_item_icon_disabled_color" type="color"/>
-    <public name="car_ui_toolbar_menu_item_icon_restricted_color" type="color"/>
     <public name="car_ui_toolbar_nav_icon_color" type="color"/>
     <public name="car_ui_toolbar_search_hint_text_color" type="color"/>
     <public name="car_ui_toolbar_tab_item_selector" type="color"/>
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 8b60d4d..53bb773 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
@@ -154,6 +154,9 @@
         mButtons.add(Pair.create("MenuItem: Toggle Visibility", v ->
                 getMenuItem(item -> item.setVisible(!item.isVisible()))));
 
+        mButtons.add(Pair.create("MenuItem: Toggle Enabled", v ->
+                getMenuItem(item -> item.setEnabled(!item.isEnabled()))));
+
         final Drawable altIcon = getDrawable(R.drawable.ic_cut);
         Map<MenuItem, Drawable> iconBackups = new HashMap<>();
         mButtons.add(Pair.create("MenuItem: Toggle Icon", v ->