diff options
author | Sam Judd <judds@google.com> | 2014-07-09 15:15:56 -0700 |
---|---|---|
committer | Sam Judd <judds@google.com> | 2014-07-09 15:26:59 -0700 |
commit | d2c42cb991e9395f4560cb433ce796082d15e3da (patch) | |
tree | 2333c3dea2cfe3e9e65fdf1dc580df98c28ceb7d /library | |
parent | 5f4610b54d517be58105bcf73ce3291ba79f9f40 (diff) | |
download | glide-d2c42cb991e9395f4560cb433ce796082d15e3da.tar.gz |
Generalize animations and add to GifRequests
Diffstat (limited to 'library')
17 files changed, 241 insertions, 183 deletions
diff --git a/library/src/main/java/com/bumptech/glide/BitmapTypeRequest.java b/library/src/main/java/com/bumptech/glide/BitmapTypeRequest.java index aa8983e1..f3370c0d 100644 --- a/library/src/main/java/com/bumptech/glide/BitmapTypeRequest.java +++ b/library/src/main/java/com/bumptech/glide/BitmapTypeRequest.java @@ -20,13 +20,13 @@ import java.io.InputStream; * {@link com.bumptech.glide.load.resource.transcode.ResourceTranscoder} to transcode the {@link Bitmap} into another * resource type. * - * @param <A> The type of model to load the {@link Bitmap} or transcoded class from. + * @param <ModelType> The type of model to load the {@link Bitmap} or transcoded class from. */ -public class BitmapTypeRequest<A> extends BitmapRequestBuilder<A, Bitmap> { +public class BitmapTypeRequest<ModelType> extends BitmapRequestBuilder<ModelType, Bitmap> { private final Context context; - private final A model; - private final ModelLoader<A, InputStream> streamModelLoader; - private ModelLoader<A, ParcelFileDescriptor> fileDescriptorModelLoader; + private final ModelType model; + private final ModelLoader<ModelType, InputStream> streamModelLoader; + private ModelLoader<ModelType, ParcelFileDescriptor> fileDescriptorModelLoader; private final Glide glide; private RequestTracker requestTracker; private RequestManager.OptionsApplier optionsApplier; @@ -50,9 +50,9 @@ public class BitmapTypeRequest<A> extends BitmapRequestBuilder<A, Bitmap> { return new FixedLoadProvider<A, ImageVideoWrapper, Bitmap, R>(modelLoader, transcoder, loadProvider); } - BitmapTypeRequest(Context context, A model, - ModelLoader<A, InputStream> streamModelLoader, - ModelLoader<A, ParcelFileDescriptor> fileDescriptorModelLoader, + BitmapTypeRequest(Context context, ModelType model, + ModelLoader<ModelType, InputStream> streamModelLoader, + ModelLoader<ModelType, ParcelFileDescriptor> fileDescriptorModelLoader, Glide glide, RequestTracker requestTracker, RequestManager.OptionsApplier optionsApplier) { super(context, model, buildProvider(glide, streamModelLoader, fileDescriptorModelLoader, Bitmap.class, null), @@ -75,8 +75,9 @@ public class BitmapTypeRequest<A> extends BitmapRequestBuilder<A, Bitmap> { * @param <R> The type of the resource the {@link Bitmap} will be transcoded to. * @return This request builder. */ - public <R> BitmapRequestBuilder<A, R> transcode(ResourceTranscoder<Bitmap, R> transcoder, Class<R> transcodeClass) { - return optionsApplier.apply(model, new BitmapRequestBuilder<A, R>(context, model, + public <R> BitmapRequestBuilder<ModelType, R> transcode(ResourceTranscoder<Bitmap, R> transcoder, + Class<R> transcodeClass) { + return optionsApplier.apply(model, new BitmapRequestBuilder<ModelType, R>(context, model, buildProvider(glide, streamModelLoader, fileDescriptorModelLoader, transcodeClass, transcoder), transcodeClass, glide, requestTracker)); } @@ -89,7 +90,7 @@ public class BitmapTypeRequest<A> extends BitmapRequestBuilder<A, Bitmap> { * * @return This request builder. */ - public BitmapRequestBuilder<A, byte[]> toBytes() { + public BitmapRequestBuilder<ModelType, byte[]> toBytes() { return transcode(new BitmapBytesTranscoder(), byte[].class); } @@ -104,7 +105,7 @@ public class BitmapTypeRequest<A> extends BitmapRequestBuilder<A, Bitmap> { * @param quality The quality level from 0-100 to use to compress the {@link Bitmap}. * @return This request builder. */ - public BitmapRequestBuilder<A, byte[]> toBytes(Bitmap.CompressFormat compressFormat, int quality) { + public BitmapRequestBuilder<ModelType, byte[]> toBytes(Bitmap.CompressFormat compressFormat, int quality) { return transcode(new BitmapBytesTranscoder(compressFormat, quality), byte[].class); } } diff --git a/library/src/main/java/com/bumptech/glide/DrawableOptions.java b/library/src/main/java/com/bumptech/glide/DrawableOptions.java new file mode 100644 index 00000000..2f8e3a4b --- /dev/null +++ b/library/src/main/java/com/bumptech/glide/DrawableOptions.java @@ -0,0 +1,83 @@ +package com.bumptech.glide; + +import android.view.animation.Animation; + +public interface DrawableOptions { + + /** + * Applies a cross fade transformation that fades from the placeholder to the loaded + * {@link android.graphics.drawable.Drawable}. If no placeholder is set, the Drawable will instead simply fade in. + * + * <p> + * Note - this only works by default for {@link android.view.View}s and + * {@link com.bumptech.glide.request.target.ViewTarget}s. + * </p> + * + * @see #crossFade(int) + * @see #crossFade(int, int) + * @see #crossFade(android.view.animation.Animation, int) + * + * @return This request builder. + */ + public GenericRequestBuilder<?, ?, ?, ?> crossFade(); + + /** + * Applies a cross fade transformation that fades from the placeholder to the loaded + * {@link android.graphics.drawable.Drawable}. If no placeholder is set the Drawable will instead simply fade in. + * + * <p> + * Note - this only works by default for {@link android.view.View}s and + * {@link com.bumptech.glide.request.target.ViewTarget}s. + * </p> + * + * @see #crossFade() + * @see #crossFade(int, int) + * @see #crossFade(android.view.animation.Animation, int) + * + * @param duration The duration of the cross fade and initial fade in. + * @return This request builder. + */ + public GenericRequestBuilder<?, ?, ?, ?> crossFade(int duration); + + + /** + * Applies a cross fade transformation that des from the placeholder to the loaded + * {@link android.graphics.drawable.Drawable}. If no placeholder is set, the Drawable will instead be animated in + * using the given {@link android.view.animation.Animation}. + * + * <p> + * Note - this only works by default for {@link android.view.View}s and + * {@link com.bumptech.glide.request.target.ViewTarget}s. + * </p> + * + * @see #crossFade() + * @see #crossFade(int) + * @see #crossFade(int, int) + * + * @param animation The Animation to use if no placeholder is set. + * @param duration The duration of the cross fade animation. + * @return This request builder. + */ + public GenericRequestBuilder<?, ?, ?, ?> crossFade(Animation animation, int duration); + + + /** + * Applies a cross fade transformation that des from the placeholder to the loaded + * {@link android.graphics.drawable.Drawable}. If no placeholder is set, the Drawable will instead be animated in + * using the {@link android.view.animation.Animation} loaded from the given animation id. + * + * <p> + * Note - this only works by default for {@link android.view.View}s and + * {@link com.bumptech.glide.request.target.ViewTarget}s. + * </p> + * + * @see #crossFade() + * @see #crossFade(int) + * @see #crossFade(android.view.animation.Animation, int) + * + * @param animationId The id of the Animation to use if no placeholder is set. + * @param duration The duration of the cross fade animation. + * @return This request builder. + */ + public GenericRequestBuilder<?, ?, ?, ?> crossFade(int animationId, int duration); +} diff --git a/library/src/main/java/com/bumptech/glide/DrawableRequestBuilder.java b/library/src/main/java/com/bumptech/glide/DrawableRequestBuilder.java index 9a5c8855..96a31c87 100644 --- a/library/src/main/java/com/bumptech/glide/DrawableRequestBuilder.java +++ b/library/src/main/java/com/bumptech/glide/DrawableRequestBuilder.java @@ -29,7 +29,7 @@ import java.io.File; */ public class DrawableRequestBuilder<ModelType> extends GenericRequestBuilder<ModelType, ImageVideoWrapper, GifBitmapWrapper, Drawable> - implements BitmapOptions { + implements BitmapOptions, DrawableOptions { private final Glide glide; private final Context context; @@ -186,90 +186,35 @@ public class DrawableRequestBuilder<ModelType> } /** - * Applies a cross fade transformation that fades from the placeholder to the loaded - * {@link android.graphics.drawable.Drawable}. If no placeholder is set, the Drawable will instead simply fade in. - * - * <p> - * Note - this only works by default for {@link android.view.View}s and - * {@link com.bumptech.glide.request.target.ViewTarget}s. - * </p> - * - * @see #crossFade(int) - * @see #crossFade(int, int) - * @see #crossFade(android.view.animation.Animation, int) - * - * @return This request builder. + * {@inheritDoc} */ public DrawableRequestBuilder<ModelType> crossFade() { - super.animate(new DrawableCrossFadeViewAnimation.DrawableCrossFadeFactory()); + super.animate(new DrawableCrossFadeViewAnimation.DrawableCrossFadeFactory<Drawable>()); return this; } /** - * Applies a cross fade transformation that fades from the placeholder to the loaded - * {@link android.graphics.drawable.Drawable}. If no placeholder is set the Drawable will instead simply fade in. - * - * <p> - * Note - this only works by default for {@link android.view.View}s and - * {@link com.bumptech.glide.request.target.ViewTarget}s. - * </p> - * - * @see #crossFade() - * @see #crossFade(int, int) - * @see #crossFade(android.view.animation.Animation, int) - * - * @param duration The duration of the cross fade and initial fade in. - * @return This request builder. + * {@inheritDoc} */ public DrawableRequestBuilder<ModelType> crossFade(int duration) { - super.animate(new DrawableCrossFadeViewAnimation.DrawableCrossFadeFactory(duration)); + super.animate(new DrawableCrossFadeViewAnimation.DrawableCrossFadeFactory<Drawable>(duration)); return this; } /** - * Applies a cross fade transformation that des from the placeholder to the loaded - * {@link android.graphics.drawable.Drawable}. If no placeholder is set, the Drawable will instead be animated in - * using the given {@link android.view.animation.Animation}. - * - * <p> - * Note - this only works by default for {@link android.view.View}s and - * {@link com.bumptech.glide.request.target.ViewTarget}s. - * </p> - * - * @see #crossFade() - * @see #crossFade(int) - * @see #crossFade(int, int) - * - * @param animation The Animation to use if no placeholder is set. - * @param duration The duration of the cross fade animation. - * @return This request builder. + * {@inheritDoc} */ public DrawableRequestBuilder<ModelType> crossFade(Animation animation, int duration) { - super.animate(new DrawableCrossFadeViewAnimation.DrawableCrossFadeFactory(animation, duration)); + super.animate(new DrawableCrossFadeViewAnimation.DrawableCrossFadeFactory<Drawable>(animation, duration)); return this; } - /** - * Applies a cross fade transformation that des from the placeholder to the loaded - * {@link android.graphics.drawable.Drawable}. If no placeholder is set, the Drawable will instead be animated in - * using the {@link android.view.animation.Animation} loaded from the given animation id. - * - * <p> - * Note - this only works by default for {@link android.view.View}s and - * {@link com.bumptech.glide.request.target.ViewTarget}s. - * </p> - * - * @see #crossFade() - * @see #crossFade(int) - * @see #crossFade(android.view.animation.Animation, int) - * - * @param animationId The id of the Animation to use if no placeholder is set. - * @param duration The duration of the cross fade animation. - * @return This request builder. + * {@inheritDoc} */ public DrawableRequestBuilder<ModelType> crossFade(int animationId, int duration) { - super.animate(new DrawableCrossFadeViewAnimation.DrawableCrossFadeFactory(context, animationId, duration)); + super.animate(new DrawableCrossFadeViewAnimation.DrawableCrossFadeFactory<Drawable>(context, animationId, + duration)); return this; } diff --git a/library/src/main/java/com/bumptech/glide/DrawableTypeRequest.java b/library/src/main/java/com/bumptech/glide/DrawableTypeRequest.java index 35f7310f..d655d450 100644 --- a/library/src/main/java/com/bumptech/glide/DrawableTypeRequest.java +++ b/library/src/main/java/com/bumptech/glide/DrawableTypeRequest.java @@ -23,17 +23,17 @@ import java.io.InputStream; * adds an {@link com.bumptech.glide.load.resource.transcode.ResourceTranscoder} to transcode the data into a * resource type other than a {@link android.graphics.drawable.Drawable}. * - * @param <A> The type of model to use to load the {@link android.graphics.drawable.BitmapDrawable} or + * @param <ModelType> The type of model to use to load the {@link android.graphics.drawable.BitmapDrawable} or * {@link com.bumptech.glide.load.resource.gif.GifDrawable}. */ -public class DrawableTypeRequest<A> extends DrawableRequestBuilder<A> implements DownloadOptions { - private final ModelLoader<A, InputStream> streamModelLoader; - private final ModelLoader<A, ParcelFileDescriptor> fileDescriptorModelLoader; +public class DrawableTypeRequest<ModelType> extends DrawableRequestBuilder<ModelType> implements DownloadOptions { + private final ModelLoader<ModelType, InputStream> streamModelLoader; + private final ModelLoader<ModelType, ParcelFileDescriptor> fileDescriptorModelLoader; private final Context context; private final Glide glide; private RequestTracker requestTracker; private RequestManager.OptionsApplier optionsApplier; - private final A model; + private final ModelType model; private static <A, Z, R> FixedLoadProvider<A, ImageVideoWrapper, Z, R> buildProvider(Glide glide, ModelLoader<A, InputStream> streamModelLoader, @@ -54,8 +54,8 @@ public class DrawableTypeRequest<A> extends DrawableRequestBuilder<A> implements return new FixedLoadProvider<A, ImageVideoWrapper, Z, R>(modelLoader, transcoder, dataLoadProvider); } - DrawableTypeRequest(A model, ModelLoader<A, InputStream> streamModelLoader, - ModelLoader<A, ParcelFileDescriptor> fileDescriptorModelLoader, Context context, Glide glide, + DrawableTypeRequest(ModelType model, ModelLoader<ModelType, InputStream> streamModelLoader, + ModelLoader<ModelType, ParcelFileDescriptor> fileDescriptorModelLoader, Context context, Glide glide, RequestTracker requestTracker, RequestManager.OptionsApplier optionsApplier) { super(context, model, buildProvider(glide, streamModelLoader, fileDescriptorModelLoader, GifBitmapWrapper.class, @@ -75,8 +75,8 @@ public class DrawableTypeRequest<A> extends DrawableRequestBuilder<A> implements * * @return A new request builder for loading a {@link android.graphics.Bitmap} */ - public BitmapTypeRequest<A> asBitmap() { - return optionsApplier.apply(model, new BitmapTypeRequest<A>(context, model, streamModelLoader, + public BitmapTypeRequest<ModelType> asBitmap() { + return optionsApplier.apply(model, new BitmapTypeRequest<ModelType>(context, model, streamModelLoader, fileDescriptorModelLoader, glide, requestTracker, optionsApplier)); } @@ -92,8 +92,8 @@ public class DrawableTypeRequest<A> extends DrawableRequestBuilder<A> implements * * @return A new request builder for loading a {@link com.bumptech.glide.load.resource.gif.GifDrawable}. */ - public GifTypeRequest<A> asGif() { - return optionsApplier.apply(model, new GifTypeRequest<A>(context, model, streamModelLoader, glide, + public GifTypeRequest<ModelType> asGif() { + return optionsApplier.apply(model, new GifTypeRequest<ModelType>(context, model, streamModelLoader, glide, requestTracker, optionsApplier)); } @@ -120,8 +120,8 @@ public class DrawableTypeRequest<A> extends DrawableRequestBuilder<A> implements return getDownloadOnlyRequest().downloadOnly(width, height); } - private GenericTranscodeRequest<A, InputStream, File> getDownloadOnlyRequest() { - return optionsApplier.apply(model, new GenericTranscodeRequest<A, InputStream, File>(context, glide, model, - streamModelLoader, InputStream.class, File.class, requestTracker, optionsApplier)); + private GenericTranscodeRequest<ModelType, InputStream, File> getDownloadOnlyRequest() { + return optionsApplier.apply(model, new GenericTranscodeRequest<ModelType, InputStream, File>(context, glide, + model, streamModelLoader, InputStream.class, File.class, requestTracker, optionsApplier)); } } diff --git a/library/src/main/java/com/bumptech/glide/GenericTranscodeRequest.java b/library/src/main/java/com/bumptech/glide/GenericTranscodeRequest.java index 4fa45389..c6da01a8 100644 --- a/library/src/main/java/com/bumptech/glide/GenericTranscodeRequest.java +++ b/library/src/main/java/com/bumptech/glide/GenericTranscodeRequest.java @@ -19,17 +19,18 @@ import java.io.File; * A class for handling requests to load a generic resource type or transcode the generic resource type into another * generic resource type. * - * @param <A> The type of the model used to retrieve data. - * @param <T> The type of data retrieved. - * @param <Z> The type of resource to be decoded from the the data. + * @param <ModelType> The type of the model used to retrieve data. + * @param <DataType> The type of data retrieved. + * @param <ResourceType> The type of resource to be decoded from the the data. */ -public class GenericTranscodeRequest<A, T, Z> extends GenericRequestBuilder<A, T, Z, Z> implements DownloadOptions { +public class GenericTranscodeRequest<ModelType, DataType, ResourceType> + extends GenericRequestBuilder<ModelType, DataType, ResourceType, ResourceType> implements DownloadOptions { private final Context context; - private final A model; + private final ModelType model; private final Glide glide; - private final ModelLoader<A, T> modelLoader; - private final Class<T> dataClass; - private final Class<Z> resourceClass; + private final ModelLoader<ModelType, DataType> modelLoader; + private final Class<DataType> dataClass; + private final Class<ResourceType> resourceClass; private final RequestTracker requestTracker; private final RequestManager.OptionsApplier optionsApplier; @@ -42,12 +43,11 @@ public class GenericTranscodeRequest<A, T, Z> extends GenericRequestBuilder<A, T return new FixedLoadProvider<A, T, Z, R>(modelLoader, transcoder, dataLoadProvider); } - GenericTranscodeRequest(Context context, Glide glide, A model, ModelLoader<A, T> modelLoader, - Class<T> dataClass, Class<Z> resourceClass, RequestTracker requestTracker, + GenericTranscodeRequest(Context context, Glide glide, ModelType model, ModelLoader<ModelType, DataType> modelLoader, + Class<DataType> dataClass, Class<ResourceType> resourceClass, RequestTracker requestTracker, RequestManager.OptionsApplier optionsApplier) { - super(context, model, - build(glide, modelLoader, dataClass, resourceClass, (ResourceTranscoder<Z, Z>) null), - resourceClass, glide, requestTracker); + super(context, model, build(glide, modelLoader, dataClass, resourceClass, + (ResourceTranscoder<ResourceType, ResourceType>) null), resourceClass, glide, requestTracker); this.context = context; this.model = model; this.glide = glide; @@ -63,14 +63,18 @@ public class GenericTranscodeRequest<A, T, Z> extends GenericRequestBuilder<A, T * * @param transcoder The transcoder to use. * @param transcodeClass The class of the resource type that will be transcoded to. - * @param <R> The type of the resource that will be transcoded to. + * @param <TranscodeType> The type of the resource that will be transcoded to. * @return A new request builder to set options for the transcoded load. */ - public <R> GenericRequestBuilder<A, T, Z, R> transcode(ResourceTranscoder<Z, R> transcoder, - Class<R> transcodeClass) { - return optionsApplier.apply(model, new GenericRequestBuilder<A, T, Z, R>(context, model, - build(glide, modelLoader, dataClass, resourceClass, transcoder), transcodeClass, glide, - requestTracker)); + public <TranscodeType> GenericRequestBuilder<ModelType, DataType, ResourceType, TranscodeType> transcode( + ResourceTranscoder<ResourceType, TranscodeType> transcoder, + Class<TranscodeType> transcodeClass) { + LoadProvider<ModelType, DataType, ResourceType, TranscodeType> loadProvider = build(glide, modelLoader, + dataClass, resourceClass, transcoder); + + return optionsApplier.apply(model, + new GenericRequestBuilder<ModelType, DataType, ResourceType, TranscodeType>(context, model, + loadProvider, transcodeClass, glide, requestTracker)); } /** @@ -96,12 +100,12 @@ public class GenericTranscodeRequest<A, T, Z> extends GenericRequestBuilder<A, T return getDownloadOnlyRequest().into(width, height); } - private GenericRequestBuilder<A, T, File, File> getDownloadOnlyRequest() { + private GenericRequestBuilder<ModelType, DataType, File, File> getDownloadOnlyRequest() { ResourceTranscoder<File, File> transcoder = UnitTranscoder.get(); - DataLoadProvider<T, File> dataLoadProvider = glide.buildDataProvider(dataClass, File.class); - FixedLoadProvider<A, T, File, File> fixedLoadProvider = new FixedLoadProvider<A, T, File, File>(modelLoader, - transcoder, dataLoadProvider); - return optionsApplier.apply(model, new GenericRequestBuilder<A, T, File, File>(context, model, + DataLoadProvider<DataType, File> dataLoadProvider = glide.buildDataProvider(dataClass, File.class); + FixedLoadProvider<ModelType, DataType, File, File> fixedLoadProvider = + new FixedLoadProvider<ModelType, DataType, File, File>(modelLoader, transcoder, dataLoadProvider); + return optionsApplier.apply(model, new GenericRequestBuilder<ModelType, DataType, File, File>(context, model, fixedLoadProvider, File.class, glide, requestTracker) diff --git a/library/src/main/java/com/bumptech/glide/GifTypeRequest.java b/library/src/main/java/com/bumptech/glide/GifTypeRequest.java index 396da00b..e0ea8de6 100644 --- a/library/src/main/java/com/bumptech/glide/GifTypeRequest.java +++ b/library/src/main/java/com/bumptech/glide/GifTypeRequest.java @@ -1,6 +1,7 @@ package com.bumptech.glide; import android.content.Context; +import android.view.animation.Animation; import com.bumptech.glide.load.model.ModelLoader; import com.bumptech.glide.load.resource.gif.GifData; @@ -10,6 +11,7 @@ import com.bumptech.glide.load.resource.transcode.ResourceTranscoder; import com.bumptech.glide.manager.RequestTracker; import com.bumptech.glide.provider.DataLoadProvider; import com.bumptech.glide.provider.FixedLoadProvider; +import com.bumptech.glide.request.animation.DrawableCrossFadeViewAnimation; import java.io.InputStream; @@ -18,13 +20,13 @@ import java.io.InputStream; * directly or that adds an {@link com.bumptech.glide.load.resource.transcode.ResourceTranscoder} to transcode * {@link com.bumptech.glide.load.resource.gif.GifData} into another resource type. * - * @param <A> The type of model to load the {@link com.bumptech.glide.load.resource.gif.GifDrawable} or other + * @param <ModelType> The type of model to load the {@link com.bumptech.glide.load.resource.gif.GifDrawable} or other * transcoded class from. */ -public class GifTypeRequest<A> extends GifRequestBuilder<A, GifDrawable> { +public class GifTypeRequest<ModelType> extends GifRequestBuilder<ModelType, GifDrawable> implements DrawableOptions { private final Context context; - private final A model; - private final ModelLoader<A, InputStream> streamModelLoader; + private final ModelType model; + private final ModelLoader<ModelType, InputStream> streamModelLoader; private final Glide glide; private final RequestTracker requestTracker; private RequestManager.OptionsApplier optionsApplier; @@ -45,7 +47,7 @@ public class GifTypeRequest<A> extends GifRequestBuilder<A, GifDrawable> { } - GifTypeRequest(Context context, A model, ModelLoader<A, InputStream> streamModelLoader, Glide glide, + GifTypeRequest(Context context, ModelType model, ModelLoader<ModelType, InputStream> streamModelLoader, Glide glide, RequestTracker requestTracker, RequestManager.OptionsApplier optionsApplier) { super(context, model, buildProvider(glide, streamModelLoader, GifDrawable.class, null), GifDrawable.class, glide, requestTracker); @@ -69,8 +71,9 @@ public class GifTypeRequest<A> extends GifRequestBuilder<A, GifDrawable> { * trasncoded to. * @return This request builder. */ - public <R> GifRequestBuilder<A, R> transcode(ResourceTranscoder<GifData, R> transcoder, Class<R> transcodeClass) { - return optionsApplier.apply(model, new GifRequestBuilder<A, R>(context, model, + public <R> GifRequestBuilder<ModelType, R> transcode(ResourceTranscoder<GifData, R> transcoder, + Class<R> transcodeClass) { + return optionsApplier.apply(model, new GifRequestBuilder<ModelType, R>(context, model, buildProvider(glide, streamModelLoader, transcodeClass, transcoder), transcodeClass, glide, requestTracker)); } @@ -84,7 +87,44 @@ public class GifTypeRequest<A> extends GifRequestBuilder<A, GifDrawable> { * * @return A new Builder object to build a request to transform the given model into the bytes of an animated gif. */ - public GifRequestBuilder<A, byte[]> toBytes() { + public GifRequestBuilder<ModelType, byte[]> toBytes() { return transcode(new GifDataBytesTranscoder(), byte[].class); } + + /** + * {@inheritDoc} + */ + @Override + public GifTypeRequest<ModelType> crossFade() { + super.animate(new DrawableCrossFadeViewAnimation.DrawableCrossFadeFactory<GifDrawable>()); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public GifTypeRequest<ModelType> crossFade(int duration) { + super.animate(new DrawableCrossFadeViewAnimation.DrawableCrossFadeFactory<GifDrawable>(duration)); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public GifTypeRequest<ModelType> crossFade(Animation animation, int duration) { + super.animate(new DrawableCrossFadeViewAnimation.DrawableCrossFadeFactory<GifDrawable>(animation, duration)); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public GifTypeRequest<ModelType> crossFade(int animationId, int duration) { + super.animate(new DrawableCrossFadeViewAnimation.DrawableCrossFadeFactory<GifDrawable>(context, animationId, + duration)); + return this; + } } diff --git a/library/src/main/java/com/bumptech/glide/request/animation/DrawableCrossFadeViewAnimation.java b/library/src/main/java/com/bumptech/glide/request/animation/DrawableCrossFadeViewAnimation.java index 27526f63..761b85d1 100644 --- a/library/src/main/java/com/bumptech/glide/request/animation/DrawableCrossFadeViewAnimation.java +++ b/library/src/main/java/com/bumptech/glide/request/animation/DrawableCrossFadeViewAnimation.java @@ -3,12 +3,10 @@ package com.bumptech.glide.request.animation; import android.content.Context; import android.graphics.drawable.Drawable; import android.graphics.drawable.TransitionDrawable; -import android.view.View; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.view.animation.AnimationUtils; - -import com.bumptech.glide.request.target.Target; +import android.widget.ImageView; /** * A cross fade {@link GlideAnimation} for {@link android.graphics.drawable.Drawable}s @@ -16,7 +14,7 @@ import com.bumptech.glide.request.target.Target; * already visible on the target to a new drawable. If no existing drawable exists, this class can instead fall back * to a default animation that doesn't rely on {@link android.graphics.drawable.TransitionDrawable}. */ -public class DrawableCrossFadeViewAnimation implements GlideAnimation<Drawable> { +public class DrawableCrossFadeViewAnimation<T extends Drawable> implements GlideAnimation<T> { // 150 ms. public static final int DEFAULT_DURATION = 300; private Animation defaultAnimation; @@ -40,12 +38,12 @@ public class DrawableCrossFadeViewAnimation implements GlideAnimation<Drawable> * cache this factory producdes an {@link NoAnimation}. * </p> */ - public static class DrawableCrossFadeFactory implements GlideAnimationFactory<Drawable> { + public static class DrawableCrossFadeFactory<T extends Drawable> implements GlideAnimationFactory<T> { private Context context; private int defaultAnimationId; private Animation defaultAnimation; private int duration; - private DrawableCrossFadeViewAnimation animation; + private DrawableCrossFadeViewAnimation<T> animation; public DrawableCrossFadeFactory() { this(getDefaultAnimation(), DEFAULT_DURATION); @@ -67,7 +65,7 @@ public class DrawableCrossFadeViewAnimation implements GlideAnimation<Drawable> } @Override - public GlideAnimation<Drawable> build(boolean isFromMemoryCache, boolean isFirstImage) { + public GlideAnimation<T> build(boolean isFromMemoryCache, boolean isFirstImage) { if (isFromMemoryCache) { return NoAnimation.get(); } @@ -76,7 +74,7 @@ public class DrawableCrossFadeViewAnimation implements GlideAnimation<Drawable> if (defaultAnimation == null) { defaultAnimation = AnimationUtils.loadAnimation(context, defaultAnimationId); } - animation = new DrawableCrossFadeViewAnimation(defaultAnimation, duration); + animation = new DrawableCrossFadeViewAnimation<T>(defaultAnimation, duration); } return animation; @@ -108,19 +106,17 @@ public class DrawableCrossFadeViewAnimation implements GlideAnimation<Drawable> * @param previous The previous drawable that is currently being displayed in the {@link android.view.View}. * @param current The new drawable that should be displayed in the {@link com.bumptech.glide.request.target.Target} * after this animation completes. - * @param view The {@link android.view.View} the animation should run on. - * @param target The {@link com.bumptech.glide.request.target.Target} wrapping the given view. + * @param view The {@link android.widget.ImageView} the animation should run on. * @return true if in the process of running the animation the current drawable is set on the view, false if the * current drawable must be set on the view manually by the caller of this method. */ @Override - public boolean animate(Drawable previous, Drawable current, View view, Target<Drawable> target) { + public boolean animate(Drawable previous, T current, ImageView view) { if (previous != null) { TransitionDrawable transitionDrawable = new TransitionDrawable(new Drawable[] { previous, current }); transitionDrawable.setCrossFadeEnabled(true); transitionDrawable.startTransition(duration); - GlideAnimation<Drawable> none = NoAnimation.get(); - target.onResourceReady(transitionDrawable, none); + view.setImageDrawable(transitionDrawable); return true; } else { view.startAnimation(defaultAnimation); diff --git a/library/src/main/java/com/bumptech/glide/request/animation/GlideAnimation.java b/library/src/main/java/com/bumptech/glide/request/animation/GlideAnimation.java index 22915688..02dc8f18 100644 --- a/library/src/main/java/com/bumptech/glide/request/animation/GlideAnimation.java +++ b/library/src/main/java/com/bumptech/glide/request/animation/GlideAnimation.java @@ -1,8 +1,7 @@ package com.bumptech.glide.request.animation; import android.graphics.drawable.Drawable; -import android.view.View; -import com.bumptech.glide.request.target.Target; +import android.widget.ImageView; /** * An interface that allows a transformation to be applied to {@link android.view.View}s in @@ -21,9 +20,8 @@ public interface GlideAnimation<R> { * @param previous The {@link android.graphics.drawable.Drawable} currently displayed in the given view. * @param current The new resource that will be displayed in the view. * @param view The view. - * @param target The target wrapping the view. * @return True if int he process of running the animation the new resource was set on the view, false if the caller * needs to manually set the current resource on the view. */ - public boolean animate(Drawable previous, R current, View view, Target<R> target); + public boolean animate(Drawable previous, R current, ImageView view); } diff --git a/library/src/main/java/com/bumptech/glide/request/animation/NoAnimation.java b/library/src/main/java/com/bumptech/glide/request/animation/NoAnimation.java index e2935dba..3b635178 100644 --- a/library/src/main/java/com/bumptech/glide/request/animation/NoAnimation.java +++ b/library/src/main/java/com/bumptech/glide/request/animation/NoAnimation.java @@ -1,8 +1,7 @@ package com.bumptech.glide.request.animation; import android.graphics.drawable.Drawable; -import android.view.View; -import com.bumptech.glide.request.target.Target; +import android.widget.ImageView; /** * A simple {@link com.bumptech.glide.request.animation.GlideAnimation} that performs no actions. @@ -38,7 +37,7 @@ public class NoAnimation implements GlideAnimation { * Performs no animation and always returns {@code false}. */ @Override - public boolean animate(Drawable previous, Object current, View view, Target target) { + public boolean animate(Drawable previous, Object current, ImageView view) { return false; } } diff --git a/library/src/main/java/com/bumptech/glide/request/animation/ViewAnimation.java b/library/src/main/java/com/bumptech/glide/request/animation/ViewAnimation.java index ade643b6..7951b5cf 100644 --- a/library/src/main/java/com/bumptech/glide/request/animation/ViewAnimation.java +++ b/library/src/main/java/com/bumptech/glide/request/animation/ViewAnimation.java @@ -2,10 +2,9 @@ package com.bumptech.glide.request.animation; import android.content.Context; import android.graphics.drawable.Drawable; -import android.view.View; import android.view.animation.Animation; import android.view.animation.AnimationUtils; -import com.bumptech.glide.request.target.Target; +import android.widget.ImageView; /** * An {@link com.bumptech.glide.request.animation.GlideAnimation} that can apply a @@ -71,17 +70,16 @@ public class ViewAnimation implements GlideAnimation { /** * Always clears the current animation on the view using {@link android.view.View#clearAnimation()}, then * starts the {@link android.view.animation.Animation} given in the constructor using - * {@link View#startAnimation(android.view.animation.Animation)} and then returns {@code false} because the - * animation does not actually set the current resource on the view. + * {@link android.view.View#startAnimation(android.view.animation.Animation)} and then returns {@code false} because + * the animation does not actually set the current resource on the view. * * @param previous {@inheritDoc} * @param current {@inheritDoc} * @param view {@inheritDoc} - * @param target {@inheritDoc} * @return {@inheritDoc} */ @Override - public boolean animate(Drawable previous, Object current, View view, Target target) { + public boolean animate(Drawable previous, Object current, ImageView view) { view.clearAnimation(); view.startAnimation(animation); diff --git a/library/src/main/java/com/bumptech/glide/request/animation/ViewPropertyAnimation.java b/library/src/main/java/com/bumptech/glide/request/animation/ViewPropertyAnimation.java index 893b4981..6e4f8e38 100644 --- a/library/src/main/java/com/bumptech/glide/request/animation/ViewPropertyAnimation.java +++ b/library/src/main/java/com/bumptech/glide/request/animation/ViewPropertyAnimation.java @@ -2,7 +2,7 @@ package com.bumptech.glide.request.animation; import android.graphics.drawable.Drawable; import android.view.View; -import com.bumptech.glide.request.target.Target; +import android.widget.ImageView; /** * An {@link com.bumptech.glide.request.animation.GlideAnimation} that accepts an interface that can apply an @@ -75,11 +75,10 @@ public class ViewPropertyAnimation implements GlideAnimation { * @param previous {@inheritDoc} * @param current {@inheritDoc} * @param view {@inheritDoc} - * @param target {@inheritDoc} * @return {@inheritDoc} */ @Override - public boolean animate(Drawable previous, Object current, View view, Target target) { + public boolean animate(Drawable previous, Object current, ImageView view) { animator.animate(view); return false; } diff --git a/library/src/main/java/com/bumptech/glide/request/target/BitmapImageViewTarget.java b/library/src/main/java/com/bumptech/glide/request/target/BitmapImageViewTarget.java index c74ec5bd..2cc1bb9b 100644 --- a/library/src/main/java/com/bumptech/glide/request/target/BitmapImageViewTarget.java +++ b/library/src/main/java/com/bumptech/glide/request/target/BitmapImageViewTarget.java @@ -30,7 +30,7 @@ public class BitmapImageViewTarget extends ViewTarget<ImageView, Bitmap> { */ @Override public void onResourceReady(Bitmap resource, GlideAnimation<Bitmap> glideAnimation) { - if (glideAnimation == null || !glideAnimation.animate(view.getDrawable(), resource, view, this)) { + if (glideAnimation == null || !glideAnimation.animate(view.getDrawable(), resource, view)) { view.setImageBitmap(resource); } } diff --git a/library/src/main/java/com/bumptech/glide/request/target/DrawableImageViewTarget.java b/library/src/main/java/com/bumptech/glide/request/target/DrawableImageViewTarget.java index 0ea5292c..ac677607 100644 --- a/library/src/main/java/com/bumptech/glide/request/target/DrawableImageViewTarget.java +++ b/library/src/main/java/com/bumptech/glide/request/target/DrawableImageViewTarget.java @@ -45,7 +45,7 @@ public class DrawableImageViewTarget extends ViewTarget<ImageView, Drawable> { } } - if (animation == null || !animation.animate(view.getDrawable(), resource, view, this)) { + if (animation == null || !animation.animate(view.getDrawable(), resource, view)) { view.setImageDrawable(resource); } } diff --git a/library/src/test/java/com/bumptech/glide/request/animation/DrawableCrossFadeViewAnimationTest.java b/library/src/test/java/com/bumptech/glide/request/animation/DrawableCrossFadeViewAnimationTest.java index e0c00667..0cc5765c 100644 --- a/library/src/test/java/com/bumptech/glide/request/animation/DrawableCrossFadeViewAnimationTest.java +++ b/library/src/test/java/com/bumptech/glide/request/animation/DrawableCrossFadeViewAnimationTest.java @@ -4,22 +4,18 @@ import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.TransitionDrawable; -import android.view.View; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; - -import com.bumptech.glide.request.target.Target; +import android.widget.ImageView; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.robolectric.Robolectric; import org.robolectric.RobolectricTestRunner; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -34,40 +30,38 @@ public class DrawableCrossFadeViewAnimationTest { @Test public void testStartsDefaultAnimationIfNoPreviousDrawableIsNotSet() { - harness.view = mock(View.class); - harness.animation.animate(harness.previous, harness.current, harness.view, harness.target); + harness.animation.animate(harness.previous, harness.current, harness.view); verify(harness.view).startAnimation(any(Animation.class)); } @Test public void testReturnsFalseIfStartsDefaultAnimation() { - assertFalse(harness.animation.animate(harness.previous, harness.current, harness.view, harness.target)); + assertFalse(harness.animation.animate(harness.previous, harness.current, harness.view)); } @Test public void testSetsTransitionDrawableIfPreviousIsNotNull() { harness.previous = new ColorDrawable(Color.WHITE); - harness.animation.animate(harness.previous, harness.current, harness.view, harness.target); + harness.animation.animate(harness.previous, harness.current, harness.view); - GlideAnimation<Drawable> noAnimation = NoAnimation.get(); - verify(harness.target).onResourceReady(any(TransitionDrawable.class), eq(noAnimation)); + verify(harness.view).setImageDrawable(any(TransitionDrawable.class)); } @Test public void testReturnsTrueIfSetsTransitionDrawable() { harness.previous = new ColorDrawable(Color.RED); - assertTrue(harness.animation.animate(harness.previous, harness.current, harness.view, harness.target)); + assertTrue(harness.animation.animate(harness.previous, harness.current, harness.view)); } @SuppressWarnings("unchecked") private static class CrossFadeHarness { Drawable previous = null; Drawable current = new ColorDrawable(Color.GRAY); - Target<Drawable> target = mock(Target.class); - View view = new View(Robolectric.application); + ImageView view = mock(ImageView.class); Animation defaultAnimation = new AlphaAnimation(0f, 1f); int duration = 200; - DrawableCrossFadeViewAnimation animation = new DrawableCrossFadeViewAnimation(defaultAnimation, duration); + DrawableCrossFadeViewAnimation<Drawable> animation = new DrawableCrossFadeViewAnimation<Drawable>( + defaultAnimation, duration); } } diff --git a/library/src/test/java/com/bumptech/glide/request/animation/ViewAnimationTest.java b/library/src/test/java/com/bumptech/glide/request/animation/ViewAnimationTest.java index b397cf3b..71f73c03 100644 --- a/library/src/test/java/com/bumptech/glide/request/animation/ViewAnimationTest.java +++ b/library/src/test/java/com/bumptech/glide/request/animation/ViewAnimationTest.java @@ -1,7 +1,7 @@ package com.bumptech.glide.request.animation; -import android.view.View; import android.view.animation.AlphaAnimation; +import android.widget.ImageView; import org.junit.Before; import org.junit.Test; @@ -16,31 +16,31 @@ import static org.mockito.Mockito.verify; @RunWith(RobolectricTestRunner.class) public class ViewAnimationTest { private AlphaAnimation animation; - private View view; + private ImageView view; private ViewAnimation viewAnimation; @Before public void setUp() { animation = new AlphaAnimation(0f, 1f); - view = mock(View.class); + view = mock(ImageView.class); viewAnimation = new ViewAnimation(animation); } @Test public void testClearsAnimationOnAnimate() { - viewAnimation.animate(null, null, view, null); + viewAnimation.animate(null, null, view); verify(view).clearAnimation(); } @Test public void testAlwaysReturnsFalse() { - assertFalse(viewAnimation.animate(null, null, view, null)); + assertFalse(viewAnimation.animate(null, null, view)); } @Test public void testStartsAnimationOnAnimate() { - viewAnimation.animate(null, null, view, null); + viewAnimation.animate(null, null, view); verify(view).startAnimation(eq(animation)); } } diff --git a/library/src/test/java/com/bumptech/glide/request/animation/ViewPropertyAnimationTest.java b/library/src/test/java/com/bumptech/glide/request/animation/ViewPropertyAnimationTest.java index dafa17e9..9079f12e 100644 --- a/library/src/test/java/com/bumptech/glide/request/animation/ViewPropertyAnimationTest.java +++ b/library/src/test/java/com/bumptech/glide/request/animation/ViewPropertyAnimationTest.java @@ -1,6 +1,6 @@ package com.bumptech.glide.request.animation; -import android.view.View; +import android.widget.ImageView; import org.junit.Before; import org.junit.Test; @@ -26,13 +26,13 @@ public class ViewPropertyAnimationTest { @Test public void testAlwaysReturnsFalse() { - assertFalse(animation.animate(null, new Object(), new View(Robolectric.application), null)); + assertFalse(animation.animate(null, new Object(), new ImageView(Robolectric.application))); } @Test public void testCallsAnimatorWithGivenView() { - View view = new View(Robolectric.application); - animation.animate(null, new Object(), view, null); + ImageView view = new ImageView(Robolectric.application); + animation.animate(null, new Object(), view); verify(animator).animate(eq(view)); } diff --git a/library/src/test/java/com/bumptech/glide/request/target/DrawableImageViewTargetTest.java b/library/src/test/java/com/bumptech/glide/request/target/DrawableImageViewTargetTest.java index 60d995cf..06cb5ff4 100644 --- a/library/src/test/java/com/bumptech/glide/request/target/DrawableImageViewTargetTest.java +++ b/library/src/test/java/com/bumptech/glide/request/target/DrawableImageViewTargetTest.java @@ -5,9 +5,10 @@ import android.graphics.drawable.AnimationDrawable; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; -import android.view.View; import android.widget.ImageView; + import com.bumptech.glide.request.animation.GlideAnimation; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -50,7 +51,7 @@ public class DrawableImageViewTargetTest { @Test public void testSetsDrawableOnViewInOnResourceReadyWhenAnimationReturnsFalse() { GlideAnimation animation = mock(GlideAnimation.class); - when(animation.animate(any(Drawable.class), any(Drawable.class), any(View.class), any(Target.class))) + when(animation.animate(any(Drawable.class), any(Drawable.class), any(ImageView.class))) .thenReturn(false); Drawable resource = new ColorDrawable(Color.GRAY); target.onResourceReady(resource, animation); @@ -62,7 +63,7 @@ public class DrawableImageViewTargetTest { public void testDoesNotSetDrawableOnViewInOnResourceReadyWhenAnimationReturnsTrue() { Drawable resource = new ColorDrawable(Color.RED); GlideAnimation animation = mock(GlideAnimation.class); - when(animation.animate((Drawable) isNull(), eq(resource), eq(view), eq(target))).thenReturn(true); + when(animation.animate((Drawable) isNull(), eq(resource), eq(view))).thenReturn(true); target.onResourceReady(resource, animation); assertNull(view.getDrawable()); @@ -85,7 +86,7 @@ public class DrawableImageViewTargetTest { target.onResourceReady(new ColorDrawable(Color.GREEN), animation); - verify(animation).animate(eq(placeholder), any(Drawable.class), any(View.class), any(Target.class)); + verify(animation).animate(eq(placeholder), any(Drawable.class), any(ImageView.class)); } @Test |