Clean up speedbump handling when going to SHADE_LOCKED

Bug: 16291973
Change-Id: Ibaa127709ff7a1a001402bd958016998e2bd23bf
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/SpeedBumpView.java b/packages/SystemUI/src/com/android/systemui/statusbar/SpeedBumpView.java
index d8d964e..816612b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/SpeedBumpView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/SpeedBumpView.java
@@ -76,23 +76,25 @@
         return true;
     }
 
-    public void performVisibilityAnimation(boolean nowVisible) {
-        animateDivider(nowVisible, null /* onFinishedRunnable */);
+    public void performVisibilityAnimation(boolean nowVisible, long delay) {
+        animateDivider(nowVisible, delay, null /* onFinishedRunnable */);
     }
 
     /**
      * Animate the divider to a new visibility.
      *
      * @param nowVisible should it now be visible
+     * @param delay the delay after the animation should start
      * @param onFinishedRunnable A runnable which should be run when the animation is
      *        finished.
      */
-    public void animateDivider(boolean nowVisible, Runnable onFinishedRunnable) {
+    public void animateDivider(boolean nowVisible, long delay, Runnable onFinishedRunnable) {
         if (nowVisible != mIsVisible) {
             // Animate dividers
             float endValue = nowVisible ? 1.0f : 0.0f;
             mLine.animate()
                     .alpha(endValue)
+                    .setStartDelay(delay)
                     .scaleX(endValue)
                     .scaleY(endValue)
                     .setInterpolator(mFastOutSlowInInterpolator)
@@ -116,13 +118,13 @@
     public void performRemoveAnimation(long duration, float translationDirection,
             Runnable onFinishedRunnable) {
         // TODO: Use duration
-        performVisibilityAnimation(false);
+        performVisibilityAnimation(false, 0 /* delay */);
     }
 
     @Override
     public void performAddAnimation(long delay, long duration) {
-        // TODO: Use delay and duration
-        performVisibilityAnimation(true);
+        // TODO: Use duration
+        performVisibilityAnimation(true, delay);
     }
 
     @Override
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java
index 1401082..aa41b9c 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java
@@ -1932,10 +1932,8 @@
             if (visible) {
                 // Make invisible to ensure that the appear animation is played.
                 mSpeedBumpView.setInvisible();
-                if (!mIsExpansionChanging) {
-                    generateAddAnimation(mSpeedBumpView);
-                }
             } else {
+                // TODO: This doesn't really work, because the view is already set to GONE above.
                 generateRemoveAnimation(mSpeedBumpView);
             }
         }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackScrollState.java b/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackScrollState.java
index 7b90a351..d0064c8 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackScrollState.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackScrollState.java
@@ -171,8 +171,7 @@
                 updateChildClip(child, newHeight, state.topOverLap);
 
                 if(child instanceof SpeedBumpView) {
-                    float lineEnd = newYTranslation + newHeight / 2;
-                    performSpeedBumpAnimation(i, (SpeedBumpView) child, lineEnd);
+                    performSpeedBumpAnimation(i, (SpeedBumpView) child, state, 0);
                 } else if (child instanceof DismissView) {
                     DismissView dismissView = (DismissView) child;
                     boolean visible = state.topOverLap < mClearAllTopPadding;
@@ -197,12 +196,14 @@
         child.setClipBounds(mClipRect);
     }
 
-    private void performSpeedBumpAnimation(int i, SpeedBumpView speedBump, float speedBumpEnd) {
+    public void performSpeedBumpAnimation(int i, SpeedBumpView speedBump, ViewState state,
+            long delay) {
         View nextChild = getNextChildNotGone(i);
         if (nextChild != null) {
+            float lineEnd = state.yTranslation + state.height / 2;
             ViewState nextState = getViewStateForView(nextChild);
-            boolean startIsAboveNext = nextState.yTranslation > speedBumpEnd;
-            speedBump.animateDivider(startIsAboveNext, null /* onFinishedRunnable */);
+            boolean startIsAboveNext = nextState.yTranslation > lineEnd;
+            speedBump.animateDivider(startIsAboveNext, delay, null /* onFinishedRunnable */);
         }
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackStateAnimator.java b/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackStateAnimator.java
index fddd3d6..edc669e 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackStateAnimator.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackStateAnimator.java
@@ -27,6 +27,7 @@
 
 import com.android.systemui.R;
 import com.android.systemui.statusbar.ExpandableView;
+import com.android.systemui.statusbar.SpeedBumpView;
 
 import java.util.ArrayList;
 import java.util.HashSet;
@@ -115,7 +116,7 @@
             }
 
             child.setClipBounds(null);
-            startAnimations(child, viewState, finalState);
+            startAnimations(child, viewState, finalState, i);
         }
         if (!isRunning()) {
             // no child has preformed any animation, lets finish
@@ -145,7 +146,7 @@
      * Start an animation to the given viewState
      */
     private void startAnimations(final ExpandableView child, StackScrollState.ViewState viewState,
-            StackScrollState finalState) {
+            StackScrollState finalState, int i) {
         int childVisibility = child.getVisibility();
         boolean wasVisible = childVisibility == View.VISIBLE;
         final float alpha = viewState.alpha;
@@ -223,6 +224,10 @@
         if (wasAdded) {
             child.performAddAnimation(delay, mCurrentLength);
         }
+        if (child instanceof SpeedBumpView) {
+            finalState.performSpeedBumpAnimation(i, (SpeedBumpView) child, viewState,
+                    delay + duration);
+        }
     }
 
     private long calculateChildAnimationDelay(StackScrollState.ViewState viewState,