Search in sources :

Example 11 with PathMeasure

use of android.graphics.PathMeasure in project MaterialLibrary by DeveloperPaul123.

the class CircularTextView method onDraw.

@Override
protected void onDraw(Canvas canvas) {
    if (text == null) {
        text = "A";
    }
    if (checkMarkPath == null) {
        checkMarkPath = getCheckMarkPath();
        PathMeasure measure = new PathMeasure(checkMarkPath, false);
        pathLength = measure.getLength();
    }
    if (text.length() != 1) {
        textPaint.setTextSize(mTextSize * 0.87f);
    } else {
        textPaint.setTextSize(mTextSize);
    }
    canvas.drawCircle(cx, cy, diameter / 2, backgroundPaint);
    canvas.drawText(text, cx, cy + mTextSize / 3.0f, textPaint);
    if (isBackShowing) {
        canvas.save();
        canvas.translate(-2 * oneDp, 4 * oneDp);
        canvas.drawPath(checkMarkPath, checkMarkPaint);
        canvas.restore();
    }
}
Also used : PathMeasure(android.graphics.PathMeasure)

Example 12 with PathMeasure

use of android.graphics.PathMeasure in project AndroidFillableLoaders by JorgeCastilloPrz.

the class FillableLoader method buildPathData.

private void buildPathData() {
    SvgPathParser parser = getPathParser();
    pathData = new PathData();
    try {
        pathData.path = parser.parsePath(svgPath);
    } catch (ParseException e) {
        pathData.path = new Path();
    }
    PathMeasure pm = new PathMeasure(pathData.path, true);
    while (true) {
        pathData.length = Math.max(pathData.length, pm.getLength());
        if (!pm.nextContour()) {
            break;
        }
    }
}
Also used : Path(android.graphics.Path) PathMeasure(android.graphics.PathMeasure) SvgPathParser(com.github.jorgecastillo.svg.SvgPathParser) ConstrainedSvgPathParser(com.github.jorgecastillo.svg.ConstrainedSvgPathParser) ParseException(java.text.ParseException)

Example 13 with PathMeasure

use of android.graphics.PathMeasure in project muzei by romannurik.

the class AnimatedMuzeiLoadingSpinnerView method rebuildGlyphData.

private void rebuildGlyphData() {
    SvgPathParser parser = new SvgPathParser() {

        @Override
        protected float transformX(float x) {
            return x * mWidth / VIEWPORT.width();
        }

        @Override
        protected float transformY(float y) {
            return y * mHeight / VIEWPORT.height();
        }
    };
    mGlyphData = new GlyphData();
    try {
        mGlyphData.path = parser.parsePath(LogoPaths.GLYPHS[0]);
    } catch (ParseException e) {
        mGlyphData.path = new Path();
        Log.e(TAG, "Couldn't parse path", e);
    }
    PathMeasure pm = new PathMeasure(mGlyphData.path, true);
    while (true) {
        mGlyphData.length = Math.max(mGlyphData.length, pm.getLength());
        if (!pm.nextContour()) {
            break;
        }
    }
    mGlyphData.paint = new Paint();
    mGlyphData.paint.setStyle(Paint.Style.STROKE);
    mGlyphData.paint.setAntiAlias(true);
    mGlyphData.paint.setColor(Color.WHITE);
    mGlyphData.paint.setStrokeWidth(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics()));
}
Also used : Path(android.graphics.Path) PathMeasure(android.graphics.PathMeasure) ParseException(java.text.ParseException) Paint(android.graphics.Paint)

Example 14 with PathMeasure

use of android.graphics.PathMeasure in project android_frameworks_base by DirtyUnicorns.

the class PatternPathMotion method setPatternPath.

/**
     * Sets the Path defining a pattern of motion between two coordinates.
     * The pattern will be translated, rotated, and scaled to fit between the start and end points.
     * The pattern must not be empty and must have the end point differ from the start point.
     *
     * @param patternPath A Path to be used as a pattern for two-dimensional motion.
     * @attr ref android.R.styleable#PatternPathMotion_patternPathData
     */
public void setPatternPath(Path patternPath) {
    PathMeasure pathMeasure = new PathMeasure(patternPath, false);
    float length = pathMeasure.getLength();
    float[] pos = new float[2];
    pathMeasure.getPosTan(length, pos, null);
    float endX = pos[0];
    float endY = pos[1];
    pathMeasure.getPosTan(0, pos, null);
    float startX = pos[0];
    float startY = pos[1];
    if (startX == endX && startY == endY) {
        throw new IllegalArgumentException("pattern must not end at the starting point");
    }
    mTempMatrix.setTranslate(-startX, -startY);
    float dx = endX - startX;
    float dy = endY - startY;
    float distance = (float) Math.hypot(dx, dy);
    float scale = 1 / distance;
    mTempMatrix.postScale(scale, scale);
    double angle = Math.atan2(dy, dx);
    mTempMatrix.postRotate((float) Math.toDegrees(-angle));
    patternPath.transform(mTempMatrix, mPatternPath);
    mOriginalPatternPath = patternPath;
}
Also used : PathMeasure(android.graphics.PathMeasure)

Example 15 with PathMeasure

use of android.graphics.PathMeasure in project AnimatedSvgView by jrummyapps.

the class AnimatedSvgView method rebuildGlyphData.

/**
   * If you set the SVG data paths more than once using {@link #setGlyphStrings(String...)} you should call this method
   * before playing the animation.
   */
@SuppressWarnings("SuspiciousNameCombination")
public void rebuildGlyphData() {
    float X = mWidth / mViewport.x;
    float Y = mHeight / mViewport.y;
    Matrix scaleMatrix = new Matrix();
    RectF outerRect = new RectF(X, X, Y, Y);
    scaleMatrix.setScale(X, Y, outerRect.centerX(), outerRect.centerY());
    mGlyphData = new GlyphData[mGlyphStrings.length];
    for (int i = 0; i < mGlyphStrings.length; i++) {
        mGlyphData[i] = new GlyphData();
        try {
            mGlyphData[i].path = ExposedPathParser.createPathFromPathData(mGlyphStrings[i]);
            mGlyphData[i].path.transform(scaleMatrix);
        } catch (Exception e) {
            mGlyphData[i].path = new Path();
            Log.e(TAG, "Couldn't parse path", e);
        }
        PathMeasure pm = new PathMeasure(mGlyphData[i].path, true);
        while (true) {
            mGlyphData[i].length = Math.max(mGlyphData[i].length, pm.getLength());
            if (!pm.nextContour()) {
                break;
            }
        }
        mGlyphData[i].paint = new Paint();
        mGlyphData[i].paint.setStyle(Paint.Style.STROKE);
        mGlyphData[i].paint.setAntiAlias(true);
        mGlyphData[i].paint.setColor(Color.WHITE);
        mGlyphData[i].paint.setStrokeWidth(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics()));
    }
}
Also used : RectF(android.graphics.RectF) Path(android.graphics.Path) Matrix(android.graphics.Matrix) PathMeasure(android.graphics.PathMeasure) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Aggregations

PathMeasure (android.graphics.PathMeasure)33 Path (android.graphics.Path)11 Paint (android.graphics.Paint)7 RectF (android.graphics.RectF)4 Point (android.graphics.Point)3 ParseException (java.text.ParseException)3 Animator (android.animation.Animator)1 AnimatorSet (android.animation.AnimatorSet)1 ObjectAnimator (android.animation.ObjectAnimator)1 PropertyValuesHolder (android.animation.PropertyValuesHolder)1 ValueAnimator (android.animation.ValueAnimator)1 SuppressLint (android.annotation.SuppressLint)1 TargetApi (android.annotation.TargetApi)1 Matrix (android.graphics.Matrix)1 PointF (android.graphics.PointF)1 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)1 ConstrainedSvgPathParser (com.github.jorgecastillo.svg.ConstrainedSvgPathParser)1 SvgPathParser (com.github.jorgecastillo.svg.SvgPathParser)1