Merge "Disabled state UI of Flash Notifications preview button" into udc-dev am: 22d3116188
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/23081916 Change-Id: I1aaac6f95b1821c08a59cabda22f84f69bfb3051 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -1581,6 +1581,22 @@
|
|||||||
column="5"/>
|
column="5"/>
|
||||||
</issue>
|
</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.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
|
||||||
|
errorLine1=" <color name="switch_bar_state_disabled_color">#1FE3E3E3</color>"
|
||||||
|
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||||
|
<location
|
||||||
|
file="res/values-night/colors.xml"
|
||||||
|
line="76"
|
||||||
|
column="5"/>
|
||||||
|
</issue>
|
||||||
|
|
||||||
<issue
|
<issue
|
||||||
id="HardCodedColor"
|
id="HardCodedColor"
|
||||||
severity="Error"
|
severity="Error"
|
||||||
@@ -2957,6 +2973,22 @@
|
|||||||
column="5"/>
|
column="5"/>
|
||||||
</issue>
|
</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.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
|
||||||
|
errorLine1=" <color name="switch_bar_state_disabled_color">#1F1F1F1F</color>"
|
||||||
|
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||||
|
<location
|
||||||
|
file="res/values/colors.xml"
|
||||||
|
line="219"
|
||||||
|
column="5"/>
|
||||||
|
</issue>
|
||||||
|
|
||||||
<issue
|
<issue
|
||||||
id="HardCodedColor"
|
id="HardCodedColor"
|
||||||
severity="Error"
|
severity="Error"
|
||||||
@@ -6253,6 +6285,38 @@
|
|||||||
column="63"/>
|
column="63"/>
|
||||||
</issue>
|
</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.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
|
||||||
|
errorLine1=" <solid android:color="@color/switch_bar_state_disabled_color"/>"
|
||||||
|
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||||
|
<location
|
||||||
|
file="res/drawable/switch_bar_bg_disabled.xml"
|
||||||
|
line="22"
|
||||||
|
column="20"/>
|
||||||
|
</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.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
|
||||||
|
errorLine1=" <solid android:color="@color/switch_bar_state_disabled_color"/>"
|
||||||
|
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||||
|
<location
|
||||||
|
file="res/drawable/switch_bar_bg_disabled.xml"
|
||||||
|
line="22"
|
||||||
|
column="20"/>
|
||||||
|
</issue>
|
||||||
|
|
||||||
<issue
|
<issue
|
||||||
id="HardCodedColor"
|
id="HardCodedColor"
|
||||||
severity="Error"
|
severity="Error"
|
||||||
|
26
res/drawable/switch_bar_bg_disabled.xml
Normal file
26
res/drawable/switch_bar_bg_disabled.xml
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 2023 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:color="?android:attr/colorControlHighlight">
|
||||||
|
<item>
|
||||||
|
<shape android:shape="rectangle">
|
||||||
|
<solid android:color="@color/switch_bar_state_disabled_color"/>
|
||||||
|
<corners android:radius="@dimen/settingslib_switch_bar_radius"/>
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
</ripple>
|
@@ -24,6 +24,7 @@
|
|||||||
android:background="@android:color/transparent">
|
android:background="@android:color/transparent">
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
|
android:id="@+id/frame"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:paddingStart="@dimen/settingslib_switchbar_padding_left"
|
android:paddingStart="@dimen/settingslib_switchbar_padding_left"
|
||||||
|
@@ -71,5 +71,8 @@
|
|||||||
<!-- Flash notifications colors -->
|
<!-- Flash notifications colors -->
|
||||||
<!-- Screen flash notification color selected stroke in color selection dialog -->
|
<!-- Screen flash notification color selected stroke in color selection dialog -->
|
||||||
<color name="screen_flash_color_button_outer_circle_stroke_color">#FFFFFF</color>
|
<color name="screen_flash_color_button_outer_circle_stroke_color">#FFFFFF</color>
|
||||||
|
|
||||||
|
<!-- Switch bar disabled state color-->
|
||||||
|
<color name="switch_bar_state_disabled_color">#1FE3E3E3</color>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
||||||
|
@@ -214,4 +214,7 @@
|
|||||||
<color name="screen_flash_preset_opacity_color_10">#4DFF017E</color> <!-- 30% Rose -->
|
<color name="screen_flash_preset_opacity_color_10">#4DFF017E</color> <!-- 30% Rose -->
|
||||||
<color name="screen_flash_preset_opacity_color_11">#4DFF00FE</color> <!-- 30% Magenta -->
|
<color name="screen_flash_preset_opacity_color_11">#4DFF00FE</color> <!-- 30% Magenta -->
|
||||||
<color name="screen_flash_preset_opacity_color_12">#667F00FF</color> <!-- 40% Violet -->
|
<color name="screen_flash_preset_opacity_color_12">#667F00FF</color> <!-- 40% Violet -->
|
||||||
|
|
||||||
|
<!-- Switch bar disabled state color-->
|
||||||
|
<color name="switch_bar_state_disabled_color">#1F1F1F1F</color>
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -17,16 +17,26 @@
|
|||||||
package com.android.settings.accessibility;
|
package com.android.settings.accessibility;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.ColorInt;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceViewHolder;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settingslib.Utils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preference for Flash notifications preview.
|
* Preference for Flash notifications preview.
|
||||||
*/
|
*/
|
||||||
public class FlashNotificationsPreviewPreference extends Preference {
|
public class FlashNotificationsPreviewPreference extends Preference {
|
||||||
|
private Drawable mBackgroundEnabled;
|
||||||
|
private Drawable mBackgroundDisabled;
|
||||||
|
@ColorInt
|
||||||
|
private int mTextColorDisabled;
|
||||||
|
|
||||||
public FlashNotificationsPreviewPreference(Context context) {
|
public FlashNotificationsPreviewPreference(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
@@ -52,5 +62,32 @@ public class FlashNotificationsPreviewPreference extends Preference {
|
|||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
setLayoutResource(R.layout.flash_notification_preview_preference);
|
setLayoutResource(R.layout.flash_notification_preview_preference);
|
||||||
|
mBackgroundEnabled = getContext().getDrawable(R.drawable.settingslib_switch_bar_bg_on);
|
||||||
|
mBackgroundDisabled = getContext().getDrawable(R.drawable.switch_bar_bg_disabled);
|
||||||
|
mTextColorDisabled = Utils.getColorAttrDefaultColor(getContext(),
|
||||||
|
android.R.attr.textColorPrimary);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||||
|
super.onBindViewHolder(holder);
|
||||||
|
|
||||||
|
final boolean enabled = isEnabled();
|
||||||
|
final View frame = holder.findViewById(R.id.frame);
|
||||||
|
if (frame != null) {
|
||||||
|
frame.setBackground(enabled ? mBackgroundEnabled : mBackgroundDisabled);
|
||||||
|
}
|
||||||
|
final TextView title = (TextView) holder.findViewById(android.R.id.title);
|
||||||
|
if (title != null) {
|
||||||
|
@ColorInt final int textColorEnabled = title.getCurrentTextColor();
|
||||||
|
title.setAlpha(enabled ? 1f : 0.38f);
|
||||||
|
title.setTextColor(enabled ? textColorEnabled : mTextColorDisabled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setEnabled(boolean enabled) {
|
||||||
|
super.setEnabled(enabled);
|
||||||
|
notifyChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -55,7 +55,7 @@ public class FlashNotificationsPreviewPreferenceController extends
|
|||||||
new Handler(Looper.getMainLooper())) {
|
new Handler(Looper.getMainLooper())) {
|
||||||
@Override
|
@Override
|
||||||
public void onChange(boolean selfChange, @Nullable Uri uri) {
|
public void onChange(boolean selfChange, @Nullable Uri uri) {
|
||||||
onSettingChanged();
|
updateState(mPreference);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ public class FlashNotificationsPreviewPreferenceController extends
|
|||||||
public void displayPreference(PreferenceScreen screen) {
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
super.displayPreference(screen);
|
super.displayPreference(screen);
|
||||||
mPreference = screen.findPreference(getPreferenceKey());
|
mPreference = screen.findPreference(getPreferenceKey());
|
||||||
onSettingChanged();
|
updateState(mPreference);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -103,10 +103,13 @@ public class FlashNotificationsPreviewPreferenceController extends
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onSettingChanged() {
|
@Override
|
||||||
if (mPreference == null) return;
|
public void updateState(Preference preference) {
|
||||||
|
super.updateState(preference);
|
||||||
mPreference.setEnabled(FlashNotificationsUtil.getFlashNotificationsState(mContext)
|
if (preference == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
preference.setEnabled(FlashNotificationsUtil.getFlashNotificationsState(mContext)
|
||||||
!= FlashNotificationsUtil.State.OFF);
|
!= FlashNotificationsUtil.State.OFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,20 +19,26 @@ package com.android.settings.accessibility;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.AttributeSet;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.ColorInt;
|
||||||
|
import androidx.preference.PreferenceViewHolder;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settingslib.Utils;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Spy;
|
import org.mockito.Spy;
|
||||||
import org.mockito.junit.MockitoJUnit;
|
import org.mockito.junit.MockitoJUnit;
|
||||||
import org.mockito.junit.MockitoRule;
|
import org.mockito.junit.MockitoRule;
|
||||||
import org.robolectric.Robolectric;
|
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.Shadows;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class FlashNotificationsPreviewPreferenceTest {
|
public class FlashNotificationsPreviewPreferenceTest {
|
||||||
@@ -41,37 +47,46 @@ public class FlashNotificationsPreviewPreferenceTest {
|
|||||||
public MockitoRule mMockitoRule = MockitoJUnit.rule();
|
public MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||||
@Spy
|
@Spy
|
||||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||||
private final AttributeSet mAttributeSet = Robolectric.buildAttributeSet().build();
|
private FlashNotificationsPreviewPreference mFlashNotificationsPreviewPreference;
|
||||||
|
private PreferenceViewHolder mPreferenceViewHolder;
|
||||||
|
|
||||||
@Test
|
@Before
|
||||||
public void constructor_assertLayoutResource_P00() {
|
public void setUp() {
|
||||||
FlashNotificationsPreviewPreference preference = new FlashNotificationsPreviewPreference(
|
mPreferenceViewHolder = PreferenceViewHolder.createInstanceForTests(
|
||||||
mContext);
|
LayoutInflater.from(mContext).inflate(
|
||||||
assertThat(preference.getLayoutResource())
|
R.layout.flash_notification_preview_preference, null));
|
||||||
.isEqualTo(R.layout.flash_notification_preview_preference);
|
mFlashNotificationsPreviewPreference = new FlashNotificationsPreviewPreference(mContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void constructor_assertLayoutResource_P01() {
|
public void setEnabled_true_verifyEnabledUi() {
|
||||||
FlashNotificationsPreviewPreference preference = new FlashNotificationsPreviewPreference(
|
@ColorInt final int textColorEnabled = ((TextView) mPreferenceViewHolder.findViewById(
|
||||||
mContext, mAttributeSet);
|
android.R.id.title)).getCurrentTextColor();
|
||||||
assertThat(preference.getLayoutResource())
|
|
||||||
.isEqualTo(R.layout.flash_notification_preview_preference);
|
mFlashNotificationsPreviewPreference.setEnabled(true);
|
||||||
|
mFlashNotificationsPreviewPreference.onBindViewHolder(mPreferenceViewHolder);
|
||||||
|
|
||||||
|
final View frame = mPreferenceViewHolder.findViewById(R.id.frame);
|
||||||
|
final int backgroundResId = Shadows.shadowOf(frame.getBackground()).getCreatedFromResId();
|
||||||
|
assertThat(backgroundResId).isEqualTo(R.drawable.settingslib_switch_bar_bg_on);
|
||||||
|
final TextView title = (TextView) mPreferenceViewHolder.findViewById(android.R.id.title);
|
||||||
|
assertThat(title.getAlpha()).isEqualTo(1f);
|
||||||
|
assertThat(title.getCurrentTextColor()).isEqualTo(textColorEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void constructor_assertLayoutResource_P02() {
|
public void setEnabled_false_verifyDisabledUi() {
|
||||||
FlashNotificationsPreviewPreference preference = new FlashNotificationsPreviewPreference(
|
@ColorInt final int textColorDisabled = Utils.getColorAttrDefaultColor(mContext,
|
||||||
mContext, mAttributeSet, 0);
|
android.R.attr.textColorPrimary);
|
||||||
assertThat(preference.getLayoutResource())
|
|
||||||
.isEqualTo(R.layout.flash_notification_preview_preference);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
mFlashNotificationsPreviewPreference.setEnabled(false);
|
||||||
public void constructor_assertLayoutResource_P03() {
|
mFlashNotificationsPreviewPreference.onBindViewHolder(mPreferenceViewHolder);
|
||||||
FlashNotificationsPreviewPreference preference = new FlashNotificationsPreviewPreference(
|
|
||||||
mContext, mAttributeSet, 0, 0);
|
final View frame = mPreferenceViewHolder.findViewById(R.id.frame);
|
||||||
assertThat(preference.getLayoutResource())
|
final int backgroundResId = Shadows.shadowOf(frame.getBackground()).getCreatedFromResId();
|
||||||
.isEqualTo(R.layout.flash_notification_preview_preference);
|
assertThat(backgroundResId).isEqualTo(R.drawable.switch_bar_bg_disabled);
|
||||||
|
final TextView title = (TextView) mPreferenceViewHolder.findViewById(android.R.id.title);
|
||||||
|
assertThat(title.getAlpha()).isEqualTo(0.38f);
|
||||||
|
assertThat(title.getCurrentTextColor()).isEqualTo(textColorDisabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user