Fixes for google3

- Removed attributes from car_ui_preference_widget_switch as it made
  the switches look weird, and we should be able to style them through
  the theme anyways.
- Removed getCallbackFragment() from our PreferenceFragment, as it's
  restricted to inside androidx, and seems to always return null

Test: Manually
Change-Id: I2438e9941cbbd601960338c80d1633a1cc0d083e
diff --git a/car-ui-lib/res/layout/car_ui_preference_widget_switch.xml b/car-ui-lib/res/layout/car_ui_preference_widget_switch.xml
index f610a63..b85340c 100644
--- a/car-ui-lib/res/layout/car_ui_preference_widget_switch.xml
+++ b/car-ui-lib/res/layout/car_ui_preference_widget_switch.xml
@@ -19,12 +19,4 @@
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@android:id/switch_widget"
     android:layout_width="wrap_content"
-    android:layout_height="wrap_content"
-    android:background="@drawable/car_ui_switch_preference_background_drawable"
-    android:foreground="?android:attr/selectableItemBackground"
-    android:showText="@bool/car_ui_preference_switch_toggle_show_text"
-    android:textColor="@color/car_ui_preference_switch_text_color"
-    android:textOff="@string/car_ui_switch_preference_off"
-    android:textOn="@string/car_ui_switch_preference_on"
-    android:thumb="@drawable/car_ui_switch_preference_toggle_thumb_drawable"
-    android:track="@drawable/car_ui_switch_preference_toggle_track_drawable"/>
+    android:layout_height="wrap_content"/>
diff --git a/car-ui-lib/res/layout/car_ui_toolbar.xml b/car-ui-lib/res/layout/car_ui_toolbar.xml
index 14d3e64..936646d 100644
--- a/car-ui-lib/res/layout/car_ui_toolbar.xml
+++ b/car-ui-lib/res/layout/car_ui_toolbar.xml
@@ -142,7 +142,7 @@
         android:layout_marginRight="@dimen/car_ui_toolbar_menu_item_margin"
         android:visibility="gone"
         app:layout_constraintTop_toTopOf="@id/toolbar_top_guideline"
-        app:layout_constraintBottom_toTopOf="@id/bottom_styleable"
+        app:layout_constraintBottom_toTopOf="@id/toolbar_bottom_guideline"
         app:layout_constraintEnd_toEndOf="@id/toolbar_end_guideline">
         <ImageView
             android:src="@drawable/car_ui_icon_overflow_menu"
diff --git a/car-ui-lib/res/values/bools.xml b/car-ui-lib/res/values/bools.xml
index 1f3633c..d970184 100644
--- a/car-ui-lib/res/values/bools.xml
+++ b/car-ui-lib/res/values/bools.xml
@@ -29,7 +29,6 @@
     <bool name="car_ui_preference_category_allow_divider_above">false</bool>
     <bool name="car_ui_preference_category_allow_divider_below">false</bool>
 
-    <bool name="car_ui_preference_switch_toggle_show_text">false</bool>
     <bool name="car_ui_preference_switch_toggle_show_animation">true</bool>
     <bool name="car_ui_preference_show_chevron">false</bool>
 </resources>
diff --git a/car-ui-lib/res/values/colors.xml b/car-ui-lib/res/values/colors.xml
index 891022c..915ea42 100644
--- a/car-ui-lib/res/values/colors.xml
+++ b/car-ui-lib/res/values/colors.xml
@@ -50,6 +50,4 @@
 
     <color name="car_ui_preference_icon_color">@android:color/white</color>
 
-    <color name="car_ui_preference_switch_text_color">#000000</color>
-
 </resources>
diff --git a/car-ui-lib/res/values/strings.xml b/car-ui-lib/res/values/strings.xml
index 4f04884..5249ad4 100644
--- a/car-ui-lib/res/values/strings.xml
+++ b/car-ui-lib/res/values/strings.xml
@@ -31,10 +31,6 @@
     <string name="car_ui_dialog_preference_positive">Ok</string>
     <!-- Negative option for a preference dialog. [CHAR_LIMIT=30] -->
     <string name="car_ui_dialog_preference_negative">Cancel</string>
-    <!-- Text to show when a preference switch is on. [CHAR_LIMIT=30] -->
-    <string name="car_ui_switch_preference_on">On</string>
-    <!-- Text to show when a preference switch is off. [CHAR_LIMIT=30] -->
-    <string name="car_ui_switch_preference_off">Off</string>
     <!-- Font family to use for preference category titles. [CHAR_LIMIT=NONE] -->
     <string name="car_ui_preference_category_title_font_family" translatable="false">sans-serif-medium</string>
 
diff --git a/car-ui-lib/res/values/styles.xml b/car-ui-lib/res/values/styles.xml
index f8e8c49..3b89f9c 100644
--- a/car-ui-lib/res/values/styles.xml
+++ b/car-ui-lib/res/values/styles.xml
@@ -87,8 +87,6 @@
 
     <style name="Preference.CarUi.SwitchPreference">
         <item name="android:widgetLayout">@layout/car_ui_preference_widget_switch</item>
