Fix PanelView over expanding behavior.

Fixes a bug that the panel height was wrongly calculated and lagging
one frame behind. Also fixes the animation when overscrolling and
then flinging the panel to collapse. In addition, the logic to handle
the over expanding is much cleaner and calculated in an absolut
manner (before, it was relative an really complicated to understand).

Bug: 14487435
Change-Id: If8dbb3e063ef63f51f6dac0ae5bf276480514103
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 7926d03..34179cb 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
@@ -48,7 +48,6 @@
         View.OnClickListener, NotificationStackScrollLayout.OnOverscrollTopChangedListener,
         KeyguardPageSwipeHelper.Callback {
 
-    private static final float EXPANSION_RUBBER_BAND_EXTRA_FACTOR = 0.6f;
     private static final float LOCK_ICON_ACTIVE_SCALE = 1.2f;
 
     private KeyguardPageSwipeHelper mPageSwiper;
@@ -719,6 +718,16 @@
         updateUnlockIcon();
     }
 
+    @Override
+    protected float getOverExpansionAmount() {
+        return mNotificationStackScroller.getCurrentOverScrollAmount(true /* top */);
+    }
+
+    @Override
+    protected float getOverExpansionPixels() {
+        return mNotificationStackScroller.getCurrentOverScrolledPixels(true /* top */);
+    }
+
     private void updateUnlockIcon() {
         if (mStatusBar.getBarState() == StatusBarState.KEYGUARD
                 || mStatusBar.getBarState() == StatusBarState.SHADE_LOCKED) {
@@ -805,14 +814,17 @@
     }
 
     @Override
-    protected void onOverExpansionChanged(float overExpansion) {
+    protected void setOverExpansion(float overExpansion, boolean isPixels) {
         if (mStatusBar.getBarState() != StatusBarState.KEYGUARD) {
-            float currentOverScroll = mNotificationStackScroller.getCurrentOverScrolledPixels(true);
-            float expansionChange = overExpansion - mOverExpansion;
-            expansionChange *= EXPANSION_RUBBER_BAND_EXTRA_FACTOR;
-            mNotificationStackScroller.setOverScrolledPixels(currentOverScroll + expansionChange,
-                    true /* onTop */,
-                    false /* animate */);
+            mNotificationStackScroller.setOnHeightChangedListener(null);
+            if (isPixels) {
+                mNotificationStackScroller.setOverScrolledPixels(
+                        overExpansion, true /* onTop */, false /* animate */);
+            } else {
+                mNotificationStackScroller.setOverScrollAmount(
+                        overExpansion, true /* onTop */, false /* animate */);
+            }
+            mNotificationStackScroller.setOnHeightChangedListener(this);
         }
     }
 
@@ -828,7 +840,10 @@
     @Override
     protected void onTrackingStopped(boolean expand) {
         super.onTrackingStopped(expand);
-        mNotificationStackScroller.setOverScrolledPixels(0.0f, true /* onTop */, true /* animate */);
+        if (expand) {
+            mNotificationStackScroller.setOverScrolledPixels(
+                    0.0f, true /* onTop */, true /* animate */);
+        }
         if (expand && (mStatusBar.getBarState() == StatusBarState.KEYGUARD
                 || mStatusBar.getBarState() == StatusBarState.SHADE_LOCKED)) {
             mPageSwiper.showAllIcons(true);