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:com.example.SmartBoard.DrawingView.java

public void onDrawRectangle(Canvas canvas) {
    Paint paint = drawPaint;
    if (points[3] == null) //point4 null when user did not touch and move on screen.
        return;//from  w w  w .j a  v  a2 s  .  co  m
    int left, top, right, bottom;
    left = points[0].x;
    top = points[0].y;
    right = points[0].x;
    bottom = points[0].y;
    for (int i = 1; i < points.length; i++) {
        left = left > points[i].x ? points[i].x : left;
        top = top > points[i].y ? points[i].y : top;
        right = right < points[i].x ? points[i].x : right;
        bottom = bottom < points[i].y ? points[i].y : bottom;
    }

    //draw stroke
    paint.setStyle(Paint.Style.STROKE);
    // paint.setColor(Color.parseColor("#AADB1255"));
    paint.setStrokeWidth(5);

    if (finished) {

        Rect rect = new Rect(left + colorballs.get(0).getWidthOfBall() / 2,
                top + colorballs.get(0).getWidthOfBall() / 2, right + colorballs.get(2).getWidthOfBall() / 2,
                bottom + colorballs.get(2).getWidthOfBall() / 2);

        JSONObject objectProperties = new JSONObject();
        String key = UUID.randomUUID().toString();

        try {
            objectProperties.put("type", "Rectangle");
            objectProperties.put("clientId", client.getClientId());
            objectProperties.put("id", key);
            objectProperties.put("color", drawPaint.getColor());
            objectProperties.put("size", 5);
            objectProperties.put("dimens", rect.flattenToString());

        } catch (JSONException e) {

        }

        objectDrawables.put(key, objectProperties);

        mqtt.publishRectangle(objectProperties);
        //reset to start drawing again
        points = new Point[4];
        colorballs.clear();
        return;
    }

    //temporary canvas drawing on resize mode
    canvas.drawRect(left + colorballs.get(0).getWidthOfBall() / 2, top + colorballs.get(0).getWidthOfBall() / 2,
            right + colorballs.get(2).getWidthOfBall() / 2, bottom + colorballs.get(2).getWidthOfBall() / 2,
            paint);

    //draw the corners
    BitmapDrawable bitmap = new BitmapDrawable();
    // draw the balls on the canvas
    paint.setTextSize(18);
    paint.setStrokeWidth(0);

    for (int i = 0; i < colorballs.size(); i++) {
        ColorBall ball = colorballs.get(i);
        canvas.drawBitmap(ball.getBitmap(), ball.getX(), ball.getY(), paint);
        //  System.out.println("RectMode");

        canvas.drawText("" + (i + 1), ball.getX(), ball.getY(), paint);
    }
}

From source file:com.example.SmartBoard.DrawingView.java

public void onDrawCircle(Canvas canvas) {
    Paint paint = drawPaint;
    if (points[3] == null) //point4 null when user did not touch and move on screen.
        return;/*from  ww  w .  j  a v  a2 s.  c  om*/
    int left, top, right, bottom;
    left = points[0].x;
    top = points[0].y;
    right = points[0].x;
    bottom = points[0].y;
    for (int i = 1; i < points.length; i++) {
        left = left > points[i].x ? points[i].x : left;
        top = top > points[i].y ? points[i].y : top;
        right = right < points[i].x ? points[i].x : right;
        bottom = bottom < points[i].y ? points[i].y : bottom;
    }

    float cx = (left + right) / 2f;
    float cy = (top + bottom) / 2f;
    float radius = (float) Math.hypot(top - bottom, right - left) / 2f;

    //draw stroke
    paint.setStyle(Paint.Style.STROKE);
    // paint.setColor(Color.parseColor("#AADB1255"));
    paint.setStrokeWidth(5);

    if (finished) {

        JSONObject objectProperties = new JSONObject();
        String key = UUID.randomUUID().toString();

        try {
            objectProperties.put("id", key);
            objectProperties.put("type", "Circle");
            objectProperties.put("color", drawPaint.getColor());
            objectProperties.put("size", 5);
            objectProperties.put("clientId", client.getClientId());
            objectProperties.put("radius", radius);
            objectProperties.put("x", cx);
            objectProperties.put("y", cy);

        } catch (JSONException e) {

        }

        objectDrawables.put(key, objectProperties);

        //  drawCanvas.drawCircle(cx, cy, radius, paint);

        //   drawCanvas.save();
        //  mqtt.publishRectangle(objectProperties);
        mqtt.publishCircle(objectProperties);

        //reset to start drawing again
        points = new Point[4];
        colorballs.clear();
        return;

    }

    canvas.drawCircle(cx, cy, radius, paint);
    // draw the balls on the canvas
    //  paint.setColor(Color.BLUE);
    paint.setTextSize(18);
    paint.setStrokeWidth(0);
    // paint.setColor(Color.BLUE);
    for (int i = 0; i < colorballs.size(); i++) {
        ColorBall ball = colorballs.get(i);
        canvas.drawBitmap(ball.getBitmap(), ball.getX(), ball.getY(), paint);

        canvas.drawText("" + (i + 1), ball.getX(), ball.getY(), paint);
    }
}

