@Override public Resource<GifBitmapWrapper> transform(Resource<GifBitmapWrapper> resource, int outWidth, int outHeight) { Resource<Bitmap> bitmapResource = resource.get().getBitmapResource(); if (bitmapResource != null) { Resource<Bitmap> transformed = wrapped.transform(bitmapResource, outWidth, outHeight); if (transformed != bitmapResource) { GifBitmapWrapper gifBitmap = new GifBitmapWrapper(transformed, null); return new GifBitmapWrapperResource(gifBitmap); } } else { //TODO: this should be pushed down into a GifData transformation? Resource<GifData> gifResource = resource.get().getGifResource(); GifData gifData = gifResource.get(); Transformation<Bitmap> newTransformation = new MultiTransformation<Bitmap>(gifData.getFrameTransformation(), wrapped); gifData.setFrameTransformation(newTransformation); return new GifBitmapWrapperResource(new GifBitmapWrapper(null, new GifDataResource(gifData))); } return resource; }
@Test @SuppressWarnings({"unchecked", "varargs"}) public void testApplyMultiTransform() { options.transforms(new CircleCrop(), new CenterCrop()); assertThat(options.isTransformationRequired()).isTrue(); assertThat(options.getTransformations()).containsKey(Bitmap.class); assertThat(options.getTransformations().get(Bitmap.class)) .isInstanceOf(MultiTransformation.class); }
@Override public void bindView(@NonNull final ForkModel model, @NonNull final ForkViewHolder holder) { holder.name.setText(model.getName()); final RequestOptions options = new RequestOptions(); options.transform(new MultiTransformation(new BlurTransformation(25), new CircleCrop())); Glide.with(getContext()) .asBitmap() .load(model.getAvatarUrl()) .apply(options) .into(holder.avatar); holder.itemView.setOnClickListener(view -> mListener.onForkItemClicked(model)); }
@Override public void bindView(@NonNull final StargazerModel model, @NonNull final UserViewHolder holder) { holder.name.setText(model.getName()); final RequestOptions options = new RequestOptions(); options.transform(new MultiTransformation(new BlurTransformation(25), new CircleCrop())); Glide.with(getContext()) .asBitmap() .load(model.getAvatarUrl()) .apply(options) .into(holder.avatar); }
@SuppressWarnings("unchecked") private Transformation<ResourceType> getFinalTransformation() { switch (transformations.size()) { case 0: return Transformation.NONE; case 1: return transformations.get(0); default: return new MultiTransformation<ResourceType>(transformations); } }
/** * Applies the given {@link Transformation}s in the given order for * {@link Bitmap Bitmaps} to the default types ({@link Bitmap}, * {@link android.graphics.drawable.BitmapDrawable}, and * {@link com.bumptech.glide.load.resource.gif.GifDrawable}) * and throws an exception if asked to transform an unknown type. * * <p>This will override previous calls to {@link #dontTransform()}. * * @param transformations One or more {@link Transformation}s for {@link Bitmap}s. * @see #optionalTransform(Transformation) * @see #optionalTransform(Class, Transformation) */ // Guaranteed to modify the current object by the isAutoCloneEnabledCheck. @SuppressWarnings({"unchecked", "varargs", "CheckResult"}) @CheckResult public RequestOptions transforms(@NonNull Transformation<Bitmap>... transformations) { return transform(new MultiTransformation<>(transformations), /*isRequired=*/ true); }