Java Code Examples for android.graphics.drawable.shapes.RoundRectShape

The following are top voted examples for showing how to use android.graphics.drawable.shapes.RoundRectShape. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: boohee_v5.6   File: BitmapHelper.java   View source code 7 votes vote down vote up
public static Bitmap roundBitmap(Bitmap bitmap, int i, int i2, float f, float f2, float f3,
                                 float f4) throws Throwable {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Rect rect = new Rect(0, 0, width, height);
    Bitmap createBitmap = (width == i && height == i2) ? Bitmap.createBitmap(bitmap.getWidth
            (), bitmap.getHeight(), Config.ARGB_8888) : Bitmap.createBitmap(i, i2, Config
            .ARGB_8888);
    Canvas canvas = new Canvas(createBitmap);
    Paint paint = new Paint();
    Rect rect2 = new Rect(0, 0, i, i2);
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(-12434878);
    float[] fArr = new float[]{f, f, f2, f2, f3, f3, f4, f4};
    ShapeDrawable shapeDrawable = new ShapeDrawable(new RoundRectShape(fArr, new RectF(0.0f,
            0.0f, 0.0f, 0.0f), fArr));
    shapeDrawable.setBounds(rect2);
    shapeDrawable.draw(canvas);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect2, paint);
    return createBitmap;
}
 
Example 2
Project: android-round-textview   File: DrawableHelper.java   View source code 6 votes vote down vote up
public static Drawable getCornerDrawable(float topLeft,
                                         float topRight,
                                         float bottomLeft,
                                         float bottomRight,
                                          @ColorInt int color) {

    float[] outerR = new float[8];
    outerR[0] = topLeft;
    outerR[1] = topLeft;
    outerR[2] = topRight;
    outerR[3] = topRight;
    outerR[4] = bottomRight;
    outerR[5] = bottomRight;
    outerR[6] = bottomLeft;
    outerR[7] = bottomLeft;

    ShapeDrawable drawable = new ShapeDrawable();
    drawable.setShape(new RoundRectShape(outerR, null, null));
    drawable.getPaint().setColor(color);

    return drawable;
}
 
Example 3
Project: editor-sql   File: Label.java   View source code 6 votes vote down vote up
private Drawable createRectDrawable(int color) {
    RoundRectShape shape = new RoundRectShape(
            new float[]{
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius
            },
            null,
            null);
    ShapeDrawable shapeDrawable = new ShapeDrawable(shape);
    shapeDrawable.getPaint().setColor(color);
    return shapeDrawable;
}
 
Example 4
Project: MDWechat   File: Label.java   View source code 6 votes vote down vote up
private Drawable createRectDrawable(int color) {
    RoundRectShape shape = new RoundRectShape(
            new float[]{
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius
            },
            null,
            null);
    ShapeDrawable shapeDrawable = new ShapeDrawable(shape);
    shapeDrawable.getPaint().setColor(color);
    return shapeDrawable;
}
 
Example 5
Project: RestClient   File: RestTestAdapter.java   View source code 6 votes vote down vote up
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
    RestTest restTest = datas.get(position);
    RoundRectShape shape = new RoundRectShape(new float[]{8, 8, 8, 8, 8, 8, 8, 8}, null, null);
    ShapeDrawable drawable = new ShapeDrawable(shape);

    String color = "6bbd5b";
    switch (restTest.getMethod().toUpperCase()) {
        case "GET":
            break;
        case "POST":
            color = "248fb2";
            break;
        case "DELETE":
            color = "e27a7a";
            break;
        case "PUT":
            color = "9b708b";
            break;
    }
    drawable.getPaint().setColor(Color.parseColor("#" + color));
    holder.tv.setBackground(drawable);
    holder.tv.setText(restTest.getMethod().toUpperCase());

    holder.spec.setText(restTest.getUrl());
}
 
Example 6
Project: Leanplum-Android-SDK   File: BitmapUtil.java   View source code 6 votes vote down vote up
private static Drawable getBackground(int normalStateColor,
    int pressedStateColor) {
  StateListDrawable background = new StateListDrawable();
  int c = SizeUtil.dp10;
  float[] r = new float[] {c, c, c, c, c, c, c, c};
  RoundRectShape rr = new RoundRectShape(r, null, null);
  ShapeDrawable cd = new ShapeDrawable();
  cd.setShape(rr);
  cd.getPaint().setColor(pressedStateColor);
  background.addState(new int[] {android.R.attr.state_pressed,
      android.R.attr.state_focused}, cd);
  background.addState(new int[] {-android.R.attr.state_pressed,
      android.R.attr.state_focused}, cd);
  background.addState(new int[] {android.R.attr.state_pressed,
      -android.R.attr.state_focused}, cd);
  ShapeDrawable cd1 = new ShapeDrawable();
  cd1.setShape(rr);
  cd1.getPaint().setColor(normalStateColor);
  background.addState(new int[] {-android.R.attr.state_pressed,
      -android.R.attr.state_focused}, cd1);
  return background;
}
 
Example 7
Project: ChatExchange-old   File: Label.java   View source code 6 votes vote down vote up
private Drawable createRectDrawable(int color) {
    RoundRectShape shape = new RoundRectShape(
            new float[]{
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius
            },
            null,
            null);
    ShapeDrawable shapeDrawable = new ShapeDrawable(shape);
    shapeDrawable.getPaint().setColor(color);
    return shapeDrawable;
}
 
Example 8
Project: Watermark   File: MediaActivity.java   View source code 6 votes vote down vote up
private StateListDrawable createDefaultOverButtonBgDrawable() {
    int dp12 = (int) ThemeUtils.applyDimensionDp(this, 12.f);
    int dp8 = (int) ThemeUtils.applyDimensionDp(this, 8.f);
    float dp4 = ThemeUtils.applyDimensionDp(this, 4.f);
    float[] round = new float[]{dp4, dp4, dp4, dp4, dp4, dp4, dp4, dp4};
    ShapeDrawable pressedDrawable = new ShapeDrawable(new RoundRectShape(round, null, null));
    pressedDrawable.setPadding(dp12, dp8, dp12, dp8);
    int pressedColor = ThemeUtils.resolveColor(this, R.attr.gallery_toolbar_over_button_pressed_color, R.color.gallery_default_toolbar_over_button_pressed_color);
    pressedDrawable.getPaint().setColor(pressedColor);

    int normalColor = ThemeUtils.resolveColor(this, R.attr.gallery_toolbar_over_button_normal_color, R.color.gallery_default_toolbar_over_button_normal_color);
    ShapeDrawable normalDrawable = new ShapeDrawable(new RoundRectShape(round, null, null));
    normalDrawable.setPadding(dp12, dp8, dp12, dp8);
    normalDrawable.getPaint().setColor(normalColor);

    StateListDrawable stateListDrawable = new StateListDrawable();
    stateListDrawable.addState(new int[]{android.R.attr.state_pressed}, pressedDrawable);
    stateListDrawable.addState(new int[]{}, normalDrawable);

    return stateListDrawable;
}
 
Example 9
Project: Toodoo   File: Label.java   View source code 6 votes vote down vote up
private Drawable createRectDrawable(int color) {
    RoundRectShape shape = new RoundRectShape(
            new float[]{
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius
            },
            null,
            null);
    ShapeDrawable shapeDrawable = new ShapeDrawable(shape);
    shapeDrawable.getPaint().setColor(color);
    return shapeDrawable;
}
 
Example 10
Project: LemonHello4Android   File: LemonHelloPrivateAnimationTool.java   View source code 6 votes vote down vote up
void setCornerRadius(View view, int radius, int color) {
    radius = _DP(radius);
    int borderWidth = 0;// 加边框后会出现空心圆角矩形的效果,所以设置为0
    float[] outerRadius = new float[8];
    float[] innerRadius = new float[8];
    for (int i = 0; i < 8; i++) {
        outerRadius[i] = radius + borderWidth;
        innerRadius[i] = radius;
    }
    ShapeDrawable shapeDrawable = // 创建图形drawable
            new ShapeDrawable(
                    // 创建圆角矩形
                    new RoundRectShape(outerRadius,
                            new RectF(borderWidth, borderWidth, borderWidth, borderWidth),
                            innerRadius));
    shapeDrawable.getPaint().setColor(color);// 使用指定的颜色绘制,即背景颜色
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        // 高版本SDK使用新的API
        view.setBackground(shapeDrawable);
    } else {
        view.setBackgroundDrawable(shapeDrawable);
    }
}
 
