Search in sources :

Example 16 with ShapeDrawable

use of android.graphics.drawable.ShapeDrawable in project PhotoNoter by yydcdut.

the class FloatingActionButton method createOuterStrokeDrawable.

/**
     * 绘制外层的drawable
     * 就是画边框
     *
     * @param strokeWidth
     * @return
     */
private Drawable createOuterStrokeDrawable(float strokeWidth) {
    //圆
    ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());
    //笔
    final Paint paint = shapeDrawable.getPaint();
    //锯齿
    paint.setAntiAlias(true);
    //描边宽度
    paint.setStrokeWidth(strokeWidth);
    //描边style,就是中空
    paint.setStyle(Style.STROKE);
    //颜色黑色,用来画边框
    paint.setColor(Color.BLACK);
    //透明度
    paint.setAlpha(opacityToAlpha(0.02f));
    return shapeDrawable;
}
Also used : ShapeDrawable(android.graphics.drawable.ShapeDrawable) Paint(android.graphics.Paint) OvalShape(android.graphics.drawable.shapes.OvalShape)

Example 17 with ShapeDrawable

use of android.graphics.drawable.ShapeDrawable in project PhotoNoter by yydcdut.

the class FloatingActionButton method createInnerStrokesDrawable.

/**
     * 创建内层drawable
     *
     * @param color
     * @param strokeWidth
     * @return
     */
private Drawable createInnerStrokesDrawable(final int color, float strokeWidth) {
    //不描边的话直接返回一个颜色为透明的drawable
    if (!mStrokeVisible) {
        return new ColorDrawable(Color.TRANSPARENT);
    }
    //圆 drawable
    ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());
    //这个暗颜色
    final int bottomStrokeColor = darkenColor(color);
    //比bottomStrokeColor透明一半
    final int bottomStrokeColorHalfTransparent = halfTransparent(bottomStrokeColor);
    //这个亮颜色
    final int topStrokeColor = lightenColor(color);
    //比topStrokeColor透明一半
    final int topStrokeColorHalfTransparent = halfTransparent(topStrokeColor);
    final Paint paint = shapeDrawable.getPaint();
    //锯齿
    paint.setAntiAlias(true);
    //描边宽度
    paint.setStrokeWidth(strokeWidth);
    //描边
    paint.setStyle(Style.STROKE);
    //draws a linear gradient
    shapeDrawable.setShaderFactory(new ShaderFactory() {

        @Override
        public Shader resize(int width, int height) {
            return new LinearGradient(width / 2, 0, width / 2, height, new int[] { topStrokeColor, topStrokeColorHalfTransparent, color, bottomStrokeColorHalfTransparent, bottomStrokeColor }, new float[] { 0f, 0.2f, 0.5f, 0.8f, 1f }, TileMode.CLAMP);
        }
    });
    return shapeDrawable;
}
Also used : LinearGradient(android.graphics.LinearGradient) ShaderFactory(android.graphics.drawable.ShapeDrawable.ShaderFactory) ColorDrawable(android.graphics.drawable.ColorDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) Paint(android.graphics.Paint) OvalShape(android.graphics.drawable.shapes.OvalShape) Shader(android.graphics.Shader) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Example 18 with ShapeDrawable

use of android.graphics.drawable.ShapeDrawable in project Genius-Android by qiujuer.

the class EditText method initBackground.

private void initBackground() {
    final int lineSize = getLineSize();
    Drawable background;
    if (lineSize == 0) {
        background = null;
    } else {
        int increment = getResources().getDimensionPixelSize(R.dimen.g_editText_lineSize_active_increment);
        int lineActive = lineSize + increment;
        int lineHalf = lineSize >> 1;
        // Creating normal state drawable
        ShapeDrawable normal = new ShapeDrawable(new BorderShape(new RectF(0, 0, 0, lineSize)));
        normal.getPaint().setColor(getLineColor(new int[] { android.R.attr.state_enabled }));
        // Creating pressed state drawable
        ShapeDrawable pressed = new ShapeDrawable(new BorderShape(new RectF(0, 0, 0, lineActive)));
        pressed.getPaint().setColor(getLineColor(new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled }));
        // Creating focused state drawable
        ShapeDrawable focused = new ShapeDrawable(new BorderShape(new RectF(0, 0, 0, lineActive)));
        focused.getPaint().setColor(getLineColor(new int[] { android.R.attr.state_focused, android.R.attr.state_enabled }));
        // Creating disabled state drawable
        ShapeDrawable disabled = new ShapeDrawable(new BorderShape(new RectF(0, 0, 0, lineHalf), lineHalf, lineSize));
        disabled.getPaint().setColor(getLineColor(new int[] { -android.R.attr.state_enabled }));
        // disabled.getPaint().setAlpha(0xA0);
        Drawable[] drawable = new Drawable[] { pressed, focused, normal, disabled };
        background = createStateListDrawable(drawable);
    }
    // Set Background
    UiCompat.setBackground(this, background);
}
Also used : RectF(android.graphics.RectF) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) BorderShape(net.qiujuer.genius.ui.drawable.shape.BorderShape) ShapeDrawable(android.graphics.drawable.ShapeDrawable) SuppressLint(android.annotation.SuppressLint) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 19 with ShapeDrawable

