package android.support.v4.content.res; import android.content.res.ColorStateList; import android.content.res.Resources; import android.content.res.Resources.NotFoundException; import android.content.res.Resources.Theme; import android.graphics.drawable.Drawable; import android.os.Build.VERSION; import android.support.annotation.ColorInt; import android.support.annotation.ColorRes; import android.support.annotation.DrawableRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; public final class ResourcesCompat { @Nullable public static Drawable getDrawable(@NonNull Resources res, @DrawableRes int id, @Nullable Theme theme) throws NotFoundException { if (VERSION.SDK_INT >= 21) { return ResourcesCompatApi21.getDrawable(res, id, theme); } return res.getDrawable(id); } @Nullable public static Drawable getDrawableForDensity(@NonNull Resources res, @DrawableRes int id, int density, @Nullable Theme theme) throws NotFoundException { if (VERSION.SDK_INT >= 21) { return ResourcesCompatApi21.getDrawableForDensity(res, id, density, theme); } if (VERSION.SDK_INT >= 15) { return ResourcesCompatIcsMr1.getDrawableForDensity(res, id, density); } return res.getDrawable(id); } @ColorInt public static int getColor(@NonNull Resources res, @ColorRes int id, @Nullable Theme theme) throws NotFoundException { if (VERSION.SDK_INT >= 23) { return ResourcesCompatApi23.getColor(res, id, theme); } return res.getColor(id); } @Nullable public static ColorStateList getColorStateList(@NonNull Resources res, @ColorRes int id, @Nullable Theme theme) throws NotFoundException { if (VERSION.SDK_INT >= 23) { return ResourcesCompatApi23.getColorStateList(res, id, theme); } return res.getColorStateList(id); } private ResourcesCompat() { } }