Example 11
Project: ShangHanLun   File: ATableViewCellDrawable.java   View source code 6 votes vote down vote up
private static RoundRectShape getShape(ATableView tableView, ATableViewCellBackgroundStyle backgroundStyle) {
    ATableViewStyle tableStyle = tableView.getStyle();

    float[] radius = new float[]{0, 0, 0, 0, 0, 0, 0, 0};
    if (tableStyle == ATableViewStyle.Grouped) {
        Resources res = tableView.getResources();

        float radii = Math.round(res.getDimension(R.dimen.atv_grouped_stroke_radius));
        if (backgroundStyle == ATableViewCellBackgroundStyle.Single) {
            radius = new float[]{radii, radii, radii, radii, radii, radii, radii, radii};
        } else if (backgroundStyle == ATableViewCellBackgroundStyle.Top) {
            radius = new float[]{radii, radii, radii, radii, 0, 0, 0, 0};
        } else if (backgroundStyle == ATableViewCellBackgroundStyle.Bottom) {
            radius = new float[]{0, 0, 0, 0, radii, radii, radii, radii};
        }
    }

    return new RoundRectShape(radius, null, null);
}
 
Example 12
Project: appinventor-extensions   File: ButtonBase.java   View source code 6 votes vote down vote up
private void setShape() {
  ShapeDrawable drawable = new ShapeDrawable();
  // Set color of drawable.
  drawable.getPaint().setColor((backgroundColor == Component.COLOR_DEFAULT)
                               ? SHAPED_DEFAULT_BACKGROUND_COLOR : backgroundColor);
  // Set shape of drawable.
  switch (shape) {
    case Component.BUTTON_SHAPE_ROUNDED:
      drawable.setShape(new RoundRectShape(ROUNDED_CORNERS_ARRAY, null, null));
      break;
    case Component.BUTTON_SHAPE_RECT:
      drawable.setShape(new RectShape());
      break;
    case Component.BUTTON_SHAPE_OVAL:
      drawable.setShape(new OvalShape());
      break;
    default:
      throw new IllegalArgumentException();
  }
  // Set drawable to the background of the button.
  view.setBackgroundDrawable(drawable);
  view.invalidate();
}
 
Example 13
Project: RLibrary   File: ResUtil.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 14
Project: RLibrary   File: ResUtil.java   View source code 6 votes vote down vote up
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;
}
 
Example 15
Project: RLibrary   File: ResUtil.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 16
Project: RLibrary   File: ResUtil.java   View source code 6 votes vote down vote up
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;
}
 
Example 17
Project: RLibrary   File: ResUtil.java   View source code 6 votes vote down vote up
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;
}
 
Example 18
Project: RLibrary   File: ResUtil.java   View source code 6 votes vote down vote up
/**
 * 正常 圆角边框;
 * 按下 圆角色块
 */
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;
}
 
Example 19
Project: starcor.xul   File: XulWorker.java   View source code 6 votes vote down vote up
private static Bitmap toRoundCornerMutableBitmap(Canvas canvas, Paint paintClear, Bitmap srcBitmap, float[] roundRadius) {
	canvas.setBitmap(srcBitmap);
	RectF inset = new RectF(1, 1, 1, 1);
	if (roundRadius.length == 2) {
		float[] tmpRoundRadius = new float[8];
		for (int i = 0; i < 4; ++i) {
			tmpRoundRadius[i * 2 + 0] = roundRadius[0];
			tmpRoundRadius[i * 2 + 1] = roundRadius[1];
			roundRadius = tmpRoundRadius;
		}
	}
	canvas.save();
	canvas.translate(-1, -1);
	RoundRectShape roundRectShape = new RoundRectShape(null, inset, roundRadius);
	roundRectShape.resize(srcBitmap.getWidth() + 2, srcBitmap.getHeight() + 2);
	roundRectShape.draw(canvas, paintClear);
	canvas.restore();
	canvas.setBitmap(null);
	return srcBitmap;
}
 
