@Test public void testGetColorStateList() throws Throwable { final ColorStateList unthemedColorStateList = ResourcesCompat.getColorStateList(mResources, R.color.complex_unthemed_selector, null); assertEquals("Unthemed color state list load: default", 0xFF70A0C0, unthemedColorStateList.getDefaultColor()); assertEquals("Unthemed color state list load: focused", 0xFF70B0F0, unthemedColorStateList.getColorForState( new int[]{android.R.attr.state_focused}, 0)); assertEquals("Unthemed color state list load: pressed", 0xFF6080B0, unthemedColorStateList.getColorForState( new int[]{android.R.attr.state_pressed}, 0)); if (Build.VERSION.SDK_INT >= 23) { final Resources.Theme yellowTheme = mResources.newTheme(); yellowTheme.applyStyle(R.style.YellowTheme, true); final ColorStateList themedYellowColorStateList = ResourcesCompat.getColorStateList(mResources, R.color.complex_themed_selector, yellowTheme); assertEquals("Themed yellow color state list load: default", 0xFFF0B000, themedYellowColorStateList.getDefaultColor()); assertEquals("Themed yellow color state list load: focused", 0xFFF0A020, themedYellowColorStateList.getColorForState( new int[]{android.R.attr.state_focused}, 0)); assertEquals("Themed yellow color state list load: pressed", 0xFFE0A040, themedYellowColorStateList.getColorForState( new int[]{android.R.attr.state_pressed}, 0)); final Resources.Theme lilacTheme = mResources.newTheme(); lilacTheme.applyStyle(R.style.LilacTheme, true); final ColorStateList themedLilacColorStateList = ResourcesCompat.getColorStateList(mResources, R.color.complex_themed_selector, lilacTheme); assertEquals("Themed lilac color state list load: default", 0xFFF080F0, themedLilacColorStateList.getDefaultColor()); assertEquals("Themed lilac color state list load: focused", 0xFFF070D0, themedLilacColorStateList.getColorForState( new int[]{android.R.attr.state_focused}, 0)); assertEquals("Themed lilac color state list load: pressed", 0xFFE070A0, themedLilacColorStateList.getColorForState( new int[]{android.R.attr.state_pressed}, 0)); } }
@Nullable @SuppressWarnings("deprecation") public static ColorStateList getColorStateList(@NonNull Resources res, @ColorRes int id, @Nullable Theme theme) throws NotFoundException { if (SDK_INT >= 23) { return res.getColorStateList(id, theme); } else { return res.getColorStateList(id); } }
ResourcesCompat { @Nullable @SuppressWarnings("deprecation") public static ColorStateList getColorStateList(@NonNull Resources res, @ColorRes int id, @Nullable Theme theme) throws NotFoundException { if (SDK_INT >= 23) { return res.getColorStateList(id, theme); } else { return res.getColorStateList(id); } } }
ResourcesCompat { @Nullable @SuppressWarnings("deprecation") public static ColorStateList getColorStateList(@NonNull Resources res, @ColorRes int id, @Nullable Theme theme) throws NotFoundException { if (SDK_INT >= 23) { return res.getColorStateList(id, theme); } else { return res.getColorStateList(id); } } private  ResourcesCompat(); }
ResourcesCompat { @Nullable @SuppressWarnings("deprecation") public static ColorStateList getColorStateList(@NonNull Resources res, @ColorRes int id, @Nullable Theme theme) throws NotFoundException { if (SDK_INT >= 23) { return res.getColorStateList(id, theme); } else { return res.getColorStateList(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 ColorStateList getColorStateList(@NonNull Resources res, @ColorRes int id, @Nullable Theme theme) throws NotFoundException { if (SDK_INT >= 23) { return res.getColorStateList(id, theme); } else { return res.getColorStateList(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);  }