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

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

Merge change I170c8251 into eclair-mr2

* changes:
  Add tests and fix vCard code.
parents df830fda 99a0a2cd
Loading
Loading
Loading
Loading
+31 −15
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ package android.pim.vcard;
    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
    // Properties both ContactsStruct in Eclair 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";
    public static final String PROPERTY_X_MSN = "X-MSN";
@@ -65,15 +65,12 @@ package android.pim.vcard;
    public static final String PROPERTY_X_JABBER = "X-JABBER";
    public static final String PROPERTY_X_GOOGLE_TALK = "X-GOOGLE-TALK";
    public static final String PROPERTY_X_SKYPE_USERNAME = "X-SKYPE-USERNAME";
    // Properties only ContactsStruct has. We alse use this.
    public static final String PROPERTY_X_QQ = "X-QQ";
    public static final String PROPERTY_X_NETMEETING = "X-NETMEETING";

    // Phone number for Skype, available as usual phone.
    public static final String PROPERTY_X_SKYPE_PSTNNUMBER = "X-SKYPE-PSTNNUMBER";
    // Some device emits this "X-" attribute, which is specifically invalid but should be
    // 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";
@@ -81,6 +78,11 @@ package android.pim.vcard;
    public static final String PROPERTY_X_NO = "X-NO";
    public static final String PROPERTY_X_DCM_HMN_MODE = "X-DCM-HMN-MODE";

    // For some historical reason, we often use the term "ATTR"/"attribute" especially toward
    // what is called "param" in both vCard specs, while vCard, while vCard importer side uses
    // "param".
    //
    // TODO: Confusing. Fix it.
    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
@@ -102,13 +104,19 @@ 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.
    // Abbreviation of "prefered" according to vCard 2.1 specification.
    // We interpret this value as "primary" property during import/export.
    //
    // Note: Both vCard specs does anything about the requirement about this attribute,
    //       but there may be some vCard importer which will get confused with more than
    //       one "PREF"s in one property name, while Android accepts them.
    public static final String ATTR_TYPE_PREF = "PREF";

    // Phone types valid in vCard and known to ContactsContract, but not so common.
    public static final String ATTR_TYPE_CAR = "CAR";
    public static final String ATTR_TYPE_ISDN = "ISDN";
    public static final String ATTR_TYPE_PAGER = "PAGER";
    public static final String ATTR_TYPE_TLX = "TLX";  // Telex

    // Phone types existing in vCard 2.1 but not known to ContactsContract.
    // TODO: should make parser make these TYPE_CUSTOM.
@@ -118,16 +126,16 @@ package android.pim.vcard;
    public static final String ATTR_TYPE_VIDEO = "VIDEO";

    // 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_PHONE_EXTRA_TYPE_OTHER = "OTHER";
    // These types are basically encoded to "X-" attributes when composing vCard.
    // Parser passes these when "X-" is added to the attribute or not.
    public static final String ATTR_PHONE_EXTRA_TYPE_CALLBACK = "CALLBACK";
    // TODO: may be "TYPE=COMPANY,PREF", not "COMPANY-MAIN".
    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";
    // vCard composer translates this type to "WORK" + "PREF". Just for parsing.
    public static final String ATTR_PHONE_EXTRA_TYPE_COMPANY_MAIN = "COMPANY-MAIN";
    // vCard composer translates this type to "VOICE" Just for parsing.
    public static final String ATTR_PHONE_EXTRA_TYPE_OTHER = "OTHER";

    // Attribute for addresses.
    public static final String ATTR_ADR_TYPE_PARCEL = "PARCEL";
@@ -142,6 +150,14 @@ package android.pim.vcard;
    // vCard 3.0.
    public static final String ATTR_TYPE_X_IRMC_N = "X-IRMC-N";

    public interface ImportOnly {
        public static final String PROPERTY_X_NICKNAME = "X-NICKNAME";
        // Some device emits this "X-" attribute for expressing Google Talk,
        // which is specifically invalid but should be 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";
    }

    private Constants() {
    }
}
 No newline at end of file
