Update master switch style

- When off, background grey
- When on, background accent
- Switch toggle always white, only change the slider color during on/off

Change-Id: I0ca49439f4e20e75517d503f28cc3068930591e8
Bug: 69462439
Test: robotests
This commit is contained in:
Fan Zhang
2018-01-10 12:22:36 -08:00
parent 256ebf4245
commit 46b5474be4
16 changed files with 210 additions and 182 deletions

View File

@@ -1,18 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<issues format="4">
<issue
id="LintError"
severity="Error"
message="No `.class` files were found in project &quot;.&quot;, so none of the classfile based checks could be run. Does the project need to be built first?"
category="Lint"
priority="10"
summary="Lint Failure"
explanation="This issue type represents a problem running lint itself. Examples include failure to find bytecode for source files (which means certain detectors could not be run), parsing errors in lint configuration files, etc.&#xA;These errors are not errors in your own code, but they are shown to make it clear that some checks were not completed.">
<location
file="."/>
</issue>
<issue
id="HardCodedColor"
severity="Error"
@@ -749,6 +737,22 @@
column="5"/>
</issue>
<issue
id="HardCodedColor"
severity="Error"
message="Avoid using hardcoded color"
category="Correctness"
priority="4"
summary="Using hardcoded color"
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
errorLine1=" &lt;color name=&quot;switch_bar_background&quot;>#ff80868B&lt;/color>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/values/colors.xml"
line="84"
column="5"/>
</issue>
<issue
id="HardCodedColor"
severity="Error"
@@ -761,7 +765,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/values/colors.xml"
line="85"
line="87"
column="5"/>
</issue>
@@ -777,7 +781,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/values/colors.xml"
line="86"
line="88"
column="5"/>
</issue>
@@ -793,7 +797,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/values/colors.xml"
line="87"
line="89"
column="5"/>
</issue>
@@ -809,7 +813,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/values/colors.xml"
line="88"
line="90"
column="5"/>
</issue>
@@ -825,7 +829,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/values/colors.xml"
line="89"
line="91"
column="5"/>
</issue>
@@ -841,7 +845,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/values/colors.xml"
line="90"
line="92"
column="5"/>
</issue>
@@ -857,7 +861,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/values/colors.xml"
line="91"
line="93"
column="5"/>
</issue>
@@ -873,7 +877,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/values/colors.xml"
line="92"
line="94"
column="5"/>
</issue>
@@ -889,7 +893,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/values/colors.xml"
line="93"
line="95"
column="5"/>
</issue>
@@ -905,7 +909,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/values/colors.xml"
line="94"
line="96"
column="5"/>
</issue>
@@ -921,7 +925,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/values/colors.xml"
line="95"
line="97"
column="5"/>
</issue>
@@ -937,7 +941,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/values/colors.xml"
line="98"
line="100"
column="5"/>
</issue>
@@ -953,7 +957,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/values/colors.xml"
line="100"
line="102"
column="5"/>
</issue>
@@ -969,7 +973,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/values/colors.xml"
line="103"
line="105"
column="5"/>
</issue>
@@ -985,7 +989,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/values/colors.xml"
line="105"
line="107"
column="5"/>
</issue>
@@ -1001,7 +1005,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/values/colors.xml"
line="108"
line="110"
column="5"/>
</issue>
@@ -1017,7 +1021,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/values/colors.xml"
line="111"
line="113"
column="5"/>
</issue>
@@ -1033,7 +1037,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/values/colors.xml"
line="114"
line="116"
column="5"/>
</issue>
@@ -1049,7 +1053,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/values/colors.xml"
line="117"
line="119"
column="5"/>
</issue>
@@ -1065,7 +1069,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/values/colors.xml"
line="118"
line="120"
column="5"/>
</issue>
@@ -1303,38 +1307,6 @@
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
errorLine1=" &lt;item android:color=&quot;#19263238&quot; android:offset=&quot;0.0&quot;/>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/drawable/ic_color_inversion.xml"
line="17"
column="23"/>
</issue>
<issue
id="HardCodedColor"
severity="Error"
message="Avoid using hardcoded color"
category="Correctness"
priority="4"
summary="Using hardcoded color"
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
errorLine1=" &lt;item android:color=&quot;#00212121&quot; android:offset=&quot;1.0&quot;/>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/drawable/ic_color_inversion.xml"
line="18"
column="23"/>
</issue>
<issue
id="HardCodedColor"
severity="Error"
message="Avoid using hardcoded color"
category="Correctness"
priority="4"
summary="Using hardcoded color"
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
errorLine1=" &lt;item android:color=&quot;#19FFFFFF&quot; android:offset=&quot;0.0&quot;/>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/drawable/ic_color_inversion.xml"
line="32"
@@ -1349,7 +1321,7 @@
priority="4"
summary="Using hardcoded color"
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
errorLine1=" &lt;item android:color=&quot;#00FFFFFF&quot; android:offset=&quot;1.0&quot;/>"
errorLine1=" &lt;item android:color=&quot;#00212121&quot; android:offset=&quot;1.0&quot;/>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/drawable/ic_color_inversion.xml"
@@ -1357,6 +1329,38 @@
column="23"/>
</issue>
<issue
id="HardCodedColor"
severity="Error"
message="Avoid using hardcoded color"
category="Correctness"
priority="4"
summary="Using hardcoded color"
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
errorLine1=" &lt;item android:color=&quot;#19FFFFFF&quot; android:offset=&quot;0.0&quot;/>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/drawable/ic_color_inversion.xml"
line="47"
column="23"/>
</issue>
<issue
id="HardCodedColor"
severity="Error"
message="Avoid using hardcoded color"
category="Correctness"
priority="4"
summary="Using hardcoded color"
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
errorLine1=" &lt;item android:color=&quot;#00FFFFFF&quot; android:offset=&quot;1.0&quot;/>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/drawable/ic_color_inversion.xml"
line="48"
column="23"/>
</issue>
<issue
id="HardCodedColor"
severity="Error"
@@ -1369,7 +1373,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/drawable/ic_daltonizer.xml"
line="16"
line="31"
column="27"/>
</issue>
@@ -1385,7 +1389,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/drawable/ic_daltonizer.xml"
line="17"
line="32"
column="27"/>
</issue>
@@ -1401,7 +1405,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/drawable/ic_daltonizer.xml"
line="36"
line="51"
column="23"/>
</issue>
@@ -1417,7 +1421,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/drawable/ic_daltonizer.xml"
line="37"
line="52"
column="23"/>
</issue>
@@ -2073,7 +2077,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="res/values-en-rXC/strings.xml"
line="2333"
line="2353"
column="168"/>
</issue>
@@ -2089,7 +2093,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="res/values-en-rAU/strings.xml"
line="2334"
line="2354"
column="64"/>
</issue>
@@ -2105,7 +2109,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="res/values-en-rCA/strings.xml"
line="2334"
line="2354"
column="64"/>
</issue>
@@ -2121,7 +2125,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="res/values-en-rGB/strings.xml"
line="2334"
line="2354"
column="64"/>
</issue>
@@ -2137,7 +2141,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="res/values-en-rIN/strings.xml"
line="2334"
line="2354"
column="64"/>
</issue>
@@ -2153,7 +2157,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="res/values/strings.xml"
line="5512"
line="5539"
column="36"/>
</issue>
@@ -2173,22 +2177,6 @@
column="41"/>
</issue>
<issue
id="HardCodedColor"
severity="Error"
message="Avoid using hardcoded color"
category="Correctness"
priority="4"
summary="Using hardcoded color"
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
errorLine1=" &lt;item name=&quot;android:colorAccent&quot;>#ff009688&lt;/item>"
errorLine2=" ^">
<location
file="res/values/styles.xml"
line="366"
column="42"/>
</issue>
<issue
id="HardCodedColor"
severity="Error"
@@ -2201,7 +2189,7 @@
errorLine2=" ^">
<location
file="res/values/styles.xml"
line="443"
line="442"
column="44"/>
</issue>
@@ -2217,7 +2205,7 @@
errorLine2=" ^">
<location
file="res/values/styles.xml"
line="449"
line="448"
column="44"/>
</issue>
@@ -2233,7 +2221,7 @@
errorLine2=" ^">
<location
file="res/values/styles.xml"
line="450"
line="449"
column="44"/>
</issue>
@@ -2249,7 +2237,7 @@
errorLine2=" ^">
<location
file="res/values/styles.xml"
line="473"
line="472"
column="41"/>
</issue>
@@ -2393,7 +2381,7 @@
errorLine2=" ^">
<location
file="res/values/themes.xml"
line="139"
line="154"
column="43"/>
</issue>
@@ -2409,7 +2397,7 @@
errorLine2=" ^">
<location
file="res/values/themes.xml"
line="140"
line="155"
column="42"/>
</issue>
@@ -2425,7 +2413,7 @@
errorLine2=" ^">
<location
file="res/values/themes.xml"
line="141"
line="156"
column="45"/>
</issue>
@@ -2437,30 +2425,14 @@
priority="4"
summary="Using hardcoded color"
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
errorLine1=" &lt;item name=&quot;switchBarBackgroundColor&quot;>@color/material_grey_200&lt;/item>"
errorLine1=" &lt;item name=&quot;switchBarBackgroundColor&quot;>@color/switch_bar_background&lt;/item>"
errorLine2=" ^">
<location
file="res/values/themes.xml"
line="147"
line="233"
column="47"/>
</issue>
<issue
id="HardCodedColor"
severity="Error"
message="Avoid using hardcoded color"
category="Correctness"
priority="4"
summary="Using hardcoded color"
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
errorLine1=" &lt;item name=&quot;android:colorControlActivated&quot;>@color/material_blue_500&lt;/item>"
errorLine2=" ^">
<location
file="res/values/themes.xml"
line="148"
column="52"/>
</issue>
<issue
id="HardCodedColor"
severity="Error"
@@ -2473,7 +2445,7 @@
errorLine2=" ^">
<location
file="res/values/themes.xml"
line="298"
line="316"
column="45"/>
</issue>
@@ -2489,7 +2461,7 @@
errorLine2=" ^">
<location
file="res/values/themes.xml"
line="299"
line="317"
column="49"/>
</issue>
@@ -2505,7 +2477,7 @@
errorLine2=" ^">
<location
file="res/values/themes.xml"
line="307"
line="325"
column="45"/>
</issue>
@@ -2521,7 +2493,7 @@
errorLine2=" ^">
<location
file="res/values/themes.xml"
line="308"
line="326"
column="49"/>
</issue>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2018 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.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#FFFFFF" />
</selector>

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2018 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.
-->
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#BFFFFFFF" />
</selector>

