use of android.graphics.Path in project DiagonalLayout by florent37.
the class DiagonalLayout method createClipPath.
private Path createClipPath(float perpendicularHeight) {
Path path = new Path();
if (settings.isBottom()) {
if (settings.isDirectionLeft()) {
path.moveTo(width - getPaddingRight() + EPSILON, height - perpendicularHeight - getPaddingBottom() + EPSILON);
path.lineTo(width - getPaddingRight() + EPSILON, height - getPaddingBottom() + EPSILON);
path.lineTo(getPaddingLeft() - EPSILON, height - getPaddingBottom() + EPSILON);
path.close();
} else {
path.moveTo(width - getPaddingRight() + EPSILON, height - getPaddingBottom() + EPSILON);
path.lineTo(getPaddingLeft() - EPSILON, height - getPaddingBottom() + EPSILON);
path.lineTo(getPaddingLeft() - EPSILON, height - perpendicularHeight - getPaddingBottom() + EPSILON);
path.close();
}
} else if (settings.isTop()) {
if (settings.isDirectionLeft()) {
path.moveTo(width - getPaddingRight() + EPSILON, getPaddingTop() + perpendicularHeight - EPSILON);
path.lineTo(getPaddingLeft() - EPSILON, getPaddingTop() - EPSILON);
path.lineTo(width - getPaddingRight() + EPSILON, getPaddingTop() - EPSILON);
path.close();
} else {
path.moveTo(width - getPaddingRight() + EPSILON, getPaddingTop() - EPSILON);
path.lineTo(getPaddingLeft() - EPSILON, getPaddingTop() + perpendicularHeight - EPSILON);
path.lineTo(getPaddingLeft() - EPSILON, getPaddingTop() - EPSILON);
path.close();
}
} else if (settings.isRight()) {
if (settings.isDirectionLeft()) {
path.moveTo(width - getPaddingRight() + EPSILON, getPaddingTop() - EPSILON);
path.lineTo(width - getPaddingRight() + EPSILON, height - getPaddingBottom() + EPSILON);
path.lineTo(width - perpendicularHeight - getPaddingRight() + EPSILON, height - getPaddingBottom() + EPSILON);
path.close();
} else {
path.moveTo(width - perpendicularHeight - getPaddingRight() - EPSILON, getPaddingTop() - EPSILON);
path.lineTo(width - getPaddingRight() + EPSILON, getPaddingTop() - EPSILON);
path.lineTo(width - getPaddingRight() + EPSILON, height - getPaddingBottom() + EPSILON);
path.close();
}
} else if (settings.isLeft()) {
if (settings.isDirectionLeft()) {
path.moveTo(getPaddingLeft() - EPSILON, getPaddingTop() - EPSILON);
path.lineTo(getPaddingLeft() + perpendicularHeight + EPSILON, getPaddingTop() - EPSILON);
path.lineTo(getPaddingLeft() - EPSILON, height - getPaddingBottom() + EPSILON);
path.close();
} else {
path.moveTo(getPaddingLeft() - EPSILON, getPaddingTop() - EPSILON);
path.lineTo(getPaddingLeft() + perpendicularHeight + EPSILON, height - getPaddingBottom() + EPSILON);
path.lineTo(getPaddingLeft() - EPSILON, height - getPaddingBottom() + EPSILON);
path.close();
}
}
return path;
}
use of android.graphics.Path in project android-pathview by geftimov.
the class SvgUtils method getPathsForViewport.
/**
* Render the svg to canvas and catch all the paths while rendering.
*
* @param width - the width to scale down the view to,
* @param height - the height to scale down the view to,
* @return All the paths from the svg.
*/
public List<SvgPath> getPathsForViewport(final int width, final int height) {
final float strokeWidth = mSourcePaint.getStrokeWidth();
Canvas canvas = new Canvas() {
private final Matrix mMatrix = new Matrix();
@Override
public int getWidth() {
return width;
}
@Override
public int getHeight() {
return height;
}
@Override
public void drawPath(Path path, Paint paint) {
Path dst = new Path();
//noinspection deprecation
getMatrix(mMatrix);
path.transform(mMatrix, dst);
paint.setAntiAlias(true);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(strokeWidth);
mPaths.add(new SvgPath(dst, paint));
}
};
rescaleCanvas(width, height, strokeWidth, canvas);
return mPaths;
}
use of android.graphics.Path in project android-pathview by geftimov.
the class SecondActivity method makeConvexArrow.
private Path makeConvexArrow(float length, float height) {
final Path path = new Path();
path.moveTo(0.0f, 0.0f);
path.lineTo(length / 4f, 0.0f);
path.lineTo(length, height / 2.0f);
path.lineTo(length / 4f, height);
path.lineTo(0.0f, height);
path.lineTo(length * 3f / 4f, height / 2f);
path.lineTo(0.0f, 0.0f);
path.close();
return path;
}
use of android.graphics.Path in project XobotOS by xamarin.
the class BulletSpan method drawLeadingMargin.
public void drawLeadingMargin(Canvas c, Paint p, int x, int dir, int top, int baseline, int bottom, CharSequence text, int start, int end, boolean first, Layout l) {
if (((Spanned) text).getSpanStart(this) == start) {
Paint.Style style = p.getStyle();
int oldcolor = 0;
if (mWantColor) {
oldcolor = p.getColor();
p.setColor(mColor);
}
p.setStyle(Paint.Style.FILL);
if (c.isHardwareAccelerated()) {
if (sBulletPath == null) {
sBulletPath = new Path();
// Bullet is slightly better to avoid aliasing artifacts on mdpi devices.
sBulletPath.addCircle(0.0f, 0.0f, 1.2f * BULLET_RADIUS, Direction.CW);
}
c.save();
c.translate(x + dir * BULLET_RADIUS, (top + bottom) / 2.0f);
c.drawPath(sBulletPath, p);
c.restore();
} else {
c.drawCircle(x + dir * BULLET_RADIUS, (top + bottom) / 2.0f, BULLET_RADIUS, p);
}
if (mWantColor) {
p.setColor(oldcolor);
}
p.setStyle(style);
}
}
use of android.graphics.Path in project XobotOS by xamarin.
the class GradientDrawable method buildRing.
private Path buildRing(GradientState st) {
if (mRingPath != null && (!st.mUseLevelForShape || !mPathIsDirty))
return mRingPath;
mPathIsDirty = false;
float sweep = st.mUseLevelForShape ? (360.0f * getLevel() / 10000.0f) : 360f;
RectF bounds = new RectF(mRect);
float x = bounds.width() / 2.0f;
float y = bounds.height() / 2.0f;
float thickness = st.mThickness != -1 ? st.mThickness : bounds.width() / st.mThicknessRatio;
// inner radius
float radius = st.mInnerRadius != -1 ? st.mInnerRadius : bounds.width() / st.mInnerRadiusRatio;
RectF innerBounds = new RectF(bounds);
innerBounds.inset(x - radius, y - radius);
bounds = new RectF(innerBounds);
bounds.inset(-thickness, -thickness);
if (mRingPath == null) {
mRingPath = new Path();
} else {
mRingPath.reset();
}
final Path ringPath = mRingPath;
// think 360 means draw the entire oval
if (sweep < 360 && sweep > -360) {
ringPath.setFillType(Path.FillType.EVEN_ODD);
// inner top
ringPath.moveTo(x + radius, y);
// outer top
ringPath.lineTo(x + radius + thickness, y);
// outer arc
ringPath.arcTo(bounds, 0.0f, sweep, false);
// inner arc
ringPath.arcTo(innerBounds, sweep, -sweep, false);
ringPath.close();
} else {
// add the entire ovals
ringPath.addOval(bounds, Path.Direction.CW);
ringPath.addOval(innerBounds, Path.Direction.CCW);
}
return ringPath;
}
Aggregations