Search in sources :

Example 46 with Path

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;
}
Also used : Path(android.graphics.Path)

Example 47 with 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;
}
Also used : Path(android.graphics.Path) Matrix(android.graphics.Matrix) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint)

Example 48 with Path

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;
}
Also used : Path(android.graphics.Path)

Example 49 with 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);
    }
}
Also used : Path(android.graphics.Path) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 50 with Path

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;
}
Also used : RectF(android.graphics.RectF) Path(android.graphics.Path)

Aggregations

Path (android.graphics.Path)631 Paint (android.graphics.Paint)237 RectF (android.graphics.RectF)142 Rect (android.graphics.Rect)40 Canvas (android.graphics.Canvas)39 Matrix (android.graphics.Matrix)36 TextPaint (android.text.TextPaint)27 Bitmap (android.graphics.Bitmap)26 ObjectAnimator (android.animation.ObjectAnimator)18 LinearGradient (android.graphics.LinearGradient)18 PointF (android.graphics.PointF)18 Point (android.graphics.Point)16 View (android.view.View)16 RadialGradient (android.graphics.RadialGradient)15 Animator (android.animation.Animator)13 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)12 PathMeasure (android.graphics.PathMeasure)11 PropertyValuesHolder (android.animation.PropertyValuesHolder)10 InflateException (android.view.InflateException)10 ViewGroup (android.view.ViewGroup)10