android.graphics.drawable.RippleDrawable Java Examples

The following examples show how to use android.graphics.drawable.RippleDrawable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CircleView.java    From APlayer with GNU General Public License v3.0 6 votes vote down vote up
private void update(@ColorInt int color) {
  innerPaint.setColor(color);
  outerPaint.setColor(shiftColorDown(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}
    };
    int[] colors = new int[]{shiftColorUp(color)};
    ColorStateList rippleColors = new ColorStateList(states, colors);
    setForeground(new RippleDrawable(rippleColors, selector, null));
  } else {
    setForeground(selector);
  }
}
 
Example #2
Source File: DayView.java    From calendarview2 with MIT License 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
    private static Drawable generateRippleDrawable(final int color, Rect bounds) {
        ColorStateList list = ColorStateList.valueOf(color);
        Drawable mask = generateCircleDrawable(Color.WHITE);
        RippleDrawable rippleDrawable = new RippleDrawable(list, null, mask);
//        API 21
        if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) {
            rippleDrawable.setBounds(bounds);
        }

//        API 22. Technically harmless to leave on for API 21 and 23, but not worth risking for 23+
        if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP_MR1) {
            int center = (bounds.left + bounds.right) / 2;
            rippleDrawable.setHotspotBounds(center, bounds.top, center, bounds.bottom);
        }

        return rippleDrawable;
    }
 
Example #3
Source File: Label.java    From clear-todolist with GNU General Public License v3.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void onActionUp() {
    if (mUsingStyle) {
        mBackgroundDrawable = getBackground();
    }

    if (mBackgroundDrawable instanceof StateListDrawable) {
        StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
        drawable.setState(new int[]{});
    } else if (Util.hasLollipop() && mBackgroundDrawable instanceof RippleDrawable) {
        RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
        ripple.setState(new int[]{});
        ripple.setHotspot(getMeasuredWidth() / 2, getMeasuredHeight() / 2);
        ripple.setVisible(true, true);
    }
    setPressed(false);
}
 
Example #4
Source File: OptionBottomSheet.java    From MusicPlayer with GNU General Public License v3.0 6 votes vote down vote up
public void addToBeRipple(int drawable,View... v) {
    if(first_time) {
        first_time = false;
        res = getResources();
    }
    int l = v.length;
    rippleViews.addAll(Arrays.asList(v));
    for(View view :v) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            view.setBackground( (RippleDrawable) res.getDrawable(drawable));
        } else {
            //TODO: setBackground below Android L
        }
        view.setClickable(true);
    }
}
 
Example #5
Source File: BaseSlider.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the color of the halo.
 *
 * @see #getHaloTintList()
 * @attr ref com.google.android.material.R.styleable#Slider_haloColor
 */
public void setHaloTintList(@NonNull ColorStateList haloColor) {
  if (haloColor.equals(this.haloColor)) {
    return;
  }

  this.haloColor = haloColor;
  Drawable background = getBackground();
  if (!shouldDrawCompatHalo() && background instanceof RippleDrawable) {
    ((RippleDrawable) background).setColor(haloColor);
    return;
  }

  haloPaint.setColor(getColorForState(haloColor));
  haloPaint.setAlpha(HALO_ALPHA);
  invalidate();
}
 
Example #6
Source File: CircleView.java    From talk-android with MIT License 6 votes vote down vote up
@SuppressLint("NewApi")
private void update(@ColorInt int color) {
    innerPaint.setColor(color);
    outerPaint.setColor(shiftColorDown(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}
        };
        int[] colors = new int[]{shiftColorUp(color)};
        ColorStateList rippleColors = new ColorStateList(states, colors);
        setForeground(new RippleDrawable(rippleColors, selector, null));
    } else {
        setForeground(selector);
    }
}
 
Example #7
Source File: Label.java    From ShareBox with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #8
Source File: Slice.java    From Slice with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("WeakerAccess")
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public Slice setRipple(@ColorInt final int mask) {
    if (SDK_LOLLIPOP) {
        if (mask != 0) {
            ShapeDrawable shape = new ShapeDrawable(new Shape() {
                @Override
                public void draw(Canvas canvas, Paint paint) {
                    paint.setColor(mask);
                    canvas.drawPath(((CustomRoundRectDrawable) drawable).buildConvexPath(), paint);
                }
            });

            RippleDrawable ripple = new RippleDrawable(buildColorStateList(mask), drawable, shape);
            view.setBackground(ripple);
        } else {
            view.setBackground(drawable);
        }
    } else {
        Log.i(TAG, "setRipple() only work for API 21+");
    }

    return this;
}
 
