Example usage for android.graphics Paint setStrokeWidth

List of usage examples for android.graphics Paint setStrokeWidth

Introduction

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

Prototype

public void setStrokeWidth(float width) 

Source Link

Document

Set the width for stroking.

Usage

From source file:org.navitproject.navit.NavitGraphics.java

protected void draw_polyline(Paint paint, int[] c) {
    paint.setStrokeWidth(c[0]);
    paint.setARGB(c[1], c[2], c[3], c[4]);
    paint.setStyle(Paint.Style.STROKE);
    //paint.setAntiAlias(true);
    //paint.setStrokeWidth(0);
    int ndashes = c[5];
    float[] intervals = new float[ndashes + (ndashes % 2)];
    for (int i = 0; i < ndashes; i++) {
        intervals[i] = c[6 + i];// w ww.  ja va2  s.  c o  m
    }

    if ((ndashes % 2) == 1) {
        intervals[ndashes] = intervals[ndashes - 1];
    }

    if (ndashes > 0) {
        paint.setPathEffect(new android.graphics.DashPathEffect(intervals, 0.0f));
    }

    Path path = new Path();
    path.moveTo(c[6 + ndashes], c[7 + ndashes]);
    for (int i = 8 + ndashes; i < c.length; i += 2) {
        path.lineTo(c[i], c[i + 1]);
    }
    //global_path.close();
    draw_canvas.drawPath(path, paint);
    paint.setPathEffect(null);
}

From source file:com.android.gallery3d.filtershow.imageshow.ImageShow.java

public void drawCompareImage(Canvas canvas, Bitmap image) {
    MasterImage master = MasterImage.getImage();
    boolean showsOriginal = master.showsOriginal();
    if (!showsOriginal && !mTouchShowOriginal)
        return;/*from w  ww .  j ava 2s .c  o  m*/
    canvas.save();
    if (image != null) {
        if (mShowOriginalDirection == 0) {
            if (Math.abs(mTouch.y - mTouchDown.y) > Math.abs(mTouch.x - mTouchDown.x)) {
                mShowOriginalDirection = UNVEIL_VERTICAL;
            } else {
                mShowOriginalDirection = UNVEIL_HORIZONTAL;
            }
        }

        int px = 0;
        int py = 0;
        if (mShowOriginalDirection == UNVEIL_VERTICAL) {
            px = mImageBounds.width();
            py = mTouch.y - mImageBounds.top;
        } else {
            px = mTouch.x - mImageBounds.left;
            py = mImageBounds.height();
            if (showsOriginal) {
                px = mImageBounds.width();
            }
        }

        Rect d = new Rect(mImageBounds.left, mImageBounds.top, mImageBounds.left + px, mImageBounds.top + py);
        if (mShowOriginalDirection == UNVEIL_HORIZONTAL) {
            if (mTouchDown.x - mTouch.x > 0) {
                d.set(mImageBounds.left + px, mImageBounds.top, mImageBounds.right, mImageBounds.top + py);
            }
        } else {
            if (mTouchDown.y - mTouch.y > 0) {
                d.set(mImageBounds.left, mImageBounds.top + py, mImageBounds.left + px, mImageBounds.bottom);
            }
        }
        canvas.clipRect(d);
        Matrix m = master.computeImageToScreen(image, 0, false);
        canvas.drawBitmap(image, m, mPaint);
        Paint paint = new Paint();
        paint.setColor(Color.BLACK);
        paint.setStrokeWidth(3);

        if (mShowOriginalDirection == UNVEIL_VERTICAL) {
            canvas.drawLine(mImageBounds.left, mTouch.y, mImageBounds.right, mTouch.y, paint);
        } else {
            canvas.drawLine(mTouch.x, mImageBounds.top, mTouch.x, mImageBounds.bottom, paint);
        }

        Rect bounds = new Rect();
        paint.setAntiAlias(true);
        paint.setTextSize(mOriginalTextSize);
        paint.getTextBounds(mOriginalText, 0, mOriginalText.length(), bounds);
        paint.setColor(Color.BLACK);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(3);
        canvas.drawText(mOriginalText, mImageBounds.left + mOriginalTextMargin,
                mImageBounds.top + bounds.height() + mOriginalTextMargin, paint);
        paint.setStyle(Paint.Style.FILL);
        paint.setStrokeWidth(1);
        paint.setColor(Color.WHITE);
        canvas.drawText(mOriginalText, mImageBounds.left + mOriginalTextMargin,
                mImageBounds.top + bounds.height() + mOriginalTextMargin, paint);
    }
    canvas.restore();
}

From source file:com.linkloving.dyh08.logic.UI.launch.view.wheelview.WheelView.java

