-
Notifications
You must be signed in to change notification settings - Fork 1
/
GlideContentProviderLoader.java
62 lines (47 loc) · 1.52 KB
/
GlideContentProviderLoader.java
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import android.content.Context;
import android.net.Uri;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.data.DataFetcher;
import com.bumptech.glide.load.model.stream.StreamModelLoader;
import java.io.InputStream;
/**
*
* Created by ahmed-basyouni on 4/22/17.
*/
public class GlideContentProviderLoader implements StreamModelLoader<Uri> {
private final Context mContext;
public GlideContentProviderLoader(Context context) {
this.mContext = context;
}
@Override
public DataFetcher<InputStream> getResourceFetcher(Uri uri, int width, int height) {
return new ProviderDataFetcher(uri, mContext);
}
private static class ProviderDataFetcher implements DataFetcher<InputStream> {
private final Uri imageUri;
private final Context mContext;
private boolean cancelled;
ProviderDataFetcher(Uri uri, Context context){
this.imageUri = uri;
this.mContext = context;
}
@Override
public InputStream loadData(Priority priority) throws Exception {
InputStream stream = null;
if(imageUri!=null && !cancelled)
stream = mContext.getContentResolver().openInputStream(imageUri);
return stream;
}
@Override
public void cleanup() {
}
@Override
public String getId() {
return imageUri.toString();
}
@Override
public void cancel() {
cancelled = true;
}
}
}