List of usage examples for android.content.res ColorStateList ColorStateList
public ColorStateList(int[][] states, @ColorInt int[] colors)
From source file:android.support.design.widget.FloatingActionButtonEclairMr1.java
private static ColorStateList createColorStateList(int selectedColor) { final int[][] states = new int[3][]; final int[] colors = new int[3]; int i = 0;/*from w w w . j a va 2 s.c om*/ states[i] = FOCUSED_ENABLED_STATE_SET; colors[i] = selectedColor; i++; states[i] = PRESSED_ENABLED_STATE_SET; colors[i] = selectedColor; i++; // Default enabled state states[i] = new int[0]; colors[i] = Color.TRANSPARENT; i++; return new ColorStateList(states, colors); }
From source file:com.acious.android.paginationseekbar.PaginationSeekBar.java
public PaginationSeekBar(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFocusable(true);//www . j a v a2 s .c o m setWillNotDraw(false); mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); float density = context.getResources().getDisplayMetrics().density; mTrackHeight = (int) (1 * density); mScrubberHeight = (int) (4 * density); int thumbSize = (int) (density * ThumbDrawable.DEFAULT_SIZE_DP); //Extra pixels for a touch area of 48dp int touchBounds = (int) (density * 32); mAddedTouchBounds = (touchBounds - thumbSize) / 2; TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PaginationSeekBar, R.attr.paginationSeekBarStyle, defStyle); int max = 100; int min = 0; int value = 1; mMirrorForRtl = a.getBoolean(R.styleable.PaginationSeekBar_psb_mirrorForRtl, mMirrorForRtl); mAllowTrackClick = a.getBoolean(R.styleable.PaginationSeekBar_psb_allowTrackClickToDrag, mAllowTrackClick); int indexMax = R.styleable.PaginationSeekBar_psb_max; int indexMin = R.styleable.PaginationSeekBar_psb_min; int indexValue = R.styleable.PaginationSeekBar_psb_value; pageCountPerOneBoard = R.styleable.PaginationSeekBar_psb_pageCountPerOneBoard; final TypedValue out = new TypedValue(); //Not sure why, but we wanted to be able to use dimensions here... if (a.getValue(indexMax, out)) { if (out.type == TypedValue.TYPE_DIMENSION) { max = a.getDimensionPixelSize(indexMax, max); } else { max = a.getInteger(indexMax, max); } } if (a.getValue(indexMin, out)) { if (out.type == TypedValue.TYPE_DIMENSION) { min = a.getDimensionPixelSize(indexMin, min); } else { min = a.getInteger(indexMin, min); } } if (a.getValue(indexValue, out)) { if (out.type == TypedValue.TYPE_DIMENSION) { value = a.getDimensionPixelSize(indexValue, value); } else { value = a.getInteger(indexValue, value); } } if (a.getValue(pageCountPerOneBoard, out)) { pageCountPerOneBoard = a.getInteger(pageCountPerOneBoard, pageCountPerOneBoard); } mMin = min; mMax = Math.max(min + 1, max); mValue = Math.max(min, Math.min(max, value)); updateKeyboardRange(); mPrevPageText = a.getString(R.styleable.PaginationSeekBar_psb_indicatorPrevPageText); mNextPageText = a.getString(R.styleable.PaginationSeekBar_psb_indicatorNextPageText); mIndicatorFormatter = a.getString(R.styleable.PaginationSeekBar_psb_indicatorFormatter); ColorStateList trackColor = a.getColorStateList(R.styleable.PaginationSeekBar_psb_trackColor); ColorStateList progressColor = a.getColorStateList(R.styleable.PaginationSeekBar_psb_progressColor); ColorStateList rippleColor = a.getColorStateList(R.styleable.PaginationSeekBar_psb_rippleColor); int thumbTextColor = a.getColor(R.styleable.PaginationSeekBar_psb_thumbTextColor, Color.WHITE); boolean editMode = isInEditMode(); if (editMode && rippleColor == null) { rippleColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.DKGRAY }); } if (editMode && trackColor == null) { trackColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.GRAY }); } if (editMode && progressColor == null) { progressColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { 0xff009688 }); } if (editMode && thumbTextColor == 0) { thumbTextColor = Color.WHITE; } mRipple = SeekBarCompat.getRipple(rippleColor); if (isLollipopOrGreater) { SeekBarCompat.setBackground(this, mRipple); } else { mRipple.setCallback(this); } TrackRectDrawable shapeDrawable = new TrackRectDrawable(trackColor); mTrack = shapeDrawable; mTrack.setCallback(this); shapeDrawable = new TrackRectDrawable(progressColor); mScrubber = shapeDrawable; mScrubber.setCallback(this); ThumbDrawable thumbDrawable = new ThumbDrawable(progressColor, thumbTextColor, thumbSize, mValue); mThumb = thumbDrawable; mThumb.setCallback(this); mThumb.setBounds(0, 0, mThumb.getIntrinsicWidth(), mThumb.getIntrinsicHeight()); if (!editMode) { mIndicator = new PopupIndicator(context, attrs, defStyle, convertValueToMessage(mMax), mPrevPageText, mNextPageText); mIndicator.setListener(mFloaterListener); } a.recycle(); setNumericTransformer(new DefaultNumericTransformer()); initPagecountPerOneboard(pageCountPerOneBoard); }
From source file:tk.wasdennnoch.androidn_ify.utils.NotificationColorUtil.java
private TextAppearanceSpan processTextAppearanceSpan(TextAppearanceSpan span) { ColorStateList colorStateList = span.getTextColor(); if (colorStateList != null) { int[] colors = (int[]) XposedHelpers.callMethod(colorStateList, "getColors"); boolean changed = false; for (int i = 0; i < colors.length; i++) { if (ImageUtils.isGrayscale(colors[i])) { // Allocate a new array so we don't change the colors in the old color state // list. if (!changed) { colors = Arrays.copyOf(colors, colors.length); }/*from w ww . ja v a2s.c o m*/ colors[i] = processColor(colors[i]); changed = true; } } if (changed) { return new TextAppearanceSpan(span.getFamily(), span.getTextStyle(), span.getTextSize(), new ColorStateList((int[][]) XposedHelpers.callMethod(colorStateList, "getStates"), colors), span.getLinkTextColor()); } } return span; }
From source file:com.vnidens.clickableedittext.ClickableEditTextHelper.java
@Override public void setEndButtonTint(@ColorInt int color) { endButtonTintList = new ColorStateList(new int[][] { STATE_DEFAULT }, new int[] { color }); updateDrawableTintList(endButtonDrawable, endButtonTintList); }
From source file:com.orca.coleherrmann.samplematerial.SlidingTabLayout.java
private void populateTabStrip() { final PagerAdapter adapter = mViewPager.getAdapter(); final View.OnClickListener tabClickListener = new TabClickListener(); for (int i = 0; i < adapter.getCount(); i++) { View tabView = null;/*w w w.java2 s. co m*/ TextView tabTitleView = null; if (mTabViewLayoutId != 0) { // If there is a custom tab view layout id set, try and inflate it tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false); tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId); } if (tabView == null) { tabView = createDefaultTabView(getContext()); } if (tabTitleView == null && TextView.class.isInstance(tabView)) { tabTitleView = (TextView) tabView; } if (mDistributeEvenly) { LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams(); lp.width = 0; lp.weight = 1; } tabTitleView.setText(adapter.getPageTitle(i)); tabView.setOnClickListener(tabClickListener); String desc = mContentDescriptions.get(i, null); if (desc != null) { tabView.setContentDescription(desc); } mTabStrip.addView(tabView); if (i == mViewPager.getCurrentItem()) { tabView.setSelected(true); } int[][] states = new int[][] { new int[] { android.R.attr.state_selected }, new int[] { android.R.attr.state_focused }, new int[] { android.R.attr.state_pressed }, new int[] { -android.R.attr.state_selected }, new int[] { -android.R.attr.state_focused }, new int[] { -android.R.attr.state_pressed } }; int[] colors = new int[] { Color.parseColor("#0083E5"), Color.parseColor("#0083E5"), Color.parseColor("#0083E5"), Color.WHITE, Color.WHITE, Color.WHITE }; ColorStateList myList = new ColorStateList(states, colors); tabTitleView.setTextColor(myList); tabTitleView.setTextSize(14); } }
From source file:com.owncloud.android.utils.ThemeUtils.java
public static void tintSwitch(SwitchCompat switchView, int color, boolean colorText) { if (colorText) { switchView.setTextColor(color);/*from ww w. j a va2 s .c o m*/ } 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") })); }
From source file:com.tr4android.support.extension.widget.LabelView.java
private static ColorStateList createColorStateList(int rippleColor, int backgroundColor) { final int compositeColor = ColorUtils.compositeColors(rippleColor, backgroundColor); return new ColorStateList(new int[][] { // states new int[] { android.R.attr.state_focused }, new int[] { android.R.attr.state_pressed }, new int[] {} // state_default }, new int[] { // colors compositeColor, compositeColor, backgroundColor }); }
From source file:com.stfalcon.chatkit.messages.MessagesListStyle.java
Drawable getMessageSelector(@ColorInt int normalColor, @ColorInt int selectedColor, @ColorInt int pressedColor, @DrawableRes int shape) { Drawable button = DrawableCompat.wrap(getVectorDrawable(shape)); DrawableCompat//ww w .ja va2 s . co m .setTintList(button, new ColorStateList( new int[][] { new int[] { android.R.attr.state_selected }, new int[] { android.R.attr.state_pressed }, new int[] { -android.R.attr.state_pressed, -android.R.attr.state_selected } }, new int[] { selectedColor, pressedColor, normalColor })); return button; }
From source file:com.doomy.library.DiscreteSeekBar.java
public DiscreteSeekBar(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFocusable(true);/*from w ww . j a v a 2 s . c o m*/ setWillNotDraw(false); mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); float density = context.getResources().getDisplayMetrics().density; mTrackHeight = (int) (1 * density); mScrubberHeight = (int) (4 * density); int thumbSize = (int) (density * ThumbDrawable.DEFAULT_SIZE_DP); //Extra pixels for a touch area of 48dp int touchBounds = (int) (density * 32); mAddedTouchBounds = (touchBounds - thumbSize) / 2; TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DiscreteSeekBar, R.attr.discreteSeekBarStyle, defStyle); int max = 100; int min = 0; int value = 0; mMirrorForRtl = a.getBoolean(R.styleable.DiscreteSeekBar_dsb_mirrorForRtl, mMirrorForRtl); mAllowTrackClick = a.getBoolean(R.styleable.DiscreteSeekBar_dsb_allowTrackClickToDrag, mAllowTrackClick); int indexMax = R.styleable.DiscreteSeekBar_dsb_max; int indexMin = R.styleable.DiscreteSeekBar_dsb_min; int indexValue = R.styleable.DiscreteSeekBar_dsb_value; final TypedValue out = new TypedValue(); //Not sure why, but we wanted to be able to use dimensions here... if (a.getValue(indexMax, out)) { if (out.type == TypedValue.TYPE_DIMENSION) { max = a.getDimensionPixelSize(indexMax, max); } else { max = a.getInteger(indexMax, max); } } if (a.getValue(indexMin, out)) { if (out.type == TypedValue.TYPE_DIMENSION) { min = a.getDimensionPixelSize(indexMin, min); } else { min = a.getInteger(indexMin, min); } } if (a.getValue(indexValue, out)) { if (out.type == TypedValue.TYPE_DIMENSION) { value = a.getDimensionPixelSize(indexValue, value); } else { value = a.getInteger(indexValue, value); } } mMin = min; mMax = Math.max(min + 1, max); mValue = Math.max(min, Math.min(max, value)); updateKeyboardRange(); mIndicatorFormatter = a.getString(R.styleable.DiscreteSeekBar_dsb_indicatorFormatter); ColorStateList trackColor = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_trackColor); ColorStateList progressColor = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_progressColor); ColorStateList rippleColor = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_rippleColor); boolean editMode = isInEditMode(); if (editMode && rippleColor == null) { rippleColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.DKGRAY }); } if (editMode && trackColor == null) { trackColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.GRAY }); } if (editMode && progressColor == null) { progressColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { 0xff009688 }); } mRipple = SeekBarCompat.getRipple(rippleColor); if (isLollipopOrGreater) { SeekBarCompat.setBackground(this, mRipple); } else { mRipple.setCallback(this); } TrackRectDrawable shapeDrawable = new TrackRectDrawable(trackColor); mTrack = shapeDrawable; mTrack.setCallback(this); shapeDrawable = new TrackRectDrawable(progressColor); mScrubber = shapeDrawable; mScrubber.setCallback(this); ThumbDrawable thumbDrawable = new ThumbDrawable(progressColor, thumbSize); mThumb = thumbDrawable; mThumb.setCallback(this); mThumb.setBounds(0, 0, mThumb.getIntrinsicWidth(), mThumb.getIntrinsicHeight()); if (!editMode) { mIndicator = new PopupIndicator(context, attrs, defStyle, convertValueToMessage(mMax)); mIndicator.setListener(mFloaterListener); } a.recycle(); setNumericTransformer(new DefaultNumericTransformer()); }
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 }); }/*from ww w . j a va 2s.c om*/ } 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 }); } }