1 package com.bumptech.glide.request.animation; 2 3 import android.view.View; 4 import android.view.animation.Animation; 5 6 /** 7 * A {@link com.bumptech.glide.request.animation.GlideAnimation GlideAnimation} that can apply a 8 * {@link android.view.animation.Animation Animation} to a {@link android.view.View View} using 9 * {@link android.view.View#startAnimation(android.view.animation.Animation) View.startAnimation}. 10 * 11 * @param <R> The type of the resource displayed in the view that is animated 12 */ 13 public class ViewAnimation<R> implements GlideAnimation<R> { 14 15 private final AnimationFactory animationFactory; 16 17 /** 18 * Constructs a new ViewAnimation that will start the given {@link android.view.animation.Animation}. 19 */ 20 ViewAnimation(AnimationFactory animationFactory) { 21 this.animationFactory = animationFactory; 22 } 23 24 /** 25 * Always clears the current animation on the view using {@link android.view.View#clearAnimation()}, then 26 * starts the {@link android.view.animation.Animation} given in the constructor using 27 * {@link android.view.View#startAnimation(android.view.animation.Animation)} and then returns {@code false} because 28 * the animation does not actually set the current resource on the view. 29 * 30 * @param current {@inheritDoc} 31 * @param adapter {@inheritDoc} 32 * @return {@inheritDoc} 33 */ 34 @Override 35 public boolean animate(R current, ViewAdapter adapter) { 36 View view = adapter.getView(); 37 if (view != null) { 38 view.clearAnimation(); 39 Animation animation = animationFactory.build(); 40 view.startAnimation(animation); 41 } 42 43 return false; 44 } 45 46 interface AnimationFactory { 47 Animation build(); 48 } 49 } 50