List of usage examples for android.graphics Path addRoundRect
public void addRoundRect(RectF rect, float rx, float ry, Direction dir)
From source file:Main.java
public static Path addRoundPath3(int width, int height, float radius) { Path path = new Path(); path.addRoundRect(new RectF(0, 0, width, height), radius, radius, Path.Direction.CW); return path;/* w w w . java 2 s . c om*/ }
From source file:Main.java
private static void drawTouchIconToCanvas(Bitmap touchIcon, Canvas canvas, Rect iconBounds) { Rect src = new Rect(0, 0, touchIcon.getWidth(), touchIcon.getHeight()); // Paint used for scaling the bitmap and drawing the rounded rect. Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setFilterBitmap(true);/*from w ww .ja v a2 s. c o m*/ canvas.drawBitmap(touchIcon, src, iconBounds, paint); // Construct a path from a round rect. This will allow drawing with // an inverse fill so we can punch a hole using the round rect. Path path = new Path(); path.setFillType(Path.FillType.INVERSE_WINDING); RectF rect = new RectF(iconBounds); rect.inset(1, 1); path.addRoundRect(rect, 8f, 8f, Path.Direction.CW); // Reuse the paint and clear the outside of the rectangle. paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); canvas.drawPath(path, paint); }
From source file:Main.java
/** * Use touch-icon or higher-resolution favicon and round the corners. * @param context Context used to get resources. * @param touchIcon Touch icon bitmap.//w w w . j av a2 s. c o m * @param canvas Canvas that holds the touch icon. */ private static void drawTouchIconToCanvas(Context context, Bitmap touchIcon, Canvas canvas) { Rect iconBounds = new Rect(0, 0, canvas.getWidth(), canvas.getHeight()); Rect src = new Rect(0, 0, touchIcon.getWidth(), touchIcon.getHeight()); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setFilterBitmap(true); canvas.drawBitmap(touchIcon, src, iconBounds, paint); // Convert dp to px. int borderRadii = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, TOUCHICON_BORDER_RADII, context.getResources().getDisplayMetrics()); Path path = new Path(); path.setFillType(Path.FillType.INVERSE_WINDING); RectF rect = new RectF(iconBounds); rect.inset(INSET_DIMENSION_FOR_TOUCHICON, INSET_DIMENSION_FOR_TOUCHICON); path.addRoundRect(rect, borderRadii, borderRadii, Path.Direction.CW); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); canvas.drawPath(path, paint); }
From source file:com.skytree.epubtest.BookViewActivity.java
@SuppressLint({ "DrawAllocation", "DrawAllocation" })
@Override// w ww . jav a 2s .co m
protected void onDraw(Canvas canvas) {
Paint paint = new Paint();
float sl, sr, st, sb;
sl = 0;
sr = this.getWidth();
float ah = this.arrowHeight; // arrow Height;
if (this.isArrowDown) {
st = 0;
sb = this.getHeight() - ah;
} else {
st = ah - 10;
sb = this.getHeight() - 10;
}
Path boxPath = new Path();
boxPath.addRoundRect(new RectF(sl, st, sr, sb), 20, 20, Path.Direction.CW);
if (arrowPosition <= arrowHeight * 1.5f) {
arrowPosition = arrowHeight * 1.5f;
} else if (arrowPosition >= this.getWidth() - arrowHeight * 1.5f) {
arrowPosition = this.getWidth() - arrowHeight * 1.5f;
}
Path arrowPath = new Path();
if (isArrowDown) {
arrowPath.moveTo(arrowPosition, sb + ah);
arrowPath.lineTo((float) (arrowPosition - ah * 0.75), sb - 10);
arrowPath.lineTo((float) (arrowPosition + ah * 0.75), sb - 10);
arrowPath.close();
} else {
arrowPath.moveTo(arrowPosition, 0);
arrowPath.lineTo((float) (arrowPosition - ah * 0.75), ah + 10);
arrowPath.lineTo((float) (arrowPosition + ah * 0.75), ah + 10);
arrowPath.close();
}
paint.setColor(this.strokeColor);
paint.setStyle(Paint.Style.FILL);
boxPath.addPath(arrowPath);
canvas.drawPath(boxPath, paint);
paint.setColor(this.boxColor);
paint.setStyle(Paint.Style.FILL);
boxPath.addPath(arrowPath);
canvas.save();
float sf = 0.995f;
float ox = (this.getWidth() - (this.getWidth() * sf)) / 2.0f;
float oy = ((this.getHeight() - arrowHeight) - ((this.getHeight() - arrowHeight) * sf)) / 2.0f;
canvas.translate(ox, oy);
canvas.scale(sf, sf);
canvas.drawPath(boxPath, paint);
canvas.restore();
if (layoutChanged) {
this.recalcLayout();
layoutChanged = false;
}
}