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

Commit a184d4b9 authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change I11526e6c into eclair-mr2

* changes:
  Clean up codes and remove/modify stale codes/comments.
parents c0b0ad21 d2145b97
Loading
Loading
Loading
Loading
+14 −13
Original line number Diff line number Diff line
@@ -89,7 +89,7 @@ public class VCardBuilder {
    private final boolean mIsJapaneseMobilePhone;
    private final boolean mOnlyOneNoteFieldIsAvailable;
    private final boolean mIsDoCoMo;
    private final boolean mUsesQuotedPrintable;
    private final boolean mShouldUseQuotedPrintable;
    private final boolean mUsesAndroidProperty;
    private final boolean mUsesDefactProperty;
    private final boolean mUsesUtf8;
@@ -110,7 +110,7 @@ public class VCardBuilder {
        mVCardType = vcardType;

        mIsV30 = VCardConfig.isV30(vcardType);
        mUsesQuotedPrintable = VCardConfig.usesQuotedPrintable(vcardType);
        mShouldUseQuotedPrintable = VCardConfig.shouldUseQuotedPrintable(vcardType);
        mIsDoCoMo = VCardConfig.isDoCoMo(vcardType);
        mIsJapaneseMobilePhone = VCardConfig.needsToConvertPhoneticString(vcardType);
        mOnlyOneNoteFieldIsAvailable = VCardConfig.onlyOneNoteFieldIsAvailable(vcardType);
@@ -529,7 +529,7 @@ public class VCardBuilder {
        if (mUsesDefactProperty) {
            if (!TextUtils.isEmpty(phoneticGivenName)) {
                final boolean reallyUseQuotedPrintable =
                    (mUsesQuotedPrintable &&
                    (mShouldUseQuotedPrintable &&
                            !VCardUtils.containsOnlyNonCrLfPrintableAscii(phoneticGivenName));
                final String encodedPhoneticGivenName;
                if (reallyUseQuotedPrintable) {
@@ -552,7 +552,7 @@ public class VCardBuilder {
            }
            if (!TextUtils.isEmpty(phoneticMiddleName)) {
                final boolean reallyUseQuotedPrintable =
                    (mUsesQuotedPrintable &&
                    (mShouldUseQuotedPrintable &&
                            !VCardUtils.containsOnlyNonCrLfPrintableAscii(phoneticMiddleName));
                final String encodedPhoneticMiddleName;
                if (reallyUseQuotedPrintable) {
@@ -575,7 +575,7 @@ public class VCardBuilder {
            }
            if (!TextUtils.isEmpty(phoneticFamilyName)) {
                final boolean reallyUseQuotedPrintable =
                    (mUsesQuotedPrintable &&
                    (mShouldUseQuotedPrintable &&
                            !VCardUtils.containsOnlyNonCrLfPrintableAscii(phoneticFamilyName));
                final String encodedPhoneticFamilyName;
                if (reallyUseQuotedPrintable) {
@@ -846,7 +846,7 @@ public class VCardBuilder {
                if (!appendCharset && !VCardUtils.containsOnlyPrintableAscii(data)) {
                    appendCharset = true;
                }
                if (mUsesQuotedPrintable &&
                if (mShouldUseQuotedPrintable &&
                        !VCardUtils.containsOnlyNonCrLfPrintableAscii(data)) {
                    reallyUseQuotedPrintable = true;
                    break;
@@ -1017,13 +1017,13 @@ public class VCardBuilder {
                final String orgline = orgBuilder.toString();
                appendLine(VCardConstants.PROPERTY_ORG, orgline,
                        !VCardUtils.containsOnlyPrintableAscii(orgline),
                        (mUsesQuotedPrintable &&
                        (mShouldUseQuotedPrintable &&
                                !VCardUtils.containsOnlyNonCrLfPrintableAscii(orgline)));

                if (!TextUtils.isEmpty(title)) {
                    appendLine(VCardConstants.PROPERTY_TITLE, title,
                            !VCardUtils.containsOnlyPrintableAscii(title),
                            (mUsesQuotedPrintable &&
                            (mShouldUseQuotedPrintable &&
                                    !VCardUtils.containsOnlyNonCrLfPrintableAscii(title)));
                }
            }
@@ -1094,7 +1094,7 @@ public class VCardBuilder {
                final boolean shouldAppendCharsetInfo =
                    !VCardUtils.containsOnlyPrintableAscii(noteStr);
                final boolean reallyUseQuotedPrintable =
                        (mUsesQuotedPrintable &&
                        (mShouldUseQuotedPrintable &&
                            !VCardUtils.containsOnlyNonCrLfPrintableAscii(noteStr));
                appendLine(VCardConstants.PROPERTY_NOTE, noteStr,
                        shouldAppendCharsetInfo, reallyUseQuotedPrintable);
@@ -1105,7 +1105,7 @@ public class VCardBuilder {
                        final boolean shouldAppendCharsetInfo =
                                !VCardUtils.containsOnlyPrintableAscii(noteStr);
                        final boolean reallyUseQuotedPrintable =
                                (mUsesQuotedPrintable &&
                                (mShouldUseQuotedPrintable &&
                                    !VCardUtils.containsOnlyNonCrLfPrintableAscii(noteStr));
                        appendLine(VCardConstants.PROPERTY_NOTE, noteStr,
                                shouldAppendCharsetInfo, reallyUseQuotedPrintable);
@@ -1541,9 +1541,10 @@ public class VCardBuilder {
    public void appendLineWithCharsetAndQPDetection(final String propertyName,
            final List<String> parameterList, final String rawValue) {
        final boolean needCharset =
            (mUsesQuotedPrintable && !VCardUtils.containsOnlyPrintableAscii(rawValue));
                !VCardUtils.containsOnlyPrintableAscii(rawValue);
        final boolean reallyUseQuotedPrintable =
            !VCardUtils.containsOnlyNonCrLfPrintableAscii(rawValue);
                (mShouldUseQuotedPrintable &&
                        !VCardUtils.containsOnlyNonCrLfPrintableAscii(rawValue));
        appendLine(propertyName, parameterList,
                rawValue, needCharset, reallyUseQuotedPrintable);
    }
@@ -1553,7 +1554,7 @@ public class VCardBuilder {
        boolean needCharset = false;
        boolean reallyUseQuotedPrintable = false;
        for (String rawValue : rawValueList) {
            if (!needCharset && mUsesQuotedPrintable &&
            if (!needCharset && mShouldUseQuotedPrintable &&
                    !VCardUtils.containsOnlyPrintableAscii(rawValue)) {
                needCharset = true;
            }
+5 −12
Original line number Diff line number Diff line
@@ -27,10 +27,7 @@ import java.util.Set;
 * but in VCardUtils.
 */
public class VCardConfig {
    private static final String LOG_TAG = "vcard.VCardConfig";

    // TODO: may be better to make the instance of this available and stop using static methods and
    //        one integer. 
    private static final String LOG_TAG = "VCardConfig";

    /* package */ static final int LOG_LEVEL_NONE = 0;
    /* package */ static final int LOG_LEVEL_PERFORMANCE_MEASUREMENT = 0x1;
@@ -44,9 +41,6 @@ public class VCardConfig {
    // decode the unicode to the original charset. If not, this setting will cause some bug. 
    public static final String DEFAULT_CHARSET = "iso-8859-1";
    
    // TODO: make the other codes use this flag
    public static final boolean IGNORE_CASE_EXCEPT_VALUE = true;
    
    public static final int FLAG_V21 = 0;
    public static final int FLAG_V30 = 1;

@@ -319,7 +313,7 @@ public class VCardConfig {
                FLAG_CONVERT_PHONETIC_NAME_STRINGS |
                FLAG_REFRAIN_QP_TO_PRIMARY_PROPERTIES);

    public static final String VCARD_TYPE_V21_JAPANESE_MOBILE_STR = "v21_japanese_mobile";
    /* package */ static final String VCARD_TYPE_V21_JAPANESE_MOBILE_STR = "v21_japanese_mobile";

    /**
     * <P>
@@ -334,7 +328,7 @@ public class VCardConfig {
    public static final int VCARD_TYPE_DOCOMO =
        (VCARD_TYPE_V21_JAPANESE_MOBILE | FLAG_DOCOMO);

    private static final String VCARD_TYPE_DOCOMO_STR = "docomo";
    /* package */ static final String VCARD_TYPE_DOCOMO_STR = "docomo";
    
    public static int VCARD_TYPE_DEFAULT = VCARD_TYPE_V21_GENERIC_UTF8;

@@ -369,7 +363,6 @@ public class VCardConfig {
        if (sVCardTypeMap.containsKey(loweredKey)) {
            return sVCardTypeMap.get(loweredKey);
        } else {
            // XXX: should return the value indicating the input is invalid?
            Log.e(LOG_TAG, "Unknown vCard type String: \"" + vcardTypeString + "\"");
            return VCARD_TYPE_DEFAULT;
        }
@@ -379,7 +372,7 @@ public class VCardConfig {
        return ((vcardType & FLAG_V30) != 0);  
    }

    public static boolean usesQuotedPrintable(final int vcardType) {
    public static boolean shouldUseQuotedPrintable(final int vcardType) {
        return !isV30(vcardType);
    }

@@ -408,7 +401,7 @@ public class VCardConfig {
    }

    public static boolean refrainsQPToPrimaryProperties(final int vcardType) {
       return (!usesQuotedPrintable(vcardType) ||
       return (!shouldUseQuotedPrintable(vcardType) ||
               ((vcardType & FLAG_REFRAIN_QP_TO_PRIMARY_PROPERTIES) != 0));
    }

+53 −74
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import android.util.Log;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -57,11 +58,11 @@ import java.util.Map;
public class VCardEntry {
    private static final String LOG_TAG = "VCardEntry";

    private final static int DEFAULT_ORGANIZATION_TYPE = Organization.TYPE_WORK;

    private static final String ACCOUNT_TYPE_GOOGLE = "com.google";
    private static final String GOOGLE_MY_CONTACTS_GROUP = "System Group: My Contacts";

    // Key: the name shown in VCard. e.g. "X-AIM", "X-ICQ"
    // Value: the result of {@link Contacts.ContactMethods#encodePredefinedImProtocol}
    private static final Map<String, Integer> sImMap = new HashMap<String, Integer>();

    static {
@@ -107,9 +108,6 @@ public class VCardEntry {
        }
    }

    /**
     * @hide only for testing
     */
    static public class EmailData {
        public final int type;
        public final String data;
@@ -154,17 +152,12 @@ public class VCardEntry {
        public final String region;
        public final String postalCode;
        public final String country;

        public final int type;
        
        // Used only when type variable is TYPE_CUSTOM.
        public final String label;

        // isPrimary is changable only when there's no appropriate one existing in
        // the original VCard.
        public boolean isPrimary;
        public PostalData(int type, List<String> propValueList,
                String label, boolean isPrimary) {

        public PostalData(final int type, final List<String> propValueList,
                final String label, boolean isPrimary) {
            this.type = type;
            dataArray = new String[ADDR_MAX_DATA_SIZE];

@@ -197,7 +190,6 @@ public class VCardEntry {
            this.region = dataArray[4];
            this.postalCode = dataArray[5];
            this.country = dataArray[6];
            
            this.label = label;
            this.isPrimary = isPrimary;
        }
@@ -207,7 +199,7 @@ public class VCardEntry {
            if (!(obj instanceof PostalData)) {
                return false;
            }
            PostalData postalData = (PostalData)obj;
            final PostalData postalData = (PostalData)obj;
            return (Arrays.equals(dataArray, postalData.dataArray) && 
                    (type == postalData.type &&
                            (type == StructuredPostal.TYPE_CUSTOM ?
@@ -215,7 +207,7 @@ public class VCardEntry {
                    (isPrimary == postalData.isPrimary));
        }

        public String getFormattedAddress(int vcardType) {
        public String getFormattedAddress(final int vcardType) {
            StringBuilder builder = new StringBuilder();
            boolean empty = true;
            if (VCardConfig.isJapaneseDevice(vcardType)) {
@@ -225,9 +217,10 @@ public class VCardEntry {
                    if (!TextUtils.isEmpty(addressPart)) {
                        if (!empty) {
                            builder.append(' ');
                        } else {
                            empty = false;
                        }
                        builder.append(addressPart);
                        empty = false;
                    }
                }
            } else {
@@ -236,9 +229,10 @@ public class VCardEntry {
                    if (!TextUtils.isEmpty(addressPart)) {
                        if (!empty) {
                            builder.append(' ');
                        } else {
                            empty = false;
                        }
                        builder.append(addressPart);
                        empty = false;
                    }
                }
            }
@@ -255,14 +249,13 @@ public class VCardEntry {

    static public class OrganizationData {
        public final int type;
        // non-final is Intended: we may change the values since this info is separated into
        // non-final is Intentional: we may change the values since this info is separated into
        // two parts in vCard: "ORG" + "TITLE".
        public String companyName;
        public String departmentName;
        public String titleName;
        // isPrimary is changable only when there's no appropriate one existing in
        // the original VCard.
        public boolean isPrimary;

        public OrganizationData(int type,
                String companyName,
                String departmentName,
@@ -303,8 +296,8 @@ public class VCardEntry {
        public final String data;
        public final boolean isPrimary;

        public ImData(int protocol, String customProtocol, int type,
                String data, boolean isPrimary) {
        public ImData(final int protocol, final String customProtocol, final int type,
                final String data, final boolean isPrimary) {
            this.protocol = protocol;
            this.customProtocol = customProtocol;
            this.type = type;
@@ -333,7 +326,7 @@ public class VCardEntry {
        }
    }
    
    static public class PhotoData {
    public static class PhotoData {
        public static final String FORMAT_FLASH = "SWF";
        public final int type;
        public final String formatName;  // used when type is not defined in ContactsContract.
@@ -367,7 +360,7 @@ public class VCardEntry {
        }
    }
    
    static /* package */ class Property {
    /* package */ static class Property {
        private String mPropertyName;
        private Map<String, Collection<String>> mParameterMap =
            new HashMap<String, Collection<String>>();
@@ -464,18 +457,12 @@ public class VCardEntry {
        mAccount = account;
    }

    /**
     * Add a phone info to phoneList.
     * @param data phone number
     * @param type type col of content://contacts/phones
     * @param label lable col of content://contacts/phones
     */
    private void addPhone(int type, String data, String label, boolean isPrimary) {
        if (mPhoneList == null) {
            mPhoneList = new ArrayList<PhoneData>();
        }
        StringBuilder builder = new StringBuilder();
        String trimed = data.trim();
        final StringBuilder builder = new StringBuilder();
        final String trimed = data.trim();
        final String formattedNumber;
        if (type == Phone.TYPE_PAGER) {
            formattedNumber = trimed;
@@ -532,13 +519,15 @@ public class VCardEntry {
                departmentName, titleName, isPrimary));
    }

    private static final List<String> sEmptyList = new ArrayList<String>(0);
    private static final List<String> sEmptyList =
            Collections.unmodifiableList(new ArrayList<String>(0));

    /**
     * Set "ORG" related values to the appropriate data. If there's more than one
     * OrganizationData objects, this input data are attached to the last one which does not
     * have valid values (not including empty but only null). If there's no
     * OrganizationData object, a new OrganizationData is created, whose title is set to null.
     * {@link OrganizationData} objects, this input data are attached to the last one which
     * does not have valid values (not including empty but only null). If there's no
     * {@link OrganizationData} object, a new {@link OrganizationData} is created,
     * whose title is set to null.
     */
    private void handleOrgValue(final int type, List<String> orgList, boolean isPrimary) {
        if (orgList == null) {
@@ -596,8 +585,6 @@ public class VCardEntry {
        addNewOrganization(type, companyName, departmentName, null, isPrimary);
    }

    private final static int DEFAULT_ORGANIZATION_TYPE = Organization.TYPE_WORK;

    /**
     * Set "title" value to the appropriate data. If there's more than one
     * OrganizationData objects, this input is attached to the last one which does not
@@ -659,21 +646,16 @@ public class VCardEntry {

        switch (size) {
            // fallthrough
        case 5:
            mSuffix = elems.get(4);
        case 4:
            mPrefix = elems.get(3);
        case 3:
            mMiddleName = elems.get(2);
        case 2:
            mGivenName = elems.get(1);
        default:
            mFamilyName = elems.get(0);
            case 5: mSuffix = elems.get(4);
            case 4: mPrefix = elems.get(3);
            case 3: mMiddleName = elems.get(2);
            case 2: mGivenName = elems.get(1);
            default: mFamilyName = elems.get(0);
        }
    }

    /**
     * Some Japanese mobile phones use this field for phonetic name,
     * Note: Some Japanese mobile phones use this field for phonetic name,
     *       since vCard 2.1 does not have "SORT-STRING" type.
     *       Also, in some cases, the field has some ';'s in it.
     *       Assume the ';' means the same meaning in N property
@@ -729,17 +711,14 @@ public class VCardEntry {

        switch (size) {
            // fallthrough
        case 3:
            mPhoneticMiddleName = elems.get(2);
        case 2:
            mPhoneticGivenName = elems.get(1);
        default:
            mPhoneticFamilyName = elems.get(0);
            case 3: mPhoneticMiddleName = elems.get(2);
            case 2: mPhoneticGivenName = elems.get(1);
            default: mPhoneticFamilyName = elems.get(0);
        }
    }

    public void addProperty(Property property) {
        String propName = property.mPropertyName;
    public void addProperty(final Property property) {
        final String propName = property.mPropertyName;
        final Map<String, Collection<String>> paramMap = property.mParameterMap;
        final List<String> propValueList = property.mPropertyValueList;
        byte[] propBytes = property.mPropertyBytes;
+10 −7
Original line number Diff line number Diff line
@@ -19,17 +19,20 @@ import android.content.ContentResolver;
import android.util.Log;

/**
 * EntryHandler implementation which commits the entry to ContentResolver.
 *
 * Note:
 * <P>
 * {@link VCardEntryHandler} implementation which commits the entry to ContentResolver.
 * </P>
 * <P>
 * Note:<BR />
 * Each vCard may contain big photo images encoded by BASE64,
 * If we store all vCard entries in memory, OutOfMemoryError may be thrown.
 * Thus, this class push each VCard entry into ContentResolver immediately.
 * </P>
 */
public class VCardEntryCommitter implements VCardEntryHandler {
    public static String LOG_TAG = "vcard.EntryComitter";
    public static String LOG_TAG = "VCardEntryComitter";

    private ContentResolver mContentResolver;
    private final ContentResolver mContentResolver;
    private long mTimeToCommit;

    public VCardEntryCommitter(ContentResolver resolver) {
+51 −74

File changed.

Preview size limit exceeded, changes collapsed.

Loading