Search in sources :

Example 1 with ProfileContactPhoto

use of org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto in project Signal-Android by signalapp.

the class ProfilePreference method refresh.

public void refresh() {
    if (profileNumberView == null)
        return;
    final Address localAddress = Address.fromSerialized(TextSecurePreferences.getLocalNumber(getContext()));
    final String profileName = TextSecurePreferences.getProfileName(getContext());
    GlideApp.with(getContext().getApplicationContext()).load(new ProfileContactPhoto(localAddress, String.valueOf(TextSecurePreferences.getProfileAvatarId(getContext())))).error(new ResourceContactPhoto(R.drawable.ic_camera_alt_white_24dp).asDrawable(getContext(), getContext().getResources().getColor(R.color.grey_400))).circleCrop().diskCacheStrategy(DiskCacheStrategy.ALL).into(avatarView);
    if (!TextUtils.isEmpty(profileName)) {
        profileNameView.setText(profileName);
    }
    profileNumberView.setText(localAddress.toPhoneString());
}
Also used : ProfileContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto) ResourceContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto) Address(org.thoughtcrime.securesms.database.Address)

Example 2 with ProfileContactPhoto

use of org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto in project Signal-Android by signalapp.

the class AvatarImageView method setAvatar.

private void setAvatar(@NonNull GlideRequests requestManager, @Nullable Recipient recipient, @NonNull AvatarOptions avatarOptions) {
    if (recipient != null) {
        RecipientContactPhoto photo = (recipient.isSelf() && avatarOptions.useSelfProfileAvatar) ? new RecipientContactPhoto(recipient, new ProfileContactPhoto(Recipient.self(), Recipient.self().getProfileAvatar())) : new RecipientContactPhoto(recipient);
        boolean shouldBlur = recipient.shouldBlurAvatar();
        ChatColors chatColors = recipient.getChatColors();
        if (!photo.equals(recipientContactPhoto) || shouldBlur != blurred || !Objects.equals(chatColors, this.chatColors)) {
            requestManager.clear(this);
            this.chatColors = chatColors;
            recipientContactPhoto = photo;
            Drawable fallbackContactPhotoDrawable = size == SIZE_SMALL ? photo.recipient.getSmallFallbackContactPhotoDrawable(getContext(), inverted, fallbackPhotoProvider, ViewUtil.getWidth(this)) : photo.recipient.getFallbackContactPhotoDrawable(getContext(), inverted, fallbackPhotoProvider, ViewUtil.getWidth(this));
            if (fixedSizeTarget != null) {
                requestManager.clear(fixedSizeTarget);
            }
            if (photo.contactPhoto != null) {
                List<Transformation<Bitmap>> transforms = new ArrayList<>();
                if (shouldBlur) {
                    transforms.add(new BlurTransformation(ApplicationDependencies.getApplication(), 0.25f, BlurTransformation.MAX_RADIUS));
                }
                transforms.add(new CircleCrop());
                blurred = shouldBlur;
                GlideRequest<Drawable> request = requestManager.load(photo.contactPhoto).dontAnimate().fallback(fallbackContactPhotoDrawable).error(fallbackContactPhotoDrawable).diskCacheStrategy(DiskCacheStrategy.ALL).downsample(DownsampleStrategy.CENTER_INSIDE).transform(new MultiTransformation<>(transforms));
                if (avatarOptions.fixedSize > 0) {
                    fixedSizeTarget = new FixedSizeTarget(avatarOptions.fixedSize);
                    request.into(fixedSizeTarget);
                } else {
                    request.into(this);
                }
            } else {
                setImageDrawable(fallbackContactPhotoDrawable);
            }
        }
        setAvatarClickHandler(recipient, avatarOptions.quickContactEnabled);
    } else {
        recipientContactPhoto = null;
        requestManager.clear(this);
        if (fallbackPhotoProvider != null) {
            setImageDrawable(fallbackPhotoProvider.getPhotoForRecipientWithoutName().asDrawable(getContext(), AvatarColor.UNKNOWN, inverted));
        } else {
            setImageDrawable(unknownRecipientDrawable);
        }
        disableQuickContact();
    }
}
Also used : ProfileContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto) BlurTransformation(org.thoughtcrime.securesms.util.BlurTransformation) MultiTransformation(com.bumptech.glide.load.MultiTransformation) BlurTransformation(org.thoughtcrime.securesms.util.BlurTransformation) Transformation(com.bumptech.glide.load.Transformation) ChatColors(org.thoughtcrime.securesms.conversation.colors.ChatColors) Drawable(android.graphics.drawable.Drawable) ArrayList(java.util.ArrayList) CircleCrop(com.bumptech.glide.load.resource.bitmap.CircleCrop)

