Example usage for android.graphics PathMeasure getLength

List of usage examples for android.graphics PathMeasure getLength

Introduction

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

Prototype

public float getLength() 

Source Link

Document

Return the total length of the current contour, or 0 if no path is associated with this measure object.

Usage

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

private void rebuildGlyphData() {
    SvgPathParser parser = new SvgPathParser() {
        @Override/*from  w  w w .  ja v a  2s.c  o m*/
        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.jrummyapps.android.widget.AnimatedSvgView.java

/**
 * If you set the SVG data paths more than once using {@link #setGlyphStrings(String...)} you should call this method
 * before playing the animation./*from w  w w . ja v  a2s.  c  o  m*/
 */
@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()));
    }
}

From source file:de.uni_weimar.mheinz.androidtouchscope.display.ScopeView.java

private int channelOnCount() {
    int count = 0;

    PathMeasure measure = new PathMeasure(mPathChan1, false);
    count += measure.getLength() > 0 ? 1 : 0;
    measure.setPath(mPathChan2, false);//  www  .j ava  2s.  co m
    count += measure.getLength() > 0 ? 1 : 0;

    return count;
}

From source file:de.uni_weimar.mheinz.androidtouchscope.display.ScopeView.java

private float smallestDistanceToPath(Path path, float x, float y) {
    PathMeasure measure = new PathMeasure(path, false);
    float pos[] = { 0f, 0f };
    float minDist = 1000f;
    float dist;/*from  w w  w . ja  v  a2  s .c o m*/

    for (int i = 0; i < measure.getLength(); ++i) {
        measure.getPosTan(i, pos, null);
        dist = (float) Math.hypot(x - pos[0], y - pos[1]);
        if (dist < minDist)
            minDist = dist;
    }
    return minDist;
}

From source file:com.waz.zclient.views.images.CircularSeekBar.java

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);
    }/*  ww  w .ja  va 2 s . com*/
}

From source file:com.github.shareme.gwsmaterialuikit.library.viewanimator.AnimationBuilder.java

/**
 * ?//  ww  w  .java 2 s  .  c o m
 *
 * @param path the path
 * @return the animation builder
 * @link http://blog.csdn.net/tianjian4592/article/details/47067161
 */
public AnimationBuilder path(Path path) {
    if (path == null) {
        return this;
    }
    final PathMeasure pathMeasure = new PathMeasure(path, false);
    return custom(new AnimationListener.Update() {
        @Override
        public void update(View view, float value) {
            float[] currentPosition = new float[2];// ???
            pathMeasure.getPosTan(value, currentPosition, null);
            final float x = currentPosition[0];
            final float y = currentPosition[1];
            ViewCompat.setX(view, x);
            ViewCompat.setY(view, y);
            Timber.d("path: value=" + value + ", x=" + x + ", y=" + y);
        }
    }, 0, pathMeasure.getLength());
}