Search in sources :

Example 51 with RippleDrawable

use of android.graphics.drawable.RippleDrawable in project Telegram-FOSS by Telegram-FOSS-Team.

the class Theme method setMaskDrawableRad.

public static void setMaskDrawableRad(Drawable rippleDrawable, int top, int bottom) {
    if (Build.VERSION.SDK_INT < 21) {
        return;
    }
    if (rippleDrawable instanceof RippleDrawable) {
        RippleDrawable drawable = (RippleDrawable) rippleDrawable;
        int count = drawable.getNumberOfLayers();
        for (int a = 0; a < count; a++) {
            Drawable layer = drawable.getDrawable(a);
            if (layer instanceof RippleRadMaskDrawable) {
                drawable.setDrawableByLayerId(android.R.id.mask, new RippleRadMaskDrawable(top, bottom));
                break;
            }
        }
    }
}
Also used : 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) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) RippleDrawable(android.graphics.drawable.RippleDrawable)

Example 52 with RippleDrawable

use of android.graphics.drawable.RippleDrawable in project Telegram-FOSS by Telegram-FOSS-Team.

the class Theme method setSelectorDrawableColor.

public static void setSelectorDrawableColor(Drawable drawable, int color, boolean selected) {
    if (drawable instanceof StateListDrawable) {
        try {
            Drawable state;
            if (selected) {
                state = getStateDrawable(drawable, 0);
                if (state instanceof ShapeDrawable) {
                    ((ShapeDrawable) state).getPaint().setColor(color);
                } else {
                    state.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                }
                state = getStateDrawable(drawable, 1);
            } else {
                state = getStateDrawable(drawable, 2);
            }
            if (state instanceof ShapeDrawable) {
                ((ShapeDrawable) state).getPaint().setColor(color);
            } else {
                state.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
            }
        } catch (Throwable ignore) {
        }
    } else if (Build.VERSION.SDK_INT >= 21 && drawable instanceof RippleDrawable) {
        RippleDrawable rippleDrawable = (RippleDrawable) drawable;
        if (selected) {
            rippleDrawable.setColor(new ColorStateList(new int[][] { StateSet.WILD_CARD }, new int[] { color }));
        } else {
            if (rippleDrawable.getNumberOfLayers() > 0) {
                Drawable drawable1 = rippleDrawable.getDrawable(0);
                if (drawable1 instanceof ShapeDrawable) {
                    ((ShapeDrawable) drawable1).getPaint().setColor(color);
                } else {
                    drawable1.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                }
            }
        }
    }
}
Also used : 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) ShapeDrawable(android.graphics.drawable.ShapeDrawable) ColorStateList(android.content.res.ColorStateList) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) StateListDrawable(android.graphics.drawable.StateListDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable)

Example 53 with RippleDrawable

use of android.graphics.drawable.RippleDrawable in project Telegram-FOSS by Telegram-FOSS-Team.

the class Theme method createSimpleSelectorCircleDrawable.

public static Drawable createSimpleSelectorCircleDrawable(int size, int defaultColor, int pressedColor) {
    OvalShape ovalShape = new OvalShape();
    ovalShape.resize(size, size);
    ShapeDrawable defaultDrawable = new ShapeDrawable(ovalShape);
    defaultDrawable.getPaint().setColor(defaultColor);
    ShapeDrawable pressedDrawable = new ShapeDrawable(ovalShape);
    if (Build.VERSION.SDK_INT >= 21) {
        pressedDrawable.getPaint().setColor(0xffffffff);
        ColorStateList colorStateList = new ColorStateList(new int[][] { StateSet.WILD_CARD }, new int[] { pressedColor });
        return new RippleDrawable(colorStateList, defaultDrawable, pressedDrawable);
    } else {
        pressedDrawable.getPaint().setColor(pressedColor);
        StateListDrawable stateListDrawable = new StateListDrawable();
        stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, pressedDrawable);
        stateListDrawable.addState(new int[] { android.R.attr.state_focused }, pressedDrawable);
        stateListDrawable.addState(StateSet.WILD_CARD, defaultDrawable);
        return stateListDrawable;
    }
}
Also used : ShapeDrawable(android.graphics.drawable.ShapeDrawable) ColorStateList(android.content.res.ColorStateList) OvalShape(android.graphics.drawable.shapes.OvalShape) StateListDrawable(android.graphics.drawable.StateListDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable)

