Example usage for android.graphics PathMeasure PathMeasure

List of usage examples for android.graphics PathMeasure PathMeasure

Introduction

In this page you can find the example usage for android.graphics PathMeasure PathMeasure.

Prototype

public PathMeasure(Path path, boolean forceClosed) 

Source Link

Document

Create a PathMeasure object associated with the specified path object (already created and specified).

Usage

From source file:com.facebook.keyframes.util.KFPathInterpolator.java

public KFPathInterpolator(float controlX1, float controlY1, float controlX2, float controlY2) {
    Path path = new Path();
    path.moveTo(0, 0);/*w  ww . j  a  v a  2s.co m*/
    path.cubicTo(controlX1, controlY1, controlX2, controlY2, 1f, 1f);
    final PathMeasure pathMeasure = new PathMeasure(path, false /* forceClosed */);
    final float pathLength = pathMeasure.getLength();
    final int numPoints = (int) (pathLength / PRECISION) + 1;
    mX = new float[numPoints];
    mY = new float[numPoints];
    final float[] position = new float[2];
    for (int i = 0; i < numPoints; ++i) {
        final float distance = (i * pathLength) / (numPoints - 1);
        pathMeasure.getPosTan(distance, position, null /* tangent */);
        mX[i] = position[0];
        mY[i] = position[1];
    }
}

From source file:android.support.transition.PatternPathMotion.java

/**
 * 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.
 *//*from w  ww.j  av a2 s .c  om*/
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 = distance(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;
}

From source file:jp.co.recruit_lifestyle.android.widget.ColoringLoadingView.java

private void initPath() {
    mColoringPath = new Path();

    mLoadingPath = new Path();
    mCharacterPath = new Path();
    mPencilPath = new PencilPath();
    mPencilPath.setWidth(mViewWidth / 6);

    Path loadingPath = LoadingPath.getPath(mViewWidth);
    mLoadingPathMeasure = new PathMeasure(loadingPath, false);
    mBackgroundPath = new BackgroundPath();
    mBackgroundPath.setWidth(mViewWidth);
}

From source file:android.support.graphics.drawable.PathInterpolatorCompat.java

private void initPath(Path path) {
    final PathMeasure pathMeasure = new PathMeasure(path, false /* forceClosed */);

    final float pathLength = pathMeasure.getLength();
    final int numPoints = min(MAX_NUM_POINTS, (int) (pathLength / PRECISION) + 1);

    if (numPoints <= 0) {
        throw new IllegalArgumentException("The Path has a invalid length " + pathLength);
    }//from  w w w  .  j ava  2  s . co  m

    mX = new float[numPoints];
    mY = new float[numPoints];

    final float[] position = new float[2];
    for (int i = 0; i < numPoints; ++i) {
        final float distance = (i * pathLength) / (numPoints - 1);
        pathMeasure.getPosTan(distance, position, null /* tangent */);

        mX[i] = position[0];
        mY[i] = position[1];
    }

    if (abs(mX[0]) > EPSILON || abs(mY[0]) > EPSILON || abs(mX[numPoints - 1] - 1) > EPSILON
            || abs(mY[numPoints - 1] - 1) > EPSILON) {
        throw new IllegalArgumentException("The Path must start at (0,0) and end at (1,1)" + " start: " + mX[0]
                + "," + mY[0] + " end:" + mX[numPoints - 1] + "," + mY[numPoints - 1]);

    }

    float prevX = 0;
    int componentIndex = 0;
    for (int i = 0; i < numPoints; i++) {
        float x = mX[componentIndex++];
        if (x < prevX) {
            throw new IllegalArgumentException("The Path cannot loop back on itself, x :" + x);
        }
        mX[i] = x;
        prevX = x;
    }

    if (pathMeasure.nextContour()) {
        throw new IllegalArgumentException("The Path should be continuous," + " can't have 2+ contours");
    }
}

From source file:com.lauszus.dronedraw.DroneDrawActivity.java