View File

@@ -31,15 +31,12 @@
<com.android.settings.widget.SwitchBar android:id="@+id/switch_bar"
android:layout_height="?android:attr/actionBarSize"
android:layout_width="match_parent"
android:background="@drawable/switchbar_background"
android:theme="?attr/switchBarTheme"
/>
android:theme="?attr/switchBarTheme" />
<FrameLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
android:layout_height="match_parent" />
</LinearLayout>
@@ -54,8 +51,7 @@
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:layout_alignParentStart="true"
android:text="@*android:string/back_button_label"
/>
android:text="@*android:string/back_button_label" />
<LinearLayout
android:orientation="horizontal"
@@ -68,15 +64,13 @@
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:text="@*android:string/skip_button_label"
android:visibility="gone"
/>
android:visibility="gone" />
<Button android:id="@+id/next_button"
android:layout_width="150dip"
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:text="@*android:string/next_button_label"
/>
android:text="@*android:string/next_button_label" />
</LinearLayout>

View File

@@ -25,7 +25,5 @@
android:layout_height="?android:attr/actionBarSize"
android:layout_width="match_parent"
android:paddingStart="0dp"
android:background="@drawable/switchbar_background"
android:theme="?attr/switchBarTheme"
/>
android:theme="?attr/switchBarTheme" />
</LinearLayout>

