Search in sources :

Example 1 with MultiTransformation

use of com.bumptech.glide.load.MultiTransformation in project DevRing by LJYcoder.

the class GlideManager method load.

private RequestBuilder load(RequestBuilder requestBuilder, LoadOption loadOption) {
    RequestOptions requestOptions = new RequestOptions();
    // 使用全局的配置进行设置
    if (loadOption == null) {
        if (mImageConfig.isShowTransition()) {
            requestBuilder.transition(DrawableTransitionOptions.withCrossFade(600));
        }
        if (mImageConfig.getLoadingResId() > 0) {
            requestOptions.placeholder(mImageConfig.getLoadingResId());
        }
        if (mImageConfig.getErrorResId() > 0) {
            requestOptions.error(mImageConfig.getErrorResId());
        }
    } else // 使用临时的配置进行设置
    {
        if (loadOption.isShowTransition()) {
            requestBuilder.transition(DrawableTransitionOptions.withCrossFade(600));
        }
        if (loadOption.getLoadingResId() > 0) {
            requestOptions.placeholder(loadOption.getLoadingResId());
        }
        if (loadOption.getErrorResId() > 0) {
            requestOptions.error(loadOption.getErrorResId());
        }
        CropCircleTransformation cropCircleTransformation = null;
        RoundedCornersTransformation roundedCornersTransformation = null;
        BlurTransformation blurTransformation = null;
        GrayscaleTransformation grayscaleTransformation = null;
        if (loadOption.isCircle()) {
            cropCircleTransformation = new CropCircleTransformation();
        } else if (loadOption.getRoundRadius() > 0) {
            roundedCornersTransformation = new RoundedCornersTransformation(loadOption.getRoundRadius(), 0);
        }
        if (loadOption.getBlurRadius() > 0) {
            blurTransformation = new BlurTransformation(loadOption.getBlurRadius());
        }
        if (loadOption.isGray()) {
            grayscaleTransformation = new GrayscaleTransformation();
        }
        MultiTransformation multiTransformation = getMultiTransformation(new CenterCrop(), cropCircleTransformation, roundedCornersTransformation, blurTransformation, grayscaleTransformation);
        if (multiTransformation != null)
            requestOptions.transform(multiTransformation);
    }
    return requestBuilder.apply(requestOptions);
}
Also used : BlurTransformation(jp.wasabeef.glide.transformations.BlurTransformation) RequestOptions(com.bumptech.glide.request.RequestOptions) CropCircleTransformation(jp.wasabeef.glide.transformations.CropCircleTransformation) GrayscaleTransformation(jp.wasabeef.glide.transformations.GrayscaleTransformation) CenterCrop(com.bumptech.glide.load.resource.bitmap.CenterCrop) MultiTransformation(com.bumptech.glide.load.MultiTransformation) RoundedCornersTransformation(jp.wasabeef.glide.transformations.RoundedCornersTransformation)

Example 2 with MultiTransformation

use of com.bumptech.glide.load.MultiTransformation 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

MultiTransformation (com.bumptech.glide.load.MultiTransformation)2 Drawable (android.graphics.drawable.Drawable)1 Transformation (com.bumptech.glide.load.Transformation)1 CenterCrop (com.bumptech.glide.load.resource.bitmap.CenterCrop)1 CircleCrop (com.bumptech.glide.load.resource.bitmap.CircleCrop)1 RequestOptions (com.bumptech.glide.request.RequestOptions)1 ArrayList (java.util.ArrayList)1 BlurTransformation (jp.wasabeef.glide.transformations.BlurTransformation)1 CropCircleTransformation (jp.wasabeef.glide.transformations.CropCircleTransformation)1 GrayscaleTransformation (jp.wasabeef.glide.transformations.GrayscaleTransformation)1 RoundedCornersTransformation (jp.wasabeef.glide.transformations.RoundedCornersTransformation)1 ProfileContactPhoto (org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto)1 ChatColors (org.thoughtcrime.securesms.conversation.colors.ChatColors)1 BlurTransformation (org.thoughtcrime.securesms.util.BlurTransformation)1