Search in sources :

Example 6 with Photo

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);
}
Also used : Note(ezvcard.property.Note) Photo(ezvcard.property.Photo) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 7 with Photo

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;
}
Also used : Timezone(ezvcard.property.Timezone) UtcOffset(ezvcard.util.UtcOffset) Address(ezvcard.property.Address) Photo(ezvcard.property.Photo) Sound(ezvcard.property.Sound) VCard(ezvcard.VCard) StructuredName(ezvcard.property.StructuredName) File(java.io.File)

Example 8 with Photo

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());
}
Also used : Photo(ezvcard.property.Photo) Document(org.jsoup.nodes.Document) VCard(ezvcard.VCard) Logo(ezvcard.property.Logo) Test(org.junit.Test)

Example 9 with Photo

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);
    }
}
Also used : Photo(ezvcard.property.Photo)

Example 10 with Photo

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));
                    }
                }
            }
        });
    }
}
Also used : RoundedBitmapDrawable(android.support.v4.graphics.drawable.RoundedBitmapDrawable) Drawable(android.graphics.drawable.Drawable) TextDrawable(com.owncloud.android.ui.TextDrawable) RoundedBitmapDrawable(android.support.v4.graphics.drawable.RoundedBitmapDrawable) Photo(ezvcard.property.Photo) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) CheckedTextView(android.widget.CheckedTextView) IOException(java.io.IOException) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Bitmap(android.graphics.Bitmap) VCardToggleEvent(com.owncloud.android.ui.events.VCardToggleEvent) ImageView(android.widget.ImageView) VCard(ezvcard.VCard)

Aggregations

Photo (ezvcard.property.Photo)19 VCard (ezvcard.VCard)14 Test (org.junit.Test)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Bitmap (android.graphics.Bitmap)3 Address (ezvcard.property.Address)3 Note (ezvcard.property.Note)3 Sound (ezvcard.property.Sound)3 StructuredName (ezvcard.property.StructuredName)3 Uid (ezvcard.property.Uid)3 Drawable (android.graphics.drawable.Drawable)2 FormattedName (ezvcard.property.FormattedName)2 Key (ezvcard.property.Key)2 Logo (ezvcard.property.Logo)2 Telephone (ezvcard.property.Telephone)2 Timezone (ezvcard.property.Timezone)2 Url (ezvcard.property.Url)2 VCardAsserter (ezvcard.property.asserter.VCardAsserter)2 TelUri (ezvcard.util.TelUri)2 UtcOffset (ezvcard.util.UtcOffset)2