Example 20
Project: MaterialFBook   File: Label.java   View source code 6 votes vote down vote up
private Drawable createRectDrawable(int color) {
    RoundRectShape shape = new RoundRectShape(
            new float[]{
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius
            },
            null,
            null);
    ShapeDrawable shapeDrawable = new ShapeDrawable(shape);
    shapeDrawable.getPaint().setColor(color);
    return shapeDrawable;
}
 
Example 21
Project: LemonBubble4Android   File: LemonBubblePrivateAnimationTool.java   View source code 6 votes vote down vote up
void setCornerRadius(View view, int radius, int color) {
    radius = _DP(radius);
    int borderWidth = 0;// 加边框后会出现空心圆角矩形的效果,所以设置为0
    float[] outerRadius = new float[8];
    float[] innerRadius = new float[8];
    for (int i = 0; i < 8; i++) {
        outerRadius[i] = radius + borderWidth;
        innerRadius[i] = radius;
    }
    ShapeDrawable shapeDrawable = // 创建图形drawable
            new ShapeDrawable(
                    // 创建圆角矩形
                    new RoundRectShape(outerRadius,
                            new RectF(borderWidth, borderWidth, borderWidth, borderWidth),
                            innerRadius));
    shapeDrawable.getPaint().setColor(color);// 使用指定的颜色绘制,即背景颜色
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        // 高版本SDK使用新的API
        view.setBackground(shapeDrawable);
    } else {
        view.setBackgroundDrawable(shapeDrawable);
    }
}
 
Example 22
Project: FloatingActionButtonEx   File: Label.java   View source code 6 votes vote down vote up
private Drawable createRectDrawable(int color) {
    RoundRectShape shape = new RoundRectShape(
            new float[]{
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius
            },
            null,
            null);
    ShapeDrawable shapeDrawable = new ShapeDrawable(shape);
    shapeDrawable.getPaint().setColor(color);
    return shapeDrawable;
}
 
Example 23
Project: talk-android   File: ThemeButton.java   View source code 6 votes vote down vote up
public void setThemeBackground(int color, int colorPressed) {
    int radius = DensityUtil.dip2px(getContext(), 2);
    float[] radii = new float[]{radius, radius, radius, radius, radius, radius, radius, radius};

    StateListDrawable states = new StateListDrawable();

    RoundRectShape disableShape = new RoundRectShape(radii, null, null);
    ShapeDrawable disableDrawable = new ShapeDrawable(disableShape);
    disableDrawable.getPaint().setColor(getResources().getColor(R.color.material_grey_300));
    states.addState(new int[]{-android.R.attr.state_enabled}, disableDrawable);

    RoundRectShape pressedShape = new RoundRectShape(radii, null, null);
    ShapeDrawable pressedDrawable = new ShapeDrawable(pressedShape);
    pressedDrawable.getPaint().setColor(colorPressed);
    states.addState(new int[]{android.R.attr.state_pressed}, pressedDrawable);

    RoundRectShape normalShape = new RoundRectShape(radii, null, null);
    ShapeDrawable normalDrawable = new ShapeDrawable(normalShape);
    normalDrawable.getPaint().setColor(color);
    states.addState(new int[]{-android.R.attr.state_pressed}, normalDrawable);

    setBackgroundDrawable(states);
}
 
Example 24
Project: AndroidProjectsClient   File: Label.java   View source code 6 votes vote down vote up
private Drawable createRectDrawable(int color) {
    RoundRectShape shape = new RoundRectShape(
            new float[] {
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius
            },
            null,
            null
    );
    ShapeDrawable shapeDrawable = new ShapeDrawable(shape);
    shapeDrawable.getPaint().setColor(color);
    return shapeDrawable;
}
 
Example 25
Project: MiddleLinesDialogUtils2.0   File: MiddleLinesDialog.java   View source code 6 votes vote down vote up
@NonNull
private ShapeDrawable getShapeDrawable(int topLeftAndRightRadius, int bottomLeftAndRightRadius, int bgColor) {
    float outRectr[] = new float[]{
            topLeftAndRightRadius, topLeftAndRightRadius,
            topLeftAndRightRadius, topLeftAndRightRadius,
            bottomLeftAndRightRadius, bottomLeftAndRightRadius,
            bottomLeftAndRightRadius, bottomLeftAndRightRadius};
    /**
     * 注意StateListDrawable的构造方法我们这里使用的
     * 是第一参数它是一个float的数组保存的是圆角的半径,它是按照top-left顺时针保存的八个值
     */
    //创建圆弧形状
    RoundRectShape rectShape = new RoundRectShape(outRectr, null, null);
    //创建drawable
    ShapeDrawable pressedDrawable = new ShapeDrawable(rectShape);
    //设置背景的颜色
    pressedDrawable.getPaint().setColor(bgColor);
    return pressedDrawable;
}
 
