summaryrefslogtreecommitdiff
path: root/src/com/android/dialer/calllog
diff options
context:
space:
mode:
authorYorke Lee <yorkelee@google.com>2013-09-10 01:13:32 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-09-10 01:13:32 +0000
commitdc778c1a6fe5548f82dabfbf5945cc53437815e3 (patch)
tree2ef5fc223de69d687e95865686b5333a3ea46a3d /src/com/android/dialer/calllog
parenta3b62d1a02f93e8ce98d2ef3a66eb997308b3321 (diff)
parent58ebe5d3fac837625b69fe1565427f17025bd780 (diff)
Merge "Add URI for unknown contacts to enable quick contact badge" into klp-dev
Diffstat (limited to 'src/com/android/dialer/calllog')
-rw-r--r--src/com/android/dialer/calllog/ContactInfoHelper.java42
1 files changed, 42 insertions, 0 deletions
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