diff options
author | Yorke Lee <yorkelee@google.com> | 2013-01-14 08:57:43 -0800 |
---|---|---|
committer | Yorke Lee <yorkelee@google.com> | 2013-01-14 11:38:39 -0800 |
commit | 02f304f721d936566d6983500d25b223d96e6e9d (patch) | |
tree | 490c5cc2ac998f96a5b3d08111a3331bcf3e7325 /core | |
parent | c19b54975214a12225a1669ae18b0005a1357189 (diff) | |
download | frameworks_base-02f304f721d936566d6983500d25b223d96e6e9d.zip frameworks_base-02f304f721d936566d6983500d25b223d96e6e9d.tar.gz frameworks_base-02f304f721d936566d6983500d25b223d96e6e9d.tar.bz2 |
Allow supplying extras when assigning QuickContactsBadge
Add assignContactFromEmail(String, boolean, Bundle)
and assignContactFromPhone(String, boolean, Bundle)
that allow the caller to provide a bundle of extras to
pre-populate the ContactEditorFragment with if a contact
is not found with the requested email address or phone number.
Bug: 7038382
Change-Id: Ib77fa484e1c39cb60d7acc27efe3a3fcf3fee62f
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/widget/QuickContactBadge.java | 63 |
1 files changed, 58 insertions, 5 deletions
diff --git a/core/java/android/widget/QuickContactBadge.java b/core/java/android/widget/QuickContactBadge.java index 786afe2..622ac8f 100644 --- a/core/java/android/widget/QuickContactBadge.java +++ b/core/java/android/widget/QuickContactBadge.java @@ -27,6 +27,7 @@ import android.database.Cursor; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.net.Uri; +import android.os.Bundle; import android.provider.ContactsContract.CommonDataKinds.Email; import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.Intents; @@ -50,6 +51,7 @@ public class QuickContactBadge extends ImageView implements OnClickListener { private Drawable mOverlay; private QueryHandler mQueryHandler; private Drawable mDefaultAvatar; + private Bundle mExtras = null; protected String[] mExcludeMimes = null; @@ -58,6 +60,8 @@ public class QuickContactBadge extends ImageView implements OnClickListener { static final private int TOKEN_EMAIL_LOOKUP_AND_TRIGGER = 2; static final private int TOKEN_PHONE_LOOKUP_AND_TRIGGER = 3; + static final private String EXTRA_URI_CONTENT = "uri_content"; + static final String[] EMAIL_LOOKUP_PROJECTION = new String[] { RawContacts.CONTACT_ID, Contacts.LOOKUP_KEY, @@ -175,7 +179,26 @@ public class QuickContactBadge extends ImageView implements OnClickListener { * until this view is clicked. */ public void assignContactFromEmail(String emailAddress, boolean lazyLookup) { + assignContactFromEmail(emailAddress, lazyLookup, null); + } + + /** + * Assign a contact based on an email address. This should only be used when + * the contact's URI is not available, as an extra query will have to be + * performed to lookup the URI based on the email. + + @param emailAddress The email address of the contact. + @param lazyLookup If this is true, the lookup query will not be performed + until this view is clicked. + @param extras A bundle of extras to populate the contact edit page with if the contact + is not found and the user chooses to add the email address to an existing contact or + create a new contact. Uses the same string constants as those found in + {@link #ContactsContract.Intents.Insert} + */ + + public void assignContactFromEmail(String emailAddress, boolean lazyLookup, Bundle extras) { mContactEmail = emailAddress; + mExtras = extras; if (!lazyLookup) { mQueryHandler.startQuery(TOKEN_EMAIL_LOOKUP, null, Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(mContactEmail)), @@ -186,6 +209,7 @@ public class QuickContactBadge extends ImageView implements OnClickListener { } } + /** * Assign a contact based on a phone number. This should only be used when * the contact's URI is not available, as an extra query will have to be @@ -196,7 +220,25 @@ public class QuickContactBadge extends ImageView implements OnClickListener { * until this view is clicked. */ public void assignContactFromPhone(String phoneNumber, boolean lazyLookup) { + assignContactFromPhone(phoneNumber, lazyLookup, new Bundle()); + } + + /** + * Assign a contact based on a phone number. This should only be used when + * the contact's URI is not available, as an extra query will have to be + * performed to lookup the URI based on the phone number. + * + * @param phoneNumber The phone number of the contact. + * @param lazyLookup If this is true, the lookup query will not be performed + * until this view is clicked. + * @param extras A bundle of extras to populate the contact edit page with if the contact + * is not found and the user chooses to add the phone number to an existing contact or + * create a new contact. Uses the same string constants as those found in + * {@link #ContactsContract.Intents.Insert} + */ + public void assignContactFromPhone(String phoneNumber, boolean lazyLookup, Bundle extras) { mContactPhone = phoneNumber; + mExtras = extras; if (!lazyLookup) { mQueryHandler.startQuery(TOKEN_PHONE_LOOKUP, null, Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, mContactPhone), @@ -213,15 +255,21 @@ public class QuickContactBadge extends ImageView implements OnClickListener { @Override public void onClick(View v) { + // If contact has been assigned, mExtras should no longer be null, but do a null check + // anyway just in case assignContactFromPhone or Email was called with a null bundle or + // wasn't assigned previously. + final Bundle extras = (mExtras == null) ? new Bundle() : mExtras; if (mContactUri != null) { QuickContact.showQuickContact(getContext(), QuickContactBadge.this, mContactUri, QuickContact.MODE_LARGE, mExcludeMimes); } else if (mContactEmail != null) { - mQueryHandler.startQuery(TOKEN_EMAIL_LOOKUP_AND_TRIGGER, mContactEmail, + extras.putString(EXTRA_URI_CONTENT, mContactEmail); + mQueryHandler.startQuery(TOKEN_EMAIL_LOOKUP_AND_TRIGGER, extras, Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(mContactEmail)), EMAIL_LOOKUP_PROJECTION, null, null, null); } else if (mContactPhone != null) { - mQueryHandler.startQuery(TOKEN_PHONE_LOOKUP_AND_TRIGGER, mContactPhone, + extras.putString(EXTRA_URI_CONTENT, mContactPhone); + mQueryHandler.startQuery(TOKEN_PHONE_LOOKUP_AND_TRIGGER, extras, Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, mContactPhone), PHONE_LOOKUP_PROJECTION, null, null, null); } else { @@ -262,12 +310,12 @@ public class QuickContactBadge extends ImageView implements OnClickListener { Uri lookupUri = null; Uri createUri = null; boolean trigger = false; - + Bundle extras = (cookie != null) ? (Bundle) cookie : new Bundle(); try { switch(token) { case TOKEN_PHONE_LOOKUP_AND_TRIGGER: trigger = true; - createUri = Uri.fromParts("tel", (String)cookie, null); + createUri = Uri.fromParts("tel", extras.getString(EXTRA_URI_CONTENT), null); //$FALL-THROUGH$ case TOKEN_PHONE_LOOKUP: { @@ -281,7 +329,8 @@ public class QuickContactBadge extends ImageView implements OnClickListener { } case TOKEN_EMAIL_LOOKUP_AND_TRIGGER: trigger = true; - createUri = Uri.fromParts("mailto", (String)cookie, null); + createUri = Uri.fromParts("mailto", + extras.getString(EXTRA_URI_CONTENT), null); //$FALL-THROUGH$ case TOKEN_EMAIL_LOOKUP: { @@ -309,6 +358,10 @@ public class QuickContactBadge extends ImageView implements OnClickListener { } else if (createUri != null) { // Prompt user to add this person to contacts final Intent intent = new Intent(Intents.SHOW_OR_CREATE_CONTACT, createUri); + if (extras != null) { + extras.remove(EXTRA_URI_CONTENT); + intent.putExtras(extras); + } getContext().startActivity(intent); } } |