@Test public void testGetDrawableForDensityThemed() throws Throwable { if (Build.VERSION.SDK_INT < 21) { return; } final Resources.Theme yellowTheme = mResources.newTheme(); yellowTheme.applyStyle(R.style.YellowTheme, true); final Resources.Theme lilacTheme = mResources.newTheme(); lilacTheme.applyStyle(R.style.LilacTheme, true); Drawable themedYellowDrawableForMediumDensity = ResourcesCompat.getDrawableForDensity(mResources, R.drawable.themed_bitmap, DisplayMetrics.DENSITY_MEDIUM, yellowTheme); TestUtils.assertAllPixelsOfColor("Themed yellow density-aware drawable load : medium color", themedYellowDrawableForMediumDensity, 0xFFF0B000); Drawable themedLilacDrawableForMediumDensity = ResourcesCompat.getDrawableForDensity(mResources, R.drawable.themed_bitmap, DisplayMetrics.DENSITY_MEDIUM, lilacTheme); TestUtils.assertAllPixelsOfColor("Themed lilac density-aware drawable load : medium color", themedLilacDrawableForMediumDensity, 0xFFF080F0); Drawable themedYellowDrawableForHighDensity = ResourcesCompat.getDrawableForDensity(mResources, R.drawable.themed_bitmap, DisplayMetrics.DENSITY_HIGH, yellowTheme); TestUtils.assertAllPixelsOfColor("Themed yellow density-aware drawable load : high color", themedYellowDrawableForHighDensity, 0xFFF0B000); Drawable themedLilacDrawableForHighDensity = ResourcesCompat.getDrawableForDensity(mResources, R.drawable.themed_bitmap, DisplayMetrics.DENSITY_HIGH, lilacTheme); TestUtils.assertAllPixelsOfColor("Themed lilac density-aware drawable load : high color", themedLilacDrawableForHighDensity, 0xFFF080F0); Drawable themedYellowDrawableForXHighDensity = ResourcesCompat.getDrawableForDensity(mResources, R.drawable.themed_bitmap, DisplayMetrics.DENSITY_XHIGH, yellowTheme); TestUtils.assertAllPixelsOfColor("Themed yellow density-aware drawable load : xhigh color", themedYellowDrawableForXHighDensity, 0xFFF0B000); Drawable themedLilacDrawableForXHighDensity = ResourcesCompat.getDrawableForDensity(mResources, R.drawable.themed_bitmap, DisplayMetrics.DENSITY_XHIGH, lilacTheme); TestUtils.assertAllPixelsOfColor("Themed lilac density-aware drawable load : xhigh color", themedLilacDrawableForXHighDensity, 0xFFF080F0); Drawable themedYellowDrawableForXXHighDensity = ResourcesCompat.getDrawableForDensity(mResources, R.drawable.themed_bitmap, DisplayMetrics.DENSITY_XXHIGH, yellowTheme); TestUtils.assertAllPixelsOfColor("Themed yellow density-aware drawable load : xxhigh color", themedYellowDrawableForXXHighDensity, 0xFFF0B000); Drawable themedLilacDrawableForXXHighDensity = ResourcesCompat.getDrawableForDensity(mResources, R.drawable.themed_bitmap, DisplayMetrics.DENSITY_XXHIGH, lilacTheme); TestUtils.assertAllPixelsOfColor("Themed lilac density-aware drawable load : xxhigh color", themedLilacDrawableForXXHighDensity, 0xFFF080F0); }
@Nullable @SuppressWarnings("deprecation") public static Drawable getDrawableForDensity(@NonNull Resources res, @DrawableRes int id, int density, @Nullable Theme theme) throws NotFoundException { if (SDK_INT >= 21) { return res.getDrawableForDensity(id, density, theme); } else if (SDK_INT >= 15) { return res.getDrawableForDensity(id, density); } else { return res.getDrawable(id); } }
ResourcesCompat { @Nullable @SuppressWarnings("deprecation") public static Drawable getDrawableForDensity(@NonNull Resources res, @DrawableRes int id, int density, @Nullable Theme theme) throws NotFoundException { if (SDK_INT >= 21) { return res.getDrawableForDensity(id, density, theme); } else if (SDK_INT >= 15) { return res.getDrawableForDensity(id, density); } else { return res.getDrawable(id); } } }
ResourcesCompat { @Nullable @SuppressWarnings("deprecation") public static Drawable getDrawableForDensity(@NonNull Resources res, @DrawableRes int id, int density, @Nullable Theme theme) throws NotFoundException { if (SDK_INT >= 21) { return res.getDrawableForDensity(id, density, theme); } else if (SDK_INT >= 15) { return res.getDrawableForDensity(id, density); } else { return res.getDrawable(id); } } private  ResourcesCompat(); }
ResourcesCompat { @Nullable @SuppressWarnings("deprecation") public static Drawable getDrawableForDensity(@NonNull Resources res, @DrawableRes int id, int density, @Nullable Theme theme) throws NotFoundException { if (SDK_INT >= 21) { return res.getDrawableForDensity(id, density, theme); } else if (SDK_INT >= 15) { return res.getDrawableForDensity(id, density); } else { return res.getDrawable(id); } } private  ResourcesCompat(); @Nullable @SuppressWarnings("deprecation") static Drawable getDrawable(@NonNull Resources res, @DrawableRes int id,
            @Nullable Theme theme); @Nullable @SuppressWarnings("deprecation") static Drawable getDrawableForDensity(@NonNull Resources res, @DrawableRes int id,
            int density, @Nullable Theme theme); @ColorInt @SuppressWarnings("deprecation") static int getColor(@NonNull Resources res, @ColorRes int id, @Nullable Theme theme); @Nullable @SuppressWarnings("deprecation") static ColorStateList getColorStateList(@NonNull Resources res, @ColorRes int id,
            @Nullable Theme theme); @Nullable static Typeface getFont(@NonNull Context context, @FontRes int id); static void getFont(@NonNull Context context, @FontRes int id,
            @NonNull FontCallback fontCallback, @Nullable Handler handler); @RestrictTo(LIBRARY_GROUP) static Typeface getFont(@NonNull Context context, @FontRes int id, TypedValue value,
            int style, @Nullable FontCallback fontCallback); }
