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