From e412b167ea33065e8196426871a0c2537d7840c7 Mon Sep 17 00:00:00 2001 From: William Xiao Date: Wed, 25 Jan 2023 13:14:03 -0800 Subject: Skip dream overlay animations when exiting low light The dream overlay currently does not animate when entering low light mode, but does animate when exiting it. This CL skips the animations when leaving low light and going back to the user dream for consistency. Bug: 260638159 Test: atest DreamOverlayStateControllerTest, atest DreamOverlayContainerViewControllerTest manually verified animations on device Change-Id: Ie097eaeef803cd5d39fa3c8206a2263ca22d5119 --- .../dreams/DreamOverlayAnimationsController.kt | 12 +++++++++++ .../DreamOverlayContainerViewController.java | 25 ++++++++++++++++++++++ .../dreams/DreamOverlayStateController.java | 10 +++++++++ .../DreamOverlayContainerViewControllerTest.java | 21 ++++++++++++++++++ .../dreams/DreamOverlayStateControllerTest.java | 24 +++++++++++++++++++++ 5 files changed, 92 insertions(+) diff --git a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayAnimationsController.kt b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayAnimationsController.kt index c882f8adceb6..c3bd5d96590e 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayAnimationsController.kt +++ b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayAnimationsController.kt @@ -182,6 +182,18 @@ constructor( } } + /** + * Ends the dream content and dream overlay animations, if they're currently running. + * @see [AnimatorSet.end] + */ + fun endAnimations() { + mAnimator = + mAnimator?.let { + it.end() + null + } + } + private fun blurAnimator( view: View, fromBlurRadius: Float, diff --git a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayContainerViewController.java b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayContainerViewController.java index 33c8379d2e5c..4aa6b5079675 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayContainerViewController.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayContainerViewController.java @@ -127,6 +127,23 @@ public class DreamOverlayContainerViewController extends ViewController callbackCaptor = + ArgumentCaptor.forClass(DreamOverlayStateController.Callback.class); + when(mStateController.isLowLightActive()).thenReturn(false); + + // Call onInit so that the callback is added. + mController.onInit(); + verify(mStateController).addCallback(callbackCaptor.capture()); + + // Send the signal that low light is exiting + callbackCaptor.getValue().onExitLowLight(); + + // View is attached to trigger animations. + mController.onViewAttached(); + + // Entry animations should be started then immediately ended to skip to the end. + verify(mAnimationsController).startEntryAnimations(); + verify(mAnimationsController).endAnimations(); + } + @Test public void testCancelDreamEntryAnimationsOnDetached() { mController.onViewAttached(); diff --git a/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayStateControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayStateControllerTest.java index ee989d1ddab6..b7d0f294ecd4 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayStateControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayStateControllerTest.java @@ -250,6 +250,30 @@ public class DreamOverlayStateControllerTest extends SysuiTestCase { assertThat(stateController.isLowLightActive()).isTrue(); } + @Test + public void testNotifyLowLightExit() { + final DreamOverlayStateController stateController = + new DreamOverlayStateController(mExecutor, true); + + stateController.addCallback(mCallback); + mExecutor.runAllReady(); + assertThat(stateController.isLowLightActive()).isFalse(); + + // Turn low light on then off to trigger the exiting callback. + stateController.setLowLightActive(true); + stateController.setLowLightActive(false); + + // Callback was only called once, when + mExecutor.runAllReady(); + verify(mCallback, times(1)).onExitLowLight(); + assertThat(stateController.isLowLightActive()).isFalse(); + + // Set with false again, which should not cause the callback to trigger again. + stateController.setLowLightActive(false); + mExecutor.runAllReady(); + verify(mCallback, times(1)).onExitLowLight(); + } + @Test public void testNotifyEntryAnimationsFinishedChanged() { final DreamOverlayStateController stateController = -- cgit v1.2.3-59-g8ed1b