Java 类android.graphics.drawable.shapes.Shape 实例源码

项目:RLibrary    文件:ResUtil.java   
/**
 * Generate bg drawable drawable.
 *
 * @param pressColor   the press color
 * @param defaultColor the default color
 * @return the drawable
 */
public static Drawable generateRoundDrawable(float radii, int pressColor, int defaultColor) {
    //圆角
    Shape roundRectShape = new RoundRectShape(new float[]{radii, radii, radii, radii, radii, radii, radii, radii}, null, null);//圆角背景

    //按下状态
    ShapeDrawable shopDrawablePress = new ShapeDrawable(roundRectShape);//圆角shape
    shopDrawablePress.getPaint().setColor(pressColor);//设置颜色

    //正常状态
    ShapeDrawable shopDrawableNormal = new ShapeDrawable(roundRectShape);
    shopDrawableNormal.getPaint().setColor(defaultColor);

    StateListDrawable bgStateDrawable = new StateListDrawable();//状态shape
    bgStateDrawable.addState(new int[]{android.R.attr.state_pressed}, shopDrawablePress);//按下状态
    bgStateDrawable.addState(new int[]{-android.R.attr.state_enabled}, shopDrawablePress);
    bgStateDrawable.addState(new int[]{}, shopDrawableNormal);//其他状态

    return bgStateDrawable;
}
项目:RLibrary    文件:ResUtil.java   
public static Drawable generateRoundDrawable(float radii, int pressColor, int disableColor, int defaultColor) {
    //圆角
    Shape roundRectShape = new RoundRectShape(new float[]{radii, radii, radii, radii, radii, radii, radii, radii}, null, null);//圆角背景

    //按下状态
    ShapeDrawable shopDrawablePress = new ShapeDrawable(roundRectShape);//圆角shape
    shopDrawablePress.getPaint().setColor(pressColor);//设置颜色

    //正常状态
    ShapeDrawable shopDrawableNormal = new ShapeDrawable(roundRectShape);
    shopDrawableNormal.getPaint().setColor(defaultColor);

    //禁用状态
    ShapeDrawable disableDrawableNormal = new ShapeDrawable(roundRectShape);
    disableDrawableNormal.getPaint().setColor(disableColor);

    StateListDrawable bgStateDrawable = new StateListDrawable();//状态shape
    bgStateDrawable.addState(new int[]{-android.R.attr.state_enabled}, disableDrawableNormal);//
    bgStateDrawable.addState(new int[]{android.R.attr.state_pressed}, shopDrawablePress);//按下状态
    bgStateDrawable.addState(new int[]{}, shopDrawableNormal);//其他状态

    return bgStateDrawable;
}
项目:RLibrary    文件:ResUtil.java   
/**
 * Generate bg drawable drawable.
 *
 * @param radii        the radii
 * @param pressColor   the press color
 * @param defaultColor the default color
 * @return the drawable
 */
