diff --git a/color-check-baseline.xml b/color-check-baseline.xml index 509d9ae0e5a..7a5e80d0a8a 100644 --- a/color-check-baseline.xml +++ b/color-check-baseline.xml @@ -1581,6 +1581,22 @@ column="5"/> + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/layout/flash_notification_preview_preference.xml b/res/layout/flash_notification_preview_preference.xml index b4be0f62df1..97f2245df0b 100644 --- a/res/layout/flash_notification_preview_preference.xml +++ b/res/layout/flash_notification_preview_preference.xml @@ -24,6 +24,7 @@ android:background="@android:color/transparent"> #FFFFFF + + + #1FE3E3E3 diff --git a/res/values/colors.xml b/res/values/colors.xml index 06e0734ba28..657ba110545 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -214,4 +214,7 @@ #4DFF017E #4DFF00FE #667F00FF + + + #1F1F1F1F diff --git a/src/com/android/settings/accessibility/FlashNotificationsPreviewPreference.java b/src/com/android/settings/accessibility/FlashNotificationsPreviewPreference.java index 9028bf182be..0141084cb12 100644 --- a/src/com/android/settings/accessibility/FlashNotificationsPreviewPreference.java +++ b/src/com/android/settings/accessibility/FlashNotificationsPreviewPreference.java @@ -17,16 +17,26 @@ package com.android.settings.accessibility; import android.content.Context; +import android.graphics.drawable.Drawable; import android.util.AttributeSet; +import android.view.View; +import android.widget.TextView; +import androidx.annotation.ColorInt; import androidx.preference.Preference; +import androidx.preference.PreferenceViewHolder; import com.android.settings.R; +import com.android.settingslib.Utils; /** * Preference for Flash notifications preview. */ public class FlashNotificationsPreviewPreference extends Preference { + private Drawable mBackgroundEnabled; + private Drawable mBackgroundDisabled; + @ColorInt + private int mTextColorDisabled; public FlashNotificationsPreviewPreference(Context context) { super(context); @@ -52,5 +62,32 @@ public class FlashNotificationsPreviewPreference extends Preference { private void init() { 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(); } } diff --git a/src/com/android/settings/accessibility/FlashNotificationsPreviewPreferenceController.java b/src/com/android/settings/accessibility/FlashNotificationsPreviewPreferenceController.java index 5a16a30bc9e..f13758439fd 100644 --- a/src/com/android/settings/accessibility/FlashNotificationsPreviewPreferenceController.java +++ b/src/com/android/settings/accessibility/FlashNotificationsPreviewPreferenceController.java @@ -55,7 +55,7 @@ public class FlashNotificationsPreviewPreferenceController extends new Handler(Looper.getMainLooper())) { @Override public void onChange(boolean selfChange, @Nullable Uri uri) { - onSettingChanged(); + updateState(mPreference); } }; @@ -73,7 +73,7 @@ public class FlashNotificationsPreviewPreferenceController extends public void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); mPreference = screen.findPreference(getPreferenceKey()); - onSettingChanged(); + updateState(mPreference); } @Override @@ -103,10 +103,13 @@ public class FlashNotificationsPreviewPreferenceController extends } } - private void onSettingChanged() { - if (mPreference == null) return; - - mPreference.setEnabled(FlashNotificationsUtil.getFlashNotificationsState(mContext) + @Override + public void updateState(Preference preference) { + super.updateState(preference); + if (preference == null) { + return; + } + preference.setEnabled(FlashNotificationsUtil.getFlashNotificationsState(mContext) != FlashNotificationsUtil.State.OFF); } } diff --git a/tests/robotests/src/com/android/settings/accessibility/FlashNotificationsPreviewPreferenceTest.java b/tests/robotests/src/com/android/settings/accessibility/FlashNotificationsPreviewPreferenceTest.java index ab38c1a734a..1e7f0898392 100644 --- a/tests/robotests/src/com/android/settings/accessibility/FlashNotificationsPreviewPreferenceTest.java +++ b/tests/robotests/src/com/android/settings/accessibility/FlashNotificationsPreviewPreferenceTest.java @@ -19,20 +19,26 @@ package com.android.settings.accessibility; import static com.google.common.truth.Truth.assertThat; 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 com.android.settings.R; +import com.android.settingslib.Utils; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Spy; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; -import org.robolectric.Robolectric; import org.robolectric.RobolectricTestRunner; +import org.robolectric.Shadows; @RunWith(RobolectricTestRunner.class) public class FlashNotificationsPreviewPreferenceTest { @@ -41,37 +47,46 @@ public class FlashNotificationsPreviewPreferenceTest { public MockitoRule mMockitoRule = MockitoJUnit.rule(); @Spy private final Context mContext = ApplicationProvider.getApplicationContext(); - private final AttributeSet mAttributeSet = Robolectric.buildAttributeSet().build(); + private FlashNotificationsPreviewPreference mFlashNotificationsPreviewPreference; + private PreferenceViewHolder mPreferenceViewHolder; - @Test - public void constructor_assertLayoutResource_P00() { - FlashNotificationsPreviewPreference preference = new FlashNotificationsPreviewPreference( - mContext); - assertThat(preference.getLayoutResource()) - .isEqualTo(R.layout.flash_notification_preview_preference); + @Before + public void setUp() { + mPreferenceViewHolder = PreferenceViewHolder.createInstanceForTests( + LayoutInflater.from(mContext).inflate( + R.layout.flash_notification_preview_preference, null)); + mFlashNotificationsPreviewPreference = new FlashNotificationsPreviewPreference(mContext); } @Test - public void constructor_assertLayoutResource_P01() { - FlashNotificationsPreviewPreference preference = new FlashNotificationsPreviewPreference( - mContext, mAttributeSet); - assertThat(preference.getLayoutResource()) - .isEqualTo(R.layout.flash_notification_preview_preference); + public void setEnabled_true_verifyEnabledUi() { + @ColorInt final int textColorEnabled = ((TextView) mPreferenceViewHolder.findViewById( + android.R.id.title)).getCurrentTextColor(); + + 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 - public void constructor_assertLayoutResource_P02() { - FlashNotificationsPreviewPreference preference = new FlashNotificationsPreviewPreference( - mContext, mAttributeSet, 0); - assertThat(preference.getLayoutResource()) - .isEqualTo(R.layout.flash_notification_preview_preference); - } + public void setEnabled_false_verifyDisabledUi() { + @ColorInt final int textColorDisabled = Utils.getColorAttrDefaultColor(mContext, + android.R.attr.textColorPrimary); - @Test - public void constructor_assertLayoutResource_P03() { - FlashNotificationsPreviewPreference preference = new FlashNotificationsPreviewPreference( - mContext, mAttributeSet, 0, 0); - assertThat(preference.getLayoutResource()) - .isEqualTo(R.layout.flash_notification_preview_preference); + mFlashNotificationsPreviewPreference.setEnabled(false); + mFlashNotificationsPreviewPreference.onBindViewHolder(mPreferenceViewHolder); + + final View frame = mPreferenceViewHolder.findViewById(R.id.frame); + final int backgroundResId = Shadows.shadowOf(frame.getBackground()).getCreatedFromResId(); + 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); } -} +} \ No newline at end of file