List of usage examples for android.content.res ColorStateList getColorForState
public int getColorForState(@Nullable int[] stateSet, int defaultColor)
From source file:com.tr4android.support.extension.picker.date.SimpleMonthView.java
void setDayHighlightColor(ColorStateList dayHighlightColor) { final int pressedColor = dayHighlightColor .getColorForState(new int[] { android.R.attr.state_enabled, android.R.attr.state_pressed }, 0); mDayHighlightPaint.setColor(pressedColor); invalidate();//from w ww . j a v a 2 s . c o m }
From source file:com.tr4android.support.extension.picker.date.SimpleMonthView.java
void setDaySelectorColor(ColorStateList dayBackgroundColor) { final int selectedColor = dayBackgroundColor .getColorForState(new int[] { android.R.attr.state_enabled, android.R.attr.state_selected }, 0); mDaySelectorPaint.setColor(selectedColor); invalidate();/* w w w. j a v a2s. c o m*/ }
From source file:android.support.design.widget.BottomNavigationView.java
private ColorStateList createDefaultColorStateList(int baseColorThemeAttr) { final TypedValue value = new TypedValue(); if (!getContext().getTheme().resolveAttribute(baseColorThemeAttr, value, true)) { return null; }/*from w w w . j av a2s. c o m*/ ColorStateList baseColor = AppCompatResources.getColorStateList(getContext(), value.resourceId); if (!getContext().getTheme().resolveAttribute(android.support.v7.appcompat.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 }); }
From source file:opt.android.datetimepicker.date.MonthView.java
public MonthView(Context context, AttributeSet attr) { super(context, attr); Resources res = context.getResources(); mDayLabelCalendar = Calendar.getInstance(); mCalendar = Calendar.getInstance(); mDayOfWeekTypeface = res.getString(R.string.day_of_week_label_typeface); mMonthTitleTypeface = res.getString(R.string.sans_serif); mDayTextColor = res.getColor(R.color.opt_dtpicker_date_picker_text_normal); mTodayNumberColor = res.getColor(R.color.opt_dtpicker_blue); mDisabledDayTextColor = res.getColor(R.color.opt_dtpicker_date_picker_text_disabled); mMonthTitleColor = res.getColor(R.color.opt_dtpicker_white); // mMonthTitleBGColor = res.getColor(R.color.circle_background); // kman/*from w w w .ja v a 2s. c om*/ final TypedArray a = context.obtainStyledAttributes(Utils.COLOR_ATTRS); final ColorStateList colorPrimary = a.getColorStateList(0); final ColorStateList colorSecondary = a.getColorStateList(1); a.recycle(); mMonthTitleColor = colorPrimary.getColorForState(ENABLED_STATE_SET, colorPrimary.getDefaultColor()); mDayTextColor = colorSecondary.getColorForState(ENABLED_STATE_SET, colorSecondary.getDefaultColor()); mDisabledDayTextColor = colorSecondary.getColorForState(Utils.DISABLED_STATE_SET, mDayTextColor); final boolean isDarkTheme = Utils.isThemeDark(mMonthTitleColor); if (isDarkTheme) { mTodayNumberColor = res.getColor(R.color.opt_dtpicker_blue_dark); } // kman end mStringBuilder = new StringBuilder(50); mFormatter = new Formatter(mStringBuilder, Locale.getDefault()); MINI_DAY_NUMBER_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.opt_dtpicker_day_number_size); MONTH_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.opt_dtpicker_month_label_size); MONTH_DAY_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.opt_dtpicker_month_day_label_text_size); MONTH_HEADER_SIZE = res.getDimensionPixelOffset(R.dimen.opt_dtpicker_month_list_item_header_height); DAY_SELECTED_CIRCLE_SIZE = res.getDimensionPixelSize(R.dimen.opt_dtpicker_day_number_select_circle_radius); mRowHeight = (res.getDimensionPixelOffset(R.dimen.opt_dtpicker_date_picker_view_animator_height) - getMonthHeaderSize()) / MAX_NUM_ROWS; // Set up accessibility components. mTouchHelper = getMonthViewTouchHelper(); ViewCompat.setAccessibilityDelegate(this, mTouchHelper); ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); mLockAccessibilityDelegate = true; // Sets up any standard paints that will be used initView(); }
From source file:com.tr4android.support.extension.picker.date.SimpleMonthView.java
/** * Applies the specified text appearance resource to a paint, returning the * text color if one is set in the text appearance. * * @param p the paint to modify//from ww w .j a v a 2 s. c o m * @param resId the resource ID of the text appearance * @return the text color, if available */ private ColorStateList applyTextAppearance(Paint p, int resId) { final TypedArray ta = getContext().obtainStyledAttributes(null, R.styleable.TextAppearance, 0, resId); final String fontFamily = ta.getString(R.styleable.TextAppearance_android_fontFamily); if (fontFamily != null) { p.setTypeface(Typeface.create(fontFamily, 0)); } p.setTextSize(ta.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize, (int) p.getTextSize())); final ColorStateList textColor = ta.getColorStateList(R.styleable.TextAppearance_android_textColor); if (textColor != null) { final int enabledColor = textColor.getColorForState(ENABLED_STATE_SET, 0); p.setColor(enabledColor); } ta.recycle(); return textColor; }
From source file:com.nihaskalam.progressbuttonlibrary.CircularProgressButton.java
private int getNormalColor(ColorStateList colorStateList) { return colorStateList.getColorForState(new int[] { android.R.attr.state_enabled }, 0); }
From source file:com.nihaskalam.progressbuttonlibrary.CircularProgressButton.java
private int getPressedColor(ColorStateList colorStateList) { return colorStateList.getColorForState(new int[] { android.R.attr.state_pressed }, 0); }
From source file:com.nihaskalam.progressbuttonlibrary.CircularProgressButton.java
private int getFocusedColor(ColorStateList colorStateList) { return colorStateList.getColorForState(new int[] { android.R.attr.state_focused }, 0); }
From source file:com.nihaskalam.progressbuttonlibrary.CircularProgressButton.java
private int getDisabledColor(ColorStateList colorStateList) { return colorStateList.getColorForState(new int[] { -android.R.attr.state_enabled }, 0); }
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 w ww .ja v a 2 s . c o m 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); }