public static Drawable generateRoundDrawable(Resources res, float radii, int pressColor, int defaultColor) {

    radii = dpToPx(res, radii);

    //外环的圆角矩形
    float[] outRadii = new float[]{radii, radii, radii, radii, radii, radii, radii, radii};//四个角的 圆角幅度,8个可以设置的值,每个角都有2个边 2*4=8个

    //按下状态
    Shape roundRectShape = new RoundRectShape(outRadii, null, null);//圆角背景
    ShapeDrawable shopDrawablePress = new ShapeDrawable(roundRectShape);//圆角shape
    shopDrawablePress.getPaint().setColor(pressColor);//设置颜色

    //正常状态
    Shape roundRectShapeNormal = new RoundRectShape(outRadii, null, null);
    ShapeDrawable shopDrawableNormal = new ShapeDrawable(roundRectShapeNormal);
    shopDrawableNormal.getPaint().setColor(defaultColor);

    StateListDrawable bgStateDrawable = new StateListDrawable();//状态shape
    bgStateDrawable.addState(new int[]{android.R.attr.state_pressed}, shopDrawablePress);//按下状态
    bgStateDrawable.addState(new int[]{}, shopDrawableNormal);//其他状态

    return bgStateDrawable;
}
项目:RLibrary    文件:ResUtil.java   
public static Drawable generateRoundDrawable(float rL1, float rL2, float rT1, float rT2,
                                             float rR1, float rR2, float rB1, float rB2,
                                             int pressColor, int defaultColor) {
    //外环的圆角矩形
    float[] outRadii = new float[]{rL1, rL2, rT1, rT2, rR1, rR2, rB1, rB2};//四个角的 圆角幅度,8个可以设置的值,每个角都有2个边 2*4=8个

    //与内环的距离
    RectF inset = new RectF(0, 0, 0, 0);

    //按下状态
    Shape roundRectShape = new RoundRectShape(outRadii, inset, null);//圆角背景
    ShapeDrawable shopDrawablePress = new ShapeDrawable(roundRectShape);//圆角shape
    shopDrawablePress.getPaint().setColor(pressColor);//设置颜色

    //正常状态
    Shape roundRectShapeNormal = new RoundRectShape(outRadii, inset, null);
    ShapeDrawable shopDrawableNormal = new ShapeDrawable(roundRectShapeNormal);
    shopDrawableNormal.getPaint().setColor(defaultColor);

    StateListDrawable bgStateDrawable = new StateListDrawable();//状态shape
    bgStateDrawable.addState(new int[]{android.R.attr.state_pressed}, shopDrawablePress);//按下状态
    bgStateDrawable.addState(new int[]{}, shopDrawableNormal);//其他状态

    return bgStateDrawable;
}
项目:RLibrary    文件:ResUtil.java   
public static Drawable generateRoundDrawable(float radiiL, float radiiR, int pressColor, int defaultColor) {
    //外环的圆角矩形
    float[] outRadii = new float[]{radiiL, radiiL, radiiR, radiiR, radiiR, radiiR, radiiL, radiiL};//四个角的 圆角幅度,8个可以设置的值,每个角都有2个边 2*4=8个

    //与内环的距离
    RectF inset = new RectF(0, 0, 0, 0);

    //按下状态
    Shape roundRectShape = new RoundRectShape(outRadii, inset, null);//圆角背景
    ShapeDrawable shopDrawablePress = new ShapeDrawable(roundRectShape);//圆角shape
    shopDrawablePress.getPaint().setColor(pressColor);//设置颜色

    //正常状态
    Shape roundRectShapeNormal = new RoundRectShape(outRadii, inset, null);
    ShapeDrawable shopDrawableNormal = new ShapeDrawable(roundRectShapeNormal);
    shopDrawableNormal.getPaint().setColor(defaultColor);

    StateListDrawable bgStateDrawable = new StateListDrawable();//状态shape
    bgStateDrawable.addState(new int[]{android.R.attr.state_pressed}, shopDrawablePress);//按下状态
    bgStateDrawable.addState(new int[]{}, shopDrawableNormal);//其他状态

    return bgStateDrawable;
}
项目:RLibrary    文件:ResUtil.java   
/**
 * 正常 圆角边框;
 * 按下 圆角色块
 */
public static Drawable generateBorderDrawable(float radii, float borderWidth, int pressColor, int defaultColor) {

    //外环的圆角矩形
    float[] outRadii = new float[]{radii, radii, radii, radii, radii, radii, radii, radii};//四个角的 圆角幅度,8个可以设置的值,每个角都有2个边 2*4=8个
    RectF inset = new RectF(borderWidth, borderWidth, borderWidth, borderWidth);

    //按下状态
    Shape roundRectShape = new RoundRectShape(outRadii, null, null);//圆角背景
    ShapeDrawable shopDrawablePress = new ShapeDrawable(roundRectShape);//圆角shape
    shopDrawablePress.getPaint().setColor(pressColor);//设置颜色

    //正常状态
    Shape roundRectShapeNormal = new RoundRectShape(outRadii, inset, outRadii);
    ShapeDrawable shopDrawableNormal = new ShapeDrawable(roundRectShapeNormal);
    shopDrawableNormal.getPaint().setColor(defaultColor);

    StateListDrawable bgStateDrawable = new StateListDrawable();//状态shape
    bgStateDrawable.addState(new int[]{android.R.attr.state_pressed}, shopDrawablePress);//按下状态
    bgStateDrawable.addState(new int[]{}, shopDrawableNormal);//其他状态

    return bgStateDrawable;
}
项目:libcommon    文件:BrushDrawable.java   
/**
     * #drawをOverrideしても良いけど、色々処理をしているので#onDrawの方をOverrideする
     * (#onDrawは#drawから呼び出される)
     */
    @Override
    protected void onDraw(final Shape shape, final Canvas canvas, final Paint paint) {
        canvas.rotate(mRotation, mPivot.x, mPivot.y);
        // これを入れると背景が透過する(backgroundの指定してても見えなくなる)
//      canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
        final int count = canvas.save();
//      final DrawFilter org = canvas.getDrawFilter();
        try {
//          canvas.setDrawFilter(mDrawFilter);
            mPaint.setShader(mShader);
/*          paint.setColor(Color.TRANSPARENT);  // 消しゴムの時
            paint.setXfermode(mClearXfermode); */
//          canvas.drawPaint(mPaint);
            super.onDraw(shape, canvas, paint); // 描画自体は上位に任せる(実際はShape#drawに任せる)
        } finally {
//          canvas.setDrawFilter(org);
            canvas.restoreToCount(count);
        }
    }
