All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bumptech.glide.request.transition.ViewAnimationFactory Maven / Gradle / Ivy

Go to download

A fast and efficient image loading library for Android focused on smooth scrolling.

There is a newer version: 5.0.0-rc01
Show newest version
package com.bumptech.glide.request.transition;

import android.content.Context;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import com.bumptech.glide.load.DataSource;

/**
 * A {@link TransitionFactory} that produces {@link ViewTransition}s.
 *
 * @param  The type of the resource that will be transitioned into a view.
 */
public class ViewAnimationFactory implements TransitionFactory {
  private final ViewTransition.ViewTransitionAnimationFactory viewTransitionAnimationFactory;
  private Transition transition;

  // Public API.
  @SuppressWarnings("unused")
  public ViewAnimationFactory(Animation animation) {
    this(new ConcreteViewTransitionAnimationFactory(animation));
  }

  public ViewAnimationFactory(int animationId) {
    this(new ResourceViewTransitionAnimationFactory(animationId));
  }

  ViewAnimationFactory(
      ViewTransition.ViewTransitionAnimationFactory viewTransitionAnimationFactory) {
    this.viewTransitionAnimationFactory = viewTransitionAnimationFactory;
  }

  /**
   * Returns a new {@link Transition} for the given arguments. If isFromMemoryCache is {@code true}
   * or isFirstImage is {@code false}, returns a {@link NoTransition} and otherwise returns a new
   * {@link ViewTransition}.
   *
   * @param dataSource {@inheritDoc}
   * @param isFirstResource   {@inheritDoc}
   */
  @Override
  public Transition build(DataSource dataSource, boolean isFirstResource) {
    if (dataSource == DataSource.MEMORY_CACHE || !isFirstResource) {
      return NoTransition.get();
    }

    if (transition == null) {
      transition = new ViewTransition<>(viewTransitionAnimationFactory);
    }

    return transition;
  }

  private static class ConcreteViewTransitionAnimationFactory implements ViewTransition
      .ViewTransitionAnimationFactory {
    private final Animation animation;

    ConcreteViewTransitionAnimationFactory(Animation animation) {
      this.animation = animation;
    }

    @Override
    public Animation build(Context context) {
      return animation;
    }
  }

  private static class ResourceViewTransitionAnimationFactory implements ViewTransition
      .ViewTransitionAnimationFactory {
    private final int animationId;

    ResourceViewTransitionAnimationFactory(int animationId) {
      this.animationId = animationId;
    }

    @Override
    public Animation build(Context context) {
      return AnimationUtils.loadAnimation(context, animationId);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy