From 034a2b329e469bf6888fbbcf91992f974015c2a8 Mon Sep 17 00:00:00 2001 From: Yorke Lee Date: Mon, 26 Aug 2013 15:46:10 -0700 Subject: Use contacts cache in call log adapter Bug: 10490038 Change-Id: I4c7fc5094f76dfaaa321bc69d595f37bb72f87ad --- src/com/android/dialer/PhoneCallDetailsHelper.java | 10 ++++++-- src/com/android/dialer/calllog/CallLogAdapter.java | 18 +++++++++++-- src/com/android/dialer/calllog/ContactInfo.java | 2 ++ .../android/dialer/calllog/ContactInfoHelper.java | 7 +++++ .../dialer/list/PhoneFavoriteMergedAdapter.java | 2 +- .../dialer/service/CachedNumberLookupService.java | 19 ++++++++++++++ src/com/android/dialerbind/ServiceFactory.java | 30 ++++++++++++++++++++++ 7 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 src/com/android/dialer/service/CachedNumberLookupService.java create mode 100644 src/com/android/dialerbind/ServiceFactory.java (limited to 'src') diff --git a/src/com/android/dialer/PhoneCallDetailsHelper.java b/src/com/android/dialer/PhoneCallDetailsHelper.java index 6f13b2e9d..b51a27bce 100644 --- a/src/com/android/dialer/PhoneCallDetailsHelper.java +++ b/src/com/android/dialer/PhoneCallDetailsHelper.java @@ -18,6 +18,7 @@ package com.android.dialer; import android.content.res.Resources; import android.graphics.Typeface; +import android.provider.ContactsContract; import android.provider.ContactsContract.CommonDataKinds.Phone; import android.telephony.PhoneNumberUtils; import android.text.SpannableString; @@ -31,6 +32,7 @@ import android.widget.TextView; import com.android.contacts.common.test.NeededForTesting; import com.android.dialer.calllog.CallTypeHelper; +import com.android.dialer.calllog.ContactInfo; import com.android.dialer.calllog.PhoneNumberHelper; /** @@ -97,8 +99,12 @@ public class PhoneCallDetailsHelper { // Only show a label if the number is shown and it is not a SIP address. if (!TextUtils.isEmpty(details.number) && !PhoneNumberUtils.isUriNumber(details.number.toString())) { - numberFormattedLabel = Phone.getTypeLabel(mResources, details.numberType, - details.numberLabel); + if (details.numberLabel == ContactInfo.GEOCODE_AS_LABEL) { + numberFormattedLabel = details.geocode; + } else { + numberFormattedLabel = Phone.getTypeLabel(mResources, details.numberType, + details.numberLabel); + } } final CharSequence nameText; diff --git a/src/com/android/dialer/calllog/CallLogAdapter.java b/src/com/android/dialer/calllog/CallLogAdapter.java index 15c9b05a6..da29bbd87 100644 --- a/src/com/android/dialer/calllog/CallLogAdapter.java +++ b/src/com/android/dialer/calllog/CallLogAdapter.java @@ -372,7 +372,8 @@ public class CallLogAdapter extends GroupingListAdapter // view. NumberWithCountryIso numberCountryIso = new NumberWithCountryIso(number, countryIso); ContactInfo existingInfo = mContactInfoCache.getPossiblyExpired(numberCountryIso); - boolean updated = (existingInfo != ContactInfo.EMPTY) && !info.equals(existingInfo); + + boolean updated = !info.equals(existingInfo); // Store the data in the cache so that the UI thread can use to display it. Store it // even if it has not changed so that it is marked as not expired. @@ -587,6 +588,7 @@ public class CallLogAdapter extends GroupingListAdapter final int ntype = info.type; final String label = info.label; final long photoId = info.photoId; + final Uri photoUri = info.photoUri; CharSequence formattedNumber = info.formattedNumber; final int[] callTypes = getCallTypes(c, count); final String geocode = c.getString(CallLogQuery.GEOCODED_LOCATION); @@ -607,7 +609,12 @@ public class CallLogAdapter extends GroupingListAdapter final boolean isHighlighted = isNew; mCallLogViewsHelper.setPhoneCallDetails(views, details, isHighlighted, mUseCallAsPrimaryAction); - setPhoto(views, photoId, lookupUri); + + if (photoId == 0 && photoUri != null) { + setPhoto(views, photoUri, lookupUri); + } else { + setPhoto(views, photoId, lookupUri); + } // Listen for the first draw if (mViewTreeObserver == null) { @@ -731,6 +738,13 @@ public class CallLogAdapter extends GroupingListAdapter mContactPhotoManager.loadThumbnail(views.quickContactView, photoId, false /* darkTheme */); } + private void setPhoto(CallLogListItemViews views, Uri photoUri, Uri contactUri) { + views.quickContactView.assignContactUri(contactUri); + mContactPhotoManager.loadDirectoryPhoto(views.quickContactView, photoUri, + false /* darkTheme */); + } + + /** * Sets whether processing of requests for contact details should be enabled. *

diff --git a/src/com/android/dialer/calllog/ContactInfo.java b/src/com/android/dialer/calllog/ContactInfo.java index e0a074d99..08633f895 100644 --- a/src/com/android/dialer/calllog/ContactInfo.java +++ b/src/com/android/dialer/calllog/ContactInfo.java @@ -39,6 +39,8 @@ public final class ContactInfo { public static ContactInfo EMPTY = new ContactInfo(); + public static String GEOCODE_AS_LABEL = ""; + @Override public int hashCode() { // Uses only name and contactUri to determine hashcode. diff --git a/src/com/android/dialer/calllog/ContactInfoHelper.java b/src/com/android/dialer/calllog/ContactInfoHelper.java index abe4a069d..10412814d 100644 --- a/src/com/android/dialer/calllog/ContactInfoHelper.java +++ b/src/com/android/dialer/calllog/ContactInfoHelper.java @@ -25,6 +25,8 @@ import android.telephony.PhoneNumberUtils; import android.text.TextUtils; import com.android.contacts.common.util.UriUtils; +import com.android.dialer.service.CachedNumberLookupService; +import com.android.dialerbind.ServiceFactory; /** * Utility class to look up the contact information for a given number. @@ -33,6 +35,9 @@ public class ContactInfoHelper { private final Context mContext; private final String mCurrentCountryIso; + private static final CachedNumberLookupService mCachedNumberLookupService = + ServiceFactory.newCachedNumberLookupService(); + public ContactInfoHelper(Context context, String currentCountryIso) { mContext = context; mCurrentCountryIso = currentCountryIso; @@ -183,6 +188,8 @@ public class ContactInfoHelper { ContactInfo info = lookupContactFromUri(uri); if (info != null && info != ContactInfo.EMPTY) { info.formattedNumber = formatPhoneNumber(number, null, countryIso); + } else if (mCachedNumberLookupService != null) { + info = mCachedNumberLookupService.lookupCachedContactFromNumber(mContext, number); } return info; } diff --git a/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java b/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java index cbb94b22a..f8e1e716d 100644 --- a/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java +++ b/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java @@ -64,8 +64,8 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter { mCallLogPadding = resources.getDimensionPixelSize(R.dimen.recent_call_log_item_padding); mContactTileAdapter = contactTileAdapter; mCallLogAdapter = callLogAdapter; - mObserver = new CustomDataSetObserver(); + mCallLogAdapter.registerDataSetObserver(mObserver); mContactTileAdapter.registerDataSetObserver(mObserver); mLoadingView = loadingView; mShowAllContactsButton = showAllContactsButton; diff --git a/src/com/android/dialer/service/CachedNumberLookupService.java b/src/com/android/dialer/service/CachedNumberLookupService.java new file mode 100644 index 000000000..a08c28564 --- /dev/null +++ b/src/com/android/dialer/service/CachedNumberLookupService.java @@ -0,0 +1,19 @@ +package com.android.dialer.service; + +import android.content.Context; + +import com.android.dialer.calllog.ContactInfo; + +public interface CachedNumberLookupService { + /** + * Perform a lookup using the cached number lookup service to return contact + * information stored in the cache that corresponds to the given number. + * + * @param context Valid context + * @param number Phone number to lookup the cache for + * @return A {@link ContactInfo} containing the contact information if the phone + * number is found in the cache, {@link ContactInfo#EMPTY} if the phone number was + * not found in the cache, and null if there was an error when querying the cache. + */ + public ContactInfo lookupCachedContactFromNumber(Context context, String number); +} diff --git a/src/com/android/dialerbind/ServiceFactory.java b/src/com/android/dialerbind/ServiceFactory.java new file mode 100644 index 000000000..e53d2e82a --- /dev/null +++ b/src/com/android/dialerbind/ServiceFactory.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2013 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 + * + * 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 + */ + +package com.android.dialerbind; + +import com.android.dialer.service.CachedNumberLookupService; + +/** + * Default static binder for services. + */ +public class ServiceFactory { + + public static CachedNumberLookupService newCachedNumberLookupService() { + // no-op + return null; + } +} -- cgit v1.2.3