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

com.bumptech.glide.load.model.stream.HttpGlideUrlLoader Maven / Gradle / Ivy

Go to download

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

The newest version!
package com.bumptech.glide.load.model.stream;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.bumptech.glide.load.Option;
import com.bumptech.glide.load.Options;
import com.bumptech.glide.load.data.HttpUrlFetcher;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.model.ModelCache;
import com.bumptech.glide.load.model.ModelLoader;
import com.bumptech.glide.load.model.ModelLoaderFactory;
import com.bumptech.glide.load.model.MultiModelLoaderFactory;
import java.io.InputStream;

/**
 * An {@link com.bumptech.glide.load.model.ModelLoader} for translating {@link
 * com.bumptech.glide.load.model.GlideUrl} (http/https URLS) into {@link java.io.InputStream} data.
 */
// Public API.
@SuppressWarnings("WeakerAccess")
public class HttpGlideUrlLoader implements ModelLoader {
  /**
   * An integer option that is used to determine the maximum connect and read timeout durations (in
   * milliseconds) for network connections.
   *
   * 

Defaults to 2500ms. */ public static final Option TIMEOUT = Option.memory("com.bumptech.glide.load.model.stream.HttpGlideUrlLoader.Timeout", 2500); @Nullable private final ModelCache modelCache; public HttpGlideUrlLoader() { this(null); } public HttpGlideUrlLoader(@Nullable ModelCache modelCache) { this.modelCache = modelCache; } @Override public LoadData buildLoadData( @NonNull GlideUrl model, int width, int height, @NonNull Options options) { // GlideUrls memoize parsed URLs so caching them saves a few object instantiations and time // spent parsing urls. GlideUrl url = model; if (modelCache != null) { url = modelCache.get(model, 0, 0); if (url == null) { modelCache.put(model, 0, 0, model); url = model; } } int timeout = options.get(TIMEOUT); return new LoadData<>(url, new HttpUrlFetcher(url, timeout)); } @Override public boolean handles(@NonNull GlideUrl model) { return true; } /** The default factory for {@link HttpGlideUrlLoader}s. */ public static class Factory implements ModelLoaderFactory { private final ModelCache modelCache = new ModelCache<>(500); @NonNull @Override public ModelLoader build(MultiModelLoaderFactory multiFactory) { return new HttpGlideUrlLoader(modelCache); } @Override public void teardown() { // Do nothing. } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy