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:jp.co.recruit_lifestyle.android.widget.ColoringLoadingView.java

public void setCharacter(Character character) {
    if (!isPreDraw) {
        mCharacter = character;/*from w ww .  ja v  a 2  s. c  om*/
        return;
    }
    Path characterPath;
    switch (character) {
    case NINJA:
        characterPath = NinjaPath.getNinjaPath(mViewWidth / 1.5f, mCenterPoint);
        break;
    case BUTTERFLY:
        characterPath = ButterflyPath.getButterflyPath(mViewWidth / 1.5f, mCenterPoint);
        break;
    case AK:
        characterPath = AkPath.getAkPath(mViewWidth / 1.5f, mCenterPoint);
        break;
    case HAIR_STYLE:
        characterPath = HairStylePath.getHairStylePath(mViewWidth / 1.5f, mCenterPoint);
        break;
    case TOOTH:
        characterPath = ToothPath.getToothPath(mViewWidth / 1.5f, mCenterPoint);
        break;
    case STORM:
        characterPath = StormPath.getStormPath(mViewWidth / 1.5f, mCenterPoint);
        break;
    case DOGEZA:
        characterPath = DogezaPath.getDogezaPath(mViewWidth / 1.5f, mCenterPoint);
        break;
    case CAT:
        characterPath = CatPath.getCatPath(mViewWidth / 1.5f, mCenterPoint);
        break;
    case VIOLIN:
        characterPath = ViolinPath.getViolinPath(mViewWidth / 1.5f, mCenterPoint);
        break;
    case CUCUMBER:
        characterPath = CucumberPath.getCucumberPath(mViewWidth / 1.5f, mCenterPoint);
        break;
    case NINJA_STAR:
        characterPath = NinjaStarPath.getNinjaStarPath(mViewWidth / 1.5f, mCenterPoint);
        break;
    case SIM:
        characterPath = NinjaStarPath.getNinjaStarPath(mViewWidth / 1.5f, mCenterPoint);
        break;

    default:
        characterPath = NinjaPath.getNinjaPath(mViewWidth / 1.5f, mCenterPoint);
        break;
    }
    mCharacterPathMeasure = new PathMeasure(characterPath, false);
    mRectF.setEmpty();
    characterPath.computeBounds(mRectF, true);
    mRegion.setEmpty();
    mRegion.set((int) mRectF.left, (int) mRectF.top, (int) mRectF.right, (int) mRectF.bottom);
    mRegion.setPath(characterPath, mRegion);
}

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 ww.j a v a  2 s .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

public void setChannelData(int channel, WaveData waveData, TimeData timeData, TriggerData trigData) {
    // being updated by user
    if (mInMovement || mInScaling)
        return;/* w  ww.  ja  v  a2s . co  m*/

    switch (channel) {
    case 1: {
        mPrevChan1 = waveData;
        int retValue = updatePath(mPathChan1, waveData);
        if (retValue > 0)
            mChan1Text = updateVoltText(CHAN1_SCALE_TEXT, waveData.voltageScale);
        else if (retValue < 0)
            mChan1Text = "";
        break;
    }
    case 2: {
        mPrevChan2 = waveData;
        int retValue = updatePath(mPathChan2, waveData);
        if (retValue > 0)
            mChan2Text = updateVoltText(CHAN2_SCALE_TEXT, waveData.voltageScale);
        else if (retValue < 0)
            mChan2Text = "";
        break;
    }
    }

    if (mOnDataChanged != null && mChangeDelay <= 0) {
        mPrevTime = timeData;
        if (timeData != null) {
            mTimeScreenOffset = toScreenPosH(timeData.timeScale, timeData.timeOffset);
            mOnDataChanged.moveTime((float) mTimeScreenOffset, false);

            mTimeText = updateTimeText(TIME_SCALE_TEXT, timeData.timeScale);
            mTimeOffsetText = updateTimeText(TIME_OFFSET_TEXT, timeData.timeOffset);
        }

        mPrevTrig = trigData;
        if (trigData != null && waveData != null
                && ((trigData.source == TriggerData.TriggerSrc.CHAN1 && channel == 1)
                        || trigData.source == TriggerData.TriggerSrc.CHAN2 && channel == 2)) {
            mTriggerScreenOffset = (float) toScreenPosV(waveData.voltageScale,
                    waveData.voltageOffset + trigData.level);
            mOnDataChanged.moveTrigger((float) mTriggerScreenOffset, false);

            mTriggerText = updateTriggerText(trigData);
        }

        if (waveData != null && waveData.data != null) {
            double cursorPos = toScreenPosV(waveData.voltageScale, waveData.voltageOffset);
            if (channel == 1)
                mChan1ScreenOffset = cursorPos;
            else
                mChan2ScreenOffset = cursorPos;
            mOnDataChanged.moveWave(channel, (int) cursorPos, false);
        }

        if (mCursorUpdateNeeded) {
            mCursorUpdateNeeded = false;

            for (CursorView cursorView : mCursorArray.values()) {
                cursorView.update();
            }
        }
    }

    // Auto select channel (if only one on, it is selected)
    if (channelOnCount() > 1) {
        if (mSelectedPath == -1)
            mSelectedPath = 1;
    } else if (new PathMeasure(mPathChan1, false).getLength() > 0)
        mSelectedPath = 1;
    else if (new PathMeasure(mPathChan2, false).getLength() > 0)
        mSelectedPath = 2;

    postInvalidate();
}

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

