@Nullable @Override public Resource<Bitmap> decode(@NonNull Uri source, int width, int height, @NonNull Options options) { Resource<Drawable> drawableResource = drawableDecoder.decode(source, width, height, options); if (drawableResource == null) { return null; } Drawable drawable = drawableResource.get(); return DrawableToBitmapConverter.convert(bitmapPool, drawable, width, height); } }
@Nullable @Override public Resource<Drawable> decode(@NonNull Uri source, int width, int height, @NonNull Options options) { String packageName = source.getAuthority(); Context targetContext = findContextForPackage(source, packageName); @DrawableRes int resId = findResourceIdFromUri(targetContext, source); // We can't get a theme from another application. Drawable drawable = DrawableDecoderCompat.getDrawable(context, targetContext, resId); return NonOwnedDrawableResource.newInstance(drawable); }
@DrawableRes private int findResourceIdFromUri(Context context, Uri source) { List<String> segments = source.getPathSegments(); if (segments.size() == NAME_URI_PATH_SEGMENTS) { return findResourceIdFromTypeAndNameResourceUri(context, source); } else if (segments.size() == ID_PATH_SEGMENTS) { return findResourceIdFromResourceIdUri(source); } else { throw new IllegalArgumentException("Unrecognized Uri format: " + source); } }
StreamBitmapDecoder streamBitmapDecoder = new StreamBitmapDecoder(downsampler, arrayPool); ResourceDrawableDecoder resourceDrawableDecoder = new ResourceDrawableDecoder(context); ResourceLoader.StreamFactory resourceLoaderStreamFactory = new ResourceLoader.StreamFactory(resources);