Keep a mirror of the system icons while expanding the panel

Because the icons are shown in two different places at the same time
(in the QS header and the status bar), we introduce a mirror view
which does nothing except draw the contents of the other view to
draw it at both locations during the animation.

Bug: 15407838
Change-Id: I82edc8b4fb7347fa8dadfb81762d22796d37fa3c
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 cec7592..30d6e9f 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
@@ -38,6 +38,7 @@
 import com.android.systemui.statusbar.ExpandableView;
 import com.android.systemui.statusbar.FlingAnimationUtils;
 import com.android.systemui.statusbar.GestureRecorder;
+import com.android.systemui.statusbar.MirrorView;
 import com.android.systemui.statusbar.StatusBarState;
 import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
 import com.android.systemui.statusbar.stack.StackStateAnimator;
@@ -64,6 +65,8 @@
     private ObservableScrollView mScrollView;
     private TextView mClockView;
 
+    private MirrorView mSystemIconsCopy;
+
     private NotificationStackScrollLayout mNotificationStackScroller;
     private int mNotificationTopPadding;
     private boolean mAnimateNextTopPaddingChange;
@@ -118,6 +121,7 @@
 
     public NotificationPanelView(Context context, AttributeSet attrs) {
         super(context, attrs);
+        mSystemIconsCopy = new MirrorView(context);
     }
 
     public void setStatusBar(PhoneStatusBar bar) {
@@ -692,14 +696,22 @@
             return;
         }
         LinearLayout systemIcons = mStatusBar.getSystemIcons();
-        if (systemIcons.getParent() != null) {
-            ((ViewGroup) systemIcons.getParent()).removeView(systemIcons);
-        }
+        ViewGroup parent = ((ViewGroup) systemIcons.getParent());
         if (toHeader) {
+            int index = parent.indexOfChild(systemIcons);
+            parent.removeView(systemIcons);
+            mSystemIconsCopy.setMirroredView(
+                    systemIcons, systemIcons.getWidth(), systemIcons.getHeight());
+            parent.addView(mSystemIconsCopy, index);
             mHeader.attachSystemIcons(systemIcons);
         } else {
+            ViewGroup newParent = mStatusBar.getSystemIconArea();
+            int index = newParent.indexOfChild(mSystemIconsCopy);
+            parent.removeView(systemIcons);
             mHeader.onSystemIconsDetached();
-            mStatusBar.reattachSystemIcons();
+            mSystemIconsCopy.setMirroredView(null, 0, 0);
+            newParent.removeView(mSystemIconsCopy);
+            newParent.addView(systemIcons, index);
         }
     }