FileDocCategorySizeDatePackage
ColorStateDrawable.javaAPI DocAndroid 5.1 API2207Thu Mar 12 22:22:50 GMT 2015com.android.colorpicker

ColorStateDrawable

public class ColorStateDrawable extends android.graphics.drawable.LayerDrawable
A drawable which sets its color filter to a color specified by the user, and changes to a slightly darker color when pressed or focused.

Fields Summary
private static final float
PRESSED_STATE_MULTIPLIER
private int
mColor
Constructors Summary
public ColorStateDrawable(android.graphics.drawable.Drawable[] layers, int color)


         
        super(layers);
        mColor = color;
    
Methods Summary
private static intgetPressedColor(int color)
Given a particular color, adjusts its value by a multiplier.

        float[] hsv = new float[3];
        Color.colorToHSV(color, hsv);
        hsv[2] = hsv[2] * PRESSED_STATE_MULTIPLIER;
        return Color.HSVToColor(hsv);
    
public booleanisStateful()

        return true;
    
protected booleanonStateChange(int[] states)

        boolean pressedOrFocused = false;
        for (int state : states) {
            if (state == android.R.attr.state_pressed || state == android.R.attr.state_focused) {
                pressedOrFocused = true;
                break;
            }
        }

        if (pressedOrFocused) {
            super.setColorFilter(getPressedColor(mColor), PorterDuff.Mode.SRC_ATOP);
        } else {
            super.setColorFilter(mColor, PorterDuff.Mode.SRC_ATOP);
        }

        return super.onStateChange(states);