From 1513fec51cbb557685f1976ee2050c73ccdbe036 Mon Sep 17 00:00:00 2001 From: Tyler Gunn Date: Fri, 5 Dec 2014 14:19:00 -0800 Subject: Updating "Add Contact" to pre-populate full contact info. 1. For recent call entries with a name and phone number, the name will now also be added. 2. For recent call entries which have complete address information provided by nearby places, all information except the contact photo will be added. The contact photo is excluded, as the ContactsLoader would attempt to load the contact photo while parsing the contact information. On a slow connection this could cause a noticeable pause while adding the contact. Bug: 17308163 Change-Id: If2e78bd1257096b344ff2dd266dcdbaeed4f1471 --- src/com/android/dialer/calllog/CallLogAdapter.java | 73 ++++++++++++++++++++-- 1 file changed, 67 insertions(+), 6 deletions(-) (limited to 'src/com/android/dialer/calllog') diff --git a/src/com/android/dialer/calllog/CallLogAdapter.java b/src/com/android/dialer/calllog/CallLogAdapter.java index 9528e4507..e799b00cc 100644 --- a/src/com/android/dialer/calllog/CallLogAdapter.java +++ b/src/com/android/dialer/calllog/CallLogAdapter.java @@ -19,13 +19,14 @@ package com.android.dialer.calllog; import android.content.ContentValues; import android.content.Context; import android.content.Intent; +import android.content.Loader; import android.content.res.Resources; import android.database.Cursor; -import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Handler; import android.os.Message; import android.provider.CallLog.Calls; +import android.provider.ContactsContract; import android.provider.ContactsContract.PhoneLookup; import android.telecom.PhoneAccountHandle; import android.text.TextUtils; @@ -44,6 +45,8 @@ import com.android.common.widget.GroupingListAdapter; import com.android.contacts.common.CallUtil; import com.android.contacts.common.ContactPhotoManager; import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest; +import com.android.contacts.common.model.Contact; +import com.android.contacts.common.model.ContactLoader; import com.android.contacts.common.util.UriUtils; import com.android.dialer.DialtactsActivity; import com.android.dialer.PhoneCallDetails; @@ -55,6 +58,7 @@ import com.android.dialer.util.ExpirableCache; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Objects; +import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; @@ -1062,7 +1066,7 @@ public class CallLogAdapter extends GroupingListAdapter } protected void bindBadge( - View view, ContactInfo info, final PhoneCallDetails details, int callType) { + View view, final ContactInfo info, final PhoneCallDetails details, int callType) { // Do not show badge in call log. if (!mIsCallLog) { final ViewStub stub = (ViewStub) view.findViewById(R.id.link_stub); @@ -1082,10 +1086,18 @@ public class CallLogAdapter extends GroupingListAdapter clickableArea.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - final Intent intent = - DialtactsActivity.getAddNumberToContactIntent(details.number); - DialerUtils.startActivityWithErrorToast(mContext, intent, - R.string.add_contact_not_available); + // If no lookup uri is provided, we need to rely on what information + // we have available; namely the phone number and name. + if (info.lookupUri == null) { + final Intent intent = + DialtactsActivity.getAddToContactIntent(details.name, + details.number, + details.numberType); + DialerUtils.startActivityWithErrorToast(mContext, intent, + R.string.add_contact_not_available); + } else { + addContactFromLookupUri(info.lookupUri); + } } }); } @@ -1434,4 +1446,53 @@ public class CallLogAdapter extends GroupingListAdapter } } } + + /** + * Invokes the "add contact" activity given the expanded contact information stored in a + * lookup URI. This can include, for example, address and website information. + * + * @param lookupUri The lookup URI. + */ + private void addContactFromLookupUri(Uri lookupUri) { + Contact contactToSave = ContactLoader.parseEncodedContactEntity(lookupUri); + if (contactToSave == null) { + return; + } + + // Note: This code mirrors code in Contacts/QuickContactsActivity. + final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT); + intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE); + + ArrayList values = contactToSave.getContentValues(); + // Only pre-fill the name field if the provided display name is an nickname + // or better (e.g. structured name, nickname) + if (contactToSave.getDisplayNameSource() + >= ContactsContract.DisplayNameSources.NICKNAME) { + intent.putExtra(ContactsContract.Intents.Insert.NAME, + contactToSave.getDisplayName()); + } else if (contactToSave.getDisplayNameSource() + == ContactsContract.DisplayNameSources.ORGANIZATION) { + // This is probably an organization. Instead of copying the organization + // name into a name entry, copy it into the organization entry. This + // way we will still consider the contact an organization. + final ContentValues organization = new ContentValues(); + organization.put(ContactsContract.CommonDataKinds.Organization.COMPANY, + contactToSave.getDisplayName()); + organization.put(ContactsContract.Data.MIMETYPE, + ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE); + values.add(organization); + } + + // Last time used and times used are aggregated values from the usage stat + // table. They need to be removed from data values so the SQL table can insert + // properly + for (ContentValues value : values) { + value.remove(ContactsContract.Data.LAST_TIME_USED); + value.remove(ContactsContract.Data.TIMES_USED); + } + intent.putExtra(ContactsContract.Intents.Insert.DATA, values); + + DialerUtils.startActivityWithErrorToast(mContext, intent, + R.string.add_contact_not_available); + } } -- cgit v1.2.3