diff options
author | Yorke Lee <yorkelee@google.com> | 2013-09-10 01:13:32 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-09-10 01:13:32 +0000 |
commit | dc778c1a6fe5548f82dabfbf5945cc53437815e3 (patch) | |
tree | 2ef5fc223de69d687e95865686b5333a3ea46a3d | |
parent | a3b62d1a02f93e8ce98d2ef3a66eb997308b3321 (diff) | |
parent | 58ebe5d3fac837625b69fe1565427f17025bd780 (diff) |
Merge "Add URI for unknown contacts to enable quick contact badge" into klp-dev
-rw-r--r-- | src/com/android/dialer/CallDetailActivity.java | 4 | ||||
-rw-r--r-- | src/com/android/dialer/calllog/ContactInfoHelper.java | 42 |
2 files changed, 45 insertions, 1 deletions
diff --git a/src/com/android/dialer/CallDetailActivity.java b/src/com/android/dialer/CallDetailActivity.java index 1f41ac43c..e26d2f020 100644 --- a/src/com/android/dialer/CallDetailActivity.java +++ b/src/com/android/dialer/CallDetailActivity.java @@ -55,6 +55,8 @@ import com.android.contacts.common.ContactPhotoManager; import com.android.contacts.common.CallUtil; import com.android.contacts.common.ClipboardUtils; import com.android.contacts.common.GeoUtil; +import com.android.contacts.common.util.Constants; +import com.android.contacts.common.util.UriUtils; import com.android.dialer.BackScrollManager.ScrollableHeader; import com.android.dialer.calllog.CallDetailHistoryAdapter; import com.android.dialer.calllog.CallTypeHelper; @@ -450,7 +452,7 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware nameOrNumber = firstDetails.number; } - if (contactUri != null) { + if (contactUri != null && !UriUtils.isEncodedContactUri(contactUri)) { mainActionIntent = new Intent(Intent.ACTION_VIEW, contactUri); // This will launch People's detail contact screen, so we probably want to // treat it as a separate People task. diff --git a/src/com/android/dialer/calllog/ContactInfoHelper.java b/src/com/android/dialer/calllog/ContactInfoHelper.java index 10412814d..5d7aa1bef 100644 --- a/src/com/android/dialer/calllog/ContactInfoHelper.java +++ b/src/com/android/dialer/calllog/ContactInfoHelper.java @@ -19,15 +19,25 @@ package com.android.dialer.calllog; import android.content.Context; import android.database.Cursor; import android.net.Uri; +import android.provider.ContactsContract; +import android.provider.ContactsContract.CommonDataKinds.Phone; import android.provider.ContactsContract.Contacts; +import android.provider.ContactsContract.Directory; +import android.provider.ContactsContract.DisplayNameSources; import android.provider.ContactsContract.PhoneLookup; import android.telephony.PhoneNumberUtils; import android.text.TextUtils; +import android.util.Log; +import com.android.contacts.common.util.Constants; import com.android.contacts.common.util.UriUtils; import com.android.dialer.service.CachedNumberLookupService; +import com.android.dialer.service.CachedNumberLookupService.CachedContactInfo; import com.android.dialerbind.ServiceFactory; +import org.json.JSONException; +import org.json.JSONObject; + /** * Utility class to look up the contact information for a given number. */ @@ -92,6 +102,7 @@ public class ContactInfoHelper { updatedInfo = new ContactInfo(); updatedInfo.number = number; updatedInfo.formattedNumber = formatPhoneNumber(number, null, countryIso); + updatedInfo.lookupUri = createTemporaryContactUri(number); } else { updatedInfo = info; } @@ -100,6 +111,37 @@ public class ContactInfoHelper { } /** + * Creates a JSON-encoded lookup uri for a unknown number without an associated contact + * + * @param number - Unknown phone number + * @return JSON-encoded URI that can be used to perform a lookup when clicking + * on the quick contact card. + */ + private static Uri createTemporaryContactUri(String number) { + try { + final JSONObject contactRows = new JSONObject() + .put(Phone.CONTENT_ITEM_TYPE, new JSONObject() + .put(Phone.NUMBER, number) + .put(Phone.TYPE, Phone.TYPE_CUSTOM)); + + final String jsonString = new JSONObject() + .put(Contacts.DISPLAY_NAME, number) + .put(Contacts.DISPLAY_NAME_SOURCE, DisplayNameSources.PHONE) + .put(Contacts.CONTENT_ITEM_TYPE, contactRows) + .toString(); + + return Contacts.CONTENT_LOOKUP_URI.buildUpon() + .appendPath(Constants.LOOKUP_URI_ENCODED) + .appendQueryParameter(Constants.LOOKUP_URI_JSON, jsonString) + .appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY, + String.valueOf(Long.MAX_VALUE)) + .build(); + } catch (JSONException e) { + return null; + } + } + + /** * Looks up a contact using the given URI. * <p> * It returns null if an error occurs, {@link ContactInfo#EMPTY} if no matching contact is |