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