Example 3 with ProfileContactPhoto

use of org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto in project Signal-Android by signalapp.

the class AvatarUtil method request.

private static <T> GlideRequest<T> request(@NonNull GlideRequest<T> glideRequest, @NonNull Context context, @NonNull Recipient recipient, boolean loadSelf, int targetSize) {
    final ContactPhoto photo;
    if (Recipient.self().equals(recipient) && loadSelf) {
        photo = new ProfileContactPhoto(recipient, recipient.getProfileAvatar());
    } else {
        photo = recipient.getContactPhoto();
    }
    final GlideRequest<T> request = glideRequest.load(photo).error(getFallback(context, recipient, targetSize)).diskCacheStrategy(DiskCacheStrategy.ALL);
    if (recipient.shouldBlurAvatar()) {
        return request.transform(new BlurTransformation(context, 0.25f, BlurTransformation.MAX_RADIUS));
    } else {
        return request;
    }
}
Also used : ProfileContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto) GeneratedContactPhoto(org.thoughtcrime.securesms.contacts.avatars.GeneratedContactPhoto) ContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ContactPhoto) ProfileContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto)

Example 4 with ProfileContactPhoto

use of org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto in project Signal-Android by WhisperSystems.

the class CallParticipantView method setPipAvatar.

private void setPipAvatar(@NonNull Recipient recipient) {
    ContactPhoto contactPhoto = recipient.isSelf() ? new ProfileContactPhoto(Recipient.self(), Recipient.self().getProfileAvatar()) : recipient.getContactPhoto();
    FallbackContactPhoto fallbackPhoto = recipient.getFallbackContactPhoto(FALLBACK_PHOTO_PROVIDER);
    GlideApp.with(this).load(contactPhoto).fallback(fallbackPhoto.asCallCard(getContext())).error(fallbackPhoto.asCallCard(getContext())).diskCacheStrategy(DiskCacheStrategy.ALL).into(pipAvatar);
    pipAvatar.setScaleType(contactPhoto == null ? ImageView.ScaleType.CENTER_INSIDE : ImageView.ScaleType.CENTER_CROP);
    ChatColors chatColors = recipient.getChatColors();
    pipAvatar.setBackground(chatColors.getChatBubbleMask());
}
Also used : ProfileContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto) FallbackContactPhoto(org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto) ChatColors(org.thoughtcrime.securesms.conversation.colors.ChatColors) ContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ContactPhoto) ProfileContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto) FallbackContactPhoto(org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto) ResourceContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto)

Example 5 with ProfileContactPhoto

use of org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto in project Signal-Android by WhisperSystems.

the class AvatarImageView method setAvatar.

