Search in sources :

Example 31 with Path

use of android.graphics.Path in project UltimateAndroid by cymcsg.

the class CirclesDrawable method initCirclesProgress.

private void initCirclesProgress(int[] colors) {
    initColors(colors);
    mPath = new Path();
    Paint basePaint = new Paint();
    basePaint.setAntiAlias(true);
    mFstHalfPaint = new Paint(basePaint);
    mScndHalfPaint = new Paint(basePaint);
    mAbovePaint = new Paint(basePaint);
    setColorFilter(mColorFilter);
}
Also used : Path(android.graphics.Path) Paint(android.graphics.Paint)

Example 32 with Path

use of android.graphics.Path in project UltimateAndroid by cymcsg.

the class CirclesDrawable method initCirclesProgress.

private void initCirclesProgress(int[] colors) {
    initColors(colors);
    mPath = new Path();
    Paint basePaint = new Paint();
    basePaint.setAntiAlias(true);
    mFstHalfPaint = new Paint(basePaint);
    mScndHalfPaint = new Paint(basePaint);
    mAbovePaint = new Paint(basePaint);
    setColorFilter(mColorFilter);
}
Also used : Path(android.graphics.Path) Paint(android.graphics.Paint)

Example 33 with Path

use of android.graphics.Path in project UltimateAndroid by cymcsg.

the class HomeDiagram method drawBrokenLine.

/**
	 * 绘制折线
	 * 
	 * @param c
	 */
public void drawBrokenLine(Canvas c) {
    int index = 0;
    float temp_x = 0;
    float temp_y = 0;
    float base = (getHeight() - tb * 3.0f) / (Collections.max(milliliter) - Collections.min(milliliter));
    Shader mShader = new LinearGradient(0, 0, 0, getHeight(), new int[] { Color.argb(100, 0, 255, 255), Color.argb(45, 0, 255, 255), Color.argb(10, 0, 255, 255) }, null, Shader.TileMode.CLAMP);
    framPanint.setShader(mShader);
    for (int i = 0; i < milliliter.size() - 1; i++) {
        float x1 = interval_left_right * i;
        float y1 = getHeight() - tb * 1.5f - (base * milliliter.get(i));
        float x2 = interval_left_right * (i + 1);
        float y2 = getHeight() - tb * 1.5f - (base * milliliter.get(i + 1));
        if ((int) (base * milliliter.get(i + 1)) == 0 && index == 0) {
            index++;
            temp_x = x1;
            temp_y = y1;
        }
        if ((int) (base * milliliter.get(i + 1)) != 0 && index != 0) {
            index = 0;
            x1 = temp_x;
            y1 = temp_y;
        }
        if (index == 0) {
            c.drawLine(x1, y1, x2, y2, paint_brokenLine);
            path.lineTo(x1, y1);
            if (i != 0)
                c.drawBitmap(bitmap_point, x1 - bitmap_point.getWidth() / 2, y1 - bitmap_point.getHeight() / 2, null);
            if (i == milliliter.size() - 2) {
                path.lineTo(x2, y2);
                path.lineTo(x2, getHeight());
                path.lineTo(0, getHeight());
                path.close();
                c.drawPath(path, framPanint);
                c.drawBitmap(bitmap_point, x2 - bitmap_point.getWidth() / 2, y2 - bitmap_point.getHeight() / 2, null);
            }
        }
    }
    paint_dottedline.setColor(orangeLineColor);
    Path path = new Path();
    path.moveTo(0, getHeight() - tb * 6.5f);
    path.lineTo(getWidth(), getHeight() - tb * 6.5f);
    PathEffect effects = new DashPathEffect(new float[] { tb * 0.3f, tb * 0.3f, tb * 0.3f, tb * 0.3f }, tb * 0.1f);
    paint_dottedline.setPathEffect(effects);
    c.drawPath(path, paint_dottedline);
}
Also used : Path(android.graphics.Path) LinearGradient(android.graphics.LinearGradient) DashPathEffect(android.graphics.DashPathEffect) PathEffect(android.graphics.PathEffect) DashPathEffect(android.graphics.DashPathEffect) Shader(android.graphics.Shader) Paint(android.graphics.Paint)

Example 34 with Path

use of android.graphics.Path in project UltimateAndroid by cymcsg.

the class TimelyView method init.

private void init() {
    // A new paint with the style as stroke.
    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setColor(Color.BLACK);
    mPaint.setStrokeWidth(5.0f);
    mPaint.setStyle(Paint.Style.STROKE);
    mPath = new Path();
}
Also used : Path(android.graphics.Path) Paint(android.graphics.Paint)

Example 35 with Path

use of android.graphics.Path in project plaid by nickbutcher.

the class GravityArcMotion method getPath.

@Override
public Path getPath(float startX, float startY, float endX, float endY) {
    // Here's a little ascii art to show how this is calculated:
    // c---------- b
    //  \        / |
    //    \     d  |
    //      \  /   e
    //        a----f
    // This diagram assumes that the horizontal distance is less than the vertical
    // distance between The start point (a) and end point (b).
    // d is the midpoint between a and b. c is the center point of the circle with
    // This path is formed by assuming that start and end points are in
    // an arc on a circle. The end point is centered in the circle vertically
    // and start is a point on the circle.
    // Triangles bfa and bde form similar right triangles. The control points
    // for the cubic Bezier arc path are the midpoints between a and e and e and b.
    Path path = new Path();
    path.moveTo(startX, startY);
    float ex;
    float ey;
    if (startY == endY) {
        ex = (startX + endX) / 2;
        ey = startY + mMinimumHorizontalTangent * Math.abs(endX - startX) / 2;
    } else if (startX == endX) {
        ex = startX + mMinimumVerticalTangent * Math.abs(endY - startY) / 2;
        ey = (startY + endY) / 2;
    } else {
        float deltaX = endX - startX;
        /**
             * This is the only change to ArcMotion
             */
        float deltaY;
        if (endY < startY) {
            // Y is inverted compared to diagram above.
            deltaY = startY - endY;
        } else {
            deltaY = endY - startY;
        }
        /**
             * End changes
             */
        // hypotenuse squared.
        float h2 = deltaX * deltaX + deltaY * deltaY;
        // Midpoint between start and end
        float dx = (startX + endX) / 2;
        float dy = (startY + endY) / 2;
        // Distance squared between end point and mid point is (1/2 hypotenuse)^2
        float midDist2 = h2 * 0.25f;
        float minimumArcDist2 = 0;
        if (Math.abs(deltaX) < Math.abs(deltaY)) {
            // Similar triangles bfa and bde mean that (ab/fb = eb/bd)
            // Therefore, eb = ab * bd / fb
            // ab = hypotenuse
            // bd = hypotenuse/2
            // fb = deltaY
            float eDistY = h2 / (2 * deltaY);
            ey = endY + eDistY;
            ex = endX;
            minimumArcDist2 = midDist2 * mMinimumVerticalTangent * mMinimumVerticalTangent;
        } else {
            // Same as above, but flip X & Y
            float eDistX = h2 / (2 * deltaX);
            ex = endX + eDistX;
            ey = endY;
            minimumArcDist2 = midDist2 * mMinimumHorizontalTangent * mMinimumHorizontalTangent;
        }
        float arcDistX = dx - ex;
        float arcDistY = dy - ey;
        float arcDist2 = arcDistX * arcDistX + arcDistY * arcDistY;
        float maximumArcDist2 = midDist2 * mMaximumTangent * mMaximumTangent;
        float newArcDistance2 = 0;
        if (arcDist2 < minimumArcDist2) {
            newArcDistance2 = minimumArcDist2;
        } else if (arcDist2 > maximumArcDist2) {
            newArcDistance2 = maximumArcDist2;
        }
        if (newArcDistance2 != 0) {
            float ratio2 = newArcDistance2 / arcDist2;
            float ratio = (float) Math.sqrt(ratio2);
            ex = dx + (ratio * (ex - dx));
            ey = dy + (ratio * (ey - dy));
        }
    }
    float controlX1 = (startX + ex) / 2;
    float controlY1 = (startY + ey) / 2;
    float controlX2 = (ex + endX) / 2;
    float controlY2 = (ey + endY) / 2;
    path.cubicTo(controlX1, controlY1, controlX2, controlY2, endX, endY);
    return path;
}
Also used : Path(android.graphics.Path)

Aggregations

Path (android.graphics.Path)1012 Paint (android.graphics.Paint)462 RectF (android.graphics.RectF)289 Matrix (android.graphics.Matrix)74 Rect (android.graphics.Rect)59 Canvas (android.graphics.Canvas)53 TextPaint (android.text.TextPaint)37 Bitmap (android.graphics.Bitmap)36 PointF (android.graphics.PointF)29 Point (android.graphics.Point)28 LinearGradient (android.graphics.LinearGradient)24 View (android.view.View)24 ObjectAnimator (android.animation.ObjectAnimator)23 Stack (java.util.Stack)22 Animator (android.animation.Animator)18 PathMeasure (android.graphics.PathMeasure)18 RadialGradient (android.graphics.RadialGradient)17 Test (org.junit.Test)15 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)14 DashPathEffect (android.graphics.DashPathEffect)14