Search in sources :

Example 1 with RawProperty

use of ezvcard.property.RawProperty in project android by nextcloud.

the class ContactOperations method convertGroupedProperties.

private void convertGroupedProperties(List<NonEmptyContentValues> contentValues, VCard vcard) {
    List<RawProperty> extendedProperties = vcard.getExtendedProperties();
    Map<String, List<RawProperty>> orderedByGroup = orderPropertiesByGroup(extendedProperties);
    final int ABDATE = 1, ABRELATEDNAMES = 2;
    for (List<RawProperty> properties : orderedByGroup.values()) {
        if (properties.size() == 1) {
            continue;
        }
        String label = null;
        String val = null;
        int mime = 0;
        for (RawProperty property : properties) {
            String name = property.getPropertyName();
            if (name.equalsIgnoreCase("X-ABDATE")) {
                // date
                label = property.getValue();
                mime = ABDATE;
                continue;
            }
            if (name.equalsIgnoreCase("X-ABRELATEDNAMES")) {
                // name
                label = property.getValue();
                mime = ABRELATEDNAMES;
                continue;
            }
            if (name.equalsIgnoreCase("X-ABLABEL")) {
                // type of value ..Birthday,anniversary
                val = property.getValue();
                continue;
            }
        }
        NonEmptyContentValues cv = null;
        switch(mime) {
            case ABDATE:
                cv = new NonEmptyContentValues(ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE);
                cv.put(ContactsContract.CommonDataKinds.Event.START_DATE, label);
                int type = DataMappings.getDateType(val);
                cv.put(ContactsContract.CommonDataKinds.Event.TYPE, type);
                break;
            case ABRELATEDNAMES:
                if (val != null) {
                    cv = new NonEmptyContentValues(ContactsContract.CommonDataKinds.Nickname.CONTENT_ITEM_TYPE);
                    cv.put(ContactsContract.CommonDataKinds.Nickname.NAME, label);
                    if (!val.equals("Nickname")) {
                        type = DataMappings.getNameType(val);
                        cv.put(ContactsContract.CommonDataKinds.Relation.TYPE, type);
                    }
                }
                break;
            default:
                continue;
        }
        contentValues.add(cv);
    }
}
Also used : RawProperty(ezvcard.property.RawProperty) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with RawProperty

use of ezvcard.property.RawProperty in project android by nextcloud.

the class ContactOperations method convertName.

private void convertName(List<NonEmptyContentValues> contentValues, VCard vcard) {
    NonEmptyContentValues values = new NonEmptyContentValues(ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);
    String firstName = null, lastName = null, namePrefix = null, nameSuffix = null;
    StructuredName n = vcard.getStructuredName();
    if (n != null) {
        firstName = n.getGiven();
        values.put(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, firstName);
        lastName = n.getFamily();
        values.put(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, lastName);
        List<String> prefixes = n.getPrefixes();
        if (!prefixes.isEmpty()) {
            namePrefix = prefixes.get(0);
            values.put(ContactsContract.CommonDataKinds.StructuredName.PREFIX, namePrefix);
        }
        List<String> suffixes = n.getSuffixes();
        if (!suffixes.isEmpty()) {
            nameSuffix = suffixes.get(0);
            values.put(ContactsContract.CommonDataKinds.StructuredName.SUFFIX, nameSuffix);
        }
    }
    FormattedName fn = vcard.getFormattedName();
    String formattedName = (fn == null) ? null : fn.getValue();
    String displayName;
    if (isEmpty(formattedName)) {
        StringBuilder sb = new StringBuilder();
        if (!isEmpty(namePrefix)) {
            sb.append(namePrefix).append(' ');
        }
        if (!isEmpty(firstName)) {
            sb.append(firstName).append(' ');
        }
        if (!isEmpty(lastName)) {
            sb.append(lastName).append(' ');
        }
        if (!isEmpty(nameSuffix)) {
            if (sb.length() > 0) {
                // delete space character
                sb.deleteCharAt(sb.length() - 1);
                sb.append(", ");
            }
            sb.append(nameSuffix);
        }
        displayName = sb.toString().trim();
    } else {
        displayName = formattedName;
    }
    values.put(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, displayName);
    RawProperty xPhoneticFirstName = vcard.getExtendedProperty("X-PHONETIC-FIRST-NAME");
    String firstPhoneticName = (xPhoneticFirstName == null) ? null : xPhoneticFirstName.getValue();
    values.put(ContactsContract.CommonDataKinds.StructuredName.PHONETIC_GIVEN_NAME, firstPhoneticName);
    RawProperty xPhoneticLastName = vcard.getExtendedProperty("X-PHONETIC-LAST-NAME");
    String lastPhoneticName = (xPhoneticLastName == null) ? null : xPhoneticLastName.getValue();
    values.put(ContactsContract.CommonDataKinds.StructuredName.PHONETIC_FAMILY_NAME, lastPhoneticName);
    contentValues.add(values);
}
Also used : RawProperty(ezvcard.property.RawProperty) FormattedName(ezvcard.property.FormattedName) StructuredName(ezvcard.property.StructuredName)

Example 3 with RawProperty

use of ezvcard.property.RawProperty in project qksms by moezbhatti.

the class ContactOperations method convertName.