ResourcesCompat { @Nullable @SuppressWarnings("deprecation") public static Drawable getDrawableForDensity(@NonNull Resources res, @DrawableRes int id, int density, @Nullable Theme theme) throws NotFoundException { if (SDK_INT >= 21) { return res.getDrawableForDensity(id, density, theme); } else if (SDK_INT >= 15) { return res.getDrawableForDensity(id, density); } else { return res.getDrawable(id); } } private  ResourcesCompat(); @Nullable @SuppressWarnings("deprecation") static Drawable getDrawable(@NonNull Resources res, @DrawableRes int id,
            @Nullable Theme theme); @Nullable @SuppressWarnings("deprecation") static Drawable getDrawableForDensity(@NonNull Resources res, @DrawableRes int id,
            int density, @Nullable Theme theme); @ColorInt @SuppressWarnings("deprecation") static int getColor(@NonNull Resources res, @ColorRes int id, @Nullable Theme theme); @Nullable @SuppressWarnings("deprecation") static ColorStateList getColorStateList(@NonNull Resources res, @ColorRes int id,
            @Nullable Theme theme); @Nullable static Typeface getFont(@NonNull Context context, @FontRes int id); static void getFont(@NonNull Context context, @FontRes int id,
            @NonNull FontCallback fontCallback, @Nullable Handler handler); @RestrictTo(LIBRARY_GROUP) static Typeface getFont(@NonNull Context context, @FontRes int id, TypedValue value,
            int style, @Nullable FontCallback fontCallback);  }