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);
}
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);
}
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());
});
}
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());
}
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"));
}
Aggregations