Launch quick contacts after selecting frequent contact on tablet

- Previously clicking on a frequently contacted person
would request the contact detail fragment to load that contact,
but the app wouldn't switch tabs or update the selected contact
in the contact list.

- Pass the Rect of the target view to the listener to launch quick
contacts

Bug: 5236515
Change-Id: Ic2d888ed02f8fd2b5a47d49f99cc96755bf55d37
diff --git a/src/com/android/contacts/ContactsUtils.java b/src/com/android/contacts/ContactsUtils.java
index 64dfaef..cb19713 100644
--- a/src/com/android/contacts/ContactsUtils.java
+++ b/src/com/android/contacts/ContactsUtils.java
@@ -24,6 +24,7 @@
 
 import android.content.Context;
 import android.content.Intent;
+import android.graphics.Rect;
 import android.location.CountryDetector;
 import android.net.Uri;
 import android.provider.ContactsContract;
@@ -221,4 +222,22 @@
         textView.setText(context.getString(textResourceId));
         return view;
     }
+
+    /**
+     * Returns the {@link Rect} with left, top, right, and bottom coordinates
+     * that are equivalent to the given {@link View}'s bounds. This is equivalent to how the
+     * target {@link Rect} is calculated in {@link QuickContact#showQuickContact}.
+     */
+    public static Rect getTargetRectFromView(Context context, View view) {
+        final float appScale = context.getResources().getCompatibilityInfo().applicationScale;
+        final int[] pos = new int[2];
+        view.getLocationOnScreen(pos);
+
+        final Rect rect = new Rect();
+        rect.left = (int) (pos[0] * appScale + 0.5f);
+        rect.top = (int) (pos[1] * appScale + 0.5f);
+        rect.right = (int) ((pos[0] + view.getWidth()) * appScale + 0.5f);
+        rect.bottom = (int) ((pos[1] + view.getHeight()) * appScale + 0.5f);
+        return rect;
+    }
 }