use of android.graphics.drawable.RippleDrawable in project QAuxiliary by cinit.
the class BackgroundDrawableUtils method getRoundRectSelectorDrawable.
public static Drawable getRoundRectSelectorDrawable(Context context, int color) {
Drawable maskDrawable = createRoundRectDrawable(LayoutHelper.dip2px(context, 3), 0xffffffff);
ColorStateList colorStateList = new ColorStateList(new int[][] { StateSet.WILD_CARD }, new int[] { (color & 0x00ffffff) | 0x19000000 });
return new RippleDrawable(colorStateList, null, maskDrawable);
}
use of android.graphics.drawable.RippleDrawable in project Phonograph_Plus by chr56.
the class TintHelper method setTintAuto.
@SuppressWarnings("deprecation")
public static void setTintAuto(@NonNull final View view, @ColorInt final 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);
ViewUtil.setBackgroundCompat(view, drawable);
}
}
}
}
use of android.graphics.drawable.RippleDrawable in project Phonograph_Plus by chr56.
the class ViewUtil method createSelectorDrawable.
public static Drawable createSelectorDrawable(Context context, @ColorInt int color) {
final StateListDrawable baseSelector = new StateListDrawable();
baseSelector.addState(new int[] { android.R.attr.state_activated }, new ColorDrawable(color));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return new RippleDrawable(ColorStateList.valueOf(color), baseSelector, new ColorDrawable(Color.WHITE));
}
baseSelector.addState(new int[] {}, new ColorDrawable(Color.TRANSPARENT));
baseSelector.addState(new int[] { android.R.attr.state_pressed }, new ColorDrawable(color));
return baseSelector;
}
use of android.graphics.drawable.RippleDrawable in project TBLauncher by TBog.
the class CustomizeUI method getSelectorDrawable.
public static Drawable getSelectorDrawable(View view, int color, boolean borderless) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Drawable mask = borderless ? null : new ColorDrawable(Color.WHITE);
Drawable content = borderless ? null : view.getBackground();
return new RippleDrawable(ColorStateList.valueOf(color), content, mask);
} else {
ColorDrawable stateColor = new ColorDrawable(color);
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(new int[] { android.R.attr.state_selected }, stateColor);
stateListDrawable.addState(new int[] { android.R.attr.state_focused }, stateColor);
stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, stateColor);
stateListDrawable.addState(new int[] {}, new ColorDrawable(Color.TRANSPARENT));
stateListDrawable.setEnterFadeDuration(300);
stateListDrawable.setExitFadeDuration(100);
return stateListDrawable;
}
}
use of android.graphics.drawable.RippleDrawable in project Telegram-FOSS by Telegram-FOSS-Team.
the class Theme method createSelectorWithBackgroundDrawable.
public static Drawable createSelectorWithBackgroundDrawable(int backgroundColor, int color) {
if (Build.VERSION.SDK_INT >= 21) {
Drawable maskDrawable = new ColorDrawable(backgroundColor);
ColorStateList colorStateList = new ColorStateList(new int[][] { StateSet.WILD_CARD }, new int[] { color });
return new RippleDrawable(colorStateList, new ColorDrawable(backgroundColor), maskDrawable);
} else {
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, new ColorDrawable(color));
stateListDrawable.addState(new int[] { android.R.attr.state_selected }, new ColorDrawable(color));
stateListDrawable.addState(StateSet.WILD_CARD, new ColorDrawable(backgroundColor));
return stateListDrawable;
}
}
Aggregations