use of ezvcard.property.Photo in project ez-vcard by mangstadt.
the class XCardWriterTest method write_group.
@Test
public void write_group() throws Exception {
VCard vcard = new VCard();
vcard.setFormattedName("John Doe");
Note note = vcard.addNote("This is a\nnote.");
note.setGroup("group1");
note.setLanguage("en");
Photo photo = new Photo("http://example.com/image.jpg", ImageType.JPEG);
photo.setGroup("group1");
vcard.addPhoto(photo);
note = new Note("Bonjour.");
note.setGroup("group2");
vcard.addNote(note);
writer.write(vcard);
writer.close();
// @formatter:off
String expected = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + "<fn><text>John Doe</text></fn>" + "<group name=\"group1\">" + "<photo>" + "<parameters>" + "<mediatype><text>image/jpeg</text></mediatype>" + "</parameters>" + "<uri>http://example.com/image.jpg</uri>" + "</photo>" + "<note>" + "<parameters>" + "<language><language-tag>en</language-tag></language>" + "</parameters>" + "<text>This is a\nnote.</text>" + "</note>" + "</group>" + "<group name=\"group2\">" + "<note><text>Bonjour.</text></note>" + "</group>" + "</vcard>" + "</vcards>";
// @formatter:on
assertOutput(expected);
}
use of ezvcard.property.Photo in project ez-vcard by mangstadt.
the class JohnDoeVCard method createVCard.
private static VCard createVCard() throws IOException {
VCard vcard = new VCard();
vcard.setKind(Kind.individual());
vcard.setGender(Gender.male());
vcard.addLanguage("en-US");
StructuredName n = new StructuredName();
n.setFamily("Doe");
n.setGiven("Jonathan");
n.getPrefixes().add("Mr");
vcard.setStructuredName(n);
vcard.setFormattedName("Jonathan Doe");
vcard.setNickname("John", "Jonny");
vcard.addTitle("Widget Engineer");
vcard.setOrganization("Acme Co. Ltd.", "Widget Department");
Address adr = new Address();
adr.setStreetAddress("123 Wall St.");
adr.setLocality("New York");
adr.setRegion("NY");
adr.setPostalCode("12345");
adr.setCountry("USA");
adr.setLabel("123 Wall St.\nNew York, NY 12345\nUSA");
adr.getTypes().add(AddressType.WORK);
vcard.addAddress(adr);
adr = new Address();
adr.setStreetAddress("123 Main St.");
adr.setLocality("Albany");
adr.setRegion("NY");
adr.setPostalCode("54321");
adr.setCountry("USA");
adr.setLabel("123 Main St.\nAlbany, NY 54321\nUSA");
adr.getTypes().add(AddressType.HOME);
vcard.addAddress(adr);
vcard.addTelephoneNumber("1-555-555-1234", TelephoneType.WORK);
vcard.addTelephoneNumber("1-555-555-5678", TelephoneType.WORK, TelephoneType.CELL);
vcard.addEmail("johndoe@hotmail.com", EmailType.HOME);
vcard.addEmail("doe.john@acme.com", EmailType.WORK);
vcard.addUrl("http://www.acme-co.com");
vcard.setCategories("widgetphile", "biker", "vCard expert");
vcard.setGeo(37.6, -95.67);
vcard.setTimezone(new Timezone(new UtcOffset(false, -5, 0), "America/New_York"));
File file = new File("portrait.jpg");
Photo photo = new Photo(file, ImageType.JPEG);
vcard.addPhoto(photo);
file = new File("pronunciation.ogg");
Sound sound = new Sound(file, SoundType.OGG);
vcard.addSound(sound);
vcard.setUid(Uid.random());
vcard.setRevision(Revision.now());
return vcard;
}
use of ezvcard.property.Photo in project ez-vcard by mangstadt.
the class HCardPageTest method logic_for_displaying_a_photo.
@Test
public void logic_for_displaying_a_photo() throws Exception {
VCard vcard = new VCard();
Document document = generate(vcard);
assertTrue(document.select(".vcard .photo").isEmpty());
assertTrue(document.select(".vcard .logo").isEmpty());
vcard = new VCard();
Photo photo = new Photo(mockData, ImageType.JPEG);
vcard.addPhoto(photo);
document = generate(vcard);
assertEquals(1, document.select(".vcard .photo").size());
assertTrue(document.select(".vcard .logo").isEmpty());
vcard = new VCard();
Logo logo = new Logo(mockData, ImageType.PNG);
vcard.addLogo(logo);
document = generate(vcard);
assertTrue(document.select(".vcard .photo").isEmpty());
assertEquals(1, document.select(".vcard .logo").size());
vcard = new VCard();
photo = new Photo(mockData, ImageType.JPEG);
vcard.addPhoto(photo);
logo = new Logo(mockData, ImageType.PNG);
vcard.addLogo(logo);
document = generate(vcard);
assertEquals(1, document.select(".vcard .photo").size());
assertTrue(document.select(".vcard .logo").isEmpty());
}
use of ezvcard.property.Photo in project qksms by moezbhatti.
the class ContactOperations method convertPhotos.
private void convertPhotos(List<NonEmptyContentValues> contentValues, VCard vcard) {
for (Photo photo : vcard.getPhotos()) {
byte[] data = photo.getData();
NonEmptyContentValues cv = new NonEmptyContentValues(ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE);
cv.put(ContactsContract.CommonDataKinds.Photo.PHOTO, data);
contentValues.add(cv);
}
}
use of ezvcard.property.Photo in project android by nextcloud.
the class ContactListAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final ContactListFragment.ContactItemViewHolder holder, final int position) {
final int verifiedPosition = holder.getAdapterPosition();
final VCard vcard = vCards.get(verifiedPosition);
if (vcard != null) {
if (checkedVCards.contains(position)) {
holder.getName().setChecked(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
holder.getName().getCheckMarkDrawable().setColorFilter(ThemeUtils.primaryAccentColor(), PorterDuff.Mode.SRC_ATOP);
}
} else {
holder.getName().setChecked(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
holder.getName().getCheckMarkDrawable().clearColorFilter();
}
}
holder.getName().setText(getDisplayName(vcard));
// photo
if (vcard.getPhotos().size() > 0) {
Photo firstPhoto = vcard.getPhotos().get(0);
String url = firstPhoto.getUrl();
byte[] data = firstPhoto.getData();
if (data != null && data.length > 0) {
Bitmap thumbnail = BitmapFactory.decodeByteArray(data, 0, data.length);
RoundedBitmapDrawable drawable = BitmapUtils.bitmapToCircularBitmapDrawable(context.getResources(), thumbnail);
holder.getBadge().setImageDrawable(drawable);
} else if (url != null) {
ImageView badge = holder.getBadge();
SimpleTarget target = new SimpleTarget<Drawable>() {
@Override
public void onResourceReady(Drawable resource, GlideAnimation glideAnimation) {
holder.getBadge().setImageDrawable(resource);
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
super.onLoadFailed(e, errorDrawable);
holder.getBadge().setImageDrawable(errorDrawable);
}
};
DisplayUtils.downloadIcon(context, url, target, R.drawable.ic_user, badge.getWidth(), badge.getHeight());
}
} else {
try {
holder.getBadge().setImageDrawable(TextDrawable.createNamedAvatar(holder.getName().getText().toString(), context.getResources().getDimension(R.dimen.list_item_avatar_icon_radius)));
} catch (Exception e) {
holder.getBadge().setImageResource(R.drawable.ic_user);
}
}
// Checkbox
holder.setVCardListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
holder.getName().setChecked(!holder.getName().isChecked());
if (holder.getName().isChecked()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
holder.getName().getCheckMarkDrawable().setColorFilter(ThemeUtils.primaryAccentColor(), PorterDuff.Mode.SRC_ATOP);
}
if (!checkedVCards.contains(verifiedPosition)) {
checkedVCards.add(verifiedPosition);
}
if (checkedVCards.size() == 1) {
EventBus.getDefault().post(new VCardToggleEvent(true));
}
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
holder.getName().getCheckMarkDrawable().clearColorFilter();
}
if (checkedVCards.contains(verifiedPosition)) {
checkedVCards.remove(verifiedPosition);
}
if (checkedVCards.size() == 0) {
EventBus.getDefault().post(new VCardToggleEvent(false));
}
}
}
});
}
}
Aggregations