From 58ebe5d3fac837625b69fe1565427f17025bd780 Mon Sep 17 00:00:00 2001 From: Yorke Lee Date: Mon, 9 Sep 2013 10:19:40 -0700 Subject: Add URI for unknown contacts to enable quick contact badge Bug: 10600250 Change-Id: I38dc59d3c6637593353601f03dbc067c36abdde7 --- src/com/android/dialer/CallDetailActivity.java | 4 ++- .../android/dialer/calllog/ContactInfoHelper.java | 42 ++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/com/android/dialer/CallDetailActivity.java b/src/com/android/dialer/CallDetailActivity.java index 05c1e7fdc..d0e18bfcf 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; } @@ -99,6 +110,37 @@ public class ContactInfoHelper { return updatedInfo; } + /** + * 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. *

-- cgit v1.2.3