Loading src/com/android/dialer/CallDetailActivity.java +31 −10 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.provider.CallLog; import android.provider.ContactsContract; import android.provider.CallLog.Calls; import android.provider.ContactsContract.CommonDataKinds.Phone; import android.provider.ContactsContract.Contacts; Loading @@ -57,6 +58,7 @@ import android.widget.Toast; import com.android.contacts.common.ContactPhotoManager; import com.android.contacts.common.CallUtil; import com.android.contacts.common.ClipboardUtils; import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest; import com.android.contacts.common.GeoUtil; import com.android.contacts.common.model.Contact; import com.android.contacts.common.model.ContactLoader; Loading Loading @@ -545,14 +547,14 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware mainActionDescription); } // This action allows to call the number that places the call. if (canPlaceCallsTo) { final CharSequence displayNumber = mPhoneNumberHelper.getDisplayNumber( firstDetails.number, firstDetails.numberPresentation, firstDetails.formattedNumber); // This action allows to call the number that places the call. if (canPlaceCallsTo) { ViewEntry entry = new ViewEntry( getString(R.string.menu_callNumber, forceLeftToRight(displayNumber)), Loading Loading @@ -623,7 +625,20 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware } }, historyList); loadContactPhotos(photoUri); final String displayNameForDefaultImage = TextUtils.isEmpty(firstDetails.name) ? displayNumber.toString() : firstDetails.name.toString(); final String lookupKey = ContactInfoHelper.getLookupKeyFromUri(contactUri); final boolean isBusiness = mContactInfoHelper.isBusiness(firstDetails.sourceType); final int contactType = isVoicemailNumber? ContactPhotoManager.TYPE_VOICEMAIL : isBusiness ? ContactPhotoManager.TYPE_BUSINESS : ContactPhotoManager.TYPE_DEFAULT; loadContactPhotos(photoUri, displayNameForDefaultImage, lookupKey, contactType); findViewById(R.id.call_detail).setVisibility(View.VISIBLE); } } Loading Loading @@ -690,6 +705,7 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware final CharSequence numberLabel; final Uri photoUri; final Uri lookupUri; int sourceType; // If this is not a regular number, there is no point in looking it up in the contacts. ContactInfo info = PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation) Loading @@ -704,6 +720,7 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware numberLabel = ""; photoUri = null; lookupUri = null; sourceType = 0; } else { formattedNumber = info.formattedNumber; nameText = info.name; Loading @@ -711,11 +728,12 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware numberLabel = info.label; photoUri = info.photoUri; lookupUri = info.lookupUri; sourceType = info.sourceType; } return new PhoneCallDetails(number, numberPresentation, formattedNumber, countryIso, geocode, new int[]{ callType }, date, duration, nameText, numberType, numberLabel, lookupUri, photoUri); nameText, numberType, numberLabel, lookupUri, photoUri, sourceType); } finally { if (callCursor != null) { callCursor.close(); Loading @@ -724,9 +742,12 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware } /** Load the contact photos and places them in the corresponding views. */ private void loadContactPhotos(Uri photoUri) { private void loadContactPhotos(Uri photoUri, String displayName, String lookupKey, int contactType) { final DefaultImageRequest request = new DefaultImageRequest(displayName, lookupKey, contactType); mContactPhotoManager.loadPhoto(mContactBackgroundView, photoUri, mContactBackgroundView.getWidth(), true); mContactBackgroundView.getWidth(), true, request); } static final class ViewEntry { Loading src/com/android/dialer/PhoneCallDetails.java +7 −2 Original line number Diff line number Diff line Loading @@ -59,13 +59,17 @@ public class PhoneCallDetails { * This is meant to store the high-res photo only. */ public final Uri photoUri; /** * The source type of the contact associated with this call. */ public final int sourceType; /** Create the details for a call with a number not associated with a contact. */ public PhoneCallDetails(CharSequence number, int numberPresentation, CharSequence formattedNumber, String countryIso, String geocode, int[] callTypes, long date, long duration) { this(number, numberPresentation, formattedNumber, countryIso, geocode, callTypes, date, duration, "", 0, "", null, null); callTypes, date, duration, "", 0, "", null, null, 0); } /** Create the details for a call with a number associated with a contact. */ Loading @@ -73,7 +77,7 @@ public class PhoneCallDetails { CharSequence formattedNumber, String countryIso, String geocode, int[] callTypes, long date, long duration, CharSequence name, int numberType, CharSequence numberLabel, Uri contactUri, Uri photoUri) { Uri photoUri, int sourceType) { this.number = number; this.numberPresentation = numberPresentation; this.formattedNumber = formattedNumber; Loading @@ -87,5 +91,6 @@ public class PhoneCallDetails { this.numberLabel = numberLabel; this.contactUri = contactUri; this.photoUri = photoUri; this.sourceType = sourceType; } } src/com/android/dialer/calllog/CallLogAdapter.java +44 −8 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.os.Message; import android.provider.CallLog.Calls; import android.provider.ContactsContract.PhoneLookup; import android.text.TextUtils; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; Loading @@ -37,11 +38,13 @@ import android.widget.TextView; import com.android.common.widget.GroupingListAdapter; import com.android.contacts.common.ContactPhotoManager; import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest; import com.android.contacts.common.util.UriUtils; import com.android.dialer.PhoneCallDetails; import com.android.dialer.PhoneCallDetailsHelper; import com.android.dialer.R; import com.android.dialer.util.ExpirableCache; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Objects; Loading Loading @@ -537,6 +540,9 @@ public class CallLogAdapter extends GroupingListAdapter final ContactInfo cachedContactInfo = getContactInfoFromCallLog(c); final boolean isVoicemailNumber = PhoneNumberUtilsWrapper.INSTANCE.isVoicemailNumber(number); // Primary action is always to call, if possible. if (PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation)) { // Sets the primary action to call the number. Loading Loading @@ -569,7 +575,7 @@ public class CallLogAdapter extends GroupingListAdapter mContactInfoCache.getCachedValue(numberCountryIso); ContactInfo info = cachedInfo == null ? null : cachedInfo.getValue(); if (!PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation) || new PhoneNumberUtilsWrapper().isVoicemailNumber(number)) { || isVoicemailNumber) { // If this is a number that cannot be dialed, there is no point in looking up a contact // for it. info = ContactInfo.EMPTY; Loading Loading @@ -609,6 +615,7 @@ public class CallLogAdapter extends GroupingListAdapter CharSequence formattedNumber = info.formattedNumber; final int[] callTypes = getCallTypes(c, count); final String geocode = c.getString(CallLogQuery.GEOCODED_LOCATION); final int sourceType = info.sourceType; final PhoneCallDetails details; if (TextUtils.isEmpty(name)) { Loading @@ -618,7 +625,7 @@ public class CallLogAdapter extends GroupingListAdapter } else { details = new PhoneCallDetails(number, numberPresentation, formattedNumber, countryIso, geocode, callTypes, date, duration, name, ntype, label, lookupUri, photoUri); duration, name, ntype, label, lookupUri, photoUri, sourceType); } final boolean isNew = c.getInt(CallLogQuery.IS_READ) == 0; Loading @@ -627,10 +634,32 @@ public class CallLogAdapter extends GroupingListAdapter mCallLogViewsHelper.setPhoneCallDetails(views, details, isHighlighted, mShowSecondaryActionButton); int contactType = ContactPhotoManager.TYPE_DEFAULT; if (isVoicemailNumber) { contactType = ContactPhotoManager.TYPE_VOICEMAIL; } else if (mContactInfoHelper.isBusiness(info.sourceType)) { contactType = ContactPhotoManager.TYPE_BUSINESS; } String lookupKey = info.lookupKey; if (lookupUri != null) { //lookupKey = ContactInfoHelper.getLookupKeyFromUri(lookupUri); } String nameForDefaultImage = null; if (TextUtils.isEmpty(name)) { nameForDefaultImage = mPhoneNumberHelper.getDisplayNumber(details.number, details.numberPresentation, details.formattedNumber).toString(); } else { nameForDefaultImage = name; } if (photoId == 0 && photoUri != null) { setPhoto(views, photoUri, lookupUri); setPhoto(views, photoUri, lookupUri, nameForDefaultImage, lookupKey, contactType); } else { setPhoto(views, photoId, lookupUri); setPhoto(views, photoId, lookupUri, nameForDefaultImage, lookupKey, contactType); } // Listen for the first draw Loading Loading @@ -853,15 +882,22 @@ public class CallLogAdapter extends GroupingListAdapter return callTypes; } private void setPhoto(CallLogListItemViews views, long photoId, Uri contactUri) { private void setPhoto(CallLogListItemViews views, long photoId, Uri contactUri, String displayName, String identifier, int contactType) { views.quickContactView.assignContactUri(contactUri); mContactPhotoManager.loadThumbnail(views.quickContactView, photoId, false /* darkTheme */); DefaultImageRequest request = new DefaultImageRequest(displayName, identifier, contactType); mContactPhotoManager.loadThumbnail(views.quickContactView, photoId, false /* darkTheme */, request); } private void setPhoto(CallLogListItemViews views, Uri photoUri, Uri contactUri) { private void setPhoto(CallLogListItemViews views, Uri photoUri, Uri contactUri, String displayName, String identifier, int contactType) { views.quickContactView.assignContactUri(contactUri); DefaultImageRequest request = new DefaultImageRequest(displayName, identifier, contactType); mContactPhotoManager.loadDirectoryPhoto(views.quickContactView, photoUri, false /* darkTheme */); false /* darkTheme */, request); } Loading src/com/android/dialer/calllog/ContactInfo.java +1 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import com.google.common.base.Objects; */ public class ContactInfo { public Uri lookupUri; public String lookupKey; public String name; public int type; public String label; Loading src/com/android/dialer/calllog/ContactInfoHelper.java +54 −31 Original line number Diff line number Diff line /* * Copyright (C) 2011 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * Unless required by applicable law or agreed to in writing, software distributed under the License * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing permissions and limitations under * the License. */ package com.android.dialer.calllog; Loading @@ -36,6 +34,8 @@ import com.android.dialerbind.ObjectFactory; import org.json.JSONException; import org.json.JSONObject; import java.util.List; /** * Utility class to look up the contact information for a given number. */ Loading Loading @@ -100,7 +100,7 @@ public class ContactInfoHelper { updatedInfo = new ContactInfo(); updatedInfo.number = number; updatedInfo.formattedNumber = formatPhoneNumber(number, null, countryIso); updatedInfo.lookupUri = createTemporaryContactUri(number); updatedInfo.lookupUri = createTemporaryContactUri(updatedInfo.formattedNumber); } else { updatedInfo = info; } Loading @@ -112,23 +112,20 @@ 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. * @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 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) final String jsonString = new JSONObject().put(Contacts.DISPLAY_NAME, number) .put(Contacts.DISPLAY_NAME_SOURCE, DisplayNameSources.PHONE) .put(Contacts.CONTENT_ITEM_TYPE, contactRows) .toString(); .put(Contacts.CONTENT_ITEM_TYPE, contactRows).toString(); return Contacts.CONTENT_LOOKUP_URI.buildUpon() return Contacts.CONTENT_LOOKUP_URI .buildUpon() .appendPath(Constants.LOOKUP_URI_ENCODED) .appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(Long.MAX_VALUE)) Loading @@ -151,8 +148,7 @@ public class ContactInfoHelper { private ContactInfo lookupContactFromUri(Uri uri) { final ContactInfo info; Cursor phonesCursor = mContext.getContentResolver().query( uri, PhoneQuery._PROJECTION, null, null, null); mContext.getContentResolver().query(uri, PhoneQuery._PROJECTION, null, null, null); if (phonesCursor != null) { try { Loading @@ -160,6 +156,7 @@ public class ContactInfoHelper { info = new ContactInfo(); long contactId = phonesCursor.getLong(PhoneQuery.PERSON_ID); String lookupKey = phonesCursor.getString(PhoneQuery.LOOKUP_KEY); info.lookupKey = lookupKey; info.lookupUri = Contacts.getLookupUri(contactId, lookupKey); info.name = phonesCursor.getString(PhoneQuery.NAME); info.type = phonesCursor.getInt(PhoneQuery.PHONE_TYPE); Loading Loading @@ -229,8 +226,8 @@ public class ContactInfoHelper { if (info != null && info != ContactInfo.EMPTY) { info.formattedNumber = formatPhoneNumber(number, null, countryIso); } else if (mCachedNumberLookupService != null) { CachedContactInfo cacheInfo = mCachedNumberLookupService .lookupCachedContactFromNumber(mContext, number); CachedContactInfo cacheInfo = mCachedNumberLookupService.lookupCachedContactFromNumber(mContext, number); info = cacheInfo != null ? cacheInfo.getContactInfo() : null; } return info; Loading @@ -241,14 +238,12 @@ public class ContactInfoHelper { * * @param number the number to be formatted. * @param normalizedNumber the normalized number of the given number. * @param countryIso the ISO 3166-1 two letters country code, the country's * convention will be used to format the number if the normalized * phone is null. * @param countryIso the ISO 3166-1 two letters country code, the country's convention will be * used to format the number if the normalized phone is null. * * @return the formatted number, or the given number if it was formatted. */ private String formatPhoneNumber(String number, String normalizedNumber, String countryIso) { private String formatPhoneNumber(String number, String normalizedNumber, String countryIso) { if (TextUtils.isEmpty(number)) { return ""; } Loading @@ -261,4 +256,32 @@ public class ContactInfoHelper { } return PhoneNumberUtils.formatNumber(number, normalizedNumber, countryIso); } /** * Parses the given URI to determine the original lookup key of the contact. */ public static String getLookupKeyFromUri(Uri lookupUri) { // Would be nice to be able to persist the lookup key somehow to avoid having to parse // the uri entirely just to retrieve the lookup key, but every uri is already parsed // once anyway to check if it is an encoded JSON uri, so this has negligible effect // on performance. if (lookupUri != null && !UriUtils.isEncodedContactUri(lookupUri)) { final List<String> segments = lookupUri.getPathSegments(); // This returns the third path segment of the uri, where the lookup key is located. // See {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}. return (segments.size() < 3) ? null : segments.get(2); } else { return null; } } /** * Given a contact's sourceType, return true if the contact is a business * * @param sourceType sourceType of the contact. This is usually populated by * {@link #mCachedNumberLookupService}. */ public boolean isBusiness(int sourceType) { return mCachedNumberLookupService.isBusiness(sourceType); } } Loading
src/com/android/dialer/CallDetailActivity.java +31 −10 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.provider.CallLog; import android.provider.ContactsContract; import android.provider.CallLog.Calls; import android.provider.ContactsContract.CommonDataKinds.Phone; import android.provider.ContactsContract.Contacts; Loading @@ -57,6 +58,7 @@ import android.widget.Toast; import com.android.contacts.common.ContactPhotoManager; import com.android.contacts.common.CallUtil; import com.android.contacts.common.ClipboardUtils; import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest; import com.android.contacts.common.GeoUtil; import com.android.contacts.common.model.Contact; import com.android.contacts.common.model.ContactLoader; Loading Loading @@ -545,14 +547,14 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware mainActionDescription); } // This action allows to call the number that places the call. if (canPlaceCallsTo) { final CharSequence displayNumber = mPhoneNumberHelper.getDisplayNumber( firstDetails.number, firstDetails.numberPresentation, firstDetails.formattedNumber); // This action allows to call the number that places the call. if (canPlaceCallsTo) { ViewEntry entry = new ViewEntry( getString(R.string.menu_callNumber, forceLeftToRight(displayNumber)), Loading Loading @@ -623,7 +625,20 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware } }, historyList); loadContactPhotos(photoUri); final String displayNameForDefaultImage = TextUtils.isEmpty(firstDetails.name) ? displayNumber.toString() : firstDetails.name.toString(); final String lookupKey = ContactInfoHelper.getLookupKeyFromUri(contactUri); final boolean isBusiness = mContactInfoHelper.isBusiness(firstDetails.sourceType); final int contactType = isVoicemailNumber? ContactPhotoManager.TYPE_VOICEMAIL : isBusiness ? ContactPhotoManager.TYPE_BUSINESS : ContactPhotoManager.TYPE_DEFAULT; loadContactPhotos(photoUri, displayNameForDefaultImage, lookupKey, contactType); findViewById(R.id.call_detail).setVisibility(View.VISIBLE); } } Loading Loading @@ -690,6 +705,7 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware final CharSequence numberLabel; final Uri photoUri; final Uri lookupUri; int sourceType; // If this is not a regular number, there is no point in looking it up in the contacts. ContactInfo info = PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation) Loading @@ -704,6 +720,7 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware numberLabel = ""; photoUri = null; lookupUri = null; sourceType = 0; } else { formattedNumber = info.formattedNumber; nameText = info.name; Loading @@ -711,11 +728,12 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware numberLabel = info.label; photoUri = info.photoUri; lookupUri = info.lookupUri; sourceType = info.sourceType; } return new PhoneCallDetails(number, numberPresentation, formattedNumber, countryIso, geocode, new int[]{ callType }, date, duration, nameText, numberType, numberLabel, lookupUri, photoUri); nameText, numberType, numberLabel, lookupUri, photoUri, sourceType); } finally { if (callCursor != null) { callCursor.close(); Loading @@ -724,9 +742,12 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware } /** Load the contact photos and places them in the corresponding views. */ private void loadContactPhotos(Uri photoUri) { private void loadContactPhotos(Uri photoUri, String displayName, String lookupKey, int contactType) { final DefaultImageRequest request = new DefaultImageRequest(displayName, lookupKey, contactType); mContactPhotoManager.loadPhoto(mContactBackgroundView, photoUri, mContactBackgroundView.getWidth(), true); mContactBackgroundView.getWidth(), true, request); } static final class ViewEntry { Loading
src/com/android/dialer/PhoneCallDetails.java +7 −2 Original line number Diff line number Diff line Loading @@ -59,13 +59,17 @@ public class PhoneCallDetails { * This is meant to store the high-res photo only. */ public final Uri photoUri; /** * The source type of the contact associated with this call. */ public final int sourceType; /** Create the details for a call with a number not associated with a contact. */ public PhoneCallDetails(CharSequence number, int numberPresentation, CharSequence formattedNumber, String countryIso, String geocode, int[] callTypes, long date, long duration) { this(number, numberPresentation, formattedNumber, countryIso, geocode, callTypes, date, duration, "", 0, "", null, null); callTypes, date, duration, "", 0, "", null, null, 0); } /** Create the details for a call with a number associated with a contact. */ Loading @@ -73,7 +77,7 @@ public class PhoneCallDetails { CharSequence formattedNumber, String countryIso, String geocode, int[] callTypes, long date, long duration, CharSequence name, int numberType, CharSequence numberLabel, Uri contactUri, Uri photoUri) { Uri photoUri, int sourceType) { this.number = number; this.numberPresentation = numberPresentation; this.formattedNumber = formattedNumber; Loading @@ -87,5 +91,6 @@ public class PhoneCallDetails { this.numberLabel = numberLabel; this.contactUri = contactUri; this.photoUri = photoUri; this.sourceType = sourceType; } }
src/com/android/dialer/calllog/CallLogAdapter.java +44 −8 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.os.Message; import android.provider.CallLog.Calls; import android.provider.ContactsContract.PhoneLookup; import android.text.TextUtils; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; Loading @@ -37,11 +38,13 @@ import android.widget.TextView; import com.android.common.widget.GroupingListAdapter; import com.android.contacts.common.ContactPhotoManager; import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest; import com.android.contacts.common.util.UriUtils; import com.android.dialer.PhoneCallDetails; import com.android.dialer.PhoneCallDetailsHelper; import com.android.dialer.R; import com.android.dialer.util.ExpirableCache; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Objects; Loading Loading @@ -537,6 +540,9 @@ public class CallLogAdapter extends GroupingListAdapter final ContactInfo cachedContactInfo = getContactInfoFromCallLog(c); final boolean isVoicemailNumber = PhoneNumberUtilsWrapper.INSTANCE.isVoicemailNumber(number); // Primary action is always to call, if possible. if (PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation)) { // Sets the primary action to call the number. Loading Loading @@ -569,7 +575,7 @@ public class CallLogAdapter extends GroupingListAdapter mContactInfoCache.getCachedValue(numberCountryIso); ContactInfo info = cachedInfo == null ? null : cachedInfo.getValue(); if (!PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation) || new PhoneNumberUtilsWrapper().isVoicemailNumber(number)) { || isVoicemailNumber) { // If this is a number that cannot be dialed, there is no point in looking up a contact // for it. info = ContactInfo.EMPTY; Loading Loading @@ -609,6 +615,7 @@ public class CallLogAdapter extends GroupingListAdapter CharSequence formattedNumber = info.formattedNumber; final int[] callTypes = getCallTypes(c, count); final String geocode = c.getString(CallLogQuery.GEOCODED_LOCATION); final int sourceType = info.sourceType; final PhoneCallDetails details; if (TextUtils.isEmpty(name)) { Loading @@ -618,7 +625,7 @@ public class CallLogAdapter extends GroupingListAdapter } else { details = new PhoneCallDetails(number, numberPresentation, formattedNumber, countryIso, geocode, callTypes, date, duration, name, ntype, label, lookupUri, photoUri); duration, name, ntype, label, lookupUri, photoUri, sourceType); } final boolean isNew = c.getInt(CallLogQuery.IS_READ) == 0; Loading @@ -627,10 +634,32 @@ public class CallLogAdapter extends GroupingListAdapter mCallLogViewsHelper.setPhoneCallDetails(views, details, isHighlighted, mShowSecondaryActionButton); int contactType = ContactPhotoManager.TYPE_DEFAULT; if (isVoicemailNumber) { contactType = ContactPhotoManager.TYPE_VOICEMAIL; } else if (mContactInfoHelper.isBusiness(info.sourceType)) { contactType = ContactPhotoManager.TYPE_BUSINESS; } String lookupKey = info.lookupKey; if (lookupUri != null) { //lookupKey = ContactInfoHelper.getLookupKeyFromUri(lookupUri); } String nameForDefaultImage = null; if (TextUtils.isEmpty(name)) { nameForDefaultImage = mPhoneNumberHelper.getDisplayNumber(details.number, details.numberPresentation, details.formattedNumber).toString(); } else { nameForDefaultImage = name; } if (photoId == 0 && photoUri != null) { setPhoto(views, photoUri, lookupUri); setPhoto(views, photoUri, lookupUri, nameForDefaultImage, lookupKey, contactType); } else { setPhoto(views, photoId, lookupUri); setPhoto(views, photoId, lookupUri, nameForDefaultImage, lookupKey, contactType); } // Listen for the first draw Loading Loading @@ -853,15 +882,22 @@ public class CallLogAdapter extends GroupingListAdapter return callTypes; } private void setPhoto(CallLogListItemViews views, long photoId, Uri contactUri) { private void setPhoto(CallLogListItemViews views, long photoId, Uri contactUri, String displayName, String identifier, int contactType) { views.quickContactView.assignContactUri(contactUri); mContactPhotoManager.loadThumbnail(views.quickContactView, photoId, false /* darkTheme */); DefaultImageRequest request = new DefaultImageRequest(displayName, identifier, contactType); mContactPhotoManager.loadThumbnail(views.quickContactView, photoId, false /* darkTheme */, request); } private void setPhoto(CallLogListItemViews views, Uri photoUri, Uri contactUri) { private void setPhoto(CallLogListItemViews views, Uri photoUri, Uri contactUri, String displayName, String identifier, int contactType) { views.quickContactView.assignContactUri(contactUri); DefaultImageRequest request = new DefaultImageRequest(displayName, identifier, contactType); mContactPhotoManager.loadDirectoryPhoto(views.quickContactView, photoUri, false /* darkTheme */); false /* darkTheme */, request); } Loading
src/com/android/dialer/calllog/ContactInfo.java +1 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import com.google.common.base.Objects; */ public class ContactInfo { public Uri lookupUri; public String lookupKey; public String name; public int type; public String label; Loading
src/com/android/dialer/calllog/ContactInfoHelper.java +54 −31 Original line number Diff line number Diff line /* * Copyright (C) 2011 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * Unless required by applicable law or agreed to in writing, software distributed under the License * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing permissions and limitations under * the License. */ package com.android.dialer.calllog; Loading @@ -36,6 +34,8 @@ import com.android.dialerbind.ObjectFactory; import org.json.JSONException; import org.json.JSONObject; import java.util.List; /** * Utility class to look up the contact information for a given number. */ Loading Loading @@ -100,7 +100,7 @@ public class ContactInfoHelper { updatedInfo = new ContactInfo(); updatedInfo.number = number; updatedInfo.formattedNumber = formatPhoneNumber(number, null, countryIso); updatedInfo.lookupUri = createTemporaryContactUri(number); updatedInfo.lookupUri = createTemporaryContactUri(updatedInfo.formattedNumber); } else { updatedInfo = info; } Loading @@ -112,23 +112,20 @@ 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. * @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 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) final String jsonString = new JSONObject().put(Contacts.DISPLAY_NAME, number) .put(Contacts.DISPLAY_NAME_SOURCE, DisplayNameSources.PHONE) .put(Contacts.CONTENT_ITEM_TYPE, contactRows) .toString(); .put(Contacts.CONTENT_ITEM_TYPE, contactRows).toString(); return Contacts.CONTENT_LOOKUP_URI.buildUpon() return Contacts.CONTENT_LOOKUP_URI .buildUpon() .appendPath(Constants.LOOKUP_URI_ENCODED) .appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(Long.MAX_VALUE)) Loading @@ -151,8 +148,7 @@ public class ContactInfoHelper { private ContactInfo lookupContactFromUri(Uri uri) { final ContactInfo info; Cursor phonesCursor = mContext.getContentResolver().query( uri, PhoneQuery._PROJECTION, null, null, null); mContext.getContentResolver().query(uri, PhoneQuery._PROJECTION, null, null, null); if (phonesCursor != null) { try { Loading @@ -160,6 +156,7 @@ public class ContactInfoHelper { info = new ContactInfo(); long contactId = phonesCursor.getLong(PhoneQuery.PERSON_ID); String lookupKey = phonesCursor.getString(PhoneQuery.LOOKUP_KEY); info.lookupKey = lookupKey; info.lookupUri = Contacts.getLookupUri(contactId, lookupKey); info.name = phonesCursor.getString(PhoneQuery.NAME); info.type = phonesCursor.getInt(PhoneQuery.PHONE_TYPE); Loading Loading @@ -229,8 +226,8 @@ public class ContactInfoHelper { if (info != null && info != ContactInfo.EMPTY) { info.formattedNumber = formatPhoneNumber(number, null, countryIso); } else if (mCachedNumberLookupService != null) { CachedContactInfo cacheInfo = mCachedNumberLookupService .lookupCachedContactFromNumber(mContext, number); CachedContactInfo cacheInfo = mCachedNumberLookupService.lookupCachedContactFromNumber(mContext, number); info = cacheInfo != null ? cacheInfo.getContactInfo() : null; } return info; Loading @@ -241,14 +238,12 @@ public class ContactInfoHelper { * * @param number the number to be formatted. * @param normalizedNumber the normalized number of the given number. * @param countryIso the ISO 3166-1 two letters country code, the country's * convention will be used to format the number if the normalized * phone is null. * @param countryIso the ISO 3166-1 two letters country code, the country's convention will be * used to format the number if the normalized phone is null. * * @return the formatted number, or the given number if it was formatted. */ private String formatPhoneNumber(String number, String normalizedNumber, String countryIso) { private String formatPhoneNumber(String number, String normalizedNumber, String countryIso) { if (TextUtils.isEmpty(number)) { return ""; } Loading @@ -261,4 +256,32 @@ public class ContactInfoHelper { } return PhoneNumberUtils.formatNumber(number, normalizedNumber, countryIso); } /** * Parses the given URI to determine the original lookup key of the contact. */ public static String getLookupKeyFromUri(Uri lookupUri) { // Would be nice to be able to persist the lookup key somehow to avoid having to parse // the uri entirely just to retrieve the lookup key, but every uri is already parsed // once anyway to check if it is an encoded JSON uri, so this has negligible effect // on performance. if (lookupUri != null && !UriUtils.isEncodedContactUri(lookupUri)) { final List<String> segments = lookupUri.getPathSegments(); // This returns the third path segment of the uri, where the lookup key is located. // See {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}. return (segments.size() < 3) ? null : segments.get(2); } else { return null; } } /** * Given a contact's sourceType, return true if the contact is a business * * @param sourceType sourceType of the contact. This is usually populated by * {@link #mCachedNumberLookupService}. */ public boolean isBusiness(int sourceType) { return mCachedNumberLookupService.isBusiness(sourceType); } }