Search in sources :

Example 26 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)

Example 27 with PathMeasure

use of android.graphics.PathMeasure in project MaterialCalendar by Haoxiqiang.

the class WeatherTemplateView method getPoints.

protected PathPoints[] getPoints(Path path, int size) {
    //Size of 100 indicates that, 100 points
    // would be extracted from the path
    PathPoints[] pointArray = new PathPoints[size];
    PathMeasure pm = new PathMeasure(path, false);
    float length = pm.getLength();
    float distance = 0f;
    float speed = length / size;
    int counter = 0;
    float[] aCoordinates = new float[2];
    while ((distance < length) && (counter < size)) {
        pm.getPosTan(distance, aCoordinates, null);
        pointArray[counter] = new PathPoints(aCoordinates[0], aCoordinates[1]);
        counter++;
        distance = distance + speed;
    }
    return pointArray;
}
Also used : PathMeasure(android.graphics.PathMeasure) Paint(android.graphics.Paint)

Example 28 with PathMeasure

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

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 29 with PathMeasure

use of android.graphics.PathMeasure in project wire-android by wireapp.

the class CircularSeekBar method calculatePointerXYPosition.

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

Example 30 with PathMeasure

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

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)

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