Search in sources :

Example 76 with RippleDrawable

use of android.graphics.drawable.RippleDrawable in project AndroidUtilLib by SiberiaDante.

the class SDRoundViewAttr method setBgSelector.

public void setBgSelector() {
    StateListDrawable bg = new StateListDrawable();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && isRippleEnable) {
        setDrawable(gd_background, backgroundColor, strokeColor);
        RippleDrawable rippleDrawable = new RippleDrawable(getPressedColorSelector(backgroundColor, backgroundPressColor), gd_background, null);
        view.setBackground(rippleDrawable);
    } else {
        setDrawable(gd_background, backgroundColor, strokeColor);
        bg.addState(new int[] { -android.R.attr.state_pressed }, gd_background);
        if (backgroundPressColor != Integer.MAX_VALUE || strokePressColor != Integer.MAX_VALUE) {
            setDrawable(gd_background_press, backgroundPressColor == Integer.MAX_VALUE ? backgroundColor : backgroundPressColor, strokePressColor == Integer.MAX_VALUE ? strokeColor : strokePressColor);
            bg.addState(new int[] { android.R.attr.state_pressed }, gd_background_press);
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            // 16
            view.setBackground(bg);
        } else {
            // noinspection deprecation
            view.setBackgroundDrawable(bg);
        }
    }
    if (view instanceof TextView) {
        if (textPressColor != Integer.MAX_VALUE) {
            ColorStateList textColors = ((TextView) view).getTextColors();
            // Log.d("AAA", textColors.getColorForState(new int[]{-android.R.attr.state_pressed}, -1) + "");
            ColorStateList colorStateList = new ColorStateList(new int[][] { new int[] { -android.R.attr.state_pressed }, new int[] { android.R.attr.state_pressed } }, new int[] { textColors.getDefaultColor(), textPressColor });
            ((TextView) view).setTextColor(colorStateList);
        }
    }
}
Also used : ColorStateList(android.content.res.ColorStateList) TextView(android.widget.TextView) StateListDrawable(android.graphics.drawable.StateListDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable)

Example 77 with RippleDrawable

use of android.graphics.drawable.RippleDrawable in project material-camera by afollestad.

the class BaseCameraFragment method setImageRes.

protected void setImageRes(ImageView iv, @DrawableRes int res) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && iv.getBackground() instanceof RippleDrawable) {
        RippleDrawable rd = (RippleDrawable) iv.getBackground();
        rd.setColor(ColorStateList.valueOf(CameraUtil.adjustAlpha(mIconTextColor, 0.3f)));
    }
    Drawable d = AppCompatResources.getDrawable(iv.getContext(), res);
    d = DrawableCompat.wrap(d.mutate());
    DrawableCompat.setTint(d, mIconTextColor);
    iv.setImageDrawable(d);
}
Also used : Drawable(android.graphics.drawable.Drawable) RippleDrawable(android.graphics.drawable.RippleDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable)

Example 78 with RippleDrawable

use of android.graphics.drawable.RippleDrawable in project material-components-android by material-components.

the class FloatingActionButtonLollipop method setBackgroundDrawable.

@Override
void setBackgroundDrawable(ColorStateList backgroundTint, PorterDuff.Mode backgroundTintMode, int rippleColor, int borderWidth) {
    // Now we need to tint the shape background with the tint
    mShapeDrawable = DrawableCompat.wrap(createShapeDrawable());
    DrawableCompat.setTintList(mShapeDrawable, backgroundTint);
    if (backgroundTintMode != null) {
        DrawableCompat.setTintMode(mShapeDrawable, backgroundTintMode);
    }
    final Drawable rippleContent;
    if (borderWidth > 0) {
        mBorderDrawable = createBorderDrawable(borderWidth, backgroundTint);
        rippleContent = new LayerDrawable(new Drawable[] { mBorderDrawable, mShapeDrawable });
    } else {
        mBorderDrawable = null;
        rippleContent = mShapeDrawable;
    }
    mRippleDrawable = new RippleDrawable(ColorStateList.valueOf(rippleColor), rippleContent, null);
    mContentBackground = mRippleDrawable;
    mShadowViewDelegate.setBackgroundDrawable(mRippleDrawable);
}
Also used : LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) InsetDrawable(android.graphics.drawable.InsetDrawable) Drawable(android.graphics.drawable.Drawable) GradientDrawable(android.graphics.drawable.GradientDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable)

Example 79 with RippleDrawable

use of android.graphics.drawable.RippleDrawable in project FloatingActionButton by Clans.

the class Label method onActionDown.

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void onActionDown() {
    if (mUsingStyle) {
        mBackgroundDrawable = getBackground();
    }
    if (mBackgroundDrawable instanceof StateListDrawable) {
        StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
        drawable.setState(new int[] { android.R.attr.state_pressed });
    } else if (Util.hasLollipop() && mBackgroundDrawable instanceof RippleDrawable) {
        RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
        ripple.setState(new int[] { android.R.attr.state_enabled, android.R.attr.state_pressed });
        ripple.setHotspot(getMeasuredWidth() / 2, getMeasuredHeight() / 2);
        ripple.setVisible(true, true);
    }
//        setPressed(true);
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable) TargetApi(android.annotation.TargetApi)

Example 80 with RippleDrawable

use of android.graphics.drawable.RippleDrawable in project FloatingActionButton by Clans.

the class Label method createFillDrawable.

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Drawable createFillDrawable() {
    StateListDrawable drawable = new StateListDrawable();
    drawable.addState(new int[] { android.R.attr.state_pressed }, createRectDrawable(mColorPressed));
    drawable.addState(new int[] {}, createRectDrawable(mColorNormal));
    if (Util.hasLollipop()) {
        RippleDrawable ripple = new RippleDrawable(new ColorStateList(new int[][] { {} }, new int[] { mColorRipple }), drawable, null);
        setOutlineProvider(new ViewOutlineProvider() {

            @Override
            public void getOutline(View view, Outline outline) {
                outline.setOval(0, 0, view.getWidth(), view.getHeight());
            }
        });
        setClipToOutline(true);
        mBackgroundDrawable = ripple;
        return ripple;
    }
    mBackgroundDrawable = drawable;
    return drawable;
}
Also used : ColorStateList(android.content.res.ColorStateList) Outline(android.graphics.Outline) StateListDrawable(android.graphics.drawable.StateListDrawable) ViewOutlineProvider(android.view.ViewOutlineProvider) View(android.view.View) TextView(android.widget.TextView) RippleDrawable(android.graphics.drawable.RippleDrawable) TargetApi(android.annotation.TargetApi)

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