@Test public void testGetDrawableForDensityUnthemed() throws Throwable { final Drawable unthemedDrawableForMediumDensity = ResourcesCompat.getDrawableForDensity(mResources, R.drawable.density_aware_drawable, DisplayMetrics.DENSITY_MEDIUM, null); final int expectedSizeForMediumDensity = (Build.VERSION.SDK_INT < 15) ? mResources.getDimensionPixelSize(R.dimen.density_aware_size) : 12; assertEquals("Unthemed density-aware drawable load: medium width", expectedSizeForMediumDensity, unthemedDrawableForMediumDensity.getIntrinsicWidth()); assertEquals("Unthemed density-aware drawable load: medium height", expectedSizeForMediumDensity, unthemedDrawableForMediumDensity.getIntrinsicHeight()); final Drawable unthemedDrawableForHighDensity = ResourcesCompat.getDrawableForDensity(mResources, R.drawable.density_aware_drawable, DisplayMetrics.DENSITY_HIGH, null); final int expectedSizeForHighDensity = (Build.VERSION.SDK_INT < 15) ? mResources.getDimensionPixelSize(R.dimen.density_aware_size) : 21; assertEquals("Unthemed density-aware drawable load: high width", expectedSizeForHighDensity, unthemedDrawableForHighDensity.getIntrinsicWidth()); assertEquals("Unthemed density-aware drawable load: high height", expectedSizeForHighDensity, unthemedDrawableForHighDensity.getIntrinsicHeight()); final Drawable unthemedDrawableForXHighDensity = ResourcesCompat.getDrawableForDensity(mResources, R.drawable.density_aware_drawable, DisplayMetrics.DENSITY_XHIGH, null); final int expectedSizeForXHighDensity = (Build.VERSION.SDK_INT < 15) ? mResources.getDimensionPixelSize(R.dimen.density_aware_size) : 32; assertEquals("Unthemed density-aware drawable load: xhigh width", expectedSizeForXHighDensity, unthemedDrawableForXHighDensity.getIntrinsicWidth()); assertEquals("Unthemed density-aware drawable load: xhigh height", expectedSizeForXHighDensity, unthemedDrawableForXHighDensity.getIntrinsicHeight()); final Drawable unthemedDrawableForXXHighDensity = ResourcesCompat.getDrawableForDensity(mResources, R.drawable.density_aware_drawable, DisplayMetrics.DENSITY_XXHIGH, null); final int expectedSizeForXXHighDensity = (Build.VERSION.SDK_INT < 15) ? mResources.getDimensionPixelSize(R.dimen.density_aware_size) : 54; assertEquals("Unthemed density-aware drawable load: xxhigh width", expectedSizeForXXHighDensity, unthemedDrawableForXXHighDensity.getIntrinsicWidth()); assertEquals("Unthemed density-aware drawable load: xxhigh height", expectedSizeForXXHighDensity, unthemedDrawableForXXHighDensity.getIntrinsicHeight()); }
@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);  }