Example 26
Project: Calendar   File: HighlightWeekendsDecorator.java   View source code 6 votes vote down vote up
private static Drawable generateBackgroundDrawable() {
    final int r = 0;
    final float[] outerR = new float[]{r, r, r, r, r, r, r, r};
    final int color = Color.parseColor("#228BC34A");

    RoundRectShape rr = new RoundRectShape(outerR, null, null);

    ShapeDrawable drawable = new ShapeDrawable(rr);
    drawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            return new LinearGradient(0, 0, 0, 0, color, color, Shader.TileMode.REPEAT);
        }
    });
    return drawable;
}
 
Example 27
Project: TbRepeatPicker   File: SUtils.java   View source code 6 votes vote down vote up
private static Drawable createButtonShape(Context context, int color) {
    // Translation of Lollipop's xml button-bg definition to Java
    int paddingH = DensityUtil.dip2px(context, 8);
    int paddingV = DensityUtil.dip2px(context, 4);
    int insetH = DensityUtil.dip2px(context, 4);
    int insetV = DensityUtil.dip2px(context, 6);
    int corner_radius = DensityUtil.dip2px(context, 2);
    float[] outerRadii = new float[8];
    Arrays.fill(outerRadii, corner_radius);

    RoundRectShape r = new RoundRectShape(outerRadii, null, null);

    ShapeDrawable shapeDrawable = new ShapeDrawable(r);
    shapeDrawable.getPaint().setColor(color);
    shapeDrawable.setPadding(paddingH, paddingV, paddingH, paddingV);

    return new InsetDrawable(shapeDrawable,
            insetH, insetV, insetH, insetV);
}
 
Example 28
Project: TbRepeatPicker   File: SUtils.java   View source code 6 votes vote down vote up
public static Drawable createBgDrawable(int color, int rTopLeft,
                                        int rTopRight, int rBottomRight,
                                        int rBottomLeft) {
    float[] outerRadii = new float[8];
    outerRadii[0] = rTopLeft;
    outerRadii[1] = rTopLeft;
    outerRadii[2] = rTopRight;
    outerRadii[3] = rTopRight;
    outerRadii[4] = rBottomRight;
    outerRadii[5] = rBottomRight;
    outerRadii[6] = rBottomLeft;
    outerRadii[7] = rBottomLeft;

    RoundRectShape r = new RoundRectShape(outerRadii, null, null);

    ShapeDrawable shapeDrawable = new ShapeDrawable(r);
    shapeDrawable.getPaint().setColor(color);

    return shapeDrawable;
}
 
Example 29
Project: Android-Toggle-Switch   File: BaseToggleSwitch.java   View source code 6 votes vote down vote up
private RoundRectShape buildRect(ToggleSwitchButton toggleSwitchButton) {
    if (isFirst(toggleSwitchButton))
        return new RoundRectShape(
                new float[]{cornerRadius, cornerRadius, 0, 0, 0, 0, cornerRadius, cornerRadius},
                null,
                null);
    else if (isLast(toggleSwitchButton))
        return new RoundRectShape(
                new float[]{0, 0, cornerRadius, cornerRadius, cornerRadius, cornerRadius, 0, 0},
                null,
                null);
    else
        return new RoundRectShape(
                new float[]{0, 0, 0, 0, 0, 0, 0, 0},
                null,
                null);
}
 
