com.bumptech.glide.provider.ResourceEncoderRegistry 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.provider;
import android.support.annotation.Nullable;
import com.bumptech.glide.load.ResourceEncoder;
import com.bumptech.glide.util.Synthetic;
import java.util.ArrayList;
import java.util.List;
/**
* Contains an ordered list of {@link ResourceEncoder}s capable of encoding arbitrary resource
* types.
*/
public class ResourceEncoderRegistry {
// TODO: this should probably be a put.
final List> encoders = new ArrayList<>();
public synchronized void append(Class resourceClass, ResourceEncoder encoder) {
encoders.add(new Entry<>(resourceClass, encoder));
}
public synchronized void prepend(Class resourceClass, ResourceEncoder encoder) {
encoders.add(0, new Entry<>(resourceClass, encoder));
}
@SuppressWarnings("unchecked")
@Nullable
public synchronized ResourceEncoder get(Class resourceClass) {
int size = encoders.size();
for (int i = 0; i < size; i++) {
Entry> entry = encoders.get(i);
if (entry.handles(resourceClass)) {
return (ResourceEncoder) entry.encoder;
}
}
// TODO: throw an exception here?
return null;
}
private static final class Entry {
private final Class resourceClass;
@Synthetic final ResourceEncoder encoder;
Entry(Class resourceClass, ResourceEncoder encoder) {
this.resourceClass = resourceClass;
this.encoder = encoder;
}
@Synthetic
boolean handles(Class> resourceClass) {
return this.resourceClass.isAssignableFrom(resourceClass);
}
}
}