Example usage for android.content.res ColorStateList getDefaultColor

List of usage examples for android.content.res ColorStateList getDefaultColor

Introduction

In this page you can find the example usage for android.content.res ColorStateList getDefaultColor.

Prototype

@ColorInt
public int getDefaultColor() 

Source Link

Document

Return the default color in this ColorStateList .

Usage

From source file:com.mightyworkouts.seekbar.DiscreteSeekBar.java

/**
 * Sets the color of the seek thumb, as well as the color of the popup indicator.
 *
 * @param thumbColorStateList The ColorStateList the seek thumb will be changed to
 * @param indicatorColor      The color the popup indicator will be changed to
 *                            The indicator will animate from thumbColorStateList(pressed state) to indicatorColor
 *                            when opening
 *///from w  w w.j a va 2  s .com
public void setThumbColor(@NonNull ColorStateList thumbColorStateList, int indicatorColor) {

    mThumb.setColorStateList(thumbColorStateList);
    //we use the "pressed" color to morph the indicator from it to its own color
    int thumbColor = thumbColorStateList.getColorForState(new int[] { PRESSED_STATE },
            thumbColorStateList.getDefaultColor());
    mIndicator.setColors(indicatorColor, thumbColor);
}

From source file:com.fenlisproject.elf.core.widget.ExtendedButton.java

public ExtendedButton(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    if (TintManager.SHOULD_BE_USED) {
        TintTypedArray a = TintTypedArray.obtainStyledAttributes(getContext(), attrs, TINT_ATTRS, defStyleAttr,
                0);/*  w  w  w  .  j av  a  2s .co  m*/
        if (a.hasValue(0)) {
            ColorStateList tint = a.getTintManager().getTintList(a.getResourceId(0, -1));
            if (tint != null) {
                setSupportBackgroundTintList(tint);
            }
        }
        a.recycle();
    }

    // First read the TextAppearance style id
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AppCompatTextView, defStyleAttr, 0);
    final int ap = a.getResourceId(R.styleable.AppCompatTextView_android_textAppearance, -1);
    a.recycle();

    // Now check TextAppearance's textAllCaps value
    if (ap != -1) {
        TypedArray appearance = context.obtainStyledAttributes(ap, R.styleable.TextAppearance);
        if (appearance.hasValue(R.styleable.TextAppearance_textAllCaps)) {
            setAllCaps(appearance.getBoolean(R.styleable.TextAppearance_textAllCaps, false));
        }
        appearance.recycle();
    }

    // Now read the style's value
    a = context.obtainStyledAttributes(attrs, R.styleable.AppCompatTextView, defStyleAttr, 0);
    if (a.hasValue(R.styleable.AppCompatTextView_textAllCaps)) {
        setAllCaps(a.getBoolean(R.styleable.AppCompatTextView_textAllCaps, false));
    }
    a.recycle();

    final ColorStateList textColors = getTextColors();
    if (textColors != null && !textColors.isStateful()) {
        // If we have a ColorStateList which isn't stateful, create one which includes
        // a disabled state

        final int disabledTextColor;
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            // Pre-Lollipop, we will use textColorSecondary with android:disabledAlpha
            // applied
            disabledTextColor = ThemeUtils.getDisabledThemeAttrColor(context,
                    android.R.attr.textColorSecondary);
        } else {
            // With certain styles on Lollipop, there is a StateListAnimator which sets
            // an alpha on the whole view, so we don't need to apply disabledAlpha to
            // textColorSecondary
            disabledTextColor = ThemeUtils.getThemeAttrColor(context, android.R.attr.textColorSecondary);
        }

        setTextColor(ThemeUtils.createDisabledStateList(textColors.getDefaultColor(), disabledTextColor));
    }
}

From source file:com.example.michaelg.myapplication.Item.discreteseekbar.DiscreteSeekBar.java

/**
 * Sets the color of the seek thumb, as well as the color of the popup indicator.
 *
 * @param thumbColorStateList The ColorStateList the seek thumb will be changed to
 * @param indicatorColor      The color the popup indicator will be changed to
 *                            The indicator will animate from thumbColorStateList(pressed state) to indicatorColor
 *                            when opening
 *//*  ww  w.  j av  a2  s . com*/
public void setThumbColor(@NonNull ColorStateList thumbColorStateList, int indicatorColor) {
    mThumb.setColorStateList(thumbColorStateList);
    //we use the "pressed" color to morph the indicator from it to its own color
    int thumbColor = thumbColorStateList.getColorForState(new int[] { PRESSED_STATE },
            thumbColorStateList.getDefaultColor());
    mIndicator.setColors(indicatorColor, thumbColor);
}

From source file:com.max.library.view.v7.AppCompatDrawableManager.java

private ColorStateList createSwitchThumbColorStateList(Context context) {
    final int[][] states = new int[3][];
    final int[] colors = new int[3];
    int i = 0;//from   ww w. ja v a 2s .c  om

    final ColorStateList thumbColor = getThemeAttrColorStateList(context, R.attr.colorSwitchThumbNormal);

    if (thumbColor != null && thumbColor.isStateful()) {
        // If colorSwitchThumbNormal is a valid ColorStateList, extract the default and
        // disabled colors from it

        // Disabled state
        states[i] = ThemeUtils.DISABLED_STATE_SET;
        colors[i] = thumbColor.getColorForState(states[i], 0);
        i++;

        states[i] = ThemeUtils.CHECKED_STATE_SET;
        colors[i] = getThemeAttrColor(context, R.attr.colorControlActivated);
        i++;

        // Default enabled state
        states[i] = ThemeUtils.EMPTY_STATE_SET;
        colors[i] = thumbColor.getDefaultColor();
        i++;
    } else {
        // Else we'll use an approximation using the default disabled alpha

        // Disabled state
        states[i] = ThemeUtils.DISABLED_STATE_SET;
        colors[i] = getDisabledThemeAttrColor(context, R.attr.colorSwitchThumbNormal);
        i++;

        states[i] = ThemeUtils.CHECKED_STATE_SET;
        colors[i] = getThemeAttrColor(context, R.attr.colorControlActivated);
        i++;

        // Default enabled state
        states[i] = ThemeUtils.EMPTY_STATE_SET;
        colors[i] = getThemeAttrColor(context, R.attr.colorSwitchThumbNormal);
        i++;
    }

    return new ColorStateList(states, colors);
}

