diff options
author | Winson Chung <winsonc@google.com> | 2012-09-28 11:37:41 -0700 |
---|---|---|
committer | Winson Chung <winsonc@google.com> | 2012-09-28 11:37:46 -0700 |
commit | 9fc6b8c5b78556d571bfaa9aa0a6a5cc499b2a01 (patch) | |
tree | eefe37e28fd305b75247692f9a95024d5936d775 /core/java/android/provider | |
parent | 8c832e9f766edfc6130c3eea30e1869e2db8de26 (diff) | |
download | frameworks_base-9fc6b8c5b78556d571bfaa9aa0a6a5cc499b2a01.zip frameworks_base-9fc6b8c5b78556d571bfaa9aa0a6a5cc499b2a01.tar.gz frameworks_base-9fc6b8c5b78556d571bfaa9aa0a6a5cc499b2a01.tar.bz2 |
Fixing crash in QuickContacts. (Bug 7252771)
Change-Id: Ibf304a4c2115f557e0408e345c7714d248fcd35d
Diffstat (limited to 'core/java/android/provider')
-rwxr-xr-x | core/java/android/provider/ContactsContract.java | 86 |
1 files changed, 54 insertions, 32 deletions
diff --git a/core/java/android/provider/ContactsContract.java b/core/java/android/provider/ContactsContract.java index b3ab385..5b49ba3 100755 --- a/core/java/android/provider/ContactsContract.java +++ b/core/java/android/provider/ContactsContract.java @@ -7659,6 +7659,54 @@ public final class ContactsContract { public static final int MODE_LARGE = 3; /** + * Constructs the QuickContacts intent with a view's rect. + * @hide + */ + public static Intent composeQuickContactsIntent(Context context, View target, Uri lookupUri, + int mode, String[] excludeMimes) { + // Find location and bounds of target view, adjusting based on the + // assumed local density. + final float appScale = context.getResources().getCompatibilityInfo().applicationScale; + final int[] pos = new int[2]; + target.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] + target.getWidth()) * appScale + 0.5f); + rect.bottom = (int) ((pos[1] + target.getHeight()) * appScale + 0.5f); + + return composeQuickContactsIntent(context, rect, lookupUri, mode, excludeMimes); + } + + /** + * Constructs the QuickContacts intent. + * @hide + */ + public static Intent composeQuickContactsIntent(Context context, Rect target, + Uri lookupUri, int mode, String[] excludeMimes) { + // When launching from an Activiy, we don't want to start a new task, but otherwise + // we *must* start a new task. (Otherwise startActivity() would crash.) + Context actualContext = context; + while ((actualContext instanceof ContextWrapper) + && !(actualContext instanceof Activity)) { + actualContext = ((ContextWrapper) actualContext).getBaseContext(); + } + final int intentFlags = (actualContext instanceof Activity) + ? Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET + : Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK; + + // Launch pivot dialog through intent for now + final Intent intent = new Intent(ACTION_QUICK_CONTACT).addFlags(intentFlags); + + intent.setData(lookupUri); + intent.setSourceBounds(target); + intent.putExtra(EXTRA_MODE, mode); + intent.putExtra(EXTRA_EXCLUDE_MIMES, excludeMimes); + return intent; + } + + /** * Trigger a dialog that lists the various methods of interacting with * the requested {@link Contacts} entry. This may be based on available * {@link ContactsContract.Data} rows under that contact, and may also @@ -7683,20 +7731,10 @@ public final class ContactsContract { */ public static void showQuickContact(Context context, View target, Uri lookupUri, int mode, String[] excludeMimes) { - // Find location and bounds of target view, adjusting based on the - // assumed local density. - final float appScale = context.getResources().getCompatibilityInfo().applicationScale; - final int[] pos = new int[2]; - target.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] + target.getWidth()) * appScale + 0.5f); - rect.bottom = (int) ((pos[1] + target.getHeight()) * appScale + 0.5f); - // Trigger with obtained rectangle - showQuickContact(context, rect, lookupUri, mode, excludeMimes); + Intent intent = composeQuickContactsIntent(context, target, lookupUri, mode, + excludeMimes); + context.startActivity(intent); } /** @@ -7727,25 +7765,9 @@ public final class ContactsContract { */ public static void showQuickContact(Context context, Rect target, Uri lookupUri, int mode, String[] excludeMimes) { - // When launching from an Activiy, we don't want to start a new task, but otherwise - // we *must* start a new task. (Otherwise startActivity() would crash.) - Context actualContext = context; - while ((actualContext instanceof ContextWrapper) - && !(actualContext instanceof Activity)) { - actualContext = ((ContextWrapper) actualContext).getBaseContext(); - } - final int intentFlags = (actualContext instanceof Activity) - ? Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET - : Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK; - - // Launch pivot dialog through intent for now - final Intent intent = new Intent(ACTION_QUICK_CONTACT).addFlags(intentFlags); - - intent.setData(lookupUri); - intent.setSourceBounds(target); - intent.putExtra(EXTRA_MODE, mode); - intent.putExtra(EXTRA_EXCLUDE_MIMES, excludeMimes); - context.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT)); + Intent intent = composeQuickContactsIntent(context, target, lookupUri, mode, + excludeMimes); + context.startActivity(intent); } } |