Java Code Examples for android.graphics.Path#approximate()

The following examples show how to use android.graphics.Path#approximate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PathInterpolator.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void initPath(Path path) {
    float[] pointComponents = path.approximate(PRECISION);

    int numPoints = pointComponents.length / 3;
    if (pointComponents[1] != 0 || pointComponents[2] != 0
            || pointComponents[pointComponents.length - 2] != 1
            || pointComponents[pointComponents.length - 1] != 1) {
        throw new IllegalArgumentException("The Path must start at (0,0) and end at (1,1)");
    }

    mX = new float[numPoints];
    mY = new float[numPoints];
    float prevX = 0;
    float prevFraction = 0;
    int componentIndex = 0;
    for (int i = 0; i < numPoints; i++) {
        float fraction = pointComponents[componentIndex++];
        float x = pointComponents[componentIndex++];
        float y = pointComponents[componentIndex++];
        if (fraction == prevFraction && x != prevX) {
            throw new IllegalArgumentException(
                    "The Path cannot have discontinuity in the X axis.");
        }
        if (x < prevX) {
            throw new IllegalArgumentException("The Path cannot loop back on itself.");
        }
        mX[i] = x;
        mY[i] = y;
        prevX = x;
        prevFraction = fraction;
    }
}
 
Example 2
Source File: PathInterpolator.java    From Animer with Apache License 2.0 5 votes vote down vote up
private void initPath(Path path) {
    float[] pointComponents = path.approximate(PRECISION);

    int numPoints = pointComponents.length / 3;
    if (pointComponents[1] != 0 || pointComponents[2] != 0
            || pointComponents[pointComponents.length - 2] != 1
            || pointComponents[pointComponents.length - 1] != 1) {
        throw new IllegalArgumentException("The Path must start at (0,0) and end at (1,1)");
    }

    mX = new float[numPoints];
    mY = new float[numPoints];
    float prevX = 0;
    float prevFraction = 0;
    int componentIndex = 0;
    for (int i = 0; i < numPoints; i++) {
        float fraction = pointComponents[componentIndex++];
        float x = pointComponents[componentIndex++];
        float y = pointComponents[componentIndex++];
        if (fraction == prevFraction && x != prevX) {
            throw new IllegalArgumentException(
                    "The Path cannot have discontinuity in the X axis.");
        }
        if (x < prevX) {
            throw new IllegalArgumentException("The Path cannot loop back on itself.");
        }
        mX[i] = x;
        mY[i] = y;
        prevX = x;
        prevFraction = fraction;
    }
}
 
Example 3
Source File: CurveMotionDrawer.java    From FunnyDraw with Apache License 2.0 5 votes vote down vote up
private float[] approximate(Path path) {
    float[] points = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        points = path.approximate(PRECISION);
    } else {
        try {
            Method method = path.getClass().getDeclaredMethod("approximate", float.class);
            method.setAccessible(true);
            points = (float[]) method.invoke(path, PRECISION);
        } catch (NoSuchMethodException | InvocationTargetException| IllegalAccessException e) {
            // impossible
        }
    }
    return points;
}
 
Example 4
Source File: PathKeyframes.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public PathKeyframes(Path path, float error) {
    if (path == null || path.isEmpty()) {
        throw new IllegalArgumentException("The path must not be null or empty");
    }
    mKeyframeData = path.approximate(error);
}