MediaStoreStreamLoader.java revision 5f4610b54d517be58105bcf73ce3291ba79f9f40
1package com.bumptech.glide.load.model.stream;
2
3import android.content.Context;
4import android.net.Uri;
5import com.bumptech.glide.load.data.DataFetcher;
6import com.bumptech.glide.load.data.MediaStoreThumbFetcher;
7import com.bumptech.glide.load.model.ModelLoader;
8
9import java.io.InputStream;
10
11/**
12 * An {@link com.bumptech.glide.load.model.ModelLoader} that can use media store uris to open pre-generated thumbnails
13 * from the media store using {@link android.provider.MediaStore.Images.Thumbnails} and
14 * {@link android.provider.MediaStore.Video.Thumbnails} if the requested size is less than or equal to the media store
15 * thumbnail size. If the given uri is not a media store uri or if the desired dimensions are too large,
16 * it falls back to the wrapped {@link com.bumptech.glide.load.model.ModelLoader} to load the
17 * {@link java.io.InputStream} data.
18 */
19public class MediaStoreStreamLoader implements ModelLoader<Uri, InputStream> {
20    private final Context context;
21    private final ModelLoader<Uri, InputStream> uriLoader;
22    private String mimeType;
23    private final long dateModified;
24    private final int orientation;
25
26    public MediaStoreStreamLoader(Context context, ModelLoader<Uri, InputStream> uriLoader, String mimeType,
27            long dateModified, int orientation) {
28        this.context = context;
29        this.uriLoader = uriLoader;
30        this.mimeType = mimeType;
31        this.dateModified = dateModified;
32        this.orientation = orientation;
33    }
34
35    @Override
36    public DataFetcher<InputStream> getResourceFetcher(Uri model, int width, int height) {
37        return new MediaStoreThumbFetcher(context, model, uriLoader.getResourceFetcher(model, width, height), width,
38                height, mimeType, dateModified, orientation);
39    }
40}
41