OSDN Git Service

Made sure the disappear animation for pulsing works correctly
authorSelim Cinek <cinek@google.com>
Wed, 20 Feb 2019 19:18:56 +0000 (11:18 -0800)
committerSelim Cinek <cinek@google.com>
Fri, 1 Mar 2019 05:39:00 +0000 (21:39 -0800)
Previously it was clipped and the shelf was visible.
Also made sure that the wakeup animation from pulsing looks
good.

Test: atest SystemUITests
Bug: 125942236
Change-Id: If850be294d89a8dd11f68fd64ef82d5f077a11f5

12 files changed:
packages/SystemUI/src/com/android/systemui/statusbar/AmbientPulseManager.java
packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java
packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationWakeUpCoordinator.kt
packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationData.java
packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java
packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java
packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableView.java
packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/AmbientState.java
packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationSection.java
packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java
packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/StackScrollAlgorithm.java
packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java

index 57d0588..5f878ce 100644 (file)
@@ -131,7 +131,7 @@ public class AmbientPulseManager extends AlertingNotificationManager {
          * @param entry the entry that changed
          * @param isPulsing true if the entry is now pulsing, false otherwise
          */
-        void onAmbientStateChanged(NotificationEntry entry, boolean isPulsing);
+        void onAmbientStateChanged(@NonNull NotificationEntry entry, boolean isPulsing);
     }
 
     private final class AmbientEntry extends AlertEntry {
index d472aeb..2cca701 100644 (file)
@@ -232,8 +232,7 @@ public class NotificationShelf extends ActivatableNotificationView implements
             openedAmount = Math.min(1.0f, openedAmount);
             viewState.openedAmount = openedAmount;
             viewState.clipTopAmount = 0;
-            viewState.alpha = mAmbientState.hasPulsingNotifications()
-                    && !mAmbientState.isPulseExpanding() ? 0 : 1;
+            viewState.alpha = 1;
             viewState.belowSpeedBump = mAmbientState.getSpeedBumpIndex() == 0;
             viewState.hideSensitive = false;
             viewState.xTranslation = getTranslationX();
@@ -501,7 +500,7 @@ public class NotificationShelf extends ActivatableNotificationView implements
         float viewEnd = row.getTranslationY() + row.getActualHeight();
         boolean isPinned = (row.isPinned() || row.isHeadsUpAnimatingAway())
                 && !mAmbientState.isDozingAndNotPulsing(row);
-        boolean shouldClipOwnTop = row.isAmbientPulsing()
+        boolean shouldClipOwnTop = row.showingAmbientPulsing()
                 || (mAmbientState.isPulseExpanding() && childIndex == 0);
         if (viewEnd > notificationClipEnd && !shouldClipOwnTop
                 && (mAmbientState.isShadeExpanded() || !isPinned)) {
@@ -671,7 +670,7 @@ public class NotificationShelf extends ActivatableNotificationView implements
                 ? fullTransitionAmount
                 : transitionAmount;
         iconState.clampedAppearAmount = clampedAmount;
-        float contentTransformationAmount = !mAmbientState.isAboveShelf(row)
+        float contentTransformationAmount = !row.isAboveShelf()
                     && (isLastChild || iconState.translateContent)
                 ? iconTransitionAmount
                 : 0.0f;
@@ -740,7 +739,7 @@ public class NotificationShelf extends ActivatableNotificationView implements
                 iconState.scaleY = 1.0f;
                 iconState.hidden = false;
             }
-            if (mAmbientState.isAboveShelf(row) || (!row.isInShelf() && (isLastChild && row.areGutsExposed()
+            if (row.isAboveShelf() || (!row.isInShelf() && (isLastChild && row.areGutsExposed()
                     || row.getTranslationZ() > mAmbientState.getBaseZHeight()))) {
                 iconState.hidden = true;
             }
index fa10d1f..d8d1c50 100644 (file)
@@ -55,7 +55,8 @@ class NotificationWakeUpCoordinator @Inject constructor(
     private var mDarkAnimator: ObjectAnimator? = null
     private var mVisibilityAmount = 0.0f
     private var mLinearVisibilityAmount = 0.0f
-    private var mPulsing: Boolean = false
+    private var mWakingUp = false
+    private val mEntrySetToClearWhenFinished = mutableSetOf<NotificationEntry>()
 
     init {
         mAmbientPulseManager.addListener(this)
@@ -77,9 +78,11 @@ class NotificationWakeUpCoordinator @Inject constructor(
     }
 
     private fun updateNotificationVisibility(animate: Boolean, increaseSpeed: Boolean) {
-        var visible = false
-        if (mPulsing) {
-            visible = mNotificationsVisibleForExpansion || mAmbientPulseManager.hasNotifications()
+        var visible = mNotificationsVisibleForExpansion || mAmbientPulseManager.hasNotifications()
+        if (!visible && mNotificationsVisible && mWakingUp && mDozeAmount != 0.0f) {
+            // let's not make notifications invisible while waking up, otherwise the animation
+            // is strange
+            return;
         }
         setNotificationsVisible(visible, animate, increaseSpeed)
     }
@@ -104,6 +107,11 @@ class NotificationWakeUpCoordinator @Inject constructor(
         mDozeAmount = interpolatedAmount
         mStackScroller.setDozeAmount(mDozeAmount)
         updateDarkAmount()
+        if (linearAmount == 0.0f) {
+            setNotificationsVisible(visible = false, animate = false, increaseSpeed = false);
+            setNotificationsVisibleForExpansion(visible = false, animate = false,
+                    increaseSpeed = false)
+        }
     }
 
     private fun startVisibilityAnimation(increaseSpeed: Boolean) {
@@ -129,9 +137,16 @@ class NotificationWakeUpCoordinator @Inject constructor(
         mLinearVisibilityAmount = visibilityAmount
         mVisibilityAmount = mVisibilityInterpolator.getInterpolation(
                 visibilityAmount)
+        handleAnimationFinished();
         updateDarkAmount()
     }
 
+    private fun handleAnimationFinished() {
+        if (mLinearDozeAmount == 0.0f || mLinearVisibilityAmount == 0.0f) {
+            mEntrySetToClearWhenFinished.forEach { it.setAmbientGoingAway(false) }
+        }
+    }
+
     fun getWakeUpHeight() : Float {
         return mStackScroller.wakeUpHeight
     }
@@ -148,8 +163,7 @@ class NotificationWakeUpCoordinator @Inject constructor(
 
     fun setDozing(dozing: Boolean, animate: Boolean) {
         if (dozing) {
-            mNotificationsVisible = false
-            mNotificationsVisibleForExpansion = false
+            setNotificationsVisible(visible = false, animate = false, increaseSpeed = false)
         }
         if (animate) {
             notifyAnimationStart(!dozing)
@@ -160,12 +174,22 @@ class NotificationWakeUpCoordinator @Inject constructor(
         return mStackScroller.setPulseHeight(height)
     }
 
-    fun setPulsing(pulsing: Boolean) {
-        mPulsing = pulsing;
-        updateNotificationVisibility(animate = true, increaseSpeed = false)
+    fun setWakingUp(wakingUp: Boolean) {
+        mWakingUp = wakingUp
+        if (wakingUp && mNotificationsVisible && !mNotificationsVisibleForExpansion) {
+            // We're waking up while pulsing, let's make sure the animation looks nice
+            mStackScroller.wakeUpFromPulse();
+        }
     }
 
-    override fun onAmbientStateChanged(entry: NotificationEntry?, isPulsing: Boolean) {
+    override fun onAmbientStateChanged(entry: NotificationEntry, isPulsing: Boolean) {
+        if (!isPulsing && mLinearDozeAmount != 0.0f) {
+            entry.setAmbientGoingAway(true)
+            mEntrySetToClearWhenFinished.add(entry)
+        } else if (isPulsing && mEntrySetToClearWhenFinished.contains(entry)) {
+            mEntrySetToClearWhenFinished.remove(entry)
+            entry.setAmbientGoingAway(false)
+        }
         updateNotificationVisibility(animate = true, increaseSpeed = false)
     }
 }
\ No newline at end of file
index 8b522a2..04ff58b 100644 (file)
@@ -112,8 +112,8 @@ public class NotificationData {
             } else if (isHeadsUp) {
                 // Provide consistent ranking with headsUpManager
                 return mHeadsUpManager.compare(a, b);
-            } else if (a.getRow().isAmbientPulsing() != b.getRow().isAmbientPulsing()) {
-                return a.getRow().isAmbientPulsing() ? -1 : 1;
+            } else if (a.getRow().showingAmbientPulsing() != b.getRow().showingAmbientPulsing()) {
+                return a.getRow().showingAmbientPulsing() ? -1 : 1;
             } else if (aMedia != bMedia) {
                 // Upsort current media notification.
                 return aMedia ? -1 : 1;
index 3bf4d4b..5cd1210 100644 (file)
@@ -571,6 +571,12 @@ public final class NotificationEntry {
         if (row != null) row.setHeadsUp(shouldHeadsUp);
     }
 
+
+    public void setAmbientGoingAway(boolean goingAway) {
+        if (row != null) row.setAmbientGoingAway(goingAway);
+    }
+
+
     public boolean mustStayOnScreen() {
         return row != null && row.mustStayOnScreen();
     }
index 1575f18..767e14c 100644 (file)
@@ -215,6 +215,11 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
     private boolean mIsAmbientPulsing;
 
     /**
+     * Happens when the notification was pulsing before and goes away to ensure smooth animations.
+     */
+    private boolean mAmbientGoingAway;
+
+    /**
      * Whether or not the notification should be redacted on the lock screen, i.e has sensitive
      * content which should be redacted on the lock screen.
      */
@@ -722,8 +727,8 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
     }
 
     @Override
-    public boolean isAmbientPulsing() {
-        return mIsAmbientPulsing;
+    public boolean showingAmbientPulsing() {
+        return mIsAmbientPulsing || mAmbientGoingAway;
     }
 
     public void setAmbientPulsing(boolean isAmbientPulsing) {
@@ -3005,7 +3010,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
 
     @Override
     public boolean isAboveShelf() {
-        return isAmbientPulsing() || (!isOnKeyguard()
+        return showingAmbientPulsing() || (!isOnKeyguard()
                 && (mIsPinned || mHeadsupDisappearRunning || (mIsHeadsUp && mAboveShelf)
                 || mExpandAnimationRunning || mChildIsExpanding));
     }
@@ -3162,6 +3167,10 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
         }
     }
 
+    public void setAmbientGoingAway(boolean goingAway) {
+        mAmbientGoingAway = goingAway;
+    }
+
     @VisibleForTesting
     protected void setChildrenContainer(NotificationChildrenContainer childrenContainer) {
         mChildrenContainer = childrenContainer;
index 29a9989..cac41da 100644 (file)
@@ -527,7 +527,7 @@ public abstract class ExpandableView extends FrameLayout implements Dumpable {
     public void setHeadsUpIsVisible() {
     }
 
-    public boolean isAmbientPulsing() {
+    public boolean showingAmbientPulsing() {
         return false;
     }
 
index 96e9a4e..53ac504 100644 (file)
@@ -185,10 +185,11 @@ public class AmbientState {
 
     /** Dark ratio of the status bar **/
     public void setDarkAmount(float darkAmount) {
-        mDarkAmount = darkAmount;
-        if (darkAmount == 1.0f) {
+        if (darkAmount == 1.0f && mDarkAmount != darkAmount) {
+            // Whenever we are fully dark, let's reset the pulseHeight again
             mPulseHeight = MAX_PULSE_HEIGHT;
         }
+        mDarkAmount = darkAmount;
     }
 
     /** Returns the dark ratio of the status bar */
@@ -307,7 +308,7 @@ public class AmbientState {
     }
 
     public boolean isPulseExpanding() {
-        return mPulseHeight != MAX_PULSE_HEIGHT && mDarkAmount != 1.0f;
+        return mPulseHeight != MAX_PULSE_HEIGHT && mDozeAmount != 0.0f && mDarkAmount != 1.0f;
     }
 
     public boolean isShadeExpanded() {
@@ -453,19 +454,6 @@ public class AmbientState {
     }
 
     /**
-     * Similar to the normal is above shelf logic but doesn't allow it to be above in AOD1.
-     *
-     * @param expandableView the view to check
-     */
-    public boolean isAboveShelf(ExpandableView expandableView) {
-        if (!(expandableView instanceof ExpandableNotificationRow)) {
-            return expandableView.isAboveShelf();
-        }
-        ExpandableNotificationRow row = (ExpandableNotificationRow) expandableView;
-        return row.isAboveShelf() && !isDozingAndNotPulsing(row);
-    }
-
-    /**
      * @return whether a view is dozing and not pulsing right now
      */
     public boolean isDozingAndNotPulsing(ExpandableView view) {
@@ -524,7 +512,7 @@ public class AmbientState {
     public void setDozeAmount(float dozeAmount) {
         if (dozeAmount != mDozeAmount) {
             mDozeAmount = dozeAmount;
-            if (dozeAmount == 1.0f) {
+            if (dozeAmount == 0.0f || dozeAmount == 1.0f) {
                 // We woke all the way up, let's reset the pulse height
                 mPulseHeight = MAX_PULSE_HEIGHT;
             }
index 8455322..599998d 100644 (file)
@@ -253,7 +253,7 @@ class NotificationSection {
                 newTop = (int) Math.ceil(firstView.getTranslationY());
             }
             top = Math.max(newTop, top);
-            if (firstView.isAmbientPulsing()) {
+            if (firstView.showingAmbientPulsing()) {
                 // If we're pulsing, the notification can actually go below!
                 bottom = Math.max(bottom, finalTranslationY
                         + ExpandableViewState.getFinalActualHeight(firstView));
index 09768ec..be34cfd 100644 (file)
@@ -1372,7 +1372,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd
     private boolean isHeadsUpTransition() {
         NotificationSection firstVisibleSection = getFirstVisibleSection();
         return mTrackingHeadsUp && firstVisibleSection != null
-                && mAmbientState.isAboveShelf(firstVisibleSection.getFirstVisibleChild());
+                && firstVisibleSection.getFirstVisibleChild().isAboveShelf();
     }
 
     /**
@@ -5635,6 +5635,34 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd
         requestChildrenUpdate();
     }
 
+    public void wakeUpFromPulse() {
+        setPulseHeight(getWakeUpHeight());
+        // Let's place the hidden views at the end of the pulsing notification to make sure we have
+        // a smooth animation
+        boolean firstVisibleView = true;
+        float wakeUplocation = -1f;
+        int childCount = getChildCount();
+        for (int i = 0; i < childCount; i++) {
+            ExpandableView view = (ExpandableView) getChildAt(i);
+            if (view.getVisibility() == View.GONE) {
+                continue;
+            }
+            boolean isShelf = view == mShelf;
+            if (!(view instanceof ExpandableNotificationRow) && !isShelf) {
+                continue;
+            }
+            if (view.getVisibility() == View.VISIBLE && !isShelf) {
+                if (firstVisibleView) {
+                    firstVisibleView = false;
+                    wakeUplocation = view.getTranslationY()
+                            + view.getActualHeight() - mShelf.getIntrinsicHeight();
+                }
+            } else if (!firstVisibleView) {
+                view.setTranslationY(wakeUplocation);
+            }
+        }
+    }
+
     /**
      * A listener that is notified when the empty space below the notifications is clicked on
      */
index 0f3cccc..f97a7e6 100644 (file)
@@ -487,7 +487,7 @@ public class StackScrollAlgorithm {
                 continue;
             }
             ExpandableNotificationRow row = (ExpandableNotificationRow) child;
-            if (!row.isAmbientPulsing() || (i == 0 && ambientState.isPulseExpanding())) {
+            if (!row.showingAmbientPulsing() || (i == 0 && ambientState.isPulseExpanding())) {
                 continue;
             }
             ExpandableViewState viewState = row.getViewState();
@@ -519,7 +519,7 @@ public class StackScrollAlgorithm {
                 if (row.mustStayOnScreen() && !childState.headsUpIsVisible) {
                     // Ensure that the heads up is always visible even when scrolled off
                     clampHunToTop(ambientState, row, childState);
-                    if (i == 0 && ambientState.isAboveShelf(row)) {
+                    if (i == 0 && row.isAboveShelf()) {
                         // the first hun can't get off screen.
                         clampHunToMaxTranslation(ambientState, row, childState);
                         childState.hidden = false;
@@ -653,7 +653,7 @@ public class StackScrollAlgorithm {
             }
             childViewState.zTranslation = baseZ
                     + childrenOnTop * zDistanceBetweenElements;
-        } else if (i == 0 && ambientState.isAboveShelf(child)) {
+        } else if (i == 0 && child.isAboveShelf()) {
             // In case this is a new view that has never been measured before, we don't want to
             // elevate if we are currently expanded more then the notification
             int shelfHeight = ambientState.getShelf() == null ? 0 :
index dfc5c86..d18b419 100644 (file)
@@ -3594,6 +3594,7 @@ public class StatusBar extends SystemUI implements DemoMode,
         @Override
         public void onStartedWakingUp() {
             mDeviceInteractive = true;
+            mWakeUpCoordinator.setWakingUp(true);
             mAmbientPulseManager.releaseAllImmediately();
             mVisualStabilityManager.setScreenOn(true);
             updateNotificationPanelTouchState();
@@ -3602,6 +3603,11 @@ public class StatusBar extends SystemUI implements DemoMode,
             mDozeServiceHost.stopDozing();
             mPulseExpansionHandler.onStartedWakingUp();
         }
+
+        @Override
+        public void onFinishedWakingUp() {
+            mWakeUpCoordinator.setWakingUp(false);
+        }
     };
 
     /**
@@ -3904,7 +3910,6 @@ public class StatusBar extends SystemUI implements DemoMode,
                     }
                     updateScrimController();
                     mPulseExpansionHandler.setPulsing(pulsing);
-                    mWakeUpCoordinator.setPulsing(pulsing);
                 }
             }, reason);
             // DozeScrimController is in pulse state, now let's ask ScrimController to start