From source file:com.dwdesign.tweetings.util.Utils.java

public static Bitmap getColorPreviewBitmap(final Context context, final int color) {
    if (context == null)
        return null;
    final float density = context.getResources().getDisplayMetrics().density;
    final int width = (int) (32 * density), height = (int) (32 * density);

    final Bitmap bm = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    final Canvas canvas = new Canvas(bm);

    final int rectrangle_size = (int) (density * 5);
    final int numRectanglesHorizontal = (int) Math.ceil(width / rectrangle_size);
    final int numRectanglesVertical = (int) Math.ceil(height / rectrangle_size);
    final Rect r = new Rect();
    boolean verticalStartWhite = true;
    for (int i = 0; i <= numRectanglesVertical; i++) {

        boolean isWhite = verticalStartWhite;
        for (int j = 0; j <= numRectanglesHorizontal; j++) {

            r.top = i * rectrangle_size;
            r.left = j * rectrangle_size;
            r.bottom = r.top + rectrangle_size;
            r.right = r.left + rectrangle_size;
            final Paint paint = new Paint();
            paint.setColor(isWhite ? Color.WHITE : Color.GRAY);

            canvas.drawRect(r, paint);//from w  w  w .  ja  v a 2s  .c om

            isWhite = !isWhite;
        }

        verticalStartWhite = !verticalStartWhite;

    }
    canvas.drawColor(color);
    final Paint paint = new Paint();
    paint.setColor(Color.WHITE);
    paint.setStrokeWidth(2.0f);
    final float[] points = new float[] { 0, 0, width, 0, 0, 0, 0, height, width, 0, width, height, 0, height,
            width, height };
    canvas.drawLines(points, paint);

    return bm;
}

From source file:com.android.systemui.statusbar.phone.NotificationPanelView.java

@Override
protected void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);
    if (DEBUG) {/* www  .j a  v  a  2s.  com*/
        Paint p = new Paint();
        p.setColor(Color.RED);
        p.setStrokeWidth(2);
        p.setStyle(Paint.Style.STROKE);
        canvas.drawLine(0, getMaxPanelHeight(), getWidth(), getMaxPanelHeight(), p);
        p.setColor(Color.BLUE);
        canvas.drawLine(0, getExpandedHeight(), getWidth(), getExpandedHeight(), p);
        p.setColor(Color.GREEN);
        canvas.drawLine(0, calculatePanelHeightQsExpanded(), getWidth(), calculatePanelHeightQsExpanded(), p);
        p.setColor(Color.YELLOW);
        canvas.drawLine(0, calculatePanelHeightShade(), getWidth(), calculatePanelHeightShade(), p);
        p.setColor(Color.MAGENTA);
        canvas.drawLine(0, calculateQsTopPadding(), getWidth(), calculateQsTopPadding(), p);
        p.setColor(Color.CYAN);
        canvas.drawLine(0, mNotificationStackScroller.getTopPadding(), getWidth(),
                mNotificationStackScroller.getTopPadding(), p);
    }
}

From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java

private void drawScrollLine(Rect r, Canvas canvas, Paint p) {
    final int right = computeDayLeftPosition(mNumDays);
    final int y = mFirstCell - 1;

    p.setAntiAlias(false);/*from w ww  .j  a  v a2s  .c  o  m*/
    p.setStyle(Style.FILL);

    p.setColor(mCalendarGridLineInnerHorizontalColor);
    p.setStrokeWidth(GRID_LINE_INNER_WIDTH);
    canvas.drawLine(GRID_LINE_LEFT_MARGIN, y, right, y, p);
    p.setAntiAlias(true);
}

From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java