private void setAvatar(@NonNull GlideRequests requestManager, @Nullable Recipient recipient, @NonNull AvatarOptions avatarOptions) {
    if (recipient != null) {
        RecipientContactPhoto photo = (recipient.isSelf() && avatarOptions.useSelfProfileAvatar) ? new RecipientContactPhoto(recipient, new ProfileContactPhoto(Recipient.self(), Recipient.self().getProfileAvatar())) : new RecipientContactPhoto(recipient);
        boolean shouldBlur = recipient.shouldBlurAvatar();
        ChatColors chatColors = recipient.getChatColors();
        if (!photo.equals(recipientContactPhoto) || shouldBlur != blurred || !Objects.equals(chatColors, this.chatColors)) {
            requestManager.clear(this);
            this.chatColors = chatColors;
            recipientContactPhoto = photo;
            Drawable fallbackContactPhotoDrawable = size == SIZE_SMALL ? photo.recipient.getSmallFallbackContactPhotoDrawable(getContext(), inverted, fallbackPhotoProvider, ViewUtil.getWidth(this)) : photo.recipient.getFallbackContactPhotoDrawable(getContext(), inverted, fallbackPhotoProvider, ViewUtil.getWidth(this));
            if (fixedSizeTarget != null) {
                requestManager.clear(fixedSizeTarget);
            }
            if (photo.contactPhoto != null) {
                List<Transformation<Bitmap>> transforms = new ArrayList<>();
                if (shouldBlur) {
                    transforms.add(new BlurTransformation(ApplicationDependencies.getApplication(), 0.25f, BlurTransformation.MAX_RADIUS));
                }
                transforms.add(new CircleCrop());
                blurred = shouldBlur;
                GlideRequest<Drawable> request = requestManager.load(photo.contactPhoto).dontAnimate().fallback(fallbackContactPhotoDrawable).error(fallbackContactPhotoDrawable).diskCacheStrategy(DiskCacheStrategy.ALL).downsample(DownsampleStrategy.CENTER_INSIDE).transform(new MultiTransformation<>(transforms));
                if (avatarOptions.fixedSize > 0) {
                    fixedSizeTarget = new FixedSizeTarget(avatarOptions.fixedSize);
                    request.into(fixedSizeTarget);
                } else {
                    request.into(this);
                }
            } else {
                setImageDrawable(fallbackContactPhotoDrawable);
            }
        }
        setAvatarClickHandler(recipient, avatarOptions.quickContactEnabled);
    } else {
        recipientContactPhoto = null;
        requestManager.clear(this);
        if (fallbackPhotoProvider != null) {
            setImageDrawable(fallbackPhotoProvider.getPhotoForRecipientWithoutName().asDrawable(getContext(), AvatarColor.UNKNOWN, inverted));
        } else {
            setImageDrawable(unknownRecipientDrawable);
        }
        disableQuickContact();
    }
}
Also used : ProfileContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto) BlurTransformation(org.thoughtcrime.securesms.util.BlurTransformation) MultiTransformation(com.bumptech.glide.load.MultiTransformation) BlurTransformation(org.thoughtcrime.securesms.util.BlurTransformation) Transformation(com.bumptech.glide.load.Transformation) ChatColors(org.thoughtcrime.securesms.conversation.colors.ChatColors) Drawable(android.graphics.drawable.Drawable) ArrayList(java.util.ArrayList) CircleCrop(com.bumptech.glide.load.resource.bitmap.CircleCrop)

Aggregations

ProfileContactPhoto (org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto)15 ContactPhoto (org.thoughtcrime.securesms.contacts.avatars.ContactPhoto)8 Drawable (android.graphics.drawable.Drawable)6 GeneratedContactPhoto (org.thoughtcrime.securesms.contacts.avatars.GeneratedContactPhoto)6 ResourceContactPhoto (org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto)5 Context (android.content.Context)4 ImageView (android.widget.ImageView)4 FallbackContactPhoto (org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto)4 ChatColors (org.thoughtcrime.securesms.conversation.colors.ChatColors)4 BlurTransformation (org.thoughtcrime.securesms.util.BlurTransformation)4 Resources (android.content.res.Resources)2 Bitmap (android.graphics.Bitmap)2 TransitionInflater (android.transition.TransitionInflater)2 View (android.view.View)2 Nullable (androidx.annotation.Nullable)2 AppCompatImageView (androidx.appcompat.widget.AppCompatImageView)2 Toolbar (androidx.appcompat.widget.Toolbar)2 DataSource (com.bumptech.glide.load.DataSource)2 MultiTransformation (com.bumptech.glide.load.MultiTransformation)2 Transformation (com.bumptech.glide.load.Transformation)2