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:org.mariotaku.twidere.view.themed.AccentSwipeRefreshLayout.java

@Override
public void setAccentTintColor(@NonNull ColorStateList color) {
    setColorSchemeColors(color.getDefaultColor());
}

From source file:org.adw.library.widgets.discreteseekbar.internal.drawable.AlmostRippleDrawable.java

public void setColor(@NonNull ColorStateList tintStateList) {
    int defaultColor = tintStateList.getDefaultColor();
    mFocusedColor = tintStateList.getColorForState(
            new int[] { android.R.attr.state_enabled, android.R.attr.state_focused }, defaultColor);
    mPressedColor = tintStateList.getColorForState(
            new int[] { android.R.attr.state_enabled, android.R.attr.state_pressed }, defaultColor);
    mDisabledColor = tintStateList.getColorForState(new int[] { -android.R.attr.state_enabled }, defaultColor);

    //The ripple should be partially transparent
    mFocusedColor = getModulatedAlphaColor(130, mFocusedColor);
    mPressedColor = getModulatedAlphaColor(130, mPressedColor);
    mDisabledColor = getModulatedAlphaColor(130, mDisabledColor);
}

From source file:com.finchuk.clock2.alarms.ui.BaseAlarmViewHolder.java

private void bindTime(Alarm alarm) {
    String time = DateFormat.getTimeFormat(getContext()).format(new Date(alarm.ringsAt()));
    if (DateFormat.is24HourFormat(getContext())) {
        mTime.setText(time);//from   ww  w  .ja va  2  s.  c  o  m
    } else {
        TimeTextUtils.setText(time, mTime);
    }

    // Use a mock TextView to get our colors, because its ColorStateList is never
    // mutated for the lifetime of this ViewHolder (even when reused).
    // This solution is robust against dark/light theme changes, whereas using
    // color resources is not.
    TextView colorsSource = (TextView) itemView.findViewById(R.id.colors_source);
    ColorStateList colors = colorsSource.getTextColors();
    int def = colors.getDefaultColor();
    // Too light
    //        int disabled = colors.getColorForState(new int[] {-android.R.attr.state_enabled}, def);
    // Material guidelines say text hints and disabled text should have the same color.
    int disabled = colorsSource.getCurrentHintTextColor();
    // However, digging around in the system's textColorHint for 21+ says its 50% black for our
    // light theme. I'd like to follow what the guidelines says, but I want code that is robust
    // against theme changes. Alternatively, override the attribute values to what you want
    // in both your dark and light themes...
    //        int disabled = ContextCompat.getColor(getContext(), R.color.text_color_disabled_light);
    // We only have two states, so we don't care about losing the other state colors.
    mTime.setTextColor(alarm.isEnabled() ? def : disabled);
}

From source file:com.andremion.counterfab.CounterFab.java

public CounterFab(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    setUseCompatPadding(true);/*from w  w w. ja  va 2 s  . c o m*/

    final float density = getResources().getDisplayMetrics().density;

    mTextSize = TEXT_SIZE_DP * density;
    float textPadding = TEXT_PADDING_DP * density;

    mAnimationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);
    mAnimationFactor = 1;

    mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setStyle(Paint.Style.STROKE);
    mTextPaint.setColor(Color.WHITE);
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setTextAlign(Paint.Align.CENTER);
    mTextPaint.setTypeface(Typeface.SANS_SERIF);

    mCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mCirclePaint.setStyle(Paint.Style.FILL);
    ColorStateList colorStateList = getBackgroundTintList();
    if (colorStateList != null) {
        mCirclePaint.setColor(colorStateList.getDefaultColor());
    } else {
        Drawable background = getBackground();
        if (background instanceof ColorDrawable) {
            ColorDrawable colorDrawable = (ColorDrawable) background;
            mCirclePaint.setColor(colorDrawable.getColor());
        }
    }

    mMaskPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mMaskPaint.setStyle(Paint.Style.FILL);
    mMaskPaint.setColor(MASK_COLOR);

    Rect textBounds = new Rect();
    mTextPaint.getTextBounds(MAX_COUNT_TEXT, 0, MAX_COUNT_TEXT.length(), textBounds);
    mTextHeight = textBounds.height();

    float textWidth = mTextPaint.measureText(MAX_COUNT_TEXT);
    float circleRadius = Math.max(textWidth, mTextHeight) / 2f + textPadding;
    mCircleBounds = new Rect(0, 0, (int) (circleRadius * 2), (int) (circleRadius * 2));
    mContentBounds = new Rect();

    onCountChanged();
}

From source file:org.adw.library.widgets.discreteseekbar.internal.drawable.MarkerDrawable.java

public MarkerDrawable(@NonNull ColorStateList tintList, int closedSize) {
    super(tintList);
    mInterpolator = new FastOutSlowInInterpolator();
    mClosedStateSize = closedSize;//  ww  w.j a v a  2s .  c o  m
    mStartColor = tintList.getColorForState(
            new int[] { android.R.attr.state_enabled, android.R.attr.state_pressed },
            tintList.getDefaultColor());
    mEndColor = tintList.getDefaultColor();

}

From source file:com.tencent.tws.assistant.widget.CheckBox.java

public void setTintButtonDrawable(ColorStateList colorStateList) {
    mIsAnimationButton = true;/* ww w .ja  v  a  2 s  . c o m*/
    int colorControlNormal = 0;
    int colorControlDisabled = 0;
    int colorControlActivated = 0;
    int colorControlActivateDisabled = 0;
    if (colorStateList.isStateful()) {
        colorControlNormal = colorStateList.getColorForState(checkOffState, colorStateList.getDefaultColor());
        colorControlDisabled = colorStateList.getColorForState(checkOffDisableState,
                colorStateList.getDefaultColor());
        colorControlActivated = colorStateList.getColorForState(checkOnState, colorStateList.getDefaultColor());
        colorControlActivateDisabled = colorStateList.getColorForState(checkOnDisableState,
                colorStateList.getDefaultColor());
    }
    setTintButtonDrawable(colorControlNormal, colorControlDisabled, colorControlActivated,
            colorControlActivateDisabled);
}

