package com.bumptech.glide.load.resource.bitmap; import android.graphics.Bitmap; import android.os.ParcelFileDescriptor; import android.util.Log; import com.bumptech.glide.Resource; import com.bumptech.glide.load.ResourceDecoder; import com.bumptech.glide.load.model.ImageVideoWrapper; import java.io.IOException; import java.io.InputStream; public class ImageVideoBitmapDecoder implements ResourceDecoder<ImageVideoWrapper, Bitmap> { private static final String TAG = "ImageVideoDecoder"; private final ResourceDecoder<InputStream, Bitmap> streamDecoder; private final ResourceDecoder<ParcelFileDescriptor, Bitmap> fileDescriptorDecoder; public ImageVideoBitmapDecoder(ResourceDecoder<InputStream, Bitmap> streamDecoder, ResourceDecoder<ParcelFileDescriptor, Bitmap> fileDescriptorDecoder) { this.streamDecoder = streamDecoder; this.fileDescriptorDecoder = fileDescriptorDecoder; } @Override public Resource<Bitmap> decode(ImageVideoWrapper source, int width, int height) throws IOException { Resource<Bitmap> result = null; InputStream is = source.getStream(); if (is != null) { try { result = streamDecoder.decode(source.getStream(), width, height); } catch (IOException e) { if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "Failed to load image from stream, trying FileDescriptor", e); } } } if (result == null) { result = fileDescriptorDecoder.decode(source.getFileDescriptor(), width, height); } return result; } @Override public String getId() { return "ImageVideoBitmapDecoder.com.bumptech.glide.load.data.bitmap"; } }