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