Search in sources :

Example 96 with RippleDrawable

use of android.graphics.drawable.RippleDrawable in project Phonograph by kabouzeid.

the class ViewUtil method createSelectorDrawable.

public static Drawable createSelectorDrawable(Context context, @ColorInt int color) {
    final StateListDrawable baseSelector = new StateListDrawable();
    baseSelector.addState(new int[] { android.R.attr.state_activated }, new ColorDrawable(color));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return new RippleDrawable(ColorStateList.valueOf(color), baseSelector, new ColorDrawable(Color.WHITE));
    }
    baseSelector.addState(new int[] {}, new ColorDrawable(Color.TRANSPARENT));
    baseSelector.addState(new int[] { android.R.attr.state_pressed }, new ColorDrawable(color));
    return baseSelector;
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable)

Example 97 with RippleDrawable

use of android.graphics.drawable.RippleDrawable in project material-hijri-calendarview by eltohamy.

the class DayView method generateRippleDrawable.

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static Drawable generateRippleDrawable(final int color) {
    ColorStateList list = ColorStateList.valueOf(color);
    Drawable mask = generateCircleDrawable(Color.WHITE);
    return new RippleDrawable(list, null, mask);
}
Also used : Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable) ColorStateList(android.content.res.ColorStateList) RippleDrawable(android.graphics.drawable.RippleDrawable) TargetApi(android.annotation.TargetApi)

Example 98 with RippleDrawable

use of android.graphics.drawable.RippleDrawable in project PhoneProfiles by henrichg.

the class ColorChooserPreferenceX method onBindViewHolder.

@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
    super.onBindViewHolder(holder);
    FrameLayout layout = (FrameLayout) holder.findViewById(R.id.dialog_color_chooser_pref_color);
    int color = Integer.parseInt(value);
    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(layout, new RippleDrawable(rippleColors, selector, null));
    } else {
        setBackgroundCompat(layout, selector);
    }
    Handler handler = new Handler(context.getMainLooper());
    handler.postDelayed(new Runnable() {

        @Override
        public void run() {
            setSummary(R.string.empty_string);
        }
    }, 200);
}
Also used : FrameLayout(android.widget.FrameLayout) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable) ColorStateList(android.content.res.ColorStateList) Handler(android.os.Handler) RippleDrawable(android.graphics.drawable.RippleDrawable)

Example 99 with RippleDrawable

use of android.graphics.drawable.RippleDrawable in project UIWidget by AriesHoo.

the class RadiusViewDelegate method init.

/**
 * 设置shape属性
 * 设置完所有属性后调用设置背景
 */
public void init() {
    if (mView instanceof EditText) {
        Log.i("v", "click:" + mView.isClickable() + ";enable:" + mView.isEnabled());
    }
    // 获取view当前drawable--用于判断是否通过默认属性设置背景
    Drawable mDrawable = mView.getBackground();
    // 判断是否使用自定义颜色值
    boolean isSetBg = mBackgroundColor != Integer.MAX_VALUE || mBackgroundPressedColor != Integer.MAX_VALUE || mBackgroundDisabledColor != Integer.MAX_VALUE || mBackgroundSelectedColor != Integer.MAX_VALUE || mStrokeWidth > 0 || mRadius > 0 || mTopLeftRadius > 0 || mTopLeftRadius > 0 || mBottomLeftRadius > 0 || mBottomRightRadius > 0;
    setDrawable(mBackgroundChecked, mBackgroundCheckedColor, mStrokeCheckedColor);
    setDrawable(mBackgroundSelected, mBackgroundSelectedColor, mStrokeSelectedColor);
    setDrawable(mBackground, mBackgroundColor, mStrokeColor);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && mRippleEnable && mView.isEnabled() && mView.isClickable()) {
        // 5.0以上且设置水波属性并且可操作
        RippleDrawable rippleDrawable = new RippleDrawable(new ColorStateList(new int[][] { new int[] { mStatePressed }, new int[] {} }, new int[] { mRippleColor != Integer.MAX_VALUE ? mRippleColor : getBackColor(mBackgroundPressedColor), mRippleColor }), getContentDrawable(mDrawable, isSetBg), null);
        mView.setBackground(rippleDrawable);
    } else {
        if (!isSetBg) {
            return;
        }
        setDrawable(mBackgroundPressed, mBackgroundPressedColor, mStrokePressedColor);
        setDrawable(mBackgroundDisabled, mBackgroundDisabledColor, mStrokeDisabledColor);
        StateListDrawable mStateDrawable = new StateListDrawable();
        mStateDrawable.setEnterFadeDuration(mEnterFadeDuration);
        mStateDrawable.setExitFadeDuration(mExitFadeDuration);
        mStateDrawable.addState(new int[] { mStatePressed }, mBackgroundPressed);
        mStateDrawable.addState(new int[] { mStateSelected }, mBackgroundSelected);
        mStateDrawable.addState(new int[] { mStateChecked }, mBackgroundChecked);
        mStateDrawable.addState(new int[] { mStateDisabled }, mBackgroundDisabled);
        // 默认状态--放置在最后否则其它状态不生效
        mStateDrawable.addState(new int[] {}, mBackground);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            mView.setBackground(mStateDrawable);
        } else {
            mView.setBackgroundDrawable(mStateDrawable);
        }
    }
    return;
}
Also used : EditText(android.widget.EditText) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable) ColorStateList(android.content.res.ColorStateList) StateListDrawable(android.graphics.drawable.StateListDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable)

Example 100 with RippleDrawable

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

the class FloatingActionButton method createFillDrawable.

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