1package com.bumptech.glide.load.resource.gif; 2 3import com.bumptech.glide.Priority; 4import com.bumptech.glide.gifdecoder.GifDecoder; 5import com.bumptech.glide.load.data.DataFetcher; 6import com.bumptech.glide.load.model.ModelLoader; 7 8class GifFrameModelLoader implements ModelLoader<GifDecoder, GifDecoder> { 9 10 @Override 11 public DataFetcher<GifDecoder> getResourceFetcher(GifDecoder model, int width, int height) { 12 return new GifFrameDataFetcher(model); 13 } 14 15 private static class GifFrameDataFetcher implements DataFetcher<GifDecoder> { 16 private final GifDecoder decoder; 17 18 public GifFrameDataFetcher(GifDecoder decoder) { 19 this.decoder = decoder; 20 } 21 22 @Override 23 public GifDecoder loadData(Priority priority) { 24 return decoder; 25 } 26 27 @Override 28 public void cleanup() { 29 // Do nothing. GifDecoder reads from an arbitrary InputStream, the caller will close that stream. 30 } 31 32 @Override 33 public String getId() { 34 return String.valueOf(decoder.getCurrentFrameIndex()); 35 } 36 37 @Override 38 public void cancel() { 39 // Do nothing. 40 } 41 } 42} 43