Example #9
Source File: ColorChooseDialog.java    From AppPlus with MIT License 6 votes vote down vote up
/**
 * 给View设置背景色
 *
 * @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);
    }
}
 
Example #10
Source File: Label.java    From FloatingActionButton with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #11
Source File: Theme.java    From APlayer with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 按下与选中触摸效果
 */
public static StateListDrawable getPressAndSelectedStateListRippleDrawable(Context context,
    Drawable selectDrawable,
    Drawable defaultDrawable,
    @ColorInt int rippleColor) {
  StateListDrawable stateListDrawable = new StateListDrawable();

  if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
    RippleDrawable rippleDrawable = new RippleDrawable(ColorStateList.valueOf(rippleColor),
        defaultDrawable, null);
    stateListDrawable.addState(new int[]{android.R.attr.state_selected}, selectDrawable);
    stateListDrawable.addState(new int[]{}, rippleDrawable);
    return stateListDrawable;
  } else {
    stateListDrawable.addState(new int[]{android.R.attr.state_selected}, selectDrawable);
    stateListDrawable.addState(new int[]{android.R.attr.state_pressed}, selectDrawable);
    stateListDrawable.addState(new int[]{}, defaultDrawable);
    return stateListDrawable;
  }
}
 
Example #12
Source File: FloatingActionButton.java    From ShareBox with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Drawable createFillDrawable() {
    StateListDrawable drawable = new StateListDrawable();
    drawable.addState(new int[]{-android.R.attr.state_enabled}, createCircleDrawable(mColorDisabled));
    drawable.addState(new int[]{android.R.attr.state_pressed}, createCircleDrawable(mColorPressed));
    drawable.addState(new int[]{}, createCircleDrawable(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;
}
 
Example #13
Source File: Label.java    From FloatingActionButton with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
    void onActionUp() {
        if (mUsingStyle) {
            mBackgroundDrawable = getBackground();
        }

        if (mBackgroundDrawable instanceof StateListDrawable) {
            StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
            drawable.setState(new int[]{});
        } else if (Util.hasLollipop() && mBackgroundDrawable instanceof RippleDrawable) {
            RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
            ripple.setState(new int[]{});
            ripple.setHotspot(getMeasuredWidth() / 2, getMeasuredHeight() / 2);
            ripple.setVisible(true, true);
        }
//        setPressed(false);
    }
 
Example #14
Source File: DayView.java    From monthweekmaterialcalendarview with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
    private static Drawable generateRippleDrawable(final int color, Rect bounds) {
        ColorStateList list = ColorStateList.valueOf(color);
        Drawable mask = generateCircleDrawable(Color.WHITE);
        RippleDrawable rippleDrawable = new RippleDrawable(list, null, mask);
//        API 21
        if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) {
            rippleDrawable.setBounds(bounds);
        }

//        API 22. Technically harmless to leave on for API 21 and 23, but not worth risking for 23+
        if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP_MR1) {
            int center = (bounds.left + bounds.right) / 2;
            rippleDrawable.setHotspotBounds(center, bounds.top, center, bounds.bottom);
        }

        return rippleDrawable;
    }
 
Example #15
Source File: DrawableCreator.java    From BackgroundLibrary with Apache License 2.0 6 votes vote down vote up
public Drawable build() {
    GradientDrawable drawable = null;
    StateListDrawable stateListDrawable = null;
    if (hasSelectDrawable) {
        stateListDrawable = getStateListDrawable();
    } else {
        drawable = getGradientDrawable();
    }
    if (rippleEnable && rippleColor != null) {
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Drawable contentDrawable = (stateListDrawable == null ? drawable : stateListDrawable);
            return new RippleDrawable(ColorStateList.valueOf(rippleColor), contentDrawable, contentDrawable);
        } else {
            StateListDrawable resultDrawable = new StateListDrawable();
            GradientDrawable unPressDrawable = getGradientDrawable();
            unPressDrawable.setColor(rippleColor);
            resultDrawable.addState(new int[]{-android.R.attr.state_pressed}, drawable);
            resultDrawable.addState(new int[]{android.R.attr.state_pressed}, unPressDrawable);
            return resultDrawable;
        }
    }

    return drawable == null ? stateListDrawable : drawable;
}
 