private void uploadCsvFile() {
    if (!mDrawView.mFullPath.isEmpty()) {
        File csvFileLocation = new File(getFilesDir(), "path.csv");
        try {/*w  w  w.jav  a  2 s .  com*/
            CSVWriter writer = new CSVWriter(new FileWriter(csvFileLocation), ',',
                    CSVWriter.NO_QUOTE_CHARACTER);
            final int dataSize = 10 * mDrawView.touchCounter; // Sample path 10 times more than actual touches
            for (int i = 0; i <= dataSize; i++) {
                PathMeasure mPathMeasure = new PathMeasure(mDrawView.mFullPath, false);

                final float t = (float) i / (float) dataSize;
                float[] xy = new float[2];
                mPathMeasure.getPosTan(mPathMeasure.getLength() * t, xy, null);

                // Normalize coordinates based on maximum dimension
                final float maxDimension = Math.max(mDrawView.getWidth(), mDrawView.getHeight());
                final float x = xy[0] / maxDimension;
                final float y = (mDrawView.getHeight() - xy[1]) / maxDimension; // Make y-axis point upward

                writer.writeNext(new String[] { Integer.toString(i), Float.toString(x), Float.toString(y) });

                //if (D) Log.d(TAG, "t: " + t + " x: " + x + " y: " + y);
            }
            writer.close();
            //sendEmail(csvFileLocation);
            uploadFileToDropbox(csvFileLocation);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.ichi2.anki.Whiteboard.java

private void touchUp() {
    PathMeasure pm = new PathMeasure(mPath, false);
    mPath.lineTo(mX, mY);/*from w  ww . j  av a 2 s  . c  om*/
    if (pm.getLength() > 0) {
        mCanvas.drawPath(mPath, mPaint);
        mUndo.add(mPath);
    } else {
        mCanvas.drawPoint(mX, mY, mPaint);
        mUndo.add(mX, mY);
    }
    mUndoModeActive = true;
    // kill the path so we don't double draw
    mPath.reset();
    if (mUndo.size() == 1 && mActivity.get() != null) {
        mActivity.get().supportInvalidateOptionsMenu();
    }
}

From source file:com.daitu_liang.study.mytest.svg.AnimatedSvgView.java

private void rebuildGlyphData() {
    SvgPathParser parser = new SvgPathParser() {
        @Override// w w  w  . j  a v a  2  s.  c om
        protected float transformX(float x) {
            return x * mWidth / mViewport.x;
        }

        @Override
        protected float transformY(float y) {
            return y * mHeight / mViewport.y;
        }
    };

    Log.i(TAG, "---mWidth = " + mWidth + "---mViewport.x = " + mViewport.x);
    if (mGlyphStrings != null) {
        mGlyphData = new GlyphData[mGlyphStrings.length];
    }
    for (int i = 0; i < mGlyphStrings.length; i++) {
        mGlyphData[i] = new GlyphData();
        try {
            mGlyphData[i].path = parser.parsePath(mGlyphStrings[i]);
        } catch (ParseException 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()));
    }
}

From source file:cc.kenai.common.AnimatedSvgView.java

private void rebuildGlyphData() {
    SvgPathParser parser = new SvgPathParser() {
        @Override//from w ww. j  a v a2 s.  com
        protected float transformX(float x) {
            return x * mWidth / mViewport.x;
        }

        @Override
        protected float transformY(float y) {
            return y * mHeight / mViewport.y;
        }
    };

    Log.i(TAG, "---mWidth = " + mWidth + "---mViewport.x = " + mViewport.x);
    Log.i(TAG, "mGlyphStrings.length = " + mGlyphStrings.length);
    mGlyphData = new GlyphData[mGlyphStrings.length];
    for (int i = 0; i < mGlyphStrings.length; i++) {
        mGlyphData[i] = new GlyphData();
        try {
            mGlyphData[i].path = parser.parsePath(mGlyphStrings[i]);
        } catch (ParseException 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()));
    }
}

From source file:com.donsen.svg.ui.common.AnimatedSvgView.java

private void rebuildGlyphData() {
    SvgPathParser parser = new SvgPathParser() {
        @Override/*  ww  w. j a  v a2 s.c  om*/
        protected float transformX(float x) {
            return x * mWidth / mViewport.x;
        }

        @Override
        protected float transformY(float y) {
            return y * mHeight / mViewport.y;
        }
    };

    mGlyphData = new GlyphData[mGlyphStrings.length];
    for (int i = 0; i < mGlyphStrings.length; i++) {
        mGlyphData[i] = new GlyphData();
        try {
            mGlyphData[i].path = parser.parsePath(mGlyphStrings[i]);
        } catch (ParseException 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()));
    }
}

From source file:com.github.jorgecastillo.FillableLoader.java

private void buildPathData() {
    SvgPathParser parser = getPathParser();
    pathData = new PathData();
    try {//from   w  w  w.  j  a v  a  2  s  . co m
        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;
        }
    }
}