com.bumptech.glide.request.transition.BitmapContainerTransitionFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of glide Show documentation
Show all versions of glide Show documentation
A fast and efficient image loading library for Android focused on smooth scrolling.
package com.bumptech.glide.request.transition;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import com.bumptech.glide.load.DataSource;
/**
* A {@link TransitionFactory} for complex types that have a {@link android.graphics.Bitmap} inside.
* The transitioning bitmap is wrapped in a {@link android.graphics.drawable.BitmapDrawable}.
* Most commonly used with {@link DrawableCrossFadeFactory}.
*
* @param The type of the composite object that contains the {@link android.graphics.Bitmap} to
* be transitioned.
*/
public abstract class BitmapContainerTransitionFactory implements TransitionFactory {
private final TransitionFactory realFactory;
// Public API.
@SuppressWarnings("WeakerAccess")
public BitmapContainerTransitionFactory(TransitionFactory realFactory) {
this.realFactory = realFactory;
}
@Override
public Transition build(DataSource dataSource, boolean isFirstResource) {
Transition transition = realFactory.build(dataSource, isFirstResource);
return new BitmapGlideAnimation(transition);
}
/**
* Retrieve the Bitmap from a composite object.
* Warning: Do not convert any arbitrary object to Bitmap
* via expensive drawing here, this method is called on the UI thread.
*
* @param current composite object containing a Bitmap and some other information
* @return the Bitmap contained within {@code current}
*/
protected abstract Bitmap getBitmap(R current);
private final class BitmapGlideAnimation implements Transition {
private final Transition transition;
BitmapGlideAnimation(Transition transition) {
this.transition = transition;
}
@Override
public boolean transition(R current, ViewAdapter adapter) {
Resources resources = adapter.getView().getResources();
Drawable currentBitmap = new BitmapDrawable(resources, getBitmap(current));
return transition.transition(currentBitmap, adapter);
}
}
}