Search in sources :

Example 11 with Photo

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

the class ContactOperations method convertPhotos.

private void convertPhotos(List<NonEmptyContentValues> contentValues, VCard vcard) {
    for (Photo photo : vcard.getPhotos()) {
        if (photo.getUrl() != null) {
            downloadPhoto(photo);
        }
        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 12 with Photo

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

the class TVAccountWizard 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) {
            Bitmap reduced = BitmapUtils.reduceBitmap(ringAccountViewModelImpl.getPhoto(), VCardUtils.VCARD_PHOTO_SIZE);
            reduced.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) Bitmap(android.graphics.Bitmap) FormattedName(ezvcard.property.FormattedName) Photo(ezvcard.property.Photo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RingAccountViewModelImpl(cx.ring.account.RingAccountViewModelImpl) VCard(ezvcard.VCard)

Example 13 with Photo

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

the class TVProfileEditingFragment method updatePhoto.

public void updatePhoto(Bitmap image) {
    if (image == null) {
        Log.w(TAG, "updatePhoto: null photo");
        return;
    }
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    image = BitmapUtils.cropImageToCircle(image);
    image = BitmapUtils.reduceBitmap(image, VCardUtils.VCARD_PHOTO_SIZE);
    image.compress(Bitmap.CompressFormat.PNG, 100, stream);
    Photo photo = new Photo(stream.toByteArray(), ImageType.PNG);
    presenter.saveVCardPhoto(photo);
}
Also used : Photo(ezvcard.property.Photo) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 14 with Photo

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

the class MainFragment method displayAccountInfos.

@Override
public void displayAccountInfos(final String address, final RingNavigationViewModel viewModel) {
    getActivity().runOnUiThread(() -> {
        if (getActivity() == null) {
            Log.e(TAG, "displayAccountInfos: Not able to get activity");
            return;
        }
        VCard vcard = viewModel.getVcard(getActivity().getFilesDir());
        if (vcard == null) {
            Log.e(TAG, "displayAccountInfos: Not able to get vcard");
            return;
        }
        String formattedName = vcard.getFormattedName().getValue();
        if (formattedName != null && !formattedName.isEmpty()) {
            titleView.setAlias(formattedName);
            if (address != null) {
                setTitle(address);
            } else {
                setTitle("");
            }
        } else {
            titleView.setAlias(address);
        }
        byte[] data = null;
        List<Photo> photos = vcard.getPhotos();
        if (!photos.isEmpty() && photos.get(0) != null) {
            data = photos.get(0).getData();
        }
        Drawable contactPicture = AvatarFactory.getAvatar(getActivity(), data, viewModel.getAccount().getDisplayUsername(), address);
        titleView.setCurrentAccountPhoto(contactPicture);
    });
}
Also used : Drawable(android.graphics.drawable.Drawable) Photo(ezvcard.property.Photo) VCard(ezvcard.VCard)

Example 15 with Photo

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

the class SampleVCardsTest method outlook2007VCard.

@Test
public void outlook2007VCard() throws Throwable {
    VCardAsserter asserter = read("outlook-2007.vcf");
    asserter.next(V2_1);
    // @formatter:off
    asserter.structuredName().family("Angstadt").given("Michael").prefixes("Mr.").suffixes("Jr.").param(VCardParameters.LANGUAGE, "en-us").noMore();
    asserter.simpleProperty(FormattedName.class).value("Mr. Michael Angstadt Jr.").noMore();
    asserter.listProperty(Nickname.class).values("Mike").noMore();
    asserter.listProperty(Organization.class).values("TheCompany", "TheDepartment").noMore();
    asserter.simpleProperty(Title.class).value("TheJobTitle").noMore();
    asserter.simpleProperty(Note.class).value("This is the NOTE field	\r\nI assume it encodes this text inside a NOTE vCard type.\r\nBut I'm not sure because there's text formatting going on here.\r\nIt does not preserve the formatting").param("ENCODING", "QUOTED-PRINTABLE").param("CHARSET", "us-ascii").noMore();
    asserter.telephone().types(TelephoneType.WORK, TelephoneType.VOICE).text("(111) 555-1111").next().types(TelephoneType.HOME, TelephoneType.VOICE).text("(111) 555-2222").next().types(TelephoneType.CELL, TelephoneType.VOICE).text("(111) 555-4444").next().types(TelephoneType.WORK, TelephoneType.FAX).text("(111) 555-3333").noMore();
    asserter.address().extendedAddress("TheOffice").streetAddress("222 Broadway").locality("New York").region("NY").postalCode("99999").country("USA").label("222 Broadway\r\nNew York, NY 99999\r\nUSA").types(AddressType.WORK, AddressType.PREF).noMore();
    asserter.simpleProperty(Url.class).value("http://mikeangstadt.name").param("TYPE", "HOME").next().value("http://mikeangstadt.name").param("TYPE", "WORK").noMore();
    asserter.simpleProperty(Role.class).value("TheProfession").noMore();
    asserter.dateProperty(Birthday.class).date("1922-03-10").noMore();
    asserter.binaryProperty(Key.class).param("ENCODING", "BASE64").param("TYPE", "X509").contentType(KeyType.X509).dataLength(514).noMore();
    asserter.email().types(EmailType.PREF, EmailType.INTERNET).value("mike.angstadt@gmail.com").noMore();
    asserter.binaryProperty(Photo.class).param("ENCODING", "BASE64").param("TYPE", "JPEG").contentType(ImageType.JPEG).dataLength(2324).noMore();
    asserter.simpleProperty(FreeBusyUrl.class).value("http://website.com/mycal").noMore();
    asserter.simpleProperty(Revision.class).value(utc("2012-08-01 18:46:31")).noMore();
    asserter.rawProperty("X-MS-TEL").value("(111) 555-4444").param("TYPE", "VOICE").param("TYPE", "CALLBACK").noMore();
    asserter.rawProperty("X-MS-OL-DEFAULT-POSTAL-ADDRESS").value("2").noMore();
    asserter.rawProperty("X-MS-ANNIVERSARY").value("20120801").noMore();
    asserter.rawProperty("X-MS-IMADDRESS").value("im@aim.com").noMore();
    asserter.rawProperty("X-MS-OL-DESIGN").value("<card xmlns=\"http://schemas.microsoft.com/office/outlook/12/electronicbusinesscards\" ver=\"1.0\" layout=\"left\" bgcolor=\"ffffff\"><img xmlns=\"\" align=\"tleft\" area=\"32\" use=\"photo\"/><fld xmlns=\"\" prop=\"name\" align=\"left\" dir=\"ltr\" style=\"b\" color=\"000000\" size=\"10\"/><fld xmlns=\"\" prop=\"org\" align=\"left\" dir=\"ltr\" color=\"000000\" size=\"8\"/><fld xmlns=\"\" prop=\"title\" align=\"left\" dir=\"ltr\" color=\"000000\" size=\"8\"/><fld xmlns=\"\" prop=\"dept\" align=\"left\" dir=\"ltr\" color=\"000000\" size=\"8\"/><fld xmlns=\"\" prop=\"telwork\" align=\"left\" dir=\"ltr\" color=\"000000\" size=\"8\"><label align=\"right\" color=\"626262\">Work</label></fld><fld xmlns=\"\" prop=\"telcell\" align=\"left\" dir=\"ltr\" color=\"000000\" size=\"8\"><label align=\"right\" color=\"626262\">Mobile</label></fld><fld xmlns=\"\" prop=\"telhome\" align=\"left\" dir=\"ltr\" color=\"000000\" size=\"8\"><label align=\"right\" color=\"626262\">Home</label></fld><fld xmlns=\"\" prop=\"email\" align=\"left\" dir=\"ltr\" color=\"000000\" size=\"8\"/><fld xmlns=\"\" prop=\"addrwork\" align=\"left\" dir=\"ltr\" color=\"000000\" size=\"8\"/><fld xmlns=\"\" prop=\"webwork\" align=\"left\" dir=\"ltr\" color=\"000000\" size=\"8\"/><fld xmlns=\"\" prop=\"blank\" size=\"8\"/><fld xmlns=\"\" prop=\"blank\" size=\"8\"/><fld xmlns=\"\" prop=\"blank\" size=\"8\"/><fld xmlns=\"\" prop=\"blank\" size=\"8\"/><fld xmlns=\"\" prop=\"blank\" size=\"8\"/><fld xmlns=\"\" prop=\"blank\" size=\"8\"/></card>").param("CHARSET", "utf-8").noMore();
    asserter.rawProperty("X-MS-MANAGER").value("TheManagerName").noMore();
    asserter.rawProperty("X-MS-ASSISTANT").value("TheAssistantName").noMore();
    asserter.rawProperty("X-MS-SPOUSE").value("TheSpouse").noMore();
    VCard vcard = asserter.getVCard();
    asserter.validate().prop(vcard.getNickname(), // not supported in 2.1
    2).prop(vcard.getFbUrls().get(0), // not supported in 2.1
    2).run();
    // @formatter:on
    asserter.done();
}
Also used : Photo(ezvcard.property.Photo) VCardAsserter(ezvcard.property.asserter.VCardAsserter) VCard(ezvcard.VCard) Key(ezvcard.property.Key) Test(org.junit.Test)

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