List of usage examples for android.content.res ColorStateList ColorStateList
public ColorStateList(int[][] states, @ColorInt int[] colors)
From source file:com.max.library.view.v7.AppCompatDrawableManager.java
private ColorStateList createCheckableButtonColorStateList(Context context) { final int[][] states = new int[3][]; final int[] colors = new int[3]; int i = 0;/*from ww w .ja v a 2 s . c o m*/ // Disabled state states[i] = ThemeUtils.DISABLED_STATE_SET; colors[i] = getDisabledThemeAttrColor(context, R.attr.colorControlNormal); 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.colorControlNormal); i++; return new ColorStateList(states, colors); }
From source file:com.kindleren.kandouwo.common.views.PagerSlidingTabStrip.java
public void setTextColor(int textColor) { //TODO test if it is right? this.tabTextColor = new ColorStateList(new int[][] { View.EMPTY_STATE_SET }, new int[] { textColor }); updateTabStyles();/*from www.jav a 2 s . c om*/ }
From source file:android.support.v7.internal.widget.TintManager.java
private ColorStateList createSpinnerColorStateList() { final int[][] states = new int[3][]; final int[] colors = new int[3]; int i = 0;// ww w. ja v a2s . c o m // Disabled state states[i] = new int[] { -android.R.attr.state_enabled }; colors[i] = getDisabledThemeAttrColor(mContext, R.attr.colorControlNormal); i++; states[i] = new int[] { -android.R.attr.state_pressed, -android.R.attr.state_focused }; colors[i] = getThemeAttrColor(mContext, R.attr.colorControlNormal); i++; states[i] = new int[0]; colors[i] = getThemeAttrColor(mContext, R.attr.colorControlActivated); i++; return new ColorStateList(states, colors); }
From source file:com.winneredge.stockly.wcommons.floatingactionwidget.FloatingActionButton.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private Drawable createFillDrawable() { StateListDrawable drawable = new StateListDrawable(); drawable.addState(new int[] { -android.R.attr.state_enabled }, createCircleDrawable(mColorDisabled)); drawable.addState(new int[] { android.R.attr.state_pressed }, createCircleDrawable(mColorPressed)); drawable.addState(new int[] {}, createCircleDrawable(mColorNormal)); if (Util.hasLollipop()) { RippleDrawable ripple = new RippleDrawable( new ColorStateList(new int[][] { {} }, new int[] { mColorRipple }), drawable, null); setOutlineProvider(new ViewOutlineProvider() { @Override//from w w w .j ava 2s . co m public void getOutline(View view, Outline outline) { outline.setOval(0, 0, view.getWidth(), view.getHeight()); } }); setClipToOutline(true); mBackgroundDrawable = ripple; return ripple; } mBackgroundDrawable = drawable; return drawable; }
From source file:com.max.library.view.v7.AppCompatDrawableManager.java
private ColorStateList createSwitchTrackColorStateList(Context context) { final int[][] states = new int[3][]; final int[] colors = new int[3]; int i = 0;//from www .jav a2 s . c o m // Disabled state states[i] = ThemeUtils.DISABLED_STATE_SET; colors[i] = getThemeAttrColor(context, android.R.attr.colorForeground, 0.1f); i++; states[i] = ThemeUtils.CHECKED_STATE_SET; colors[i] = getThemeAttrColor(context, R.attr.colorControlActivated, 0.3f); i++; // Default enabled state states[i] = ThemeUtils.EMPTY_STATE_SET; colors[i] = getThemeAttrColor(context, android.R.attr.colorForeground, 0.3f); i++; return new ColorStateList(states, colors); }
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; }//ww w . j a v a 2 s. c om 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.example.michaelg.myapplication.Item.discreteseekbar.DiscreteSeekBar.java
/** * Sets the color of the seekbar ripple/*from w w w . j ava 2 s . c om*/ * * @param color The color the track ripple will be changed to */ public void setRippleColor(int color) { setRippleColor(new ColorStateList(new int[][] { new int[] {} }, new int[] { color })); }
From source file:com.github.shareme.gwsmaterialuikit.library.material.widget.EditText.java
@Override protected void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super.applyStyle(context, attrs, defStyleAttr, defStyleRes); CharSequence text = mInputView == null ? null : mInputView.getText(); removeAllViews();//from w w w . ja v a2 s .com TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.EditText, defStyleAttr, defStyleRes); int labelPadding = -1; int labelTextSize = -1; ColorStateList labelTextColor = null; int supportPadding = -1; int supportTextSize = -1; ColorStateList supportColors = null; ColorStateList supportErrorColors = null; String supportHelper = null; String supportError = null; ColorStateList dividerColors = null; ColorStateList dividerErrorColors = null; int dividerHeight = -1; int dividerPadding = -1; int dividerAnimDuration = -1; mAutoCompleteMode = a.getInteger(R.styleable.EditText_et_autoCompleteMode, mAutoCompleteMode); if (needCreateInputView(mAutoCompleteMode)) { switch (mAutoCompleteMode) { case AUTOCOMPLETE_MODE_SINGLE: mInputView = new InternalAutoCompleteTextView(context, attrs, defStyleAttr); break; case AUTOCOMPLETE_MODE_MULTI: mInputView = new InternalMultiAutoCompleteTextView(context, attrs, defStyleAttr); break; default: mInputView = new InternalEditText(context, attrs, defStyleAttr); break; } ViewUtil.applyFont(mInputView, attrs, defStyleAttr, defStyleRes); if (text != null) mInputView.setText(text); mInputView.addTextChangedListener(new InputTextWatcher()); if (mDivider != null) { mDivider.setAnimEnable(false); ViewUtil.setBackground(mInputView, mDivider); mDivider.setAnimEnable(true); } } else ViewUtil.applyStyle(mInputView, attrs, defStyleAttr, defStyleRes); mInputView.setVisibility(View.VISIBLE); mInputView.setFocusableInTouchMode(true); for (int i = 0, count = a.getIndexCount(); i < count; i++) { int attr = a.getIndex(i); if (attr == R.styleable.EditText_et_labelEnable) mLabelEnable = a.getBoolean(attr, false); else if (attr == R.styleable.EditText_et_labelPadding) labelPadding = a.getDimensionPixelSize(attr, 0); else if (attr == R.styleable.EditText_et_labelTextSize) labelTextSize = a.getDimensionPixelSize(attr, 0); else if (attr == R.styleable.EditText_et_labelTextColor) labelTextColor = a.getColorStateList(attr); else if (attr == R.styleable.EditText_et_labelTextAppearance) getLabelView().setTextAppearance(context, a.getResourceId(attr, 0)); else if (attr == R.styleable.EditText_et_labelEllipsize) { int labelEllipsize = a.getInteger(attr, 0); switch (labelEllipsize) { case 1: getLabelView().setEllipsize(TruncateAt.START); break; case 2: getLabelView().setEllipsize(TruncateAt.MIDDLE); break; case 3: getLabelView().setEllipsize(TruncateAt.END); break; case 4: getLabelView().setEllipsize(TruncateAt.MARQUEE); break; default: getLabelView().setEllipsize(TruncateAt.END); break; } } else if (attr == R.styleable.EditText_et_labelInAnim) mLabelInAnimId = a.getResourceId(attr, 0); else if (attr == R.styleable.EditText_et_labelOutAnim) mLabelOutAnimId = a.getResourceId(attr, 0); else if (attr == R.styleable.EditText_et_supportMode) mSupportMode = a.getInteger(attr, 0); else if (attr == R.styleable.EditText_et_supportPadding) supportPadding = a.getDimensionPixelSize(attr, 0); else if (attr == R.styleable.EditText_et_supportTextSize) supportTextSize = a.getDimensionPixelSize(attr, 0); else if (attr == R.styleable.EditText_et_supportTextColor) supportColors = a.getColorStateList(attr); else if (attr == R.styleable.EditText_et_supportTextErrorColor) supportErrorColors = a.getColorStateList(attr); else if (attr == R.styleable.EditText_et_supportTextAppearance) getSupportView().setTextAppearance(context, a.getResourceId(attr, 0)); else if (attr == R.styleable.EditText_et_supportEllipsize) { int supportEllipsize = a.getInteger(attr, 0); switch (supportEllipsize) { case 1: getSupportView().setEllipsize(TruncateAt.START); break; case 2: getSupportView().setEllipsize(TruncateAt.MIDDLE); break; case 3: getSupportView().setEllipsize(TruncateAt.END); break; case 4: getSupportView().setEllipsize(TruncateAt.MARQUEE); break; default: getSupportView().setEllipsize(TruncateAt.END); break; } } else if (attr == R.styleable.EditText_et_supportMaxLines) getSupportView().setMaxLines(a.getInteger(attr, 0)); else if (attr == R.styleable.EditText_et_supportLines) getSupportView().setLines(a.getInteger(attr, 0)); else if (attr == R.styleable.EditText_et_supportSingleLine) getSupportView().setSingleLine(a.getBoolean(attr, false)); else if (attr == R.styleable.EditText_et_supportMaxChars) mSupportMaxChars = a.getInteger(attr, 0); else if (attr == R.styleable.EditText_et_helper) supportHelper = a.getString(attr); else if (attr == R.styleable.EditText_et_error) supportError = a.getString(attr); else if (attr == R.styleable.EditText_et_inputId) mInputView.setId(a.getResourceId(attr, 0)); else if (attr == R.styleable.EditText_et_dividerColor) dividerColors = a.getColorStateList(attr); else if (attr == R.styleable.EditText_et_dividerErrorColor) dividerErrorColors = a.getColorStateList(attr); else if (attr == R.styleable.EditText_et_dividerHeight) dividerHeight = a.getDimensionPixelSize(attr, 0); else if (attr == R.styleable.EditText_et_dividerPadding) dividerPadding = a.getDimensionPixelSize(attr, 0); else if (attr == R.styleable.EditText_et_dividerAnimDuration) dividerAnimDuration = a.getInteger(attr, 0); else if (attr == R.styleable.EditText_et_dividerCompoundPadding) mDividerCompoundPadding = a.getBoolean(attr, true); } a.recycle(); if (mInputView.getId() == 0) mInputView.setId(ViewUtil.generateViewId()); if (mDivider == null) { mDividerColors = dividerColors; mDividerErrorColors = dividerErrorColors; if (mDividerColors == null) { int[][] states = new int[][] { new int[] { -android.R.attr.state_focused }, new int[] { android.R.attr.state_focused, android.R.attr.state_enabled }, }; int[] colors = new int[] { ThemeUtil.colorControlNormal(context, 0xFF000000), ThemeUtil.colorControlActivated(context, 0xFF000000), }; mDividerColors = new ColorStateList(states, colors); } if (mDividerErrorColors == null) mDividerErrorColors = ColorStateList.valueOf(ThemeUtil.colorAccent(context, 0xFFFF0000)); if (dividerHeight < 0) dividerHeight = 0; if (dividerPadding < 0) dividerPadding = 0; if (dividerAnimDuration < 0) dividerAnimDuration = context.getResources().getInteger(android.R.integer.config_shortAnimTime); mDividerPadding = dividerPadding; mInputView.setPadding(0, 0, 0, mDividerPadding + dividerHeight); mDivider = new DividerDrawable(dividerHeight, mDividerCompoundPadding ? mInputView.getTotalPaddingLeft() : 0, mDividerCompoundPadding ? mInputView.getTotalPaddingRight() : 0, mDividerColors, dividerAnimDuration); mDivider.setInEditMode(isInEditMode()); mDivider.setAnimEnable(false); ViewUtil.setBackground(mInputView, mDivider); mDivider.setAnimEnable(true); } else { if (dividerHeight >= 0 || dividerPadding >= 0) { if (dividerHeight < 0) dividerHeight = mDivider.getDividerHeight(); if (dividerPadding >= 0) mDividerPadding = dividerPadding; mInputView.setPadding(0, 0, 0, mDividerPadding + dividerHeight); mDivider.setDividerHeight(dividerHeight); mDivider.setPadding(mDividerCompoundPadding ? mInputView.getTotalPaddingLeft() : 0, mDividerCompoundPadding ? mInputView.getTotalPaddingRight() : 0); } if (dividerColors != null) mDividerColors = dividerColors; if (dividerErrorColors != null) mDividerErrorColors = dividerErrorColors; mDivider.setColor(getError() == null ? mDividerColors : mDividerErrorColors); if (dividerAnimDuration >= 0) mDivider.setAnimationDuration(dividerAnimDuration); } if (labelPadding >= 0) getLabelView().setPadding(mDivider.getPaddingLeft(), 0, mDivider.getPaddingRight(), labelPadding); if (labelTextSize >= 0) getLabelView().setTextSize(TypedValue.COMPLEX_UNIT_PX, labelTextSize); if (labelTextColor != null) getLabelView().setTextColor(labelTextColor); if (mLabelEnable) { mLabelVisible = true; getLabelView().setText(mInputView.getHint()); addView(getLabelView(), 0, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); setLabelVisible(!TextUtils.isEmpty(mInputView.getText().toString()), false); } if (supportTextSize >= 0) getSupportView().setTextSize(TypedValue.COMPLEX_UNIT_PX, supportTextSize); if (supportColors != null) mSupportColors = supportColors; else if (mSupportColors == null) mSupportColors = context.getResources().getColorStateList(R.color.abc_secondary_text_material_light); if (supportErrorColors != null) mSupportErrorColors = supportErrorColors; else if (mSupportErrorColors == null) mSupportErrorColors = ColorStateList.valueOf(ThemeUtil.colorAccent(context, 0xFFFF0000)); if (supportPadding >= 0) getSupportView().setPadding(mDivider.getPaddingLeft(), supportPadding, mDivider.getPaddingRight(), 0); if (supportHelper == null && supportError == null) getSupportView().setTextColor(getError() == null ? mSupportColors : mSupportErrorColors); else if (supportHelper != null) setHelper(supportHelper); else setError(supportError); if (mSupportMode != SUPPORT_MODE_NONE) { switch (mSupportMode) { case SUPPORT_MODE_CHAR_COUNTER: getSupportView().setGravity(Gravity.END); updateCharCounter(mInputView.getText().length()); break; case SUPPORT_MODE_HELPER: case SUPPORT_MODE_HELPER_WITH_ERROR: getSupportView().setGravity(GravityCompat.START); break; } addView(getSupportView(), new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); } addView(mInputView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); requestLayout(); }
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 w w. j ava 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); }
From source file:com.max.library.view.v7.AppCompatDrawableManager.java
private ColorStateList createEditTextColorStateList(Context context) { final int[][] states = new int[3][]; final int[] colors = new int[3]; int i = 0;/* w w w. ja v a2s .c o m*/ // Disabled state states[i] = ThemeUtils.DISABLED_STATE_SET; colors[i] = getDisabledThemeAttrColor(context, R.attr.colorControlNormal); i++; states[i] = ThemeUtils.NOT_PRESSED_OR_FOCUSED_STATE_SET; colors[i] = getThemeAttrColor(context, R.attr.colorControlNormal); i++; // Default enabled state states[i] = ThemeUtils.EMPTY_STATE_SET; colors[i] = getThemeAttrColor(context, R.attr.colorControlActivated); i++; return new ColorStateList(states, colors); }