Search in sources :

Example 1 with FormattedName

use of ezvcard.property.FormattedName 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 2 with FormattedName

use of ezvcard.property.FormattedName 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 3 with FormattedName

use of ezvcard.property.FormattedName in project ring-client-android by savoirfairelinux.

the class AccountWizardActivity method saveProfile.

@Override
public void saveProfile(final String accountID, final RingAccountViewModel ringAccountViewModel) {
    runOnUiThread(() -> {
        RingAccountViewModelImpl ringAccountViewModelImpl = (RingAccountViewModelImpl) ringAccountViewModel;
        VCard vcard = new VCard();
        vcard.setFormattedName(new FormattedName(ringAccountViewModelImpl.getFullName()));
        vcard.setUid(new Uid(ringAccountViewModelImpl.getUsername()));
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        if (ringAccountViewModelImpl.getPhoto() != null) {
            ringAccountViewModelImpl.getPhoto().compress(Bitmap.CompressFormat.PNG, 100, stream);
            Photo photoVCard = new Photo(stream.toByteArray(), ImageType.PNG);
            vcard.removeProperties(Photo.class);
            vcard.addPhoto(photoVCard);
        }
        vcard.removeProperties(RawProperty.class);
        VCardUtils.saveLocalProfileToDisk(vcard, accountID, getFilesDir());
    });
}
Also used : Uid(ezvcard.property.Uid) FormattedName(ezvcard.property.FormattedName) Photo(ezvcard.property.Photo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) VCard(ezvcard.VCard)

Example 4 with FormattedName

use of ezvcard.property.FormattedName in project ring-client-android by savoirfairelinux.

the class SIPCreationPresenter method saveProfile.

private void saveProfile(String accountID) {
    VCard vcard = new VCard();
    String formattedName = mAccount.getUsername();
    if (formattedName.isEmpty()) {
        formattedName = mAccount.getAlias();
    }
    vcard.setFormattedName(new FormattedName(formattedName));
    String vcardUid = formattedName + accountID;
    vcard.setUid(new Uid(vcardUid));
    vcard.removeProperties(RawProperty.class);
    VCardUtils.saveLocalProfileToDisk(vcard, accountID, mDeviceService.provideFilesDir());
}
Also used : Uid(ezvcard.property.Uid) FormattedName(ezvcard.property.FormattedName) VCard(ezvcard.VCard)

Example 5 with FormattedName

use of ezvcard.property.FormattedName in project ring-client-android by savoirfairelinux.

the class VCardUtilsTest method testVCardToString.

@Test
public void testVCardToString() {
    VCard vcard = new VCard();
    vcard.addFormattedName(new FormattedName("SFL Test"));
    String result = VCardUtils.vcardToString(vcard);
    assertTrue(result.contentEquals("BEGIN:VCARD\r\n" + "VERSION:2.1\r\n" + "X-PRODID:ez-vcard 0.10.2\r\n" + "FN:SFL Test\r\n" + "END:VCARD\r\n"));
}
Also used : FormattedName(ezvcard.property.FormattedName) VCard(ezvcard.VCard) Test(org.junit.Test)

Aggregations

FormattedName (ezvcard.property.FormattedName)19 Test (org.junit.Test)11 VCard (ezvcard.VCard)6 RawProperty (ezvcard.property.RawProperty)3 StructuredName (ezvcard.property.StructuredName)3 Uid (ezvcard.property.Uid)3 Photo (ezvcard.property.Photo)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Bitmap (android.graphics.Bitmap)1 RingAccountViewModelImpl (cx.ring.account.RingAccountViewModelImpl)1 VCardVersion (ezvcard.VCardVersion)1 VCardReader (ezvcard.io.text.VCardReader)1 AddressType (ezvcard.parameter.AddressType)1 EmailType (ezvcard.parameter.EmailType)1 TelephoneType (ezvcard.parameter.TelephoneType)1 Address (ezvcard.property.Address)1 Email (ezvcard.property.Email)1 Note (ezvcard.property.Note)1 ProductId (ezvcard.property.ProductId)1 Telephone (ezvcard.property.Telephone)1