项目:Slice    文件:Slice.java   
@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+");
    }
}
项目:FriendCircle    文件:DotWidget.java   
@Override
protected void onDraw(Shape shape, Canvas canvas, Paint paint) {
    super.onDraw(shape, canvas, paint);
    if (!TextUtils.isEmpty(text)) {

        Rect r = getBounds();
        if (dotTextSize == 0) {
            dotTextSize = (int) (r.width() * 0.5);
            textPaint.setTextSize(dotTextSize);
        }
        //保证文字居中
        Paint.FontMetricsInt fontMetrics = textPaint.getFontMetricsInt();
        int baseline = r.top + (r.bottom - r.top - fontMetrics.bottom + fontMetrics.top) / 2 - fontMetrics.top;
        textPaint.setTextAlign(Paint.Align.CENTER);
        canvas.drawText(text, r.centerX(), baseline, textPaint);
    }
}
项目:Slice    文件:Slice.java   
@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+");
    }
}
项目:Klyph    文件:ProfileImageView.java   
public BorderDrawable(String shapeType, final int borderColor, final int borderWidth)
{
    super();

    final Shape shape = shapeType.equals(RECT) ? new RectShape() : new OvalShape();

    final ShapeDrawable transparentShape = new ShapeDrawable(shape);
    transparentShape.getPaint().setColor(0x00000000);// Transparent

    final GradientDrawable shapeDrawable = new GradientDrawable();
    shapeDrawable.setShape(shapeType.equals(RECT) ? GradientDrawable.RECTANGLE : GradientDrawable.OVAL);
    shapeDrawable.setStroke(borderWidth, borderColor);

    addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_focused, -android.R.attr.state_pressed }, shapeDrawable);
    addState(new int[] { android.R.attr.state_enabled, -android.R.attr.state_focused, android.R.attr.state_pressed }, shapeDrawable);
    addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_focused, android.R.attr.state_pressed }, shapeDrawable);
    addState(new int[] {}, transparentShape);
}
项目:CEFCommon    文件:MSDrawable.java   
private void set(@Nullable Drawable bitmapDrawable, @Nullable Bitmap bitmap, @Nullable Shape shape, int state, int color) {
        if (bitmapDrawable != null || bitmap != null || shape != null) {
            mMode = Mode.MULTI_ICON;
        }
        mColors[state] = color;
//        mShapes[state] = shape;
        mShapeDrawables[state] = shape != null ? new ShapeDrawable(shape) : null;
        if (bitmapDrawable == null && bitmap != null) {
            mBitmapDrawables[state] = null;
            mBitmaps[state] = bitmap;
            mFinal[state] = null;
        } else if (bitmapDrawable instanceof BitmapDrawable) {
            mBitmapDrawables[state] = (BitmapDrawable) bitmapDrawable;
            mBitmaps[state] = bitmap;
            mFinal[state] = null;
        } else {
            mBitmapDrawables[state] = null;
            mBitmaps[state] = null;
            mFinal[state] = bitmapDrawable;
        }
    }
