private ComparableResDrawable(@DrawableRes int resId, Configuration config, Drawable drawable) { super(drawable); this.mResId = resId; this.mConfig = config; }
@DrawableRes public static int getIcon(int serviceId) { switch (serviceId) { case 0: return R.drawable.place_holder_youtube; case 1: return R.drawable.place_holder_circle; default: return R.drawable.service; } }
/** * @param drawable - desired drawable for the Toolbar left cancel icon */ public void setToolbarCancelDrawable(@DrawableRes int drawable) { mOptionBundle.putInt(EXTRA_UCROP_WIDGET_CANCEL_DRAWABLE, drawable); }
/** * @param drawable - desired drawable for the Toolbar right crop icon */ public void setToolbarCropDrawable(@DrawableRes int drawable) { mOptionBundle.putInt(EXTRA_UCROP_WIDGET_CROP_DRAWABLE, drawable); }
private static Drawable loadDrawableV4( Context context, @DrawableRes int id, @Nullable Theme theme) { Resources resources = context.getResources(); return ResourcesCompat.getDrawable(resources, id, theme); } }
@DrawableRes private int findResourceIdFromResourceIdUri(Uri source) { List<String> segments = source.getPathSegments(); try { return Integer.parseInt(segments.get(RESOURCE_ID_SEGMENT_INDEX)); } catch (NumberFormatException e) { throw new IllegalArgumentException("Unrecognized Uri format: " + source, e); } } }
@Nullable public Drawable resolveDrawableRes(@DrawableRes int resId) { if (resId == 0) { return null; } return mResources.getDrawable(resId); }
/** * See {@code getDrawable(Context, int, Theme)}. */ public static Drawable getDrawable( Context ourContext, Context targetContext, @DrawableRes int id) { return getDrawable(ourContext, targetContext, id, /*theme=*/ null); }
@SuppressWarnings("deprecation") public static Drawable resolveDrawable(@DrawableRes int resId, Context context) { Resources resources = context.getResources(); Resources.Theme theme = context.getTheme(); if (Build.VERSION.SDK_INT >= 22) { return resources.getDrawable(resId, theme); } else { return resources.getDrawable(resId); } }
public T setProgressResource(@DrawableRes int resId) { mProgressDrawable = null; mProgressView.setImageResource(resId); return self(); } // public T setArrowBitmap(Bitmap bitmap) {
public T setArrowResource(@DrawableRes int resId) { mArrowDrawable = null; mArrowView.setImageResource(resId); return self(); }
@DrawableRes private int findResourceIdFromTypeAndNameResourceUri(Context context, Uri source) { List<String> segments = source.getPathSegments(); String packageName = source.getAuthority(); String typeName = segments.get(TYPE_PATH_SEGMENT_INDEX); String resourceName = segments.get(NAME_PATH_SEGMENT_INDEX); int result = context.getResources().getIdentifier(resourceName, typeName, packageName); if (result == MISSING_RESOURCE_ID) { result = Resources.getSystem().getIdentifier(resourceName, typeName, ANDROID_PACKAGE_NAME); } if (result == MISSING_RESOURCE_ID) { throw new IllegalArgumentException("Failed to find resource id for: " + source); } return result; }
/** * Sets the small icon of the notification which is also shown in the system status bar. * * <p>See {@link NotificationCompat.Builder#setSmallIcon(int)}. * * @param smallIconResourceId The resource id of the small icon. */ public final void setSmallIcon(@DrawableRes int smallIconResourceId) { if (this.smallIconResourceId != smallIconResourceId) { this.smallIconResourceId = smallIconResourceId; invalidate(); } }
InternalNode stateListAnimatorRes(@DrawableRes int resId) { mPrivateFlags |= PFLAG_STATE_LIST_ANIMATOR_RES_SET; mStateListAnimatorRes = resId; wrapInView(); return this; }
@DrawableRes @Override public int getTabIconRes(Context context) { return ThemeHelper.resolveResourceIdFromAttr(context, R.attr.ic_bookmark); }
private static Drawable loadDrawableV7(Context context, @DrawableRes int id, @Nullable Theme theme) { Context resourceContext = theme != null ? new ContextThemeWrapper(context, theme) : context; return AppCompatResources.getDrawable(resourceContext, id); }
@NonNull @CheckResult T load(@RawRes @DrawableRes @Nullable Integer resourceId);
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()); }
@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); } }
@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); }