private void drawGridBackground(Rect r, Canvas canvas, Paint p) {
    Style savedStyle = p.getStyle();

    final float stopX = computeDayLeftPosition(mNumDays);
    float y = 0;// w w  w  .ja v a2  s.co m
    final float deltaY = mCellHeight + HOUR_GAP;
    int linesIndex = 0;
    final float startY = 0;
    final float stopY = HOUR_GAP + 24 * (mCellHeight + HOUR_GAP);
    float x = mHoursWidth;

    // Draw the inner horizontal grid lines
    p.setColor(mCalendarGridLineInnerHorizontalColor);
    p.setStrokeWidth(GRID_LINE_INNER_WIDTH);
    p.setAntiAlias(false);
    y = 0;
    linesIndex = 0;
    for (int hour = 0; hour <= 24; hour++) {
        mLines[linesIndex++] = GRID_LINE_LEFT_MARGIN;
        mLines[linesIndex++] = y;
        mLines[linesIndex++] = stopX;
        mLines[linesIndex++] = y;
        y += deltaY;
    }
    if (mCalendarGridLineInnerVerticalColor != mCalendarGridLineInnerHorizontalColor) {
        canvas.drawLines(mLines, 0, linesIndex, p);
        linesIndex = 0;
        p.setColor(mCalendarGridLineInnerVerticalColor);
    }

    // Draw the inner vertical grid lines
    for (int day = 0; day <= mNumDays; day++) {
        x = computeDayLeftPosition(day);
        mLines[linesIndex++] = x;
        mLines[linesIndex++] = startY;
        mLines[linesIndex++] = x;
        mLines[linesIndex++] = stopY;
    }
    canvas.drawLines(mLines, 0, linesIndex, p);

    // Restore the saved style.
    p.setStyle(savedStyle);
    p.setAntiAlias(true);
}

From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java

private Rect drawEventRect(Event event, Canvas canvas, Paint p, Paint eventTextPaint, int visibleTop,
        int visibleBot) {
    // Draw the Event Rect
    Rect r = mRect;/*from   w  w  w .  ja  v a  2s.  c  om*/
    r.top = Math.max((int) event.top + EVENT_RECT_TOP_MARGIN, visibleTop);
    r.bottom = Math.min((int) event.bottom - EVENT_RECT_BOTTOM_MARGIN, visibleBot);
    r.left = (int) event.left + EVENT_RECT_LEFT_MARGIN;
    r.right = (int) event.right;

    int color;
    if (event == mClickedEvent) {
        color = mClickedColor;
    } else {
        color = event.color;
    }

    p.setStyle(Style.FILL_AND_STROKE);
    p.setAntiAlias(false);

    int floorHalfStroke = (int) Math.floor(EVENT_RECT_STROKE_WIDTH / 2.0f);
    int ceilHalfStroke = (int) Math.ceil(EVENT_RECT_STROKE_WIDTH / 2.0f);
    r.top = Math.max((int) event.top + EVENT_RECT_TOP_MARGIN + floorHalfStroke, visibleTop);
    r.bottom = Math.min((int) event.bottom - EVENT_RECT_BOTTOM_MARGIN - ceilHalfStroke, visibleBot);
    r.left += floorHalfStroke;
    r.right -= ceilHalfStroke;
    p.setStrokeWidth(EVENT_RECT_STROKE_WIDTH);
    p.setColor(color);
    int alpha = p.getAlpha();
    p.setAlpha(mEventsAlpha);
    canvas.drawRect(r, p);
    p.setAlpha(alpha);
    p.setStyle(Style.FILL);

    // If this event is selected, then use the selection color
    if (mSelectedEvent == event && mClickedEvent != null) {
        boolean paintIt = false;
        color = 0;

        if (paintIt) {
            p.setColor(color);
            canvas.drawRect(r, p);
        }
        p.setAntiAlias(true);
    }

    // Setup rect for drawEventText which follows
    r.top = (int) event.top + EVENT_RECT_TOP_MARGIN;
    r.bottom = (int) event.bottom - EVENT_RECT_BOTTOM_MARGIN;
    r.left = (int) event.left + EVENT_RECT_LEFT_MARGIN;
    r.right = (int) event.right - EVENT_RECT_RIGHT_MARGIN;
    return r;
}

From source file:net.droidsolutions.droidcharts.core.plot.CategoryPlot.java

/**
 * Utility method for drawing a line perpendicular to the range axis (used
 * for crosshairs).//  w w w .j  a  v a2  s . c o  m
 * 
 * @param g2
 *            the graphics device.
 * @param dataArea
 *            the area defined by the axes.
 * @param value
 *            the data value.
 * @param stroke
 *            the line stroke (<code>null</code> not permitted).
 * @param paint
 *            the line paint (<code>null</code> not permitted).
 */
protected void drawRangeLine(Canvas g2, Rectangle2D dataArea, double value, float stroke, Paint paint) {

    double java2D = getRangeAxis().valueToJava2D(value, dataArea, getRangeAxisEdge());
    Line2D line = null;
    if (this.orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(java2D, dataArea.getMinY(), java2D, dataArea.getMaxY());
    } else if (this.orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(dataArea.getMinX(), java2D, dataArea.getMaxX(), java2D);
    }
    paint.setStrokeWidth(stroke);
    g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(), (float) line.getY2(), paint);

}

From source file:net.droidsolutions.droidcharts.core.plot.CategoryPlot.java

/**
 * Draws a range crosshair.//  w w  w  .  j  av  a 2  s.co  m
 * 
 * @param g2
 *            the graphics target.
 * @param dataArea
 *            the data area.
 * @param orientation
 *            the plot orientation.
 * @param value
 *            the crosshair value.
 * @param axis
 *            the axis against which the value is measured.
 * @param stroke
 *            the stroke used to draw the crosshair line.
 * @param paint
 *            the paint used to draw the crosshair line.
 * 
 * @see #drawDomainCrosshair(Graphics2D, Rectangle2D, PlotOrientation, int,
 *      Comparable, Comparable, Stroke, Paint)
 * 
 * @since 1.0.5
 */
protected void drawRangeCrosshair(Canvas g2, Rectangle2D dataArea, PlotOrientation orientation, double value,
        ValueAxis axis, float stroke, Paint paint) {

    if (!axis.getRange().contains(value)) {
        return;
    }
    Line2D line = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        double xx = axis.valueToJava2D(value, dataArea, RectangleEdge.BOTTOM);
        line = new Line2D.Double(xx, dataArea.getMinY(), xx, dataArea.getMaxY());
    } else {
        double yy = axis.valueToJava2D(value, dataArea, RectangleEdge.LEFT);
        line = new Line2D.Double(dataArea.getMinX(), yy, dataArea.getMaxX(), yy);
    }
    paint.setStrokeWidth(stroke);
    g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(), (float) line.getY2(), paint);

}

From source file:net.droidsolutions.droidcharts.core.plot.CategoryPlot.java

/**
 * Draws a domain crosshair.//from  w w w. j  ava  2  s. c  om
 * 
 * @param g2
 *            the graphics target.
 * @param dataArea
 *            the data area.
 * @param orientation
 *            the plot orientation.
 * @param datasetIndex
 *            the dataset index.
 * @param rowKey
 *            the row key.
 * @param columnKey
 *            the column key.
 * @param stroke
 *            the stroke used to draw the crosshair line.
 * @param paint
 *            the paint used to draw the crosshair line.
 * 
 * @see #drawRangeCrosshair(Graphics2D, Rectangle2D, PlotOrientation,
 *      double, ValueAxis, Stroke, Paint)
 * 
 * @since 1.0.11
 */
protected void drawDomainCrosshair(Canvas g2, Rectangle2D dataArea, PlotOrientation orientation,
        int datasetIndex, Comparable rowKey, Comparable columnKey, float stroke, Paint paint) {

    CategoryDataset dataset = getDataset(datasetIndex);
    CategoryAxis axis = getDomainAxisForDataset(datasetIndex);
    CategoryItemRenderer renderer = getRenderer(datasetIndex);
    Line2D line = null;
    if (orientation == PlotOrientation.VERTICAL) {
        double xx = renderer.getItemMiddle(rowKey, columnKey, dataset, axis, dataArea, RectangleEdge.BOTTOM);
        line = new Line2D.Double(xx, dataArea.getMinY(), xx, dataArea.getMaxY());
    } else {
        double yy = renderer.getItemMiddle(rowKey, columnKey, dataset, axis, dataArea, RectangleEdge.LEFT);
        line = new Line2D.Double(dataArea.getMinX(), yy, dataArea.getMaxX(), yy);
    }
    paint.setStrokeWidth(stroke);
    g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(), (float) line.getY2(), paint);

}