Twelve: SettingsLib: Use Material 3 switches

Change-Id: I57f84693251620c5398c288b6e6fe9a2b32ffe09
diff --git a/app/src/main/res/color/settingslib_switch_thumb_color.xml b/app/src/main/res/color/settingslib_switch_thumb_color.xml
deleted file mode 100644
index ce1668d..0000000
--- a/app/src/main/res/color/settingslib_switch_thumb_color.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-     SPDX-FileCopyrightText: 2021 The Android Open Source Project
-     SPDX-License-Identifier: Apache-2.0
--->
-<selector xmlns:android="http://schemas.android.com/apk/res/android">
-    <!-- Disabled status of thumb -->
-    <item android:color="?attr/colorOutline" android:state_enabled="false" />
-    <!-- Toggle off status of thumb -->
-    <item android:color="?attr/colorOutline" android:state_checked="false" />
-    <!-- Enabled or toggle on status of thumb -->
-    <item android:color="?attr/colorOnPrimary" />
-</selector>
diff --git a/app/src/main/res/color/settingslib_switch_track_color.xml b/app/src/main/res/color/settingslib_switch_track_color.xml
deleted file mode 100644
index ba62e66..0000000
--- a/app/src/main/res/color/settingslib_switch_track_color.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-     SPDX-FileCopyrightText: 2021 The Android Open Source Project
-     SPDX-License-Identifier: Apache-2.0
--->
-<selector xmlns:android="http://schemas.android.com/apk/res/android">
-    <!-- Disabled status of thumb -->
-    <item android:alpha="?android:attr/disabledAlpha" android:color="?attr/colorSurfaceVariant" android:state_enabled="false" />
-    <!-- Toggle off status of thumb -->
-    <item android:color="?attr/colorSurfaceVariant" android:state_checked="false" />
-    <!-- Enabled or toggle on status of thumb -->
-    <item android:color="?attr/colorPrimary" />
-</selector>
diff --git a/app/src/main/res/drawable/settingslib_switch_thumb.xml b/app/src/main/res/drawable/settingslib_switch_thumb.xml
deleted file mode 100644
index 35ca08d..0000000
--- a/app/src/main/res/drawable/settingslib_switch_thumb.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-     SPDX-FileCopyrightText: 2021 The Android Open Source Project
-     SPDX-License-Identifier: Apache-2.0
--->
-<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
-    <item
-        android:bottom="4dp"
-        android:left="4dp"
-        android:right="4dp"
-        android:top="4dp">
-        <shape android:shape="oval">
-            <size
-                android:width="20dp"
-                android:height="20dp" />
-            <solid android:color="@color/settingslib_switch_thumb_color" />
-        </shape>
-    </item>
-</layer-list>
diff --git a/app/src/main/res/drawable/settingslib_switch_track.xml b/app/src/main/res/drawable/settingslib_switch_track.xml
deleted file mode 100644
index 52675f5..0000000
--- a/app/src/main/res/drawable/settingslib_switch_track.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-     SPDX-FileCopyrightText: 2021 The Android Open Source Project
-     SPDX-License-Identifier: Apache-2.0
--->
-<shape xmlns:android="http://schemas.android.com/apk/res/android"
-    android:width="52dp"
-    android:height="28dp"
-    android:shape="rectangle">
-
-    <solid android:color="@color/settingslib_switch_track_color" />
-    <corners android:radius="35dp" />
-</shape>
diff --git a/app/src/main/res/layout/settingslib_switch.xml b/app/src/main/res/layout/settingslib_switch.xml
new file mode 100644
index 0000000..5020013
--- /dev/null
+++ b/app/src/main/res/layout/settingslib_switch.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     SPDX-FileCopyrightText: 2024 The LineageOS Project
+     SPDX-License-Identifier: Apache-2.0
+-->
+<com.google.android.material.materialswitch.MaterialSwitch 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="@null"
+    android:clickable="false"
+    android:focusable="false" />
diff --git a/app/src/main/res/layout/settingslib_switch_compat.xml b/app/src/main/res/layout/settingslib_switch_compat.xml
new file mode 100644
index 0000000..2815d87
--- /dev/null
+++ b/app/src/main/res/layout/settingslib_switch_compat.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     SPDX-FileCopyrightText: 2024 The LineageOS Project
+     SPDX-License-Identifier: Apache-2.0
+-->
+<com.google.android.material.materialswitch.MaterialSwitch xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/switchWidget"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content"
+    android:background="@null"
+    android:clickable="false"
+    android:focusable="false" />
diff --git a/app/src/main/res/values/themes_settingslib.xml b/app/src/main/res/values/themes_settingslib.xml
index 7c83791..855b562 100644
--- a/app/src/main/res/values/themes_settingslib.xml
+++ b/app/src/main/res/values/themes_settingslib.xml
@@ -8,7 +8,6 @@
     <style name="Theme.SettingsLib" parent="Theme.Material3.DayNight.NoActionBar">
         <item name="android:listPreferredItemPaddingLeft">24dp</item>
         <item name="android:listPreferredItemPaddingStart">24dp</item>
-        <item name="android:switchStyle">@style/Theme.SettingsLib.Switch</item>
         <item name="alertDialogTheme">@style/Theme.SettingsLib.AlertDialog</item>
         <item name="materialAlertDialogTheme">@style/Theme.SettingsLib.AlertDialog</item>
         <item name="preferenceTheme">@style/Theme.SettingsLib.PreferenceTheme</item>
@@ -20,14 +19,6 @@
         <item name="dialogCornerRadius">16dp</item>
     </style>
 
-    <!-- Settings switch theme. -->
-    <style name="Theme.SettingsLib.Switch" parent="@android:style/Widget.Material.CompoundButton.Switch">
-        <item name="android:switchMinWidth">52dp</item>
-        <item name="android:minHeight">48dp</item>
-        <item name="android:track">@drawable/settingslib_switch_track</item>
-        <item name="android:thumb">@drawable/settingslib_switch_thumb</item>
-    </style>
-
     <!-- Settings collapsing toolbar style -->
     <style name="Theme.SettingsLib.ToolbarCollapsedTextAppearance" parent="TextAppearance.Material3.ActionBar.Title" />
 
@@ -43,5 +34,15 @@
         <item name="android:listPreferredItemPaddingLeft">32dp</item>
         <item name="android:listPreferredItemPaddingStart">32dp</item>
         <item name="android:tint">?attr/colorOnSurface</item>
+        <item name="switchPreferenceCompatStyle">@style/Theme.SettingsLib.SwitchPreferenceCompat</item>
+        <item name="switchPreferenceStyle">@style/Theme.SettingsLib.SwitchPreference</item>
+    </style>
+
+    <style name="Theme.SettingsLib.SwitchPreference" parent="@style/Preference.SwitchPreference.Material">
+        <item name="widgetLayout">@layout/settingslib_switch</item>
+    </style>
+
+    <style name="Theme.SettingsLib.SwitchPreferenceCompat" parent="@style/Preference.SwitchPreferenceCompat.Material">
+        <item name="widgetLayout">@layout/settingslib_switch_compat</item>
     </style>
 </resources>