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:de.hs_bremen.aurora_hunter.ui.views.KpIndexChartView.java

public void onDraw(Canvas canvas) {

    if (points.size() == 0) {
        return;/*  www  . ja v  a 2 s  . c  om*/
    }
    Path path = new Path();
    int height = canvas.getHeight();
    int width = canvas.getWidth();

    for (Point point : points) {
        point.x = point.percentageX * width + 60;
        // Log.i("scaleFactor", " : " + scaleFactor);
        //Log.i("percent", " : " + percent);

        point.y = (float) ((1 - point.percentageY * scaleFactor) * height * 0.7 + 30);
    }

    if (points.size() > 1) {
        //calcuate x/y based on size of canvas
        for (int i = 0; i < points.size(); i++) {
            if (i >= 0) {
                Point point = points.get(i);
                //  Log.i("dx",point.x + " - " + point.y );
                if (i == 0) {
                    Point next = points.get(i + 1);
                    point.dx = ((next.x - point.x) / 5);
                    point.dy = ((next.y - point.y) / 5);
                } else if (i == points.size() - 1) {
                    Point prev = points.get(i - 1);
                    point.dx = ((point.x - prev.x) / 5);
                    point.dy = ((point.y - prev.y) / 5);
                } else {
                    Point next = points.get(i + 1);
                    Point prev = points.get(i - 1);
                    point.dx = ((next.x - prev.x) / 5);
                    point.dy = ((next.y - prev.y) / 5);
                }
            }
        }
    }

    if (points.size() > 0) {
        path.moveTo(0, (float) (canvas.getHeight() * 0.8));
        path.lineTo(0, points.get(0).y);

    }
    boolean first = true;

    for (int i = 0; i < points.size(); i++) {
        Point point = points.get(i);
        if (first) {
            first = false;
            path.cubicTo(point.x - point.x * 2, point.y - point.y / 5, point.x - point.dx, point.y - point.dy,
                    point.x, point.y);
        } else {
            Point prev = points.get(i - 1);
            //  Log.i("Draw", point.dx  + " " + point.dy);
            path.cubicTo(prev.x + prev.dx, prev.y + prev.dy, point.x - point.dx, point.y - point.dy, point.x,
                    point.y);
        }
    }
    path.lineTo(width, (float) (height * 0.8));

    path.lineTo(width, (float) (height * 0.9));
    path.lineTo(0, (float) (height * 0.9));

    canvas.drawPath(path, mGraphPaint);
    canvas.drawRect(0, (float) (height * 0.9), width, height, mGraphPaint);

    double Kp1Height = (1 - 0.6666666) * height;//points.get(points.size()-1).y;
    canvas.drawRect(0, (float) Kp1Height, width, (float) Kp1Height + 1, paintG1Line);
    canvas.drawText("G1", 2, (float) Kp1Height, paintTxt);
    int detlaY = 15;

    for (Point p : points) {
        int val = (int) Math.round(9 * p.percentageY);
        //if last element
        if (points.indexOf(p) == points.size() - 1) {
            //Log.i("last", p.toString());
            //   canvas.drawText(val + "", p.x-150,p.y - detlaY, paintTxt);
        } else {
            canvas.drawText(val + "", p.x - 10, p.y - detlaY, paintTxt);
        }
        //Log.i("point", p.toString());
    }
    // Log.i("Lenght", points.size() + " ");

}

From source file:org.akop.crosswords.view.CrosswordView.java

private void renderCell(Canvas canvas, Cell cell, RectF cellRect, Paint fillPaint) {
    canvas.drawRect(cellRect, fillPaint);
    canvas.drawRect(cellRect, mCellStrokePaint);

    if (cell.mCircled) {
        canvas.drawCircle(cellRect.centerX(), cellRect.centerY(), mCircleRadius, mCircleStrokePaint);
    }/*from w w w  .  j a  v a 2  s  .  c o m*/

    if (cell.mNumber != null) {
        mNumberTextPaint.getTextBounds(cell.mNumber, 0, cell.mNumber.length(), mTempRect);

        float numberX = cellRect.left + mNumberTextPadding + (mTempRect.width() / 2);
        float numberY = cellRect.top + mNumberTextPadding + mTempRect.height();

        if (cell.mCircled) {
            canvas.drawText(cell.mNumber, numberX, numberY, mNumberStrokePaint);
        }

        canvas.drawText(cell.mNumber, numberX, numberY, mNumberTextPaint);
    }

    if (cell.mCheated) {
        Path path = new Path();
        path.moveTo(cellRect.right, cellRect.bottom);
        path.lineTo(cellRect.right - mMarkerSideLength, cellRect.bottom);
        path.lineTo(cellRect.right, cellRect.bottom - mMarkerSideLength);
        path.close();

        canvas.drawPath(path, mCheatedCellFillPaint);
        canvas.drawPath(path, mCellStrokePaint);
    }

    if (cell.mError) {
        Path path = new Path();
        path.moveTo(cellRect.left, cellRect.bottom);
        path.lineTo(cellRect.left + mMarkerSideLength, cellRect.bottom);
        path.lineTo(cellRect.left, cellRect.bottom - mMarkerSideLength);
        path.close();

        canvas.drawPath(path, mMistakeCellFillPaint);
        canvas.drawPath(path, mCellStrokePaint);
    }

    if (!cell.isEmpty()) {
        mAnswerTextPaint.getTextBounds(cell.mCharStr, 0, cell.mCharStr.length(), mTempRect);
        canvas.drawText(cell.mCharStr, cellRect.left + mCellSize / 2,
                cellRect.top + mCellSize - mAnswerTextPadding, mAnswerTextPaint);
    }
}

From source file:de.hs_bremen.aurora_hunter.ui.views.PredictionGraphView.java

public void onDraw(Canvas canvas) {
    if (mPoints.size() == 0) {
        return;/*from ww w  . jav a 2s  .co  m*/
    }
    int yOffsetForLabels = 0;

    if (mMax * mScaleFactor > 0.8) {
        yOffsetForLabels = 15;
    }
    Path path = new Path();
    int height = canvas.getHeight();
    int width = canvas.getWidth();

    for (Point point : mPoints) {
        point.x = point.percentageX * width + 60;
        // Log.i("mScaleFactor", " : " + mScaleFactor);
        //Log.i("percent", " : " + percent);

        point.y = (float) ((1 - point.percentageY * mScaleFactor) * height) + yOffsetForLabels * 3;
    }

    if (mPoints.size() > 1) {
        //calcuate x/y based on size of canvas
        for (int i = 0; i < mPoints.size(); i++) {
            if (i >= 0) {
                Point point = mPoints.get(i);
                //  Log.i("dx",point.x + " - " + point.y );
                if (i == 0) {
                    Point next = mPoints.get(i + 1);
                    point.dx = ((next.x - point.x) / 5);
                    point.dy = ((next.y - point.y) / 5);
                } else if (i == mPoints.size() - 1) {
                    Point prev = mPoints.get(i - 1);
                    point.dx = ((point.x - prev.x) / 5);
                    point.dy = ((point.y - prev.y) / 5);
                } else {
                    Point next = mPoints.get(i + 1);
                    Point prev = mPoints.get(i - 1);
                    point.dx = ((next.x - prev.x) / 5);
                    point.dy = ((next.y - prev.y) / 5);
                }
            }
        }
    }

    if (mPoints.size() > 0) {
        path.moveTo(0, (float) (canvas.getHeight() * 0.8));
        path.lineTo(0, mPoints.get(0).y);

    }
    boolean first = true;

    for (int i = 0; i < mPoints.size(); i++) {
        Point point = mPoints.get(i);
        if (first) {
            first = false;
            path.cubicTo(point.x - point.x * 2, point.y - point.y / 5, point.x - point.dx, point.y - point.dy,
                    point.x, point.y);
        } else {
            Point prev = mPoints.get(i - 1);
            //  Log.i("Draw", point.dx  + " " + point.dy);
            path.cubicTo(prev.x + prev.dx, prev.y + prev.dy, point.x - point.dx, point.y - point.dy, point.x,
                    point.y);
        }
    }

    if (mPoints.size() > 0) {
        path.lineTo(width, mPoints.get(mPoints.size() - 1).y);
    }
    path.lineTo(width, height);
    path.lineTo(0, height);

    canvas.drawPath(path, mGraphPaint);

    int detlaY = 30;

    for (Point p : mPoints) {

        int val = (int) Math.round(p.percentageY * 100);
        //if last element

        if (mPoints.indexOf(p) == mPoints.size() - 1) {
            //Log.i("last", p.toString());
            if (val == 0 || p.y > getHeight()) {
                canvas.drawText(val + "%", p.x - 150, getHeight() - detlaY, mTextPaint);
            } else {
                canvas.drawText(val + "%", p.x - 150, p.y - detlaY + yOffsetForLabels, mTextPaint);
            }

        } else {
            if (val == 0 || p.y > getHeight()) {
                canvas.drawText(val + "%", p.x - 20, getHeight() - detlaY, mTextPaint);
            } else {
                canvas.drawText(val + "%", p.x - 20, p.y - detlaY + yOffsetForLabels, mTextPaint);
            }

        }
        //Log.i("point", p.toString());
    }
    // Log.i("Lenght", mPoints.size() + " ");

    float levelStart = (float) (canvas.getHeight() - (mNotificationLevel * canvas.getHeight()));
    float lineHeight = DpToPixelUtil.convertDpToPixel(2, getContext());

    if (mViewMode == PredictionFragment.NOTIFICATION_MODE.SET_NOTIFICATION_LEVEL) {
        mNotificationLevelPaint.setAlpha(150);
        float leftOffset = 0;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

            float arcHeight = DpToPixelUtil.convertDpToPixel(30, getContext());
            leftOffset = arcHeight;
            RectF rectF = new RectF(getWidth() - arcHeight, levelStart - arcHeight / 2, getWidth(),
                    levelStart + arcHeight / 2);
            canvas.drawArc(rectF, 0, 360, true, mNotificationLevelPaint);

        }
        canvas.drawRect(0, levelStart, canvas.getWidth() - leftOffset, levelStart + lineHeight,
                mNotificationLevelPaint);

        mNotificationLevelPaint.setAlpha(20);
        canvas.drawRect(0, levelStart + lineHeight, canvas.getWidth(), canvas.getHeight(),
                mNotificationLevelPaint);
        String text = Math.round(mNotificationLevel * 100) + "%";
        canvas.drawText(text, DpToPixelUtil.convertDpToPixel(10, getContext()),
                levelStart + DpToPixelUtil.convertDpToPixel(25, getContext()), mNotificationLevelTextPaint);
    } else {
        mNotificationLevelPaint.setAlpha(30);
        canvas.drawRect(0, levelStart, canvas.getWidth(), levelStart + lineHeight, mNotificationLevelPaint);
    }

}

From source file:net.droidsolutions.droidcharts.core.renderer.category.LineAndShapeRenderer.java

private Path convertAwtPathToAndroid(PathIterator pi) {
    Path path = new Path();
    float[] coords = new float[6];
    while (!pi.isDone()) {
        int windingRule = pi.getWindingRule();

        if (windingRule == PathIterator.WIND_EVEN_ODD) {
            path.setFillType(Path.FillType.EVEN_ODD);
        } else {/* w ww .  ja va  2  s.c om*/
            path.setFillType(Path.FillType.INVERSE_EVEN_ODD);
        }

        int pathType = pi.currentSegment(coords);

        switch (pathType) {
        case PathIterator.SEG_CLOSE:
            path.close();
            break;
        case PathIterator.SEG_CUBICTO:
            path.cubicTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
            break;
        case PathIterator.SEG_LINETO:
            path.lineTo(coords[0], coords[1]);
            break;
        case PathIterator.SEG_MOVETO:
            path.moveTo(coords[0], coords[1]);
            break;
        case PathIterator.SEG_QUADTO:
            path.quadTo(coords[0], coords[1], coords[2], coords[3]);
            break;
        }

        pi.next();
    }
    return path;
}

From source file:com.larvalabs.svgandroid.SVGParser.java

/**
 * This is where the hard-to-parse paths are handled.
 * Uppercase rules are absolute positions, lowercase are relative.
 * Types of path rules://  ww  w. j  a  v a  2 s .  co  m
 * <p/>
 * <ol>
 * <li>M/m - (x y)+ - Move to (without drawing)
 * <li>Z/z - (no params) - Close path (back to starting point)
 * <li>L/l - (x y)+ - Line to
 * <li>H/h - x+ - Horizontal ine to
 * <li>V/v - y+ - Vertical line to
 * <li>C/c - (x1 y1 x2 y2 x y)+ - Cubic bezier to
 * <li>S/s - (x2 y2 x y)+ - Smooth cubic bezier to (shorthand that assumes the x2, y2 from previous C/S is the x1, y1 of this bezier)
 * <li>Q/q - (x1 y1 x y)+ - Quadratic bezier to
 * <li>T/t - (x y)+ - Smooth quadratic bezier to (assumes previous control point is "reflection" of last one w.r.t. to current point)
 * </ol>
 * <p/>
 * Numbers are separate by whitespace, comma or nothing at all (!) if they are self-delimiting, (ie. begin with a - sign)
 *
 * @param s the path string from the XML
 */
