Disabled state UI of Flash Notifications preview button

When both the camera flash and screen flash toggles are turned off, tapping on the preview button will have no effect and may confuse users. To avoid this, the appearance of the preview button should be updated to clearly indicated that its current state is disabled. This wil help users better understand the situation and prevent confusion.

Bug: 276494146
Test: checks the UI manually
Test: make RunSettingsRoboTests ROBOTEST_FILTER=FlashNotificationsPreviewPreferenceTest
Change-Id: I55b11188fde6e551921a9b0f7c89daa20a8b766b
This commit is contained in:
Angela Wang
2023-05-04 08:54:35 +00:00
parent 3f16621b86
commit 53a8cc0326
8 changed files with 185 additions and 33 deletions

View File

@@ -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);
}
}
}