Fixed bugs in the stack scroller

- A hole could occur when collapsing and expanding in the same touch
- The second card was not correctly resized if the stack was scrolled

Bug: 15996450
Change-Id: Ie779ed5d63b8c55d490c459955bafbc583bfce97
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 4086022..641dea3 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java
@@ -1800,14 +1800,14 @@
     public void onExpansionStopped() {
         mIsExpansionChanging = false;
         mStackScrollAlgorithm.onExpansionStopped();
+        if (!mIsExpanded) {
+            mOwnScrollY = 0;
+        }
     }
 
     private void setIsExpanded(boolean isExpanded) {
         mIsExpanded = isExpanded;
         mStackScrollAlgorithm.setIsExpanded(isExpanded);
-        if (!isExpanded) {
-            mOwnScrollY = 0;
-        }
     }
 
     @Override
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackScrollAlgorithm.java b/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackScrollAlgorithm.java
index 7c522d3..65019af 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackScrollAlgorithm.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackScrollAlgorithm.java
@@ -399,6 +399,10 @@
             if (i == 0) {
                 childViewState.alpha = 1.0f;
                 childViewState.yTranslation = Math.max(mCollapsedSize - algorithmState.scrollY, 0);
+                if (childViewState.yTranslation + childViewState.height > bottomPeekStart) {
+                    childViewState.height = (int) Math.max(
+                            bottomPeekStart - childViewState.yTranslation, mCollapsedSize);
+                }
                 childViewState.location = StackScrollState.ViewState.LOCATION_FIRST_CARD;
             }
             if (childViewState.location == StackScrollState.ViewState.LOCATION_UNKNOWN) {