Search in sources :

Example 1 with Transformation

use of com.bumptech.glide.load.Transformation in project AgileDev by LZ9.

the class GlideImageLoader method setTransformation.

/**
 * 对图片进行变换
 */
@SuppressWarnings("unchecked")
private void setTransformation(Context context, DrawableTypeRequest request, GlideBuilderBean bean) {
    List<Transformation<Bitmap>> list = new ArrayList<>();
    if (bean.useBlur) {
        list.add(new BlurTransformation(context, bean.blurRadius));
    }
    if (bean.useFilterColor) {
        list.add(new ColorFilterTransformation(context, bean.filterColor));
    }
    if (bean.useRoundCorner) {
        list.add(new RoundedCornersTransformation(context, (int) bean.roundCornerRadius, bean.roundedCornersMargin, bean.cornerType));
    }
    if (bean.useGrayscale) {
        list.add(new GrayscaleTransformation(context));
    }
    if (bean.useCircle) {
        list.add(new CropCircleTransformation(context));
    }
    if (bean.useCropSquare) {
        list.add(new CropSquareTransformation(context));
    }
    if (bean.useMask) {
        list.add(new MaskTransformation(context, bean.maskResId));
    }
    if (list.size() > 0) {
        Transformation[] transformations = new Transformation[list.size()];
        for (int i = 0; i < list.size(); i++) {
            transformations[i] = list.get(i);
        }
        request.bitmapTransform(transformations);
    }
}
Also used : BlurTransformation(com.lodz.android.imageloader.glide.transformations.BlurTransformation) MaskTransformation(com.lodz.android.imageloader.glide.transformations.MaskTransformation) RoundedCornersTransformation(com.lodz.android.imageloader.glide.transformations.RoundedCornersTransformation) ColorFilterTransformation(com.lodz.android.imageloader.glide.transformations.ColorFilterTransformation) GrayscaleTransformation(com.lodz.android.imageloader.glide.transformations.GrayscaleTransformation) CropCircleTransformation(com.lodz.android.imageloader.glide.transformations.CropCircleTransformation) CropSquareTransformation(com.lodz.android.imageloader.glide.transformations.CropSquareTransformation) Transformation(com.bumptech.glide.load.Transformation) BlurTransformation(com.lodz.android.imageloader.glide.transformations.BlurTransformation) MaskTransformation(com.lodz.android.imageloader.glide.transformations.MaskTransformation) ArrayList(java.util.ArrayList) CropCircleTransformation(com.lodz.android.imageloader.glide.transformations.CropCircleTransformation) CropSquareTransformation(com.lodz.android.imageloader.glide.transformations.CropSquareTransformation) GrayscaleTransformation(com.lodz.android.imageloader.glide.transformations.GrayscaleTransformation) RoundedCornersTransformation(com.lodz.android.imageloader.glide.transformations.RoundedCornersTransformation) ColorFilterTransformation(com.lodz.android.imageloader.glide.transformations.ColorFilterTransformation)

Example 2 with Transformation

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

Example 3 with Transformation

use of com.bumptech.glide.load.Transformation in project glide by bumptech.

the class EngineKeyTest method testEqualsAndHashCode.

