Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4ad8e0c5 authored by Angela Wang's avatar Angela Wang
Browse files

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
parent b6e0cd99
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -13446,7 +13446,7 @@
    <!-- Label of the color option show in the summary of screen flash preference. [CHAR LIMIT=60] -->
    <string name="screen_flash_color_violet">Violet</string>
    <!-- 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] -->
    <string name="color_selector_dialog_cancel">Cancel</string>
+1 −1
Original line number Diff line number Diff line
@@ -110,7 +110,7 @@ public class FlashNotificationsPreviewPreferenceController extends
        if (preference == null) {
            return;
        }
        preference.setEnabled(FlashNotificationsUtil.getFlashNotificationsState(mContext)
        preference.setVisible(FlashNotificationsUtil.getFlashNotificationsState(mContext)
                != FlashNotificationsUtil.State.OFF);
    }
}
+2 −3
Original line number Diff line number Diff line
@@ -65,8 +65,7 @@ public class ScreenFlashNotificationColorDialogFragment extends DialogFragment i
        final ScreenFlashNotificationColorDialogFragment result =
                new ScreenFlashNotificationColorDialogFragment();
        result.mCurrentColor = initialColor;
        result.mConsumer = colorConsumer != null ? colorConsumer : i -> {
        };
        result.mConsumer = colorConsumer != null ? colorConsumer : i -> {};
        return result;
    }

@@ -89,7 +88,7 @@ public class ScreenFlashNotificationColorDialogFragment extends DialogFragment i
                .setNeutralButton(R.string.flash_notifications_preview, null)
                .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);
                    mConsumer.accept(mCurrentColor);
                })
+23 −14
Original line number Diff line number Diff line
@@ -67,22 +67,23 @@ public class FlashNotificationsPreviewPreferenceControllerTest {
    public MockitoRule mMockitoRule = MockitoJUnit.rule();
    @Spy
    private final Context mContext = ApplicationProvider.getApplicationContext();
    @Spy
    private ContentResolver mContentResolver = mContext.getContentResolver();
    @Mock
    private PreferenceScreen mPreferenceScreen;
    @Mock
    private Preference mPreference;
    @Spy
    private ContentResolver mContentResolver = mContext.getContentResolver();

    private FlashNotificationsPreviewPreferenceController mController;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        when(mPreferenceScreen.findPreference(PREFERENCE_KEY)).thenReturn(mPreference);
        when(mPreference.getKey()).thenReturn(PREFERENCE_KEY);

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

@@ -97,40 +98,45 @@ public class FlashNotificationsPreviewPreferenceControllerTest {
    }

    @Test
    public void testDisplayPreference_torchPresent_cameraOff_screenOff_verifyDisabled() {
    public void testDisplayPreference_torchPresent_cameraOff_screenOff_notVisible() {
        setFlashNotificationsState(FlashNotificationsUtil.State.OFF);

        mController.displayPreference(mPreferenceScreen);
        verify(mPreference).setEnabled(eq(false));

        assertThat(mPreference.isVisible()).isFalse();
    }

    @Test
    public void testDisplayPreference_torchPresent_cameraOn_screenOff_verifyEnabled() {
    public void testDisplayPreference_torchPresent_cameraOn_screenOff_isVisible() {
        setFlashNotificationsState(FlashNotificationsUtil.State.CAMERA);

        mController.displayPreference(mPreferenceScreen);
        verify(mPreference).setEnabled(eq(true));

        assertThat(mPreference.isVisible()).isTrue();
    }

    @Test
    public void testDisplayPreference_torchPresent_cameraOff_screenOn_verifyEnabled() {
    public void testDisplayPreference_torchPresent_cameraOff_screenOn_isVisible() {
        setFlashNotificationsState(FlashNotificationsUtil.State.SCREEN);

        mController.displayPreference(mPreferenceScreen);
        verify(mPreference).setEnabled(eq(true));

        assertThat(mPreference.isVisible()).isTrue();
    }

    @Test
    public void testDisplayPreference_torchPresent_cameraOn_screenOn_verifyEnabled() {
    public void testDisplayPreference_torchPresent_cameraOn_screenOn_isVisible() {
        setFlashNotificationsState(FlashNotificationsUtil.State.CAMERA_SCREEN);

        mController.displayPreference(mPreferenceScreen);
        verify(mPreference).setEnabled(eq(true));

        assertThat(mPreference.isVisible()).isTrue();
    }

    @Test
    public void testHandlePreferenceTreeClick_invalidPreference() {
        mController.handlePreferenceTreeClick(mock(Preference.class));

        verify(mContext, never()).sendBroadcastAsUser(any(), any());
    }

@@ -160,6 +166,7 @@ public class FlashNotificationsPreviewPreferenceControllerTest {
    @Test
    public void onStateChanged_onResume_cameraUri_verifyRegister() {
        mController.onStateChanged(mock(LifecycleOwner.class), Lifecycle.Event.ON_RESUME);

        verify(mContentResolver).registerContentObserver(
                eq(Settings.System.getUriFor(Settings.System.CAMERA_FLASH_NOTIFICATION)),
                anyBoolean(), eq(mController.mContentObserver));
@@ -168,6 +175,7 @@ public class FlashNotificationsPreviewPreferenceControllerTest {
    @Test
    public void onStateChanged_onResume_screenUri_verifyRegister() {
        mController.onStateChanged(mock(LifecycleOwner.class), Lifecycle.Event.ON_RESUME);

        verify(mContentResolver).registerContentObserver(
                eq(Settings.System.getUriFor(Settings.System.SCREEN_FLASH_NOTIFICATION)),
                anyBoolean(), eq(mController.mContentObserver));
@@ -176,6 +184,7 @@ public class FlashNotificationsPreviewPreferenceControllerTest {
    @Test
    public void onStateChanged_onPause_verifyUnregister() {
        mController.onStateChanged(mock(LifecycleOwner.class), Lifecycle.Event.ON_PAUSE);

        verify(mContentResolver).unregisterContentObserver(eq(mController.mContentObserver));
    }
}