Example usage for android.graphics Paint setStrokeCap

List of usage examples for android.graphics Paint setStrokeCap

Introduction

In this page you can find the example usage for android.graphics Paint setStrokeCap.

Prototype

public void setStrokeCap(Cap cap) 

Source Link

Document

Set the paint's Cap.

Usage

From source file:net.line2soft.preambul.views.SlippyMapActivity.java

/**
 * Creates a {@link Paint} object with a certain color
 * @param color The wanted color// ww  w .j a  va 2s . c om
 * @param alpha The alpha channel
 * @return The created Paint object
 */
private Paint createPaint(int color, int alpha) {
    Paint pnt = new Paint(Paint.ANTI_ALIAS_FLAG);
    pnt.setColor(color);
    pnt.setAlpha(alpha);
    pnt.setStyle(Paint.Style.STROKE);
    pnt.setStrokeWidth(7);
    pnt.setStrokeJoin(Paint.Join.ROUND);
    pnt.setStrokeCap(Paint.Cap.ROUND);
    //pnt.setPathEffect(new DashPathEffect(new float[] { 20, 20 }, 0));
    return pnt;
}

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

/**
 * Draw a single data item.//w  w  w .  ja v  a2  s  .  c om
 * 
 * @param g2
 *            the graphics device.
 * @param state
 *            the renderer state.
 * @param dataArea
 *            the area in which the data is drawn.
 * @param plot
 *            the plot.
 * @param domainAxis
 *            the domain axis.
 * @param rangeAxis
 *            the range axis.
 * @param dataset
 *            the dataset.
 * @param row
 *            the row index (zero-based).
 * @param column
 *            the column index (zero-based).
 * @param pass
 *            the pass index.
 */
public void drawItem(Canvas g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {

    // do nothing if item is not visible
    if (!getItemVisible(row, column)) {
        return;
    }

    // do nothing if both the line and shape are not visible
    if (!getItemLineVisible(row, column) && !getItemShapeVisible(row, column)) {
        return;
    }

    // nothing is drawn for null...
    Number v = dataset.getValue(row, column);
    if (v == null) {
        return;
    }

    int visibleRow = state.getVisibleSeriesIndex(row);
    if (visibleRow < 0) {
        return;
    }
    int visibleRowCount = state.getVisibleSeriesCount();

    PlotOrientation orientation = plot.getOrientation();

    // current data point...
    double x1;
    if (this.useSeriesOffset) {
        x1 = domainAxis.getCategorySeriesMiddle(column, dataset.getColumnCount(), visibleRow, visibleRowCount,
                this.itemMargin, dataArea, plot.getDomainAxisEdge());
    } else {
        x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
    }
    double value = v.doubleValue();
    double y1 = rangeAxis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());

    if (pass == 0 && getItemLineVisible(row, column)) {
        if (column != 0) {
            Number previousValue = dataset.getValue(row, column - 1);
            if (previousValue != null) {
                // previous data point...
                double previous = previousValue.doubleValue();
                double x0;
                if (this.useSeriesOffset) {
                    x0 = domainAxis.getCategorySeriesMiddle(column - 1, dataset.getColumnCount(), visibleRow,
                            visibleRowCount, this.itemMargin, dataArea, plot.getDomainAxisEdge());
                } else {
                    x0 = domainAxis.getCategoryMiddle(column - 1, getColumnCount(), dataArea,
                            plot.getDomainAxisEdge());
                }
                double y0 = rangeAxis.valueToJava2D(previous, dataArea, plot.getRangeAxisEdge());

                Line2D line = null;
                if (orientation == PlotOrientation.HORIZONTAL) {
                    line = new Line2D.Double(y0, x0, y1, x1);
                } else if (orientation == PlotOrientation.VERTICAL) {
                    line = new Line2D.Double(x0, y0, x1, y1);
                }
                Paint paint = getItemPaint(row, column);
                Float stroke = getItemStroke(row, column);

                paint.setStyle(Paint.Style.STROKE);
                paint.setStrokeWidth(stroke);
                paint.setStrokeCap(Paint.Cap.ROUND);
                g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(),
                        (float) line.getY2(), paint);
            }
        }
    }

    if (pass == 1) {
        Shape shape = getItemShape(row, column);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, y1, x1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, x1, y1);
        }

        if (getItemShapeVisible(row, column)) {
            if (getItemShapeFilled(row, column)) {
                Paint paint;
                if (this.useFillPaint) {
                    paint = getItemFillPaint(row, column);
                } else {
                    paint = getItemPaint(row, column);
                }
                paint.setStyle(Paint.Style.FILL_AND_STROKE);
                Path path = convertAwtPathToAndroid(shape.getPathIterator(null));
                g2.drawPath(path, paint);

            }
            if (this.drawOutlines) {
                Paint paint;
                if (this.useOutlinePaint) {
                    paint = getItemOutlinePaint(row, column);
                } else {
                    paint = getItemPaint(row, column);
                }
                paint.setStyle(Paint.Style.STROKE);
                paint.setStrokeWidth(getItemOutlineStroke(row, column));
                Path path = convertAwtPathToAndroid(shape.getPathIterator(null));
                g2.drawPath(path, paint);
            }
        }

        // draw the item label if there is one...
        if (isItemLabelVisible(row, column)) {
            if (orientation == PlotOrientation.HORIZONTAL) {
                drawItemLabel(g2, orientation, dataset, row, column, y1, x1, (value < 0.0));
            } else if (orientation == PlotOrientation.VERTICAL) {
                drawItemLabel(g2, orientation, dataset, row, column, x1, y1, (value < 0.0));
            }
        }

        // submit the current data point as a crosshair candidate
        int datasetIndex = plot.indexOf(dataset);
        updateCrosshairValues(state.getCrosshairState(), dataset.getRowKey(row), dataset.getColumnKey(column),
                value, datasetIndex, x1, y1, orientation);

        // add an item entity, if this information is being collected
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            addItemEntity(entities, dataset, row, column, shape);
        }
    }

}