/**
 * Draws rect for current value//from ww w .ja  v  a  2 s.c om
 *
 * @param canvas the canvas for drawing
 */
private void drawCenterRect(Canvas canvas) {
    int center = getHeight() / 2;
    int offset = (int) (getItemHeight() / 2 * 1.2);

    // Remarked by wulianghuan
    // Rect rect = new Rect(left, top, right, bottom)
    // centerDrawable.setBounds(bounds)
    // centerDrawable.setBounds(0, center - offset, getWidth(), center + offset);
    // centerDrawable.draw(canvas);

    Paint paint = new Paint();
    paint.setColor(Color.parseColor("#FFD0D0D0"));
    // 
    paint.setStrokeWidth((float) 1);
    // 
    canvas.drawLine(0, center - offset, getWidth(), center - offset, paint);
    // 
    canvas.drawLine(0, center + offset, getWidth(), center + offset, paint);
    // */
}

From source file:com.smp.musicspeed.MainActivity.java

private void addBarGraphRenderers() {
    Paint paint = new Paint();
    paint.setStrokeWidth(10.5f);
    paint.setAntiAlias(true);/*from   www  . j  a v a  2 s .co  m*/
    paint.setColor(Color.argb(255, 144, 202, 249));
    BarGraphRenderer barGraphRendererBottom = new BarGraphRenderer(4, paint, false);
    visualizerView.addRenderer(barGraphRendererBottom);
}

From source file:com.xgf.inspection.qrcode.google.zxing.client.CaptureActivity.java

/**
 * Superimpose a line for 1D or dots for 2D to highlight the key features of
 * the barcode./*from   w ww . jav a  2s .c  o m*/
 *
 * @param barcode
 *            A bitmap of the captured image.
 * @param rawResult
 *            The decoded results which contains the points to draw.
 */
private void drawResultPoints(Bitmap barcode, Result rawResult) {
    ResultPoint[] points = rawResult.getResultPoints();
    if (points != null && points.length > 0) {
        Canvas canvas = new Canvas(barcode);
        Paint paint = new Paint();
        paint.setColor(getResources().getColor(R.color.result_points));
        if (points.length == 2) {
            paint.setStrokeWidth(4.0f);
            drawLine(canvas, paint, points[0], points[1]);
        } else if (points.length == 4 && (rawResult.getBarcodeFormat() == BarcodeFormat.UPC_A
                || rawResult.getBarcodeFormat() == BarcodeFormat.EAN_13)) {
            // Hacky special case -- draw two lines, for the barcode and
            // metadata
            drawLine(canvas, paint, points[0], points[1]);
            drawLine(canvas, paint, points[2], points[3]);
        } else {
            paint.setStrokeWidth(10.0f);
            for (ResultPoint point : points) {
                canvas.drawPoint(point.getX(), point.getY(), paint);
            }
        }
    }
}

From source file:info.bartowski.easteregg.LLand.java

@Override
public void onDraw(Canvas c) {
    super.onDraw(c);

    if (!DEBUG_DRAW)
        return;/* w w w . jav a  2s.c  o m*/

    final Paint pt = new Paint();
    pt.setColor(0xFFFFFFFF);
    final int L = mDroid.corners.length;
    final int N = L / 2;
    for (int i = 0; i < N; i++) {
        final int x = (int) mDroid.corners[i * 2];
        final int y = (int) mDroid.corners[i * 2 + 1];
        c.drawCircle(x, y, 4, pt);
        c.drawLine(x, y, mDroid.corners[(i * 2 + 2) % L], mDroid.corners[(i * 2 + 3) % L], pt);
    }

    pt.setStyle(Paint.Style.STROKE);
    pt.setStrokeWidth(getResources().getDisplayMetrics().density);

    final int M = getChildCount();
    pt.setColor(0x8000FF00);
    for (int i = 0; i < M; i++) {
        final View v = getChildAt(i);
        if (v == mDroid)
            continue;
        if (!(v instanceof GameView))
            continue;
        if (v instanceof Pop) {
            final Pop p = (Pop) v;
            c.drawCircle(p.cx, p.cy, p.r, pt);
        } else {
            final Rect r = new Rect();
            v.getHitRect(r);
            c.drawRect(r, pt);
        }
    }

    pt.setColor(Color.BLACK);
    final StringBuilder sb = new StringBuilder("obstacles: ");
    for (Obstacle ob : mObstaclesInPlay) {
        sb.append(ob.hitRect.toShortString());
        sb.append(" ");
    }
    pt.setTextSize(20f);
    c.drawText(sb.toString(), 20, 100, pt);
}

From source file:com.appeaser.sublimepickerlibrary.timepicker.RadialTimePickerView.java

private void drawSelector(Canvas canvas, int index, Path selectorPath, float alphaMod) {
    final int alpha = (int) (mAlpha[index % 2].getValue() * alphaMod + 0.5f);
    final int color = applyAlpha(mSelectorColor, alpha);

    // Calculate the current radius at which to place the selection circle.
    final int selRadius = mSelectorRadius;
    final int selLength = mCircleRadius - mTextInset[index];
    final double selAngleRad = Math.toRadians(mSelectionDegrees[index % 2]);
    final float selCenterX = mXCenter + selLength * (float) Math.sin(selAngleRad);
    final float selCenterY = mYCenter - selLength * (float) Math.cos(selAngleRad);

    // Draw the selection circle.
    final Paint paint = mPaintSelector[index % 2][SELECTOR_CIRCLE];
    paint.setColor(color);//from   ww  w. j a v  a2 s.c o m
    canvas.drawCircle(selCenterX, selCenterY, selRadius, paint);

    // If needed, set up the clip path for later.
    if (selectorPath != null) {
        selectorPath.reset();
        selectorPath.addCircle(selCenterX, selCenterY, selRadius, Path.Direction.CCW);
    }

    // Draw the dot if we're between two items.
    final boolean shouldDrawDot = mSelectionDegrees[index % 2] % 30 != 0;
    if (shouldDrawDot) {
        final Paint dotPaint = mPaintSelector[index % 2][SELECTOR_DOT];
        dotPaint.setColor(mSelectorDotColor);
        canvas.drawCircle(selCenterX, selCenterY, mSelectorDotRadius, dotPaint);
    }

    // Shorten the line to only go from the edge of the center dot to the
    // edge of the selection circle.
    final double sin = Math.sin(selAngleRad);
    final double cos = Math.cos(selAngleRad);
    final int lineLength = selLength - selRadius;
    final int centerX = mXCenter + (int) (mCenterDotRadius * sin);
    final int centerY = mYCenter - (int) (mCenterDotRadius * cos);
    final float linePointX = centerX + (int) (lineLength * sin);
    final float linePointY = centerY - (int) (lineLength * cos);

    // Draw the line.
    final Paint linePaint = mPaintSelector[index % 2][SELECTOR_LINE];
    linePaint.setColor(color);
    linePaint.setStrokeWidth(mSelectorStroke);
    canvas.drawLine(mXCenter, mYCenter, linePointX, linePointY, linePaint);
}

From source file:org.navitproject.navit.NavitGraphics.java

protected void draw_text(Paint paint, int x, int y, String text, int size, int dx, int dy, int bgcolor) {
    int oldcolor = paint.getColor();
    Path path = null;//from w w w.  j a v a 2  s  .  c o m

    paint.setTextSize(size / 15);
    paint.setStyle(Paint.Style.FILL);

    if (dx != 0x10000 || dy != 0) {
        path = new Path();
        path.moveTo(x, y);
        path.rLineTo(dx, dy);
        paint.setTextAlign(android.graphics.Paint.Align.LEFT);
    }

    if (bgcolor != 0) {
        paint.setStrokeWidth(3);
        paint.setColor(bgcolor);
        paint.setStyle(Paint.Style.STROKE);
        if (path == null) {
            draw_canvas.drawText(text, x, y, paint);
        } else {
            draw_canvas.drawTextOnPath(text, path, 0, 0, paint);
        }
        paint.setStyle(Paint.Style.FILL);
        paint.setColor(oldcolor);
    }

    if (path == null) {
        draw_canvas.drawText(text, x, y, paint);
    } else {
        draw_canvas.drawTextOnPath(text, path, 0, 0, paint);
    }
    paint.clearShadowLayer();
}

From source file:net.droidsolutions.droidcharts.core.renderer.AbstractCategoryItemRenderer.java

/**
 * Draws a marker for the range axis./*from  w  ww.j a  v a  2s  .co m*/
 * 
 * @param g2
 *            the graphics device (not <code>null</code>).
 * @param plot
 *            the plot (not <code>null</code>).
 * @param axis
 *            the range axis (not <code>null</code>).
 * @param marker
 *            the marker to be drawn (not <code>null</code>).
 * @param dataArea
 *            the area inside the axes (not <code>null</code>).
 * 
 * @see #drawDomainMarker(Graphics2D, CategoryPlot, CategoryAxis,
 *      CategoryMarker, Rectangle2D)
 */
