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:com.ww.administrator.demotest.util.ViewUtil.java

public static RippleDrawable createRipple(@NonNull Palette palette,
        @FloatRange(from = 0f, to = 1f) float darkAlpha, @FloatRange(from = 0f, to = 1f) float lightAlpha,
        @ColorInt int fallbackColor, boolean bounded) {
    int rippleColor = fallbackColor;
    // try the named swatches in preference order
    if (palette.getVibrantSwatch() != null) {
        rippleColor = ColorUtil.modifyAlpha(palette.getVibrantSwatch().getRgb(), darkAlpha);
    } else if (palette.getLightVibrantSwatch() != null) {
        rippleColor = ColorUtil.modifyAlpha(palette.getLightVibrantSwatch().getRgb(), lightAlpha);
    } else if (palette.getDarkVibrantSwatch() != null) {
        rippleColor = ColorUtil.modifyAlpha(palette.getDarkVibrantSwatch().getRgb(), darkAlpha);
    } else if (palette.getMutedSwatch() != null) {
        rippleColor = ColorUtil.modifyAlpha(palette.getMutedSwatch().getRgb(), darkAlpha);
    } else if (palette.getLightMutedSwatch() != null) {
        rippleColor = ColorUtil.modifyAlpha(palette.getLightMutedSwatch().getRgb(), lightAlpha);
    } else if (palette.getDarkMutedSwatch() != null) {
        rippleColor = ColorUtil.modifyAlpha(palette.getDarkMutedSwatch().getRgb(), darkAlpha);
    }//from   ww  w .jav a  2 s.c o  m
    return new RippleDrawable(ColorStateList.valueOf(rippleColor), null,
            bounded ? new ColorDrawable(Color.WHITE) : null);
}

From source file:jp.tkgktyk.xposed.forcetouchdetector.app.util.fab.FloatingActionButtonLollipop.java

@Override
void setBackgroundDrawable(Drawable originalBackground, ColorStateList backgroundTint,
        PorterDuff.Mode backgroundTintMode, int rippleColor, int borderWidth) {
    // Now we need to tint the original background with the tint
    mShapeDrawable = DrawableCompat.wrap(originalBackground.mutate());
    DrawableCompat.setTintList(mShapeDrawable, backgroundTint);
    if (backgroundTintMode != null) {
        DrawableCompat.setTintMode(mShapeDrawable, backgroundTintMode);
    }//from w w  w.  ja  v a 2s.  com

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

    mShadowViewDelegate.setBackgroundDrawable(mRippleDrawable);
    mShadowViewDelegate.setShadowPadding(0, 0, 0, 0);
}

From source file:com.auth0.android.lock.views.ActionButton.java

private Drawable generateStateBackground(Theme lockTheme) {
    int normalColor = lockTheme.getPrimaryColor(getContext());
    int pressedColor = lockTheme.getDarkPrimaryColor(getContext());
    int disabledColor = ContextCompat.getColor(getContext(), R.color.com_auth0_lock_submit_disabled);

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        return new RippleDrawable(ColorStateList.valueOf(pressedColor), new ColorDrawable(normalColor), null);
    } else {// ww w  .  j a va  2s  . c o m
        StateListDrawable states = new StateListDrawable();
        states.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_pressed },
                new ColorDrawable(pressedColor));
        states.addState(new int[] { android.R.attr.state_enabled }, new ColorDrawable(normalColor));
        states.addState(new int[] {}, new ColorDrawable(disabledColor));
        return states;
    }
}

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

public static RippleDrawable createRipple(@NonNull Palette palette,
        @FloatRange(from = 0f, to = 1f) float darkAlpha, @FloatRange(from = 0f, to = 1f) float lightAlpha,
        @ColorInt int fallbackColor, boolean bounded) {
    int rippleColor = fallbackColor;
    if (palette != null) {
        // try the named swatches in preference order
        if (palette.getVibrantSwatch() != null) {
            rippleColor = ColorUtils.modifyAlpha(palette.getVibrantSwatch().getRgb(), darkAlpha);

        } else if (palette.getLightVibrantSwatch() != null) {
            rippleColor = ColorUtils.modifyAlpha(palette.getLightVibrantSwatch().getRgb(), lightAlpha);
        } else if (palette.getDarkVibrantSwatch() != null) {
            rippleColor = ColorUtils.modifyAlpha(palette.getDarkVibrantSwatch().getRgb(), darkAlpha);
        } else if (palette.getMutedSwatch() != null) {
            rippleColor = ColorUtils.modifyAlpha(palette.getMutedSwatch().getRgb(), darkAlpha);
        } else if (palette.getLightMutedSwatch() != null) {
            rippleColor = ColorUtils.modifyAlpha(palette.getLightMutedSwatch().getRgb(), lightAlpha);
        } else if (palette.getDarkMutedSwatch() != null) {
            rippleColor = ColorUtils.modifyAlpha(palette.getDarkMutedSwatch().getRgb(), darkAlpha);
        }/* w  ww  .  ja v  a  2  s  .  co  m*/
    }
    return new RippleDrawable(ColorStateList.valueOf(rippleColor), null,
            bounded ? new ColorDrawable(Color.WHITE) : null);
}

From source file:org.opensilk.common.ui.widget.FloatingActionButton.java

/**
 * >= api 21/*w  ww  .j a  v a 2 s.co m*/
 */
