Made sure that HUNS with full screen intents stay pinned

When a HUN came in with a full screen intent came in and the shade
was open, the notification was not pinned and therefore got lost
when the shade was closed, potentially leading to missed alarms
or calls.

Bug: 20431566
Change-Id: I0d5da0f9baba8d9f68ba2755c40c5fd9a8471191
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 de28ac7..081a9c5 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackScrollAlgorithm.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackScrollAlgorithm.java
@@ -311,8 +311,7 @@
                     StackViewState viewState = resultState.getViewStateForView(
                             nextChild);
                     // The child below the dragged one must be fully visible
-                    if (!NotificationStackScrollLayout.isPinnedHeadsUp(draggedView)
-                            || NotificationStackScrollLayout.isPinnedHeadsUp(nextChild)) {
+                    if (ambientState.isShadeExpanded()) {
                         viewState.alpha = 1;
                     }
                 }
@@ -508,8 +507,18 @@
             }
             StackViewState childState = resultState.getViewStateForView(row);
             boolean isTopEntry = topHeadsUpEntry == row;
+            if (mIsExpanded) {
+                if (isTopEntry) {
+                    childState.height += row.getHeadsUpHeight() - mCollapsedSize;
+                }
+                childState.height = Math.max(childState.height, row.getHeadsUpHeight());
+                // Ensure that the heads up is always visible even when scrolled off from the bottom
+                float bottomPosition = ambientState.getMaxHeadsUpTranslation() - childState.height;
+                childState.yTranslation = Math.min(childState.yTranslation,
+                        bottomPosition);
+            }
             if (row.isPinned()) {
-                childState.yTranslation = 0;
+                childState.yTranslation = Math.max(childState.yTranslation, 0);
                 childState.height = row.getHeadsUpHeight();
                 if (!isTopEntry) {
                     // Ensure that a headsUp doesn't vertically extend further than the heads-up at
@@ -519,15 +528,6 @@
                     childState.yTranslation = topState.yTranslation + topState.height
                             - childState.height;
                 }
-            } else if (mIsExpanded) {
-                if (isTopEntry) {
-                    childState.height += row.getHeadsUpHeight() - mCollapsedSize;
-                }
-                childState.height = Math.max(childState.height, row.getHeadsUpHeight());
-                // Ensure that the heads up is always visible even when scrolled of from the bottom
-                float bottomPosition = ambientState.getMaxHeadsUpTranslation() - childState.height;
-                childState.yTranslation = Math.min(childState.yTranslation,
-                        bottomPosition);
             }
         }
     }