Search in sources :

Example 46 with RippleDrawable

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);
}
Also used : ShapeDrawable(android.graphics.drawable.ShapeDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable) Drawable(android.graphics.drawable.Drawable) ColorStateList(android.content.res.ColorStateList) RippleDrawable(android.graphics.drawable.RippleDrawable)

Example 47 with RippleDrawable

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);
            }
        }
    }
}
Also used : AppCompatEditText(androidx.appcompat.widget.AppCompatEditText) EditText(android.widget.EditText) SeekBar(android.widget.SeekBar) Drawable(android.graphics.drawable.Drawable) RippleDrawable(android.graphics.drawable.RippleDrawable) ColorStateList(android.content.res.ColorStateList) RadioButton(android.widget.RadioButton) SuppressLint(android.annotation.SuppressLint) RippleDrawable(android.graphics.drawable.RippleDrawable) Switch(android.widget.Switch) RadioButton(android.widget.RadioButton) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) Button(android.widget.Button) CheckBox(android.widget.CheckBox) SuppressLint(android.annotation.SuppressLint) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) ImageView(android.widget.ImageView) ProgressBar(android.widget.ProgressBar) SwitchCompat(androidx.appcompat.widget.SwitchCompat)

Example 48 with RippleDrawable

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;
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable)

Example 49 with RippleDrawable

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;
    }
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable) PaintDrawable(android.graphics.drawable.PaintDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable)

Example 50 with RippleDrawable

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;
    }
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) TypingDotsDrawable(org.telegram.ui.Components.TypingDotsDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) StatusDrawable(org.telegram.ui.Components.StatusDrawable) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) FragmentContextViewWavesDrawable(org.telegram.ui.Components.FragmentContextViewWavesDrawable) NinePatchDrawable(android.graphics.drawable.NinePatchDrawable) RoundStatusDrawable(org.telegram.ui.Components.RoundStatusDrawable) BackgroundGradientDrawable(org.telegram.ui.Components.BackgroundGradientDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) ChoosingStickerStatusDrawable(org.telegram.ui.Components.ChoosingStickerStatusDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) PlayingGameDrawable(org.telegram.ui.Components.PlayingGameDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ScamDrawable(org.telegram.ui.Components.ScamDrawable) MotionBackgroundDrawable(org.telegram.ui.Components.MotionBackgroundDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable) AudioVisualizerDrawable(org.telegram.ui.Components.AudioVisualizerDrawable) SendingFileDrawable(org.telegram.ui.Components.SendingFileDrawable) RecordStatusDrawable(org.telegram.ui.Components.RecordStatusDrawable) MsgClockDrawable(org.telegram.ui.Components.MsgClockDrawable) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) ColorStateList(android.content.res.ColorStateList) StateListDrawable(android.graphics.drawable.StateListDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable)

Aggregations

RippleDrawable (android.graphics.drawable.RippleDrawable)115 StateListDrawable (android.graphics.drawable.StateListDrawable)60 Drawable (android.graphics.drawable.Drawable)49 ColorStateList (android.content.res.ColorStateList)47 GradientDrawable (android.graphics.drawable.GradientDrawable)30 TargetApi (android.annotation.TargetApi)26 ShapeDrawable (android.graphics.drawable.ShapeDrawable)23 View (android.view.View)21 Paint (android.graphics.Paint)20 ColorDrawable (android.graphics.drawable.ColorDrawable)20 SuppressLint (android.annotation.SuppressLint)15 TextView (android.widget.TextView)15 FrameLayout (android.widget.FrameLayout)12 LayerDrawable (android.graphics.drawable.LayerDrawable)11 ImageView (android.widget.ImageView)11 RLottieDrawable (org.telegram.ui.Components.RLottieDrawable)11 CombinedDrawable (org.telegram.ui.Components.CombinedDrawable)10 ScamDrawable (org.telegram.ui.Components.ScamDrawable)10 Outline (android.graphics.Outline)9 BitmapDrawable (android.graphics.drawable.BitmapDrawable)9