@SuppressWarnings("NewApi")
protected RippleDrawable createRippleDrawable() {
    ShapeDrawable drawable = new ShapeDrawable(new OvalShape());
    drawable.getPaint().setColor(mColorNormal);
    return new RippleDrawable(createRippleStateList(), drawable, null);
}

From source file:com.gudong.appkit.ui.fragment.ColorChooseDialog.java

/**
 * View//from  w ww.  j  a  v  a2s.co m
 *
 * @param view
 * @param color
 */
private void setBackgroundSelector(View view, int color) {
    Drawable selector = createSelector(color);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        int[][] states = new int[][] { new int[] { -android.R.attr.state_pressed },
                new int[] { android.R.attr.state_pressed } };
        int[] colors = new int[] { shiftColor(color), color };
        ColorStateList rippleColors = new ColorStateList(states, colors);
        setBackgroundCompat(view, new RippleDrawable(rippleColors, selector, null));
    } else {
        setBackgroundCompat(view, selector);
    }
}

From source file:com.flexible.flexibleadapter.utils.DrawableUtils.java

/**
 * Helper to get a custom selectable background with Ripple if device has at least Lollipop.
 *
 * @param normalColor  the color in normal state
 * @param pressedColor the pressed color
 * @param rippleColor  the color of the ripple
 * @return the RippleDrawable with StateListDrawable if at least Lollipop, the normal
 * StateListDrawable otherwise//from  w w w . j  a v  a  2s .  c o  m
 * @since 5.0.0-b7 Created
 * <br/>5.0.0-rc1 RippleColor becomes the 3rd parameter
 */
public static Drawable getSelectableBackgroundCompat(@ColorInt int normalColor, @ColorInt int pressedColor,
        @ColorInt int rippleColor) {
    if (Utils.hasLollipop()) {
        return new RippleDrawable(ColorStateList.valueOf(rippleColor),
                getStateListDrawable(normalColor, pressedColor), getRippleMask(normalColor));
    } else {
        return getStateListDrawable(normalColor, pressedColor);
    }
}

From source file:com.appeaser.sublimepickerlibrary.utilities.SUtils.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static Drawable createButtonRippleBg(Context context, int colorButtonNormal,
        int colorControlHighlight) {
    return new RippleDrawable(ColorStateList.valueOf(colorControlHighlight), null,
            createButtonShape(context, colorButtonNormal));
}

From source file:com.flexible.flexibleadapter.utils.DrawableUtils.java

/**
 * Adds a ripple effect to any background.
 *
 * @param drawable    any background drawable
 * @param rippleColor the color of the ripple
 * @return the RippleDrawable with the chosen background drawable if at least Lollipop,
 * the provided drawable otherwise/*from   w ww. j  a  v  a  2 s  .  c o m*/
 * @since 5.0.0-rc1
 */
public static Drawable getRippleDrawable(Drawable drawable, @ColorInt int rippleColor) {
    if (Utils.hasLollipop()) {
        return new RippleDrawable(ColorStateList.valueOf(rippleColor), drawable, getRippleMask(Color.BLACK));
    } else {
        return drawable;
    }
}

From source file:ticwear.design.widget.FloatingActionButton.java

public FloatingActionButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    mProgressPadding = new Rect();
    mTouchArea = new Rect();

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionButton, defStyleAttr,
            defStyleRes);/* w ww  .  j a v a  2  s.c  o m*/
    int rippleColor = a.getColor(R.styleable.FloatingActionButton_tic_rippleColor, 0);
    mSize = a.getInt(R.styleable.FloatingActionButton_tic_fabSize, SIZE_NORMAL);
    final float pressedTranslationZ = a.getDimension(R.styleable.FloatingActionButton_tic_pressedTranslationZ,
            0f);

    int resId = a.getResourceId(R.styleable.FloatingActionButton_tic_circularDrawableStyle, 0);

    int translationX = a.getDimensionPixelOffset(R.styleable.FloatingActionButton_tic_minimizeTranslationX, 0);
    int translationY = a.getDimensionPixelOffset(R.styleable.FloatingActionButton_tic_minimizeTranslationY, 0);

    a.recycle();

    Drawable shapeDrawable = createShapeDrawable();
    Drawable rippleDrawable = new RippleDrawable(ColorStateList.valueOf(rippleColor), shapeDrawable, null);

    CircularProgressDrawable progressDrawable = createProgressDrawable(context, resId);

    Drawable backgroundDrawable = new CircularProgressContainerDrawable(new Drawable[] { rippleDrawable },
            progressDrawable);
    super.setBackgroundDrawable(backgroundDrawable);

    int strokeSize = progressDrawable.getStrokeSize();
    mProgressPadding.left = strokeSize;
    mProgressPadding.right = strokeSize;
    mProgressPadding.top = strokeSize;
    mProgressPadding.bottom = strokeSize;

    final int maxImageSize = (int) getResources().getDimension(R.dimen.tic_design_fab_image_size);
    mImagePadding = (getSizeDimension() + mProgressPadding.left + mProgressPadding.right - maxImageSize) / 2;
    setPadding(mImagePadding, mImagePadding, mImagePadding, mImagePadding);

    mAnimator = new FloatingActionButtonAnimator(this);
    mAnimator.setPressedTranslationZ(pressedTranslationZ);
    setMinimizeTranslation(translationX, translationY);

    mShowProgress = false;
}