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

com.bumptech.glide.provider.ResourceEncoderRegistry 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.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);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy