@Override public IBuilder roundRect(int radius) { this.radius = radius; float[] radii = {radius, radius, radius, radius, radius, radius, radius, radius}; this.shape = new RoundRectShape(radii, null, null); return this; }
private static Drawable buildRoundedRect(int radius, int color) { final float[] radii = new float[8]; Arrays.fill(radii, radius); final RoundRectShape roundedRectShape = new RoundRectShape(radii, null, radii); final ShapeDrawable drawable = new ShapeDrawable(roundedRectShape); drawable.getPaint().setColor(color); return drawable; } }
private static Drawable buildRoundedRect(ComponentContext c, int color, int cornerRadiusDp) { final float cornerRadiusPx = TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, cornerRadiusDp, c.getResources().getDisplayMetrics()); final float[] radii = new float[8]; Arrays.fill(radii, cornerRadiusPx); final RoundRectShape roundedRectShape = new RoundRectShape(radii, null, radii); final ShapeDrawable drawable = new ShapeDrawable(roundedRectShape); drawable.getPaint().setColor(color); return drawable; } }
static ShapeDrawable getMessageBackground(ComponentContext c, int color) { final RoundRectShape roundedRectShape = new RoundRectShape( new float[] {40, 40, 40, 40, 40, 40, 40, 40}, null, new float[] {40, 40, 40, 40, 40, 40, 40, 40}); final ShapeDrawable oval = new ShapeDrawable(roundedRectShape); oval.getPaint().setColor(color); return oval; }
private static Drawable buildRoundedRect(ComponentContext c, int color, int cornerRadiusDp) { final float cornerRadiusPx = TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, cornerRadiusDp, c.getResources().getDisplayMetrics()); final float[] radii = new float[8]; Arrays.fill(radii, cornerRadiusPx); final RoundRectShape roundedRectShape = new RoundRectShape(radii, null, radii); final ShapeDrawable drawable = new ShapeDrawable(roundedRectShape); drawable.getPaint().setColor(color); return drawable; } }
/** * helper to create an ripple mask with the given color and radius * * @param color the color * @param radius the radius * @return the mask drawable */ private static Drawable getRippleMask(int color, int radius) { float[] outerRadius = new float[8]; Arrays.fill(outerRadius, radius); RoundRectShape r = new RoundRectShape(outerRadius, null, null); ShapeDrawable shapeDrawable = new ShapeDrawable(r); shapeDrawable.getPaint().setColor(color); return shapeDrawable; }
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; }
ShapeDrawable footerBackground = new ShapeDrawable(); // The corners are ordered top-left, top-right, bottom-right, // bottom-left. For each corner, the array contains 2 values, [X_radius, // Y_radius] float[] radii = new float[8]; radii[0] = activity.getResources().getDimension(R.dimen.footer_corners); radii[1] = activity.getResources().getDimension(R.dimen.footer_corners); radii[2] = activity.getResources().getDimension(R.dimen.footer_corners); radii[3] = activity.getResources().getDimension(R.dimen.footer_corners); footerBackground.setShape(new RoundRectShape(radii, null, null)); int color = ((Application) activity.getApplication()).getColor(); footerBackground.getPaint().setColor(color); views.setBackgroundDrawable(footerBackground);
// Draw a simple progressBar from xml progressBar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal); // Convert the color (Decimal value) to HEX value: (e.g: #4b96a0) String color = colorDecToHex(75, 150, 160); // Define a shape with rounded corners final float[] roundedCorners = new float[] { 5, 5, 5, 5, 5, 5, 5, 5 }; ShapeDrawable pgDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners, null, null)); // Sets the progressBar color pgDrawable.getPaint().setColor(Color.parseColor(color)); // Adds the drawable to your progressBar ClipDrawable progress = new ClipDrawable(pgDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL); progressBar.setProgressDrawable(progress); // Sets a background to have the 3D effect progressBar.setBackgroundDrawable(Utils.getActivity().getResources() .getDrawable(android.R.drawable.progress_horizontal)); // Adds your progressBar to your layout contentLayout.addView(progressBar);
@NonNull private static Drawable getRippleMask(int color) { float[] outerRadii = new float[8]; // 3 is radius of final ripple, // instead of 3 you can give required final radius Arrays.fill(outerRadii, 3); RoundRectShape r = new RoundRectShape(outerRadii, null, null); ShapeDrawable shapeDrawable = new ShapeDrawable(r); shapeDrawable.getPaint().setColor(color); return shapeDrawable; }
new RoundRectShape(m_arrfTopHalfOuterRadii, null, null); ShapeDrawable top_shape_drawable = new ShapeDrawable(top_round_rect); top_shape_drawable.getPaint().setColor(m_nTopColor); new RoundRectShape(m_arrfBottomHalfOuterRadii, null, null); ShapeDrawable bottom_shape_drawable = new ShapeDrawable(bottom_round_rect); bottom_shape_drawable.getPaint().setColor(m_nBottomColor);
private Drawable buildRatingBarDrawables(Bitmap[] images) { final int[] requiredIds = { android.R.id.background, android.R.id.secondaryProgress, android.R.id.progress }; final float[] roundedCorners = new float[] { 5, 5, 5, 5, 5, 5, 5, 5 }; Drawable[] pieces = new Drawable[3]; for (int i = 0; i < 3; i++) { ShapeDrawable sd = new ShapeDrawable(new RoundRectShape( roundedCorners, null, null)); BitmapShader bitmapShader = new BitmapShader(images[i], Shader.TileMode.REPEAT, Shader.TileMode.CLAMP); sd.getPaint().setShader(bitmapShader); ClipDrawable cd = new ClipDrawable(sd, Gravity.LEFT, ClipDrawable.HORIZONTAL); if (i == 0) { pieces[i] = sd; } else { pieces[i] = cd; } } LayerDrawable ld = new LayerDrawable(pieces); for (int i = 0; i < 3; i++) { ld.setId(i, requiredIds[i]); } return ld; }
@Override public IBuilder roundRect(int radius) { this.radius = radius; float[] radii = {radius, radius, radius, radius, radius, radius, radius, radius}; this.shape = new RoundRectShape(radii, null, null); return this; }
Shape getDrawableShape() { final float[] roundedCorners = new float[]{5, 5, 5, 5, 5, 5, 5, 5}; return new RoundRectShape(roundedCorners, null, null); }
@Override public IBuilder roundRect(int radius) { this.radius = radius; float[] radii = {radius, radius, radius, radius, radius, radius, radius, radius}; this.shape = new RoundRectShape(radii, null, null); return this; }
//Create new ClipDrawable to replace the old one float pxCornerRadius = viewUtils.convertDpToPixel(5); final float[] roundedCorners = new float[] { pxCornerRadius, pxCornerRadius, pxCornerRadius, pxCornerRadius, pxCornerRadius, pxCornerRadius, pxCornerRadius, pxCornerRadius }; ShapeDrawable shpDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners, null, null)); shpDrawable.getPaint().setColor(Color.CYAN); final ClipDrawable newProgressClip = new ClipDrawable(shpDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL); //Replace the existing ClipDrawable with this new one final LayerDrawable layers = (LayerDrawable) progressBar.getProgressDrawable(); layers.setDrawableByLayerId(R.id.my_progress, newProgressClip);
private static Drawable getRippleMask(int color) { float[] outerRadii = new float[8]; // 3 is radius of final ripple, // instead of 3 you can give required final radius Arrays.fill(outerRadii, 3); RoundRectShape r = new RoundRectShape(outerRadii, null, null); ShapeDrawable shapeDrawable = new ShapeDrawable(r); shapeDrawable.getPaint().setColor(color); return shapeDrawable; } }
private ShapeDrawable getDefaultBackground() { int r = dipToPixels(DEFAULT_CORNER_RADIUS_DIP); 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(badgeColor); return drawable; }
private void setBottomCorners(View llBtnGroup) { int radius = DisplayUtil.dp2px(getContext(), DEFAULT_RADIUS); float[] outerRadii = new float[] { 0, 0, 0, 0, radius, radius, radius, radius }; RoundRectShape roundRectShape = new RoundRectShape(outerRadii, null, null); ShapeDrawable shapeDrawable = new ShapeDrawable(roundRectShape); shapeDrawable.getPaint().setColor(Color.WHITE); shapeDrawable.getPaint().setStyle(Paint.Style.FILL); llBtnGroup.setBackgroundDrawable(shapeDrawable); }
private void setBackgroundColor() { if (0 == mBackgroundColor) { return; } int radius = DisplayUtil.dp2px(getContext(), 6); float[] outerRadii = new float[] { radius, radius, radius, radius, 0, 0, 0, 0 }; RoundRectShape roundRectShape = new RoundRectShape(outerRadii, null, null); ShapeDrawable shapeDrawable = new ShapeDrawable(roundRectShape); shapeDrawable.getPaint().setColor(mBackgroundColor); shapeDrawable.getPaint().setStyle(Paint.Style.FILL); mBkgView.setBackgroundDrawable(shapeDrawable); }