Example #16
Source File: DayView.java    From material-calendarview with MIT License 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static Drawable generateRippleDrawable(final int color, Rect bounds) {
  ColorStateList list = ColorStateList.valueOf(color);
  Drawable mask = generateCircleDrawable(Color.WHITE);
  RippleDrawable rippleDrawable = new RippleDrawable(list, null, mask);
  //        API 21
  if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) {
    rippleDrawable.setBounds(bounds);
  }

  //        API 22. Technically harmless to leave on for API 21 and 23, but not worth risking for 23+
  if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP_MR1) {
    int center = (bounds.left + bounds.right) / 2;
    rippleDrawable.setHotspotBounds(center, bounds.top, center, bounds.bottom);
  }

  return rippleDrawable;
}
 
Example #17
Source File: Utils.java    From BottomSheetPickers with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the color on the {@code view}'s {@code selectableItemBackground} or the
 * borderless variant, whichever was set as the background.
 * @param view the view that should have its highlight color changed
 */
public static void setColorControlHighlight(@NonNull View view, @ColorInt int color) {
    Drawable selectableItemBackground = view.getBackground();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
            && selectableItemBackground instanceof RippleDrawable) {
        ((RippleDrawable) selectableItemBackground).setColor(ColorStateList.valueOf(color));
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Utils.isTv(view.getContext())) {
            ((RippleDrawable) selectableItemBackground).setRadius(72);
        }
    } else {
        // Draws the color (src) onto the background (dest) *in the same plane*.
        // That means the color is not overlapping (i.e. on a higher z-plane, covering)
        // the background. That would be done with SRC_OVER.
        // The DrawableCompat tinting APIs *could* be a viable alternative, if you
        // call setTintMode(). Previous attempts using those APIs failed without
        // the tint mode. However, those APIs have the overhead of mutating and wrapping
        // the drawable.
        selectableItemBackground.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    }
}
 
Example #18
Source File: Peek.java    From Android-3DTouch-PeekView with MIT License 6 votes vote down vote up
private void forceRippleAnimation(View view, MotionEvent event) {
    Drawable background = view.getBackground();

    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && background instanceof RippleDrawable) {
        final RippleDrawable rippleDrawable = (RippleDrawable) background;

        rippleDrawable.setState(new int[]{android.R.attr.state_pressed, android.R.attr.state_enabled});
        rippleDrawable.setHotspot(event.getX(), event.getY());

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                rippleDrawable.setState(new int[]{});
            }
        }, 300);
    }
}
 
Example #19
Source File: Slice.java    From Slice with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("WeakerAccess")
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public Slice setRipple(@ColorInt final int mask) {
    if (SDK_LOLLIPOP) {
        if (mask != 0) {
            ShapeDrawable shape = new ShapeDrawable(new Shape() {
                @Override
                public void draw(Canvas canvas, Paint paint) {
                    paint.setColor(mask);
                    canvas.drawPath(((CustomRoundRectDrawable) drawable).buildConvexPath(), paint);
                }
            });

            RippleDrawable ripple = new RippleDrawable(buildColorStateList(mask), drawable, shape);
            view.setBackground(ripple);
        } else {
            view.setBackground(drawable);
        }
    } else {
        Log.i(TAG, "setRipple() only work for API 21+");
    }

    return this;
}
 
Example #20
Source File: Theme.java    From APlayer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 按下触摸效果
 */
public static Drawable getPressDrawable(Drawable defaultDrawable, Drawable effectDrawable,
    @ColorInt int rippleColor, Drawable contentDrawable, Drawable maskDrawable) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    return new RippleDrawable(ColorStateList.valueOf(rippleColor),
        contentDrawable,
        maskDrawable);
  } else {
    StateListDrawable stateListDrawable = new StateListDrawable();
    stateListDrawable.addState(new int[]{android.R.attr.state_pressed}, effectDrawable);
    stateListDrawable.addState(new int[]{}, defaultDrawable);
    return stateListDrawable;
  }
}
 
Example #21
Source File: ViewUtils.java    From materialup with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
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);
}
 
Example #22
Source File: ViewUtils.java    From materialup with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
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 = 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);
    }
    return new RippleDrawable(ColorStateList.valueOf(rippleColor), null,
            bounded ? new ColorDrawable(Color.WHITE) : null);
}
 
