Example usage for android.graphics Path moveTo

List of usage examples for android.graphics Path moveTo

Introduction

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

Prototype

public void moveTo(float x, float y) 

Source Link

Document

Set the beginning of the next contour to the point (x,y).

Usage

From source file:com.bliex.android.lockpatternlib.PatternView.java

@Override
protected void onDraw(Canvas canvas) {

    final ArrayList<Cell> pattern = mPattern;
    final int count = pattern.size();
    final boolean[][] drawLookup = mPatternDrawLookup;

    if (mPatternDisplayMode == DisplayMode.Animate) {

        // figure out which circles to draw

        // + 1 so we pause on complete pattern
        final int oneCycle = (count + 1) * MILLIS_PER_CIRCLE_ANIMATING;
        final int spotInCycle = (int) (SystemClock.elapsedRealtime() - mAnimatingPeriodStart) % oneCycle;
        final int numCircles = spotInCycle / MILLIS_PER_CIRCLE_ANIMATING;

        clearPatternDrawLookup();//  w ww .  j a va 2 s.c  om
        for (int i = 0; i < numCircles; i++) {
            final Cell cell = pattern.get(i);
            drawLookup[cell.getRow()][cell.getColumn()] = true;
        }

        // figure out in progress portion of ghosting line

        final boolean needToUpdateInProgressPoint = numCircles > 0 && numCircles < count;

        if (needToUpdateInProgressPoint) {
            final float percentageOfNextCircle = ((float) (spotInCycle % MILLIS_PER_CIRCLE_ANIMATING))
                    / MILLIS_PER_CIRCLE_ANIMATING;

            final Cell currentCell = pattern.get(numCircles - 1);
            final float centerX = getCenterXForColumn(currentCell.column);
            final float centerY = getCenterYForRow(currentCell.row);

            final Cell nextCell = pattern.get(numCircles);
            final float dx = percentageOfNextCircle * (getCenterXForColumn(nextCell.column) - centerX);
            final float dy = percentageOfNextCircle * (getCenterYForRow(nextCell.row) - centerY);
            mInProgressX = centerX + dx;
            mInProgressY = centerY + dy;
        }
        // TODO: Infinite loop here...
        invalidate();
    }

    final Path currentPath = mCurrentPath;
    currentPath.rewind();

    // draw the circles
    for (int i = 0; i < 3; i++) {
        float centerY = getCenterYForRow(i);
        for (int j = 0; j < 3; j++) {
            CellState cellState = mCellStates[i][j];
            float centerX = getCenterXForColumn(j);
            float translationY = cellState.translationY;
            drawCircle(canvas, (int) centerX, (int) centerY + translationY, cellState.radius, drawLookup[i][j],
                    cellState.alpha);
        }
    }

    // TODO: the path should be created and cached every time we hit-detect a cell
    // only the last segment of the path should be computed here
    // draw the path of the pattern (unless we are in stealth mode)
    final boolean drawPath = !mInStealthMode;

    if (drawPath) {

        mPathPaint.setColor(getCurrentColor(true /* partOfPattern */));
        // Anyway other drawing sets their own alpha ignoring the original; And in this way we
        // can use ?colorControlNormal better.
        //            mPathPaint.setAlpha(100);

        boolean anyCircles = false;
        float lastX = 0f;
        float lastY = 0f;
        for (int i = 0; i < count; i++) {
            Cell cell = pattern.get(i);

            // only draw the part of the pattern stored in
            // the lookup table (this is only different in the case
            // of animation).
            if (!drawLookup[cell.row][cell.column]) {
                break;
            }
            anyCircles = true;

            float centerX = getCenterXForColumn(cell.column);
            float centerY = getCenterYForRow(cell.row);
            if (i != 0) {
                CellState state = mCellStates[cell.row][cell.column];
                currentPath.rewind();
                currentPath.moveTo(lastX, lastY);
                if (state.lineEndX != Float.MIN_VALUE && state.lineEndY != Float.MIN_VALUE) {
                    currentPath.lineTo(state.lineEndX, state.lineEndY);
                } else {
                    currentPath.lineTo(centerX, centerY);
                }
                canvas.drawPath(currentPath, mPathPaint);
            }
            lastX = centerX;
            lastY = centerY;
        }

        // draw last in progress section
        if ((mPatternInProgress || mPatternDisplayMode == DisplayMode.Animate) && anyCircles) {
            currentPath.rewind();
            currentPath.moveTo(lastX, lastY);
            currentPath.lineTo(mInProgressX, mInProgressY);

            //                mPathPaint.setAlpha((int) (calculateLastSegmentAlpha(
            //                        mInProgressX, mInProgressY, lastX, lastY) * 255f));
            canvas.drawPath(currentPath, mPathPaint);
        }
    }
}

From source file:com.android.nobug.view.pattern.PatternView.java

@Override
protected void onDraw(Canvas canvas) {

    final ArrayList<Cell> pattern = mPattern;
    final int count = pattern.size();
    final boolean[][] drawLookup = mPatternDrawLookup;

    if (mPatternDisplayMode == DisplayMode.Animate) {

        // figure out which circles to draw

        // + 1 so we pause on complete pattern
        final int oneCycle = (count + 1) * MILLIS_PER_CIRCLE_ANIMATING;
        final int spotInCycle = (int) (SystemClock.elapsedRealtime() - mAnimatingPeriodStart) % oneCycle;
        final int numCircles = spotInCycle / MILLIS_PER_CIRCLE_ANIMATING;

        clearPatternDrawLookup();/*from w w w .j  ava2 s  .  co m*/
        for (int i = 0; i < numCircles; i++) {
            final Cell cell = pattern.get(i);
            drawLookup[cell.getRow()][cell.getColumn()] = true;
        }

        // figure out in progress portion of ghosting line

        final boolean needToUpdateInProgressPoint = numCircles > 0 && numCircles < count;

        if (needToUpdateInProgressPoint) {
            final float percentageOfNextCircle = ((float) (spotInCycle % MILLIS_PER_CIRCLE_ANIMATING))
                    / MILLIS_PER_CIRCLE_ANIMATING;

            final Cell currentCell = pattern.get(numCircles - 1);
            final float centerX = getCenterXForColumn(currentCell.column);
            final float centerY = getCenterYForRow(currentCell.row);

            final Cell nextCell = pattern.get(numCircles);
            final float dx = percentageOfNextCircle * (getCenterXForColumn(nextCell.column) - centerX);
            final float dy = percentageOfNextCircle * (getCenterYForRow(nextCell.row) - centerY);
            mInProgressX = centerX + dx;
            mInProgressY = centerY + dy;
        }
        // TODO: Infinite loop here...
        invalidate();
    }

    final Path currentPath = mCurrentPath;
    currentPath.rewind();

    // draw the circles
    for (int i = 0; i < mRowCount; i++) {
        float centerY = getCenterYForRow(i);
        for (int j = 0; j < mColumnCount; j++) {
            CellState cellState = mCellStates[i][j];
            float centerX = getCenterXForColumn(j);
            float translationY = cellState.translationY;
            drawCircle(canvas, (int) centerX, (int) centerY + translationY, cellState.radius, drawLookup[i][j],
                    cellState.alpha);
        }
    }

    // TODO: the path should be created and cached every time we hit-detect a cell
    // only the last segment of the path should be computed here
    // draw the path of the pattern (unless we are in stealth mode)
    final boolean drawPath = !mInStealthMode;

    if (drawPath) {

        mPathPaint.setColor(getCurrentColor(true /* partOfPattern */));
        // Anyway other drawing sets their own alpha ignoring the original; And in this way we
        // can use ?colorControlNormal better.
        mPathPaint.setAlpha(255);

        boolean anyCircles = false;
        float lastX = 0f;
        float lastY = 0f;
        for (int i = 0; i < count; i++) {
            Cell cell = pattern.get(i);

            // only draw the part of the pattern stored in
            // the lookup table (this is only different in the case
            // of animation).
            if (!drawLookup[cell.row][cell.column]) {
                break;
            }
            anyCircles = true;

            float centerX = getCenterXForColumn(cell.column);
            float centerY = getCenterYForRow(cell.row);
            if (i != 0) {
                CellState state = mCellStates[cell.row][cell.column];
                currentPath.rewind();
                currentPath.moveTo(lastX, lastY);
                if (state.lineEndX != Float.MIN_VALUE && state.lineEndY != Float.MIN_VALUE) {
                    currentPath.lineTo(state.lineEndX, state.lineEndY);
                } else {
                    currentPath.lineTo(centerX, centerY);
                }
                canvas.drawPath(currentPath, mPathPaint);
            }
            lastX = centerX;
            lastY = centerY;
        }

        // draw last in progress section
        if ((mPatternInProgress || mPatternDisplayMode == DisplayMode.Animate) && anyCircles) {
            currentPath.rewind();
            currentPath.moveTo(lastX, lastY);
            currentPath.lineTo(mInProgressX, mInProgressY);

            mPathPaint.setAlpha(
                    (int) (calculateLastSegmentAlpha(mInProgressX, mInProgressY, lastX, lastY) * 255f));
            canvas.drawPath(currentPath, mPathPaint);
        }
    }
}

From source file:com.zwj.customview.gesturelock.PatternView.java

@Override
protected void onDraw(Canvas canvas) {
    final ArrayList<Cell> pattern = mPattern;
    final int count = pattern.size();
    final boolean[][] drawLookup = mPatternDrawLookup;

    if (mPatternDisplayMode == DisplayMode.Animate) {

        // figure out which circles to draw

        // + 1 so we pause on complete pattern
        final int oneCycle = (count + 1) * MILLIS_PER_CIRCLE_ANIMATING;
        final int spotInCycle = (int) (SystemClock.elapsedRealtime() - mAnimatingPeriodStart) % oneCycle;
        final int numCircles = spotInCycle / MILLIS_PER_CIRCLE_ANIMATING;

        clearPatternDrawLookup();//w  w w .  ja v  a2s  .  c o  m
        for (int i = 0; i < numCircles; i++) {
            final Cell cell = pattern.get(i);
            drawLookup[cell.getRow()][cell.getColumn()] = true;
        }

        // figure out in progress portion of ghosting line

        final boolean needToUpdateInProgressPoint = numCircles > 0 && numCircles < count;

        if (needToUpdateInProgressPoint) {
            final float percentageOfNextCircle = ((float) (spotInCycle % MILLIS_PER_CIRCLE_ANIMATING))
                    / MILLIS_PER_CIRCLE_ANIMATING;

            final Cell currentCell = pattern.get(numCircles - 1);
            final float centerX = getCenterXForColumn(currentCell.column);
            final float centerY = getCenterYForRow(currentCell.row);

            final Cell nextCell = pattern.get(numCircles);
            final float dx = percentageOfNextCircle * (getCenterXForColumn(nextCell.column) - centerX);
            final float dy = percentageOfNextCircle * (getCenterYForRow(nextCell.row) - centerY);
            mInProgressX = centerX + dx;
            mInProgressY = centerY + dy;
        }
        // TODO: Infinite loop here...
        invalidate();
    }

    final Path currentPath = mCurrentPath;
    currentPath.rewind();

    // draw the circles
    for (int i = 0; i < mRowCount; i++) {
        float centerY = getCenterYForRow(i);
        for (int j = 0; j < mColumnCount; j++) {
            CellState cellState = mCellStates[i][j];
            float centerX = getCenterXForColumn(j);
            float translationY = cellState.translationY;

            // TODO 
            drawCircle(canvas, (int) centerX, (int) centerY + translationY, cellState.radius, drawLookup[i][j],
                    cellState.alpha);
        }
    }

    // TODO: the path should be created and cached every time we hit-detect a cell
    // only the last segment of the path should be computed here
    // draw the path of the pattern (unless we are in stealth mode)
    final boolean drawPath = !mInStealthMode;

    if (drawPath) {

        mPathPaint.setColor(getCurrentColor(true /* partOfPattern */));
        // Anyway other drawing sets their own alpha ignoring the original; And in this way we
        // can use ?colorControlNormal better.
        mPathPaint.setAlpha(255);

        boolean anyCircles = false;
        float lastX = 0f;
        float lastY = 0f;
        for (int i = 0; i < count; i++) {
            Cell cell = pattern.get(i);

            // only draw the part of the pattern stored in
            // the lookup table (this is only different in the case
            // of animation).
            if (!drawLookup[cell.row][cell.column]) {
                break;
            }
            anyCircles = true;

            float centerX = getCenterXForColumn(cell.column);
            float centerY = getCenterYForRow(cell.row);
            if (i != 0) {
                CellState state = mCellStates[cell.row][cell.column];
                currentPath.rewind();
                currentPath.moveTo(lastX, lastY);
                if (state.lineEndX != Float.MIN_VALUE && state.lineEndY != Float.MIN_VALUE) {
                    currentPath.lineTo(state.lineEndX, state.lineEndY);
                } else {
                    currentPath.lineTo(centerX, centerY);
                }
                canvas.drawPath(currentPath, mPathPaint);
            }
            lastX = centerX;
            lastY = centerY;
        }

        // draw last in progress section
        if ((mPatternInProgress || mPatternDisplayMode == DisplayMode.Animate) && anyCircles) {
            currentPath.rewind();
            currentPath.moveTo(lastX, lastY);
            currentPath.lineTo(mInProgressX, mInProgressY);

            mPathPaint.setAlpha(
                    (int) (calculateLastSegmentAlpha(mInProgressX, mInProgressY, lastX, lastY) * 255f));
            canvas.drawPath(currentPath, mPathPaint);
        }
    }
}

