Fix animation of notification handle bar when panel changes height

The notification panel uses LayoutTransition to animate changes to
the list of notifications. This works for the items themselves as
items are added or removed; the new/old items animate in/out and the
existing items animate to make or remove space.

But the handle at the bottom of the list (the gray translucent line) does
not play well with these changes. For example, when an item is swiped away
the handle snaps into its new location before the rest of the items have
finished animating.

The problem comes from a constraint of LayoutTransition; it handles changes
to the container it operates on, and to the parent hierarchy all the way up
to the root. However, it cannot animate changes to siblings of the parents.
So when the list resizes due to item changes, the handle (which is in a sibling
of the list) does not animate this change, but just reacts instantly.

The fix is to draw the handle not as a view itself, but rather as part of the
parent container of the list. So as the list animates a resize, the container will
also animate, and any graphics in the container will animate along with it.
No matter what size the container of the list is, the line will be drawn at
the bottom of it.

Issue #7024902 Notification panel animation incorrect when swiping notification out

Change-Id: Ifc412cb6bcdc6ead35993b0320364a2a95a16e11
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 13a34ad..9c978d5 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
@@ -17,11 +17,23 @@
 package com.android.systemui.statusbar.phone;
 
 import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Canvas;
+import android.graphics.drawable.Drawable;
 import android.util.AttributeSet;
+import com.android.systemui.R;
 
 public class NotificationPanelView extends PanelView {
+
+    Drawable mHandleBar;
+    float mHandleBarHeight;
+
     public NotificationPanelView(Context context, AttributeSet attrs) {
         super(context, attrs);
+
+        Resources resources = context.getResources();
+        mHandleBar = resources.getDrawable(R.drawable.status_bar_close);
+        mHandleBarHeight = resources.getDimension(R.dimen.close_handle_height);
     }
 
     @Override
@@ -31,4 +43,20 @@
             "notifications,v=" + vel);
         super.fling(vel, always);
     }
+
+    @Override
+    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+        super.onLayout(changed, left, top, right, bottom);
+        if (changed) {
+            mHandleBar.setBounds(0, 0, getWidth(), (int) mHandleBarHeight);
+        }
+    }
+
+    @Override
+    public void draw(Canvas canvas) {
+        super.draw(canvas);
+        canvas.translate(0, getHeight() - mHandleBarHeight);
+        mHandleBar.draw(canvas);
+        canvas.translate(0, -getHeight() + mHandleBarHeight);
+    }
 }