summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Stanley Wang <stanleytfwang@google.com> 2021-03-09 21:13:17 +0800
committer Stanley Wang <stanleytfwang@google.com> 2021-05-07 16:02:44 +0800
commitd979dbd6af97cb32c91a9c1b4a4a9b3515cef489 (patch)
tree8d445b97f250b0362c69cc39f29848024c7bfeb4
parentf9e526df48bad6012c3049637bb5b5cf134967a2 (diff)
Update MainSwitchBar to Material Next style.
Fix: 182255113 Test: Run robotest and see the ui Change-Id: I2d407bb463a13ed986fe7fe3611e4c00c55284dd
-rw-r--r--packages/SettingsLib/MainSwitchPreference/Android.bp2
-rw-r--r--packages/SettingsLib/MainSwitchPreference/res/drawable/switch_bar_bg_disabled.xml (renamed from packages/SettingsLib/MainSwitchPreference/res/drawable/track_on.xml)20
-rw-r--r--packages/SettingsLib/MainSwitchPreference/res/drawable/switch_bar_bg_off.xml (renamed from packages/SettingsLib/MainSwitchPreference/res/drawable/track_off_indicator.xml)28
-rw-r--r--packages/SettingsLib/MainSwitchPreference/res/drawable/switch_bar_bg_on.xml (renamed from packages/SettingsLib/MainSwitchPreference/res/drawable/track_off.xml)20
-rw-r--r--packages/SettingsLib/MainSwitchPreference/res/drawable/thumb_disabled.xml33
-rw-r--r--packages/SettingsLib/MainSwitchPreference/res/drawable/thumb_off.xml24
-rw-r--r--packages/SettingsLib/MainSwitchPreference/res/drawable/thumb_on.xml24
-rw-r--r--packages/SettingsLib/MainSwitchPreference/res/drawable/thumb_selector.xml5
-rw-r--r--packages/SettingsLib/MainSwitchPreference/res/drawable/track_disabled_background.xml (renamed from packages/SettingsLib/MainSwitchPreference/res/drawable/track_on_indicator.xml)25
-rw-r--r--packages/SettingsLib/MainSwitchPreference/res/drawable/track_off_background.xml24
-rw-r--r--packages/SettingsLib/MainSwitchPreference/res/drawable/track_on_background.xml26
-rw-r--r--packages/SettingsLib/MainSwitchPreference/res/drawable/track_selector.xml5
-rw-r--r--packages/SettingsLib/MainSwitchPreference/res/layout-v31/main_switch_bar.xml13
-rw-r--r--packages/SettingsLib/MainSwitchPreference/res/layout/main_switch_bar.xml1
-rw-r--r--packages/SettingsLib/MainSwitchPreference/res/values-night/colors.xml9
-rw-r--r--packages/SettingsLib/MainSwitchPreference/res/values/colors.xml18
-rw-r--r--packages/SettingsLib/MainSwitchPreference/res/values/dimens.xml20
-rw-r--r--packages/SettingsLib/MainSwitchPreference/res/values/styles.xml2
-rw-r--r--packages/SettingsLib/MainSwitchPreference/src/com/android/settingslib/widget/MainSwitchBar.java30
-rw-r--r--packages/SettingsLib/MainSwitchPreference/src/com/android/settingslib/widget/MainSwitchPreference.java2
-rw-r--r--packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/MainSwitchPreferenceTest.java9
21 files changed, 187 insertions, 153 deletions
diff --git a/packages/SettingsLib/MainSwitchPreference/Android.bp b/packages/SettingsLib/MainSwitchPreference/Android.bp
index 7b7496ca650a..4ce854ada849 100644
--- a/packages/SettingsLib/MainSwitchPreference/Android.bp
+++ b/packages/SettingsLib/MainSwitchPreference/Android.bp
@@ -14,7 +14,7 @@ android_library {
resource_dirs: ["res"],
static_libs: [
- "androidx.preference_preference",
+ "androidx.preference_preference",
],
sdk_version: "system_current",
diff --git a/packages/SettingsLib/MainSwitchPreference/res/drawable/track_on.xml b/packages/SettingsLib/MainSwitchPreference/res/drawable/switch_bar_bg_disabled.xml
index cf241129f16d..b646f0a5d26d 100644
--- a/packages/SettingsLib/MainSwitchPreference/res/drawable/track_on.xml
+++ b/packages/SettingsLib/MainSwitchPreference/res/drawable/switch_bar_bg_disabled.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
- Copyright (C) 2020 The Android Open Source Project
+ Copyright (C) 2021 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.
@@ -15,12 +15,12 @@
limitations under the License.
-->
-<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:drawable="@drawable/track_on_background" />
- <item
- android:width="13.19dp"
- android:height="10.06dp"
- android:gravity="center"
- android:right="21dp"
- android:drawable="@drawable/track_on_indicator" />
-</layer-list>
+<ripple xmlns:android="http://schemas.android.com/apk/res/android"
+ android:color="?android:attr/colorControlHighlight">
+ <item>
+ <shape android:shape="rectangle">
+ <solid android:color="@color/state_off_color"/>
+ <corners android:radius="@dimen/switch_bar_radius"/>
+ </shape>
+ </item>
+</ripple>
diff --git a/packages/SettingsLib/MainSwitchPreference/res/drawable/track_off_indicator.xml b/packages/SettingsLib/MainSwitchPreference/res/drawable/switch_bar_bg_off.xml
index 6cc6224ae6c5..b646f0a5d26d 100644
--- a/packages/SettingsLib/MainSwitchPreference/res/drawable/track_off_indicator.xml
+++ b/packages/SettingsLib/MainSwitchPreference/res/drawable/switch_bar_bg_off.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
- Copyright (C) 2020 The Android Open Source Project
+ Copyright (C) 2021 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.
@@ -15,20 +15,12 @@
limitations under the License.
-->
-<vector
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:width="13.33dp"
- android:height="1.67dp"
- android:viewportWidth="13.33"
- android:viewportHeight="1.67">
-
- <group>
- <clip-path
- android:pathData="M0 0H13.3333V1.66667H0V0Z" />
-
- <path
- android:pathData="M0 0V1.66667H13.3333V0"
- android:fillColor="@android:color/white" />
- </group>
-
-</vector>
+<ripple xmlns:android="http://schemas.android.com/apk/res/android"
+ android:color="?android:attr/colorControlHighlight">
+ <item>
+ <shape android:shape="rectangle">
+ <solid android:color="@color/state_off_color"/>
+ <corners android:radius="@dimen/switch_bar_radius"/>
+ </shape>
+ </item>
+</ripple>
diff --git a/packages/SettingsLib/MainSwitchPreference/res/drawable/track_off.xml b/packages/SettingsLib/MainSwitchPreference/res/drawable/switch_bar_bg_on.xml
index b29f4596d77c..afea8bd8e288 100644
--- a/packages/SettingsLib/MainSwitchPreference/res/drawable/track_off.xml
+++ b/packages/SettingsLib/MainSwitchPreference/res/drawable/switch_bar_bg_on.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
- Copyright (C) 2020 The Android Open Source Project
+ Copyright (C) 2021 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.
@@ -15,12 +15,12 @@
limitations under the License.
-->
-<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:drawable="@drawable/track_off_background" />
- <item
- android:width="13.33dp"
- android:height="1.67dp"
- android:left="21dp"
- android:gravity="center"
- android:drawable="@drawable/track_off_indicator" />
-</layer-list>
+<ripple xmlns:android="http://schemas.android.com/apk/res/android"
+ android:color="?android:attr/colorControlHighlight">
+ <item>
+ <shape android:shape="rectangle">
+ <solid android:color="@color/state_on_color"/>
+ <corners android:radius="@dimen/switch_bar_radius"/>
+ </shape>
+ </item>
+</ripple>
diff --git a/packages/SettingsLib/MainSwitchPreference/res/drawable/thumb_disabled.xml b/packages/SettingsLib/MainSwitchPreference/res/drawable/thumb_disabled.xml
new file mode 100644
index 000000000000..9e6cfbdff58c
--- /dev/null
+++ b/packages/SettingsLib/MainSwitchPreference/res/drawable/thumb_disabled.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2021 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.
+ -->
+
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+ <item
+ android:top="@dimen/switch_thumb_margin"
+ android:left="@dimen/switch_thumb_margin"
+ android:right="@dimen/switch_thumb_margin"
+ android:bottom="@dimen/switch_thumb_margin">
+ <shape android:shape="oval">
+ <size
+ android:height="@dimen/switch_thumb_size"
+ android:width="@dimen/switch_thumb_size"/>
+ <solid
+ android:color="@color/state_off_color"
+ android:alpha="?android:attr/disabledAlpha"/>
+ </shape>
+ </item>
+</layer-list>
diff --git a/packages/SettingsLib/MainSwitchPreference/res/drawable/thumb_off.xml b/packages/SettingsLib/MainSwitchPreference/res/drawable/thumb_off.xml
index 2be00b95af3c..f6d88151b1fa 100644
--- a/packages/SettingsLib/MainSwitchPreference/res/drawable/thumb_off.xml
+++ b/packages/SettingsLib/MainSwitchPreference/res/drawable/thumb_off.xml
@@ -16,16 +16,16 @@
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
- <item
- android:top="4dp"
- android:left="4dp"
- android:right="4dp"
- android:bottom="4dp">
-
- <shape android:shape="oval" >
- <size android:height="20dp" android:width="20dp" />
- <solid android:color="@color/thumb_off" />
- </shape>
-
- </item>
+ <item
+ android:top="@dimen/switch_thumb_margin"
+ android:left="@dimen/switch_thumb_margin"
+ android:right="@dimen/switch_thumb_margin"
+ android:bottom="@dimen/switch_thumb_margin">
+ <shape android:shape="oval">
+ <size
+ android:height="@dimen/switch_thumb_size"
+ android:width="@dimen/switch_thumb_size"/>
+ <solid android:color="@color/state_off_color"/>
+ </shape>
+ </item>
</layer-list>
diff --git a/packages/SettingsLib/MainSwitchPreference/res/drawable/thumb_on.xml b/packages/SettingsLib/MainSwitchPreference/res/drawable/thumb_on.xml
index e85eb42007b8..61230b5071f2 100644
--- a/packages/SettingsLib/MainSwitchPreference/res/drawable/thumb_on.xml
+++ b/packages/SettingsLib/MainSwitchPreference/res/drawable/thumb_on.xml
@@ -16,16 +16,16 @@
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
- <item
- android:top="4dp"
- android:left="4dp"
- android:right="4dp"
- android:bottom="4dp">
-
- <shape android:shape="oval" >
- <size android:height="20dp" android:width="20dp" />
- <solid android:color="?android:attr/colorAccent" />
- </shape>
-
- </item>
+ <item
+ android:top="@dimen/switch_thumb_margin"
+ android:left="@dimen/switch_thumb_margin"
+ android:right="@dimen/switch_thumb_margin"
+ android:bottom="@dimen/switch_thumb_margin">
+ <shape android:shape="oval">
+ <size
+ android:height="@dimen/switch_thumb_size"
+ android:width="@dimen/switch_thumb_size"/>
+ <solid android:color="@color/state_on_color"/>
+ </shape>
+ </item>
</layer-list>
diff --git a/packages/SettingsLib/MainSwitchPreference/res/drawable/thumb_selector.xml b/packages/SettingsLib/MainSwitchPreference/res/drawable/thumb_selector.xml
index 8cc9bb3d5198..a541eaab6d51 100644
--- a/packages/SettingsLib/MainSwitchPreference/res/drawable/thumb_selector.xml
+++ b/packages/SettingsLib/MainSwitchPreference/res/drawable/thumb_selector.xml
@@ -16,6 +16,7 @@
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:drawable="@drawable/thumb_on" android:state_checked="true" />
- <item android:drawable="@drawable/thumb_off" android:state_checked="false" />
+ <item android:drawable="@drawable/thumb_on" android:state_checked="true"/>
+ <item android:drawable="@drawable/thumb_off" android:state_checked="false"/>
+ <item android:drawable="@drawable/thumb_disabled" android:state_enabled="false"/>
</selector>
diff --git a/packages/SettingsLib/MainSwitchPreference/res/drawable/track_on_indicator.xml b/packages/SettingsLib/MainSwitchPreference/res/drawable/track_disabled_background.xml
index 2281d045e101..b6c7313a89a2 100644
--- a/packages/SettingsLib/MainSwitchPreference/res/drawable/track_on_indicator.xml
+++ b/packages/SettingsLib/MainSwitchPreference/res/drawable/track_disabled_background.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
- Copyright (C) 2020 The Android Open Source Project
+ Copyright (C) 2021 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.
@@ -15,17 +15,12 @@
limitations under the License.
-->
-<vector
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:width="13.19dp"
- android:height="10.06dp"
- android:viewportWidth="13.19"
- android:viewportHeight="10.06">
-
- <group>
- <path
- android:pathData="M4.75012 8.12738L1.62262 4.99988L0.557617 6.05738L4.75012 10.2499L13.7501 1.24988L12.6926 0.192383L4.75012 8.12738Z"
- android:fillColor="@android:color/white" />
- </group>
-
-</vector>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle"
+ android:width="@dimen/switch_track_width"
+ android:height="@dimen/switch_track_height">
+ <solid
+ android:color="@color/track_off_color"
+ android:alpha="?android:attr/disabledAlpha"/>
+ <corners android:radius="@dimen/switch_track_radius"/>
+</shape>
diff --git a/packages/SettingsLib/MainSwitchPreference/res/drawable/track_off_background.xml b/packages/SettingsLib/MainSwitchPreference/res/drawable/track_off_background.xml
index c838654dd209..f2c11b6db504 100644
--- a/packages/SettingsLib/MainSwitchPreference/res/drawable/track_off_background.xml
+++ b/packages/SettingsLib/MainSwitchPreference/res/drawable/track_off_background.xml
@@ -15,20 +15,10 @@
limitations under the License.
-->
-<vector
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:width="52dp"
- android:height="28dp"
- android:viewportWidth="52"
- android:viewportHeight="28">
-
- <group>
- <clip-path
- android:pathData="M14 0H38C45.732 0 52 6.26801 52 14C52 21.732 45.732 28 38 28H14C6.26801 28 0 21.732 0 14C0 6.26801 6.26801 0 14 0Z" />
-
- <path
- android:pathData="M0 0V28H52V0"
- android:fillColor="@color/track_off" />
- </group>
-
-</vector>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle"
+ android:width="@dimen/switch_track_width"
+ android:height="@dimen/switch_track_height">
+ <solid android:color="@color/track_off_color"/>
+ <corners android:radius="@dimen/switch_track_radius"/>
+</shape>
diff --git a/packages/SettingsLib/MainSwitchPreference/res/drawable/track_on_background.xml b/packages/SettingsLib/MainSwitchPreference/res/drawable/track_on_background.xml
index bb1a7ef9c733..924646291c5f 100644
--- a/packages/SettingsLib/MainSwitchPreference/res/drawable/track_on_background.xml
+++ b/packages/SettingsLib/MainSwitchPreference/res/drawable/track_on_background.xml
@@ -15,22 +15,10 @@
limitations under the License.
-->
-<vector
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:width="52dp"
- android:height="28dp"
- android:viewportWidth="52"
- android:viewportHeight="28"
- android:tint="@*android:color/switch_track_material">
-
- <group>
- <clip-path
- android:pathData="M14 0H38C45.732 0 52 6.26801 52 14C52 21.732 45.732 28 38 28H14C6.26801 28 0 21.732 0 14C0 6.26801 6.26801 0 14 0Z" />
-
- <path
- android:pathData="M0 0V28H52V0"
- android:fillColor="@*android:color/white_disabled_material" />
-
- </group>
-
-</vector>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle"
+ android:width="@dimen/switch_track_width"
+ android:height="@dimen/switch_track_height">
+ <solid android:color="@color/track_on_color"/>
+ <corners android:radius="@dimen/switch_track_radius"/>
+</shape>
diff --git a/packages/SettingsLib/MainSwitchPreference/res/drawable/track_selector.xml b/packages/SettingsLib/MainSwitchPreference/res/drawable/track_selector.xml
index 5c699be4939a..50a03b9b64a0 100644
--- a/packages/SettingsLib/MainSwitchPreference/res/drawable/track_selector.xml
+++ b/packages/SettingsLib/MainSwitchPreference/res/drawable/track_selector.xml
@@ -16,6 +16,7 @@
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:drawable="@drawable/track_on" android:state_checked="true" />
- <item android:drawable="@drawable/track_off" android:state_checked="false" />
+ <item android:drawable="@drawable/track_on_background" android:state_checked="true"/>
+ <item android:drawable="@drawable/track_off_background" android:state_checked="false"/>
+ <item android:drawable="@drawable/track_disabled_background" android:state_enabled="false"/>
</selector>
diff --git a/packages/SettingsLib/MainSwitchPreference/res/layout-v31/main_switch_bar.xml b/packages/SettingsLib/MainSwitchPreference/res/layout-v31/main_switch_bar.xml
index 3ce9421f8e97..9ccf63aec018 100644
--- a/packages/SettingsLib/MainSwitchPreference/res/layout-v31/main_switch_bar.xml
+++ b/packages/SettingsLib/MainSwitchPreference/res/layout-v31/main_switch_bar.xml
@@ -19,6 +19,10 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
+ android:paddingStart="?android:attr/listPreferredItemPaddingStart"
+ android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
+ android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
+ android:paddingRight="?android:attr/listPreferredItemPaddingRight"
android:background="?android:attr/colorBackground"
android:orientation="vertical">
@@ -27,7 +31,6 @@
android:minHeight="@dimen/min_switch_bar_height"
android:layout_height="wrap_content"
android:layout_width="match_parent"
- android:background="?android:attr/selectableItemBackground"
android:paddingLeft="@dimen/switchbar_margin_start"
android:paddingRight="@dimen/switchbar_margin_end">
@@ -41,7 +44,6 @@
android:maxLines="2"
android:ellipsize="end"
android:textAppearance="?android:attr/textAppearanceListItem"
- android:textAlignment="viewStart"
style="@style/MainSwitchText" />
<ImageView
@@ -58,18 +60,13 @@
<Switch
android:id="@android:id/switch_widget"
android:layout_width="wrap_content"
- android:layout_height="wrap_content"
+ android:layout_height="48dp"
android:layout_gravity="center_vertical"
android:track="@drawable/track_selector"
android:thumb="@drawable/thumb_selector"
android:theme="@style/Settings.MainSwitch"/>
</LinearLayout>
- <View
- android:id="@+id/below_divider"
- android:layout_width="match_parent"
- android:layout_height="1dp"
- android:background="?android:attr/listDivider" />
</LinearLayout>
diff --git a/packages/SettingsLib/MainSwitchPreference/res/layout/main_switch_bar.xml b/packages/SettingsLib/MainSwitchPreference/res/layout/main_switch_bar.xml
index 5dc320924da2..ac827330333f 100644
--- a/packages/SettingsLib/MainSwitchPreference/res/layout/main_switch_bar.xml
+++ b/packages/SettingsLib/MainSwitchPreference/res/layout/main_switch_bar.xml
@@ -54,4 +54,3 @@
android:theme="@style/Widget.SwitchBar.Switch"/>
</LinearLayout>
-
diff --git a/packages/SettingsLib/MainSwitchPreference/res/values-night/colors.xml b/packages/SettingsLib/MainSwitchPreference/res/values-night/colors.xml
index e54569e9a814..7457285d397c 100644
--- a/packages/SettingsLib/MainSwitchPreference/res/values-night/colors.xml
+++ b/packages/SettingsLib/MainSwitchPreference/res/values-night/colors.xml
@@ -15,11 +15,10 @@
limitations under the License.
-->
-<resources>
-
- <color name="thumb_off">#BFFFFFFF</color>
- <color name="track_off">@*android:color/material_grey_600</color>
-
+<resources xmlns:androidprv="http://schemas.android.com/apk/prv/res/android">
<color name="switchbar_switch_track_tint">#82000000</color>
<color name="switchbar_switch_thumb_tint">@android:color/black</color>
+
+ <!-- Material next track on color-->
+ <color name="track_on_color">?androidprv:attr/colorSurfaceHighlight</color>
</resources>
diff --git a/packages/SettingsLib/MainSwitchPreference/res/values/colors.xml b/packages/SettingsLib/MainSwitchPreference/res/values/colors.xml
index b5a73b17ed34..ea7bfd4163d2 100644
--- a/packages/SettingsLib/MainSwitchPreference/res/values/colors.xml
+++ b/packages/SettingsLib/MainSwitchPreference/res/values/colors.xml
@@ -15,12 +15,20 @@
limitations under the License.
-->
-<resources>
-
- <color name="thumb_off">#BFFFFFFF</color>
- <color name="track_off">@*android:color/material_grey_600</color>
-
+<resources xmlns:androidprv="http://schemas.android.com/apk/prv/res/android">
<color name="switchbar_background_color">@*android:color/material_grey_600</color>
<color name="switchbar_switch_track_tint">#BFFFFFFF</color>
<color name="switchbar_switch_thumb_tint">@android:color/white</color>
+
+ <!-- Material next state on color-->
+ <color name="state_on_color">?androidprv:attr/colorAccentPrimary</color>
+
+ <!-- Material next state off color-->
+ <color name="state_off_color">?androidprv:attr/colorAccentSecondary</color>
+
+ <!-- Material next track on color-->
+ <color name="track_on_color">?androidprv:attr/colorAccentPrimaryVariant</color>
+
+ <!-- Material next track off color-->
+ <color name="track_off_color">?androidprv:attr/colorAccentSecondaryVariant</color>
</resources>
diff --git a/packages/SettingsLib/MainSwitchPreference/res/values/dimens.xml b/packages/SettingsLib/MainSwitchPreference/res/values/dimens.xml
index c471bcd645a6..67886bcbcbd9 100644
--- a/packages/SettingsLib/MainSwitchPreference/res/values/dimens.xml
+++ b/packages/SettingsLib/MainSwitchPreference/res/values/dimens.xml
@@ -18,7 +18,7 @@
<resources>
<!-- Size of layout margin left -->
- <dimen name="switchbar_margin_start">22dp</dimen>
+ <dimen name="switchbar_margin_start">24dp</dimen>
<!-- Size of layout margin right -->
<dimen name="switchbar_margin_end">16dp</dimen>
@@ -35,6 +35,24 @@
<!-- Restricted icon in switch bar -->
<dimen name="restricted_icon_margin_end">16dp</dimen>
+ <!-- Radius of switch bar -->
+ <dimen name="switch_bar_radius">28dp</dimen>
+
+ <!-- Margin of switch thumb -->
+ <dimen name="switch_thumb_margin">4dp</dimen>
+
+ <!-- Size of switch thumb -->
+ <dimen name="switch_thumb_size">20dp</dimen>
+
+ <!-- Width of switch track -->
+ <dimen name="switch_track_width">52dp</dimen>
+
+ <!-- Height of switch track -->
+ <dimen name="switch_track_height">28dp</dimen>
+
+ <!-- Radius of switch track -->
+ <dimen name="switch_track_radius">35dp</dimen>
+
<!-- SwitchBar sub settings margin start / end -->
<dimen name="switchbar_subsettings_margin_start">72dp</dimen>
<dimen name="switchbar_subsettings_margin_end">16dp</dimen>
diff --git a/packages/SettingsLib/MainSwitchPreference/res/values/styles.xml b/packages/SettingsLib/MainSwitchPreference/res/values/styles.xml
index e05809799865..5867695c5dc7 100644
--- a/packages/SettingsLib/MainSwitchPreference/res/values/styles.xml
+++ b/packages/SettingsLib/MainSwitchPreference/res/values/styles.xml
@@ -19,6 +19,8 @@
<style name="MainSwitchText">
<item name="android:textSize">20sp</item>
+ <item name="android:fontFamily">@*android:string/config_headlineFontFamily</item>
+ <item name="android:textColor">@android:color/black</item>
</style>
<style name="Settings.MainSwitch" parent="@android:style/Widget.Material.CompoundButton.Switch">
diff --git a/packages/SettingsLib/MainSwitchPreference/src/com/android/settingslib/widget/MainSwitchBar.java b/packages/SettingsLib/MainSwitchPreference/src/com/android/settingslib/widget/MainSwitchBar.java
index 2be3f0d815aa..7913e0ab7697 100644
--- a/packages/SettingsLib/MainSwitchPreference/src/com/android/settingslib/widget/MainSwitchBar.java
+++ b/packages/SettingsLib/MainSwitchPreference/src/com/android/settingslib/widget/MainSwitchBar.java
@@ -18,6 +18,7 @@ package com.android.settingslib.widget;
import android.content.Context;
import android.content.res.TypedArray;
+import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
@@ -50,6 +51,10 @@ public class MainSwitchBar extends LinearLayout implements CompoundButton.OnChec
protected TextView mTextView;
protected Switch mSwitch;
+ private Drawable mBackgroundOn;
+ private Drawable mBackgroundOff;
+ private Drawable mBackgroundDisabled;
+ private View mFrameView;
public MainSwitchBar(Context context) {
this(context, null);
@@ -81,8 +86,12 @@ public class MainSwitchBar extends LinearLayout implements CompoundButton.OnChec
setFocusable(true);
setClickable(true);
+ mFrameView = findViewById(R.id.frame);
mTextView = (TextView) findViewById(R.id.switch_text);
mSwitch = (Switch) findViewById(android.R.id.switch_widget);
+ mBackgroundOn = getContext().getDrawable(R.drawable.switch_bar_bg_on);
+ mBackgroundOff = getContext().getDrawable(R.drawable.switch_bar_bg_off);
+ mBackgroundDisabled = getContext().getDrawable(R.drawable.switch_bar_bg_disabled);
addOnSwitchChangeListener((switchView, isChecked) -> setChecked(isChecked));
@@ -194,21 +203,31 @@ public class MainSwitchBar extends LinearLayout implements CompoundButton.OnChec
super.setEnabled(enabled);
mTextView.setEnabled(enabled);
mSwitch.setEnabled(enabled);
+
+ if (BuildCompat.isAtLeastS()) {
+ if (enabled) {
+ mFrameView.setBackground(isChecked() ? mBackgroundOn : mBackgroundOff);
+ } else {
+ mFrameView.setBackground(mBackgroundDisabled);
+ }
+ }
}
private void propagateChecked(boolean isChecked) {
+ setBackground(isChecked);
+
final int count = mSwitchChangeListeners.size();
for (int n = 0; n < count; n++) {
mSwitchChangeListeners.get(n).onSwitchChanged(mSwitch, isChecked);
}
}
- private void setBackground(boolean checked) {
- if (BuildCompat.isAtLeastS()) {
- return;
+ private void setBackground(boolean isChecked) {
+ if (!BuildCompat.isAtLeastS()) {
+ setBackgroundColor(isChecked ? mBackgroundActivatedColor : mBackgroundColor);
+ } else {
+ mFrameView.setBackground(isChecked ? mBackgroundOn : mBackgroundOff);
}
-
- setBackgroundColor(checked ? mBackgroundActivatedColor : mBackgroundColor);
}
static class SavedState extends BaseSavedState {
@@ -273,6 +292,7 @@ public class MainSwitchBar extends LinearLayout implements CompoundButton.OnChec
mSwitch.setChecked(ss.mChecked);
setChecked(ss.mChecked);
+ setBackground(ss.mChecked);
setVisibility(ss.mVisible ? View.VISIBLE : View.GONE);
mSwitch.setOnCheckedChangeListener(ss.mVisible ? this : null);
diff --git a/packages/SettingsLib/MainSwitchPreference/src/com/android/settingslib/widget/MainSwitchPreference.java b/packages/SettingsLib/MainSwitchPreference/src/com/android/settingslib/widget/MainSwitchPreference.java
index 1f7f8d44d610..cafc7036f146 100644
--- a/packages/SettingsLib/MainSwitchPreference/src/com/android/settingslib/widget/MainSwitchPreference.java
+++ b/packages/SettingsLib/MainSwitchPreference/src/com/android/settingslib/widget/MainSwitchPreference.java
@@ -63,7 +63,7 @@ public class MainSwitchPreference extends TwoStatePreference {
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
- holder.setDividerAllowedAbove(true);
+ holder.setDividerAllowedAbove(false);
holder.setDividerAllowedBelow(false);
mMainSwitchBar = (MainSwitchBar) holder.findViewById(R.id.main_switch_bar);
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/MainSwitchPreferenceTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/MainSwitchPreferenceTest.java
index 2e77acaa0807..12f329daaaff 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/MainSwitchPreferenceTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/MainSwitchPreferenceTest.java
@@ -59,15 +59,6 @@ public class MainSwitchPreferenceTest {
}
@Test
- public void shouldAllowDividerBelow() {
- mPreference.onBindViewHolder(mHolder);
-
- View divider = mRootView.findViewById(R.id.below_divider);
-
- assertThat(divider.getVisibility()).isEqualTo(View.VISIBLE);
- }
-
- @Test
public void updateStatus_shouldMatchTheStatus() {
mPreference.onBindViewHolder(mHolder);
mPreference.updateStatus(true);