use of ezvcard.VCard 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));
}
}
}
});
}
}
use of ezvcard.VCard in project ring-client-android by savoirfairelinux.
the class NotificationServiceImpl method showIncomingTrustRequestNotification.
@Override
public void showIncomingTrustRequestNotification(Account account) {
int notificationId = getIncomingTrustNotificationId(account.getAccountID());
NotificationCompat.Builder messageNotificationBuilder = mNotificationBuilders.get(notificationId);
if (messageNotificationBuilder != null) {
notificationManager.cancel(notificationId);
} else {
messageNotificationBuilder = new NotificationCompat.Builder(mContext, NOTIF_CHANNEL_REQUEST);
}
Collection<TrustRequest> requests = account.getRequests();
if (requests.isEmpty()) {
return;
} else if (requests.size() == 1) {
TrustRequest request = requests.iterator().next();
messageNotificationBuilder = new NotificationCompat.Builder(mContext, NOTIF_CHANNEL_REQUEST);
Bundle info = new Bundle();
info.putString(TRUST_REQUEST_NOTIFICATION_ACCOUNT_ID, account.getAccountID());
info.putString(TRUST_REQUEST_NOTIFICATION_FROM, request.getContactId());
messageNotificationBuilder.setContentText(request.getDisplayname()).addAction(R.drawable.ic_action_accept, mContext.getText(R.string.accept), PendingIntent.getService(mContext, random.nextInt(), new Intent(DRingService.ACTION_TRUST_REQUEST_ACCEPT).setClass(mContext, DRingService.class).putExtras(info), PendingIntent.FLAG_ONE_SHOT)).addAction(R.drawable.ic_delete_white, mContext.getText(R.string.refuse), PendingIntent.getService(mContext, random.nextInt(), new Intent(DRingService.ACTION_TRUST_REQUEST_REFUSE).setClass(mContext, DRingService.class).putExtras(info), PendingIntent.FLAG_ONE_SHOT)).addAction(R.drawable.ic_close_white, mContext.getText(R.string.block), PendingIntent.getService(mContext, random.nextInt(), new Intent(DRingService.ACTION_TRUST_REQUEST_BLOCK).setClass(mContext, DRingService.class).putExtras(info), PendingIntent.FLAG_ONE_SHOT));
VCard vCard = request.getVCard();
List<Photo> photos = vCard == null ? null : vCard.getPhotos();
byte[] data = null;
if (photos != null && !photos.isEmpty()) {
data = photos.get(0).getData();
}
setContactPicture(data, request.getDisplayname(), request.getContactId(), messageNotificationBuilder);
} else {
messageNotificationBuilder.setContentText(String.format(mContext.getString(R.string.contact_request_msg), Integer.toString(requests.size())));
messageNotificationBuilder.setLargeIcon(null);
messageNotificationBuilder.mActions.clear();
}
messageNotificationBuilder.setDefaults(NotificationCompat.DEFAULT_ALL).setPriority(NotificationCompat.PRIORITY_HIGH).setAutoCancel(true).setSmallIcon(R.drawable.ic_ring_logo_white).setCategory(NotificationCompat.CATEGORY_SOCIAL).setContentTitle(mContext.getString(R.string.contact_request_title));
Intent intentOpenTrustRequestFragment = new Intent(HomeActivity.ACTION_PRESENT_TRUST_REQUEST_FRAGMENT).setClass(mContext, HomeActivity.class).putExtra(ContactRequestsFragment.ACCOUNT_ID, account.getAccountID());
messageNotificationBuilder.setContentIntent(PendingIntent.getActivity(mContext, random.nextInt(), intentOpenTrustRequestFragment, PendingIntent.FLAG_ONE_SHOT));
messageNotificationBuilder.setColor(ResourcesCompat.getColor(mContext.getResources(), R.color.color_primary_dark, null));
mNotificationBuilders.put(notificationId, messageNotificationBuilder);
notificationManager.notify(notificationId, messageNotificationBuilder.build());
}
use of ezvcard.VCard 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());
});
}
use of ezvcard.VCard in project ring-client-android by savoirfairelinux.
the class ContactServiceImpl method loadVCardContactData.
@Override
public void loadVCardContactData(CallContact callContact) {
if (!callContact.getPhones().isEmpty()) {
String username = callContact.getPhones().get(0).getNumber().getRawRingId();
VCard vcard = VCardUtils.loadPeerProfileFromDisk(mContext.getFilesDir(), username + ".vcf");
callContact.setVCardProfile(vcard);
}
}
use of ezvcard.VCard in project ring-client-android by savoirfairelinux.
the class AccountService method sendProfile.
/**
* put VCard on the DHT
*/
public void sendProfile(final String callId, final String accountId) {
mExecutor.submit(() -> {
VCard vcard = VCardUtils.loadLocalProfileFromDisk(mDeviceRuntimeService.provideFilesDir(), accountId);
String stringVCard = VCardUtils.vcardToString(vcard);
int nbTotal = stringVCard.length() / VCARD_CHUNK_SIZE + (stringVCard.length() % VCARD_CHUNK_SIZE != 0 ? 1 : 0);
int i = 1;
Random r = new Random(System.currentTimeMillis());
int key = r.nextInt();
Log.d(TAG, "sendProfile, vcard " + stringVCard);
while (i <= nbTotal) {
HashMap<String, String> chunk = new HashMap<>();
Log.d(TAG, "length vcard " + stringVCard.length() + " id " + key + " part " + i + " nbTotal " + nbTotal);
String keyHashMap = VCardUtils.MIME_RING_PROFILE_VCARD + "; id=" + key + ",part=" + i + ",of=" + nbTotal;
String message = stringVCard.substring(0, Math.min(VCARD_CHUNK_SIZE, stringVCard.length()));
chunk.put(keyHashMap, message);
if (stringVCard.length() > VCARD_CHUNK_SIZE) {
stringVCard = stringVCard.substring(VCARD_CHUNK_SIZE);
}
i++;
Ringservice.sendTextMessage(callId, StringMap.toSwig(chunk), "Me", false);
}
});
}
Aggregations