-        <item name="android:switchTextOn">@string/car_ui_switch_preference_on</item>
-        <item name="android:switchTextOff">@string/car_ui_switch_preference_off</item>
     </style>
 
     <style name="PreferenceFragment.CarUi">
diff --git a/car-ui-lib/res/values/values.xml b/car-ui-lib/res/values/values.xml
index d6da9e9..a33f167 100644
--- a/car-ui-lib/res/values/values.xml
+++ b/car-ui-lib/res/values/values.xml
@@ -19,8 +19,5 @@
     <bool name="car_ui_tab_flexible_layout">false</bool>
     <item name="car_ui_tab_item_layout" type="layout">@layout/car_ui_tab_item</item>
 
-    <item name="car_ui_switch_preference_toggle_thumb_drawable" type="drawable">@*android:drawable/switch_thumb_material_anim</item>
-    <item name="car_ui_switch_preference_toggle_track_drawable" type="drawable">@*android:drawable/switch_track_material</item>
-    <item name="car_ui_switch_preference_background_drawable" type="drawable">@null</item>
     <item name="car_ui_preference_icon_chevron_drawable" type="drawable">@null</item>
 </resources>
diff --git a/car-ui-lib/src/com/android/car/ui/preference/PreferenceFragment.java b/car-ui-lib/src/com/android/car/ui/preference/PreferenceFragment.java
index 68d0699..aee90f0 100644
--- a/car-ui-lib/src/com/android/car/ui/preference/PreferenceFragment.java
+++ b/car-ui-lib/src/com/android/car/ui/preference/PreferenceFragment.java
@@ -48,17 +48,9 @@
     @Override
     public void onDisplayPreferenceDialog(Preference preference) {
 
-        boolean handled = false;
-        if (getCallbackFragment() instanceof OnPreferenceDisplayDialogCallback) {
-            handled = ((OnPreferenceDisplayDialogCallback) getCallbackFragment())
-                    .onPreferenceDisplayDialog(this, preference);
-        }
-        if (!handled && getActivity() instanceof OnPreferenceDisplayDialogCallback) {
-            handled = ((OnPreferenceDisplayDialogCallback) getActivity())
-                    .onPreferenceDisplayDialog(this, preference);
-        }
-
-        if (handled) {
+        if (getActivity() instanceof OnPreferenceDisplayDialogCallback
+                && ((OnPreferenceDisplayDialogCallback) getActivity())
+                .onPreferenceDisplayDialog(this, preference)) {
             return;
         }
 
diff --git a/car-ui-lib/src/com/android/car/ui/preference/PreferenceSwitchWidget.java b/car-ui-lib/src/com/android/car/ui/preference/PreferenceSwitchWidget.java
index 39ad79a..e15a351 100644
--- a/car-ui-lib/src/com/android/car/ui/preference/PreferenceSwitchWidget.java
+++ b/car-ui-lib/src/com/android/car/ui/preference/PreferenceSwitchWidget.java
@@ -28,11 +28,11 @@
  */
 public class PreferenceSwitchWidget extends Switch {
 
-    private Context mContext;
+    private boolean mEnableAnimation = true;
 
     public PreferenceSwitchWidget(Context context) {
         super(context);
-        mContext = context;
+        init(context);
     }
 
     public PreferenceSwitchWidget(Context context, AttributeSet attrs) {
@@ -42,26 +42,25 @@
 
     public PreferenceSwitchWidget(Context context, AttributeSet attrs, int defStyleAttr) {
         super(context, attrs, defStyleAttr);
-        mContext = context;
+        init(context);
     }
 
     public PreferenceSwitchWidget(Context context, AttributeSet attrs, int defStyleAttr,
             int defStyleRes) {
         super(context, attrs, defStyleAttr, defStyleRes);
-        mContext = context;
+        init(context);
+    }
+
+    private void init(Context context) {
+        mEnableAnimation = context.getResources().getBoolean(
+                R.bool.car_ui_preference_switch_toggle_show_animation);
     }
 
     @Override
     public void setChecked(boolean checked) {
         super.setChecked(checked);
 
-        if (mContext == null) {
-            return;
-        }
-
-        boolean enableAnimation = mContext.getResources().getBoolean(
-                R.bool.car_ui_preference_switch_toggle_show_animation);
-        if (!enableAnimation) {
+        if (!mEnableAnimation) {
             jumpDrawablesToCurrentState();
         }
     }
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 db9e00b..85085c2 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
@@ -185,7 +185,8 @@
         }
     }
 
-    private CarUiRecyclerView.Adapter mAdapter = new CarUiRecyclerView.Adapter() {
+    private CarUiRecyclerView.Adapter<ViewHolder> mAdapter =
+            new CarUiRecyclerView.Adapter<ViewHolder>() {
         @Override
         public int getItemCount() {
             return mButtons.size();
@@ -199,9 +200,9 @@
         }
 
         @Override
-        public void onBindViewHolder(@NonNull CarUiRecyclerView.ViewHolder holder, int position) {
+        public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
             Pair<CharSequence, View.OnClickListener> pair = mButtons.get(position);
-            ((ViewHolder) holder).bind(pair.first, pair.second);
+            holder.bind(pair.first, pair.second);
         }
     };