Home | History | Annotate | Download | only in file_descriptor
      1 package com.bumptech.glide.load.model.file_descriptor;
      2 
      3 import android.content.Context;
      4 import android.net.Uri;
      5 import android.os.ParcelFileDescriptor;
      6 
      7 import com.bumptech.glide.Glide;
      8 import com.bumptech.glide.load.data.DataFetcher;
      9 import com.bumptech.glide.load.data.FileDescriptorAssetPathFetcher;
     10 import com.bumptech.glide.load.data.FileDescriptorLocalUriFetcher;
     11 import com.bumptech.glide.load.model.GenericLoaderFactory;
     12 import com.bumptech.glide.load.model.GlideUrl;
     13 import com.bumptech.glide.load.model.ModelLoader;
     14 import com.bumptech.glide.load.model.ModelLoaderFactory;
     15 import com.bumptech.glide.load.model.UriLoader;
     16 
     17 /**
     18  * A {@link ModelLoader} For translating {@link Uri} models for local uris into {@link ParcelFileDescriptor} data.
     19  */
     20 public class FileDescriptorUriLoader extends UriLoader<ParcelFileDescriptor> implements FileDescriptorModelLoader<Uri> {
     21 
     22     /**
     23      * The default factory for {@link com.bumptech.glide.load.model.file_descriptor.FileDescriptorUriLoader}s.
     24      */
     25     public static class Factory implements ModelLoaderFactory<Uri, ParcelFileDescriptor> {
     26         @Override
     27         public ModelLoader<Uri, ParcelFileDescriptor> build(Context context, GenericLoaderFactory factories) {
     28             return new FileDescriptorUriLoader(context, factories.buildModelLoader(GlideUrl.class,
     29                     ParcelFileDescriptor.class));
     30         }
     31 
     32         @Override
     33         public void teardown() {
     34             // Do nothing.
     35         }
     36     }
     37 
     38     public FileDescriptorUriLoader(Context context) {
     39         this(context, Glide.buildFileDescriptorModelLoader(GlideUrl.class, context));
     40     }
     41 
     42     public FileDescriptorUriLoader(Context context, ModelLoader<GlideUrl, ParcelFileDescriptor> urlLoader) {
     43         super(context, urlLoader);
     44     }
     45 
     46     @Override
     47     protected DataFetcher<ParcelFileDescriptor> getLocalUriFetcher(Context context, Uri uri) {
     48         return new FileDescriptorLocalUriFetcher(context, uri);
     49     }
     50 
     51     @Override
     52     protected DataFetcher<ParcelFileDescriptor> getAssetPathFetcher(Context context, String assetPath) {
     53         return new FileDescriptorAssetPathFetcher(context.getApplicationContext().getAssets(), assetPath);
     54     }
     55 }
     56