项目:KlyphMessenger    文件:ProfileImageView.java   
public BorderDrawable(String shapeType, final int borderColor, final int borderWidth)
{
    super();

    final Shape shape = shapeType.equals(RECT) ? new RectShape() : new OvalShape();

    final ShapeDrawable transparentShape = new ShapeDrawable(shape);
    transparentShape.getPaint().setColor(0x00000000);// Transparent

    final GradientDrawable shapeDrawable = new GradientDrawable();
    shapeDrawable.setShape(shapeType.equals(RECT) ? GradientDrawable.RECTANGLE : GradientDrawable.OVAL);
    shapeDrawable.setStroke(borderWidth, borderColor);

    addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_focused, -android.R.attr.state_pressed }, shapeDrawable);
    addState(new int[] { android.R.attr.state_enabled, -android.R.attr.state_focused, android.R.attr.state_pressed }, shapeDrawable);
    addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_focused, android.R.attr.state_pressed }, shapeDrawable);
    addState(new int[] {}, transparentShape);
}
项目:geoPingProject    文件:PersonColorDrawableHelper.java   
protected void onDraw(Shape shape, Canvas canvas, Paint paint) {
    // V1
    shape.draw(canvas, fillpaint);
    shape.draw(canvas, strokepaint);

    // V2
    // shape.resize(canvas.getClipBounds().right,
    // canvas.getClipBounds().bottom);
    // shape.draw(canvas, fillpaint);
    //
    // Matrix matrix = new Matrix();
    // matrix.setRectToRect(new RectF(0, 0,
    // canvas.getClipBounds().right, canvas.getClipBounds().bottom), new
    // RectF(strokeWidth / 2, strokeWidth / 2,
    // canvas.getClipBounds().right - strokeWidth
    // / 2, canvas.getClipBounds().bottom - strokeWidth / 2),
    // Matrix.ScaleToFit.FILL);
    // canvas.concat(matrix);
    //
    // shape.draw(canvas, strokepaint);
}
项目:geoPingProject    文件:PersonColorDrawableHelper.java   
public BubbleBackgroudShapeDrawable(Shape s,final int fill, int stroke, int strokeWidth) {
            super(s);
            this.strokeWidth = strokeWidth;
            fillpaint =  this.getPaint();
//            fillpaint.setColor(fill);
            final Rect r = getBounds();
//            fillpaint.setShader(new LinearGradient(0, r.width(), 0, 0,  fill, Color.WHITE, Shader.TileMode.MIRROR));
            ShapeDrawable.ShaderFactory sf = new ShapeDrawable.ShaderFactory() {
                @Override
                public Shader resize(int width, int height) { 
                    LinearGradient lg =   new LinearGradient(0, width, 0, 0,  Color.WHITE,  fill, Shader.TileMode.REPEAT);
                    return lg;
                }
            };
            setShaderFactory(sf);
            strokepaint = new Paint(fillpaint);
            strokepaint.setStyle(Paint.Style.STROKE);
            strokepaint.setStrokeWidth(strokeWidth);
            strokepaint.setColor(stroke);
        }
项目:geoPingProject    文件:PersonColorDrawableHelper.java   
protected void onDraw(Shape shape, Canvas canvas, Paint paint) {
    // V1
    shape.draw(canvas, fillpaint);
    shape.draw(canvas, strokepaint);

    // V2
    // shape.resize(canvas.getClipBounds().right,
    // canvas.getClipBounds().bottom);
    // shape.draw(canvas, fillpaint);
    //
    // Matrix matrix = new Matrix();
    // matrix.setRectToRect(new RectF(0, 0,
    // canvas.getClipBounds().right, canvas.getClipBounds().bottom), new
    // RectF(strokeWidth / 2, strokeWidth / 2,
    // canvas.getClipBounds().right - strokeWidth
    // / 2, canvas.getClipBounds().bottom - strokeWidth / 2),
    // Matrix.ScaleToFit.FILL);
    // canvas.concat(matrix);
    //
    // shape.draw(canvas, strokepaint);
}
项目:buddycloud-android    文件:TooltipErrorView.java   
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
@Override
public boolean onPreDraw() {

    mContentHolder.measure(getMeasuredWidth(), getTextHeight() + mPointHeightPx);

    Shape shape = getTooltipShape();
    ShapeDrawable d = new ShapeDrawable(shape);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        mContentHolder.setBackground(d);
    } else {
        mContentHolder.setBackgroundDrawable(d);
    }

    return true;
}
项目:CalendarLMS    文件:CalendarAdapter.java   
@Override
protected void onDraw(Shape shape, Canvas canvas, Paint paint) {
    paint.setColor(this.fill);
    canvas.drawRect(canvas.getClipBounds(), paint);

    // border
    paint.setColor(this.stroke);

    // left border
    if (column != 0) {
        canvas.drawLine(0, 0, 0, canvas.getClipBounds().bottom, paint);
    }

    // right border
    //canvas.drawLine(canvas.getClipBounds().right - 1, 0, canvas.getClipBounds().right - 1, canvas.getClipBounds().bottom, paint);

    // top border
    if (row != 0) {
        canvas.drawLine(0, 0, canvas.getClipBounds().right, 0, paint);
    }

    // bottom border
    //canvas.drawLine(0, canvas.getClipBounds().bottom - 1, canvas.getClipBounds().right, canvas.getClipBounds().bottom - 1, paint);
}
项目:GitHub    文件:DefaultSectionAdapter.java   
public BottomBorderBackground(Shape s, int fill, int stroke) {
    super(s);
    fillpaint = new Paint(this.getPaint());
    fillpaint.setColor(fill);
    strokepaint = new Paint(fillpaint);
    strokepaint.setStyle(Paint.Style.STROKE);
    strokepaint.setStrokeWidth(2);
    strokepaint.setColor(stroke);
}
项目:SOS-The-Healthcare-Companion    文件:ContactBadge.java   
private void initOverlay(Context context, Shape shape) {
    // pressed state
    TypedValue typedValue = new TypedValue();
    Theme theme = context.getTheme();

    mPressedOverlay = new ShapeDrawable(shape);
    int overlayColor = Color.parseColor("#aa888888");
    if (theme.resolveAttribute(R.attr.cp_badgeOverlayColor, typedValue, true)) {
        overlayColor = typedValue.data;
    }
    Paint paint = mPressedOverlay.getPaint();
    paint.setColor(overlayColor);
    paint.setStyle(Paint.Style.FILL);
    paint.setAntiAlias(true);
}
项目:editor-sql    文件:FloatingActionButton.java   
private CircleDrawable(Shape s) {
    super(s);
    circleInsetHorizontal = hasShadow() ? mShadowRadius + Math.abs(mShadowXOffset) : 0;
    circleInsetVertical = hasShadow() ? mShadowRadius + Math.abs(mShadowYOffset) : 0;

    if (mProgressBarEnabled) {
        circleInsetHorizontal += mProgressWidth;
        circleInsetVertical += mProgressWidth;
    }
}
项目:MDWechat    文件:FloatingActionButton.java   
private CircleDrawable(Shape s) {
    super(s);
    circleInsetHorizontal = hasShadow() ? mShadowRadius + Math.abs(mShadowXOffset) : 0;
    circleInsetVertical = hasShadow() ? mShadowRadius + Math.abs(mShadowYOffset) : 0;

    if (mProgressBarEnabled) {
        circleInsetHorizontal += mProgressWidth;
        circleInsetVertical += mProgressWidth;
    }
}
项目:ChatExchange-old    文件:FloatingActionButton.java   
private CircleDrawable(Shape s) {
    super(s);
    circleInsetHorizontal = hasShadow() ? mShadowRadius + Math.abs(mShadowXOffset) : 0;
    circleInsetVertical = hasShadow() ? mShadowRadius + Math.abs(mShadowYOffset) : 0;

    if (mProgressBarEnabled) {
        circleInsetHorizontal += mProgressWidth;
        circleInsetVertical += mProgressWidth;
    }
}
项目:Toodoo    文件:FloatingActionButton.java   
private CircleDrawable(Shape s) {
    super(s);
    circleInsetHorizontal = hasShadow() ? mShadowRadius + Math.abs(mShadowXOffset) : 0;
    circleInsetVertical = hasShadow() ? mShadowRadius + Math.abs(mShadowYOffset) : 0;

    if (mProgressBarEnabled) {
        circleInsetHorizontal += mProgressWidth;
        circleInsetVertical += mProgressWidth;
    }
}
项目:ShangHanLun    文件:ATableViewPlainFooterDrawable.java   
@Override
protected void onDraw(Shape shape, Canvas canvas, Paint paint) {
    float offset = mStrokeWidth / 2;
    while (offset < shape.getHeight()) {
        canvas.drawLine(0, offset, shape.getWidth(), offset, mStrokePaint);
        offset += mStrokeOffset;
    }
}
项目:ShangHanLun    文件:ATableViewCellDrawable.java   
@Override
protected void onDraw(Shape shape, Canvas canvas, Paint paint) {
    canvas.save();
    Rect bounds = canvas.getClipBounds();

    // bottom etched line.
    if (mBottomEtchedPaint != null) shape.draw(canvas, mBottomEtchedPaint);
    canvas.restore();
    canvas.save();

    // separator.
    canvas.concat(getSeparatorPaintMatrix(bounds));
    shape.draw(canvas, mSeparatorPaint);
    canvas.restore();
    canvas.save();

    // top etched line.
    canvas.concat(getTopEtchedPaintMatrix(bounds));
    if (mTopEtchedPaint != null) shape.draw(canvas, mTopEtchedPaint);
    canvas.restore();
    canvas.save();

    // background.
    canvas.concat(getBackgroundPaintMatrix(bounds));
    shape.draw(canvas, mBackgroundPaint);
    canvas.restore();
    canvas.save();

    // selected.
    canvas.concat(getSelectedPaintMatrix(bounds));
    if (mSelectedPaint != null) {

        // we'll set the selected color on onDraw event since we don't know drawable height up to here.
        Shader shader = new LinearGradient(0, 0, 0, mRowHeight, mStartColor, mEndColor, Shader.TileMode.MIRROR);
        mSelectedPaint.setShader(shader);

        shape.draw(canvas, mSelectedPaint);
    }
}
项目:AdPlayBanner    文件:PointView.java   
private void change() {
    float[] outerR = new float[]{mSize / 2, mSize / 2, mSize / 2, mSize / 2, mSize / 2, mSize / 2, mSize / 2, mSize / 2};
    Shape shape = new RoundRectShape(outerR, null, null);
    ShapeDrawable shapeDrawable = new ShapeDrawable(shape);
    shapeDrawable.setIntrinsicHeight((int) mSize);
    shapeDrawable.setIntrinsicWidth((int) mSize);
    shapeDrawable.setPadding(0, 0, 0, 0);
    shapeDrawable.getPaint().setColor(mColor);
    shapeDrawable.getPaint().setStyle(Paint.Style.FILL);
    setBackgroundDrawable(shapeDrawable);
    setHeight((int) mSize);
    setMinWidth((int) mSize);
}
项目:RLibrary    文件:ResUtil.java   
/**
 * Generate bg drawable drawable.
 *
 * @param radii        the radii
 * @param borderWidth  the border width
 * @param pressColor   the press color
 * @param defaultColor the default color
 * @return the drawable
 */
public static Drawable generateRoundBorderDrawable(Resources res, float radii, float borderWidth, int pressColor, int defaultColor) {

    radii = dpToPx(res, radii);
    borderWidth = dpToPx(res, borderWidth);

    //外环的圆角矩形
    float[] outRadii = new float[]{radii, radii, radii, radii, radii, radii, radii, radii};//四个角的 圆角幅度,8个可以设置的值,每个角都有2个边 2*4=8个

    //与内环的距离
    RectF inset = new RectF(borderWidth, borderWidth, borderWidth, borderWidth);

    //按下状态
    Shape roundRectShape = new RoundRectShape(outRadii, inset, null);//圆角背景
    ShapeDrawable shopDrawablePress = new ShapeDrawable(roundRectShape);//圆角shape
    shopDrawablePress.getPaint().setColor(pressColor);//设置颜色

    //正常状态
    Shape roundRectShapeNormal = new RoundRectShape(outRadii, inset, null);
    ShapeDrawable shopDrawableNormal = new ShapeDrawable(roundRectShapeNormal);
    shopDrawableNormal.getPaint().setColor(defaultColor);

    StateListDrawable bgStateDrawable = new StateListDrawable();//状态shape
    bgStateDrawable.addState(new int[]{android.R.attr.state_pressed}, shopDrawablePress);//按下状态
    bgStateDrawable.addState(new int[]{}, shopDrawableNormal);//其他状态

    return bgStateDrawable;
}
项目:RLibrary    文件:ResUtil.java   
public static Drawable generateRoundBorderDrawable(float radii, float borderWidth,
                                                   int pressColor, int disableColor, int defaultColor) {

    //外环的圆角矩形,
    // 左上 右上   左下 右下
    float[] outRadii = new float[]{radii, radii, radii, radii, radii, radii, radii, radii};//四个角的 圆角幅度,8个可以设置的值,每个角都有2个边 2*4=8个

    //与内环的距离
    RectF inset = new RectF(borderWidth, borderWidth, borderWidth, borderWidth);

    //按下状态
    Shape roundRectShape = new RoundRectShape(outRadii, inset, outRadii);//圆角背景
    ShapeDrawable shopDrawablePress = new ShapeDrawable(roundRectShape);//圆角shape
    shopDrawablePress.getPaint().setColor(pressColor);//设置颜色

    ShapeDrawable shopDrawableEnable = new ShapeDrawable(roundRectShape);
    shopDrawableEnable.getPaint().setColor(disableColor);

    //正常状态
    Shape roundRectShapeNormal = new RoundRectShape(outRadii, inset, outRadii);
    ShapeDrawable shopDrawableNormal = new ShapeDrawable(roundRectShapeNormal);
    shopDrawableNormal.getPaint().setColor(defaultColor);

    StateListDrawable bgStateDrawable = new StateListDrawable();//状态shape
    bgStateDrawable.addState(new int[]{-android.R.attr.state_enabled}, shopDrawableEnable);//按下状态
    bgStateDrawable.addState(new int[]{android.R.attr.state_checked}, shopDrawablePress);//按下状态
    bgStateDrawable.addState(new int[]{android.R.attr.state_pressed}, shopDrawablePress);//按下状态
    bgStateDrawable.addState(new int[]{android.R.attr.state_focused}, shopDrawablePress);//焦点状态
    bgStateDrawable.addState(new int[]{}, shopDrawableNormal);//其他状态

    return bgStateDrawable;
}
项目:RLibrary    文件:ResUtil.java   
public static Drawable generateStrokeDrawable(float radii, float borderWidth, int pressColor, int defaultColor, int disableColor) {
    float[] outRadii = new float[]{radii, radii, radii, radii, radii, radii, radii, radii};//四个角的 圆角幅度,8个可以设置的值,每个角都有2个边 2*4=8个

    //与内环的距离
    RectF inset = new RectF(borderWidth, borderWidth, borderWidth, borderWidth);

    //按下状态
    Shape roundRectShape = new RoundRectShape(outRadii, inset, outRadii);//圆角背景
    ShapeDrawable shopDrawablePress = new ShapeDrawable(roundRectShape);//圆角shape
    shopDrawablePress.getPaint().setColor(pressColor);//设置颜色

    ShapeDrawable shopDrawableEnable = new ShapeDrawable(roundRectShape);
    shopDrawableEnable.getPaint().setColor(disableColor);

    //正常状态
    Shape roundRectShapeNormal = new RoundRectShape(outRadii, inset, outRadii);
    ShapeDrawable shopDrawableNormal = new ShapeDrawable(roundRectShapeNormal);
    shopDrawableNormal.getPaint().setColor(defaultColor);

    StateListDrawable bgStateDrawable = new StateListDrawable();//状态shape
    bgStateDrawable.addState(new int[]{-android.R.attr.state_enabled}, shopDrawableEnable);//按下状态
    bgStateDrawable.addState(new int[]{android.R.attr.state_checked}, shopDrawablePress);//按下状态
    bgStateDrawable.addState(new int[]{android.R.attr.state_pressed}, shopDrawablePress);//按下状态
    bgStateDrawable.addState(new int[]{android.R.attr.state_focused}, shopDrawablePress);//焦点状态
    bgStateDrawable.addState(new int[]{}, shopDrawableNormal);//其他状态

    return bgStateDrawable;
}
项目:RLibrary    文件:ResUtil.java   
/**
 * Generate bg drawable drawable.
 *
 * @param radii       圆角角度
 * @param borderWidth 厚度
 * @param color       颜色
 * @return the drawable
 */
public static Drawable generateRoundBorderDrawable(float radii, float borderWidth, int color) {

    float[] radiiF = new float[]{radii, radii, radii, radii, radii, radii, radii, radii};//四个角的 圆角幅度,8个可以设置的值,每个角都有2个边 2*4=8个
    RectF rectF = new RectF(borderWidth, borderWidth, borderWidth, borderWidth);

    Shape roundRectShape = new RoundRectShape(radiiF, rectF, radiiF);//圆角背景
    ShapeDrawable shopDrawablePress = new ShapeDrawable(roundRectShape);//圆角shape
    shopDrawablePress.getPaint().setColor(color);//设置颜色

    return shopDrawablePress;
}
项目:RLibrary    文件:ResUtil.java   
public static Drawable generateCircleBgDrawable(float width, int color) {
    Shape arcShape = new ArcShape(0, 360);
    ShapeDrawable shopDrawablePress = new ShapeDrawable(arcShape);//圆形shape
    shopDrawablePress.getPaint().setColor(color);//设置颜色
    shopDrawablePress.getPaint().setStyle(Paint.Style.STROKE);//设置颜色
    shopDrawablePress.getPaint().setStrokeWidth(width);//设置颜色
    return shopDrawablePress;
}
项目:RLibrary    文件:ResUtil.java   
/**
 * 创建一个框框的Drawable
 */
