List of usage examples for android.content.res ColorStateList valueOf
@NonNull public static ColorStateList valueOf(@ColorInt int color)
From source file:com.appsummary.luoxf.myappsummary.DetailActivity.java
private void updateBackground(FloatingActionButton fab, Palette palette) { int lightVibrantColor = palette.getLightVibrantColor(getResources().getColor(android.R.color.white)); int vibrantColor = palette.getVibrantColor(getResources().getColor(R.color.accent)); fab.setRippleColor(lightVibrantColor); fab.setBackgroundTintList(ColorStateList.valueOf(vibrantColor)); }
From source file:ua.boberproduction.bbr.notes.NoteEditorFragment.java
private void enableSaveButton(boolean enable) { if (floatingActionButton != null) { if (enable) { floatingActionButton.setEnabled(true); floatingActionButton.setBackgroundTintList( ColorStateList.valueOf(ContextCompat.getColor(getActivity(), R.color.colorPrimary))); } else {//from w w w. ja va 2s. c o m floatingActionButton.setEnabled(false); floatingActionButton.setBackgroundTintList( ColorStateList.valueOf(ContextCompat.getColor(getActivity(), R.color.save_btn_disabled))); } } }
From source file:com.jinzht.pro.smarttablayout.SmartTabLayout.java
public SmartTabLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // Disable the Scroll Bar setHorizontalScrollBarEnabled(false); // Make sure that the Tab Strips fills this View setFillViewport(true);//from w ww. j a va 2 s . c o m final DisplayMetrics dm = getResources().getDisplayMetrics(); final float density = dm.density; int tabBackgroundResId = NO_ID; boolean textAllCaps = TAB_VIEW_TEXT_ALL_CAPS; ColorStateList textColors; float textSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP, dm); int textHorizontalPadding = (int) (TAB_VIEW_PADDING_DIPS * density); int textMinWidth = (int) (TAB_VIEW_TEXT_MIN_WIDTH * density); boolean distributeEvenly = DEFAULT_DISTRIBUTE_EVENLY; int customTabLayoutId = NO_ID; int customTabTextViewId = NO_ID; TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.stl_SmartTabLayout, defStyle, 0); tabBackgroundResId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_defaultTabBackground, tabBackgroundResId); textAllCaps = a.getBoolean(R.styleable.stl_SmartTabLayout_stl_defaultTabTextAllCaps, textAllCaps); textColors = a.getColorStateList(R.styleable.stl_SmartTabLayout_stl_defaultTabTextColor); textSize = a.getDimension(R.styleable.stl_SmartTabLayout_stl_defaultTabTextSize, textSize); textHorizontalPadding = a.getDimensionPixelSize( R.styleable.stl_SmartTabLayout_stl_defaultTabTextHorizontalPadding, textHorizontalPadding); textMinWidth = a.getDimensionPixelSize(R.styleable.stl_SmartTabLayout_stl_defaultTabTextMinWidth, textMinWidth); customTabLayoutId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_customTabTextLayoutId, customTabLayoutId); customTabTextViewId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_customTabTextViewId, customTabTextViewId); distributeEvenly = a.getBoolean(R.styleable.stl_SmartTabLayout_stl_distributeEvenly, distributeEvenly); a.recycle(); this.titleOffset = (int) (TITLE_OFFSET_DIPS * density); this.tabViewBackgroundResId = tabBackgroundResId; this.tabViewTextAllCaps = textAllCaps; this.tabViewTextColors = (textColors != null) ? textColors : ColorStateList.valueOf(TAB_VIEW_TEXT_COLOR); this.tabViewTextSize = textSize; this.tabViewTextHorizontalPadding = textHorizontalPadding; this.tabViewTextMinWidth = textMinWidth; this.distributeEvenly = distributeEvenly; if (customTabLayoutId != NO_ID) { setCustomTabView(customTabLayoutId, customTabTextViewId); } this.tabStrip = new SmartTabStrip(context, attrs); if (distributeEvenly && tabStrip.isIndicatorAlwaysInCenter()) { throw new UnsupportedOperationException( "'distributeEvenly' and 'indicatorAlwaysInCenter' both use does not support"); } addView(tabStrip, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); }
From source file:com.varejodigital.activities.DetailActivity.java
private void updateBackground(View view, Palette palette) { int lightMutedColor = palette.getLightMutedColor(getResources().getColor(R.color.accent)); int mutedColor = palette.getMutedColor(getResources().getColor(R.color.accent)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { RippleDrawable ripple = (RippleDrawable) view.getBackground(); GradientDrawable rippleBackground = (GradientDrawable) ripple.getDrawable(0); rippleBackground.setColor(lightMutedColor); ripple.setColor(ColorStateList.valueOf(mutedColor)); } else {/* ww w . ja va 2 s .com*/ StateListDrawable drawable = (StateListDrawable) view.getBackground(); drawable.setColorFilter(mutedColor, PorterDuff.Mode.SRC_ATOP); } }
From source file:cn.edu.qzu.face.PagerSlidingTabStrip.java
public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFillViewport(true);/*from ww w . j a v a 2 s . com*/ setWillNotDraw(false); tabsContainer = new LinearLayout(context); tabsContainer.setOrientation(LinearLayout.HORIZONTAL); tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); addView(tabsContainer); DisplayMetrics dm = getResources().getDisplayMetrics(); scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm); indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm); underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm); dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm); tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm); dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm); tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm); // get system attrs (android:textSize and android:textColor) TypedArray a = context.obtainStyledAttributes(attrs, ATTRS); tabTextSize = a.getDimensionPixelSize(0, tabTextSize); tabTextColor = a.getColor(1, tabTextColor); tabTextColorStateList = a.getColorStateList(1); if (tabTextColorStateList == null) { tabTextColorStateList = ColorStateList.valueOf(tabTextColor); } a.recycle(); // get custom attrs // a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip); // // indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor); // underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor); // dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor); // indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight, indicatorHeight); // underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight, underlineHeight); // dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding, dividerPadding); // tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding); // tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground, tabBackgroundResId); // shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand); // scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset); // textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps); a.recycle(); rectPaint = new Paint(); rectPaint.setAntiAlias(true); rectPaint.setStyle(Style.FILL); dividerPaint = new Paint(); dividerPaint.setAntiAlias(true); dividerPaint.setStrokeWidth(dividerWidth); defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f); if (locale == null) { locale = getResources().getConfiguration().locale; } }
From source file:com.facebook.react.views.slider.ReactSlider.java
@TargetApi(21) public void setProgressBackgroundColor(Integer value) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { setProgressBackgroundTintList(ColorStateList.valueOf(value)); } else {//ww w .j a v a2s . com if (getProgressDrawable() instanceof LayerDrawable) { LayerDrawable layer = (LayerDrawable) getProgressDrawable(); DrawableCompat.setTintList(layer.findDrawableByLayerId(android.R.id.background).mutate(), ColorStateList.valueOf(value)); } } }
From source file:com.flexible.flexibleadapter.utils.DrawableUtils.java
/** * Helper to get a custom selectable background with Ripple if device has at least Lollipop. * * @param normalColor the color in normal state * @param pressedColor the pressed color * @param rippleColor the color of the ripple * @return the RippleDrawable with StateListDrawable if at least Lollipop, the normal * StateListDrawable otherwise/*from w w w . j a va 2 s .c om*/ * @since 5.0.0-b7 Created * <br/>5.0.0-rc1 RippleColor becomes the 3rd parameter */ public static Drawable getSelectableBackgroundCompat(@ColorInt int normalColor, @ColorInt int pressedColor, @ColorInt int rippleColor) { if (Utils.hasLollipop()) { return new RippleDrawable(ColorStateList.valueOf(rippleColor), getStateListDrawable(normalColor, pressedColor), getRippleMask(normalColor)); } else { return getStateListDrawable(normalColor, pressedColor); } }
From source file:uk.ac.horizon.artcodes.scanner.ScannerActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); hideSystemUI();//from w w w.j av a 2 s. c om setContentView(R.layout.scanner); settingIcons = (LinearLayout) findViewById(R.id.settingsSwitches); progressBar = (ProgressBar) findViewById(R.id.progressBar); cameraView = (CameraView) findViewById(R.id.cameraView); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayShowTitleEnabled(false); } if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.CAMERA }, CAMERA_PERMISSION_REQUEST); } menuAnimator = new VisibilityAnimator(findViewById(R.id.settingsMenu), findViewById(R.id.settingsMenuButton)); TextView settingsFeedback = (TextView) findViewById(R.id.settingsFeedback); textAnimator = new TextAnimator(settingsFeedback); ViewGroup bottomView = (ViewGroup) findViewById(R.id.bottomView); if (bottomView != null) { actionView = getLayoutInflater().inflate(R.layout.scanner_action, bottomView, false); bottomView.addView(actionView); actionAnimator = new VisibilityAnimator(actionView); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { progressBar.setIndeterminateTintList(ColorStateList.valueOf(0xff33b5e5)); } }
From source file:io.romain.passport.utils.glide.CityItemTarget.java
@SuppressWarnings("RedundantCast") @Override/*from w w w. j a v a2s . c om*/ @TargetApi(21) public void onGenerated(Palette palette) { sUrlPaletteCache.put(mCity.picture(), palette); Context context = getView().getContext(); ((FourThreeImageView) getView()).setForeground(new LayerDrawable(new Drawable[] { ViewUtils.createRipple(palette, 0.25f, 0.5f, ContextCompat.getColor(context, R.color.mid_grey), true), ScrimUtil.makeCubicGradientScrimDrawable(ContextCompat.getColor(context, R.color.scrim), 5, Gravity.BOTTOM) })); int color; switch (ColorUtils.isDark(palette)) { default: case ColorUtils.LIGHTNESS_UNKNOWN: case ColorUtils.IS_DARK: color = getColor(context, android.R.color.white); mViewHolder.name.setTextColor(getColor(context, R.color.text_primary_light)); break; case ColorUtils.IS_LIGHT: color = getColor(context, android.R.color.black); mViewHolder.name.setTextColor(getColor(context, R.color.text_primary_dark)); break; } mViewHolder.favorite.setImageTintList(ColorStateList.valueOf(color)); mViewHolder.remove.setImageTintList(ColorStateList.valueOf(color)); }
From source file:com.bitflake.counter.HorizontalPicker.java
public HorizontalPicker(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // create the selector wheel paint TextPaint paint = new TextPaint(); paint.setAntiAlias(true);/*from w w w .j a va 2 s . c om*/ textPaint = paint; TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.HorizontalPicker, defStyle, 0); CharSequence[] values; int ellipsize = 3; // END default value int sideItems = this.sideItems; try { textColor = a.getColorStateList(R.styleable.HorizontalPicker_android_textColor); if (textColor == null) { textColor = ColorStateList.valueOf(0xFF000000); } values = a.getTextArray(R.styleable.HorizontalPicker_values); ellipsize = a.getInt(R.styleable.HorizontalPicker_android_ellipsize, ellipsize); marqueeRepeatLimit = a.getInt(R.styleable.HorizontalPicker_android_marqueeRepeatLimit, marqueeRepeatLimit); dividerSize = a.getDimension(R.styleable.HorizontalPicker_dividerSize, dividerSize); sideItems = a.getInt(R.styleable.HorizontalPicker_sideItems, sideItems); float textSize = a.getDimension(R.styleable.HorizontalPicker_android_textSize, -1); if (textSize > -1) { setTextSize(textSize); } } finally { a.recycle(); } switch (ellipsize) { case 1: setEllipsize(TextUtils.TruncateAt.START); break; case 2: setEllipsize(TextUtils.TruncateAt.MIDDLE); break; case 3: setEllipsize(TextUtils.TruncateAt.END); break; case 4: setEllipsize(TextUtils.TruncateAt.MARQUEE); break; } Paint.FontMetricsInt fontMetricsInt = textPaint.getFontMetricsInt(); boringMetrics = new BoringLayout.Metrics(); boringMetrics.ascent = fontMetricsInt.ascent; boringMetrics.bottom = fontMetricsInt.bottom; boringMetrics.descent = fontMetricsInt.descent; boringMetrics.leading = fontMetricsInt.leading; boringMetrics.top = fontMetricsInt.top; boringMetrics.width = itemWidth; setWillNotDraw(false); flingScrollerX = new OverScroller(context); adjustScrollerX = new OverScroller(context, new DecelerateInterpolator(2.5f)); // initialize constants ViewConfiguration configuration = ViewConfiguration.get(context); touchSlop = configuration.getScaledTouchSlop(); mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity(); maximumFlingVelocity = configuration.getScaledMaximumFlingVelocity() / SELECTOR_MAX_FLING_VELOCITY_ADJUSTMENT; overscrollDistance = configuration.getScaledOverscrollDistance(); previousScrollerX = Integer.MIN_VALUE; setValues(values); setSideItems(sideItems); touchHelper = new PickerTouchHelper(this); ViewCompat.setAccessibilityDelegate(this, touchHelper); }