View File

@@ -19,7 +19,8 @@
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:id="@+id/switch_text"
<TextView
android:id="@+id/switch_text"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
@@ -28,9 +29,11 @@
android:ellipsize="end"
android:textAppearance="@style/TextAppearance.Switch"
android:textColor="?android:attr/textColorPrimary"
android:textSize="18sp"
android:textAlignment="viewStart" />
<ImageView android:id="@+id/restricted_icon"
<ImageView
android:id="@+id/restricted_icon"
android:layout_width="@dimen/restricted_icon_size"
android:layout_height="@dimen/restricted_icon_size"
android:src="@drawable/ic_info"
@@ -39,11 +42,12 @@
android:layout_marginEnd="@dimen/restricted_icon_margin_end"
android:visibility="gone" />
<com.android.settings.widget.ToggleSwitch android:id="@+id/switch_widget"
<com.android.settings.widget.ToggleSwitch
android:id="@+id/switch_widget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:theme="@style/ThemeOverlay.SwitchBar.Settings" />
android:theme="@style/Widget.SwitchBar.Switch" />
</merge>

View File

@@ -14,8 +14,8 @@
limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabs_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
@@ -25,7 +25,6 @@
android:id="@+id/switch_bar"
android:layout_height="?android:attr/actionBarSize"
android:layout_width="match_parent"
android:background="@drawable/switchbar_background"
android:theme="?attr/switchBarTheme" />
<FrameLayout

