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

Commit 710f8d96 authored by Maurice Chu's avatar Maurice Chu Committed by Android (Google) Code Review
Browse files

Merge "Enable parsing phone number in ContactLoader" into jb-mr1-dev

parents dc0405b4 10bf684e
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -42,7 +42,6 @@ import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.Directory;
import android.provider.ContactsContract.DisplayNameSources;
import android.provider.ContactsContract.StatusUpdates;
import android.telephony.PhoneNumberUtils;
import android.text.TextUtils;
import android.util.Log;
import android.view.ContextMenu;
@@ -573,9 +572,7 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen
                } else if (dataItem instanceof PhoneDataItem && hasData) {
                    PhoneDataItem phone = (PhoneDataItem) dataItem;
                    // Build phone entries
                    String phoneNumberE164 = phone.getNormalizedNumber();
                    entry.data = PhoneNumberUtils.formatNumber(
                            entry.data, phoneNumberE164, mDefaultCountryIso);
                    entry.data = phone.getFormattedPhoneNumber();
                    final Intent phoneIntent = mHasPhone ?
                            ContactsUtils.getCallIntent(entry.data) : null;
                    final Intent smsIntent = mHasSms ? new Intent(Intent.ACTION_SENDTO,
+1 −1
Original line number Diff line number Diff line
@@ -187,7 +187,7 @@ public class ContactLoaderFragment extends Fragment implements FragmentKeyListen
            Uri lookupUri = args.getParcelable(LOADER_ARG_CONTACT_URI);
            return new ContactLoader(mContext, lookupUri, true /* loadGroupMetaData */,
                    true /* loadStreamItems */, true /* load invitable account types */,
                    true /* postViewNotification */);
                    true /* postViewNotification */, true /* computeFormattedPhoneNumber */);
        }

        @Override
+21 −3
Original line number Diff line number Diff line
@@ -41,10 +41,12 @@ import android.text.TextUtils;
import android.util.Log;
import android.util.LongSparseArray;

import com.android.contacts.ContactsUtils;
import com.android.contacts.GroupMetaData;
import com.android.contacts.model.account.AccountType;
import com.android.contacts.model.account.AccountTypeWithDataSet;
import com.android.contacts.model.dataitem.DataItem;
import com.android.contacts.model.dataitem.PhoneDataItem;
import com.android.contacts.model.dataitem.PhotoDataItem;
import com.android.contacts.util.ContactLoaderUtils;
import com.android.contacts.util.DataStatus;
@@ -81,17 +83,18 @@ public class ContactLoader extends AsyncTaskLoader<Contact> {
    private boolean mLoadStreamItems;
    private boolean mLoadInvitableAccountTypes;
    private boolean mPostViewNotification;
    private boolean mComputeFormattedPhoneNumber;
    private Contact mContact;
    private ForceLoadContentObserver mObserver;
    private final Set<Long> mNotifiedRawContactIds = Sets.newHashSet();

    public ContactLoader(Context context, Uri lookupUri, boolean postViewNotification) {
        this(context, lookupUri, false, false, false, postViewNotification);
        this(context, lookupUri, false, false, false, postViewNotification, false);
    }

    public ContactLoader(Context context, Uri lookupUri, boolean loadGroupMetaData,
            boolean loadStreamItems, boolean loadInvitableAccountTypes,
            boolean postViewNotification) {
            boolean postViewNotification, boolean computeFormattedPhoneNumber) {
        super(context);
        mLookupUri = lookupUri;
        mRequestedUri = lookupUri;
@@ -99,6 +102,7 @@ public class ContactLoader extends AsyncTaskLoader<Contact> {
        mLoadStreamItems = loadStreamItems;
        mLoadInvitableAccountTypes = loadInvitableAccountTypes;
        mPostViewNotification = postViewNotification;
        mComputeFormattedPhoneNumber = computeFormattedPhoneNumber;
    }

    /**
@@ -379,7 +383,8 @@ public class ContactLoader extends AsyncTaskLoader<Contact> {
                }
                if (!cursor.isNull(ContactQuery.DATA_ID)) {
                    ContentValues data = loadDataValues(cursor);
                    rawContact.addDataItemValues(data);
                    final DataItem item = rawContact.addDataItemValues(data);
                    processDataItem(item);

                    if (!cursor.isNull(ContactQuery.PRESENCE)
                            || !cursor.isNull(ContactQuery.STATUS)) {
@@ -399,6 +404,19 @@ public class ContactLoader extends AsyncTaskLoader<Contact> {
        }
    }

    /**
     * Performs any further computations on the data item
     */
    private void processDataItem(DataItem dataItem) {
        if (dataItem instanceof PhoneDataItem) {
            if (mComputeFormattedPhoneNumber) {
                final PhoneDataItem phoneDataItem = (PhoneDataItem) dataItem;
                final String defaultCountryIso = ContactsUtils.getCurrentCountryIso(getContext());
                phoneDataItem.computeFormattedPhoneNumber(defaultCountryIso);
            }
        }
    }

    /**
     * Looks for the photo data item in entities. If found, creates a new Bitmap instance. If
     * not found, returns null
+10 −4
Original line number Diff line number Diff line
@@ -228,12 +228,18 @@ public class RawContact {
        setAccount(null, null, null);
    }

    public void addDataItemValues(ContentValues values) {
        addNamedDataItemValues(Data.CONTENT_URI, values);
    /**
     * Creates and inserts a DataItem object that wraps the content values, and returns it.
     */
    public DataItem addDataItemValues(ContentValues values) {
        final NamedDataItem namedItem = addNamedDataItemValues(Data.CONTENT_URI, values);
        return namedItem.dataItem;
    }

    public void addNamedDataItemValues(Uri uri, ContentValues values) {
        mDataItems.add(new NamedDataItem(uri, DataItem.createFrom(this, values)));
    public NamedDataItem addNamedDataItemValues(Uri uri, ContentValues values) {
        final NamedDataItem namedItem = new NamedDataItem(uri, DataItem.createFrom(this, values));
        mDataItems.add(namedItem);
        return namedItem;
    }

    public List<DataItem> getDataItems() {
+16 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.contacts.model.dataitem;
import android.content.ContentValues;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.telephony.PhoneNumberUtils;

import com.android.contacts.model.RawContact;

@@ -28,6 +29,8 @@ import com.android.contacts.model.RawContact;
 */
public class PhoneDataItem extends DataItem {

    public static final String KEY_FORMATTED_PHONE_NUMBER = "formattedPhoneNumber";

    /* package */ PhoneDataItem(RawContact rawContact, ContentValues values) {
        super(rawContact, values);
    }
@@ -43,6 +46,10 @@ public class PhoneDataItem extends DataItem {
        return getContentValues().getAsString(Phone.NORMALIZED_NUMBER);
    }

    public String getFormattedPhoneNumber() {
        return getContentValues().getAsString(KEY_FORMATTED_PHONE_NUMBER);
    }

    /**
     * Values are Phone.TYPE_*
     */
@@ -54,4 +61,13 @@ public class PhoneDataItem extends DataItem {
        return getContentValues().getAsString(Phone.LABEL);
    }

    public void computeFormattedPhoneNumber(String defaultCountryIso) {
        final String phoneNumber = getNumber();
        if (phoneNumber != null) {
            final String formattedPhoneNumber = PhoneNumberUtils.formatNumber(phoneNumber,
                    getNormalizedNumber(), defaultCountryIso);
            getContentValues().put(KEY_FORMATTED_PHONE_NUMBER, formattedPhoneNumber);
        }
    }

}
Loading