Java Code Examples for android.graphics.drawable.RippleDrawable#setColor()
The following examples show how to use
android.graphics.drawable.RippleDrawable#setColor() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ForegroundDelegate.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 6 votes |
static void setupForeground(View view, Drawable drawable, Integer color, Integer alpha) { if (view instanceof IForeground) { if (color != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (drawable instanceof RippleDrawable) { RippleDrawable rippleDrawable = (RippleDrawable) drawable; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { rippleDrawable.setColor(ColorStateList.valueOf(color)); } if (alpha != null) { rippleDrawable.setAlpha(alpha); } } } } ((IForeground) view).setForeground(drawable); } }
Example 2
Source File: DetailActivityL.java From google-io-2014-compat with Apache License 2.0 | 5 votes |
@Override public void colorButton(int id, int bgColor, int tintColor) { View buttonView = findViewById(id); RippleDrawable ripple = (RippleDrawable) buttonView.getBackground(); GradientDrawable rippleBackground = (GradientDrawable) ripple.getDrawable(0); rippleBackground.setColor(bgColor); ripple.setColor(ColorStateList.valueOf(tintColor)); }
Example 3
Source File: DetailActivity.java From google-io-2014 with Apache License 2.0 | 5 votes |
private void colorRipple(int id, int bgColor, int tintColor) { View buttonView = findViewById(id); RippleDrawable ripple = (RippleDrawable) buttonView.getBackground(); GradientDrawable rippleBackground = (GradientDrawable) ripple.getDrawable(0); rippleBackground.setColor(bgColor); ripple.setColor(ColorStateList.valueOf(tintColor)); }
Example 4
Source File: TintHelper.java From a with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("deprecation") public static void setTintAuto(final @NonNull View view, final @ColorInt int color, boolean background, final boolean isDark) { if (!background) { if (view instanceof RadioButton) setTint((RadioButton) view, color, isDark); else if (view instanceof SeekBar) setTint((SeekBar) view, color, isDark); else if (view instanceof ProgressBar) setTint((ProgressBar) view, color); else if (view instanceof AppCompatEditText) setTint((AppCompatEditText) view, color, isDark); else if (view instanceof CheckBox) setTint((CheckBox) view, color, isDark); else if (view instanceof ImageView) setTint((ImageView) view, color); else if (view instanceof Switch) setTint((Switch) view, color, isDark); else if (view instanceof SwitchCompat) setTint((SwitchCompat) view, color, isDark); else if (view instanceof SearchView) { int iconIdS[] = new int[]{androidx.appcompat.R.id.search_button, androidx.appcompat.R.id.search_close_btn,}; for (int iconId : iconIdS) { ImageView icon = view.findViewById(iconId); if (icon != null) { setTint(icon, color); } } } else { background = true; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !background && view.getBackground() instanceof RippleDrawable) { // Ripples for the above views (e.g. when you tap and hold a switch or checkbox) RippleDrawable rd = (RippleDrawable) view.getBackground(); @SuppressLint("PrivateResource") final int unchecked = ContextCompat.getColor(view.getContext(), isDark ? R.color.ripple_material_dark : R.color.ripple_material_light); final int checked = ColorUtil.adjustAlpha(color, 0.4f); final ColorStateList sl = new ColorStateList( new int[][]{ new int[]{-android.R.attr.state_activated, -android.R.attr.state_checked}, new int[]{android.R.attr.state_activated}, new int[]{android.R.attr.state_checked} }, new int[]{ unchecked, checked, checked } ); rd.setColor(sl); } } if (background) { // Need to tint the background of a view if (view instanceof FloatingActionButton || view instanceof Button) { setTintSelector(view, color, false, isDark); } else if (view.getBackground() != null) { Drawable drawable = view.getBackground(); if (drawable != null) { drawable = createTintedDrawable(drawable, color); ViewUtil.setBackgroundCompat(view, drawable); } } } }
Example 5
Source File: TintHelper.java From MyBookshelf with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("deprecation") public static void setTintAuto(final @NonNull View view, final @ColorInt int color, boolean background, final boolean isDark) { if (!background) { if (view instanceof RadioButton) setTint((RadioButton) view, color, isDark); else if (view instanceof SeekBar) setTint((SeekBar) view, color, isDark); else if (view instanceof ProgressBar) setTint((ProgressBar) view, color); else if (view instanceof AppCompatEditText) setTint((AppCompatEditText) view, color, isDark); else if (view instanceof CheckBox) setTint((CheckBox) view, color, isDark); else if (view instanceof ImageView) setTint((ImageView) view, color); else if (view instanceof Switch) setTint((Switch) view, color, isDark); else if (view instanceof SwitchCompat) setTint((SwitchCompat) view, color, isDark); else if (view instanceof SearchView) { int iconIdS[] = new int[]{androidx.appcompat.R.id.search_button, androidx.appcompat.R.id.search_close_btn,}; for (int iconId : iconIdS) { ImageView icon = view.findViewById(iconId); if (icon != null) { setTint(icon, color); } } } else { background = true; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !background && view.getBackground() instanceof RippleDrawable) { // Ripples for the above views (e.g. when you tap and hold a switch or checkbox) RippleDrawable rd = (RippleDrawable) view.getBackground(); @SuppressLint("PrivateResource") final int unchecked = ContextCompat.getColor(view.getContext(), isDark ? R.color.ripple_material_dark : R.color.ripple_material_light); final int checked = ColorUtil.adjustAlpha(color, 0.4f); final ColorStateList sl = new ColorStateList( new int[][]{ new int[]{-android.R.attr.state_activated, -android.R.attr.state_checked}, new int[]{android.R.attr.state_activated}, new int[]{android.R.attr.state_checked} }, new int[]{ unchecked, checked, checked } ); rd.setColor(sl); } } if (background) { // Need to tint the background of a view if (view instanceof FloatingActionButton || view instanceof Button) { setTintSelector(view, color, false, isDark); } else if (view.getBackground() != null) { Drawable drawable = view.getBackground(); if (drawable != null) { drawable = createTintedDrawable(drawable, color); ViewUtil.setBackgroundCompat(view, drawable); } } } }
Example 6
Source File: DynamicTintUtils.java From dynamic-support with Apache License 2.0 | 4 votes |
/** * Set a view background tint according to the supplied color. * * @param view The view to set the background tint. * @param background The background color to calculate the default color. * @param color The tint color to be used. * @param borderless {@code true} if the view is borderless. * @param checkable {@code true} if the view is checkable. */ @TargetApi(Build.VERSION_CODES.LOLLIPOP) public static void setViewBackgroundTint(@NonNull View view, @ColorInt int background, @ColorInt int color, boolean borderless, boolean checkable) { @ColorInt int pressedColor = DynamicColorUtils.shiftColor(color, WidgetDefaults.ADS_SHIFT_LIGHT, WidgetDefaults.ADS_SHIFT_DARK); if (view instanceof MaterialButton) { if (borderless) { if (!DynamicSdkUtils.is21()) { pressedColor = DynamicColorUtils.getStateColor( DynamicColorUtils.adjustAlpha( pressedColor, WidgetDefaults.ADS_STATE_PRESSED), WidgetDefaults.ADS_STATE_LIGHT, WidgetDefaults.ADS_STATE_DARK); ViewCompat.setBackgroundTintList(view, DynamicResourceUtils.getColorStateList( Color.TRANSPARENT, pressedColor, checkable)); } else { ((MaterialButton) view).setRippleColor( DynamicResourceUtils.getColorStateList( Color.TRANSPARENT, pressedColor, checkable)); } } else { ViewCompat.setBackgroundTintList(view, DynamicResourceUtils.getColorStateList( DynamicColorUtils.getTintColor(background), color, pressedColor, checkable)); } } else if (view instanceof TintableBackgroundView) { if (borderless) { ViewCompat.setBackgroundTintList(view, DynamicResourceUtils.getColorStateList( Color.TRANSPARENT, pressedColor, checkable)); } else { ViewCompat.setBackgroundTintList(view, DynamicResourceUtils.getColorStateList( DynamicColorUtils.getTintColor(background), color, pressedColor, checkable)); } } else { if (!DynamicSdkUtils.is21()) { background = DynamicColorUtils.getStateColor( DynamicColorUtils.adjustAlpha(DynamicColorUtils.getTintColor(background), WidgetDefaults.ADS_STATE_PRESSED), WidgetDefaults.ADS_STATE_LIGHT, WidgetDefaults.ADS_STATE_DARK); pressedColor = DynamicColorUtils.getStateColor( DynamicColorUtils.adjustAlpha(color, WidgetDefaults.ADS_STATE_PRESSED), WidgetDefaults.ADS_STATE_LIGHT, WidgetDefaults.ADS_STATE_DARK); if (borderless) { DynamicDrawableUtils.setBackground(view, DynamicResourceUtils.getStateListDrawable(Color.TRANSPARENT, background, pressedColor, checkable)); } else { // TODO: } } } if (DynamicSdkUtils.is21() && view.getBackground() instanceof RippleDrawable) { if (borderless) { pressedColor = DynamicColorUtils.adjustAlpha( color, WidgetDefaults.ADS_STATE_PRESSED); } pressedColor = DynamicColorUtils.getStateColor(pressedColor, WidgetDefaults.ADS_STATE_LIGHT, WidgetDefaults.ADS_STATE_DARK); RippleDrawable rippleDrawable = (RippleDrawable) view.getBackground(); if (checkable && !(view instanceof DynamicCheckedTextView)) { background = DynamicColorUtils.getStateColor( DynamicColorUtils.adjustAlpha( DynamicColorUtils.getTintColor(background), WidgetDefaults.ADS_STATE_PRESSED), WidgetDefaults.ADS_STATE_LIGHT, WidgetDefaults.ADS_STATE_DARK); rippleDrawable.setColor(DynamicResourceUtils.getColorStateList( Color.TRANSPARENT, background, pressedColor, true)); } else { rippleDrawable.setColor(ColorStateList.valueOf(pressedColor)); } } }
Example 7
Source File: TintHelper.java From APlayer with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("deprecation") public static void setTintAuto(final @NonNull View view, final @ColorInt int color, boolean background, final boolean isDark) { if (!background) { if (view instanceof RadioButton) { setTint((RadioButton) view, color, isDark); } else if (view instanceof SeekBar) { setTint((SeekBar) view, color, isDark); } else if (view instanceof ProgressBar) { setTint((ProgressBar) view, color); } else if (view instanceof EditText) { setTint((EditText) view, color, isDark); } else if (view instanceof CheckBox) { setTint((CheckBox) view, color, isDark); } else if (view instanceof ImageView) { setTint((ImageView) view, color); } else if (view instanceof Switch) { setTint((Switch) view, color, isDark); } else if (view instanceof SwitchCompat) { setTint((SwitchCompat) view, color, isDark); } else { background = true; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !background && view.getBackground() instanceof RippleDrawable) { // Ripples for the above views (e.g. when you tap and hold a switch or checkbox) RippleDrawable rd = (RippleDrawable) view.getBackground(); @SuppressLint("PrivateResource") final int unchecked = ContextCompat .getColor(view.getContext(), isDark ? R.color.ripple_material_dark : R.color.ripple_material_light); final int checked = ColorUtil.adjustAlpha(color, 0.4f); final ColorStateList sl = new ColorStateList( new int[][]{ new int[]{-android.R.attr.state_activated, -android.R.attr.state_checked}, new int[]{android.R.attr.state_activated}, new int[]{android.R.attr.state_checked} }, new int[]{ unchecked, checked, checked } ); rd.setColor(sl); } } if (background) { // Need to tint the background of a view if (view instanceof FloatingActionButton || view instanceof Button) { setTintSelector(view, color, false, isDark); } else if (view.getBackground() != null) { Drawable drawable = view.getBackground(); if (drawable != null) { drawable = createTintedDrawable(drawable, color); setBackgroundCompat(view, drawable); } } } }