List of usage examples for android.content.res ColorStateList getColorForState
public int getColorForState(@Nullable int[] stateSet, int defaultColor)
From source file:Main.java
/** * Ensures the tint filter is consistent with the current tint color and * mode.// ww w. ja v a 2s .c om */ public static PorterDuffColorFilter updateTintFilter(Drawable drawable, PorterDuffColorFilter tintFilter, ColorStateList tint, PorterDuff.Mode tintMode) { if (tint == null || tintMode == null) { return null; } final int color = tint.getColorForState(drawable.getState(), Color.TRANSPARENT); return new PorterDuffColorFilter(color, tintMode); }
From source file:com.telly.mrvector.Utils.java
/** * Ensures the tint filter is consistent with the current tint color and * mode./*from w w w. ja v a2 s . c o m*/ */ static PorterDuffColorFilter updateTintFilter(Drawable drawable, PorterDuffColorFilter tintFilter, ColorStateList tint, PorterDuff.Mode tintMode) { if (tint == null || tintMode == null) { return null; } final int color = tint.getColorForState(drawable.getState(), Color.TRANSPARENT); if (tintFilter == null || !LOLLIPOP_PLUS) { // TODO worth caching them? return new PorterDuffColorFilter(color, tintMode); } tryInvoke(tintFilter, "setColor", INT_ARG, color); tryInvoke(tintFilter, "setMode", MODE_ARG, tintMode); return tintFilter; }
From source file:com.john.main.Utils.java
/** * Ensures the tint filter is consistent with the current tint color and * mode./*from ww w . j a va 2 s. c o m*/ */ static PorterDuffColorFilter updateTintFilter(Drawable drawable, PorterDuffColorFilter tintFilter, ColorStateList tint, Mode tintMode) { if (tint == null || tintMode == null) { return null; } final int color = tint.getColorForState(drawable.getState(), Color.TRANSPARENT); if (tintFilter == null || !LOLLIPOP_PLUS) { // TODO worth caching them? return new PorterDuffColorFilter(color, tintMode); } tryInvoke(tintFilter, "setColor", INT_ARG, color); tryInvoke(tintFilter, "setMode", MODE_ARG, tintMode); return tintFilter; }
From source file:android.support.v7.internal.widget.ThemeUtils.java
static int getDisabledThemeAttrColor(Context context, int attr) { final ColorStateList csl = getThemeAttrColorStateList(context, attr); if (csl != null && csl.isStateful()) { // If the CSL is stateful, we'll assume it has a disabled state and use it return csl.getColorForState(DISABLED_STATE_SET, csl.getDefaultColor()); } else {//w ww . ja va2 s . c o m // Else, we'll generate the color using disabledAlpha from the theme final TypedValue tv = getTypedValue(); // Now retrieve the disabledAlpha value from the theme context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, tv, true); final float disabledAlpha = tv.getFloat(); return getThemeAttrColor(context, attr, disabledAlpha); } }
From source file:android.support.v7.widget.ThemeUtils.java
public static int getDisabledThemeAttrColor(Context context, int attr) { final ColorStateList csl = getThemeAttrColorStateList(context, attr); if (csl != null && csl.isStateful()) { // If the CSL is stateful, we'll assume it has a disabled state and use it return csl.getColorForState(DISABLED_STATE_SET, csl.getDefaultColor()); } else {//from w w w. j a v a 2 s. co m // Else, we'll generate the color using disabledAlpha from the theme final TypedValue tv = getTypedValue(); // Now retrieve the disabledAlpha value from the theme context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, tv, true); final float disabledAlpha = tv.getFloat(); return getThemeAttrColor(context, attr, disabledAlpha); } }
From source file:com.bilibili.magicasakura.utils.TintManager.java
private static PorterDuffColorFilter createTintFilter(Context context, ColorStateList tint, PorterDuff.Mode tintMode, final int[] state) { if (tint == null || tintMode == null) { return null; }/*from w ww . ja v a 2 s . c o m*/ final int color = ThemeUtils.replaceColor(context, tint.getColorForState(state, tint.getDefaultColor())); return getPorterDuffColorFilter(color, tintMode); }
From source file:com.bilibili.magicasakura.utils.ThemeUtils.java
public static int getDisabledThemeAttrColor(Context context, @AttrRes int attr) { final ColorStateList csl = getThemeAttrColorStateList(context, attr); if (csl != null && csl.isStateful()) { // If the CSL is stateful, we'll assume it has a disabled state and use it return csl.getColorForState(DISABLED_STATE_SET, csl.getDefaultColor()); } else {//www.j a va 2 s. c o m // Else, we'll generate the color using disabledAlpha from the theme final TypedValue tv = getTypedValue(); // Now retrieve the disabledAlpha value from the theme context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, tv, true); final float disabledAlpha = tv.getFloat(); return getThemeAttrColor(context, attr, disabledAlpha); } }
From source file:com.demo.wondersdaili.mvp.utils.ThemeUtils.java
static TintInfo parseColorStateList(ColorStateList origin) { if (origin == null) return null; boolean hasDisable = false; int originDefaultColor = origin.getDefaultColor(); LinkedList<int[]> stateList = new LinkedList<>(); LinkedList<Integer> colorList = new LinkedList<>(); int disableColor = origin.getColorForState(DISABLED_STATE_SET, 0); if (disableColor != originDefaultColor) { hasDisable = true;/* w w w . ja v a2 s . co m*/ stateList.add(DISABLED_STATE_SET); colorList.add(disableColor); } int pressedColor = origin.getColorForState(wrapState(hasDisable, PRESSED_STATE_SET), 0); if (pressedColor != originDefaultColor) { stateList.add(PRESSED_STATE_SET); colorList.add(pressedColor); } int focusColor = origin.getColorForState(wrapState(hasDisable, FOCUSED_STATE_SET), 0); if (focusColor != originDefaultColor) { stateList.add(FOCUSED_STATE_SET); colorList.add(focusColor); } int checkedColor = origin.getColorForState(wrapState(hasDisable, CHECKED_STATE_SET), 0); if (checkedColor != originDefaultColor) { stateList.add(CHECKED_STATE_SET); colorList.add(checkedColor); } int selectedColor = origin.getColorForState(wrapState(hasDisable, SELECTED_STATE_SET), 0); if (selectedColor != originDefaultColor) { stateList.add(SELECTED_STATE_SET); colorList.add(selectedColor); } int normalColor = origin.getColorForState(wrapState(hasDisable, EMPTY_STATE_SET), 0); if (normalColor != 0) { stateList.add(EMPTY_STATE_SET); colorList.add(normalColor); } if (colorList.size() > 1) { return new TintInfo(stateList, colorList); } else { return null; } }
From source file:android.support.v7.widget.AppCompatDrawableManager.java
private static PorterDuffColorFilter createTintFilter(ColorStateList tint, PorterDuff.Mode tintMode, final int[] state) { if (tint == null || tintMode == null) { return null; }/*from ww w. j a v a 2 s. c o m*/ final int color = tint.getColorForState(state, Color.TRANSPARENT); return getPorterDuffColorFilter(color, tintMode); }
From source file:com.bilibili.magicasakura.utils.ThemeUtils.java
static com.bilibili.magicasakura.utils.TintInfo parseColorStateList(ColorStateList origin) { if (origin == null) return null; boolean hasDisable = false; int originDefaultColor = origin.getDefaultColor(); LinkedList<int[]> stateList = new LinkedList<>(); LinkedList<Integer> colorList = new LinkedList<>(); int disableColor = origin.getColorForState(DISABLED_STATE_SET, 0); if (disableColor != originDefaultColor) { hasDisable = true;/* w ww . j a v a2 s . c o m*/ stateList.add(DISABLED_STATE_SET); colorList.add(disableColor); } int pressedColor = origin.getColorForState(wrapState(hasDisable, PRESSED_STATE_SET), 0); if (pressedColor != originDefaultColor) { stateList.add(PRESSED_STATE_SET); colorList.add(pressedColor); } int focusColor = origin.getColorForState(wrapState(hasDisable, FOCUSED_STATE_SET), 0); if (focusColor != originDefaultColor) { stateList.add(FOCUSED_STATE_SET); colorList.add(focusColor); } int checkedColor = origin.getColorForState(wrapState(hasDisable, CHECKED_STATE_SET), 0); if (checkedColor != originDefaultColor) { stateList.add(CHECKED_STATE_SET); colorList.add(checkedColor); } int selectedColor = origin.getColorForState(wrapState(hasDisable, SELECTED_STATE_SET), 0); if (selectedColor != originDefaultColor) { stateList.add(SELECTED_STATE_SET); colorList.add(selectedColor); } int normalColor = origin.getColorForState(wrapState(hasDisable, EMPTY_STATE_SET), 0); if (normalColor != 0) { stateList.add(EMPTY_STATE_SET); colorList.add(normalColor); } if (colorList.size() > 1) { return new com.bilibili.magicasakura.utils.TintInfo(stateList, colorList); } else { return null; } }