diff options
| author | 2023-01-26 20:15:49 +0000 | |
|---|---|---|
| committer | 2023-01-26 20:15:49 +0000 | |
| commit | 6fb611c962dc5c54c571325b2df0ce888c5f230d (patch) | |
| tree | 017a414313b18c68b8020e060e4343db3efe10fc | |
| parent | d5ead3ae5614f4846c9bf9b3d45be4c152f6d229 (diff) | |
| parent | e412b167ea33065e8196426871a0c2537d7840c7 (diff) | |
Merge "Skip dream overlay animations when exiting low light" into tm-qpr-dev
5 files changed, 92 insertions, 0 deletions
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 c2dcdd0eed17..4de96e342b2f 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayContainerViewController.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayContainerViewController.java @@ -124,6 +124,23 @@ public class DreamOverlayContainerViewController extends ViewController<DreamOve } }; + /** + * If true, overlay entry animations should be skipped once. + * + * This is turned on when exiting low light and should be turned off once the entry animations + * are skipped once. + */ + private boolean mSkipEntryAnimations; + + private final DreamOverlayStateController.Callback + mDreamOverlayStateCallback = + new DreamOverlayStateController.Callback() { + @Override + public void onExitLowLight() { + mSkipEntryAnimations = true; + } + }; + @Inject public DreamOverlayContainerViewController( DreamOverlayContainerView containerView, @@ -165,6 +182,7 @@ public class DreamOverlayContainerViewController extends ViewController<DreamOve @Override protected void onInit() { + mStateController.addCallback(mDreamOverlayStateCallback); mStatusBarViewController.init(); mComplicationHostViewController.init(); mDreamOverlayAnimationsController.init(mView); @@ -179,6 +197,13 @@ public class DreamOverlayContainerViewController extends ViewController<DreamOve // Start dream entry animations. Skip animations for low light clock. if (!mStateController.isLowLightActive()) { mDreamOverlayAnimationsController.startEntryAnimations(); + + if (mSkipEntryAnimations) { + // If we're transitioning from the low light dream back to the user dream, skip the + // overlay animations and show immediately. + mDreamOverlayAnimationsController.endAnimations(); + mSkipEntryAnimations = false; + } } } diff --git a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayStateController.java b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayStateController.java index ccfdd0966e98..2c7ecb1182f2 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayStateController.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayStateController.java @@ -83,6 +83,12 @@ public class DreamOverlayStateController implements */ default void onAvailableComplicationTypesChanged() { } + + /** + * Called when the low light dream is exiting and transitioning back to the user dream. + */ + default void onExitLowLight() { + } } private final Executor mExecutor; @@ -278,6 +284,10 @@ public class DreamOverlayStateController implements * @param active {@code true} if low light mode is active, {@code false} otherwise. */ public void setLowLightActive(boolean active) { + if (isLowLightActive() && !active) { + // Notify that we're exiting low light only on the transition from active to not active. + mCallbacks.forEach(Callback::onExitLowLight); + } modifyState(active ? OP_SET_STATE : OP_CLEAR_STATE, STATE_LOW_LIGHT_ACTIVE); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayContainerViewControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayContainerViewControllerTest.java index 3d9afacfadc9..84c97862710f 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayContainerViewControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayContainerViewControllerTest.java @@ -209,6 +209,27 @@ public class DreamOverlayContainerViewControllerTest extends SysuiTestCase { } @Test + public void testSkipEntryAnimationsWhenExitingLowLight() { + ArgumentCaptor<DreamOverlayStateController.Callback> 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(); mController.onViewDetached(); 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 @@ -251,6 +251,30 @@ public class DreamOverlayStateControllerTest extends SysuiTestCase { } @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 = new DreamOverlayStateController(mExecutor, true); |