List of usage examples for android.content.res ColorStateList getDefaultColor
@ColorInt public int getDefaultColor()
From source file:com.android.launcher3.BubbleTextView.java
@Override public void setTextColor(ColorStateList colors) { mTextColor = colors.getDefaultColor(); super.setTextColor(colors); }
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; }/* w w w . j a v a 2s. 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:com.ruesga.rview.drawer.DrawerNavigationView.java
@SuppressWarnings("ConstantConditions") private ColorStateList createDefaultColorStateList(int baseColorThemeAttr) { final TypedValue value = new TypedValue(); if (!getContext().getTheme().resolveAttribute(baseColorThemeAttr, value, true)) { return null; }//from w w w.jav a 2 s . c o m if (value.resourceId == 0) { return null; } 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, SELECTED_STATE_SET, EMPTY_STATE_SET }, new int[] { baseColor.getColorForState(DISABLED_STATE_SET, defaultColor), colorPrimary, colorPrimary, defaultColor }); }
From source file:com.bilibili.magicasakura.utils.ThemeUtils.java
public static ColorStateList getThemeColorStateList(Context context, ColorStateList origin) { if (origin == null) return null; if (origin.isStateful()) { TintInfo tintInfo = parseColorStateList(origin); if (tintInfo == null || tintInfo.isInvalid()) { return origin; }//from ww w . ja va 2s. co m int[] newColors; int[][] newStates; int index = 0; boolean hasDisableColor = StateSet.stateSetMatches(tintInfo.mTintStates[0], DISABLED_STATE_SET); if (!hasDisableColor) { newStates = new int[tintInfo.mTintStates.length + 1][]; newColors = new int[tintInfo.mTintStates.length + 1]; newStates[index] = DISABLED_STATE_SET; newColors[index] = getDisabledThemeAttrColor(context, R.attr.themeColorSecondary); index++; } else { newStates = new int[tintInfo.mTintStates.length][]; newColors = new int[tintInfo.mTintStates.length]; } for (int i = 0; i < tintInfo.mTintStates.length; i++) { newStates[index] = tintInfo.mTintStates[i]; newColors[index] = replaceColor(context, tintInfo.mTintColors[i]); index++; } return new ColorStateList(newStates, newColors); } return ColorStateList.valueOf(replaceColor(context, origin.getDefaultColor())); }
From source file:com.appunite.list.FastScroller.java
private void init(Context context) { // Get both the scrollbar states drawables TypedArray ta = context.getTheme().obtainStyledAttributes(ATTRS); useThumbDrawable(context, ta.getDrawable(THUMB_DRAWABLE)); mTrackDrawable = ta.getDrawable(TRACK_DRAWABLE); mOverlayDrawableLeft = ta.getDrawable(PREVIEW_BACKGROUND_LEFT); mOverlayDrawableRight = ta.getDrawable(PREVIEW_BACKGROUND_RIGHT); mOverlayPosition = ta.getInt(OVERLAY_POSITION, OVERLAY_FLOATING); mScrollCompleted = true;/*from w ww . j a v a 2 s . co m*/ getSectionsFromIndexer(); mOverlaySize = context.getResources().getDimensionPixelSize(R.dimen.fastscroll_overlay_size); mOverlayPos = new RectF(); mScrollFade = new ScrollFade(); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setTextAlign(Paint.Align.CENTER); mPaint.setTextSize(mOverlaySize / 2); ColorStateList textColor = ta.getColorStateList(TEXT_COLOR); int textColorNormal = textColor.getDefaultColor(); mPaint.setColor(textColorNormal); mPaint.setStyle(Paint.Style.FILL_AND_STROKE); // to show mOverlayDrawable properly if (mList.getWidth() > 0 && mList.getHeight() > 0) { onSizeChanged(mList.getWidth(), mList.getHeight(), 0, 0); } mState = STATE_NONE; refreshDrawableState(); ta.recycle(); mScaledTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); mMatchDragPosition = context .getApplicationInfo().targetSdkVersion >= android.os.Build.VERSION_CODES.HONEYCOMB; setScrollbarPosition(Compat.getVerticalScrollbarPosition(mList)); }
From source file:com.common.widget.hzlib.FastScroller.java
private void init(Context context) { // Get both the scrollbar states drawables TypedArray ta = context.getTheme().obtainStyledAttributes(ATTRS); useThumbDrawable(context, ta.getDrawable(THUMB_DRAWABLE)); mTrackDrawable = ta.getDrawable(TRACK_DRAWABLE); mOverlayDrawableLeft = ta.getDrawable(PREVIEW_BACKGROUND_LEFT); mOverlayDrawableRight = ta.getDrawable(PREVIEW_BACKGROUND_RIGHT); mOverlayPosition = ta.getInt(OVERLAY_POSITION, OVERLAY_FLOATING); mScrollCompleted = true;// ww w . j a v a 2 s.c o m getSectionsFromIndexer(); mOverlaySize = context.getResources().getDimensionPixelSize(R.dimen.fastscroll_overlay_size); mOverlayPos = new RectF(); mScrollFade = new ScrollFade(); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setTextAlign(Paint.Align.CENTER); mPaint.setTextSize(mOverlaySize / 2); ColorStateList textColor = ta.getColorStateList(TEXT_COLOR); int textColorNormal = textColor.getDefaultColor(); mPaint.setColor(textColorNormal); mPaint.setStyle(Paint.Style.FILL_AND_STROKE); // to show mOverlayDrawable properly if (mList.getWidth() > 0 && mList.getHeight() > 0) { onSizeChanged(mList.getWidth(), mList.getHeight(), 0, 0); } mState = STATE_NONE; refreshDrawableState(); ta.recycle(); mScaledTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); mMatchDragPosition = context .getApplicationInfo().targetSdkVersion >= android.os.Build.VERSION_CODES.HONEYCOMB; setScrollbarPosition(mList.getVerticalScrollbarPosition()); }
From source file:com.gh4a.BaseActivity.java
private ColorStateList createDefaultNavigationColorStateList(int baseColorThemeAttr) { TypedValue value = new TypedValue(); if (!getTheme().resolveAttribute(baseColorThemeAttr, value, true)) { return null; }//from ww w.ja v a 2 s . c om ColorStateList baseColor = ContextCompat.getColorStateList(this, value.resourceId); if (!getTheme().resolveAttribute(android.support.design.R.attr.colorAccent, value, true)) { return null; } int colorAccent = value.data; int defaultColor = baseColor.getDefaultColor(); final int[] disabledStateSet = { -android.R.attr.state_enabled }; final int[] checkedStateSet = { android.R.attr.state_checked }; final int[][] states = { disabledStateSet, checkedStateSet, { 0 } }; final int[] colors = { baseColor.getColorForState(disabledStateSet, defaultColor), colorAccent, defaultColor }; return new ColorStateList(states, colors); }
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. j ava 2 s .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:android.support.v7.internal.widget.TintButton.java
public TintButton(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 a v a2 s . c om if (a.hasValue(0)) { setSupportBackgroundTintList(a.getTintManager().getColorStateList(a.getResourceId(0, -1))); } 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:android.support.v7.internal.widget.TintManager.java
private ColorStateList createSwitchThumbColorStateList() { final int[][] states = new int[3][]; final int[] colors = new int[3]; int i = 0;/*from w w w . j a v a 2s .c o m*/ final ColorStateList thumbColor = getThemeAttrColorStateList(mContext, 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] = new int[] { -android.R.attr.state_enabled }; colors[i] = thumbColor.getColorForState(states[i], 0); i++; states[i] = new int[] { android.R.attr.state_checked }; colors[i] = getThemeAttrColor(mContext, R.attr.colorControlActivated); i++; // Default enabled state states[i] = new int[0]; colors[i] = thumbColor.getDefaultColor(); i++; } else { // Else we'll use an approximation using the default disabled alpha // Disabled state states[i] = new int[] { -android.R.attr.state_enabled }; colors[i] = getDisabledThemeAttrColor(mContext, R.attr.colorSwitchThumbNormal); i++; states[i] = new int[] { android.R.attr.state_checked }; colors[i] = getThemeAttrColor(mContext, R.attr.colorControlActivated); i++; // Default enabled state states[i] = new int[0]; colors[i] = getThemeAttrColor(mContext, R.attr.colorSwitchThumbNormal); i++; } return new ColorStateList(states, colors); }