Example 30
Project: CheckSmarter   File: SUtils.java   View source code 6 votes vote down vote up
private static Drawable createButtonShape(Context context, int color) {
    // Translation of Lollipop's xml button-bg definition to Java
    int paddingH = context.getResources()
            .getDimensionPixelSize(R.dimen.button_padding_horizontal_material);
    int paddingV = context.getResources()
            .getDimensionPixelSize(R.dimen.button_padding_vertical_material);
    int insetH = context.getResources()
            .getDimensionPixelSize(R.dimen.button_inset_horizontal_material);
    int insetV = context.getResources()
            .getDimensionPixelSize(R.dimen.button_inset_vertical_material);

    float[] outerRadii = new float[8];
    Arrays.fill(outerRadii, CORNER_RADIUS);

    RoundRectShape r = new RoundRectShape(outerRadii, null, null);

    ShapeDrawable shapeDrawable = new ShapeDrawable(r);
    shapeDrawable.getPaint().setColor(color);
    shapeDrawable.setPadding(paddingH, paddingV, paddingH, paddingV);

    return new InsetDrawable(shapeDrawable,
            insetH, insetV, insetH, insetV);
}
 
Example 31
Project: CheckSmarter   File: SUtils.java   View source code 6 votes vote down vote up
public static Drawable createBgDrawable(int color, int rTopLeft,
                                        int rTopRight, int rBottomRight,
                                        int rBottomLeft) {
    float[] outerRadii = new float[8];
    outerRadii[0] = rTopLeft;
    outerRadii[1] = rTopLeft;
    outerRadii[2] = rTopRight;
    outerRadii[3] = rTopRight;
    outerRadii[4] = rBottomRight;
    outerRadii[5] = rBottomRight;
    outerRadii[6] = rBottomLeft;
    outerRadii[7] = rBottomLeft;

    RoundRectShape r = new RoundRectShape(outerRadii, null, null);

    ShapeDrawable shapeDrawable = new ShapeDrawable(r);
    shapeDrawable.getPaint().setColor(color);

    return shapeDrawable;
}
 
Example 32
Project: FriendCircle   File: DotWidget.java   View source code 6 votes vote down vote up
private ShapeDrawable getDotBackground() {
    ShapeDrawable drawable = null;
    switch (mode) {
        case ROUND_RECT:
            int radius = dip2Pixels(dotRadius);
            float[] outerRect = new float[] { radius, radius, radius, radius, radius, radius, radius, radius };

            RoundRectShape rr = new RoundRectShape(outerRect, null, null);
            drawable = new InnerShapeDrawableWithText(rr, dotText);
            drawable.getPaint().setColor(dotColor);
            break;
        case CIRCLE:
            OvalShape os = new OvalShape();
            drawable = new InnerShapeDrawableWithText(os, dotText);
            drawable.getPaint().setColor(dotColor);
            //                int paddingPixels = dip2Pixels(8);
            //                drawable.setPadding(paddingPixels, paddingPixels, paddingPixels,
            //                        paddingPixels);
            break;
    }

    return drawable;
}
 
Example 33
Project: Newton_for_Android_AS   File: CustomToast.java   View source code 6 votes vote down vote up
public CustomToast(Context context) {
	// 此处必须是ApplicationContext,因为Activity退出也可以显示
	context = context.getApplicationContext();
	
	windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
	rootView = new LinearLayout(context);
	
	// 背景设置为圆角矩形
	float r = 10;
	float[] outerR = new float[] { r, r, r, r, r, r, r, r };
	RoundRectShape rr = new RoundRectShape(outerR, null, null);
	ShapeDrawable drawable = new ShapeDrawable(rr);
	drawable.getPaint().setColor(Color.BLACK);
	
	int a = UIUtil.dip2px(context, 10);
	drawable.setPadding(a, a, a, a);
	
	rootView.setBackgroundDrawable(drawable);
}
 
Example 34
Project: MiddleLinesDialogUtils   File: MiddleLinesDialog.java   View source code 6 votes vote down vote up
@NonNull
private ShapeDrawable getShapeDrawable(int topLeftAndRightRadius, int bottomLeftAndRightRadius, int bgColor) {
    float outRectr[] = new float[]{
            topLeftAndRightRadius, topLeftAndRightRadius,
            topLeftAndRightRadius, topLeftAndRightRadius,
            bottomLeftAndRightRadius, bottomLeftAndRightRadius,
            bottomLeftAndRightRadius, bottomLeftAndRightRadius};
    /**
     * 注意StateListDrawable的构造方法我们这里使用的
     * 是第一参数它是一个float的数组保存的是圆角的半径,它是按照top-left顺时针保存的八个值
     */
    //创建圆弧形状
    RoundRectShape rectShape = new RoundRectShape(outRectr, null, null);
    //创建drawable
    ShapeDrawable pressedDrawable = new ShapeDrawable(rectShape);
    //设置背景的颜色
    pressedDrawable.getPaint().setColor(bgColor);
    return pressedDrawable;
}
 
