Merge "Update MainSwitchBar to Material Next style." into sc-dev
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?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");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -15,12 +15,12 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
<item android:drawable="@drawable/track_on_background" />
|
android:color="?android:attr/colorControlHighlight">
|
||||||
<item
|
<item>
|
||||||
android:width="13.19dp"
|
<shape android:shape="rectangle">
|
||||||
android:height="10.06dp"
|
<solid android:color="@color/state_off_color"/>
|
||||||
android:gravity="center"
|
<corners android:radius="@dimen/switch_bar_radius"/>
|
||||||
android:right="21dp"
|
</shape>
|
||||||
android:drawable="@drawable/track_on_indicator" />
|
</item>
|
||||||
</layer-list>
|
</ripple>
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?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");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -15,20 +15,12 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<vector
|
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
android:color="?android:attr/colorControlHighlight">
|
||||||
android:width="13.33dp"
|
<item>
|
||||||
android:height="1.67dp"
|
<shape android:shape="rectangle">
|
||||||
android:viewportWidth="13.33"
|
<solid android:color="@color/state_off_color"/>
|
||||||
android:viewportHeight="1.67">
|
<corners android:radius="@dimen/switch_bar_radius"/>
|
||||||
|
</shape>
|
||||||
<group>
|
</item>
|
||||||
<clip-path
|
</ripple>
|
||||||
android:pathData="M0 0H13.3333V1.66667H0V0Z" />
|
|
||||||
|
|
||||||
<path
|
|
||||||
android:pathData="M0 0V1.66667H13.3333V0"
|
|
||||||
android:fillColor="@android:color/white" />
|
|
||||||
</group>
|
|
||||||
|
|
||||||
</vector>
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?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");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -15,12 +15,12 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
<item android:drawable="@drawable/track_off_background" />
|
android:color="?android:attr/colorControlHighlight">
|
||||||
<item
|
<item>
|
||||||
android:width="13.33dp"
|
<shape android:shape="rectangle">
|
||||||
android:height="1.67dp"
|
<solid android:color="@color/state_on_color"/>
|
||||||
android:left="21dp"
|
<corners android:radius="@dimen/switch_bar_radius"/>
|
||||||
android:gravity="center"
|
</shape>
|
||||||
android:drawable="@drawable/track_off_indicator" />
|
</item>
|
||||||
</layer-list>
|
</ripple>
|
||||||
@@ -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>
|
||||||
@@ -17,15 +17,15 @@
|
|||||||
|
|
||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<item
|
<item
|
||||||
android:top="4dp"
|
android:top="@dimen/switch_thumb_margin"
|
||||||
android:left="4dp"
|
android:left="@dimen/switch_thumb_margin"
|
||||||
android:right="4dp"
|
android:right="@dimen/switch_thumb_margin"
|
||||||
android:bottom="4dp">
|
android:bottom="@dimen/switch_thumb_margin">
|
||||||
|
|
||||||
<shape android:shape="oval">
|
<shape android:shape="oval">
|
||||||
<size android:height="20dp" android:width="20dp" />
|
<size
|
||||||
<solid android:color="@color/thumb_off" />
|
android:height="@dimen/switch_thumb_size"
|
||||||
|
android:width="@dimen/switch_thumb_size"/>
|
||||||
|
<solid android:color="@color/state_off_color"/>
|
||||||
</shape>
|
</shape>
|
||||||
|
|
||||||
</item>
|
</item>
|
||||||
</layer-list>
|
</layer-list>
|
||||||
|
|||||||
@@ -17,15 +17,15 @@
|
|||||||
|
|
||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<item
|
<item
|
||||||
android:top="4dp"
|
android:top="@dimen/switch_thumb_margin"
|
||||||
android:left="4dp"
|
android:left="@dimen/switch_thumb_margin"
|
||||||
android:right="4dp"
|
android:right="@dimen/switch_thumb_margin"
|
||||||
android:bottom="4dp">
|
android:bottom="@dimen/switch_thumb_margin">
|
||||||
|
|
||||||
<shape android:shape="oval">
|
<shape android:shape="oval">
|
||||||
<size android:height="20dp" android:width="20dp" />
|
<size
|
||||||
<solid android:color="?android:attr/colorAccent" />
|
android:height="@dimen/switch_thumb_size"
|
||||||
|
android:width="@dimen/switch_thumb_size"/>
|
||||||
|
<solid android:color="@color/state_on_color"/>
|
||||||
</shape>
|
</shape>
|
||||||
|
|
||||||
</item>
|
</item>
|
||||||
</layer-list>
|
</layer-list>
|
||||||
|
|||||||
@@ -18,4 +18,5 @@
|
|||||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
<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_on" android:state_checked="true"/>
|
||||||
<item android:drawable="@drawable/thumb_off" android:state_checked="false"/>
|
<item android:drawable="@drawable/thumb_off" android:state_checked="false"/>
|
||||||
|
<item android:drawable="@drawable/thumb_disabled" android:state_enabled="false"/>
|
||||||
</selector>
|
</selector>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?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");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -15,17 +15,12 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<vector
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
android:shape="rectangle"
|
||||||
android:width="13.19dp"
|
android:width="@dimen/switch_track_width"
|
||||||
android:height="10.06dp"
|
android:height="@dimen/switch_track_height">
|
||||||
android:viewportWidth="13.19"
|
<solid
|
||||||
android:viewportHeight="10.06">
|
android:color="@color/track_off_color"
|
||||||
|
android:alpha="?android:attr/disabledAlpha"/>
|
||||||
<group>
|
<corners android:radius="@dimen/switch_track_radius"/>
|
||||||
<path
|
</shape>
|
||||||
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>
|
|
||||||
@@ -15,20 +15,10 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<vector
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
android:shape="rectangle"
|
||||||
android:width="52dp"
|
android:width="@dimen/switch_track_width"
|
||||||
android:height="28dp"
|
android:height="@dimen/switch_track_height">
|
||||||
android:viewportWidth="52"
|
<solid android:color="@color/track_off_color"/>
|
||||||
android:viewportHeight="28">
|
<corners android:radius="@dimen/switch_track_radius"/>
|
||||||
|
</shape>
|
||||||
<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>
|
|
||||||
|
|||||||
@@ -15,22 +15,10 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<vector
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
android:shape="rectangle"
|
||||||
android:width="52dp"
|
android:width="@dimen/switch_track_width"
|
||||||
android:height="28dp"
|
android:height="@dimen/switch_track_height">
|
||||||
android:viewportWidth="52"
|
<solid android:color="@color/track_on_color"/>
|
||||||
android:viewportHeight="28"
|
<corners android:radius="@dimen/switch_track_radius"/>
|
||||||
android:tint="@*android:color/switch_track_material">
|
</shape>
|
||||||
|
|
||||||
<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>
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
<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_on_background" android:state_checked="true"/>
|
||||||
<item android:drawable="@drawable/track_off" android:state_checked="false" />
|
<item android:drawable="@drawable/track_off_background" android:state_checked="false"/>
|
||||||
|
<item android:drawable="@drawable/track_disabled_background" android:state_enabled="false"/>
|
||||||
</selector>
|
</selector>
|
||||||
|
|||||||
@@ -19,6 +19,10 @@
|
|||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="match_parent"
|
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:background="?android:attr/colorBackground"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
@@ -27,7 +31,6 @@
|
|||||||
android:minHeight="@dimen/min_switch_bar_height"
|
android:minHeight="@dimen/min_switch_bar_height"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:background="?android:attr/selectableItemBackground"
|
|
||||||
android:paddingLeft="@dimen/switchbar_margin_start"
|
android:paddingLeft="@dimen/switchbar_margin_start"
|
||||||
android:paddingRight="@dimen/switchbar_margin_end">
|
android:paddingRight="@dimen/switchbar_margin_end">
|
||||||
|
|
||||||
@@ -41,7 +44,6 @@
|
|||||||
android:maxLines="2"
|
android:maxLines="2"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:textAppearance="?android:attr/textAppearanceListItem"
|
android:textAppearance="?android:attr/textAppearanceListItem"
|
||||||
android:textAlignment="viewStart"
|
|
||||||
style="@style/MainSwitchText" />
|
style="@style/MainSwitchText" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
@@ -58,18 +60,13 @@
|
|||||||
<Switch
|
<Switch
|
||||||
android:id="@android:id/switch_widget"
|
android:id="@android:id/switch_widget"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="48dp"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:track="@drawable/track_selector"
|
android:track="@drawable/track_selector"
|
||||||
android:thumb="@drawable/thumb_selector"
|
android:thumb="@drawable/thumb_selector"
|
||||||
android:theme="@style/Settings.MainSwitch"/>
|
android:theme="@style/Settings.MainSwitch"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<View
|
|
||||||
android:id="@+id/below_divider"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="1dp"
|
|
||||||
android:background="?android:attr/listDivider" />
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -54,4 +54,3 @@
|
|||||||
android:theme="@style/Widget.SwitchBar.Switch"/>
|
android:theme="@style/Widget.SwitchBar.Switch"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,11 +15,10 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<resources>
|
<resources xmlns:androidprv="http://schemas.android.com/apk/prv/res/android">
|
||||||
|
|
||||||
<color name="thumb_off">#BFFFFFFF</color>
|
|
||||||
<color name="track_off">@*android:color/material_grey_600</color>
|
|
||||||
|
|
||||||
<color name="switchbar_switch_track_tint">#82000000</color>
|
<color name="switchbar_switch_track_tint">#82000000</color>
|
||||||
<color name="switchbar_switch_thumb_tint">@android:color/black</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>
|
</resources>
|
||||||
|
|||||||
@@ -15,12 +15,20 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<resources>
|
<resources xmlns:androidprv="http://schemas.android.com/apk/prv/res/android">
|
||||||
|
|
||||||
<color name="thumb_off">#BFFFFFFF</color>
|
|
||||||
<color name="track_off">@*android:color/material_grey_600</color>
|
|
||||||
|
|
||||||
<color name="switchbar_background_color">@*android:color/material_grey_600</color>
|
<color name="switchbar_background_color">@*android:color/material_grey_600</color>
|
||||||
<color name="switchbar_switch_track_tint">#BFFFFFFF</color>
|
<color name="switchbar_switch_track_tint">#BFFFFFFF</color>
|
||||||
<color name="switchbar_switch_thumb_tint">@android:color/white</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>
|
</resources>
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<!-- Size of layout margin left -->
|
<!-- Size of layout margin left -->
|
||||||
<dimen name="switchbar_margin_start">22dp</dimen>
|
<dimen name="switchbar_margin_start">24dp</dimen>
|
||||||
|
|
||||||
<!-- Size of layout margin right -->
|
<!-- Size of layout margin right -->
|
||||||
<dimen name="switchbar_margin_end">16dp</dimen>
|
<dimen name="switchbar_margin_end">16dp</dimen>
|
||||||
@@ -35,6 +35,24 @@
|
|||||||
<!-- Restricted icon in switch bar -->
|
<!-- Restricted icon in switch bar -->
|
||||||
<dimen name="restricted_icon_margin_end">16dp</dimen>
|
<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 -->
|
<!-- SwitchBar sub settings margin start / end -->
|
||||||
<dimen name="switchbar_subsettings_margin_start">72dp</dimen>
|
<dimen name="switchbar_subsettings_margin_start">72dp</dimen>
|
||||||
<dimen name="switchbar_subsettings_margin_end">16dp</dimen>
|
<dimen name="switchbar_subsettings_margin_end">16dp</dimen>
|
||||||
|
|||||||
@@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
<style name="MainSwitchText">
|
<style name="MainSwitchText">
|
||||||
<item name="android:textSize">20sp</item>
|
<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>
|
||||||
|
|
||||||
<style name="Settings.MainSwitch" parent="@android:style/Widget.Material.CompoundButton.Switch">
|
<style name="Settings.MainSwitch" parent="@android:style/Widget.Material.CompoundButton.Switch">
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package com.android.settingslib.widget;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
@@ -50,6 +51,10 @@ public class MainSwitchBar extends LinearLayout implements CompoundButton.OnChec
|
|||||||
|
|
||||||
protected TextView mTextView;
|
protected TextView mTextView;
|
||||||
protected Switch mSwitch;
|
protected Switch mSwitch;
|
||||||
|
private Drawable mBackgroundOn;
|
||||||
|
private Drawable mBackgroundOff;
|
||||||
|
private Drawable mBackgroundDisabled;
|
||||||
|
private View mFrameView;
|
||||||
|
|
||||||
public MainSwitchBar(Context context) {
|
public MainSwitchBar(Context context) {
|
||||||
this(context, null);
|
this(context, null);
|
||||||
@@ -81,8 +86,12 @@ public class MainSwitchBar extends LinearLayout implements CompoundButton.OnChec
|
|||||||
setFocusable(true);
|
setFocusable(true);
|
||||||
setClickable(true);
|
setClickable(true);
|
||||||
|
|
||||||
|
mFrameView = findViewById(R.id.frame);
|
||||||
mTextView = (TextView) findViewById(R.id.switch_text);
|
mTextView = (TextView) findViewById(R.id.switch_text);
|
||||||
mSwitch = (Switch) findViewById(android.R.id.switch_widget);
|
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));
|
addOnSwitchChangeListener((switchView, isChecked) -> setChecked(isChecked));
|
||||||
|
|
||||||
@@ -194,21 +203,31 @@ public class MainSwitchBar extends LinearLayout implements CompoundButton.OnChec
|
|||||||
super.setEnabled(enabled);
|
super.setEnabled(enabled);
|
||||||
mTextView.setEnabled(enabled);
|
mTextView.setEnabled(enabled);
|
||||||
mSwitch.setEnabled(enabled);
|
mSwitch.setEnabled(enabled);
|
||||||
|
|
||||||
|
if (BuildCompat.isAtLeastS()) {
|
||||||
|
if (enabled) {
|
||||||
|
mFrameView.setBackground(isChecked() ? mBackgroundOn : mBackgroundOff);
|
||||||
|
} else {
|
||||||
|
mFrameView.setBackground(mBackgroundDisabled);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void propagateChecked(boolean isChecked) {
|
private void propagateChecked(boolean isChecked) {
|
||||||
|
setBackground(isChecked);
|
||||||
|
|
||||||
final int count = mSwitchChangeListeners.size();
|
final int count = mSwitchChangeListeners.size();
|
||||||
for (int n = 0; n < count; n++) {
|
for (int n = 0; n < count; n++) {
|
||||||
mSwitchChangeListeners.get(n).onSwitchChanged(mSwitch, isChecked);
|
mSwitchChangeListeners.get(n).onSwitchChanged(mSwitch, isChecked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setBackground(boolean checked) {
|
private void setBackground(boolean isChecked) {
|
||||||
if (BuildCompat.isAtLeastS()) {
|
if (!BuildCompat.isAtLeastS()) {
|
||||||
return;
|
setBackgroundColor(isChecked ? mBackgroundActivatedColor : mBackgroundColor);
|
||||||
|
} else {
|
||||||
|
mFrameView.setBackground(isChecked ? mBackgroundOn : mBackgroundOff);
|
||||||
}
|
}
|
||||||
|
|
||||||
setBackgroundColor(checked ? mBackgroundActivatedColor : mBackgroundColor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class SavedState extends BaseSavedState {
|
static class SavedState extends BaseSavedState {
|
||||||
@@ -273,6 +292,7 @@ public class MainSwitchBar extends LinearLayout implements CompoundButton.OnChec
|
|||||||
|
|
||||||
mSwitch.setChecked(ss.mChecked);
|
mSwitch.setChecked(ss.mChecked);
|
||||||
setChecked(ss.mChecked);
|
setChecked(ss.mChecked);
|
||||||
|
setBackground(ss.mChecked);
|
||||||
setVisibility(ss.mVisible ? View.VISIBLE : View.GONE);
|
setVisibility(ss.mVisible ? View.VISIBLE : View.GONE);
|
||||||
mSwitch.setOnCheckedChangeListener(ss.mVisible ? this : null);
|
mSwitch.setOnCheckedChangeListener(ss.mVisible ? this : null);
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public class MainSwitchPreference extends TwoStatePreference {
|
|||||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||||
super.onBindViewHolder(holder);
|
super.onBindViewHolder(holder);
|
||||||
|
|
||||||
holder.setDividerAllowedAbove(true);
|
holder.setDividerAllowedAbove(false);
|
||||||
holder.setDividerAllowedBelow(false);
|
holder.setDividerAllowedBelow(false);
|
||||||
|
|
||||||
mMainSwitchBar = (MainSwitchBar) holder.findViewById(R.id.main_switch_bar);
|
mMainSwitchBar = (MainSwitchBar) holder.findViewById(R.id.main_switch_bar);
|
||||||
|
|||||||
@@ -58,15 +58,6 @@ public class MainSwitchPreferenceTest {
|
|||||||
.isEqualTo(defaultOnText);
|
.isEqualTo(defaultOnText);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldAllowDividerBelow() {
|
|
||||||
mPreference.onBindViewHolder(mHolder);
|
|
||||||
|
|
||||||
View divider = mRootView.findViewById(R.id.below_divider);
|
|
||||||
|
|
||||||
assertThat(divider.getVisibility()).isEqualTo(View.VISIBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateStatus_shouldMatchTheStatus() {
|
public void updateStatus_shouldMatchTheStatus() {
|
||||||
mPreference.onBindViewHolder(mHolder);
|
mPreference.onBindViewHolder(mHolder);
|
||||||
|
|||||||
Reference in New Issue
Block a user