Fix user switcher ripple emanation point

Bug: 18444431
Change-Id: I35b053b151ba1e6e326d3a6c2bd2c3c8e3ad8c28
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSDetailClipper.java b/packages/SystemUI/src/com/android/systemui/qs/QSDetailClipper.java
index 111484b..a318efc 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSDetailClipper.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSDetailClipper.java
@@ -42,14 +42,21 @@
         }
         final int w = mDetail.getWidth() - x;
         final int h = mDetail.getHeight() - y;
+        int innerR = 0;
+        if (x < 0 || w < 0 || y < 0 || h < 0) {
+            innerR = Math.abs(x);
+            innerR = Math.min(innerR, Math.abs(y));
+            innerR = Math.min(innerR, Math.abs(w));
+            innerR = Math.min(innerR, Math.abs(h));
+        }
         int r = (int) Math.ceil(Math.sqrt(x * x + y * y));
         r = (int) Math.max(r, Math.ceil(Math.sqrt(w * w + y * y)));
         r = (int) Math.max(r, Math.ceil(Math.sqrt(w * w + h * h)));
         r = (int) Math.max(r, Math.ceil(Math.sqrt(x * x + h * h)));
         if (in) {
-            mAnimator = ViewAnimationUtils.createCircularReveal(mDetail, x, y, 0, r);
+            mAnimator = ViewAnimationUtils.createCircularReveal(mDetail, x, y, innerR, r);
         } else {
-            mAnimator = ViewAnimationUtils.createCircularReveal(mDetail, x, y, r, 0);
+            mAnimator = ViewAnimationUtils.createCircularReveal(mDetail, x, y, r, innerR);
         }
         mAnimator.setDuration((long)(mAnimator.getDuration() * 1.5));
         if (listener != null) {
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
index b4ae20d..cd4f299 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
@@ -215,9 +215,19 @@
         mFooter.refreshState();
     }
 
-    public void showDetailAdapter(boolean show, DetailAdapter adapter) {
+    public void showDetailAdapter(boolean show, DetailAdapter adapter, int[] locationInWindow) {
+        int xInWindow = locationInWindow[0];
+        int yInWindow = locationInWindow[1];
+        mDetail.getLocationInWindow(locationInWindow);
+
         Record r = new Record();
         r.detailAdapter = adapter;
+        r.x = xInWindow - locationInWindow[0];
+        r.y = yInWindow - locationInWindow[1];
+
+        locationInWindow[0] = xInWindow;
+        locationInWindow[1] = yInWindow;
+
         showDetail(show, r);
     }
 
@@ -337,7 +347,13 @@
         if (r instanceof TileRecord) {
             handleShowDetailTile((TileRecord) r, show);
         } else {
-            handleShowDetailImpl(r, show, getWidth() /* x */, 0/* y */);
+            int x = 0;
+            int y = 0;
+            if (r != null) {
+                x = r.x;
+                y = r.y;
+            }
+            handleShowDetailImpl(r, show, x, y);
         }
     }
 
@@ -558,6 +574,8 @@
     private static class Record {
         View detailView;
         DetailAdapter detailAdapter;
+        int x;
+        int y;
     }
 
     protected static final class TileRecord extends Record {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/MultiUserSwitch.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/MultiUserSwitch.java
index 82f5a9e..f11d83c 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/MultiUserSwitch.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/MultiUserSwitch.java
@@ -42,6 +42,8 @@
     private boolean mKeyguardMode;
     final UserManager mUserManager;
 
+    private final int[] mTmpInt2 = new int[2];
+
     public MultiUserSwitch(Context context, AttributeSet attrs) {
         super(context, attrs);
         mUserManager = UserManager.get(getContext());
@@ -77,7 +79,15 @@
                     UserSwitcherController userSwitcherController =
                             mQsPanel.getHost().getUserSwitcherController();
                     if (userSwitcherController != null) {
-                        mQsPanel.showDetailAdapter(true, userSwitcherController.userDetailAdapter);
+                        View center = getChildCount() > 0 ? getChildAt(0) : this;
+
+                        center.getLocationInWindow(mTmpInt2);
+                        mTmpInt2[0] += center.getWidth() / 2;
+                        mTmpInt2[1] += center.getHeight() / 2;
+
+                        mQsPanel.showDetailAdapter(true,
+                                userSwitcherController.userDetailAdapter,
+                                mTmpInt2);
                     }
                 }
             }