From source file:com.appeaser.sublimenavigationviewlibrary.SublimeThemer.java

private void setDefaultIconTintList() {
    TypedValue value = new TypedValue();
    if (mContext.getTheme().resolveAttribute(android.R.attr.textColorPrimary, value, true)) {
        ColorStateList baseColor = mContext.getResources().getColorStateList(value.resourceId);
        if (mContext.getTheme().resolveAttribute(R.attr.colorPrimary, value, true)) {
            int colorPrimary = value.data;
            int defaultColor = baseColor.getDefaultColor();
            mIconTintList = new ColorStateList(
                    new int[][] { DISABLED_STATE_SET, CHECKED_STATE_SET, EMPTY_STATE_SET },
                    new int[] { baseColor.getColorForState(DISABLED_STATE_SET, defaultColor), colorPrimary,
                            defaultColor });
        }/* www. j a  v  a 2  s .  com*/
    }

    if (mIconTintList == null) {
        // Defaults
        boolean isLightTheme = mDefaultTheme == SublimeThemer.DefaultTheme.LIGHT;

        int defDisabled = isLightTheme
                ? mContext.getResources().getColor(R.color.snv_primary_text_disabled_material_light)
                : mContext.getResources().getColor(R.color.snv_primary_text_disabled_material_dark);
        int defChecked = isLightTheme ? mContext.getResources().getColor(R.color.snv_primary_material_light)
                : mContext.getResources().getColor(R.color.snv_primary_material_dark);
        int defEmptySet = isLightTheme
                ? mContext.getResources().getColor(R.color.snv_primary_text_default_material_light)
                : mContext.getResources().getColor(R.color.snv_primary_text_default_material_dark);
        mIconTintList = new ColorStateList(
                new int[][] { DISABLED_STATE_SET, CHECKED_STATE_SET, EMPTY_STATE_SET },
                new int[] { defDisabled, defChecked, defEmptySet });
    }
}

From source file:com.appeaser.sublimenavigationviewlibrary.SublimeThemer.java

private void setDefaultCheckableItemTintList() {
    TypedValue value = new TypedValue();
    if (mContext.getTheme().resolveAttribute(android.R.attr.textColorPrimary, value, true)) {
        ColorStateList baseColor = mContext.getResources().getColorStateList(value.resourceId);
        if (mContext.getTheme().resolveAttribute(R.attr.colorPrimary, value, true)) {
            int colorPrimary = value.data;
            int defaultColor = baseColor.getDefaultColor();
            mCheckableItemTintList = new ColorStateList(
                    new int[][] { DISABLED_STATE_SET, CHECKABLE_ITEM_CHECKED_STATE_SET, EMPTY_STATE_SET },
                    new int[] { baseColor.getColorForState(DISABLED_STATE_SET, defaultColor), colorPrimary,
                            defaultColor });
        }/*from w  w w .  j  a va 2  s  .  c  o m*/
    }

    if (mCheckableItemTintList == null) {
        // Defaults
        boolean isLightTheme = mDefaultTheme == SublimeThemer.DefaultTheme.LIGHT;

        int defDisabled = isLightTheme
                ? mContext.getResources().getColor(R.color.snv_primary_text_disabled_material_light)
                : mContext.getResources().getColor(R.color.snv_primary_text_disabled_material_dark);
        int defChecked = isLightTheme ? mContext.getResources().getColor(R.color.snv_primary_material_light)
                : mContext.getResources().getColor(R.color.snv_primary_material_dark);
        int defEmptySet = isLightTheme
                ? mContext.getResources().getColor(R.color.snv_primary_text_default_material_light)
                : mContext.getResources().getColor(R.color.snv_primary_text_default_material_dark);
        mCheckableItemTintList = new ColorStateList(
                new int[][] { DISABLED_STATE_SET, CHECKABLE_ITEM_CHECKED_STATE_SET, EMPTY_STATE_SET },
                new int[] { defDisabled, defChecked, defEmptySet });
    }
}

From source file:com.yy.androidlib.widget.tab.PagerSlidingTabStrip.java

public void setTextColorResource(int resId) {
    ColorStateList colorStateList = getResources().getColorStateList(resId);
    this.tabTextColor = colorStateList.getDefaultColor();
    this.tabTextCheckedColor = colorStateList.getColorForState(new int[] { android.R.attr.state_checked },
            tabTextColor);//from w  w  w . ja  v  a 2s  .  co m
    updateTabStyles();
}

From source file:com.example.administrator.smartbj.Drawer.MyNavigationView.java

private ColorStateList createDefaultColorStateList(int baseColorThemeAttr) {
    TypedValue value = new TypedValue();
    if (!getContext().getTheme().resolveAttribute(baseColorThemeAttr, value, true)) {
        return null;
    }/*w  w  w  . ja  v  a 2s .c o  m*/
    ColorStateList baseColor = getResources().getColorStateList(value.resourceId);
    if (!getContext().getTheme().resolveAttribute(android.support.design.R.attr.colorPrimary, value, true)) {
        return null;
    }
    int colorPrimary = value.data;
    int defaultColor = baseColor.getDefaultColor();
    return new ColorStateList(new int[][] { DISABLED_STATE_SET, CHECKED_STATE_SET, EMPTY_STATE_SET },
            new int[] { baseColor.getColorForState(DISABLED_STATE_SET, defaultColor), colorPrimary,
                    defaultColor });
}