blob: a8e793fc55ebc3e155a487fcd634e8f3e293165b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
package com.bumptech.glide.load.model;
import android.net.Uri;
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 <T> The type of data that will be loaded from the given {@link java.lang.String}.
*/
public class StringLoader<T> implements ModelLoader<String, T> {
private final ModelLoader<Uri, T> uriLoader;
public StringLoader(ModelLoader<Uri, T> uriLoader) {
this.uriLoader = uriLoader;
}
@Override
public DataFetcher<T> getResourceFetcher(String model, int width, int height) {
Uri uri;
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));
}
}
|