Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 56cb0efa authored by Yorke Lee's avatar Yorke Lee
Browse files

Use new ContactPhotoManager APIs for letter tile avatars

*Modify the following uses of ContactPhotoManager.loadPhoto in the following
classes to include a DefaultImageRequest, populated with the contact's
display name, lookupkey, and contact type as necessary

CallDetailActivity
CallLogAdapter
PhoneFavoriteTileView

*Add utility methods to ContactInfoHelper, to parse a lookupUri for a lookup
key, as well as determine whether or not a contact is a business contact,
from its sourceType field.
*Add a sourceType field to PhoneCallDetails which can be used to track
whether or not PhoneCallDetails belongs to a business contact
*Add a lookupKey field to ContactInfo

Bug: 13101785
Change-Id: If339a9c038f92a0212f8f8b45b5e3cc5f6442562
parent 8b584915
Loading
Loading
Loading
Loading
+31 −10
Original line number Original line Diff line number Diff line
@@ -32,6 +32,7 @@ import android.net.Uri;
import android.os.AsyncTask;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Bundle;
import android.provider.CallLog;
import android.provider.CallLog;
import android.provider.ContactsContract;
import android.provider.CallLog.Calls;
import android.provider.CallLog.Calls;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Contacts;
@@ -56,6 +57,7 @@ import android.widget.Toast;
import com.android.contacts.common.ContactPhotoManager;
import com.android.contacts.common.ContactPhotoManager;
import com.android.contacts.common.CallUtil;
import com.android.contacts.common.CallUtil;
import com.android.contacts.common.ClipboardUtils;
import com.android.contacts.common.ClipboardUtils;
import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest;
import com.android.contacts.common.GeoUtil;
import com.android.contacts.common.GeoUtil;
import com.android.contacts.common.model.Contact;
import com.android.contacts.common.model.Contact;
import com.android.contacts.common.model.ContactLoader;
import com.android.contacts.common.model.ContactLoader;
@@ -545,14 +547,14 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware
                            mainActionDescription);
                            mainActionDescription);
                }
                }


                // This action allows to call the number that places the call.
                if (canPlaceCallsTo) {
                final CharSequence displayNumber =
                final CharSequence displayNumber =
                        mPhoneNumberHelper.getDisplayNumber(
                        mPhoneNumberHelper.getDisplayNumber(
                                firstDetails.number,
                                firstDetails.number,
                                firstDetails.numberPresentation,
                                firstDetails.numberPresentation,
                                firstDetails.formattedNumber);
                                firstDetails.formattedNumber);


                // This action allows to call the number that places the call.
                if (canPlaceCallsTo) {
                    ViewEntry entry = new ViewEntry(
                    ViewEntry entry = new ViewEntry(
                            getString(R.string.menu_callNumber,
                            getString(R.string.menu_callNumber,
                                    forceLeftToRight(displayNumber)),
                                    forceLeftToRight(displayNumber)),
@@ -623,7 +625,20 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware
                            }
                            }
                        },
                        },
                        historyList);
                        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);
                findViewById(R.id.call_detail).setVisibility(View.VISIBLE);
            }
            }
        }
        }
@@ -690,6 +705,7 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware
            final CharSequence numberLabel;
            final CharSequence numberLabel;
            final Uri photoUri;
            final Uri photoUri;
            final Uri lookupUri;
            final Uri lookupUri;
            int sourceType;
            // If this is not a regular number, there is no point in looking it up in the contacts.
            // If this is not a regular number, there is no point in looking it up in the contacts.
            ContactInfo info =
            ContactInfo info =
                    PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation)
                    PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation)
