下面列出了android.graphics.Path#addOval ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Draw the {@link EdgeDetail} for this View. Note that on API 11 - 17 clipPath is only available
* if HardwareAcceleration is disable. A function {@link DecoView#enableCompatibilityMode()}
* is provided which will disable on affected platforms however this needs to be explicitly
* called by the user, otherwise EdgeDetails will not be drawn
*
* @param canvas Canvas to draw to
*/
private void drawArcEdgeDetail(@NonNull Canvas canvas) {
ArrayList<EdgeDetail> edgeDetailList = getSeriesItem().getEdgeDetail();
if (edgeDetailList == null) {
return;
}
for (EdgeDetail edgeDetail : edgeDetailList) {
final boolean drawInner = edgeDetail.getEdgeType() == EdgeDetail.EdgeType.EDGE_INNER;
if (edgeDetail.getClipPath() == null) {
float inset = (edgeDetail.getRatio() - 0.5f) * mSeriesItem.getLineWidth();
if (drawInner) {
inset = -inset;
}
Path clipPath = new Path();
RectF clipRect = new RectF(mBoundsInset);
clipRect.inset(inset, inset);
clipPath.addOval(clipRect, Path.Direction.CW);
edgeDetail.setClipPath(clipPath);
}
drawClippedArc(canvas, edgeDetail.getClipPath(), edgeDetail.getColor(),
drawInner ? Region.Op.INTERSECT : Region.Op.DIFFERENCE);
}
}
@Override
protected Path getPath(Canvas canvas, Paint paint) {
Path path = new Path();
float cx = ParserHelper.fromPercentageToFloat(mCx, mCanvasWidth, 0, mScale);
float cy = ParserHelper.fromPercentageToFloat(mCy, mCanvasHeight, 0, mScale);
float rx = ParserHelper.fromPercentageToFloat(mRx, mCanvasWidth, 0, mScale);
float ry = ParserHelper.fromPercentageToFloat(mRy, mCanvasHeight, 0, mScale);
RectF oval = new RectF(cx - rx, cy - ry, cx + rx, cy + ry);
path.addOval(oval, Path.Direction.CW);
return path;
}
/**
* Draw the {@link EdgeDetail} for this View. Note that on API 11 - 17 clipPath is only available
* if HardwareAcceleration is disable. A function {@link DecoView#enableCompatibilityMode()}
* is provided which will disable on affected platforms however this needs to be explicitly
* called by the user, otherwise EdgeDetails will not be drawn
*
* @param canvas Canvas to draw to
*/
private void drawArcEdgeDetail(@NonNull Canvas canvas) {
ArrayList<EdgeDetail> edgeDetailList = getSeriesItem().getEdgeDetail();
if (edgeDetailList == null) {
return;
}
for (EdgeDetail edgeDetail : edgeDetailList) {
final boolean drawInner = edgeDetail.getEdgeType() == EdgeDetail.EdgeType.EDGE_INNER;
if (drawInner) {
//TODO: Implement EDGE_INNER for pie
Log.w(TAG, "EDGE_INNER Not Yet Implemented for pie chart");
continue;
}
if (edgeDetail.getClipPath() == null) {
float inset = (edgeDetail.getRatio() - 0.5f) * mPaint.getStrokeWidth();
Path clipPath = new Path();
RectF clipRect = new RectF(mBoundsInset);
clipRect.inset(inset, inset);
clipPath.addOval(clipRect, Path.Direction.CW);
edgeDetail.setClipPath(clipPath);
}
//noinspection ConstantConditions
drawClippedArc(canvas, edgeDetail.getClipPath(), edgeDetail.getColor(),
drawInner ? Region.Op.INTERSECT : Region.Op.DIFFERENCE);
}
}
@Override
public void addOval(Path path, float left, float top, float right, float bottom,
Path.Direction dir) {
final RectF oval = get();
oval.set(left, top, right, bottom);
path.addOval(oval, dir);
put(oval);
}
@Override
public void addOval(Path path, float left, float top, float right, float bottom,
Path.Direction dir) {
final RectF oval = get();
oval.set(left, top, right, bottom);
path.addOval(oval, dir);
put(oval);
}
@Override
protected Path newPath() {
Path path = ObjectPool.pathPool.checkOut();
RectF rect = new RectF(center.x - radiusX, center.y - radiusY, center.x + radiusX, center.y
+ radiusY);
path.addOval(rect, Direction.CW);
return path;
}
@Override
protected Path createShapePath() {
Path path = new Path();
path.addOval(shapeBox, Path.Direction.CW);
return path;
}
@Override
protected void onResetPath(Path path, Rect bounds) {
path.reset();
path.addOval(bounds.left, bounds.top, bounds.right, bounds.bottom, Path.Direction.CW);
}
@Override
protected void onResetPath(Path path, Rect bounds) {
path.reset();
path.addOval(bounds.left - 1, bounds.top - 1, bounds.right + 1, bounds.bottom + 1, Path.Direction.CW);
}
@Override
public void addOval(Path path, float left, float top, float right, float bottom,
Path.Direction dir) {
path.addOval(left, top, right, bottom, dir);
}
@Override
public void addOval(Path path, float left, float top, float right, float bottom,
Path.Direction dir) {
path.addOval(left, top, right, bottom, dir);
}
public static void addEllipse(Path path, float x, float y, float w, float h)
{
path.addOval(new RectF(x, y, x + w, y + h), Direction.CW);
}
public static void addEllipse(Path path, float x, float y, float w, float h, Direction dir)
{
path.addOval(new RectF(x, y, x + w, y + h), dir);
}