Search in sources :

Example 56 with RippleDrawable

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

the class Theme method createCircleSelectorDrawable.

public static Drawable createCircleSelectorDrawable(int color, int leftInset, int rightInset) {
    if (Build.VERSION.SDK_INT >= 21) {
        maskPaint.setColor(0xffffffff);
        Drawable maskDrawable = new Drawable() {

            @Override
            public void draw(Canvas canvas) {
                android.graphics.Rect bounds = getBounds();
                final int rad = (Math.max(bounds.width(), bounds.height()) / 2) + leftInset + rightInset;
                canvas.drawCircle(bounds.centerX() - leftInset + rightInset, bounds.centerY(), rad, maskPaint);
            }

            @Override
            public void setAlpha(int alpha) {
            }

            @Override
            public void setColorFilter(ColorFilter colorFilter) {
            }

            @Override
            public int getOpacity() {
                return PixelFormat.UNKNOWN;
            }
        };
        ColorStateList colorStateList = new ColorStateList(new int[][] { StateSet.WILD_CARD }, new int[] { color });
        return new RippleDrawable(colorStateList, null, 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(0x00000000));
        return stateListDrawable;
    }
}
Also used : 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)

Example 57 with RippleDrawable

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

the class Theme method getRoundRectSelectorDrawable.

public static Drawable getRoundRectSelectorDrawable(int color) {
    if (Build.VERSION.SDK_INT >= 21) {
        Drawable maskDrawable = createRoundRectDrawable(AndroidUtilities.dp(3), 0xffffffff);
        ColorStateList colorStateList = new ColorStateList(new int[][] { StateSet.WILD_CARD }, new int[] { (color & 0x00ffffff) | 0x19000000 });
        return new RippleDrawable(colorStateList, null, maskDrawable);
    } else {
        StateListDrawable stateListDrawable = new StateListDrawable();
        stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, createRoundRectDrawable(AndroidUtilities.dp(3), (color & 0x00ffffff) | 0x19000000));
        stateListDrawable.addState(new int[] { android.R.attr.state_selected }, createRoundRectDrawable(AndroidUtilities.dp(3), (color & 0x00ffffff) | 0x19000000));
        stateListDrawable.addState(StateSet.WILD_CARD, new ColorDrawable(0x00000000));
        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)

Example 58 with RippleDrawable

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

the class Theme method createSimpleSelectorRoundRectDrawable.

public static Drawable createSimpleSelectorRoundRectDrawable(int rad, int defaultColor, int pressedColor, int maskColor) {
    ShapeDrawable defaultDrawable = new ShapeDrawable(new RoundRectShape(new float[] { rad, rad, rad, rad, rad, rad, rad, rad }, null, null));
    defaultDrawable.getPaint().setColor(defaultColor);
    ShapeDrawable pressedDrawable = new ShapeDrawable(new RoundRectShape(new float[] { rad, rad, rad, rad, rad, rad, rad, rad }, null, null));
    pressedDrawable.getPaint().setColor(maskColor);
    if (Build.VERSION.SDK_INT >= 21) {
        ColorStateList colorStateList = new ColorStateList(new int[][] { StateSet.WILD_CARD }, new int[] { pressedColor });
        return new RippleDrawable(colorStateList, defaultDrawable, pressedDrawable);
    } else {
        StateListDrawable stateListDrawable = new StateListDrawable();
        stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, pressedDrawable);
        stateListDrawable.addState(new int[] { android.R.attr.state_selected }, pressedDrawable);
        stateListDrawable.addState(StateSet.WILD_CARD, defaultDrawable);
        return stateListDrawable;
    }
}
Also used : RoundRectShape(android.graphics.drawable.shapes.RoundRectShape) ShapeDrawable(android.graphics.drawable.ShapeDrawable) ColorStateList(android.content.res.ColorStateList) StateListDrawable(android.graphics.drawable.StateListDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable)

Example 59 with RippleDrawable

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

the class PagerSlidingTabStrip method addIconTab.

private void addIconTab(final int position, Drawable drawable, CharSequence contentDescription) {
    ImageView tab = new ImageView(getContext()) {

        @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            if (pager.getAdapter() instanceof IconTabProvider) {
                ((IconTabProvider) pager.getAdapter()).customOnDraw(canvas, position);
            }
        }

        @Override
        public void setSelected(boolean selected) {
            super.setSelected(selected);
            Drawable background = getBackground();
            if (Build.VERSION.SDK_INT >= 21 && background != null) {
                int color = Theme.getColor(selected ? Theme.key_chat_emojiPanelIconSelected : Theme.key_chat_emojiBottomPanelIcon);
                Theme.setSelectorDrawableColor(background, Color.argb(30, Color.red(color), Color.green(color), Color.blue(color)), true);
            }
        }
    };
    tab.setFocusable(true);
    if (Build.VERSION.SDK_INT >= 21) {
        RippleDrawable rippleDrawable = (RippleDrawable) Theme.createSelectorDrawable(Theme.getColor(Theme.key_chat_emojiBottomPanelIcon));
        Theme.setRippleDrawableForceSoftware(rippleDrawable);
        tab.setBackground(rippleDrawable);
    }
    tab.setImageDrawable(drawable);
    tab.setScaleType(ImageView.ScaleType.CENTER);
    tab.setOnClickListener(v -> {
        if (pager.getAdapter() instanceof IconTabProvider) {
            if (!((IconTabProvider) pager.getAdapter()).canScrollToTab(position)) {
                return;
            }
        }
        pager.setCurrentItem(position, false);
    });
    tabsContainer.addView(tab);
    tab.setSelected(position == currentPosition);
    tab.setContentDescription(contentDescription);
}
Also used : Canvas(android.graphics.Canvas) Drawable(android.graphics.drawable.Drawable) RippleDrawable(android.graphics.drawable.RippleDrawable) ImageView(android.widget.ImageView) Paint(android.graphics.Paint) RippleDrawable(android.graphics.drawable.RippleDrawable)

Example 60 with RippleDrawable

use of android.graphics.drawable.RippleDrawable in project GreenHouse by utsanjan.

the class MaterialCardViewHelper method updateRippleColor.

private void updateRippleColor() {
    Drawable drawable;
    if (!RippleUtils.USE_FRAMEWORK_RIPPLE || (drawable = this.rippleDrawable) == null) {
        MaterialShapeDrawable materialShapeDrawable = this.compatRippleDrawable;
        if (materialShapeDrawable != null) {
            materialShapeDrawable.setFillColor(this.rippleColor);
            return;
        }
        return;
    }
    ((RippleDrawable) drawable).setColor(this.rippleColor);
}
Also used : MaterialShapeDrawable(com.google.android.material.shape.MaterialShapeDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) InsetDrawable(android.graphics.drawable.InsetDrawable) Drawable(android.graphics.drawable.Drawable) MaterialShapeDrawable(com.google.android.material.shape.MaterialShapeDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable) 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