@@ -704,6 +720,7 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware
                numberLabel = "";
                numberLabel = "";
                photoUri = null;
                photoUri = null;
                lookupUri = null;
                lookupUri = null;
                sourceType = 0;
            } else {
            } else {
                formattedNumber = info.formattedNumber;
                formattedNumber = info.formattedNumber;
                nameText = info.name;
                nameText = info.name;
@@ -711,11 +728,12 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware
                numberLabel = info.label;
                numberLabel = info.label;
                photoUri = info.photoUri;
                photoUri = info.photoUri;
                lookupUri = info.lookupUri;
                lookupUri = info.lookupUri;
                sourceType = info.sourceType;
            }
            }
            return new PhoneCallDetails(number, numberPresentation,
            return new PhoneCallDetails(number, numberPresentation,
                    formattedNumber, countryIso, geocode,
                    formattedNumber, countryIso, geocode,
                    new int[]{ callType }, date, duration,
                    new int[]{ callType }, date, duration,
                    nameText, numberType, numberLabel, lookupUri, photoUri);
                    nameText, numberType, numberLabel, lookupUri, photoUri, sourceType);
        } finally {
        } finally {
            if (callCursor != null) {
            if (callCursor != null) {
                callCursor.close();
                callCursor.close();
@@ -724,9 +742,12 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware
    }
    }


    /** Load the contact photos and places them in the corresponding views. */
    /** 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,
        mContactPhotoManager.loadPhoto(mContactBackgroundView, photoUri,
                mContactBackgroundView.getWidth(), true);
                mContactBackgroundView.getWidth(), true, request);
    }
    }


    static final class ViewEntry {
    static final class ViewEntry {
+7 −2
Original line number Original line Diff line number Diff line
@@ -59,13 +59,17 @@ public class PhoneCallDetails {
     * This is meant to store the high-res photo only.
     * This is meant to store the high-res photo only.
     */
     */
    public final Uri photoUri;
    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. */
    /** Create the details for a call with a number not associated with a contact. */
    public PhoneCallDetails(CharSequence number, int numberPresentation,
    public PhoneCallDetails(CharSequence number, int numberPresentation,
            CharSequence formattedNumber, String countryIso, String geocode,
            CharSequence formattedNumber, String countryIso, String geocode,
            int[] callTypes, long date, long duration) {
            int[] callTypes, long date, long duration) {
        this(number, numberPresentation, formattedNumber, countryIso, geocode,
        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. */
    /** Create the details for a call with a number associated with a contact. */
@@ -73,7 +77,7 @@ public class PhoneCallDetails {
            CharSequence formattedNumber, String countryIso, String geocode,
            CharSequence formattedNumber, String countryIso, String geocode,
            int[] callTypes, long date, long duration, CharSequence name,
            int[] callTypes, long date, long duration, CharSequence name,
            int numberType, CharSequence numberLabel, Uri contactUri,
            int numberType, CharSequence numberLabel, Uri contactUri,
            Uri photoUri) {
            Uri photoUri, int sourceType) {
        this.number = number;
        this.number = number;
        this.numberPresentation = numberPresentation;
        this.numberPresentation = numberPresentation;
        this.formattedNumber = formattedNumber;
        this.formattedNumber = formattedNumber;
@@ -87,5 +91,6 @@ public class PhoneCallDetails {
        this.numberLabel = numberLabel;
        this.numberLabel = numberLabel;
        this.contactUri = contactUri;
        this.contactUri = contactUri;
        this.photoUri = photoUri;
        this.photoUri = photoUri;
        this.sourceType = sourceType;
    }
    }
}
}
+44 −8
Original line number Original line Diff line number Diff line
@@ -27,6 +27,7 @@ import android.os.Message;
import android.provider.CallLog.Calls;
import android.provider.CallLog.Calls;
import android.provider.ContactsContract.PhoneLookup;
import android.provider.ContactsContract.PhoneLookup;
import android.text.TextUtils;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup;
@@ -37,11 +38,13 @@ import android.widget.TextView;


import com.android.common.widget.GroupingListAdapter;
import com.android.common.widget.GroupingListAdapter;
import com.android.contacts.common.ContactPhotoManager;
import com.android.contacts.common.ContactPhotoManager;
import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest;
import com.android.contacts.common.util.UriUtils;
import com.android.contacts.common.util.UriUtils;
import com.android.dialer.PhoneCallDetails;
import com.android.dialer.PhoneCallDetails;
import com.android.dialer.PhoneCallDetailsHelper;
import com.android.dialer.PhoneCallDetailsHelper;
import com.android.dialer.R;
import com.android.dialer.R;
import com.android.dialer.util.ExpirableCache;
import com.android.dialer.util.ExpirableCache;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Objects;
import com.google.common.base.Objects;


@@ -537,6 +540,9 @@ public class CallLogAdapter extends GroupingListAdapter


        final ContactInfo cachedContactInfo = getContactInfoFromCallLog(c);
        final ContactInfo cachedContactInfo = getContactInfoFromCallLog(c);


        final boolean isVoicemailNumber =
                PhoneNumberUtilsWrapper.INSTANCE.isVoicemailNumber(number);

        // Primary action is always to call, if possible.
        // Primary action is always to call, if possible.
        if (PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation)) {
        if (PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation)) {
            // Sets the primary action to call the number.
            // Sets the primary action to call the number.
@@ -569,7 +575,7 @@ public class CallLogAdapter extends GroupingListAdapter
                mContactInfoCache.getCachedValue(numberCountryIso);
                mContactInfoCache.getCachedValue(numberCountryIso);
        ContactInfo info = cachedInfo == null ? null : cachedInfo.getValue();
        ContactInfo info = cachedInfo == null ? null : cachedInfo.getValue();
        if (!PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation)
        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
            // If this is a number that cannot be dialed, there is no point in looking up a contact
            // for it.
            // for it.
            info = ContactInfo.EMPTY;
            info = ContactInfo.EMPTY;
@@ -609,6 +615,7 @@ public class CallLogAdapter extends GroupingListAdapter
        CharSequence formattedNumber = info.formattedNumber;
        CharSequence formattedNumber = info.formattedNumber;
        final int[] callTypes = getCallTypes(c, count);
        final int[] callTypes = getCallTypes(c, count);
        final String geocode = c.getString(CallLogQuery.GEOCODED_LOCATION);
        final String geocode = c.getString(CallLogQuery.GEOCODED_LOCATION);
        final int sourceType = info.sourceType;
        final PhoneCallDetails details;
        final PhoneCallDetails details;


        if (TextUtils.isEmpty(name)) {
        if (TextUtils.isEmpty(name)) {
@@ -618,7 +625,7 @@ public class CallLogAdapter extends GroupingListAdapter
        } else {
        } else {
            details = new PhoneCallDetails(number, numberPresentation,
            details = new PhoneCallDetails(number, numberPresentation,
                    formattedNumber, countryIso, geocode, callTypes, date,
                    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;
        final boolean isNew = c.getInt(CallLogQuery.IS_READ) == 0;
@@ -627,10 +634,32 @@ public class CallLogAdapter extends GroupingListAdapter
        mCallLogViewsHelper.setPhoneCallDetails(views, details, isHighlighted,
        mCallLogViewsHelper.setPhoneCallDetails(views, details, isHighlighted,
                mShowSecondaryActionButton);
                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) {
        if (photoId == 0 && photoUri != null) {
            setPhoto(views, photoUri, lookupUri);
            setPhoto(views, photoUri, lookupUri, nameForDefaultImage, lookupKey, contactType);
        } else {
        } else {
            setPhoto(views, photoId, lookupUri);
            setPhoto(views, photoId, lookupUri, nameForDefaultImage, lookupKey, contactType);
        }
        }


        // Listen for the first draw
        // Listen for the first draw
@@ -853,15 +882,22 @@ public class CallLogAdapter extends GroupingListAdapter
        return callTypes;
        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);
        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);
        views.quickContactView.assignContactUri(contactUri);
        DefaultImageRequest request = new DefaultImageRequest(displayName, identifier,
                contactType);
        mContactPhotoManager.loadDirectoryPhoto(views.quickContactView, photoUri,
        mContactPhotoManager.loadDirectoryPhoto(views.quickContactView, photoUri,
                false /* darkTheme */);
                false /* darkTheme */, request);
    }
    }




+1 −0
Original line number Original line Diff line number Diff line
@@ -27,6 +27,7 @@ import com.google.common.base.Objects;
 */
 */
public class ContactInfo {
public class ContactInfo {
    public Uri lookupUri;
    public Uri lookupUri;
    public String lookupKey;
    public String name;
    public String name;
    public int type;
    public int type;
    public String label;
    public String label;
+54 −31
Original line number Original line Diff line number Diff line
/*
/*
 * Copyright (C) 2011 The Android Open Source Project
 * Copyright (C) 2011 The Android Open Source Project
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * you may not use this file except in compliance with the License.
 * in compliance with the License. You may obtain a copy of the License at
 * You may obtain a copy of the License at
 *
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 *
 * Unless required by applicable law or agreed to in writing, software
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * distributed under the License is distributed on an "AS IS" BASIS,
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * or implied. See the License for the specific language governing permissions and limitations under
 * See the License for the specific language governing permissions and
 * the License.
 * limitations under the License.
 */
 */


package com.android.dialer.calllog;
package com.android.dialer.calllog;
@@ -37,6 +35,8 @@ import com.android.dialerbind.ObjectFactory;
import org.json.JSONException;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONObject;


import java.util.List;

/**
/**
 * Utility class to look up the contact information for a given number.
 * Utility class to look up the contact information for a given number.
 */
 */
@@ -101,7 +101,7 @@ public class ContactInfoHelper {
                updatedInfo = new ContactInfo();
                updatedInfo = new ContactInfo();
                updatedInfo.number = number;
                updatedInfo.number = number;
                updatedInfo.formattedNumber = formatPhoneNumber(number, null, countryIso);
                updatedInfo.formattedNumber = formatPhoneNumber(number, null, countryIso);
                updatedInfo.lookupUri = createTemporaryContactUri(number);
                updatedInfo.lookupUri = createTemporaryContactUri(updatedInfo.formattedNumber);
            } else {
            } else {
                updatedInfo = info;
                updatedInfo = info;
            }
            }
@@ -113,23 +113,20 @@ public class ContactInfoHelper {
     * Creates a JSON-encoded lookup uri for a unknown number without an associated contact
     * Creates a JSON-encoded lookup uri for a unknown number without an associated contact
     *
     *
     * @param number - Unknown phone number
     * @param number - Unknown phone number
     * @return JSON-encoded URI that can be used to perform a lookup when clicking
     * @return JSON-encoded URI that can be used to perform a lookup when clicking on the quick
     * on the quick contact card.
     *         contact card.
     */
     */
    private static Uri createTemporaryContactUri(String number) {
    private static Uri createTemporaryContactUri(String number) {
        try {
        try {
            final JSONObject contactRows = new JSONObject()
            final JSONObject contactRows = new JSONObject().put(Phone.CONTENT_ITEM_TYPE,
                    .put(Phone.CONTENT_ITEM_TYPE, new JSONObject()
                    new JSONObject().put(Phone.NUMBER, number).put(Phone.TYPE, Phone.TYPE_CUSTOM));
                            .put(Phone.NUMBER, number)
                                    .put(Phone.TYPE, Phone.TYPE_CUSTOM));


            final String jsonString = new JSONObject()
            final String jsonString = new JSONObject().put(Contacts.DISPLAY_NAME, number)
                    .put(Contacts.DISPLAY_NAME, number)
                    .put(Contacts.DISPLAY_NAME_SOURCE, DisplayNameSources.PHONE)
                    .put(Contacts.DISPLAY_NAME_SOURCE, DisplayNameSources.PHONE)
                            .put(Contacts.CONTENT_ITEM_TYPE, contactRows)
                    .put(Contacts.CONTENT_ITEM_TYPE, contactRows).toString();
                            .toString();


            return Contacts.CONTENT_LOOKUP_URI.buildUpon()
            return Contacts.CONTENT_LOOKUP_URI
                    .buildUpon()
                    .appendPath(Constants.LOOKUP_URI_ENCODED)
                    .appendPath(Constants.LOOKUP_URI_ENCODED)
                    .appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY,
                    .appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY,
                            String.valueOf(Long.MAX_VALUE))
                            String.valueOf(Long.MAX_VALUE))
@@ -152,8 +149,7 @@ public class ContactInfoHelper {
    private ContactInfo lookupContactFromUri(Uri uri) {
    private ContactInfo lookupContactFromUri(Uri uri) {
        final ContactInfo info;
        final ContactInfo info;
        Cursor phonesCursor =
        Cursor phonesCursor =
                mContext.getContentResolver().query(
                mContext.getContentResolver().query(uri, PhoneQuery._PROJECTION, null, null, null);
                        uri, PhoneQuery._PROJECTION, null, null, null);


        if (phonesCursor != null) {
        if (phonesCursor != null) {
            try {
            try {
@@ -161,6 +157,7 @@ public class ContactInfoHelper {
                    info = new ContactInfo();
                    info = new ContactInfo();
                    long contactId = phonesCursor.getLong(PhoneQuery.PERSON_ID);
                    long contactId = phonesCursor.getLong(PhoneQuery.PERSON_ID);
                    String lookupKey = phonesCursor.getString(PhoneQuery.LOOKUP_KEY);
                    String lookupKey = phonesCursor.getString(PhoneQuery.LOOKUP_KEY);
                    info.lookupKey = lookupKey;
                    info.lookupUri = Contacts.getLookupUri(contactId, lookupKey);
                    info.lookupUri = Contacts.getLookupUri(contactId, lookupKey);
                    info.name = phonesCursor.getString(PhoneQuery.NAME);
                    info.name = phonesCursor.getString(PhoneQuery.NAME);
                    info.type = phonesCursor.getInt(PhoneQuery.PHONE_TYPE);
                    info.type = phonesCursor.getInt(PhoneQuery.PHONE_TYPE);
@@ -230,8 +227,8 @@ public class ContactInfoHelper {
        if (info != null && info != ContactInfo.EMPTY) {
        if (info != null && info != ContactInfo.EMPTY) {
            info.formattedNumber = formatPhoneNumber(number, null, countryIso);
            info.formattedNumber = formatPhoneNumber(number, null, countryIso);
        } else if (mCachedNumberLookupService != null) {
        } else if (mCachedNumberLookupService != null) {
            CachedContactInfo cacheInfo = mCachedNumberLookupService
            CachedContactInfo cacheInfo =
                .lookupCachedContactFromNumber(mContext, number);
                    mCachedNumberLookupService.lookupCachedContactFromNumber(mContext, number);
            info = cacheInfo != null ? cacheInfo.getContactInfo() : null;
            info = cacheInfo != null ? cacheInfo.getContactInfo() : null;
        }
        }
        return info;
        return info;
@@ -242,14 +239,12 @@ public class ContactInfoHelper {
     *
     *
     * @param number the number to be formatted.
     * @param number the number to be formatted.
     * @param normalizedNumber the normalized number of the given number.
     * @param normalizedNumber the normalized number of the given number.
     * @param countryIso the ISO 3166-1 two letters country code, the country's
     * @param countryIso the ISO 3166-1 two letters country code, the country's convention will be
     *        convention will be used to format the number if the normalized
     *        used to format the number if the normalized phone is null.
     *        phone is null.
     *
     *
     * @return the formatted number, or the given number if it was formatted.
     * @return the formatted number, or the given number if it was formatted.
     */
     */
    private String formatPhoneNumber(String number, String normalizedNumber,
    private String formatPhoneNumber(String number, String normalizedNumber, String countryIso) {
            String countryIso) {
        if (TextUtils.isEmpty(number)) {
        if (TextUtils.isEmpty(number)) {
            return "";
            return "";
        }
        }
@@ -262,4 +257,32 @@ public class ContactInfoHelper {
        }
        }
        return PhoneNumberUtils.formatNumber(number, normalizedNumber, countryIso);
        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