@@ -7658,6 +7658,54 @@ public static final class QuickContact {
76587658 */
76597659 public static final int MODE_LARGE = 3 ;
76607660
7661+ /**
7662+ * Constructs the QuickContacts intent with a view's rect.
7663+ * @hide
7664+ */
7665+ public static Intent composeQuickContactsIntent (Context context , View target , Uri lookupUri ,
7666+ int mode , String [] excludeMimes ) {
7667+ // Find location and bounds of target view, adjusting based on the
7668+ // assumed local density.
7669+ final float appScale = context .getResources ().getCompatibilityInfo ().applicationScale ;
7670+ final int [] pos = new int [2 ];
7671+ target .getLocationOnScreen (pos );
7672+
7673+ final Rect rect = new Rect ();
7674+ rect .left = (int ) (pos [0 ] * appScale + 0.5f );
7675+ rect .top = (int ) (pos [1 ] * appScale + 0.5f );
7676+ rect .right = (int ) ((pos [0 ] + target .getWidth ()) * appScale + 0.5f );
7677+ rect .bottom = (int ) ((pos [1 ] + target .getHeight ()) * appScale + 0.5f );
7678+
7679+ return composeQuickContactsIntent (context , rect , lookupUri , mode , excludeMimes );
7680+ }
7681+
7682+ /**
7683+ * Constructs the QuickContacts intent.
7684+ * @hide
7685+ */
7686+ public static Intent composeQuickContactsIntent (Context context , Rect target ,
7687+ Uri lookupUri , int mode , String [] excludeMimes ) {
7688+ // When launching from an Activiy, we don't want to start a new task, but otherwise
7689+ // we *must* start a new task. (Otherwise startActivity() would crash.)
7690+ Context actualContext = context ;
7691+ while ((actualContext instanceof ContextWrapper )
7692+ && !(actualContext instanceof Activity )) {
7693+ actualContext = ((ContextWrapper ) actualContext ).getBaseContext ();
7694+ }
7695+ final int intentFlags = (actualContext instanceof Activity )
7696+ ? Intent .FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
7697+ : Intent .FLAG_ACTIVITY_NEW_TASK | Intent .FLAG_ACTIVITY_CLEAR_TASK ;
7698+
7699+ // Launch pivot dialog through intent for now
7700+ final Intent intent = new Intent (ACTION_QUICK_CONTACT ).addFlags (intentFlags );
7701+
7702+ intent .setData (lookupUri );
7703+ intent .setSourceBounds (target );
7704+ intent .putExtra (EXTRA_MODE , mode );
7705+ intent .putExtra (EXTRA_EXCLUDE_MIMES , excludeMimes );
7706+ return intent ;
7707+ }
7708+
76617709 /**
76627710 * Trigger a dialog that lists the various methods of interacting with
76637711 * the requested {@link Contacts} entry. This may be based on available
@@ -7683,20 +7731,10 @@ public static final class QuickContact {
76837731 */
76847732 public static void showQuickContact (Context context , View target , Uri lookupUri , int mode ,
76857733 String [] excludeMimes ) {
7686- // Find location and bounds of target view, adjusting based on the
7687- // assumed local density.
7688- final float appScale = context .getResources ().getCompatibilityInfo ().applicationScale ;
7689- final int [] pos = new int [2 ];
7690- target .getLocationOnScreen (pos );
7691-
7692- final Rect rect = new Rect ();
7693- rect .left = (int ) (pos [0 ] * appScale + 0.5f );
7694- rect .top = (int ) (pos [1 ] * appScale + 0.5f );
7695- rect .right = (int ) ((pos [0 ] + target .getWidth ()) * appScale + 0.5f );
7696- rect .bottom = (int ) ((pos [1 ] + target .getHeight ()) * appScale + 0.5f );
7697-
76987734 // Trigger with obtained rectangle
7699- showQuickContact (context , rect , lookupUri , mode , excludeMimes );
7735+ Intent intent = composeQuickContactsIntent (context , target , lookupUri , mode ,
7736+ excludeMimes );
7737+ context .startActivity (intent );
77007738 }
77017739
77027740 /**
@@ -7727,25 +7765,9 @@ public static void showQuickContact(Context context, View target, Uri lookupUri,
77277765 */
77287766 public static void showQuickContact (Context context , Rect target , Uri lookupUri , int mode ,
77297767 String [] excludeMimes ) {
7730- // When launching from an Activiy, we don't want to start a new task, but otherwise
7731- // we *must* start a new task. (Otherwise startActivity() would crash.)
7732- Context actualContext = context ;
7733- while ((actualContext instanceof ContextWrapper )
7734- && !(actualContext instanceof Activity )) {
7735- actualContext = ((ContextWrapper ) actualContext ).getBaseContext ();
7736- }
7737- final int intentFlags = (actualContext instanceof Activity )
7738- ? Intent .FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
7739- : Intent .FLAG_ACTIVITY_NEW_TASK | Intent .FLAG_ACTIVITY_CLEAR_TASK ;
7740-
7741- // Launch pivot dialog through intent for now
7742- final Intent intent = new Intent (ACTION_QUICK_CONTACT ).addFlags (intentFlags );
7743-
7744- intent .setData (lookupUri );
7745- intent .setSourceBounds (target );
7746- intent .putExtra (EXTRA_MODE , mode );
7747- intent .putExtra (EXTRA_EXCLUDE_MIMES , excludeMimes );
7748- context .startActivityAsUser (intent , new UserHandle (UserHandle .USER_CURRENT ));
7768+ Intent intent = composeQuickContactsIntent (context , target , lookupUri , mode ,
7769+ excludeMimes );
7770+ context .startActivity (intent );
77497771 }
77507772 }
77517773
0 commit comments