From source file:com.skytree.epubtest.BookViewActivity.java

@SuppressLint({ "DrawAllocation", "DrawAllocation" })
@Override//  w w w.j  a v  a2s .c om
protected void onDraw(Canvas canvas) {
    Paint paint = new Paint();

    float sl, sr, st, sb;
    sl = 0;
    sr = this.getWidth();
    float ah = this.arrowHeight; // arrow Height;
    if (this.isArrowDown) {
        st = 0;
        sb = this.getHeight() - ah;
    } else {
        st = ah - 10;
        sb = this.getHeight() - 10;
    }

    Path boxPath = new Path();
    boxPath.addRoundRect(new RectF(sl, st, sr, sb), 20, 20, Path.Direction.CW);

    if (arrowPosition <= arrowHeight * 1.5f) {
        arrowPosition = arrowHeight * 1.5f;
    } else if (arrowPosition >= this.getWidth() - arrowHeight * 1.5f) {
        arrowPosition = this.getWidth() - arrowHeight * 1.5f;
    }

    Path arrowPath = new Path();
    if (isArrowDown) {
        arrowPath.moveTo(arrowPosition, sb + ah);
        arrowPath.lineTo((float) (arrowPosition - ah * 0.75), sb - 10);
        arrowPath.lineTo((float) (arrowPosition + ah * 0.75), sb - 10);
        arrowPath.close();
    } else {
        arrowPath.moveTo(arrowPosition, 0);
        arrowPath.lineTo((float) (arrowPosition - ah * 0.75), ah + 10);
        arrowPath.lineTo((float) (arrowPosition + ah * 0.75), ah + 10);
        arrowPath.close();
    }

    paint.setColor(this.strokeColor);
    paint.setStyle(Paint.Style.FILL);
    boxPath.addPath(arrowPath);
    canvas.drawPath(boxPath, paint);

    paint.setColor(this.boxColor);
    paint.setStyle(Paint.Style.FILL);
    boxPath.addPath(arrowPath);
    canvas.save();
    float sf = 0.995f;
    float ox = (this.getWidth() - (this.getWidth() * sf)) / 2.0f;
    float oy = ((this.getHeight() - arrowHeight) - ((this.getHeight() - arrowHeight) * sf)) / 2.0f;

    canvas.translate(ox, oy);
    canvas.scale(sf, sf);
    canvas.drawPath(boxPath, paint);
    canvas.restore();

    if (layoutChanged) {
        this.recalcLayout();
        layoutChanged = false;
    }
}

From source file:com.codename1.impl.android.AndroidImplementation.java

static Path cn1ShapeToAndroidPath(com.codename1.ui.geom.Shape shape, Path p) {
    //Path p = new Path();
    p.rewind();//w  w w  .  j  av  a 2 s  .co m
    com.codename1.ui.geom.PathIterator it = shape.getPathIterator();
    //p.setWindingRule(it.getWindingRule() == com.codename1.ui.geom.PathIterator.WIND_EVEN_ODD ? GeneralPath.WIND_EVEN_ODD : GeneralPath.WIND_NON_ZERO);
    float[] buf = new float[6];
    while (!it.isDone()) {
        int type = it.currentSegment(buf);
        switch (type) {
        case com.codename1.ui.geom.PathIterator.SEG_MOVETO:
            p.moveTo(buf[0], buf[1]);
            break;
        case com.codename1.ui.geom.PathIterator.SEG_LINETO:
            p.lineTo(buf[0], buf[1]);
            break;
        case com.codename1.ui.geom.PathIterator.SEG_QUADTO:
            p.quadTo(buf[0], buf[1], buf[2], buf[3]);
            break;
        case com.codename1.ui.geom.PathIterator.SEG_CUBICTO:
            p.cubicTo(buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
            break;
        case com.codename1.ui.geom.PathIterator.SEG_CLOSE:
            p.close();
            break;

        }
        it.next();
    }

    return p;
}