Example 35
Project: clear-todolist   File: Label.java   View source code 6 votes vote down vote up
private Drawable createRectDrawable(int color) {
    RoundRectShape shape = new RoundRectShape(
            new float[]{
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius
            },
            null,
            null);
    ShapeDrawable shapeDrawable = new ShapeDrawable(shape);
    shapeDrawable.getPaint().setColor(color);
    return shapeDrawable;
}
 
Example 36
Project: neveshtanak-Deprecated-   File: Label.java   View source code 6 votes vote down vote up
private Drawable createRectDrawable(int color) {
    RoundRectShape shape = new RoundRectShape(
            new float[]{
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius
            },
            null,
            null);
    ShapeDrawable shapeDrawable = new ShapeDrawable(shape);
    shapeDrawable.getPaint().setColor(color);
    return shapeDrawable;
}
 
Example 37
Project: SublimePicker   File: SUtils.java   View source code 6 votes vote down vote up
private static Drawable createButtonShape(Context context, int color) {
    // Translation of Lollipop's xml button-bg definition to Java
    int paddingH = context.getResources()
            .getDimensionPixelSize(R.dimen.button_padding_horizontal_material);
    int paddingV = context.getResources()
            .getDimensionPixelSize(R.dimen.button_padding_vertical_material);
    int insetH = context.getResources()
            .getDimensionPixelSize(R.dimen.button_inset_horizontal_material);
    int insetV = context.getResources()
            .getDimensionPixelSize(R.dimen.button_inset_vertical_material);

    float[] outerRadii = new float[8];
    Arrays.fill(outerRadii, CORNER_RADIUS);

    RoundRectShape r = new RoundRectShape(outerRadii, null, null);

    ShapeDrawable shapeDrawable = new ShapeDrawable(r);
    shapeDrawable.getPaint().setColor(color);
    shapeDrawable.setPadding(paddingH, paddingV, paddingH, paddingV);

    return new InsetDrawable(shapeDrawable,
            insetH, insetV, insetH, insetV);
}
 
Example 38
Project: SublimePicker   File: SUtils.java   View source code 6 votes vote down vote up
public static Drawable createBgDrawable(int color, int rTopLeft,
                                        int rTopRight, int rBottomRight,
                                        int rBottomLeft) {
    float[] outerRadii = new float[8];
    outerRadii[0] = rTopLeft;
    outerRadii[1] = rTopLeft;
    outerRadii[2] = rTopRight;
    outerRadii[3] = rTopRight;
    outerRadii[4] = rBottomRight;
    outerRadii[5] = rBottomRight;
    outerRadii[6] = rBottomLeft;
    outerRadii[7] = rBottomLeft;

    RoundRectShape r = new RoundRectShape(outerRadii, null, null);

    ShapeDrawable shapeDrawable = new ShapeDrawable(r);
    shapeDrawable.getPaint().setColor(color);

    return shapeDrawable;
}
 
Example 39
Project: NQH_FloatingActionButton   File: Label.java   View source code 6 votes vote down vote up
private Drawable createRectDrawable(int color) {
    RoundRectShape shape = new RoundRectShape(
            new float[]{
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius
            },
            null,
            null);
    ShapeDrawable shapeDrawable = new ShapeDrawable(shape);
    shapeDrawable.getPaint().setColor(color);
    return shapeDrawable;
}
 
Example 40
Project: flowzr-android-black   File: Label.java   View source code 6 votes vote down vote up
private Drawable createRectDrawable(int color) {
    RoundRectShape shape = new RoundRectShape(
            new float[]{
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius
            },
            null,
            null);
    ShapeDrawable shapeDrawable = new ShapeDrawable(shape);
    shapeDrawable.getPaint().setColor(color);
    return shapeDrawable;
}