From source file:am.widget.indicatortabstrip.IndicatorTabStrip.java

/**
 * ??/*  w  w  w.  jav a2 s. c  om*/
 *
 * @param gradient ??
 */
public void setGradient(ColorStateList gradient) {
    if (gradient == null) {
        mGradient = null;
        invalidate();
    } else if (mGradient != gradient && gradient.isStateful()) {
        mGradient = gradient;
        invalidate();
    } else {
        setItemBackground(new ColorDrawable(gradient.getDefaultColor()));
    }
}

From source file:android.support.v7ox.widget.AppCompatDrawableManager.java

private ColorStateList createSwitchThumbColorStateList(Context context) {
    final int[][] states = new int[3][];
    final int[] colors = new int[3];
    int i = 0;/*from ww  w  .j  a  va  2 s.  c  o m*/

    final ColorStateList thumbColor = ThemeUtils.getThemeAttrColorStateList(context,
            R.attr.colorSwitchThumbNormal_ox);

    if (thumbColor != null && thumbColor.isStateful()) {
        // If colorSwitchThumbNormal is a valid ColorStateList, extract the default and
        // disabled colors from it

        // Disabled state
        states[i] = ThemeUtils.DISABLED_STATE_SET;
        colors[i] = thumbColor.getColorForState(states[i], 0);
        i++;

        states[i] = ThemeUtils.CHECKED_STATE_SET;
        colors[i] = ThemeUtils.getThemeAttrColor(context, R.attr.colorControlActivated_ox);
        i++;

        // Default enabled state
        states[i] = ThemeUtils.EMPTY_STATE_SET;
        colors[i] = thumbColor.getDefaultColor();
        i++;
    } else {
        // Else we'll use an approximation using the default disabled alpha

        // Disabled state
        states[i] = ThemeUtils.DISABLED_STATE_SET;
        colors[i] = ThemeUtils.getDisabledThemeAttrColor(context, R.attr.colorSwitchThumbNormal_ox);
        i++;

        states[i] = ThemeUtils.CHECKED_STATE_SET;
        colors[i] = ThemeUtils.getThemeAttrColor(context, R.attr.colorControlActivated_ox);
        i++;

        // Default enabled state
        states[i] = ThemeUtils.EMPTY_STATE_SET;
        colors[i] = ThemeUtils.getThemeAttrColor(context, R.attr.colorSwitchThumbNormal_ox);
        i++;
    }

    return new ColorStateList(states, colors);
}

From source file:com.musenkishi.atelier.Atelier.java

private static void applyColorToView(final FloatingActionButton floatingActionButton, int color,
        boolean fromCache, boolean shouldMask) {
    if (fromCache) {
        if (shouldMask) {
            if (floatingActionButton.getDrawable() != null) {
                floatingActionButton.getDrawable().mutate().setColorFilter(color, PorterDuff.Mode.MULTIPLY);
            } else if (floatingActionButton.getBackground() != null) {
                floatingActionButton.getBackground().mutate().setColorFilter(color, PorterDuff.Mode.MULTIPLY);
            }/*from w ww  .  java  2 s  . co  m*/
        } else {
            ColorStateList colorStateList = ColorStateList.valueOf(color);
            floatingActionButton.setBackgroundTintList(colorStateList);
        }
    } else {
        if (shouldMask) {

            Integer colorFrom;
            ValueAnimator.AnimatorUpdateListener imageAnimatorUpdateListener = new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                    if (floatingActionButton.getDrawable() != null) {
                        floatingActionButton.getDrawable().mutate().setColorFilter(
                                (Integer) valueAnimator.getAnimatedValue(), PorterDuff.Mode.MULTIPLY);
                    } else if (floatingActionButton.getBackground() != null) {
                        floatingActionButton.getBackground().mutate().setColorFilter(
                                (Integer) valueAnimator.getAnimatedValue(), PorterDuff.Mode.MULTIPLY);
                    }
                }
            };
            ValueAnimator.AnimatorUpdateListener animatorUpdateListener;

            PaletteTag paletteTag = (PaletteTag) floatingActionButton.getTag(viewTagKey);
            animatorUpdateListener = imageAnimatorUpdateListener;
            colorFrom = paletteTag.getColor();
            floatingActionButton.setTag(viewTagKey, new PaletteTag(paletteTag.getId(), color));

            Integer colorTo = color;
            ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
            colorAnimation.addUpdateListener(animatorUpdateListener);
            colorAnimation.setDuration(300);
            colorAnimation.start();

        } else {

            Integer colorFrom = Color.parseColor("#FFFAFAFA");

            ColorStateList colorStateList = floatingActionButton.getBackgroundTintList();
            if (colorStateList != null) {
                colorFrom = colorStateList.getDefaultColor();
            }

            Integer colorTo = color;
            ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
            colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animator) {
                    int color = (Integer) animator.getAnimatedValue();
                    floatingActionButton.setBackgroundTintList(ColorStateList.valueOf(color));
                }
            });
            colorAnimation.setDuration(300);
            colorAnimation.start();
        }
    }
}