Example usage for android.content.res ColorStateList ColorStateList

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

Introduction

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

Prototype

public ColorStateList(int[][] states, @ColorInt int[] colors) 

Source Link

Document

Creates a ColorStateList that returns the specified mapping from states to colors.

Usage

From source file:com.tr4android.support.extension.picker.PickerThemeUtils.java

public static ColorStateList getTextColorPrimaryActivatedStateList(Context context) {
    final float disabledAlpha = getDisabledAlpha(context);
    final int textColor = ThemeUtils.getThemeAttrColor(context, android.R.attr.textColorPrimary);
    final int textColorActivated = ContextCompat.getColor(context, R.color.abc_primary_text_material_dark);
    return new ColorStateList(new int[][] { // states
            new int[] { -android.R.attr.state_enabled, android.R.attr.state_selected },
            new int[] { -android.R.attr.state_enabled }, new int[] { android.R.attr.state_selected },
            new int[] {} // state_default
    }, new int[] { // colors
            setAlphaComponent(textColorActivated, disabledAlpha), setAlphaComponent(textColor, disabledAlpha),
            textColorActivated, textColor });
}

From source file:io.github.hidroh.materialistic.widget.IconButton.java

public IconButton(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    setBackgroundResource(AppUtils.getThemedResId(context, R.attr.selectableItemBackgroundBorderless));
    TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.IconButton, 0, 0);
    int colorDisabled = ContextCompat.getColor(context,
            AppUtils.getThemedResId(context, android.R.attr.textColorSecondary));
    int colorDefault = ContextCompat.getColor(context,
            AppUtils.getThemedResId(context, android.R.attr.textColorPrimary));
    int colorEnabled = ta.getColor(R.styleable.IconButton_tint, colorDefault);
    mColorStateList = new ColorStateList(STATES, new int[] { colorEnabled, colorDisabled });
    mTinted = ta.hasValue(R.styleable.IconButton_tint);
    if (getSuggestedMinimumWidth() == 0) {
        setMinimumWidth(context.getResources().getDimensionPixelSize(R.dimen.icon_button_width));
    }/*from ww w . jav  a  2 s.com*/
    setScaleType(ScaleType.CENTER);
    setImageDrawable(getDrawable());
    ta.recycle();
}

From source file:com.dm.material.dashboard.candybar.helpers.ColorHelper.java

public static ColorStateList getColorStateList(int attr, @ColorInt int color, @ColorInt int color2) {
    int[][] states = new int[][] { new int[] { attr }, new int[] {} };
    int[] colors = new int[] { color, color2 };
    return new ColorStateList(states, colors);
}

From source file:ren.qinc.markdowneditors.base.BaseDrawerLayoutActivity.java

private void initDrawer() {
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, mDrawerLayout, getToolbar(),
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    mDrawerLayout.setDrawerListener(toggle);
    toggle.syncState();/*from www  .  j a  va 2  s  .  c  o m*/

    mNavigationView.setNavigationItemSelectedListener(this);

    ColorStateList colorStateList = new ColorStateList(
            new int[][] { { android.R.attr.state_checked, android.R.attr.state_enabled },
                    { android.R.attr.state_enabled }, {} },
            new int[] { BaseApplication.color(R.color.colorPrimary),
                    BaseApplication.color(R.color.colorSecondaryText), 0xffDCDDDD });
    mNavigationView.setItemIconTintList(colorStateList);//?
    mNavigationView.setItemTextColor(colorStateList);//item?
    if (getDefaultMenuItemId() > 0)
        mNavigationView.setCheckedItem(getDefaultMenuItemId());//
}

From source file:com.owncloud.android.ui.ThemeableSwitchPreference.java

