Search in sources :

Example 36 with PathMeasure

use of android.graphics.PathMeasure in project Osmand by osmandapp.

the class RulerControlLayer method drawTextOnCenterOfPath.

private void drawTextOnCenterOfPath(Canvas canvas, float x1, float x2, Path path, String text) {
    PathMeasure pm = new PathMeasure(path, false);
    Rect bounds = new Rect();
    lineFontAttrs.paint.getTextBounds(text, 0, text.length(), bounds);
    float hOffset = pm.getLength() / 2 - bounds.width() / 2;
    if (x1 >= x2) {
        float[] pos = new float[2];
        pm.getPosTan(pm.getLength() / 2, pos, null);
        canvas.rotate(180, pos[0], pos[1]);
        canvas.drawTextOnPath(text, path, hOffset, bounds.height() + VERTICAL_OFFSET, lineFontAttrs.paint2);
        canvas.drawTextOnPath(text, path, hOffset, bounds.height() + VERTICAL_OFFSET, lineFontAttrs.paint);
        canvas.rotate(-180, pos[0], pos[1]);
    } else {
        canvas.drawTextOnPath(text, path, hOffset, -VERTICAL_OFFSET, lineFontAttrs.paint2);
        canvas.drawTextOnPath(text, path, hOffset, -VERTICAL_OFFSET, lineFontAttrs.paint);
    }
}
Also used : Rect(android.graphics.Rect) PathMeasure(android.graphics.PathMeasure)

Example 37 with PathMeasure

use of android.graphics.PathMeasure in project Bitocle by mthli.

the class FloatingActionMenu method calculateItemPositions.

/**
 * Calculates the desired positions of all items.
 */
private void calculateItemPositions() {
    // Create an arc that starts from startAngle and ends at endAngle
    // in an area that is as large as 4*radius^2
    Point center = getActionViewCenter();
    RectF area = new RectF(center.x - radius, center.y - radius, center.x + radius, center.y + radius);
    Path orbit = new Path();
    orbit.addArc(area, startAngle, endAngle - startAngle);
    PathMeasure measure = new PathMeasure(orbit, false);
    // Prevent overlapping when it is a full circle
    int divisor;
    if (Math.abs(endAngle - startAngle) >= 360 || subActionItems.size() <= 1) {
        divisor = subActionItems.size();
    } else {
        divisor = subActionItems.size() - 1;
    }
    // Measure this path, in order to find points that have the same distance between each other
    for (int i = 0; i < subActionItems.size(); i++) {
        float[] coords = new float[] { 0f, 0f };
        measure.getPosTan((i) * measure.getLength() / divisor, coords, null);
        // get the x and y values of these points and set them to each of sub action items.
        subActionItems.get(i).x = (int) coords[0] - subActionItems.get(i).width / 2;
        subActionItems.get(i).y = (int) coords[1] - subActionItems.get(i).height / 2;
    }
}
Also used : RectF(android.graphics.RectF) Path(android.graphics.Path) PathMeasure(android.graphics.PathMeasure) Point(android.graphics.Point) Point(android.graphics.Point)

Example 38 with PathMeasure

use of android.graphics.PathMeasure in project Depth-LIB-Android- by danielzeller.

the class PathBitmapMesh method matchVertsToPath.

public void matchVertsToPath(Path path, float bottomCoord, float extraOffset) {
    PathMeasure pm = new PathMeasure(path, false);
    for (int i = 0; i < staticVerts.length / 2; i++) {
        float yIndexValue = staticVerts[i * 2 + 1];
        float xIndexValue = staticVerts[i * 2];
        float percentOffsetX = (0.000001f + xIndexValue) / bitmap.getWidth();
        float percentOffsetX2 = (0.000001f + xIndexValue) / (bitmap.getWidth() + extraOffset);
        percentOffsetX2 += pathOffsetPercent;
        pm.getPosTan(pm.getLength() * (1f - percentOffsetX), coords, null);
        pm.getPosTan(pm.getLength() * (1f - percentOffsetX2), coords2, null);
        if (yIndexValue == 0) {
            setXY(drawingVerts, i, coords[0], coords2[1]);
        } else {
            setXY(drawingVerts, i, coords[0], bottomCoord);
        }
    }
}
Also used : PathMeasure(android.graphics.PathMeasure) Paint(android.graphics.Paint)

Example 39 with PathMeasure

use of android.graphics.PathMeasure in project Depth-LIB-Android- by danielzeller.

the class RenderableTree method matchVertsToPath.

private void matchVertsToPath() {
    PathMeasure pmLeft = new PathMeasure(pathLeft, false);
    PathMeasure pmRight = new PathMeasure(pathRight, false);
    float[] coords = new float[2];
    for (int i = 0; i < staticVerts.length / 2; i++) {
        float yIndexValue = staticVerts[i * 2 + 1];
        float xIndexValue = staticVerts[i * 2];
        if (xIndexValue == 0) {
            float percentOffsetY = (0.000001f + yIndexValue) / bitmap.getHeight();
            pmLeft.getPosTan(pmLeft.getLength() * (1f - percentOffsetY), coords, null);
            setXY(drawingVerts, i, coords[0], coords[1]);
        } else {
            float percentOffsetY = (0.000001f + yIndexValue) / bitmap.getHeight();
            pmRight.getPosTan(pmRight.getLength() * (1f - percentOffsetY), coords, null);
            setXY(drawingVerts, i, coords[0], coords[1]);
        }
    }
}
Also used : PathMeasure(android.graphics.PathMeasure) Paint(android.graphics.Paint)

Example 40 with PathMeasure

use of android.graphics.PathMeasure in project Timber by naman14.

the class CircularSeekBar method calculatePointerXYPosition.

private void calculatePointerXYPosition() {
    PathMeasure pm = new PathMeasure(mCircleProgressPath, false);
    boolean returnValue = pm.getPosTan(pm.getLength(), mPointerPositionXY, null);
    if (!returnValue) {
        pm = new PathMeasure(mCirclePath, false);
        returnValue = pm.getPosTan(0, mPointerPositionXY, null);
    }
}
Also used : PathMeasure(android.graphics.PathMeasure)

Aggregations

PathMeasure (android.graphics.PathMeasure)48 Path (android.graphics.Path)18 Paint (android.graphics.Paint)11 RectF (android.graphics.RectF)5 Point (android.graphics.Point)3 ParseException (java.text.ParseException)3 Animator (android.animation.Animator)2 AnimatorSet (android.animation.AnimatorSet)2 ObjectAnimator (android.animation.ObjectAnimator)2 PropertyValuesHolder (android.animation.PropertyValuesHolder)2 ValueAnimator (android.animation.ValueAnimator)2 SuppressLint (android.annotation.SuppressLint)2 TargetApi (android.annotation.TargetApi)2 Matrix (android.graphics.Matrix)2 PointF (android.graphics.PointF)2 Rect (android.graphics.Rect)2 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)2 DashPathEffect (android.graphics.DashPathEffect)1 PathEffect (android.graphics.PathEffect)1 Nullable (android.support.annotation.Nullable)1