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

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

Merge change I6ce46417 into eclair-mr2

* changes:
  Clean-up vCard code.
parents 94ab3b6d 021de736
Loading
Loading
Loading
Loading
+65 −12
Original line number Diff line number Diff line
@@ -16,15 +16,46 @@
package android.pim.vcard;

/**
 * Constants used in both composer and parser.
 * Constants used in both exporter and importer code.
 */
/* package */ class Constants {

    public static final String ATTR_TYPE = "TYPE";
    
    public static final String VERSION_V21 = "2.1";
    public static final String VERSION_V30 = "3.0";

    // The property names valid both in vCard 2.1 and 3.0.
    public static final String PROPERTY_BEGIN = "BEGIN";
    public static final String PROPERTY_VERSION = "VERSION";
    public static final String PROPERTY_N = "N";
    public static final String PROPERTY_FN = "FN";
    public static final String PROPERTY_ADR = "ADR";
    public static final String PROPERTY_EMAIL = "EMAIL";
    public static final String PROPERTY_NOTE = "NOTE";
    public static final String PROPERTY_ORG = "ORG";
    public static final String PROPERTY_SOUND = "SOUND";  // Not fully supported.
    public static final String PROPERTY_TEL = "TEL";
    public static final String PROPERTY_TITLE = "TITLE";
    public static final String PROPERTY_ROLE = "ROLE";
    public static final String PROPERTY_PHOTO = "PHOTO";
    public static final String PROPERTY_LOGO = "LOGO";
    public static final String PROPERTY_URL = "URL";
    public static final String PROPERTY_BDAY = "BDAY";  // Birthday
    public static final String PROPERTY_END = "END";

    // Valid property names not supported (not appropriately handled) by our vCard importer now.
    public static final String PROPERTY_REV = "REV";
    public static final String PROPERTY_AGENT = "AGENT";

    // Available in vCard 3.0. Shoud not use when composing vCard 2.1 file.
    public static final String PROPERTY_NAME = "NAME";
    public static final String PROPERTY_NICKNAME = "NICKNAME";
    public static final String PROPERTY_SORT_STRING = "SORT-STRING";
    
    // De-fact property values expressing phonetic names.
    public static final String PROPERTY_X_PHONETIC_FIRST_NAME = "X-PHONETIC-FIRST-NAME";
    public static final String PROPERTY_X_PHONETIC_MIDDLE_NAME = "X-PHONETIC-MIDDLE-NAME";
    public static final String PROPERTY_X_PHONETIC_LAST_NAME = "X-PHONETIC-LAST-NAME";

    // Properties both the current (as of 2009-08-17) ContactsStruct and de-fact vCard extensions
    // shown in http://en.wikipedia.org/wiki/VCard support are defined here.
    public static final String PROPERTY_X_AIM = "X-AIM";
@@ -40,6 +71,18 @@ package android.pim.vcard;
    // always properly accepted, and emitted in some special case (for that device/application).
    public static final String PROPERTY_X_GOOGLE_TALK_WITH_SPACE = "X-GOOGLE TALK";

    // Android specific properties
    // Use only in vCard paser code.
    public static final String PROPERTY_X_NICKNAME = "X-NICKNAME";

    // Properties for DoCoMo vCard.
    public static final String PROPERTY_X_CLASS = "X-CLASS";
    public static final String PROPERTY_X_REDUCTION = "X-REDUCTION";
    public static final String PROPERTY_X_NO = "X-NO";
    public static final String PROPERTY_X_DCM_HMN_MODE = "X-DCM-HMN-MODE";

    public static final String ATTR_TYPE = "TYPE";

    // How more than one TYPE fields are expressed is different between vCard 2.1 and vCard 3.0
    //
    // e.g.
@@ -59,6 +102,7 @@ package android.pim.vcard;
    public static final String ATTR_TYPE_VOICE = "VOICE";
    public static final String ATTR_TYPE_INTERNET = "INTERNET";

    // Abbreviation of "preferable"? We interpret this value as "primary" property.
    public static final String ATTR_TYPE_PREF = "PREF";

    // Phone types valid in vCard and known to ContactsContract, but not so common.
@@ -73,17 +117,26 @@ package android.pim.vcard;
    public static final String ATTR_TYPE_BBS = "BBS";
    public static final String ATTR_TYPE_VIDEO = "VIDEO";

    // Phone types existing in the current Contacts structure but not valid in vCard (at least 2.1)
    // Attribute for Phones, which are not formally valid in vCard (at least 2.1).
    // These types are encoded to "X-" attributes when composing vCard for now.
    // Parser passes these even if "X-" is added to the attribute.
    public static final String ATTR_TYPE_PHONE_EXTRA_OTHER = "OTHER";
    public static final String ATTR_TYPE_PHONE_EXTRA_CALLBACK = "CALLBACK";
    public static final String ATTR_PHONE_EXTRA_TYPE_OTHER = "OTHER";
    public static final String ATTR_PHONE_EXTRA_TYPE_CALLBACK = "CALLBACK";
    // TODO: may be "TYPE=COMPANY,PREF", not "COMPANY-MAIN".
    public static final String ATTR_TYPE_PHONE_EXTRA_COMPANY_MAIN = "COMPANY-MAIN";
    public static final String ATTR_TYPE_PHONE_EXTRA_RADIO = "RADIO";
    public static final String ATTR_TYPE_PHONE_EXTRA_TELEX = "TELEX";
    public static final String ATTR_TYPE_PHONE_EXTRA_TTY_TDD = "TTY-TDD";
    public static final String ATTR_TYPE_PHONE_EXTRA_ASSISTANT = "ASSISTANT";
    public static final String ATTR_PHONE_EXTRA_TYPE_COMPANY_MAIN = "COMPANY-MAIN";
    public static final String ATTR_PHONE_EXTRA_TYPE_RADIO = "RADIO";
    public static final String ATTR_PHONE_EXTRA_TYPE_TELEX = "TELEX";
    public static final String ATTR_PHONE_EXTRA_TYPE_TTY_TDD = "TTY-TDD";
    public static final String ATTR_PHONE_EXTRA_TYPE_ASSISTANT = "ASSISTANT";

    // Attribute for addresses.
    public static final String ATTR_ADR_TYPE_PARCEL = "PARCEL";
    public static final String ATTR_ADR_TYPE_DOM = "DOM";
    public static final String ATTR_ADR_TYPE_INTL = "INTL";

    // Attribute types not officially valid but used in some vCard exporter.
    // Do not use in composer side.
    public static final String ATTR_EXTRA_TYPE_COMPANY = "COMPANY";

    // DoCoMo specific attribute. Used with "SOUND" property, which is alternate of SORT-STRING in
    // vCard 3.0.
+28 −77
Original line number Diff line number Diff line
@@ -71,9 +71,6 @@ public class ContactStruct {
        sImMap.put(Constants.PROPERTY_X_GOOGLE_TALK_WITH_SPACE, Im.PROTOCOL_GOOGLE_TALK);
    }
    
    /**
     * @hide only for testing
     */
    static public class PhoneData {
        public final int type;
        public final String data;
@@ -251,9 +248,6 @@ public class ContactStruct {
        }
    }
    
    /**
     * @hide only for testing.
     */
    static public class OrganizationData {
        public final int type;
        // non-final is Intended: we may change the values since this info is separated into
@@ -328,9 +322,6 @@ public class ContactStruct {
        }
    }
    
    /**
     * @hide only for testing.
     */
    static public class PhotoData {
        public static final String FORMAT_FLASH = "SWF";
        public final int type;
@@ -372,10 +363,6 @@ public class ContactStruct {
        private List<String> mPropertyValueList = new ArrayList<String>();
        private byte[] mPropertyBytes;
        
        public Property() {
            clear();
        }
        
        public void setPropertyName(final String propertyName) {
            mPropertyName = propertyName;
        }
@@ -415,6 +402,7 @@ public class ContactStruct {
            mPropertyName = null;
            mParameterMap.clear();
            mPropertyValueList.clear();
            mPropertyBytes = null;
        }
    }
    
@@ -464,45 +452,6 @@ public class ContactStruct {
        mAccount = account;
    }

    /**
     * @hide only for testing.
     */
    public ContactStruct(String givenName,
            String familyName,
            String middleName,
            String prefix,
            String suffix,
            String phoneticGivenName,
            String pheneticFamilyName,
            String phoneticMiddleName,
            List<String> nicknameList,
            List<byte[]> photoBytesList,
            List<String> noteList,
            List<PhoneData> phoneList, 
            List<EmailData> emailList,
            List<PostalData> postalList,
            List<OrganizationData> organizationList,
            List<ImData> imList,
            List<PhotoData> photoList,
            List<String> websiteList) {
        this(VCardConfig.VCARD_TYPE_DEFAULT);
        mGivenName = givenName;
        mFamilyName = familyName;
        mPrefix = prefix;
        mSuffix = suffix;
        mPhoneticGivenName = givenName;
        mPhoneticFamilyName = familyName;
        mPhoneticMiddleName = middleName;
        mNickNameList = nicknameList;
        mNoteList = noteList;
        mEmailList = emailList;
        mPostalList = postalList;
        mOrganizationList = organizationList;
        mImList = imList;
        mPhotoList = photoList;
        mWebsiteList = websiteList;
    }

    /**
     * Add a phone info to phoneList.
     * @param data phone number
@@ -758,21 +707,22 @@ public class ContactStruct {
        }
        final String propValue = listToString(propValueList).trim();
        
        if (propName.equals("VERSION")) {
        if (propName.equals(Constants.PROPERTY_VERSION)) {
            // vCard version. Ignore this.
        } else if (propName.equals("FN")) {
        } else if (propName.equals(Constants.PROPERTY_FN)) {
            mFullName = propValue;
        } else if (propName.equals("NAME") && mFullName == null) {
        } else if (propName.equals(Constants.PROPERTY_NAME) && mFullName == null) {
            // Only in vCard 3.0. Use this if FN, which must exist in vCard 3.0 but may not
            // actually exist in the real vCard data, does not exist.
            mFullName = propValue;
        } else if (propName.equals("N")) {
        } else if (propName.equals(Constants.PROPERTY_N)) {
            handleNProperty(propValueList);
        } else if (propName.equals("SORT-STRING")) {
        } else if (propName.equals(Constants.PROPERTY_NICKNAME)) {
            mPhoneticFullName = propValue;
        } else if (propName.equals("NICKNAME") || propName.equals("X-NICKNAME")) {
        } else if (propName.equals(Constants.PROPERTY_NICKNAME) ||
                propName.equals(Constants.PROPERTY_X_NICKNAME)) {
            addNickName(propValue);
        } else if (propName.equals("SOUND")) {
        } else if (propName.equals(Constants.PROPERTY_SOUND)) {
            Collection<String> typeCollection = paramMap.get(Constants.ATTR_TYPE);
            if (typeCollection != null && typeCollection.contains(Constants.ATTR_TYPE_X_IRMC_N)) {
                // As of 2009-10-08, Parser side does not split a property value into separated
@@ -786,7 +736,7 @@ public class ContactStruct {
            } else {
                // Ignore this field since Android cannot understand what it is.
            }
        } else if (propName.equals("ADR")) {
        } else if (propName.equals(Constants.PROPERTY_ADR)) {
            boolean valuesAreAllEmpty = true;
            for (String value : propValueList) {
                if (value.length() > 0) {
@@ -811,15 +761,15 @@ public class ContactStruct {
                        type = StructuredPostal.TYPE_HOME;
                        label = "";
                    } else if (typeString.equals(Constants.ATTR_TYPE_WORK) || 
                            typeString.equalsIgnoreCase("COMPANY")) {
                            typeString.equalsIgnoreCase(Constants.ATTR_EXTRA_TYPE_COMPANY)) {
                        // "COMPANY" seems emitted by Windows Mobile, which is not
                        // specifically supported by vCard 2.1. We assume this is same
                        // as "WORK".
                        type = StructuredPostal.TYPE_WORK;
                        label = "";
                    } else if (typeString.equals("PARCEL") || 
                            typeString.equals("DOM") ||
                            typeString.equals("INTL")) {
                    } else if (typeString.equals(Constants.ATTR_ADR_TYPE_PARCEL) ||
                            typeString.equals(Constants.ATTR_ADR_TYPE_DOM) ||
                            typeString.equals(Constants.ATTR_ADR_TYPE_INTL)) {
                        // We do not have any appropriate way to store this information.
                    } else {
                        if (typeString.startsWith("X-") && type < 0) {
@@ -838,7 +788,7 @@ public class ContactStruct {
            }

            addPostal(type, propValueList, label, isPrimary);
        } else if (propName.equals("EMAIL")) {
        } else if (propName.equals(Constants.PROPERTY_EMAIL)) {
            int type = -1;
            String label = null;
            boolean isPrimary = false;
@@ -870,7 +820,7 @@ public class ContactStruct {
                type = Email.TYPE_OTHER;
            }
            addEmail(type, propValue, label, isPrimary);
        } else if (propName.equals("ORG")) {
        } else if (propName.equals(Constants.PROPERTY_ORG)) {
            // vCard specification does not specify other types.
            final int type = Organization.TYPE_WORK;
            boolean isPrimary = false;
@@ -883,12 +833,13 @@ public class ContactStruct {
                }
            }
            handleOrgValue(type, propValueList, isPrimary);
        } else if (propName.equals("TITLE")) {
        } else if (propName.equals(Constants.PROPERTY_TITLE)) {
            handleTitleValue(propValue);
        } else if (propName.equals("ROLE")) {
        } else if (propName.equals(Constants.PROPERTY_ROLE)) {
            // This conflicts with TITLE. Ignore for now...
            // handleTitleValue(propValue);
        } else if (propName.equals("PHOTO") || propName.equals("LOGO")) {
        } else if (propName.equals(Constants.PROPERTY_PHOTO) ||
                propName.equals(Constants.PROPERTY_LOGO)) {
            Collection<String> paramMapValue = paramMap.get("VALUE");
            if (paramMapValue != null && paramMapValue.contains("URL")) {
                // Currently we do not have appropriate example for testing this case.
@@ -907,7 +858,7 @@ public class ContactStruct {
                }
                addPhotoBytes(formatName, propBytes, isPrimary);
            }
        } else if (propName.equals("TEL")) {
        } else if (propName.equals(Constants.PROPERTY_TEL)) {
            final Collection<String> typeCollection = paramMap.get(Constants.ATTR_TYPE);
            final Object typeObject = VCardUtils.getPhoneTypeFromStrings(typeCollection);
            final int type;
@@ -959,20 +910,20 @@ public class ContactStruct {
                type = Phone.TYPE_HOME;
            }
            addIm(type, propValue, null, isPrimary);
        } else if (propName.equals("NOTE")) {
        } else if (propName.equals(Constants.PROPERTY_NOTE)) {
            addNote(propValue);
        } else if (propName.equals("URL")) {
        } else if (propName.equals(Constants.PROPERTY_URL)) {
            if (mWebsiteList == null) {
                mWebsiteList = new ArrayList<String>(1);
            }
            mWebsiteList.add(propValue);
        } else if (propName.equals("X-PHONETIC-FIRST-NAME")) {
        } else if (propName.equals(Constants.PROPERTY_X_PHONETIC_FIRST_NAME)) {
            mPhoneticGivenName = propValue;
        } else if (propName.equals("X-PHONETIC-MIDDLE-NAME")) {
        } else if (propName.equals(Constants.PROPERTY_X_PHONETIC_MIDDLE_NAME)) {
            mPhoneticMiddleName = propValue;
        } else if (propName.equals("X-PHONETIC-LAST-NAME")) {
        } else if (propName.equals(Constants.PROPERTY_X_PHONETIC_LAST_NAME)) {
            mPhoneticFamilyName = propValue;
        } else if (propName.equals("BDAY")) {
        } else if (propName.equals(Constants.PROPERTY_BDAY)) {
            mBirthday = propValue;
        /*} else if (propName.equals("REV")) {                
            // Revision of this VCard entry. I think we can ignore this.
+210 −233

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1
Original line number Diff line number Diff line
@@ -149,7 +149,7 @@ public class VCardParser_V21 extends VCardParser {
    }

    protected String getVersionString() {
        return "2.1";
        return Constants.VERSION_V21;
    }

    /**
+12 −11
Original line number Diff line number Diff line
@@ -61,14 +61,15 @@ public class VCardUtils {
        sKnownPhoneTypesMap_StoI.put(Constants.ATTR_TYPE_WORK, Phone.TYPE_WORK);
        sKnownPhoneTypesMap_StoI.put(Constants.ATTR_TYPE_CELL, Phone.TYPE_MOBILE);
                
        sKnownPhoneTypesMap_StoI.put(Constants.ATTR_TYPE_PHONE_EXTRA_OTHER, Phone.TYPE_OTHER);
        sKnownPhoneTypesMap_StoI.put(Constants.ATTR_TYPE_PHONE_EXTRA_CALLBACK, Phone.TYPE_CALLBACK);
        sKnownPhoneTypesMap_StoI.put(Constants.ATTR_PHONE_EXTRA_TYPE_OTHER, Phone.TYPE_OTHER);
        sKnownPhoneTypesMap_StoI.put(Constants.ATTR_PHONE_EXTRA_TYPE_CALLBACK, Phone.TYPE_CALLBACK);
        sKnownPhoneTypesMap_StoI.put(
                Constants.ATTR_TYPE_PHONE_EXTRA_COMPANY_MAIN, Phone.TYPE_COMPANY_MAIN);
        sKnownPhoneTypesMap_StoI.put(Constants.ATTR_TYPE_PHONE_EXTRA_RADIO, Phone.TYPE_RADIO);
        sKnownPhoneTypesMap_StoI.put(Constants.ATTR_TYPE_PHONE_EXTRA_TELEX, Phone.TYPE_TELEX);
        sKnownPhoneTypesMap_StoI.put(Constants.ATTR_TYPE_PHONE_EXTRA_TTY_TDD, Phone.TYPE_TTY_TDD);
        sKnownPhoneTypesMap_StoI.put(Constants.ATTR_TYPE_PHONE_EXTRA_ASSISTANT, Phone.TYPE_ASSISTANT);
                Constants.ATTR_PHONE_EXTRA_TYPE_COMPANY_MAIN, Phone.TYPE_COMPANY_MAIN);
        sKnownPhoneTypesMap_StoI.put(Constants.ATTR_PHONE_EXTRA_TYPE_RADIO, Phone.TYPE_RADIO);
        sKnownPhoneTypesMap_StoI.put(Constants.ATTR_PHONE_EXTRA_TYPE_TELEX, Phone.TYPE_TELEX);
        sKnownPhoneTypesMap_StoI.put(Constants.ATTR_PHONE_EXTRA_TYPE_TTY_TDD, Phone.TYPE_TTY_TDD);
        sKnownPhoneTypesMap_StoI.put(Constants.ATTR_PHONE_EXTRA_TYPE_ASSISTANT,
                Phone.TYPE_ASSISTANT);

        sPhoneTypesSetUnknownToContacts = new HashSet<String>();
        sPhoneTypesSetUnknownToContacts.add(Constants.ATTR_TYPE_MODEM);