Example #23
Source File: ViewUtils.java    From android-proguards with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #24
Source File: FloatingActionButton.java    From ticdesign with Apache License 2.0 5 votes vote down vote up
private RippleDrawable getRippleDrawable() {
    if (getBackground() instanceof CircularProgressContainerDrawable) {
        Drawable content = ((CircularProgressContainerDrawable) getBackground()).getContentDrawable(0);
        if (content instanceof RippleDrawable) {
            return (RippleDrawable) content;
        }
    }
    return null;
}
 
Example #25
Source File: BtnFuncFactory.java    From XposedNavigationBar with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 创建按钮并且设置对应功能
 *
 * @param line
 * @param sc
 */
public void createBtnAndSetFunc(LinearLayout line, ShortCut sc) {
    int iconScale = DataHook.iconScale;
    LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    p.weight = 1;
    p.gravity = Gravity.CENTER;

    Context context = line.getContext();
    ImageView btn = new ImageView(context);

    String iconPath = sc.getIconPath();
    Bitmap iconBitmap = null;
    if (iconPath != null) {
        iconBitmap = ImageUtil.zoomBitmap(iconPath, iconScale);
    }
    if (iconBitmap == null) {
        iconBitmap = ImageUtil.byte2Bitmap(mMapImgRes.get(sc.getCode()));
        iconBitmap = ImageUtil.zommBitmap(iconBitmap, iconScale);
    }
    btn.setImageBitmap(iconBitmap);

    ColorStateList colorStateList = createColorStateList(0xffffffff, 0xffcccccc, 0xff0000ff, 0xffff0000);
    RippleDrawable ripple = new RippleDrawable(colorStateList, null, null);
    btn.setBackground(ripple);
    btn.setScaleType(ImageView.ScaleType.CENTER);
    btn.setOnClickListener(getBtnFuncOfName(sc));
    btn.setOnLongClickListener(getBtnLongFuncOfName(sc.getCode()));

    line.addView(btn, p);
}
 
Example #26
Source File: BackgroundUtilsImplPostLollipop.java    From CameraColorPicker with Apache License 2.0 5 votes vote down vote up
/**
 * Get a ripple drawable.
 *
 * @param normalColor  color assigned to normal state.
 * @param pressedColor color assigned to pressed state.
 * @return well initialize ripple background.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static RippleDrawable getPressedColorRippleDrawable(int normalColor, int pressedColor) {
    return new RippleDrawable(
            ColorStateList.valueOf(pressedColor),
            new ColorDrawable(normalColor),
            new ColorDrawable(Color.WHITE)
    );
}
 
Example #27
Source File: ViewHelper.java    From FastAccess with GNU General Public License v3.0 5 votes vote down vote up
public static Drawable getDrawableSelector(int normalColor, int pressedColor) {
    if (AppHelper.isLollipopOrHigher()) {
        return new RippleDrawable(ColorStateList.valueOf(pressedColor), getRippleMask(normalColor), getRippleMask(normalColor));
    } else {
        return getStateListDrawable(normalColor, pressedColor);
    }
}
 
Example #28
Source File: FloatingActionButton.java    From ShareBox with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void onActionUp() {
    if (mBackgroundDrawable instanceof StateListDrawable) {
        StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
        drawable.setState(new int[]{android.R.attr.state_enabled});
    } else if (Util.hasLollipop()) {
        RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
        ripple.setState(new int[]{android.R.attr.state_enabled});
        ripple.setHotspot(calculateCenterX(), calculateCenterY());
        ripple.setVisible(true, true);
    }
}
 
Example #29
Source File: FloatingActionButton.java    From ShareBox with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void onActionDown() {
    if (mBackgroundDrawable instanceof StateListDrawable) {
        StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
        drawable.setState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed});
    } else if (Util.hasLollipop()) {
        RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
        ripple.setState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed});
        ripple.setHotspot(calculateCenterX(), calculateCenterY());
        ripple.setVisible(true, true);
    }
}
 
Example #30
Source File: BaseSlider.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the radius of the halo in pixels.
 *
 * @see #getHaloRadius()
 * @attr ref com.google.android.material.R.styleable#Slider_haloRadius
 */
public void setHaloRadius(@IntRange(from = 0) @Dimension int radius) {
  if (radius == haloRadius) {
    return;
  }

  haloRadius = radius;
  Drawable background = getBackground();
  if (!shouldDrawCompatHalo() && background instanceof RippleDrawable) {
    DrawableUtils.setRippleDrawableRadius((RippleDrawable) background, haloRadius);
    return;
  }

  postInvalidate();
}