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

com.bumptech.glide.load.model.StringLoader 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.load.model;

import android.net.Uri;
import android.text.TextUtils;

import com.bumptech.glide.load.data.DataFetcher;

import java.io.File;

/**
 * A model loader for handling certain string models. Handles paths, urls, and any uri string with a scheme handled by
 * {@link android.content.ContentResolver#openInputStream(Uri)}.
 *
 * @param  The type of data that will be loaded from the given {@link java.lang.String}.
 */
public class StringLoader implements ModelLoader {
    private final ModelLoader uriLoader;

    public StringLoader(ModelLoader uriLoader) {
        this.uriLoader = uriLoader;
    }

    @Override
    public DataFetcher getResourceFetcher(String model, int width, int height) {
        Uri uri;
        if (TextUtils.isEmpty(model)) {
            return null;
        } else if (model.startsWith("/")) {
            uri = toFileUri(model);
        } else {
            uri = Uri.parse(model);
            final String scheme = uri.getScheme();
            if (scheme == null) {
                uri = toFileUri(model);
            }
        }

        return uriLoader.getResourceFetcher(uri, width, height);
    }

    private static Uri toFileUri(String path) {
        return Uri.fromFile(new File(path));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy