Example usage for android.graphics Path close

List of usage examples for android.graphics Path close

Introduction

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

Prototype

public void close() 

Source Link

Document

Close the current contour.

Usage

From source file:com.wanikani.androidnotifier.graph.HistogramPlot.java

protected void drawBar(Canvas canvas, Samples bar, float left, float right) {
    long base, height;
    float top, tbl;
    Paint lpaint;//from ww  w  .  j a v a 2  s  .  c  o m
    Paint paint;
    Path path;
    RectF rect;

    top = vp.getY(vp.yMax);
    base = 0;
    for (Sample sample : bar.samples) {
        if (sample.value > 0) {
            height = sample.value;

            if (base > vp.yMax)
                ;
            else if (base + height > vp.yMax) {
                path = new Path();
                path.moveTo(left, vp.getY(base));
                path.lineTo(left, top);
                path.lineTo(left + (right - left) / 3, top - 10);
                path.lineTo(left + (right - left) * 2 / 3, top + 5);
                path.lineTo(right, top);
                path.lineTo(right, vp.getY(base));
                path.close();
                canvas.drawPath(path, pas.series.get(sample.series));
            } else {
                rect = new RectF(left, vp.getY(base + height), right, vp.getY(base));
                rect.intersect(meas.plotArea);
                paint = pas.series.get(sample.series);
                paint.setStyle(Style.FILL);
                canvas.drawRect(rect, paint);
                paint.setStyle(Style.STROKE);
                canvas.drawRect(rect, paint);
            }
            base += height;
        }
    }

    if (base <= vp.yMax) {
        lpaint = pas.levelupPaint;
        tbl = vp.getY(base) - meas.headroom / 2;
    } else {
        lpaint = pas.levelupPaintInside;
        tbl = vp.getY(vp.yMax) + meas.margin;
    }

    if (base > 0 && drawTotal)
        canvas.drawText(Long.toString(base), (left + right) / 2, tbl, lpaint);
}

From source file:com.wanikani.androidnotifier.graph.TYPlot.java

/**
 * Draws a segment containins samples//w  w  w  .  j a va 2  s . c  om
 * @param canvas the canvas
 * @param series the series
 * @param interval the interval
 * @param base a float array initially set to zero, and updated by this method
 * @param samples the samples 
 */
protected void drawPlot(Canvas canvas, Pager.Series series, Pager.Interval interval, float base[],
        float samples[]) {
    Path path;
    Paint p;
    int i, n;

    p = pas.series.get(series);
    n = interval.stop - interval.start + 1;
    if (p == null || samples.length == 0 || n <= 0)
        return;

    path = new Path();

    path.moveTo(vp.getRelPosition(interval.start + n), vp.getY(base[n - 1]));

    for (i = n - 1; i >= 0; i--) {
        path.lineTo(vp.getRelPosition(interval.start + i), vp.getY(base[i]));
        base[i] += samples[i];
    }

    for (i = 0; i < n; i++)
        path.lineTo(vp.getRelPosition(interval.start + i), vp.getY(base[i]));

    path.lineTo(vp.getRelPosition(interval.start + n), vp.getY(base[n - 1]));

    path.close();

    canvas.drawPath(path, p);
}

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 {//from   w ww. ja v a 2  s  . c o  m
            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:org.androfarsh.widget.DragGridLayout.java

@Override
protected void dispatchDraw(Canvas canvas) {
    if (mDebugMode) {
        mPaint.setStyle(Style.FILL_AND_STROKE);
        final Path path = new Path();

        path.reset();/*from  w w  w. ja v a 2s  . co m*/
        mCellsRegion.getBoundaryPath(path);
        path.close();
        mPaint.setColor(0x660000cc);
        canvas.drawPath(path, mPaint);

        path.reset();
        mFreeCellsRegion.getBoundaryPath(path);
        path.close();
        mPaint.setColor(0x66cc0000);
        canvas.drawPath(path, mPaint);
    }

    if (mRootView == null) {
        drawCellGrid(canvas);
    }
    super.dispatchDraw(canvas);
}

From source file:com.github.jokar.rxupload.widget.ProgressDownloadView.java

private void makePathBubble() {

    if (mPathBubble == null) {
        mPathBubble = new Path();
    }//from ww  w . j  a  v a  2s.  c  o m

    int width = mBubbleWidth;
    int height = mBubbleHeight;
    int arrowWidth = width / 3;

    //Rect r = new Rect(Math.max(getPaddingLeft()-width/2-arrowWidth/4, mProgress*mWidth/100-width/2-arrowWidth/4), mHeight/2-height + calculatedeltaY(), Math.max(getPaddingLeft()+width/2-arrowWidth/4, mProgress*mWidth/100+width/2-arrowWidth/4), mHeight/2+height-height + calculatedeltaY());
    Rect r = new Rect((int) (Math.max(getPaddingLeft() - width / 2, mProgress * mWidth / 100 - width / 2)),
            (int) (mHeight / 2 - height + calculateDeltaY()),
            (int) (Math.max(getPaddingLeft() + width / 2, mProgress * mWidth / 100 + width / 2)),
            (int) (mHeight / 2 + height - height + calculateDeltaY()));
    int arrowHeight = (int) (arrowWidth / 1.5f);
    int radius = 8;

    Path path = new Path();

    // Down arrow
    path.moveTo(r.left + r.width() / 2 - arrowWidth / 2, r.top + r.height() - arrowHeight);
    bubbleAnchorX = r.left + r.width() / 2;
    bubbleAnchorY = r.top + r.height();
    path.lineTo(bubbleAnchorX, bubbleAnchorY);
    path.lineTo(r.left + r.width() / 2 + arrowWidth / 2, r.top + r.height() - arrowHeight);

    // Go to bottom-right
    path.lineTo(r.left + r.width() - radius, r.top + r.height() - arrowHeight);

    // Bottom-right arc
    path.arcTo(new RectF(r.left + r.width() - 2 * radius, r.top + r.height() - arrowHeight - 2 * radius,
            r.left + r.width(), r.top + r.height() - arrowHeight), 90, -90);

    // Go to upper-right
    path.lineTo(r.left + r.width(), r.top + arrowHeight);

    // Upper-right arc
    path.arcTo(new RectF(r.left + r.width() - 2 * radius, r.top, r.right, r.top + 2 * radius), 0, -90);

    // Go to upper-left
    path.lineTo(r.left + radius, r.top);

    // Upper-left arc
    path.arcTo(new RectF(r.left, r.top, r.left + 2 * radius, r.top + 2 * radius), 270, -90);

    // Go to bottom-left
    path.lineTo(r.left, r.top + r.height() - arrowHeight - radius);

    // Bottom-left arc
    path.arcTo(new RectF(r.left, r.top + r.height() - arrowHeight - 2 * radius, r.left + 2 * radius,
            r.top + r.height() - arrowHeight), 180, -90);

    path.close();

    mPathBubble.set(path);
}

From source file:org.onebusaway.android.map.googlemapsv2.StopOverlay.java

/**
 * Creates a bus stop icon with the given direction arrow, or without a direction arrow if
 * the direction is NO_DIRECTION/*w ww  .  ja  va2  s .c  o  m*/
 *
 * @param direction Bus stop direction, obtained from ObaStop.getDirection() and defined in
 *                  constants in this class, or NO_DIRECTION if the stop icon shouldn't have a
 *                  direction arrow
 * @return a bus stop icon bitmap with the arrow pointing the given direction, or with no arrow
 * if direction is NO_DIRECTION
 */
private static Bitmap createBusStopIcon(String direction) throws NullPointerException {
    if (direction == null) {
        throw new IllegalArgumentException(direction);
    }

    Resources r = Application.get().getResources();
    Context context = Application.get();

    Float directionAngle = null; // 0-360 degrees
    Bitmap bm;
    Canvas c;
    Drawable shape;
    Float rotationX = null, rotationY = null; // Point around which to rotate the arrow

    Paint arrowPaintFill = new Paint();
    arrowPaintFill.setStyle(Paint.Style.FILL);
    arrowPaintFill.setAntiAlias(true);

    if (direction.equals(NO_DIRECTION)) {
        // Don't draw the arrow
        bm = Bitmap.createBitmap(mPx, mPx, Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds(0, 0, bm.getWidth(), bm.getHeight());
    } else if (direction.equals(NORTH)) {
        directionAngle = 0f;
        bm = Bitmap.createBitmap(mPx, (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds(0, (int) mBuffer, mPx, bm.getHeight());
        // Shade with darkest color at tip of arrow
        arrowPaintFill.setShader(new LinearGradient(bm.getWidth() / 2, 0, bm.getWidth() / 2, mArrowHeightPx,
                r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR));
        // For NORTH, no rotation occurs - use center of image anyway so we have some value
        rotationX = bm.getWidth() / 2f;
        rotationY = bm.getHeight() / 2f;
    } else if (direction.equals(NORTH_WEST)) {
        directionAngle = 315f; // Arrow is drawn N, rotate 315 degrees
        bm = Bitmap.createBitmap((int) (mPx + mBuffer), (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds((int) mBuffer, (int) mBuffer, bm.getWidth(), bm.getHeight());
        // Shade with darkest color at tip of arrow
        arrowPaintFill.setShader(new LinearGradient(0, 0, mBuffer, mBuffer, r.getColor(R.color.theme_primary),
                r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR));
        // Rotate around below coordinates (trial and error)
        rotationX = mPx / 2f + mBuffer / 2f;
        rotationY = bm.getHeight() / 2f - mBuffer / 2f;
    } else if (direction.equals(WEST)) {
        directionAngle = 0f; // Arrow is drawn pointing West, so no rotation
        bm = Bitmap.createBitmap((int) (mPx + mBuffer), mPx, Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds((int) mBuffer, 0, bm.getWidth(), bm.getHeight());
        arrowPaintFill.setShader(new LinearGradient(0, bm.getHeight() / 2, mArrowHeightPx, bm.getHeight() / 2,
                r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR));
        // For WEST
        rotationX = bm.getHeight() / 2f;
        rotationY = bm.getHeight() / 2f;
    } else if (direction.equals(SOUTH_WEST)) {
        directionAngle = 225f; // Arrow is drawn N, rotate 225 degrees
        bm = Bitmap.createBitmap((int) (mPx + mBuffer), (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds((int) mBuffer, 0, bm.getWidth(), mPx);
        arrowPaintFill.setShader(new LinearGradient(0, bm.getHeight(), mBuffer, bm.getHeight() - mBuffer,
                r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR));
        // Rotate around below coordinates (trial and error)
        rotationX = bm.getWidth() / 2f - mBuffer / 4f;
        rotationY = mPx / 2f + mBuffer / 4f;
    } else if (direction.equals(SOUTH)) {
        directionAngle = 180f; // Arrow is drawn N, rotate 180 degrees
        bm = Bitmap.createBitmap(mPx, (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds(0, 0, bm.getWidth(), (int) (bm.getHeight() - mBuffer));
        arrowPaintFill.setShader(new LinearGradient(bm.getWidth() / 2, bm.getHeight(), bm.getWidth() / 2,
                bm.getHeight() - mArrowHeightPx, r.getColor(R.color.theme_primary),
                r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR));
        rotationX = bm.getWidth() / 2f;
        rotationY = bm.getHeight() / 2f;
    } else if (direction.equals(SOUTH_EAST)) {
        directionAngle = 135f; // Arrow is drawn N, rotate 135 degrees
        bm = Bitmap.createBitmap((int) (mPx + mBuffer), (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds(0, 0, mPx, mPx);
        arrowPaintFill.setShader(new LinearGradient(bm.getWidth(), bm.getHeight(), bm.getWidth() - mBuffer,
                bm.getHeight() - mBuffer, r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent),
                Shader.TileMode.MIRROR));
        // Rotate around below coordinates (trial and error)
        rotationX = (mPx + mBuffer / 2) / 2f;
        rotationY = bm.getHeight() / 2f;
    } else if (direction.equals(EAST)) {
        directionAngle = 180f; // Arrow is drawn pointing West, so rotate 180
        bm = Bitmap.createBitmap((int) (mPx + mBuffer), mPx, Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds(0, 0, mPx, bm.getHeight());
        arrowPaintFill.setShader(new LinearGradient(bm.getWidth(), bm.getHeight() / 2,
                bm.getWidth() - mArrowHeightPx, bm.getHeight() / 2, r.getColor(R.color.theme_primary),
                r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR));
        rotationX = bm.getWidth() / 2f;
        rotationY = bm.getHeight() / 2f;
    } else if (direction.equals(NORTH_EAST)) {
        directionAngle = 45f; // Arrow is drawn pointing N, so rotate 45 degrees
        bm = Bitmap.createBitmap((int) (mPx + mBuffer), (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds(0, (int) mBuffer, mPx, bm.getHeight());
        // Shade with darkest color at tip of arrow
        arrowPaintFill.setShader(new LinearGradient(bm.getWidth(), 0, bm.getWidth() - mBuffer, mBuffer,
                r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR));
        // Rotate around middle of circle
        rotationX = (float) mPx / 2;
        rotationY = bm.getHeight() - (float) mPx / 2;
    } else {
        throw new IllegalArgumentException(direction);
    }

    shape.draw(c);

    if (direction.equals(NO_DIRECTION)) {
        // Everything after this point is for drawing the arrow image, so return the bitmap as-is for no arrow
        return bm;
    }

    /**
     * Draw the arrow - all dimensions should be relative to px so the arrow is drawn the same
     * size for all orientations
     */
    // Height of the cutout in the bottom of the triangle that makes it an arrow (0=triangle)
    final float CUTOUT_HEIGHT = mPx / 12;
    Path path = new Path();
    float x1 = 0, y1 = 0; // Tip of arrow
    float x2 = 0, y2 = 0; // lower left
    float x3 = 0, y3 = 0; // cutout in arrow bottom
    float x4 = 0, y4 = 0; // lower right

    if (direction.equals(NORTH) || direction.equals(SOUTH) || direction.equals(NORTH_EAST)
            || direction.equals(SOUTH_EAST) || direction.equals(NORTH_WEST) || direction.equals(SOUTH_WEST)) {
        // Arrow is drawn pointing NORTH
        // Tip of arrow
        x1 = mPx / 2;
        y1 = 0;

        // lower left
        x2 = (mPx / 2) - (mArrowWidthPx / 2);
        y2 = mArrowHeightPx;

        // cutout in arrow bottom
        x3 = mPx / 2;
        y3 = mArrowHeightPx - CUTOUT_HEIGHT;

        // lower right
        x4 = (mPx / 2) + (mArrowWidthPx / 2);
        y4 = mArrowHeightPx;
    } else if (direction.equals(EAST) || direction.equals(WEST)) {
        // Arrow is drawn pointing WEST
        // Tip of arrow
        x1 = 0;
        y1 = mPx / 2;

        // lower left
        x2 = mArrowHeightPx;
        y2 = (mPx / 2) - (mArrowWidthPx / 2);

        // cutout in arrow bottom
        x3 = mArrowHeightPx - CUTOUT_HEIGHT;
        y3 = mPx / 2;

        // lower right
        x4 = mArrowHeightPx;
        y4 = (mPx / 2) + (mArrowWidthPx / 2);
    }

    path.setFillType(Path.FillType.EVEN_ODD);
    path.moveTo(x1, y1);
    path.lineTo(x2, y2);
    path.lineTo(x3, y3);
    path.lineTo(x4, y4);
    path.lineTo(x1, y1);
    path.close();

    // Rotate arrow around (rotationX, rotationY) point
    Matrix matrix = new Matrix();
    matrix.postRotate(directionAngle, rotationX, rotationY);
    path.transform(matrix);

    c.drawPath(path, arrowPaintFill);
    c.drawPath(path, mArrowPaintStroke);

    return bm;
}

From source file:com.breel.wearables.shadowclock.graphics.ShapeShadow.java

public void parseJSON(String jsonFile) {
    if (jsonFile != null) {
        // Load all the JSONs with the numbers information
        try {/*from w  w  w  .j  a va2s. co m*/
            JSONObject obj = new JSONObject(loadJSONFromAsset(jsonFile));
            Log.d(TAG, "SHAPE SHADOW JSON FILE " + jsonFile + ": LOADED");

            id = obj.getString("id");

            JSONArray jsonPathData;
            JSONArray jsonShadowData;

            if (!id.equals("5")) {
                jsonPathData = obj.getJSONArray("path");
                jsonShadowData = obj.getJSONArray("shadow");

                Log.d(TAG, "JSON PATH DATA LENGTH: " + jsonPathData.length() + "");
                Log.d(TAG, "JSON SHADOW DATA LENGTH: " + jsonShadowData.length() + "");

                shapePath.reset();
                for (int i = 0; i < jsonPathData.length(); i++) {
                    try {
                        JSONObject elem = jsonPathData.getJSONObject(i);
                        String type = elem.getString("type");
                        JSONArray data = elem.getJSONArray("data");
                        if (type.equals("move")) {
                            shapePath.moveTo((float) data.getInt(0), (float) data.getInt(1));
                        } else if (type.equals("line")) {
                            shapePath.lineTo((float) data.getInt(0), (float) data.getInt(1));
                        } else if (type.equals("bezier")) {
                            shapePath.cubicTo((float) data.getInt(0), (float) data.getInt(1),
                                    (float) data.getInt(2), (float) data.getInt(3), (float) data.getInt(4),
                                    (float) data.getInt(5));
                        }
                    } catch (JSONException e) {
                        Log.d(TAG, "JSON ELEM EXCEPTION" + e.getMessage() + "");
                    }
                }
                shapePath.close();

                Random r = new Random();
                r.nextGaussian();

                JSONArray holesContainer = obj.getJSONArray("holes");
                Path holePath = new Path();
                for (int i = 0; i < holesContainer.length(); i++) {
                    JSONObject jsonInside = holesContainer.getJSONObject(i);
                    JSONArray hole = jsonInside.getJSONArray("data");
                    holePath.reset();
                    for (int j = 0; j < hole.length(); j++) {
                        try {
                            JSONObject elem = hole.getJSONObject(j);
                            String type = elem.getString("type");
                            JSONArray data = elem.getJSONArray("data");
                            if (type.equals("move")) {
                                holePath.moveTo((float) data.getInt(0), (float) data.getInt(1));
                            } else if (type.equals("line")) {
                                holePath.lineTo((float) data.getInt(0), (float) data.getInt(1));
                            } else if (type.equals("bezier")) {
                                holePath.cubicTo((float) data.getInt(0), (float) data.getInt(1),
                                        (float) data.getInt(2), (float) data.getInt(3), (float) data.getInt(4),
                                        (float) data.getInt(5));
                            }
                        } catch (JSONException e) {
                            Log.d(TAG, "JSON HOLE EXCEPTION" + e.getMessage() + "");
                        }
                    }
                    holePath.close();
                    shapePath.op(holePath, Path.Op.DIFFERENCE);
                }

                pathTransform.reset();
                pathTransform.setScale(scale + 0.04f, scale + 0.04f);
                shapePath.transform(pathTransform);
                boundsPath.transform(pathTransform);

                pathTransform.setTranslate(positionX - 0.3f, positionY - 0.3f);
                shapePath.transform(pathTransform);
                boundsPath.transform(pathTransform);

                int shadowTmpX;
                int shadowTmpY;

                shadowPaths.clear();
                vertexArray.clear();

                for (int i = 0; i < jsonShadowData.length(); i += 2) {
                    shadowTmpX = jsonShadowData.getInt(i);
                    shadowTmpY = jsonShadowData.getInt(i + 1);
                    addVertex(shadowTmpX, shadowTmpY);
                }
            } else {
                jsonPathData = obj.getJSONArray("path");
                jsonShadowData = obj.getJSONArray("shadow");

                Log.d(TAG, "JSON PATH DATA LENGTH: " + jsonPathData.length() + "");
                Log.d(TAG, "JSON SHADOW DATA LENGTH: " + jsonShadowData.length() + "");

                shapePath.reset();
                for (int i = 0; i < jsonPathData.length(); i++) {
                    JSONArray cords = jsonPathData.getJSONArray(i);
                    Path chunk = new Path();
                    chunk.reset();
                    for (int j = 0; j < cords.length(); j++) {
                        try {
                            JSONObject elem = cords.getJSONObject(j);
                            String type = elem.getString("type");
                            JSONArray data = elem.getJSONArray("data");
                            if (type.equals("move")) {
                                chunk.moveTo((float) data.getInt(0), (float) data.getInt(1));
                            } else if (type.equals("line")) {
                                chunk.lineTo((float) data.getInt(0), (float) data.getInt(1));
                            } else if (type.equals("bezier")) {
                                chunk.cubicTo((float) data.getInt(0), (float) data.getInt(1),
                                        (float) data.getInt(2), (float) data.getInt(3), (float) data.getInt(4),
                                        (float) data.getInt(5));
                            }
                        } catch (JSONException e) {
                            Log.d(TAG, "JSON 5 NUMBER ELEM EXCEPTION" + e.getMessage() + "");
                        }
                    }
                    chunk.close();
                    shapePath.op(chunk, Path.Op.UNION);
                }

                pathTransform.reset();
                pathTransform.setScale(scale, scale);
                shapePath.transform(pathTransform);
                boundsPath.transform(pathTransform);

                pathTransform.setTranslate(positionX, positionY);
                shapePath.transform(pathTransform);
                boundsPath.transform(pathTransform);

                shadowPaths.clear();
                vertexArray.clear();

                int shadowTmpX;
                int shadowTmpY;
                for (int i = 0; i < jsonShadowData.length(); i++) {
                    JSONArray coords = jsonShadowData.getJSONArray(i);
                    for (int j = 0; j < coords.length(); j += 2) {
                        shadowTmpX = coords.getInt(j);
                        shadowTmpY = coords.getInt(j + 1);
                        addVertex((float) shadowTmpX, (float) shadowTmpY);
                    }

                }
            }
        } catch (JSONException e) {
            Log.d(TAG, "JSON ROOT EXCEPTION" + e.getMessage() + "");
        }
    }
}

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);
    }// w  w w  . jav a2 s  .  c om

    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:cw.kop.autobackground.settings.WearSettingsFragment.java

private void drawAnalog() {
    if (!AppSettings.getTimeType().equals(AppSettings.ANALOG)) {
        return;/*from w  ww .j ava 2s .co  m*/
    }

    canvas = surfaceView.getHolder().lockCanvas();

    if (canvas == null) {
        return;
    }

    setPaints();

    if (imageBitmap != null) {
        canvas.drawBitmap(imageBitmap, 0, 0, bitmapPaint);
    }
    //        Time time = new Time();
    //        time.setToNow();
    //        time.set(time.toMillis(false) + AppSettings.getTimeOffset());
    //
    //        float hour = time.hour + time.minute / 60f;
    //        float minute = time.minute + time.second / 60f;
    //        float second = time.second;
    float centerX = watchContainer.getWidth() * 0.222f;
    float centerY = watchContainer.getHeight() * 0.222f;
    float radius = centerX;
    // Draw tick marks

    for (int i = 0; i < 12; i++) {
        canvas.drawLine((float) (centerX + (radius * tickRadius / 100f) * Math.cos(Math.toRadians(i * 30f))),
                (float) (centerY + (radius * tickRadius / 100f) * Math.sin(Math.toRadians(i * 30f))),
                (float) (centerX + (radius) * Math.cos(Math.toRadians(i * 30f))),
                (float) (centerY + (radius) * Math.sin(Math.toRadians(i * 30f))), tickPaint);
    }

    // Draw clock hands

    // Draw shadows first to prevent outline overlapping other hands

    Path hourShadowPath = new Path();
    hourShadowPath.moveTo((float) (centerX + hourWidth / 1.5f * Math.cos(Math.toRadians(90f))),
            (float) (centerY + hourWidth / 1.5f * Math.sin(Math.toRadians(90f))));
    hourShadowPath.quadTo((float) (centerX - (hourWidth / 1.5f) * Math.cos(Math.toRadians(0f))),
            (float) (centerY - (hourWidth / 1.5f) * Math.sin(Math.toRadians(0f))),
            (float) (centerX + hourWidth / 1.5f * Math.cos(Math.toRadians(270f))),
            (float) (centerY + hourWidth / 1.5f * Math.sin(Math.toRadians(270f))));
    hourShadowPath.lineTo(
            (float) (centerX + (radius * hourRadius / 100f + 2.0f) * Math.cos(Math.toRadians(0f))),
            (float) (centerY + (radius * hourRadius / 100f + 2.0f) * Math.sin(Math.toRadians(0f))));
    hourShadowPath.close();
    canvas.drawPath(hourShadowPath, hourShadowPaint);

    Path minuteShadowPath = new Path();
    minuteShadowPath.moveTo((float) (centerX + minuteWidth / 1.5f * Math.cos(Math.toRadians(0f))),
            (float) (centerY + minuteWidth / 1.5f * Math.sin(Math.toRadians(0f))));
    minuteShadowPath.quadTo((float) (centerX - (minuteWidth / 1.5f) * Math.cos(Math.toRadians(-180f))),
            (float) (centerY - (minuteWidth / 1.5f) * Math.sin(Math.toRadians(-180f))),
            (float) (centerX + minuteWidth / 1.5f * Math.cos(Math.toRadians(90f))),
            (float) (centerY + minuteWidth / 1.5f * Math.sin(Math.toRadians(90f))));
    minuteShadowPath.lineTo(
            (float) (centerX + (radius * minuteRadius / 100f + 2.0f) * Math.cos(Math.toRadians(-90f))),
            (float) (centerY + (radius * minuteRadius / 100f + 2.0f) * Math.sin(Math.toRadians(-90f))));
    minuteShadowPath.close();
    canvas.drawPath(minuteShadowPath, minuteShadowPaint);

    Path secondShadowPath = new Path();
    secondShadowPath.moveTo((float) (centerX + secondWidth / 1.5f * Math.cos(Math.toRadians(225f))),
            (float) (centerY + secondWidth / 1.5f * Math.sin(Math.toRadians(225f))));
    secondShadowPath.quadTo((float) (centerX - (secondWidth / 1.5f) * Math.cos(Math.toRadians(45f))),
            (float) (centerY - (secondWidth / 1.5f) * Math.sin(Math.toRadians(45f))),
            (float) (centerX + secondWidth / 1.5f * Math.cos(Math.toRadians(315f))),
            (float) (centerY + secondWidth / 1.5f * Math.sin(Math.toRadians(315f))));
    secondShadowPath.lineTo(
            (float) (centerX + (radius * secondRadius / 100f + 2f) * Math.cos(Math.toRadians(135f))),
            (float) (centerY + (radius * secondRadius / 100f + 2.0f) * Math.sin(Math.toRadians(135f))));
    secondShadowPath.close();
    canvas.drawPath(secondShadowPath, secondShadowPaint);

    // Now draw actual hands

    Path hourPath = new Path();
    hourPath.moveTo((float) (centerX + hourWidth / 2f * Math.cos(Math.toRadians(90f))),
            (float) (centerY + hourWidth / 2f * Math.sin(Math.toRadians(90f))));
    hourPath.quadTo((float) (centerX - (hourWidth / 2f) * Math.cos(Math.toRadians(0f))),
            (float) (centerY - (hourWidth / 2f) * Math.sin(Math.toRadians(0f))),
            (float) (centerX + hourWidth / 2f * Math.cos(Math.toRadians(270f))),
            (float) (centerY + hourWidth / 2f * Math.sin(Math.toRadians(270f))));
    hourPath.lineTo((float) (centerX + (radius * hourRadius / 100f) * Math.cos(Math.toRadians(0f))),
            (float) (centerY + (radius * hourRadius / 100f) * Math.sin(Math.toRadians(0f))));
    hourPath.close();
    canvas.drawPath(hourPath, hourPaint);

    Path minutePath = new Path();
    minutePath.moveTo((float) (centerX + minuteWidth / 2f * Math.cos(Math.toRadians(0f))),
            (float) (centerY + minuteWidth / 2f * Math.sin(Math.toRadians(0f))));
    minutePath.quadTo((float) (centerX - (minuteWidth / 2f) * Math.cos(Math.toRadians(-180f))),
            (float) (centerY - (minuteWidth / 2f) * Math.sin(Math.toRadians(-180f))),
            (float) (centerX + minuteWidth / 2f * Math.cos(Math.toRadians(90f))),
            (float) (centerY + minuteWidth / 2f * Math.sin(Math.toRadians(90f))));
    minutePath.lineTo((float) (centerX + (radius * minuteRadius / 100f) * Math.cos(Math.toRadians(-90f))),
            (float) (centerY + (radius * minuteRadius / 100f) * Math.sin(Math.toRadians(-90f))));
    minutePath.close();
    canvas.drawPath(minutePath, minutePaint);

    Path secondPath = new Path();
    secondPath.moveTo((float) (centerX + secondWidth / 2f * Math.cos(Math.toRadians(225f))),
            (float) (centerY + secondWidth / 2f * Math.sin(Math.toRadians(225f))));
    secondPath.quadTo((float) (centerX - (secondWidth / 2f) * Math.cos(Math.toRadians(45f))),
            (float) (centerY - (secondWidth / 2f) * Math.sin(Math.toRadians(45f))),
            (float) (centerX + secondWidth / 2f * Math.cos(Math.toRadians(315f))),
            (float) (centerY + secondWidth / 2f * Math.sin(Math.toRadians(315f))));
    secondPath.lineTo((float) (centerX + (radius * secondRadius / 100f) * Math.cos(Math.toRadians(135f))),
            (float) (centerY + (radius * secondRadius / 100f) * Math.sin(Math.toRadians(135f))));
    secondPath.close();
    canvas.drawPath(secondPath, secondPaint);

    surfaceView.getHolder().unlockCanvasAndPost(canvas);
}

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:/*w  w w  .j  a va2s  .c om*/
 * <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;
}