/** * See {@code getDrawable(Context, int, Theme)}. */ public static Drawable getDrawable( Context ourContext, Context targetContext, @DrawableRes int id) { return getDrawable(ourContext, targetContext, id, /*theme=*/ null); }
private static Drawable getDrawable( Context ourContext, Context targetContext, @DrawableRes int id, @Nullable Theme theme) { try { // Race conditions may cause us to attempt to load using v7 more than once. That's ok since // this check is a modest optimization and the output will be correct anyway. if (shouldCallAppCompatResources) { return loadDrawableV7(targetContext, id, theme); } } catch (NoClassDefFoundError error) { shouldCallAppCompatResources = false; } catch (IllegalStateException e) { if (ourContext.getPackageName().equals(targetContext.getPackageName())) { throw e; } return ContextCompat.getDrawable(targetContext, id); } catch (Resources.NotFoundException e) { // Ignored, this can be thrown when drawable compat attempts to decode a canary resource. If // that decode attempt fails, we still want to try with the v4 ResourcesCompat below. } return loadDrawableV4(targetContext, id, theme != null ? theme : targetContext.getTheme()); }
@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); }
private Drawable loadDrawable(@DrawableRes int resourceId) { Theme theme = requestOptions.getTheme() != null ? requestOptions.getTheme() : context.getTheme(); return DrawableDecoderCompat.getDrawable(glideContext, resourceId, theme); }