public static Drawable createStrokeDrawable(int color, float radii, float borderWidth) {
    float[] outRadii = new float[]{radii, radii, radii, radii, radii, radii, radii, radii};//四个角的 圆角幅度,8个可以设置的值,每个角都有2个边 2*4=8个
    RectF inset = new RectF(borderWidth, borderWidth, borderWidth, borderWidth);
    Shape roundRectShape = new RoundRectShape(outRadii, inset, outRadii);//圆角背景
    ShapeDrawable shapeDrawable = new ShapeDrawable(roundRectShape);//圆角shape
    shapeDrawable.getPaint().setColor(color);//设置颜色
    return shapeDrawable;
}
项目:RLibrary    文件:ResUtil.java   
public static Drawable createSolidDrawable(int color, float radii) {
    float[] outRadii = new float[]{radii, radii, radii, radii, radii, radii, radii, radii};//四个角的 圆角幅度,8个可以设置的值,每个角都有2个边 2*4=8个
    Shape roundRectShape = new RoundRectShape(outRadii, null, null);//圆角背景
    ShapeDrawable shapeDrawable = new ShapeDrawable(roundRectShape);//圆角shape
    shapeDrawable.getPaint().setColor(color);//设置颜色
    return shapeDrawable;
}
项目:libcommon    文件:BrushDrawable.java   
public void setRotation(final float rotation) {
//      if (DEBUG) Log.v(TAG, "setRotation:" + rotation);
        final Shape shape = getShape();
        if (shape instanceof BaseShape) {
            ((BaseShape)shape).setRotation(rotation);
            mRotation = 0;
        } else {
            if (mRotation != rotation) {
                mRotation = rotation;
            }
        }
        invalidateSelf();
    }
项目:templated-messaging    文件:ContactBadge.java   
private void initOverlay(Context context, Shape shape) {
    // pressed state
    TypedValue typedValue = new TypedValue();
    Theme theme = context.getTheme();

    mPressedOverlay = new ShapeDrawable(shape);
    int overlayColor = Color.parseColor("#aa888888");
    if (theme.resolveAttribute(R.attr.cp_badgeOverlayColor, typedValue, true)) {
        overlayColor = typedValue.data;
    }
    Paint paint = mPressedOverlay.getPaint();
    paint.setColor(overlayColor);
    paint.setStyle(Paint.Style.FILL);
    paint.setAntiAlias(true);
}
项目:FloatingActionButtonEx    文件:FloatingActionButton.java   
private CircleDrawable(Shape s) {
    super(s);
    circleInsetHorizontal = hasShadow() ? mShadowRadius + Math.abs(mShadowXOffset) : 0;
    circleInsetVertical = hasShadow() ? mShadowRadius + Math.abs(mShadowYOffset) : 0;

    if (mProgressBarEnabled) {
        circleInsetHorizontal += mProgressWidth;
        circleInsetVertical += mProgressWidth;
    }
}
项目:truth-android    文件:ShapeSubject.java   
public static SubjectFactory<ShapeSubject, Shape> type() {
  return new SubjectFactory<ShapeSubject, Shape>() {
    @Override
    public ShapeSubject getSubject(FailureStrategy fs, Shape that) {
      return new ShapeSubject(fs, that);
    }
  };
}
项目:react-native-navigation    文件:TopBarBorder.java   
@Override
protected void onDraw(Shape shape, Canvas canvas, Paint paint) {
    paint.setColor(backgroundColor.getColor(Color.WHITE));
    super.onDraw(shape, canvas, paint);
    createBorder(canvas);
    canvas.drawPath(border.path, pathPaint);
}
项目:UILibrary    文件:MaskDrawable.java   
public MaskDrawable(Drawable content, Shape mask){
    mDrawingContent = content;
    mMask = mask;

    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setColor(0xFFFFFFFF);
}