View File

@@ -57,7 +57,6 @@
<!-- SwitchBar sub settings margin start / end -->
<dimen name="switchbar_subsettings_margin_start">80dp</dimen>
<dimen name="switchbar_subsettings_margin_end">24dp</dimen>
<dimen name="search_bar_height">64dp</dimen>
<dimen name="search_bar_half_height">32dp</dimen>

View File

@@ -123,6 +123,7 @@
<attr name="switchBarMarginStart" format="dimension" />
<attr name="switchBarMarginEnd" format="dimension" />
<attr name="switchBarBackgroundColor" format="color" />
<attr name="switchBarBackgroundActivatedColor" format="color" />
<attr name="preferenceBackgroundColor" format="color" />

View File

@@ -81,6 +81,8 @@
<color name="material_blue_700">#3367D6</color>
<color name="material_grey_100">#f5f5f5</color>
<color name="material_grey_200">#ffffff</color>
<color name="switch_bar_background">#ff80868B</color>
<color name="message_text_incoming">#ffffffff</color>
<color name="message_text_outgoing">#ff323232</color>

View File

@@ -112,7 +112,7 @@
<!-- SwitchBar sub settings margin start / end -->
<dimen name="switchbar_subsettings_margin_start">72dp</dimen>
<dimen name="switchbar_subsettings_margin_end">16dp</dimen>
<dimen name="switchbar_subsettings_margin_end">24dp</dimen>
<!-- The following two margins need to match, with the caveat that
the second should be negative. The second one ensures that the icons and text

View File

@@ -155,13 +155,7 @@
<item name="android:colorAccent">@color/material_blue_700</item>
<item name="android:titleTextColor">@color/material_blue_700</item>
<item name="preferenceTheme">@style/PreferenceTheme</item>
<item name="switchBarTheme">@style/SetupWizardAccessibilitySwitchBarTheme</item>
</style>
<style name="SetupWizardAccessibilitySwitchBarTheme" parent="ThemeOverlay.SwitchBar.Settings">
<item name="switchBarBackgroundColor">@color/material_grey_200</item>
<item name="android:colorControlActivated">@color/material_blue_500</item>
<item name="android:textColorPrimary">@android:color/black</item>
<item name="switchBarTheme">@style/ThemeOverlay.SwitchBar.Settings</item>
</style>
<!-- Theme with no local references, used by AccountPreferenceBase where we have to inflate
@@ -205,7 +199,7 @@
<!-- Redefine the ActionBar style for contentInsetStart -->
<item name="android:actionBarStyle">@style/Theme.ActionBar.SubSettings</item>
<item name="switchBarTheme">@style/ThemeOverlay.SwitchBar.SubSettings</item>
<item name="switchBarTheme">@style/ThemeOverlay.SwitchBar.Settings</item>
</style>
<!-- Variant of the settings theme with no action bar. -->
@@ -233,15 +227,16 @@
</style>
<style name="ThemeOverlay.SwitchBar.Settings" parent="@android:style/ThemeOverlay.Material.ActionBar">
<item name="android:textColorPrimary">@android:color/white</item>
<item name="switchBarMarginStart">@dimen/switchbar_subsettings_margin_start</item>
<item name="switchBarMarginEnd">@dimen/switchbar_subsettings_margin_end</item>
<item name="switchBarBackgroundColor">?android:attr/colorSecondary</item>
<item name="switchBarBackgroundColor">@color/switch_bar_background</item>
<item name="switchBarBackgroundActivatedColor">?android:attr/colorAccent</item>
</style>
<style name="ThemeOverlay.SwitchBar.SubSettings" parent="@android:style/ThemeOverlay.Material.ActionBar">
<item name="switchBarMarginStart">@dimen/switchbar_subsettings_margin_start</item>
<item name="switchBarMarginEnd">@dimen/switchbar_subsettings_margin_end</item>
<item name="switchBarBackgroundColor">?android:attr/colorSecondary</item>
<style name="Widget.SwitchBar.Switch" parent="@android:style/Widget.Material.CompoundButton.Switch">
<item name="android:trackTint">@color/switchbar_switch_track_tint</item>
<item name="android:thumbTint">@color/switchbar_switch_thumb_tint</item>
</style>
<style name="Theme.CryptKeeper" parent="@android:style/Theme.Material.NoActionBar">

