From d2c42cb991e9395f4560cb433ce796082d15e3da Mon Sep 17 00:00:00 2001 From: Sam Judd Date: Wed, 9 Jul 2014 15:15:56 -0700 Subject: Generalize animations and add to GifRequests --- .../java/com/bumptech/glide/BitmapTypeRequest.java | 25 +++---- .../java/com/bumptech/glide/DrawableOptions.java | 83 ++++++++++++++++++++++ .../com/bumptech/glide/DrawableRequestBuilder.java | 75 +++---------------- .../com/bumptech/glide/DrawableTypeRequest.java | 28 ++++---- .../bumptech/glide/GenericTranscodeRequest.java | 52 +++++++------- .../java/com/bumptech/glide/GifTypeRequest.java | 56 ++++++++++++--- .../animation/DrawableCrossFadeViewAnimation.java | 22 +++--- .../glide/request/animation/GlideAnimation.java | 6 +- .../glide/request/animation/NoAnimation.java | 5 +- .../glide/request/animation/ViewAnimation.java | 10 ++- .../request/animation/ViewPropertyAnimation.java | 5 +- .../request/target/BitmapImageViewTarget.java | 2 +- .../request/target/DrawableImageViewTarget.java | 2 +- .../DrawableCrossFadeViewAnimationTest.java | 24 +++---- .../glide/request/animation/ViewAnimationTest.java | 12 ++-- .../animation/ViewPropertyAnimationTest.java | 8 +-- .../target/DrawableImageViewTargetTest.java | 9 +-- 17 files changed, 241 insertions(+), 183 deletions(-) create mode 100644 library/src/main/java/com/bumptech/glide/DrawableOptions.java (limited to 'library') 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 The type of model to load the {@link Bitmap} or transcoded class from. + * @param The type of model to load the {@link Bitmap} or transcoded class from. */ -public class BitmapTypeRequest extends BitmapRequestBuilder { +public class BitmapTypeRequest extends BitmapRequestBuilder { private final Context context; - private final A model; - private final ModelLoader streamModelLoader; - private ModelLoader fileDescriptorModelLoader; + private final ModelType model; + private final ModelLoader streamModelLoader; + private ModelLoader fileDescriptorModelLoader; private final Glide glide; private RequestTracker requestTracker; private RequestManager.OptionsApplier optionsApplier; @@ -50,9 +50,9 @@ public class BitmapTypeRequest extends BitmapRequestBuilder { return new FixedLoadProvider(modelLoader, transcoder, loadProvider); } - BitmapTypeRequest(Context context, A model, - ModelLoader streamModelLoader, - ModelLoader fileDescriptorModelLoader, + BitmapTypeRequest(Context context, ModelType model, + ModelLoader streamModelLoader, + ModelLoader 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 extends BitmapRequestBuilder { * @param The type of the resource the {@link Bitmap} will be transcoded to. * @return This request builder. */ - public BitmapRequestBuilder transcode(ResourceTranscoder transcoder, Class transcodeClass) { - return optionsApplier.apply(model, new BitmapRequestBuilder(context, model, + public BitmapRequestBuilder transcode(ResourceTranscoder transcoder, + Class transcodeClass) { + return optionsApplier.apply(model, new BitmapRequestBuilder(context, model, buildProvider(glide, streamModelLoader, fileDescriptorModelLoader, transcodeClass, transcoder), transcodeClass, glide, requestTracker)); } @@ -89,7 +90,7 @@ public class BitmapTypeRequest extends BitmapRequestBuilder { * * @return This request builder. */ - public BitmapRequestBuilder toBytes() { + public BitmapRequestBuilder toBytes() { return transcode(new BitmapBytesTranscoder(), byte[].class); } @@ -104,7 +105,7 @@ public class BitmapTypeRequest extends BitmapRequestBuilder { * @param quality The quality level from 0-100 to use to compress the {@link Bitmap}. * @return This request builder. */ - public BitmapRequestBuilder toBytes(Bitmap.CompressFormat compressFormat, int quality) { + public BitmapRequestBuilder 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. + * + *

+ * Note - this only works by default for {@link android.view.View}s and + * {@link com.bumptech.glide.request.target.ViewTarget}s. + *

+ * + * @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. + * + *

+ * Note - this only works by default for {@link android.view.View}s and + * {@link com.bumptech.glide.request.target.ViewTarget}s. + *

+ * + * @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}. + * + *

+ * Note - this only works by default for {@link android.view.View}s and + * {@link com.bumptech.glide.request.target.ViewTarget}s. + *

+ * + * @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. + * + *

+ * Note - this only works by default for {@link android.view.View}s and + * {@link com.bumptech.glide.request.target.ViewTarget}s. + *

+ * + * @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 extends GenericRequestBuilder - implements BitmapOptions { + implements BitmapOptions, DrawableOptions { private final Glide glide; private final Context context; @@ -186,90 +186,35 @@ public class DrawableRequestBuilder } /** - * 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. - * - *

- * Note - this only works by default for {@link android.view.View}s and - * {@link com.bumptech.glide.request.target.ViewTarget}s. - *

- * - * @see #crossFade(int) - * @see #crossFade(int, int) - * @see #crossFade(android.view.animation.Animation, int) - * - * @return This request builder. + * {@inheritDoc} */ public DrawableRequestBuilder crossFade() { - super.animate(new DrawableCrossFadeViewAnimation.DrawableCrossFadeFactory()); + super.animate(new DrawableCrossFadeViewAnimation.DrawableCrossFadeFactory()); 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. - * - *

- * Note - this only works by default for {@link android.view.View}s and - * {@link com.bumptech.glide.request.target.ViewTarget}s. - *

- * - * @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 crossFade(int duration) { - super.animate(new DrawableCrossFadeViewAnimation.DrawableCrossFadeFactory(duration)); + super.animate(new DrawableCrossFadeViewAnimation.DrawableCrossFadeFactory(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}. - * - *

- * Note - this only works by default for {@link android.view.View}s and - * {@link com.bumptech.glide.request.target.ViewTarget}s. - *

- * - * @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 crossFade(Animation animation, int duration) { - super.animate(new DrawableCrossFadeViewAnimation.DrawableCrossFadeFactory(animation, duration)); + super.animate(new DrawableCrossFadeViewAnimation.DrawableCrossFadeFactory(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. - * - *

- * Note - this only works by default for {@link android.view.View}s and - * {@link com.bumptech.glide.request.target.ViewTarget}s. - *

- * - * @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 crossFade(int animationId, int duration) { - super.animate(new DrawableCrossFadeViewAnimation.DrawableCrossFadeFactory(context, animationId, duration)); + super.animate(new DrawableCrossFadeViewAnimation.DrawableCrossFadeFactory(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
The type of model to use to load the {@link android.graphics.drawable.BitmapDrawable} or + * @param 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 extends DrawableRequestBuilder implements DownloadOptions { - private final ModelLoader streamModelLoader; - private final ModelLoader fileDescriptorModelLoader; +public class DrawableTypeRequest extends DrawableRequestBuilder implements DownloadOptions { + private final ModelLoader streamModelLoader; + private final ModelLoader 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 FixedLoadProvider buildProvider(Glide glide, ModelLoader streamModelLoader, @@ -54,8 +54,8 @@ public class DrawableTypeRequest extends DrawableRequestBuilder implements return new FixedLoadProvider(modelLoader, transcoder, dataLoadProvider); } - DrawableTypeRequest(A model, ModelLoader streamModelLoader, - ModelLoader fileDescriptorModelLoader, Context context, Glide glide, + DrawableTypeRequest(ModelType model, ModelLoader streamModelLoader, + ModelLoader 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 extends DrawableRequestBuilder implements * * @return A new request builder for loading a {@link android.graphics.Bitmap} */ - public BitmapTypeRequest asBitmap() { - return optionsApplier.apply(model, new BitmapTypeRequest(context, model, streamModelLoader, + public BitmapTypeRequest asBitmap() { + return optionsApplier.apply(model, new BitmapTypeRequest(context, model, streamModelLoader, fileDescriptorModelLoader, glide, requestTracker, optionsApplier)); } @@ -92,8 +92,8 @@ public class DrawableTypeRequest extends DrawableRequestBuilder implements * * @return A new request builder for loading a {@link com.bumptech.glide.load.resource.gif.GifDrawable}. */ - public GifTypeRequest asGif() { - return optionsApplier.apply(model, new GifTypeRequest(context, model, streamModelLoader, glide, + public GifTypeRequest asGif() { + return optionsApplier.apply(model, new GifTypeRequest(context, model, streamModelLoader, glide, requestTracker, optionsApplier)); } @@ -120,8 +120,8 @@ public class DrawableTypeRequest extends DrawableRequestBuilder implements return getDownloadOnlyRequest().downloadOnly(width, height); } - private GenericTranscodeRequest getDownloadOnlyRequest() { - return optionsApplier.apply(model, new GenericTranscodeRequest(context, glide, model, - streamModelLoader, InputStream.class, File.class, requestTracker, optionsApplier)); + private GenericTranscodeRequest getDownloadOnlyRequest() { + return optionsApplier.apply(model, new GenericTranscodeRequest(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 The type of the model used to retrieve data. - * @param The type of data retrieved. - * @param The type of resource to be decoded from the the data. + * @param The type of the model used to retrieve data. + * @param The type of data retrieved. + * @param The type of resource to be decoded from the the data. */ -public class GenericTranscodeRequest extends GenericRequestBuilder implements DownloadOptions { +public class GenericTranscodeRequest + extends GenericRequestBuilder implements DownloadOptions { private final Context context; - private final A model; + private final ModelType model; private final Glide glide; - private final ModelLoader modelLoader; - private final Class dataClass; - private final Class resourceClass; + private final ModelLoader modelLoader; + private final Class dataClass; + private final Class resourceClass; private final RequestTracker requestTracker; private final RequestManager.OptionsApplier optionsApplier; @@ -42,12 +43,11 @@ public class GenericTranscodeRequest extends GenericRequestBuilder(modelLoader, transcoder, dataLoadProvider); } - GenericTranscodeRequest(Context context, Glide glide, A model, ModelLoader modelLoader, - Class dataClass, Class resourceClass, RequestTracker requestTracker, + GenericTranscodeRequest(Context context, Glide glide, ModelType model, ModelLoader modelLoader, + Class dataClass, Class resourceClass, RequestTracker requestTracker, RequestManager.OptionsApplier optionsApplier) { - super(context, model, - build(glide, modelLoader, dataClass, resourceClass, (ResourceTranscoder) null), - resourceClass, glide, requestTracker); + super(context, model, build(glide, modelLoader, dataClass, resourceClass, + (ResourceTranscoder) null), resourceClass, glide, requestTracker); this.context = context; this.model = model; this.glide = glide; @@ -63,14 +63,18 @@ public class GenericTranscodeRequest extends GenericRequestBuilder The type of the resource that will be transcoded to. + * @param The type of the resource that will be transcoded to. * @return A new request builder to set options for the transcoded load. */ - public GenericRequestBuilder transcode(ResourceTranscoder transcoder, - Class transcodeClass) { - return optionsApplier.apply(model, new GenericRequestBuilder(context, model, - build(glide, modelLoader, dataClass, resourceClass, transcoder), transcodeClass, glide, - requestTracker)); + public GenericRequestBuilder transcode( + ResourceTranscoder transcoder, + Class transcodeClass) { + LoadProvider loadProvider = build(glide, modelLoader, + dataClass, resourceClass, transcoder); + + return optionsApplier.apply(model, + new GenericRequestBuilder(context, model, + loadProvider, transcodeClass, glide, requestTracker)); } /** @@ -96,12 +100,12 @@ public class GenericTranscodeRequest extends GenericRequestBuilder getDownloadOnlyRequest() { + private GenericRequestBuilder getDownloadOnlyRequest() { ResourceTranscoder transcoder = UnitTranscoder.get(); - DataLoadProvider dataLoadProvider = glide.buildDataProvider(dataClass, File.class); - FixedLoadProvider fixedLoadProvider = new FixedLoadProvider(modelLoader, - transcoder, dataLoadProvider); - return optionsApplier.apply(model, new GenericRequestBuilder(context, model, + DataLoadProvider dataLoadProvider = glide.buildDataProvider(dataClass, File.class); + FixedLoadProvider fixedLoadProvider = + new FixedLoadProvider(modelLoader, transcoder, dataLoadProvider); + return optionsApplier.apply(model, new GenericRequestBuilder(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 The type of model to load the {@link com.bumptech.glide.load.resource.gif.GifDrawable} or other + * @param The type of model to load the {@link com.bumptech.glide.load.resource.gif.GifDrawable} or other * transcoded class from. */ -public class GifTypeRequest extends GifRequestBuilder { +public class GifTypeRequest extends GifRequestBuilder implements DrawableOptions { private final Context context; - private final A model; - private final ModelLoader streamModelLoader; + private final ModelType model; + private final ModelLoader streamModelLoader; private final Glide glide; private final RequestTracker requestTracker; private RequestManager.OptionsApplier optionsApplier; @@ -45,7 +47,7 @@ public class GifTypeRequest extends GifRequestBuilder { } - GifTypeRequest(Context context, A model, ModelLoader streamModelLoader, Glide glide, + GifTypeRequest(Context context, ModelType model, ModelLoader 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 extends GifRequestBuilder { * trasncoded to. * @return This request builder. */ - public GifRequestBuilder transcode(ResourceTranscoder transcoder, Class transcodeClass) { - return optionsApplier.apply(model, new GifRequestBuilder(context, model, + public GifRequestBuilder transcode(ResourceTranscoder transcoder, + Class transcodeClass) { + return optionsApplier.apply(model, new GifRequestBuilder(context, model, buildProvider(glide, streamModelLoader, transcodeClass, transcoder), transcodeClass, glide, requestTracker)); } @@ -84,7 +87,44 @@ public class GifTypeRequest extends GifRequestBuilder { * * @return A new Builder object to build a request to transform the given model into the bytes of an animated gif. */ - public GifRequestBuilder toBytes() { + public GifRequestBuilder toBytes() { return transcode(new GifDataBytesTranscoder(), byte[].class); } + + /** + * {@inheritDoc} + */ + @Override + public GifTypeRequest crossFade() { + super.animate(new DrawableCrossFadeViewAnimation.DrawableCrossFadeFactory()); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public GifTypeRequest crossFade(int duration) { + super.animate(new DrawableCrossFadeViewAnimation.DrawableCrossFadeFactory(duration)); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public GifTypeRequest crossFade(Animation animation, int duration) { + super.animate(new DrawableCrossFadeViewAnimation.DrawableCrossFadeFactory(animation, duration)); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public GifTypeRequest crossFade(int animationId, int duration) { + super.animate(new DrawableCrossFadeViewAnimation.DrawableCrossFadeFactory(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 { +public class DrawableCrossFadeViewAnimation implements GlideAnimation { // 150 ms. public static final int DEFAULT_DURATION = 300; private Animation defaultAnimation; @@ -40,12 +38,12 @@ public class DrawableCrossFadeViewAnimation implements GlideAnimation * cache this factory producdes an {@link NoAnimation}. *

*/ - public static class DrawableCrossFadeFactory implements GlideAnimationFactory { + public static class DrawableCrossFadeFactory implements GlideAnimationFactory { private Context context; private int defaultAnimationId; private Animation defaultAnimation; private int duration; - private DrawableCrossFadeViewAnimation animation; + private DrawableCrossFadeViewAnimation animation; public DrawableCrossFadeFactory() { this(getDefaultAnimation(), DEFAULT_DURATION); @@ -67,7 +65,7 @@ public class DrawableCrossFadeViewAnimation implements GlideAnimation } @Override - public GlideAnimation build(boolean isFromMemoryCache, boolean isFirstImage) { + public GlideAnimation build(boolean isFromMemoryCache, boolean isFirstImage) { if (isFromMemoryCache) { return NoAnimation.get(); } @@ -76,7 +74,7 @@ public class DrawableCrossFadeViewAnimation implements GlideAnimation if (defaultAnimation == null) { defaultAnimation = AnimationUtils.loadAnimation(context, defaultAnimationId); } - animation = new DrawableCrossFadeViewAnimation(defaultAnimation, duration); + animation = new DrawableCrossFadeViewAnimation(defaultAnimation, duration); } return animation; @@ -108,19 +106,17 @@ public class DrawableCrossFadeViewAnimation implements GlideAnimation * @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 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 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 { * @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 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 { */ @Override public void onResourceReady(Bitmap resource, GlideAnimation 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 { } } - 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 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 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 animation = new DrawableCrossFadeViewAnimation( + 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 -- cgit v1.2.3