Search in sources :

Example 1 with Photo

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

the class RingNavigationFragment method profileContainerClicked.

@OnClick(R.id.profile_container)
public void profileContainerClicked() {
    Log.d(TAG, "profileContainerClicked: Click on the edit profile");
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.profile);
    LayoutInflater inflater = LayoutInflater.from(getActivity());
    ViewGroup view = (ViewGroup) inflater.inflate(R.layout.dialog_profile, null);
    final EditText editText = view.findViewById(R.id.user_name);
    editText.setText(presenter.getAlias(mSelectedAccount));
    mProfilePhoto = view.findViewById(R.id.profile_photo);
    mProfilePhoto.setImageDrawable(mUserImage.getDrawable());
    ImageButton cameraView = view.findViewById(R.id.camera);
    cameraView.setOnClickListener(v -> presenter.cameraClicked());
    ImageButton gallery = view.findViewById(R.id.gallery);
    gallery.setOnClickListener(v -> presenter.galleryClicked());
    builder.setView(view);
    builder.setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.cancel());
    builder.setPositiveButton(android.R.string.ok, (dialog, which) -> {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        if (mSourcePhoto != null && mProfilePhoto.getDrawable() != ResourcesCompat.getDrawable(getResources(), R.drawable.ic_contact_picture_fallback, null)) {
            // FIXME: Reduce the bitmap but not use it.
            BitmapUtils.reduceBitmap(mSourcePhoto, VCardUtils.VCARD_PHOTO_SIZE);
            mSourcePhoto.compress(Bitmap.CompressFormat.PNG, 100, stream);
            Photo photo = new Photo(stream.toByteArray(), ImageType.PNG);
            presenter.saveVCardFormattedName(editText.getText().toString().trim());
            presenter.saveVCardPhoto(photo);
            mSourcePhoto = null;
        } else {
            presenter.saveVCardFormattedName(editText.getText().toString().trim());
        }
    });
    builder.show();
}
Also used : AlertDialog(android.app.AlertDialog) EditText(android.widget.EditText) ImageButton(android.widget.ImageButton) ViewGroup(android.view.ViewGroup) LayoutInflater(android.view.LayoutInflater) Photo(ezvcard.property.Photo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OnClick(butterknife.OnClick)

Example 2 with Photo

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

the class VCardServiceImpl method loadSmallVCard.

@Override
public VCard loadSmallVCard(String accountId) {
    VCard vcard = VCardUtils.loadLocalProfileFromDisk(mContext.getFilesDir(), accountId);
    if (vcard != null && !vcard.getPhotos().isEmpty()) {
        // Reduce photo size to fit in one DHT packet
        Bitmap photo = BitmapUtils.bytesToBitmap(vcard.getPhotos().get(0).getData());
        photo = BitmapUtils.reduceBitmap(photo, 30000);
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        photo.compress(Bitmap.CompressFormat.PNG, 100, stream);
        vcard.removeProperties(Photo.class);
        vcard.addPhoto(new Photo(stream.toByteArray(), ImageType.PNG));
        vcard.removeProperties(RawProperty.class);
    }
    return vcard;
}
Also used : Bitmap(android.graphics.Bitmap) Photo(ezvcard.property.Photo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) VCard(ezvcard.VCard)

Example 3 with Photo

use of ezvcard.property.Photo 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 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 5 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)

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