View File

@@ -22,6 +22,8 @@ import android.content.Context;
import android.content.res.TypedArray;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.ColorInt;
import android.support.annotation.StringRes;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.TextAppearanceSpan;
@@ -42,6 +44,7 @@ import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.RestrictedLockUtils;
import java.util.ArrayList;
import java.util.List;
public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedChangeListener,
View.OnClickListener {
@@ -56,7 +59,14 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
void onSwitchChanged(Switch switchView, boolean isChecked);
}
private MetricsFeatureProvider mMetricsFeatureProvider;
private static final int[] XML_ATTRIBUTES = {
R.attr.switchBarMarginStart,
R.attr.switchBarMarginEnd,
R.attr.switchBarBackgroundColor,
R.attr.switchBarBackgroundActivatedColor};
private final List<OnSwitchChangeListener> mSwitchChangeListeners = new ArrayList<>();
private final MetricsFeatureProvider mMetricsFeatureProvider;
private final TextAppearanceSpan mSummarySpan;
private ToggleSwitch mSwitch;
@@ -64,20 +74,20 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
private TextView mTextView;
private String mLabel;
private String mSummary;
@ColorInt
private int mBackgroundColor;
@ColorInt
private int mBackgroundActivatedColor;
@StringRes
private int mOnTextId;
@StringRes
private int mOffTextId;
private boolean mLoggingIntialized;
private boolean mDisabledByAdmin;
private EnforcedAdmin mEnforcedAdmin = null;
private String mMetricsTag;
private final ArrayList<OnSwitchChangeListener> mSwitchChangeListeners = new ArrayList<>();
private static int[] XML_ATTRIBUTES = {
R.attr.switchBarMarginStart, R.attr.switchBarMarginEnd,
R.attr.switchBarBackgroundColor};
public SwitchBar(Context context) {
this(context, null);
@@ -99,32 +109,30 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
final TypedArray a = context.obtainStyledAttributes(attrs, XML_ATTRIBUTES);
int switchBarMarginStart = (int) a.getDimension(0, 0);
int switchBarMarginEnd = (int) a.getDimension(1, 0);
int switchBarBackgroundColor = (int) a.getColor(2, 0);
mBackgroundColor = a.getColor(2, 0);
mBackgroundActivatedColor = a.getColor(3, 0);
a.recycle();
mTextView = (TextView) findViewById(R.id.switch_text);
mTextView = findViewById(R.id.switch_text);
mTextView.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
mSummarySpan = new TextAppearanceSpan(mContext, R.style.TextAppearance_Small_SwitchBar);
ViewGroup.MarginLayoutParams lp = (MarginLayoutParams) mTextView.getLayoutParams();
lp.setMarginStart(switchBarMarginStart);
mSwitch = (ToggleSwitch) findViewById(R.id.switch_widget);
mSwitch = findViewById(R.id.switch_widget);
// Prevent onSaveInstanceState() to be called as we are managing the state of the Switch
// on our own
mSwitch.setSaveEnabled(false);
mSwitch.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
lp = (MarginLayoutParams) mSwitch.getLayoutParams();
lp.setMarginEnd(switchBarMarginEnd);
setBackgroundColor(switchBarBackgroundColor);
setBackgroundColor(mBackgroundColor);
setSwitchBarText(R.string.switch_on_text, R.string.switch_off_text);
addOnSwitchChangeListener(new OnSwitchChangeListener() {
@Override
public void onSwitchChanged(Switch switchView, boolean isChecked) {
setTextViewLabel(isChecked);
}
});
addOnSwitchChangeListener(
(switchView, isChecked) -> setTextViewLabelAndBackground(isChecked));
mRestrictedIcon = findViewById(R.id.restricted_icon);
@@ -140,15 +148,16 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
mMetricsTag = tag;
}
public void setTextViewLabel(boolean isChecked) {
public void setTextViewLabelAndBackground(boolean isChecked) {
mLabel = getResources().getString(isChecked ? mOnTextId : mOffTextId);
setBackgroundColor(isChecked ? mBackgroundActivatedColor : mBackgroundColor);
updateText();
}
public void setSwitchBarText(int onText, int offText) {
mOnTextId = onText;
mOffTextId = offText;
setTextViewLabel(isChecked());
setTextViewLabelAndBackground(isChecked());
}
public void setSummary(String summary) {
@@ -169,12 +178,12 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
}
public void setChecked(boolean checked) {
setTextViewLabel(checked);
setTextViewLabelAndBackground(checked);
mSwitch.setChecked(checked);
}
public void setCheckedInternal(boolean checked) {
setTextViewLabel(checked);
setTextViewLabelAndBackground(checked);
mSwitch.setCheckedInternal(checked);
}
@@ -338,7 +347,7 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
super.onRestoreInstanceState(ss.getSuperState());
mSwitch.setCheckedInternal(ss.checked);
setTextViewLabel(ss.checked);
setTextViewLabelAndBackground(ss.checked);
setVisibility(ss.visible ? View.VISIBLE : View.GONE);
mSwitch.setOnCheckedChangeListener(ss.visible ? this : null);

View File

@@ -43,7 +43,7 @@ public class SwitchBarController extends SwitchWidgetController implements
@Override
public void updateTitle(boolean isChecked) {
mSwitchBar.setTextViewLabel(isChecked);
mSwitchBar.setTextViewLabelAndBackground(isChecked);
}
@Override

View File

@@ -24,8 +24,8 @@ public class ToggleSwitch extends Switch {
private ToggleSwitch.OnBeforeCheckedChangeListener mOnBeforeListener;
public static interface OnBeforeCheckedChangeListener {
public boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked);
public interface OnBeforeCheckedChangeListener {
boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked);
}
public ToggleSwitch(Context context) {

View File

@@ -17,10 +17,10 @@
package com.android.settings.widget;
import static com.google.common.truth.Truth.assertThat;
import static org.robolectric.RuntimeEnvironment.application;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.widget.TextView;
import com.android.settings.R;
@@ -38,36 +38,50 @@ import org.robolectric.annotation.Config;
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class SwitchBarTest {
private static final int COLOR_BACKGROUND = 1;
private static final int COLOR_BACKGROUND_ACTIVATED = 2;
private Context mContext;
private SwitchBar mBar;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mBar = new SwitchBar(application, Robolectric.buildAttributeSet().build());
mBar = new SwitchBar(application, Robolectric.buildAttributeSet()
.addAttribute(R.attr.switchBarBackgroundColor, String.valueOf(COLOR_BACKGROUND))
.addAttribute(R.attr.switchBarBackgroundActivatedColor,
String.valueOf(COLOR_BACKGROUND_ACTIVATED))
.build());
}
@Test
public void testDefaultLabels() {
int defaultOnText = R.string.switch_on_text;
int defaultOffText = R.string.switch_off_text;
public void cycleChecked_defaultLabel_shouldUpdateTextAndBackground() {
final int defaultOnText = R.string.switch_on_text;
final int defaultOffText = R.string.switch_off_text;
assertThat(((TextView) mBar.findViewById(R.id.switch_text)).getText())
.isEqualTo(mContext.getString(defaultOffText));
assertThat(mBar.getBackground()).isEqualTo(new ColorDrawable(COLOR_BACKGROUND));
mBar.setChecked(true);
assertThat(mBar.getBackground()).isEqualTo(new ColorDrawable(COLOR_BACKGROUND_ACTIVATED));
assertThat(((TextView) mBar.findViewById(R.id.switch_text)).getText())
.isEqualTo(mContext.getString(defaultOnText));
}
@Test
public void testCustomLabels() {
int onText = R.string.master_clear_progress_text;
int offText = R.string.manage_space_text;
public void cycleChecked_customLabel_shouldUpdateTextAndBackground() {
final int onText = R.string.master_clear_progress_text;
final int offText = R.string.manage_space_text;
mBar.setSwitchBarText(onText, offText);
assertThat(mBar.getBackground()).isEqualTo(new ColorDrawable(COLOR_BACKGROUND));
assertThat(((TextView) mBar.findViewById(R.id.switch_text)).getText())
.isEqualTo(mContext.getString(offText));
mBar.setChecked(true);
assertThat(mBar.getBackground()).isEqualTo(new ColorDrawable(COLOR_BACKGROUND_ACTIVATED));
assertThat(((TextView) mBar.findViewById(R.id.switch_text)).getText())
.isEqualTo(mContext.getString(onText));
}