From 34518f66357c25c0d7024d52684e1bd9d3645eed Mon Sep 17 00:00:00 2001 From: Selim Cinek Date: Thu, 28 Feb 2019 19:41:18 -0800 Subject: [PATCH] Follow up addressing comments of pulsing refactor Because of various rebases, this is much easier. Test: atest SystemUITests Fixes: 125942236 Change-Id: I169a0ee1843b8a34d29289cc70eaf650bade6997 --- .../systemui/statusbar/PulseExpansionHandler.kt | 10 +++--- .../notification/NotificationWakeUpCoordinator.kt | 37 ++++++++++++++-------- .../stack/NotificationStackScrollLayout.java | 9 ++++-- .../statusbar/phone/NotificationPanelView.java | 2 -- .../stack/NotificationStackScrollLayoutTest.java | 4 ++- .../statusbar/phone/NotificationPanelViewTest.java | 16 ++++++++-- 6 files changed, 50 insertions(+), 28 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/PulseExpansionHandler.kt b/packages/SystemUI/src/com/android/systemui/statusbar/PulseExpansionHandler.kt index 3009eeaaf095..e5dbcd374169 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/PulseExpansionHandler.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/PulseExpansionHandler.kt @@ -48,6 +48,10 @@ import kotlin.math.max class PulseExpansionHandler @Inject constructor(context: Context, private val mWakeUpCoordinator: NotificationWakeUpCoordinator) : Gefingerpoken { + companion object { + private val RUBBERBAND_FACTOR_STATIC = 0.25f + private val SPRING_BACK_ANIMATION_LENGTH_MS = 375 + } private val mPowerManager: PowerManager? private var mShadeController: ShadeController? = null @@ -265,10 +269,4 @@ constructor(context: Context, interface ExpansionCallback { fun setEmptyDragAmount(amount: Float) } - - companion object { - private val RUBBERBAND_FACTOR_STATIC = 0.25f - - private val SPRING_BACK_ANIMATION_LENGTH_MS = 375 - } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationWakeUpCoordinator.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationWakeUpCoordinator.kt index f0c7f76874eb..ccb8d9bf46c1 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationWakeUpCoordinator.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationWakeUpCoordinator.kt @@ -18,9 +18,10 @@ package com.android.systemui.statusbar.notification import android.animation.ObjectAnimator import android.util.FloatProperty -import android.view.animation.Interpolator import com.android.systemui.Interpolators +import com.android.systemui.plugins.statusbar.StatusBarStateController import com.android.systemui.statusbar.AmbientPulseManager +import com.android.systemui.statusbar.SysuiStatusBarStateController import com.android.systemui.statusbar.notification.collection.NotificationEntry import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout import com.android.systemui.statusbar.notification.stack.StackStateAnimator @@ -30,8 +31,9 @@ import javax.inject.Singleton @Singleton class NotificationWakeUpCoordinator @Inject constructor( - private val mAmbientPulseManager: AmbientPulseManager) - : AmbientPulseManager.OnAmbientChangedListener { + private val mAmbientPulseManager: AmbientPulseManager, + private val mStatusBarStateController: StatusBarStateController) + : AmbientPulseManager.OnAmbientChangedListener, StatusBarStateController.StateListener { private val mNotificationVisibility = object : FloatProperty("notificationVisibility") { @@ -60,6 +62,7 @@ class NotificationWakeUpCoordinator @Inject constructor( init { mAmbientPulseManager.addListener(this) + mStatusBarStateController.addCallback(this) } fun setStackScroller(stackScroller: NotificationStackScrollLayout) { @@ -75,6 +78,12 @@ class NotificationWakeUpCoordinator @Inject constructor( increaseSpeed: Boolean) { mNotificationsVisibleForExpansion = visible updateNotificationVisibility(animate, increaseSpeed) + if (!visible && mNotificationsVisible) { + // If we stopped expanding and we're still visible because we had a pulse that hasn't + // times out, let's release them all to make sure were not stuck in a state where + // notifications are visible + mAmbientPulseManager.releaseAllImmediately() + } } private fun updateNotificationVisibility(animate: Boolean, increaseSpeed: Boolean) { @@ -102,12 +111,17 @@ class NotificationWakeUpCoordinator @Inject constructor( } } - fun setDozeAmount(linearAmount: Float, interpolatedAmount: Float) { - mLinearDozeAmount = linearAmount - mDozeAmount = interpolatedAmount + override fun onDozeAmountChanged(linear: Float, eased: Float) { + if (linear != 1.0f && linear != 0.0f + && (mLinearDozeAmount == 0.0f || mLinearDozeAmount == 1.0f)) { + // Let's notify the scroller that an animation started + notifyAnimationStart(mLinearDozeAmount == 1.0f) + } + mLinearDozeAmount = linear + mDozeAmount = eased mStackScroller.setDozeAmount(mDozeAmount) updateDarkAmount() - if (linearAmount == 0.0f) { + if (linear == 0.0f) { setNotificationsVisible(visible = false, animate = false, increaseSpeed = false); setNotificationsVisibleForExpansion(visible = false, animate = false, increaseSpeed = false) @@ -148,7 +162,7 @@ class NotificationWakeUpCoordinator @Inject constructor( } fun getWakeUpHeight() : Float { - return mStackScroller.wakeUpHeight + return mStackScroller.pulseHeight } private fun updateDarkAmount() { @@ -161,13 +175,10 @@ class NotificationWakeUpCoordinator @Inject constructor( mStackScroller.notifyDarkAnimationStart(!awake) } - fun setDozing(dozing: Boolean, animate: Boolean) { - if (dozing) { + override fun onDozingChanged(isDozing: Boolean) { + if (isDozing) { setNotificationsVisible(visible = false, animate = false, increaseSpeed = false) } - if (animate) { - notifyAnimationStart(!dozing) - } } fun setPulseHeight(height: Float): Float { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java index da25a098d2fd..a54de5f0f5a9 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java @@ -583,12 +583,15 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd } } - public float getWakeUpHeight() { + /** + * @return the height at which we will wake up when pulsing + */ + public float getPulseHeight() { ActivatableNotificationView firstChild = getFirstChildWithBackground(); if (firstChild != null) { return firstChild.getCollapsedHeight(); } - return 0; + return 0f; } @Override @@ -5651,7 +5654,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd } public void wakeUpFromPulse() { - setPulseHeight(getWakeUpHeight()); + setPulseHeight(getPulseHeight()); // Let's place the hidden views at the end of the pulsing notification to make sure we have // a smooth animation boolean firstVisibleView = true; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java index e4d513a36aec..a35488518faa 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java @@ -2836,7 +2836,6 @@ public class NotificationPanelView extends PanelView implements final float darkAmount = dozing ? 1 : 0; mStatusBarStateController.setDozeAmount(darkAmount, animate); - mWakeUpCoordinator.setDozing(mDozing, animate); } @Override @@ -2847,7 +2846,6 @@ public class NotificationPanelView extends PanelView implements mKeyguardStatusView.setDarkAmount(mInterpolatedDarkAmount); mKeyguardBottomArea.setDarkAmount(mInterpolatedDarkAmount); positionClockAndNotifications(); - mWakeUpCoordinator.setDozeAmount(mLinearDarkAmount, mInterpolatedDarkAmount); } public void setPulsing(boolean pulsing) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutTest.java index d83508201529..e28be4517875 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutTest.java @@ -52,6 +52,7 @@ import com.android.systemui.R; import com.android.systemui.SysuiTestCase; import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin; import com.android.systemui.plugins.statusbar.StatusBarStateController; +import com.android.systemui.statusbar.AmbientPulseManager; import com.android.systemui.statusbar.EmptyShadeView; import com.android.systemui.statusbar.NotificationPresenter; import com.android.systemui.statusbar.NotificationRemoteInputManager; @@ -141,7 +142,8 @@ public class NotificationStackScrollLayoutTest extends SysuiTestCase { // holds a copy of the CUT's instances of these classes, so they still refer to the CUT's // member variables, not the spy's member variables. mStackScrollerInternal = new NotificationStackScrollLayout(getContext(), null, - true /* allowLongPress */, mNotificationRoundnessManager); + true /* allowLongPress */, mNotificationRoundnessManager, + new AmbientPulseManager(mContext)); mStackScroller = spy(mStackScrollerInternal); mStackScroller.setShelf(notificationShelf); mStackScroller.setStatusBar(mBar); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewTest.java index a97fa1ff1629..36212c27ecb6 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewTest.java @@ -28,8 +28,12 @@ import android.testing.TestableLooper; import com.android.keyguard.KeyguardStatusView; import com.android.systemui.SysuiTestCase; import com.android.systemui.plugins.statusbar.StatusBarStateController; +import com.android.systemui.statusbar.AmbientPulseManager; import com.android.systemui.statusbar.NotificationLockscreenUserManager; +import com.android.systemui.statusbar.PulseExpansionHandler; +import com.android.systemui.statusbar.StatusBarStateControllerImpl; import com.android.systemui.statusbar.SysuiStatusBarStateController; +import com.android.systemui.statusbar.notification.NotificationWakeUpCoordinator; import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout; import com.android.systemui.statusbar.policy.ConfigurationController; import com.android.systemui.statusbar.policy.ZenModeController; @@ -65,7 +69,12 @@ public class NotificationPanelViewTest extends SysuiTestCase { mDependency.injectMockDependency(NotificationLockscreenUserManager.class); mDependency.injectMockDependency(ConfigurationController.class); mDependency.injectMockDependency(ZenModeController.class); - mNotificationPanelView = new TestableNotificationPanelView(); + NotificationWakeUpCoordinator coordinator = + new NotificationWakeUpCoordinator( + new AmbientPulseManager(mContext), + new StatusBarStateControllerImpl()); + PulseExpansionHandler expansionHandler = new PulseExpansionHandler(mContext, coordinator); + mNotificationPanelView = new TestableNotificationPanelView(coordinator, expansionHandler); } @Test @@ -92,8 +101,9 @@ public class NotificationPanelViewTest extends SysuiTestCase { } private class TestableNotificationPanelView extends NotificationPanelView { - TestableNotificationPanelView() { - super(NotificationPanelViewTest.this.mContext, null); + TestableNotificationPanelView(NotificationWakeUpCoordinator coordinator, + PulseExpansionHandler expansionHandler) { + super(NotificationPanelViewTest.this.mContext, null, coordinator, expansionHandler); mNotificationStackScroller = mNotificationStackScrollLayout; mKeyguardStatusView = NotificationPanelViewTest.this.mKeyguardStatusView; mKeyguardStatusBar = NotificationPanelViewTest.this.mKeyguardStatusBar; -- 2.11.0