Example usage for android.graphics.drawable RippleDrawable RippleDrawable

List of usage examples for android.graphics.drawable RippleDrawable RippleDrawable

Introduction

In this page you can find the example usage for android.graphics.drawable RippleDrawable RippleDrawable.

Prototype

public RippleDrawable(@NonNull ColorStateList color, @Nullable Drawable content, @Nullable Drawable mask) 

Source Link

Document

Creates a new ripple drawable with the specified ripple color and optional content and mask drawables.

Usage

From source file:Main.java

public static RippleDrawable getPressedColorRippleDrawable(int paramInt1, int paramInt2) {
    return new RippleDrawable(getPressedColorSelector(paramInt1, paramInt2),
            getColorDrawableFromColor(paramInt1), null);
}

From source file:Main.java

public static RippleDrawable getPressedColorRippleDrawable(int normalColor, int pressedColor) {
    return new RippleDrawable(getPressedColorSelector(normalColor, pressedColor),
            getColorDrawableFromColor(normalColor), null);
}

From source file:Main.java

@NonNull
public static Drawable getAdaptiveRippleDrawable(int normalColor) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return new RippleDrawable(ColorStateList.valueOf(darker(normalColor)), getRippleMask(normalColor),
                null);//w  ww.  java 2  s  .  c o m
    } else {
        return getStateListDrawable(normalColor, darker(normalColor));
    }
}

From source file:Main.java

public static Drawable createRippleDrawable(final View v, final int color, Drawable pressed) {

    Drawable drawable = v.getBackground();

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

        if (drawable instanceof RippleDrawable) {
            drawable = ((RippleDrawable) drawable).getDrawable(0);

            RippleDrawable rippleDrawable = new RippleDrawable(new ColorStateList(
                    new int[][] { new int[] { android.R.attr.state_pressed }, new int[] { 0 } },
                    new int[] { color, 0 }), drawable, null);

            return rippleDrawable;
        } else {/*from  ww  w  .j  av a 2  s. co  m*/
            if (drawable == null) {
                drawable = new ColorDrawable(0);
                v.setBackground(drawable);
                RippleDrawable rippleDrawable = new RippleDrawable(new ColorStateList(
                        new int[][] { new int[] { android.R.attr.state_pressed }, new int[] { 0 } },
                        new int[] { color, 0 }), drawable, new ColorDrawable(0xffffffff));
                return rippleDrawable;
            } else {
                RippleDrawable rippleDrawable = new RippleDrawable(new ColorStateList(
                        new int[][] { new int[] { android.R.attr.state_pressed }, new int[] { 0 } },
                        new int[] { color, 0 }), drawable, null);
                return rippleDrawable;
            }
        }
    } else {

        if (drawable == null) {
            drawable = new ColorDrawable(color);
        }

        if (pressed == null) {
            pressed = drawable;
        }

        StateListDrawable sld = new StateListDrawable();
        sld.addState(new int[] { android.R.attr.state_pressed, }, pressed);

        if (v.getBackground() != null) {
            sld.addState(new int[] { 0, }, drawable);
        }

        return sld;
    }
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@NonNull/*from  www . j a va2  s . c o m*/
private static Drawable getPressedColorRippleDrawable(int normalColor, int pressedColor) {
    Drawable drawable = new RippleDrawable(getPressedColorSelector(normalColor, pressedColor),
            getColorDrawableFromColor(normalColor), null);
    drawable.setAlpha(70);
    return drawable;
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static Drawable getRippleDrawable(int pressedColor, Integer normalColor) {
    ColorStateList colorStateList = getPressedColorSelector(pressedColor);
    Drawable mask, content = null;/*  w w w  . j a  v  a2 s  .  c om*/

    if (null == normalColor) {
        mask = new ShapeDrawable();
    } else {
        content = new ColorDrawable(normalColor);
        mask = getRippleMask(Color.WHITE);
    }
    return new RippleDrawable(colorStateList, content, mask);
}

From source file:net.xpece.android.colorpicker.ColorStateDrawable.java

public static Drawable create(Drawable[] layers, int color, int pressed) {
    if (Build.VERSION.SDK_INT >= 21) {
        LayerDrawable ld = new LayerDrawable(layers);
        ld.setColorFilter(color, PorterDuff.Mode.SRC_IN);
        RippleDrawable rd = new RippleDrawable(ColorStateList.valueOf(pressed), ld, null);
        return rd;
    } else {//from ww  w.  j a  va  2s  .  c  om
        return new ColorStateDrawable(layers, color, pressed);
    }
}

From source file:com.ww.administrator.demotest.util.ViewUtil.java

public static RippleDrawable createRipple(@ColorInt int color, @FloatRange(from = 0f, to = 1f) float alpha,
        boolean bounded) {
    color = ColorUtil.modifyAlpha(color, alpha);
    return new RippleDrawable(ColorStateList.valueOf(color), null,
            bounded ? new ColorDrawable(Color.WHITE) : null);
}

From source file:com.agenmate.lollipop.util.ViewUtils.java

public static RippleDrawable createRipple(@ColorInt int color, @FloatRange(from = 0f, to = 1f) float alpha,
        boolean bounded) {
    color = ColorUtils.modifyAlpha(color, alpha);
    return new RippleDrawable(ColorStateList.valueOf(color), null,
            bounded ? new ColorDrawable(Color.WHITE) : null);
}

From source file:android.support.design.widget.FloatingActionButtonLollipop.java

@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);
    }//from   w ww  . j  a  v a 2s.  c  o  m

    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);
}