java类android.graphics.drawable.RippleDrawable的实例源码

Label.java 文件源码 项目:FloatingActionButtonEx 阅读 25 收藏 0 点赞 0 评论 0
@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;
}
Label.java 文件源码 项目:FloatingActionButtonEx 阅读 26 收藏 0 点赞 0 评论 0
@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);
}
Label.java 文件源码 项目:FloatingActionButtonEx 阅读 33 收藏 0 点赞 0 评论 0
@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);
}
CircleView.java 文件源码 项目:talk-android 阅读 24 收藏 0 点赞 0 评论 0
@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);
    }
}
FloatingActionButtonLollipop.java 文件源码 项目:permissionsModule 阅读 18 收藏 0 点赞 0 评论 0
@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);
}
SideFragment.java 文件源码 项目:android_packages_apps_tv 阅读 21 收藏 0 点赞 0 评论 0
@Override
public void onClick(View view) {
    if (mItem instanceof RadioButtonItem) {
        mAdapter.clearRadioGroup(mItem);
    }
    if (view.getBackground() instanceof RippleDrawable) {
        view.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (mItem != null) {
                    mItem.onSelected();
                }
            }
        }, view.getResources().getInteger(R.integer.side_panel_ripple_anim_duration));
    } else {
        mItem.onSelected();
    }
}
Label.java 文件源码 项目:AndroidProjectsClient 阅读 24 收藏 0 点赞 0 评论 0
@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() && mUsingRipple) {
        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;
}
Label.java 文件源码 项目:AndroidProjectsClient 阅读 30 收藏 0 点赞 0 评论 0
@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);
    }
Label.java 文件源码 项目:AndroidProjectsClient 阅读 28 收藏 0 点赞 0 评论 0
@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);
    }
Slice.java 文件源码 项目:Slice 阅读 35 收藏 0 点赞 0 评论 0
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void setRipple(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+");
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号