提交 876b9f6a 编写于 作者: S Sam Judd

Allow transformations to be replaced.

上级 186211e3
......@@ -247,6 +247,9 @@ public class BitmapRequestBuilder<ModelType, TranscodeType>
/**
* Transform images using {@link com.bumptech.glide.load.resource.bitmap.CenterCrop}.
*
* @see #fitCenter()
* @see #transform(com.bumptech.glide.load.Transformation[])
*
* @return This request builder.
*/
public BitmapRequestBuilder<ModelType, TranscodeType> centerCrop() {
......@@ -256,6 +259,9 @@ public class BitmapRequestBuilder<ModelType, TranscodeType>
/**
* Transform images using {@link com.bumptech.glide.load.resource.bitmap.FitCenter}.
*
* @see #centerCrop()
* @see #transform(com.bumptech.glide.load.Transformation[])
*
* @return This request builder.
*/
public BitmapRequestBuilder<ModelType, TranscodeType> fitCenter() {
......@@ -264,10 +270,13 @@ public class BitmapRequestBuilder<ModelType, TranscodeType>
/**
* {@inheritDoc}
*
* @see #fitCenter()
* @see #centerCrop()
*/
@Override
public BitmapRequestBuilder<ModelType, TranscodeType> transform(Transformation<Bitmap> transformation) {
super.transform(transformation);
public BitmapRequestBuilder<ModelType, TranscodeType> transform(Transformation<Bitmap>... transformations) {
super.transform(transformations);
return this;
}
......
......@@ -144,6 +144,10 @@ public class DrawableRequestBuilder<ModelType>
/**
* Transform {@link Drawable}s using {@link com.bumptech.glide.load.resource.bitmap.CenterCrop}.
*
* @see #fitCenter()
* @see #bitmapTransform(com.bumptech.glide.load.Transformation[])
* @see #transform(com.bumptech.glide.load.Transformation[])
*
* @return This request builder.
*/
public DrawableRequestBuilder<ModelType> centerCrop() {
......@@ -154,6 +158,10 @@ public class DrawableRequestBuilder<ModelType>
* Transform {@link android.graphics.drawable.Drawable}s using
* {@link com.bumptech.glide.load.resource.bitmap.FitCenter}.
*
* @see #centerCrop()
* @see #bitmapTransform(com.bumptech.glide.load.Transformation[])
* @see #transform(com.bumptech.glide.load.Transformation[])
*
* @return This request builder.
*/
public DrawableRequestBuilder<ModelType> fitCenter() {
......@@ -161,19 +169,33 @@ public class DrawableRequestBuilder<ModelType>
}
/**
* Transform {@link android.graphics.drawable.Drawable}s using the given bitmap transformation.
* Transform {@link android.graphics.drawable.Drawable}s using the given {@link android.graphics.Bitmap}
* transformations. Replaces any previous transformations.
*
* @see #fitCenter()
* @see #centerCrop()
* @see #transform(com.bumptech.glide.load.Transformation[])
*
* @return This request builder.
*/
public DrawableRequestBuilder<ModelType> bitmapTransform(Transformation<Bitmap> bitmapTransformation) {
return transform(new GifBitmapWrapperTransformation(bitmapTransformation));
public DrawableRequestBuilder<ModelType> bitmapTransform(Transformation<Bitmap>... bitmapTransformations) {
GifBitmapWrapperTransformation[] transformations =
new GifBitmapWrapperTransformation[bitmapTransformations.length];
for (int i = 0; i < bitmapTransformations.length; i++) {
transformations[i] = new GifBitmapWrapperTransformation(bitmapTransformations[i]);
}
return transform(transformations);
}
/**
* {@inheritDoc}
*
* @see #bitmapTransform(com.bumptech.glide.load.Transformation[])
* @see #centerCrop()
* @see #fitCenter()
*/
@Override
public DrawableRequestBuilder<ModelType> transform(Transformation<GifBitmapWrapper> transformation) {
public DrawableRequestBuilder<ModelType> transform(Transformation<GifBitmapWrapper>... transformation) {
super.transform(transformation);
return this;
}
......
......@@ -31,8 +31,6 @@ import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.util.Util;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
/**
* A generic class that can handle loading a bitmap either from an image or as a thumbnail from a video given
......@@ -52,8 +50,6 @@ public class GenericRequestBuilder<ModelType, DataType, ResourceType, TranscodeT
private final Class<TranscodeType> transcodeClass;
private final Glide glide;
private final RequestTracker requestTracker;
private List<Transformation<ResourceType>> transformations = null;
private Transformation<ResourceType> singleTransformation = UnitTransformation.get();
private int placeholderId;
private int errorId;
private RequestListener<ModelType, TranscodeType> requestListener;
......@@ -69,6 +65,7 @@ public class GenericRequestBuilder<ModelType, DataType, ResourceType, TranscodeT
private int overrideHeight = -1;
private int overrideWidth = -1;
private DiskCacheStrategy diskCacheStrategy = DiskCacheStrategy.RESULT;
private Transformation<ResourceType> transformation = UnitTransformation.get();
GenericRequestBuilder(Context context, ModelType model,
LoadProvider<ModelType, DataType, ResourceType, TranscodeType> loadProvider,
......@@ -292,20 +289,18 @@ public class GenericRequestBuilder<ModelType, DataType, ResourceType, TranscodeT
}
/**
* Transform images with the given {@link Transformation}. Appends this transformation onto any existing
* transformations
* Transform resources with the given {@link Transformation}s. Replaces any existing transformation or
* transformations.
*
* @param transformation the transformation to apply.
* @param transformations the transformations to apply in order.
* @return This RequestBuilder
*/
public GenericRequestBuilder<ModelType, DataType, ResourceType, TranscodeType> transform(
Transformation<ResourceType> transformation) {
if (singleTransformation == UnitTransformation.get()) {
singleTransformation = transformation;
Transformation<ResourceType>... transformations) {
if (transformations.length == 1) {
transformation = transformations[0];
} else {
transformations = new ArrayList<Transformation<ResourceType>>();
transformations.add(singleTransformation);
transformations.add(transformation);
transformation = new MultiTransformation<ResourceType>(transformations);
}
return this;
......@@ -651,7 +646,7 @@ public class GenericRequestBuilder<ModelType, DataType, ResourceType, TranscodeT
requestListener,
requestCoordinator,
glide.getEngine(),
getFinalTransformation(),
transformation,
transcodeClass,
isCacheable,
animationFactory,
......@@ -659,13 +654,4 @@ public class GenericRequestBuilder<ModelType, DataType, ResourceType, TranscodeT
overrideHeight,
diskCacheStrategy);
}
@SuppressWarnings("unchecked")
private Transformation<ResourceType> getFinalTransformation() {
if (transformations == null) {
return singleTransformation;
} else {
return new MultiTransformation<ResourceType>(transformations);
}
}
}
......@@ -141,7 +141,9 @@ public class GifRequestBuilder<ModelType> extends GenericRequestBuilder<ModelTyp
/**
* Transforms each frame of the GIF using {@link com.bumptech.glide.load.resource.bitmap.CenterCrop}.
*
* @see #transformFrame(com.bumptech.glide.load.Transformation)
* @see #transformFrame(com.bumptech.glide.load.Transformation[])
* @see #fitCenter()
* @see #transform(com.bumptech.glide.load.Transformation[])
*
* @return This request builder.
*/
......@@ -152,7 +154,9 @@ public class GifRequestBuilder<ModelType> extends GenericRequestBuilder<ModelTyp
/**
* Transforms each frame of the GIF using {@link com.bumptech.glide.load.resource.bitmap.FitCenter}.
*
* @see #transformFrame(com.bumptech.glide.load.Transformation)
* @see #transformFrame(com.bumptech.glide.load.Transformation[])
* @see #centerCrop()
* @see #transform(com.bumptech.glide.load.Transformation[])
*
* @return This request builder..
*/
......@@ -163,19 +167,33 @@ public class GifRequestBuilder<ModelType> extends GenericRequestBuilder<ModelTyp
/**
* Transforms each frame of the GIF using the given transformation.
*
* @param bitmapTransformation The transformation to use.
* @see #fitCenter()
* @see #centerCrop()
* @see #transform(com.bumptech.glide.load.Transformation[])
*
* @param bitmapTransformations The transformation to use.
* @return This request builder.
*/
public GifRequestBuilder<ModelType> transformFrame(Transformation<Bitmap> bitmapTransformation) {
return transform(new GifDataTransformation(bitmapTransformation));
public GifRequestBuilder<ModelType> transformFrame(Transformation<Bitmap>... bitmapTransformations) {
GifDataTransformation[] transformations = new GifDataTransformation[bitmapTransformations.length];
for (int i = 0; i < bitmapTransformations.length; i++) {
transformations[i] = new GifDataTransformation(bitmapTransformations[i]);
}
return transform(transformations);
}
/**
* {@inheritDoc}
*
* @see #fitCenter()
* @see #centerCrop()
* @see #transformFrame(com.bumptech.glide.load.Transformation[])
*
*/
@Override
public GifRequestBuilder<ModelType> transform(Transformation<GifData> transformation) {
super.transform(transformation);
public GifRequestBuilder<ModelType> transform(Transformation<GifData>... transformations) {
super.transform(transformations);
return this;
}
......
......@@ -7,8 +7,8 @@ import com.bumptech.glide.load.ResourceEncoder;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.manager.RequestTracker;
import com.bumptech.glide.provider.LoadProvider;
import com.bumptech.glide.request.animation.GlideAnimationFactory;
import com.bumptech.glide.request.Request;
import com.bumptech.glide.request.animation.GlideAnimationFactory;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.tests.BackgroundUtil;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册