@Test
public void testEqualsAndHashCode() {
    Options memoryOptions = new Options();
    memoryOptions.set(Option.memory("key", new Object()), new Object());
    Options diskOptions = new Options();
    diskOptions.set(Option.disk("key", new CacheKeyUpdater<String>() {

        @Override
        public void update(@NonNull byte[] keyBytes, @NonNull String value, @NonNull MessageDigest messageDigest) {
            messageDigest.update(keyBytes);
            messageDigest.update(value.getBytes(Key.CHARSET));
        }
    }), "value");
    new EqualsTester().addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, new Options()), new EngineKey("id", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, new Options())).addEqualityGroup(new EngineKey("otherId", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, new Options())).addEqualityGroup(new EngineKey("id", new ObjectKey("otherSignature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, new Options())).addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 200, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, new Options())).addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 100, 200, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, new Options())).addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>singletonMap(Object.class, transformation), Object.class, Object.class, new Options())).addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Integer.class, Object.class, new Options())).addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Integer.class, new Options())).addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, memoryOptions)).addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, diskOptions)).testEquals();
}
Also used : Options(com.bumptech.glide.load.Options) Transformation(com.bumptech.glide.load.Transformation) CacheKeyUpdater(com.bumptech.glide.load.Option.CacheKeyUpdater) EqualsTester(com.google.common.testing.EqualsTester) NonNull(android.support.annotation.NonNull) ObjectKey(com.bumptech.glide.signature.ObjectKey) MessageDigest(java.security.MessageDigest) Test(org.junit.Test)

Example 4 with Transformation

use of com.bumptech.glide.load.Transformation in project glide by bumptech.

the class GifDrawableTransformationTest method testSetsTransformationAsFrameTransformation.

@Test
@SuppressWarnings("unchecked")
public void testSetsTransformationAsFrameTransformation() {
    Resource<GifDrawable> resource = mockResource();
    GifDrawable gifDrawable = mock(GifDrawable.class);
    Transformation<Bitmap> unitTransformation = UnitTransformation.get();
    when(gifDrawable.getFrameTransformation()).thenReturn(unitTransformation);
    when(gifDrawable.getIntrinsicWidth()).thenReturn(500);
    when(gifDrawable.getIntrinsicHeight()).thenReturn(500);
    when(resource.get()).thenReturn(gifDrawable);
    Bitmap firstFrame = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
    when(gifDrawable.getFirstFrame()).thenReturn(firstFrame);
    final int width = 123;
    final int height = 456;
    Bitmap expectedBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Resource<Bitmap> expectedResource = mockResource();
    when(expectedResource.get()).thenReturn(expectedBitmap);
    when(wrapped.transform(any(Context.class), Util.<Bitmap>anyResource(), anyInt(), anyInt())).thenReturn(expectedResource);
    transformation.transform(context, resource, width, height);
    verify(gifDrawable).setFrameTransformation(isA(Transformation.class), eq(expectedBitmap));
}
Also used : Context(android.content.Context) Bitmap(android.graphics.Bitmap) UnitTransformation(com.bumptech.glide.load.resource.UnitTransformation) Transformation(com.bumptech.glide.load.Transformation) Test(org.junit.Test)

Aggregations

Transformation (com.bumptech.glide.load.Transformation)4 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Context (android.content.Context)1 Bitmap (android.graphics.Bitmap)1 Drawable (android.graphics.drawable.Drawable)1 NonNull (android.support.annotation.NonNull)1 MultiTransformation (com.bumptech.glide.load.MultiTransformation)1 CacheKeyUpdater (com.bumptech.glide.load.Option.CacheKeyUpdater)1 Options (com.bumptech.glide.load.Options)1 UnitTransformation (com.bumptech.glide.load.resource.UnitTransformation)1 CircleCrop (com.bumptech.glide.load.resource.bitmap.CircleCrop)1 ObjectKey (com.bumptech.glide.signature.ObjectKey)1 EqualsTester (com.google.common.testing.EqualsTester)1 BlurTransformation (com.lodz.android.imageloader.glide.transformations.BlurTransformation)1 ColorFilterTransformation (com.lodz.android.imageloader.glide.transformations.ColorFilterTransformation)1 CropCircleTransformation (com.lodz.android.imageloader.glide.transformations.CropCircleTransformation)1 CropSquareTransformation (com.lodz.android.imageloader.glide.transformations.CropSquareTransformation)1 GrayscaleTransformation (com.lodz.android.imageloader.glide.transformations.GrayscaleTransformation)1 MaskTransformation (com.lodz.android.imageloader.glide.transformations.MaskTransformation)1