private void convertName(List<NonEmptyContentValues> contentValues, VCard vcard) {
    NonEmptyContentValues values = new NonEmptyContentValues(ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);
    String firstName = null, lastName = null, namePrefix = null, nameSuffix = null;
    StructuredName n = vcard.getStructuredName();
    if (n != null) {
        firstName = n.getGiven();
        values.put(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, firstName);
        lastName = n.getFamily();
        values.put(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, lastName);
        List<String> prefixes = n.getPrefixes();
        if (!prefixes.isEmpty()) {
            namePrefix = prefixes.get(0);
            values.put(ContactsContract.CommonDataKinds.StructuredName.PREFIX, namePrefix);
        }
        List<String> suffixes = n.getSuffixes();
        if (!suffixes.isEmpty()) {
            nameSuffix = suffixes.get(0);
            values.put(ContactsContract.CommonDataKinds.StructuredName.SUFFIX, nameSuffix);
        }
    }
    FormattedName fn = vcard.getFormattedName();
    String formattedName = (fn == null) ? null : fn.getValue();
    String displayName;
    if (isEmpty(formattedName)) {
        StringBuilder sb = new StringBuilder();
        if (!isEmpty(namePrefix)) {
            sb.append(namePrefix).append(' ');
        }
        if (!isEmpty(firstName)) {
            sb.append(firstName).append(' ');
        }
        if (!isEmpty(lastName)) {
            sb.append(lastName).append(' ');
        }
        if (!isEmpty(nameSuffix)) {
            if (sb.length() > 0) {
                // delete space character
                sb.deleteCharAt(sb.length() - 1);
                sb.append(", ");
            }
            sb.append(nameSuffix);
        }
        displayName = sb.toString().trim();
    } else {
        displayName = formattedName;
    }
    values.put(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, displayName);
    RawProperty xPhoneticFirstName = vcard.getExtendedProperty("X-PHONETIC-FIRST-NAME");
    String firstPhoneticName = (xPhoneticFirstName == null) ? null : xPhoneticFirstName.getValue();
    values.put(ContactsContract.CommonDataKinds.StructuredName.PHONETIC_GIVEN_NAME, firstPhoneticName);
    RawProperty xPhoneticLastName = vcard.getExtendedProperty("X-PHONETIC-LAST-NAME");
    String lastPhoneticName = (xPhoneticLastName == null) ? null : xPhoneticLastName.getValue();
    values.put(ContactsContract.CommonDataKinds.StructuredName.PHONETIC_FAMILY_NAME, lastPhoneticName);
    contentValues.add(values);
}
Also used : RawProperty(ezvcard.property.RawProperty) FormattedName(ezvcard.property.FormattedName) StructuredName(ezvcard.property.StructuredName)

Example 4 with RawProperty

use of ezvcard.property.RawProperty in project qksms by moezbhatti.

the class ContactOperations method convertIms.

private void convertIms(List<NonEmptyContentValues> contentValues, VCard vcard) {
    // handle extended properties
    for (Map.Entry<String, Integer> entry : DataMappings.getImPropertyNameMappings().entrySet()) {
        String propertyName = entry.getKey();
        Integer protocolType = entry.getValue();
        List<RawProperty> rawProperties = vcard.getExtendedProperties(propertyName);
        for (RawProperty rawProperty : rawProperties) {
            NonEmptyContentValues cv = new NonEmptyContentValues(ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE);
            String value = rawProperty.getValue();
            cv.put(ContactsContract.CommonDataKinds.Im.DATA, value);
            cv.put(ContactsContract.CommonDataKinds.Im.PROTOCOL, protocolType);
            contentValues.add(cv);
        }
    }
    // handle IMPP properties
    for (Impp impp : vcard.getImpps()) {
        NonEmptyContentValues cv = new NonEmptyContentValues(ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE);
        String immpAddress = impp.getHandle();
        cv.put(ContactsContract.CommonDataKinds.Im.DATA, immpAddress);
        int immpProtocolType = DataMappings.getIMTypeFromProtocol(impp.getProtocol());
        cv.put(ContactsContract.CommonDataKinds.Im.PROTOCOL, immpProtocolType);
        contentValues.add(cv);
    }
}
Also used : RawProperty(ezvcard.property.RawProperty) Impp(ezvcard.property.Impp) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with RawProperty

use of ezvcard.property.RawProperty in project ez-vcard by mangstadt.

the class RawPropertyScribe method _parseJson.

@Override
protected RawProperty _parseJson(JCardValue value, VCardDataType dataType, VCardParameters parameters, ParseContext context) {
    String valueStr = jcardValueToString(value);
    RawProperty property = new RawProperty(propertyName, valueStr);
    property.setDataType(dataType);
    return property;
}
Also used : RawProperty(ezvcard.property.RawProperty)

Aggregations

RawProperty (ezvcard.property.RawProperty)22 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)4 VCard (ezvcard.VCard)3 VCardVersion (ezvcard.VCardVersion)3 FormattedName (ezvcard.property.FormattedName)3 Impp (ezvcard.property.Impp)3 VCardProperty (ezvcard.property.VCardProperty)3 LuckyNumProperty (ezvcard.io.LuckyNumProperty)2 LuckyNumScribe (ezvcard.io.LuckyNumProperty.LuckyNumScribe)2 Label (ezvcard.property.Label)2 ProductId (ezvcard.property.ProductId)2 StructuredName (ezvcard.property.StructuredName)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 VCardDataType (ezvcard.VCardDataType)1 AgeProperty (ezvcard.io.AgeProperty)1 AgeScribe (ezvcard.io.AgeProperty.AgeScribe)1 CannotParseException (ezvcard.io.CannotParseException)1