+34 −23
Original line number Diff line number Diff line
@@ -68,7 +68,8 @@ public class ContactStruct {
        sImMap.put(Constants.PROPERTY_X_JABBER, Im.PROTOCOL_JABBER);
        sImMap.put(Constants.PROPERTY_X_SKYPE_USERNAME, Im.PROTOCOL_SKYPE);
        sImMap.put(Constants.PROPERTY_X_GOOGLE_TALK, Im.PROTOCOL_GOOGLE_TALK);
        sImMap.put(Constants.PROPERTY_X_GOOGLE_TALK_WITH_SPACE, Im.PROTOCOL_GOOGLE_TALK);
        sImMap.put(Constants.ImportOnly.PROPERTY_X_GOOGLE_TALK_WITH_SPACE,
                Im.PROTOCOL_GOOGLE_TALK);
    }
    
    static public class PhoneData {
@@ -292,16 +293,18 @@ public class ContactStruct {
    }
    
    static public class ImData {
        public final int protocol;
        public final String customProtocol;
        public final int type;
        public final String data;
        public final String label;
        public final boolean isPrimary;
        
        // TODO: ContactsConstant#PROTOCOL, ContactsConstant#CUSTOM_PROTOCOL should be used?
        public ImData(int type, String data, String label, boolean isPrimary) {
        public ImData(int protocol, String customProtocol, int type,
                String data, boolean isPrimary) {
            this.protocol = protocol;
            this.customProtocol = customProtocol;
            this.type = type;
            this.data = data;
            this.label = label;
            this.isPrimary = isPrimary;
        }
        
@@ -311,14 +314,18 @@ public class ContactStruct {
                return false;
            }
            ImData imData = (ImData)obj;
            return (type == imData.type && data.equals(imData.data) &&
                    label.equals(imData.label) && isPrimary == imData.isPrimary);
            return (type == imData.type && protocol == imData.protocol
                    && (customProtocol != null ? customProtocol.equals(imData.customProtocol) :
                        (imData.customProtocol == null))
                    && (data != null ? data.equals(imData.data) : (imData.data == null))
                    && isPrimary == imData.isPrimary);
        }
        
        @Override
        public String toString() {
            return String.format("type: %d, data: %s, label: %s, isPrimary: %s",
                    type, data, label, isPrimary);
            return String.format(
                    "type: %d, protocol: %d, custom_protcol: %s, data: %s, isPrimary: %s",
                    type, protocol, customProtocol, data, isPrimary);
        }
    }
    
@@ -440,7 +447,7 @@ public class ContactStruct {
    private final Account mAccount;

    public ContactStruct() {
        this(VCardConfig.VCARD_TYPE_V21_GENERIC);
        this(VCardConfig.VCARD_TYPE_V21_GENERIC_UTF8);
    }

    public ContactStruct(int vcardType) {
@@ -619,11 +626,12 @@ public class ContactStruct {
        addNewOrganization(DEFAULT_ORGANIZATION_TYPE, null, null, title, false);
    }

    private void addIm(int type, String data, String label, boolean isPrimary) {
    private void addIm(int protocol, String customProtocol, int type,
            String propValue, boolean isPrimary) {
        if (mImList == null) {
            mImList = new ArrayList<ImData>();
        }
        mImList.add(new ImData(type, data, label, isPrimary));
        mImList.add(new ImData(protocol, customProtocol, type, propValue, isPrimary));
    }
    
    private void addNote(final String note) {
@@ -720,7 +728,7 @@ public class ContactStruct {
        } else if (propName.equals(Constants.PROPERTY_NICKNAME)) {
            mPhoneticFullName = propValue;
        } else if (propName.equals(Constants.PROPERTY_NICKNAME) ||
                propName.equals(Constants.PROPERTY_X_NICKNAME)) {
                propName.equals(Constants.ImportOnly.PROPERTY_X_NICKNAME)) {
            addNickName(propValue);
        } else if (propName.equals(Constants.PROPERTY_SOUND)) {
            Collection<String> typeCollection = paramMap.get(Constants.ATTR_TYPE);
@@ -892,24 +900,27 @@ public class ContactStruct {
            }
            addPhone(type, propValue, label, isPrimary);
        } else if (sImMap.containsKey(propName)) {
            int type = sImMap.get(propName);
            final int protocol = sImMap.get(propName);
            boolean isPrimary = false;
            int type = -1;
            final Collection<String> typeCollection = paramMap.get(Constants.ATTR_TYPE);
            if (typeCollection != null) {
                for (String typeString : typeCollection) {
                    if (typeString.equals(Constants.ATTR_TYPE_PREF)) {
                        isPrimary = true;
                    } else if (typeString.equalsIgnoreCase(Constants.ATTR_TYPE_HOME)) {
                        type = Phone.TYPE_HOME;
                    } else if (type < 0) {
                        if (typeString.equalsIgnoreCase(Constants.ATTR_TYPE_HOME)) {
                            type = Im.TYPE_HOME;
                        } else if (typeString.equalsIgnoreCase(Constants.ATTR_TYPE_WORK)) {
                        type = Phone.TYPE_WORK;
                            type = Im.TYPE_WORK;
                        }
                    }
                }
            }
            if (type < 0) {
                type = Phone.TYPE_HOME;
            }
            addIm(type, propValue, null, isPrimary);
            addIm(protocol, null, type, propValue, isPrimary);
        } else if (propName.equals(Constants.PROPERTY_NOTE)) {
            addNote(propValue);
        } else if (propName.equals(Constants.PROPERTY_URL)) {
@@ -1158,10 +1169,10 @@ public class ContactStruct {
                builder.withValueBackReference(Im.RAW_CONTACT_ID, 0);
                builder.withValue(Data.MIMETYPE, Im.CONTENT_ITEM_TYPE);
                builder.withValue(Im.TYPE, imData.type);
                if (imData.type == Im.TYPE_CUSTOM) {
                    builder.withValue(Im.LABEL, imData.label);
                builder.withValue(Im.PROTOCOL, imData.protocol);
                if (imData.protocol == Im.PROTOCOL_CUSTOM) {
                    builder.withValue(Im.CUSTOM_PROTOCOL, imData.customProtocol);
                }
                builder.withValue(Im.DATA, imData.data);
                if (imData.isPrimary) {
                    builder.withValue(Data.IS_PRIMARY, 1);
                }
+563 −276

File changed.

Preview size limit exceeded, changes collapsed.

+197 −95

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ public class VCardDataBuilder implements VCardBuilder {
    private List<EntryHandler> mEntryHandlers = new ArrayList<EntryHandler>();
    
    public VCardDataBuilder() {
        this(null, null, false, VCardConfig.VCARD_TYPE_V21_GENERIC, null);
        this(null, null, false, VCardConfig.VCARD_TYPE_V21_GENERIC_UTF8, null);
    }

    /**
Loading