Update UI for Flash notifications
1. Hide the preview button when it's disabled 2. Change the text from “Done” to “Save” in the color selector dialog Flag: EXEMPT simple UI change Bug: 356978471 Test: manually, video attached on the bug Test: atest FlashNotificationsPreviewPreferenceControllerTest Change-Id: I2e6e697ad10f0207602d613085663cdd82521ea2
This commit is contained in:
@@ -13446,7 +13446,7 @@
|
|||||||
<!-- Label of the color option show in the summary of screen flash preference. [CHAR LIMIT=60] -->
|
<!-- Label of the color option show in the summary of screen flash preference. [CHAR LIMIT=60] -->
|
||||||
<string name="screen_flash_color_violet">Violet</string>
|
<string name="screen_flash_color_violet">Violet</string>
|
||||||
<!-- Button to save the selection in screen flash color selection dialog. [CHAR LIMIT=20] -->
|
<!-- Button to save the selection in screen flash color selection dialog. [CHAR LIMIT=20] -->
|
||||||
<string name="color_selector_dialog_done">Done</string>
|
<string name="color_selector_dialog_save">Save</string>
|
||||||
<!-- Button to close the dialog without saving in screen flash color selection dialog. [CHAR LIMIT=20] -->
|
<!-- Button to close the dialog without saving in screen flash color selection dialog. [CHAR LIMIT=20] -->
|
||||||
<string name="color_selector_dialog_cancel">Cancel</string>
|
<string name="color_selector_dialog_cancel">Cancel</string>
|
||||||
|
|
||||||
|
@@ -110,7 +110,7 @@ public class FlashNotificationsPreviewPreferenceController extends
|
|||||||
if (preference == null) {
|
if (preference == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
preference.setEnabled(FlashNotificationsUtil.getFlashNotificationsState(mContext)
|
preference.setVisible(FlashNotificationsUtil.getFlashNotificationsState(mContext)
|
||||||
!= FlashNotificationsUtil.State.OFF);
|
!= FlashNotificationsUtil.State.OFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -65,8 +65,7 @@ public class ScreenFlashNotificationColorDialogFragment extends DialogFragment i
|
|||||||
final ScreenFlashNotificationColorDialogFragment result =
|
final ScreenFlashNotificationColorDialogFragment result =
|
||||||
new ScreenFlashNotificationColorDialogFragment();
|
new ScreenFlashNotificationColorDialogFragment();
|
||||||
result.mCurrentColor = initialColor;
|
result.mCurrentColor = initialColor;
|
||||||
result.mConsumer = colorConsumer != null ? colorConsumer : i -> {
|
result.mConsumer = colorConsumer != null ? colorConsumer : i -> {};
|
||||||
};
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +88,7 @@ public class ScreenFlashNotificationColorDialogFragment extends DialogFragment i
|
|||||||
.setNeutralButton(R.string.flash_notifications_preview, null)
|
.setNeutralButton(R.string.flash_notifications_preview, null)
|
||||||
.setNegativeButton(R.string.color_selector_dialog_cancel, (dialog, which) -> {
|
.setNegativeButton(R.string.color_selector_dialog_cancel, (dialog, which) -> {
|
||||||
})
|
})
|
||||||
.setPositiveButton(R.string.color_selector_dialog_done, (dialog, which) -> {
|
.setPositiveButton(R.string.color_selector_dialog_save, (dialog, which) -> {
|
||||||
mCurrentColor = colorSelectorLayout.getCheckedColor(DEFAULT_SCREEN_FLASH_COLOR);
|
mCurrentColor = colorSelectorLayout.getCheckedColor(DEFAULT_SCREEN_FLASH_COLOR);
|
||||||
mConsumer.accept(mCurrentColor);
|
mConsumer.accept(mCurrentColor);
|
||||||
})
|
})
|
||||||
|
@@ -67,22 +67,23 @@ public class FlashNotificationsPreviewPreferenceControllerTest {
|
|||||||
public MockitoRule mMockitoRule = MockitoJUnit.rule();
|
public MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||||
@Spy
|
@Spy
|
||||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||||
@Mock
|
|
||||||
private PreferenceScreen mPreferenceScreen;
|
|
||||||
@Mock
|
|
||||||
private Preference mPreference;
|
|
||||||
@Spy
|
@Spy
|
||||||
private ContentResolver mContentResolver = mContext.getContentResolver();
|
private ContentResolver mContentResolver = mContext.getContentResolver();
|
||||||
|
@Mock
|
||||||
|
private PreferenceScreen mPreferenceScreen;
|
||||||
|
private Preference mPreference;
|
||||||
private FlashNotificationsPreviewPreferenceController mController;
|
private FlashNotificationsPreviewPreferenceController mController;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
when(mPreferenceScreen.findPreference(PREFERENCE_KEY)).thenReturn(mPreference);
|
|
||||||
when(mPreference.getKey()).thenReturn(PREFERENCE_KEY);
|
|
||||||
|
|
||||||
when(mContext.getContentResolver()).thenReturn(mContentResolver);
|
when(mContext.getContentResolver()).thenReturn(mContentResolver);
|
||||||
|
|
||||||
|
mPreference = new Preference(mContext);
|
||||||
|
mPreference.setKey(PREFERENCE_KEY);
|
||||||
|
when(mPreferenceScreen.findPreference(PREFERENCE_KEY)).thenReturn(mPreference);
|
||||||
|
|
||||||
mController = new FlashNotificationsPreviewPreferenceController(mContext, PREFERENCE_KEY);
|
mController = new FlashNotificationsPreviewPreferenceController(mContext, PREFERENCE_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,40 +98,45 @@ public class FlashNotificationsPreviewPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDisplayPreference_torchPresent_cameraOff_screenOff_verifyDisabled() {
|
public void testDisplayPreference_torchPresent_cameraOff_screenOff_notVisible() {
|
||||||
setFlashNotificationsState(FlashNotificationsUtil.State.OFF);
|
setFlashNotificationsState(FlashNotificationsUtil.State.OFF);
|
||||||
|
|
||||||
mController.displayPreference(mPreferenceScreen);
|
mController.displayPreference(mPreferenceScreen);
|
||||||
verify(mPreference).setEnabled(eq(false));
|
|
||||||
|
assertThat(mPreference.isVisible()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDisplayPreference_torchPresent_cameraOn_screenOff_verifyEnabled() {
|
public void testDisplayPreference_torchPresent_cameraOn_screenOff_isVisible() {
|
||||||
setFlashNotificationsState(FlashNotificationsUtil.State.CAMERA);
|
setFlashNotificationsState(FlashNotificationsUtil.State.CAMERA);
|
||||||
|
|
||||||
mController.displayPreference(mPreferenceScreen);
|
mController.displayPreference(mPreferenceScreen);
|
||||||
verify(mPreference).setEnabled(eq(true));
|
|
||||||
|
assertThat(mPreference.isVisible()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDisplayPreference_torchPresent_cameraOff_screenOn_verifyEnabled() {
|
public void testDisplayPreference_torchPresent_cameraOff_screenOn_isVisible() {
|
||||||
setFlashNotificationsState(FlashNotificationsUtil.State.SCREEN);
|
setFlashNotificationsState(FlashNotificationsUtil.State.SCREEN);
|
||||||
|
|
||||||
mController.displayPreference(mPreferenceScreen);
|
mController.displayPreference(mPreferenceScreen);
|
||||||
verify(mPreference).setEnabled(eq(true));
|
|
||||||
|
assertThat(mPreference.isVisible()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDisplayPreference_torchPresent_cameraOn_screenOn_verifyEnabled() {
|
public void testDisplayPreference_torchPresent_cameraOn_screenOn_isVisible() {
|
||||||
setFlashNotificationsState(FlashNotificationsUtil.State.CAMERA_SCREEN);
|
setFlashNotificationsState(FlashNotificationsUtil.State.CAMERA_SCREEN);
|
||||||
|
|
||||||
mController.displayPreference(mPreferenceScreen);
|
mController.displayPreference(mPreferenceScreen);
|
||||||
verify(mPreference).setEnabled(eq(true));
|
|
||||||
|
assertThat(mPreference.isVisible()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHandlePreferenceTreeClick_invalidPreference() {
|
public void testHandlePreferenceTreeClick_invalidPreference() {
|
||||||
mController.handlePreferenceTreeClick(mock(Preference.class));
|
mController.handlePreferenceTreeClick(mock(Preference.class));
|
||||||
|
|
||||||
verify(mContext, never()).sendBroadcastAsUser(any(), any());
|
verify(mContext, never()).sendBroadcastAsUser(any(), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,6 +166,7 @@ public class FlashNotificationsPreviewPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onStateChanged_onResume_cameraUri_verifyRegister() {
|
public void onStateChanged_onResume_cameraUri_verifyRegister() {
|
||||||
mController.onStateChanged(mock(LifecycleOwner.class), Lifecycle.Event.ON_RESUME);
|
mController.onStateChanged(mock(LifecycleOwner.class), Lifecycle.Event.ON_RESUME);
|
||||||
|
|
||||||
verify(mContentResolver).registerContentObserver(
|
verify(mContentResolver).registerContentObserver(
|
||||||
eq(Settings.System.getUriFor(Settings.System.CAMERA_FLASH_NOTIFICATION)),
|
eq(Settings.System.getUriFor(Settings.System.CAMERA_FLASH_NOTIFICATION)),
|
||||||
anyBoolean(), eq(mController.mContentObserver));
|
anyBoolean(), eq(mController.mContentObserver));
|
||||||
@@ -168,6 +175,7 @@ public class FlashNotificationsPreviewPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onStateChanged_onResume_screenUri_verifyRegister() {
|
public void onStateChanged_onResume_screenUri_verifyRegister() {
|
||||||
mController.onStateChanged(mock(LifecycleOwner.class), Lifecycle.Event.ON_RESUME);
|
mController.onStateChanged(mock(LifecycleOwner.class), Lifecycle.Event.ON_RESUME);
|
||||||
|
|
||||||
verify(mContentResolver).registerContentObserver(
|
verify(mContentResolver).registerContentObserver(
|
||||||
eq(Settings.System.getUriFor(Settings.System.SCREEN_FLASH_NOTIFICATION)),
|
eq(Settings.System.getUriFor(Settings.System.SCREEN_FLASH_NOTIFICATION)),
|
||||||
anyBoolean(), eq(mController.mContentObserver));
|
anyBoolean(), eq(mController.mContentObserver));
|
||||||
@@ -176,6 +184,7 @@ public class FlashNotificationsPreviewPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onStateChanged_onPause_verifyUnregister() {
|
public void onStateChanged_onPause_verifyUnregister() {
|
||||||
mController.onStateChanged(mock(LifecycleOwner.class), Lifecycle.Event.ON_PAUSE);
|
mController.onStateChanged(mock(LifecycleOwner.class), Lifecycle.Event.ON_PAUSE);
|
||||||
|
|
||||||
verify(mContentResolver).unregisterContentObserver(eq(mController.mContentObserver));
|
verify(mContentResolver).unregisterContentObserver(eq(mController.mContentObserver));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user