Example 54 with RippleDrawable

use of android.graphics.drawable.RippleDrawable in project Telegram-FOSS by Telegram-FOSS-Team.

the class Theme method getSelectorDrawable.

public static Drawable getSelectorDrawable(int color, String backgroundColor) {
    if (backgroundColor != null) {
        if (Build.VERSION.SDK_INT >= 21) {
            Drawable maskDrawable = new ColorDrawable(0xffffffff);
            ColorStateList colorStateList = new ColorStateList(new int[][] { StateSet.WILD_CARD }, new int[] { color });
            return new RippleDrawable(colorStateList, new ColorDrawable(getColor(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(getColor(backgroundColor)));
            return stateListDrawable;
        }
    } else {
        return createSelectorDrawable(color, 2);
    }
}
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)

Example 55 with RippleDrawable

use of android.graphics.drawable.RippleDrawable in project Telegram-FOSS by Telegram-FOSS-Team.

the class Theme method createSelectorDrawable.

public static Drawable createSelectorDrawable(int color, int maskType, int radius) {
    Drawable drawable;
    if (Build.VERSION.SDK_INT >= 21) {
        Drawable maskDrawable = null;
        if ((maskType == 1 || maskType == 5) && Build.VERSION.SDK_INT >= 23) {
            maskDrawable = null;
        } else if (maskType == 1 || maskType == 3 || maskType == 4 || maskType == 5 || maskType == 6 || maskType == 7) {
            maskPaint.setColor(0xffffffff);
            maskDrawable = new Drawable() {

                RectF rect;

                @Override
                public void draw(Canvas canvas) {
                    android.graphics.Rect bounds = getBounds();
                    if (maskType == 7) {
                        if (rect == null) {
                            rect = new RectF();
                        }
                        rect.set(bounds);
                        canvas.drawRoundRect(rect, AndroidUtilities.dp(6), AndroidUtilities.dp(6), maskPaint);
                    } else {
                        int rad;
                        if (maskType == 1 || maskType == 6) {
                            rad = AndroidUtilities.dp(20);
                        } else if (maskType == 3) {
                            rad = (Math.max(bounds.width(), bounds.height()) / 2);
                        } else {
                            rad = (int) Math.ceil(Math.sqrt((bounds.left - bounds.centerX()) * (bounds.left - bounds.centerX()) + (bounds.top - bounds.centerY()) * (bounds.top - bounds.centerY())));
                        }
                        canvas.drawCircle(bounds.centerX(), bounds.centerY(), rad, maskPaint);
                    }
                }

                @Override
                public void setAlpha(int alpha) {
                }

                @Override
                public void setColorFilter(ColorFilter colorFilter) {
                }

                @Override
                public int getOpacity() {
                    return PixelFormat.UNKNOWN;
                }
            };
        } else if (maskType == 2) {
            maskDrawable = new ColorDrawable(0xffffffff);
        }
        ColorStateList colorStateList = new ColorStateList(new int[][] { StateSet.WILD_CARD }, new int[] { color });
        RippleDrawable rippleDrawable = new RippleDrawable(colorStateList, null, maskDrawable);
        if (Build.VERSION.SDK_INT >= 23) {
            if (maskType == 1) {
                rippleDrawable.setRadius(radius <= 0 ? AndroidUtilities.dp(20) : radius);
            } else if (maskType == 5) {
                rippleDrawable.setRadius(RippleDrawable.RADIUS_AUTO);
            }
        }
        return rippleDrawable;
    } 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(0x00000000));
        return stateListDrawable;
    }
}
Also used : RectF(android.graphics.RectF) Rect(android.graphics.Rect) ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) ColorFilter(android.graphics.ColorFilter) ColorDrawable(android.graphics.drawable.ColorDrawable) Canvas(android.graphics.Canvas) 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) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) 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