public void drawRangeMarker(Canvas g2, CategoryPlot plot, ValueAxis axis, Marker marker, Rectangle2D dataArea) {

    if (marker instanceof ValueMarker) {
        ValueMarker vm = (ValueMarker) marker;
        double value = vm.getValue();
        Range range = axis.getRange();

        if (!range.contains(value)) {
            return;
        }

        PlotOrientation orientation = plot.getOrientation();
        double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());
        Line2D line = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY());
        } else if (orientation == PlotOrientation.VERTICAL) {
            line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v);
        }

        Paint p = marker.getPaint();
        p.setAlpha(vm.getAlpha());
        p.setStrokeWidth(marker.getStroke());
        g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(), (float) line.getY2(), p);

        String label = marker.getLabel();
        RectangleAnchor anchor = marker.getLabelAnchor();
        if (label != null) {
            Font labelFont = marker.getLabelFont();
            // g2.setFont(labelFont);

            Point2D coordinates = calculateRangeMarkerTextAnchorPoint(g2, orientation, dataArea,
                    line.getBounds2D(), marker.getLabelOffset(), LengthAdjustmentType.EXPAND, anchor);
            TextUtilities.drawAlignedString(label, g2, (float) coordinates.getX(), (float) coordinates.getY(),
                    marker.getLabelTextAnchor(), marker.getLabelPaint());
        }
        // g2.setComposite(savedComposite);
        p.setAlpha(255);
    } else if (marker instanceof IntervalMarker) {
        IntervalMarker im = (IntervalMarker) marker;
        double start = im.getStartValue();
        double end = im.getEndValue();
        Range range = axis.getRange();
        if (!(range.intersects(start, end))) {
            return;
        }

        double start2d = axis.valueToJava2D(start, dataArea, plot.getRangeAxisEdge());
        double end2d = axis.valueToJava2D(end, dataArea, plot.getRangeAxisEdge());
        double low = Math.min(start2d, end2d);
        double high = Math.max(start2d, end2d);

        PlotOrientation orientation = plot.getOrientation();
        Rectangle2D rect = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            // clip left and right bounds to data area
            low = Math.max(low, dataArea.getMinX());
            high = Math.min(high, dataArea.getMaxX());
            rect = new Rectangle2D.Double(low, dataArea.getMinY(), high - low, dataArea.getHeight());
        } else if (orientation == PlotOrientation.VERTICAL) {
            // clip top and bottom bounds to data area
            low = Math.max(low, dataArea.getMinY());
            high = Math.min(high, dataArea.getMaxY());
            rect = new Rectangle2D.Double(dataArea.getMinX(), low, dataArea.getWidth(), high - low);
        }
        Paint p = marker.getPaint();
        p.setAlpha((int) marker.getAlpha() * 100);// TODO ALPHA
        p.setStyle(Paint.Style.FILL);

        g2.drawRect((float) rect.getMinX(), (float) rect.getMinY(), (float) rect.getMaxX(),
                (float) rect.getMinY(), p);

        // now draw the outlines, if visible...
        if (im.getOutlinePaint() != null && im.getOutlineStroke() != 0.0f) {
            if (orientation == PlotOrientation.VERTICAL) {
                Line2D line = new Line2D.Double();
                double x0 = dataArea.getMinX();
                double x1 = dataArea.getMaxX();
                Paint paint = im.getOutlinePaint();
                paint.setStrokeWidth(im.getOutlineStroke());

                if (range.contains(start)) {
                    line.setLine(x0, start2d, x1, start2d);
                    g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(),
                            (float) line.getY2(), paint);
                }
                if (range.contains(end)) {
                    line.setLine(x0, end2d, x1, end2d);
                    g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(),
                            (float) line.getY2(), paint);
                }
            } else { // PlotOrientation.HORIZONTAL
                Line2D line = new Line2D.Double();
                double y0 = dataArea.getMinY();
                double y1 = dataArea.getMaxY();
                Paint paint = im.getOutlinePaint();
                paint.setStrokeWidth(im.getOutlineStroke());
                if (range.contains(start)) {
                    line.setLine(start2d, y0, start2d, y1);
                    g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(),
                            (float) line.getY2(), paint);
                }
                if (range.contains(end)) {
                    line.setLine(end2d, y0, end2d, y1);
                    g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(),
                            (float) line.getY2(), paint);
                }
            }
        }

        String label = marker.getLabel();
        RectangleAnchor anchor = marker.getLabelAnchor();
        if (label != null) {
            Font labelFont = marker.getLabelFont();
            // g2.setFont(labelFont);
            Paint pp = marker.getLabelPaint();
            // g2.setPaint(marker.getLabelPaint());
            Point2D coordinates = calculateRangeMarkerTextAnchorPoint(g2, orientation, dataArea, rect,
                    marker.getLabelOffset(), marker.getLabelOffsetType(), anchor);
            TextUtilities.drawAlignedString(label, g2, (float) coordinates.getX(), (float) coordinates.getY(),
                    marker.getLabelTextAnchor(), pp);
        }
        p.setAlpha(255);
    }
}