Handling a few more border cases with HUNs

Also does sorting correctly now.
The status bar now allows touches below when a
heads-up is on.
Also fixes a few flashes when a heads up was
dismissed or appeared.

Change-Id: I4d90a07333ad2e5ea2a13704cdc9d9184716681a
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 6fe609e..eacc436 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
@@ -510,9 +510,6 @@
 
     @Override
     protected void flingToHeight(float vel, boolean expand, float target) {
-        if (!expand && mHeadsUpManager.hasPinnedHeadsUp()) {
-            target = mHeadsUpManager.getHighestPinnedHeadsUp();
-        }
         mHeadsUpTouchHelper.notifyFling(!expand);
         super.flingToHeight(vel, expand, target);
     }
@@ -722,7 +719,7 @@
                 || event.getActionMasked() == MotionEvent.ACTION_UP) {
             mConflictingQsExpansionGesture = false;
         }
-        if (event.getActionMasked() == MotionEvent.ACTION_DOWN && mExpandedHeight == 0
+        if (event.getActionMasked() == MotionEvent.ACTION_DOWN && isShadeCollapsed()
                 && mQsExpansionEnabled) {
             mTwoFingerQsExpandPossible = true;
         }
@@ -1774,7 +1771,7 @@
     }
 
     private void updateMaxHeadsUpTranslation() {
-        mNotificationStackScroller.setMaxHeadsUpTranslation(getHeight() - mBottomBarHeight);
+        mNotificationStackScroller.setHeadsUpBoundaries(getHeight(), mBottomBarHeight);
     }
 
     @Override
@@ -2151,16 +2148,12 @@
 
     @Override
     public void OnHeadsUpStateChanged(NotificationData.Entry entry, boolean isHeadsUp) {
-        // TODO: figure out the conditions when not to generate an animation
         mNotificationStackScroller.generateHeadsUpAnimation(entry.row, isHeadsUp);
-        if (isShadeCollapsed()) {
-            setExpandedHeight(mHeadsUpManager.getHighestPinnedHeadsUp());
-        }
     }
 
-    private boolean isShadeCollapsed() {
-        // TODO: handle this cleaner
-        return mHeader.getTranslationY() + mHeader.getCollapsedHeight() <= 0;
+    @Override
+    protected boolean isShadeCollapsed() {
+        return mExpandedHeight == 0 || mHeadsUpManager.hasPinnedHeadsUp();
     }
 
     @Override