com.bumptech.glide.load.MultiTransformation 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.load;
import android.content.Context;
import androidx.annotation.NonNull;
import com.bumptech.glide.load.engine.Resource;
import java.security.MessageDigest;
import java.util.Arrays;
import java.util.Collection;
/**
* A transformation that applies one or more transformations in iteration order to a resource.
*
* @param The type of {@link com.bumptech.glide.load.engine.Resource} that will be transformed.
*/
public class MultiTransformation implements Transformation {
private final Collection extends Transformation> transformations;
@SafeVarargs
@SuppressWarnings("varargs")
public MultiTransformation(@NonNull Transformation... transformations) {
if (transformations.length == 0) {
throw new IllegalArgumentException(
"MultiTransformation must contain at least one Transformation");
}
this.transformations = Arrays.asList(transformations);
}
public MultiTransformation(@NonNull Collection extends Transformation> transformationList) {
if (transformationList.isEmpty()) {
throw new IllegalArgumentException(
"MultiTransformation must contain at least one Transformation");
}
this.transformations = transformationList;
}
@NonNull
@Override
public Resource transform(
@NonNull Context context, @NonNull Resource resource, int outWidth, int outHeight) {
Resource previous = resource;
for (Transformation transformation : transformations) {
Resource transformed = transformation.transform(context, previous, outWidth, outHeight);
if (previous != null && !previous.equals(resource) && !previous.equals(transformed)) {
previous.recycle();
}
previous = transformed;
}
return previous;
}
@Override
public boolean equals(Object o) {
if (o instanceof MultiTransformation) {
MultiTransformation> other = (MultiTransformation>) o;
return transformations.equals(other.transformations);
}
return false;
}
@Override
public int hashCode() {
return transformations.hashCode();
}
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
for (Transformation transformation : transformations) {
transformation.updateDiskCacheKey(messageDigest);
}
}
}