@RequiresApi(Build.VERSION_CODES.JELLY_BEAN)
private void findSwitch(ViewGroup viewGroup) {
    for (int i = 0; i < viewGroup.getChildCount(); i++) {
        View child = viewGroup.getChildAt(i);

        if (child instanceof Switch) {
            Switch switchView = (Switch) child;

            int color = ThemeUtils.primaryAccentColor();
            int trackColor = Color.argb(77, Color.red(color), Color.green(color), Color.blue(color));

            // setting the thumb color
            DrawableCompat.setTintList(switchView.getThumbDrawable(),
                    new ColorStateList(new int[][] { new int[] { android.R.attr.state_checked }, new int[] {} },
                            new int[] { color, Color.WHITE }));

            // setting the track color
            DrawableCompat.setTintList(switchView.getTrackDrawable(),
                    new ColorStateList(new int[][] { new int[] { android.R.attr.state_checked }, new int[] {} },
                            new int[] { trackColor, Color.parseColor("#4D000000") }));

            break;
        } else if (child instanceof ViewGroup) {
            findSwitch((ViewGroup) child);
        }/*from  ww w.j  ava 2 s  .  c  o m*/
    }
}

From source file:com.aqtc.bmobnews.util.ResourcesUtils.java

/**
 * ColorStateList//from   www  .j a  v a 2  s.c om
 * create a ColorStateList instance
 *
 * @param normal normal
 * @param pressed pressed
 * @param focused focused
 * @param unable unable
 * @return ColorStateList
 */
public static ColorStateList createColorStateList(@ColorInt int normal, @ColorInt int pressed,
        @ColorInt int focused, @ColorInt int unable) {
    colors[0] = pressed;
    colors[1] = focused;
    colors[2] = normal;
    colors[3] = focused;
    colors[4] = unable;
    colors[5] = normal;
    return new ColorStateList(states, colors);
}

From source file:com.android.datetimepicker.date.TextViewWithCircularIndicator.java

/**
 * Programmatically set the color state list (see mdtp_date_picker_year_selector)
 * @param accentColor pressed state text color
 * @param darkMode current theme mode//from  ww w.  j  a v  a2  s.  co  m
 * @return ColorStateList with pressed state
 */
private ColorStateList createTextColor(int accentColor, boolean darkMode) {
    int[][] states = new int[][] { new int[] { android.R.attr.state_pressed }, // pressed
            new int[] { android.R.attr.state_selected }, // selected
            new int[] {} };
    int[] colors = new int[] { accentColor, Color.WHITE, darkMode ? Color.WHITE : Color.BLACK };
    return new ColorStateList(states, colors);
}

From source file:com.tr4android.support.extension.picker.PickerThemeUtils.java

public static ColorStateList getTextColorSecondaryActivatedStateList(Context context) {
    final float disabledAlpha = getDisabledAlpha(context);
    final int textColor = ThemeUtils.getThemeAttrColor(context, android.R.attr.textColorSecondary);
    final int textColorActivated = ContextCompat.getColor(context, R.color.abc_secondary_text_material_dark);
    return new ColorStateList(new int[][] { // states
            new int[] { -android.R.attr.state_enabled, android.R.attr.state_selected },
            new int[] { -android.R.attr.state_enabled }, new int[] { android.R.attr.state_selected },
            new int[] {} // state_default
    }, new int[] { // colors
            setAlphaComponent(textColorActivated, disabledAlpha), setAlphaComponent(textColor, disabledAlpha),
            textColorActivated, textColor });
}

From source file:com.tafayor.selfcamerashot.taflib.helpers.GraphicsHelper.java

public static ColorStateList getColorStateList(int color) {
    ColorStateList myColorStateList = new ColorStateList(new int[][] { new int[] {} }, new int[] { color, });

    return myColorStateList;

}

From source file:com.androidinspain.deskclock.timer.TimerItem.java

@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    mLabelView = (TextView) findViewById(R.id.timer_label);
    mResetAddButton = (Button) findViewById(R.id.reset_add);
    mCircleView = (TimerCircleView) findViewById(R.id.timer_time);
    mTimerText = (TextView) findViewById(R.id.timer_time_text);
    mTimerTextController = new TimerTextController(mTimerText);

    final Context c = mTimerText.getContext();
    final int colorAccent = ThemeUtils.resolveColor(c, R.attr.colorAccent);
    final int textColorPrimary = ThemeUtils.resolveColor(c, android.R.attr.textColorPrimary);
    mTimerText.setTextColor(new ColorStateList(new int[][] { { -state_activated, -state_pressed }, {} },
            new int[] { textColorPrimary, colorAccent }));
}