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