Search in sources :

Example 91 with VCard

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

Example 92 with VCard

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());
}
Also used : HomeActivity(cx.ring.client.HomeActivity) Bundle(android.os.Bundle) TrustRequest(cx.ring.model.TrustRequest) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) List(java.util.List) ArrayList(java.util.ArrayList) DRingService(cx.ring.service.DRingService) VCard(ezvcard.VCard)

Example 93 with VCard

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());
    });
}
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 94 with VCard

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

Example 95 with 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);
        }
    });
}
Also used : Random(java.util.Random) HashMap(java.util.HashMap) VCard(ezvcard.VCard)

Aggregations

VCard (ezvcard.VCard)191 Test (org.junit.Test)134 StringWriter (java.io.StringWriter)29 StructuredName (ezvcard.property.StructuredName)23 Person (com.google.api.services.people.v1.model.Person)22 Telephone (ezvcard.property.Telephone)21 Photo (ezvcard.property.Photo)17 Email (ezvcard.property.Email)16 List (java.util.List)16 EmailAddress (com.google.api.services.people.v1.model.EmailAddress)15 Document (org.w3c.dom.Document)15 VCardVersion (ezvcard.VCardVersion)14 XCardDocumentStreamWriter (ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter)14 Address (ezvcard.property.Address)14 PhoneNumber (com.google.api.services.people.v1.model.PhoneNumber)13 Collectors (java.util.stream.Collectors)12 Name (com.google.api.services.people.v1.model.Name)11 File (java.io.File)11 Truth.assertThat (com.google.common.truth.Truth.assertThat)10 Pair (com.google.gdata.util.common.base.Pair)10