use of android.graphics.drawable.ShapeDrawable in project FlyRefresh by race604.

the class PullHeaderLayout method setActionDrawable.

public void setActionDrawable(Drawable actionDrawable) {
    mActionDrawable = actionDrawable;
    if (mActionDrawable != null) {
        if (mActionView == null) {
            final int bgColor = UIUtils.getThemeColorFromAttrOrRes(getContext(), R.attr.colorAccent, R.color.accent);
            final int pressedColor = UIUtils.darkerColor(bgColor, 0.8f);
            final ShapeDrawable bgDrawable = new ShapeDrawable(new OvalShape());
            bgDrawable.getPaint().setColor(bgColor);
            mActionView = new FloatingActionButton(getContext());
            mActionView.setRippleColor(pressedColor);
            mActionView.setBackgroundDrawable(bgDrawable);
            addView(mActionView, new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        }
        if (mFlyView == null) {
            mFlyView = new ImageView(getContext());
            mFlyView.setScaleType(ImageView.ScaleType.FIT_XY);
            addView(mFlyView, new LayoutParams(ACTION_ICON_SIZE, ACTION_ICON_SIZE));
            mFlyView.bringToFront();
            float elevation = ViewCompat.getElevation(mActionView);
            ViewCompat.setElevation(mFlyView, elevation + 1);
        }
        mFlyView.setImageDrawable(mActionDrawable);
    } else {
        if (mActionView != null) {
            removeView(mActionView);
            removeView(mFlyView);
            mActionView = null;
            mFlyView = null;
        }
    }
}
Also used : ShapeDrawable(android.graphics.drawable.ShapeDrawable) FloatingActionButton(android.support.design.widget.FloatingActionButton) ImageView(android.widget.ImageView) OvalShape(android.graphics.drawable.shapes.OvalShape)

Example 20 with ShapeDrawable

use of android.graphics.drawable.ShapeDrawable in project MusicVideoPlayer by MartingKing.

the class CircleImageView method setBackgroundColor.

/**
 * Update the background color of the circle image view.
 */
public void setBackgroundColor(int colorRes) {
    if (getBackground() instanceof ShapeDrawable) {
        final Resources res = getResources();
        ((ShapeDrawable) getBackground()).getPaint().setColor(res.getColor(R.color.green));
    }
}
Also used : ShapeDrawable(android.graphics.drawable.ShapeDrawable) Resources(android.content.res.Resources)

Aggregations

ShapeDrawable (android.graphics.drawable.ShapeDrawable)131 OvalShape (android.graphics.drawable.shapes.OvalShape)64 Paint (android.graphics.Paint)38 Drawable (android.graphics.drawable.Drawable)30 LayerDrawable (android.graphics.drawable.LayerDrawable)28 SuppressLint (android.annotation.SuppressLint)20 RoundRectShape (android.graphics.drawable.shapes.RoundRectShape)20 StateListDrawable (android.graphics.drawable.StateListDrawable)18 ClipDrawable (android.graphics.drawable.ClipDrawable)17 Bitmap (android.graphics.Bitmap)16 BitmapDrawable (android.graphics.drawable.BitmapDrawable)16 BitmapShader (android.graphics.BitmapShader)15 AnimationDrawable (android.graphics.drawable.AnimationDrawable)14 ColorDrawable (android.graphics.drawable.ColorDrawable)11 RectShape (android.graphics.drawable.shapes.RectShape)10 Resources (android.content.res.Resources)8 Shape (android.graphics.drawable.shapes.Shape)8 Canvas (android.graphics.Canvas)6 Shader (android.graphics.Shader)6 ImageView (android.widget.ImageView)6