private int updatePath(Path path, WaveData waveData) {
    int retValue = -1;
    if (waveData == null || waveData.data == null || waveData.data.length == 0) {
        path.rewind();/*from w  ww.j a va2  s .  co m*/
        return retValue;
    }

    retValue = 0;
    int length = Math.min(BaseScope.SAMPLE_LENGTH, waveData.data.length) - 10;
    float widthRatio = (float) (mContentWidth) / (length * DISPLAY_RATIO);
    double vScale = waveData.voltageScale;
    if (vScale == 0)
        vScale = 1.0f;

    Path newPath = new Path();
    double point = manipulatePoint(waveData.voltageOffset, vScale, waveData.data[10]);

    float j = -(length * (1 - DISPLAY_RATIO)) / 2;
    newPath.moveTo(j++ * widthRatio, (float) point);

    for (int i = 11; i < waveData.data.length; ++i, ++j) {
        point = manipulatePoint(waveData.voltageOffset, vScale, waveData.data[i]);
        newPath.lineTo(j * widthRatio, (float) point);
    }

    if (new PathMeasure(path, false).getLength() == 0) {
        path.set(newPath);
        return retValue;
    }

    if (mChangeDelay <= 0) {
        path.set(newPath);
        retValue = 1;
    } else {
        mChangeDelay--;
    }

    return retValue;
}

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

private static void setupPathMotion(Path path, ObjectAnimator oa, float precision, String propertyXName,
        String propertyYName) {/*from w  w  w. j  a  v a2 s.  co m*/
    // Measure the total length the whole path.
    final PathMeasure measureForTotalLength = new PathMeasure(path, false);
    float totalLength = 0;
    // The sum of the previous contour plus the current one. Using the sum here b/c we want to
    // directly substract from it later.
    ArrayList<Float> contourLengths = new ArrayList<>();
    contourLengths.add(0f);
    do {
        final float pathLength = measureForTotalLength.getLength();
        totalLength += pathLength;
        contourLengths.add(totalLength);

    } while (measureForTotalLength.nextContour());

    // Now determine how many sample points we need, and the step for next sample.
    final PathMeasure pathMeasure = new PathMeasure(path, false);

    final int numPoints = min(MAX_NUM_POINTS, (int) (totalLength / precision) + 1);

    float[] mX = new float[numPoints];
    float[] mY = new float[numPoints];
    final float[] position = new float[2];

    int contourIndex = 0;
    float step = totalLength / (numPoints - 1);
    float currentDistance = 0;

    // For each sample point, determine whether we need to move on to next contour.
    // After we find the right contour, then sample it using the current distance value minus
    // the previously sampled contours' total length.
    for (int i = 0; i < numPoints; ++i) {
        pathMeasure.getPosTan(currentDistance, position, null);
        pathMeasure.getPosTan(currentDistance, position, null);

        mX[i] = position[0];
        mY[i] = position[1];
        currentDistance += step;
        if ((contourIndex + 1) < contourLengths.size()
                && currentDistance > contourLengths.get(contourIndex + 1)) {
            currentDistance -= contourLengths.get(contourIndex + 1);
            contourIndex++;
            pathMeasure.nextContour();
        }
    }

    // Given the x and y value of the sample points, setup the ObjectAnimator properly.
    PropertyValuesHolder x = null;
    PropertyValuesHolder y = null;
    if (propertyXName != null) {
        x = PropertyValuesHolder.ofFloat(propertyXName, mX);
    }
    if (propertyYName != null) {
        y = PropertyValuesHolder.ofFloat(propertyYName, mY);
    }
    if (x == null) {
        oa.setValues(y);
    } else if (y == null) {
        oa.setValues(x);
    } else {
        oa.setValues(x, y);
    }
}

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

/**
 * ?// w w w . j  a v a  2s  .co 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());
}

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);//from w  w w  .  j  av  a2  s.c om
    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 ww  .ja  v a2 s. co  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. java2 s.c o  m*/
}