private static Path doPath(String s) {
    int n = s.length();
    ParserHelper ph = new ParserHelper(s, 0);
    ph.skipWhitespace();
    Path p = new Path();
    float lastX = 0;
    float lastY = 0;
    float lastX1 = 0;
    float lastY1 = 0;
    RectF r = new RectF();
    char cmd = 'x';
    while (ph.pos < n) {
        char next = s.charAt(ph.pos);
        if (!Character.isDigit(next) && !(next == '.') && !(next == '-')) {
            cmd = next;
            ph.advance();
        } else if (cmd == 'M') { // implied command
            cmd = 'L';
        } else if (cmd == 'm') { // implied command
            cmd = 'l';
        } else { // implied command
            // Log.d(TAG, "Implied command: " + cmd);
        }
        p.computeBounds(r, true);
        // Log.d(TAG, "  " + cmd + " " + r);
        // Util.debug("* Commands remaining: '" + path + "'.");
        boolean wasCurve = false;
        switch (cmd) {
        case 'M':
        case 'm': {
            float x = ph.nextFloat();
            float y = ph.nextFloat();
            if (cmd == 'm') {
                p.rMoveTo(x, y);
                lastX += x;
                lastY += y;
            } else {
                p.moveTo(x, y);
                lastX = x;
                lastY = y;
            }
            break;
        }
        case 'Z':
        case 'z': {
            p.close();
            break;
        }
        case 'L':
        case 'l': {
            float x = ph.nextFloat();
            float y = ph.nextFloat();
            if (cmd == 'l') {
                p.rLineTo(x, y);
                lastX += x;
                lastY += y;
            } else {
                p.lineTo(x, y);
                lastX = x;
                lastY = y;
            }
            break;
        }
        case 'H':
        case 'h': {
            float x = ph.nextFloat();
            if (cmd == 'h') {
                p.rLineTo(x, 0);
                lastX += x;
            } else {
                p.lineTo(x, lastY);
                lastX = x;
            }
            break;
        }
        case 'V':
        case 'v': {
            float y = ph.nextFloat();
            if (cmd == 'v') {
                p.rLineTo(0, y);
                lastY += y;
            } else {
                p.lineTo(lastX, y);
                lastY = y;
            }
            break;
        }
        case 'C':
        case 'c': {
            wasCurve = true;
            float x1 = ph.nextFloat();
            float y1 = ph.nextFloat();
            float x2 = ph.nextFloat();
            float y2 = ph.nextFloat();
            float x = ph.nextFloat();
            float y = ph.nextFloat();
            if (cmd == 'c') {
                x1 += lastX;
                x2 += lastX;
                x += lastX;
                y1 += lastY;
                y2 += lastY;
                y += lastY;
            }
            p.cubicTo(x1, y1, x2, y2, x, y);
            lastX1 = x2;
            lastY1 = y2;
            lastX = x;
            lastY = y;
            break;
        }
        case 'S':
        case 's': {
            wasCurve = true;
            float x2 = ph.nextFloat();
            float y2 = ph.nextFloat();
            float x = ph.nextFloat();
            float y = ph.nextFloat();
            if (cmd == 's') {
                x2 += lastX;
                x += lastX;
                y2 += lastY;
                y += lastY;
            }
            float x1 = 2 * lastX - lastX1;
            float y1 = 2 * lastY - lastY1;
            p.cubicTo(x1, y1, x2, y2, x, y);
            lastX1 = x2;
            lastY1 = y2;
            lastX = x;
            lastY = y;
            break;
        }
        case 'A':
        case 'a': {
            float rx = ph.nextFloat();
            float ry = ph.nextFloat();
            float theta = ph.nextFloat();
            int largeArc = (int) ph.nextFloat();
            int sweepArc = (int) ph.nextFloat();
            float x = ph.nextFloat();
            float y = ph.nextFloat();
            if (cmd == 'a') {
                x += lastX;
                y += lastY;
            }
            drawArc(p, lastX, lastY, x, y, rx, ry, theta, largeArc == 1, sweepArc == 1);
            lastX = x;
            lastY = y;
            break;
        }
        default:
            Log.d(TAG, "Invalid path command: " + cmd);
            ph.advance();
        }
        if (!wasCurve) {
            lastX1 = lastX;
            lastY1 = lastY;
        }
        ph.skipWhitespace();
    }
    return p;
}

From source file:com.jiahuan.svgmapview.core.helper.map.SVGParser.java

/**
 * This is where the hard-to-parse paths are handled. Uppercase rules are
 * absolute positions, lowercase are relative. Types of path rules:
 * <p/>//ww  w. ja  va2s .c o m
 * <ol>
 * <li>M/m - (x y)+ - Move to (without drawing)
 * <li>Z/z - (no params) - Close path (back to starting point)
 * <li>L/l - (x y)+ - Line to
 * <li>H/h - x+ - Horizontal ine to
 * <li>V/v - y+ - Vertical line to
 * <li>C/c - (x1 y1 x2 y2 x y)+ - Cubic bezier to
 * <li>S/s - (x2 y2 x y)+ - Smooth cubic bezier to (shorthand that assumes
 * the x2, y2 from previous C/S is the x1, y1 of this bezier)
 * <li>Q/q - (x1 y1 x y)+ - Quadratic bezier to
 * <li>T/t - (x y)+ - Smooth quadratic bezier to (assumes previous control
 * point is "reflection" of last one w.r.t. to current point)
 * </ol>
 * <p/>
 * Numbers are separate by whitespace, comma or nothing at all (!) if they
 * are self-delimiting, (ie. begin with a - sign)
 * 
 * @param s
 *            the path string from the XML
 */
private static Path doPath(String s) {
    int n = s.length();
    ParserHelper ph = new ParserHelper(s, 0);
    ph.skipWhitespace();
    Path p = new Path();
    float lastX = 0;
    float lastY = 0;
    float lastX1 = 0;
    float lastY1 = 0;
    float subPathStartX = 0;
    float subPathStartY = 0;
    char prevCmd = 0;
    while (ph.pos < n) {
        char cmd = s.charAt(ph.pos);
        switch (cmd) {
        case '-':
        case '+':
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
            if (prevCmd == 'm' || prevCmd == 'M') {
                cmd = (char) ((prevCmd) - 1);
                break;
            } else if (("lhvcsqta").indexOf(Character.toLowerCase(prevCmd)) >= 0) {
                cmd = prevCmd;
                break;
            }
        default: {
            ph.advance();
            prevCmd = cmd;
        }
        }

        boolean wasCurve = false;
        switch (cmd) {
        case 'M':
        case 'm': {
            float x = ph.nextFloat();
            float y = ph.nextFloat();
            if (cmd == 'm') {
                subPathStartX += x;
                subPathStartY += y;
                p.rMoveTo(x, y);
                lastX += x;
                lastY += y;
            } else {
                subPathStartX = x;
                subPathStartY = y;
                p.moveTo(x, y);
                lastX = x;
                lastY = y;
            }
            break;
        }
        case 'Z':
        case 'z': {
            p.close();
            p.moveTo(subPathStartX, subPathStartY);
            lastX = subPathStartX;
            lastY = subPathStartY;
            lastX1 = subPathStartX;
            lastY1 = subPathStartY;
            wasCurve = true;
            break;
        }
        case 'T':
        case 't':
            // todo - smooth quadratic Bezier (two parameters)
        case 'L':
        case 'l': {
            float x = ph.nextFloat();
            float y = ph.nextFloat();
            if (cmd == 'l') {
                p.rLineTo(x, y);
                lastX += x;
                lastY += y;
            } else {
                p.lineTo(x, y);
                lastX = x;
                lastY = y;
            }
            break;
        }
        case 'H':
        case 'h': {
            float x = ph.nextFloat();
            if (cmd == 'h') {
                p.rLineTo(x, 0);
                lastX += x;
            } else {
                p.lineTo(x, lastY);
                lastX = x;
            }
            break;
        }
        case 'V':
        case 'v': {
            float y = ph.nextFloat();
            if (cmd == 'v') {
                p.rLineTo(0, y);
                lastY += y;
            } else {
                p.lineTo(lastX, y);
                lastY = y;
            }
            break;
        }
        case 'C':
        case 'c': {
            wasCurve = true;
            float x1 = ph.nextFloat();
            float y1 = ph.nextFloat();
            float x2 = ph.nextFloat();
            float y2 = ph.nextFloat();
            float x = ph.nextFloat();
            float y = ph.nextFloat();
            if (cmd == 'c') {
                x1 += lastX;
                x2 += lastX;
                x += lastX;
                y1 += lastY;
                y2 += lastY;
                y += lastY;
            }
            p.cubicTo(x1, y1, x2, y2, x, y);
            lastX1 = x2;
            lastY1 = y2;
            lastX = x;
            lastY = y;
            break;
        }
        case 'Q':
        case 'q':
            // todo - quadratic Bezier (four parameters)
        case 'S':
        case 's': {
            wasCurve = true;
            float x2 = ph.nextFloat();
            float y2 = ph.nextFloat();
            float x = ph.nextFloat();
            float y = ph.nextFloat();
            if (Character.isLowerCase(cmd)) {
                x2 += lastX;
                x += lastX;
                y2 += lastY;
                y += lastY;
            }
            float x1 = 2 * lastX - lastX1;
            float y1 = 2 * lastY - lastY1;
            p.cubicTo(x1, y1, x2, y2, x, y);
            lastX1 = x2;
            lastY1 = y2;
            lastX = x;
            lastY = y;
            break;
        }
        case 'A':
        case 'a': {
            float rx = ph.nextFloat();
            float ry = ph.nextFloat();
            float theta = ph.nextFloat();
            int largeArc = ph.nextFlag();
            int sweepArc = ph.nextFlag();
            float x = ph.nextFloat();
            float y = ph.nextFloat();
            if (cmd == 'a') {
                x += lastX;
                y += lastY;
            }
            drawArc(p, lastX, lastY, x, y, rx, ry, theta, largeArc, sweepArc);
            lastX = x;
            lastY = y;
            break;
        }
        default:
            Log.w(TAG, "Invalid path command: " + cmd);
            ph.advance();
        }
        if (!wasCurve) {
            lastX1 = lastX;
            lastY1 = lastY;
        }
        ph.skipWhitespace();
    }
    return p;
}

From source file:com.hippo.widget.lockpattern.LockPatternView.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 .  jav  a  2 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 < 3; i++) {
        float centerY = getCenterYForRow(i);
        for (int j = 0; j < 3; j++) {
            CellState cellState = mCellStates[i][j];
            float centerX = getCenterXForColumn(j);
            float size = cellState.size * cellState.scale;
            float translationY = cellState.translateY;
            drawCircle(canvas, (int) centerX, (int) centerY + translationY, size, 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 */));

        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.rexmtorres.android.patternlock.PatternLockView.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  .  ja v  a2 s.com*/
        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;
            drawDot(canvas, (int) centerX, (int) centerY + translationY, cellState.radius, drawLookup[i][j],
                    cellState.alpha, cellState.bitmapDot);
        }
    }

    // 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 */));
        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:io.authme.sdk.widget.LockPatternView.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  ww  . java  2  s . c  o m*/
        for (int i = 0; i < numCircles; i++) {
            final Cell cell = pattern.get(i);
            drawLookup[cell.row][cell.column] = 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 < MATRIX_WIDTH; i++) {
        float centerY = getCenterYForRow(i);
        for (int j = 0; j < MATRIX_WIDTH; j++) {
            CellState cellState = mCellStates[i][j];
            float centerX = getCenterXForColumn(j);
            float size = cellState.size * cellState.scale;
            float translationY = cellState.translateY;
            drawCircle(canvas, (int) centerX, (int) centerY + translationY, size, 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 */));

        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:electrifierzzz.robotcontrol.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  va 2 s. 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 < 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(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);
        }
    }
}