List of usage examples for android.graphics Paint setStrokeWidth
public void setStrokeWidth(float width)
From source file:com.gm.common.ui.widget.pageindicator.PageIndicatorView.java
private void drawWithNoEffect(@NonNull Canvas canvas, int position, int x, int y) { float radius = radiusPx; if (animationType == AnimationType.SCALE) { radius *= scaleFactor;// w w w . ja v a2s . c o m } int color = unselectedColor; if (position == selectedPosition) { color = selectedColor; } Paint paint; if (animationType == AnimationType.FILL) { paint = strokePaint; paint.setStrokeWidth(strokePx); } else { paint = fillPaint; } paint.setColor(color); canvas.drawCircle(x, y, radius, paint); }
From source file:net.droidsolutions.droidcharts.core.renderer.xy.AbstractXYItemRenderer.java
/** * Draws a vertical line on the chart to represent a 'range marker'. * * @param g2 the graphics device./*from ww w .j a va 2 s . co m*/ * @param plot the plot. * @param domainAxis the domain axis. * @param marker the marker line. * @param dataArea the axis data area. */ public void drawDomainMarker(Canvas g2, XYPlot plot, ValueAxis domainAxis, Marker marker, Rectangle2D dataArea) { if (marker instanceof ValueMarker) { ValueMarker vm = (ValueMarker) marker; double value = vm.getValue(); Range range = domainAxis.getRange(); if (!range.contains(value)) { return; } double v = domainAxis.valueToJava2D(value, dataArea, plot.getDomainAxisEdge()); PlotOrientation orientation = plot.getOrientation(); Line2D line = null; if (orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY()); } Paint paint = marker.getPaint(); int oldAlpha = paint.getAlpha(); paint.setAlpha(marker.getAlpha()); Float stroke = marker.getStroke(); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(stroke); 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(); Paint lPaint = marker.getLabelPaint(); lPaint.setTypeface(labelFont.getTypeFace()); lPaint.setTextSize(labelFont.getSize()); int lOldAlpha = lPaint.getAlpha(); lPaint.setAlpha(marker.getAlpha()); Point2D coordinates = calculateDomainMarkerTextAnchorPoint(g2, orientation, dataArea, line.getBounds2D(), marker.getLabelOffset(), LengthAdjustmentType.EXPAND, anchor); TextUtilities.drawAlignedString(label, g2, (float) coordinates.getX(), (float) coordinates.getY(), marker.getLabelTextAnchor(), lPaint); lPaint.setAlpha(lOldAlpha); } paint.setAlpha(oldAlpha); } else if (marker instanceof IntervalMarker) { IntervalMarker im = (IntervalMarker) marker; double start = im.getStartValue(); double end = im.getEndValue(); Range range = domainAxis.getRange(); if (!(range.intersects(start, end))) { return; } double start2d = domainAxis.valueToJava2D(start, dataArea, plot.getDomainAxisEdge()); double end2d = domainAxis.valueToJava2D(end, dataArea, plot.getDomainAxisEdge()); double low = Math.min(start2d, end2d); double high = Math.max(start2d, end2d); PlotOrientation orientation = plot.getOrientation(); Rectangle2D rect = null; if (orientation == PlotOrientation.HORIZONTAL) { // 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); } else if (orientation == PlotOrientation.VERTICAL) { // 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()); } Paint p = marker.getPaint(); int oldAlpha = p.getAlpha(); p.setAlpha(marker.getAlpha()); p.setStyle(Paint.Style.FILL); g2.drawRect((float) rect.getMinX(), (float) rect.getMinY(), (float) rect.getMaxX(), (float) rect.getMaxY(), p); p.setAlpha(oldAlpha); // now draw the outlines, if visible... if (im.getOutlinePaint() != null && im.getOutlineStroke() != null) { if (orientation == PlotOrientation.VERTICAL) { Line2D line = new Line2D.Double(); double y0 = dataArea.getMinY(); double y1 = dataArea.getMaxY(); Paint oPiant = im.getOutlinePaint(); oPiant.setStyle(Paint.Style.STROKE); int oOldAlpha = oPiant.getAlpha(); oPiant.setAlpha(marker.getAlpha()); oPiant.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(), oPiant); } if (range.contains(end)) { line.setLine(end2d, y0, end2d, y1); g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(), (float) line.getY2(), oPiant); } oPiant.setAlpha(oOldAlpha); } else { // PlotOrientation.HORIZONTAL Line2D line = new Line2D.Double(); double x0 = dataArea.getMinX(); double x1 = dataArea.getMaxX(); Paint oPiant = im.getOutlinePaint(); oPiant.setStyle(Paint.Style.STROKE); int oOldAlpha = oPiant.getAlpha(); oPiant.setAlpha(marker.getAlpha()); oPiant.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(), oPiant); } if (range.contains(end)) { line.setLine(x0, end2d, x1, end2d); g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(), (float) line.getY2(), oPiant); } oPiant.setAlpha(oOldAlpha); } } String label = marker.getLabel(); RectangleAnchor anchor = marker.getLabelAnchor(); if (label != null) { Font labelFont = marker.getLabelFont(); Paint paint = marker.getLabelPaint(); paint.setTypeface(labelFont.getTypeFace()); paint.setTextSize(labelFont.getSize()); Point2D coordinates = calculateDomainMarkerTextAnchorPoint(g2, orientation, dataArea, rect, marker.getLabelOffset(), marker.getLabelOffsetType(), anchor); TextUtilities.drawAlignedString(label, g2, (float) coordinates.getX(), (float) coordinates.getY(), marker.getLabelTextAnchor(), paint); } } }
From source file:com.example.SmartBoard.DrawingView.java
public void onDrawLine(Canvas canvas) { Paint paint = drawPaint; if (points[1] == null) //point4 null when user did not touch and move on screen. return;/* w w w . j a v a2s. c o m*/ //draw stroke paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(5); if (finished) { JSONObject objectProperties = new JSONObject(); String key = UUID.randomUUID().toString(); try { objectProperties.put("id", key); objectProperties.put("clientId", client.getClientId()); objectProperties.put("type", "Line"); objectProperties.put("color", drawPaint.getColor()); objectProperties.put("size", 5); objectProperties.put("startx", linePath.startx()); objectProperties.put("starty", linePath.starty()); objectProperties.put("stopx", linePath.stopx()); objectProperties.put("stopy", linePath.stopy()); objectProperties.put("gradient", linePath.getGradient()); objectProperties.put("length", linePath.length()); } catch (JSONException e) { e.printStackTrace(); } objectDrawables.put(key, objectProperties); mqtt.publishLine(objectProperties); //reset to start drawing again points = new Point[4]; colorballs.clear(); return; } canvas.drawLine(linePath.startx(), linePath.starty(), linePath.stopx(), linePath.stopy(), paint); // 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); canvas.drawText("" + (i + 1), ball.getX(), ball.getY(), paint); } }
From source file:com.nextgis.mobile.fragment.MapFragment.java
protected void drawScaleRuler() { int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, 10, getResources().getDisplayMetrics()); int notch = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, 1, getResources().getDisplayMetrics()); Bitmap ruler = Bitmap.createBitmap(px, px, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(ruler); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(ContextCompat.getColor(getActivity(), R.color.primary_dark)); paint.setStrokeWidth(4); paint.setStyle(Paint.Style.STROKE); canvas.drawLine(0, px, px, px, paint); canvas.drawLine(0, px, 0, 0, paint); canvas.drawLine(0, 0, notch, 0, paint); canvas.drawLine(px, px, px, px - notch, paint); mScaleRuler.setImageBitmap(ruler);/*w ww . ja v a 2 s.co m*/ }
From source file:info.bartowski.easteregg.MLand.java
@Override public void onDraw(Canvas c) { super.onDraw(c); if (SHOW_TOUCHES) { for (Player p : mPlayers) { if (p.mTouchX > 0) { mTouchPaint.setColor(0x80FFFFFF & p.color); mPlayerTracePaint.setColor(0x80FFFFFF & p.color); float x1 = p.mTouchX; float y1 = p.mTouchY; c.drawCircle(x1, y1, 100, mTouchPaint); float x2 = p.getX() + p.getPivotX(); float y2 = p.getY() + p.getPivotY(); float angle = PI_2 - (float) Math.atan2(x2 - x1, y2 - y1); x1 += 100 * Math.cos(angle); y1 += 100 * Math.sin(angle); c.drawLine(x1, y1, x2, y2, mPlayerTracePaint); }//from w w w.j a va 2s.c om } } if (!DEBUG_DRAW) return; final Paint pt = new Paint(); pt.setColor(0xFFFFFFFF); for (Player p : mPlayers) { final int L = p.corners.length; final int N = L / 2; for (int i = 0; i < N; i++) { final int x = (int) p.corners[i * 2]; final int y = (int) p.corners[i * 2 + 1]; c.drawCircle(x, y, 4, pt); c.drawLine(x, y, p.corners[(i * 2 + 2) % L], p.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 instanceof Player) continue; if (!(v instanceof GameView)) continue; if (v instanceof Pop) { final Pop pop = (Pop) v; c.drawCircle(pop.cx, pop.cy, pop.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.example.SmartBoard.DrawingView.java
@Override protected void onDraw(Canvas canvas) { drawCanvas.drawPath(drawPath, drawPaint); drawCanvas.drawPath(drawPathRecv, drawPaintSender); if (rectMode) { //draw rectangle drawPaint.setXfermode(null);/*from w w w .ja v a 2 s.c o m*/ onDrawRectangle(canvas); } else if (circleMode) { drawPaint.setXfermode(null); onDrawCircle(canvas); } else if (lineMode) { drawPaint.setXfermode(null); onDrawLine(canvas); } else if (textMode) { drawPaint.setXfermode(null); onDrawText(canvas); } else if (dragMode && !dragFinished) { drawPaint.setXfermode(null); onDragDraw(canvas, dragX, dragY); } else if (colorDropperMode) { drawPaint.setXfermode(null); onDrawColorDropper(canvas, dropperX, dropperY); } else if (textSizeMode) { drawPaint.setXfermode(null); } canvas.drawBitmap(canvasBitmap, 0, 0, canvasPaint); //redraw objects Paint tempPaint = new Paint(); tempPaint.setStyle(Paint.Style.STROKE); for (String key : textObjects.keySet()) { if (key.compareTo("") == 0) { continue; } JSONObject o = textObjects.get(key); tempPaint.setColor(o.optInt("color")); tempPaint.setStrokeWidth(o.optInt("size")); canvas.drawBitmap(mqtt.stringToBitmap(o.optString("textBitmap")), o.optInt("x"), o.optInt("y"), tempPaint); } for (String key : objectDrawables.keySet()) { //hashtable problems no time to explain. But it creates a duplicate of last item I add to the table. //So dont print duplicates which have empty string key values if (key.compareTo("") == 0) { continue; } JSONObject o = objectDrawables.get(key); String objectType = o.optString("type"); tempPaint.setColor(o.optInt("color")); tempPaint.setStrokeWidth(o.optInt("size")); if (objectType.compareTo("Circle") == 0) { canvas.drawCircle(o.optInt("x"), o.optInt("y"), o.optInt("radius"), tempPaint); } else if (objectType.compareTo("Line") == 0) { canvas.drawLine(o.optInt("startx"), o.optInt("starty"), o.optInt("stopx"), o.optInt("stopy"), tempPaint); } else if (objectType.compareTo("Rectangle") == 0) { canvas.drawRect(Rect.unflattenFromString(o.optString("dimens")), tempPaint); } else if (objectType.compareTo("Text") == 0) { //canvas.drawRect(Rect.unflattenFromString(o.optString("region")), drawPaint); canvas.drawBitmap(mqtt.stringToBitmap(o.optString("textBitmap")), o.optInt("x"), o.optInt("y"), tempPaint); } } }
From source file:net.droidsolutions.droidcharts.core.renderer.xy.AbstractXYItemRenderer.java
/** * Draws a line perpendicular to the range axis. * * @param g2 the graphics device./* ww w . ja v a 2 s. c om*/ * @param plot the plot. * @param axis the value axis. * @param dataArea the area for plotting data (not yet adjusted for any 3D * effect). * @param value the value at which the grid line should be drawn. * @param paint the paint. * @param stroke the stroke. */ public void drawRangeLine(Canvas g2, XYPlot plot, ValueAxis axis, Rectangle2D dataArea, double value, Paint paint, Float stroke) { Range range = axis.getRange(); if (!range.contains(value)) { return; } PlotOrientation orientation = plot.getOrientation(); Line2D line = null; double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge()); 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.setStyle(Paint.Style.STROKE); 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.renderer.xy.AbstractXYItemRenderer.java
/** * Draws a line perpendicular to the domain axis. * * @param g2 the graphics device./*from w w w . j av a 2 s .c om*/ * @param plot the plot. * @param axis the value axis. * @param dataArea the area for plotting data (not yet adjusted for any 3D * effect). * @param value the value at which the grid line should be drawn. * @param paint the paint (<code>null</code> not permitted). * @param stroke the stroke (<code>null</code> not permitted). * * @since 1.0.5 */ public void drawDomainLine(Canvas g2, XYPlot plot, ValueAxis axis, Rectangle2D dataArea, double value, Paint paint, Float stroke) { Range range = axis.getRange(); if (!range.contains(value)) { return; } PlotOrientation orientation = plot.getOrientation(); Line2D line = null; double v = axis.valueToJava2D(value, dataArea, plot.getDomainAxisEdge()); if (orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY()); } paint.setStyle(Paint.Style.STROKE); 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.renderer.AbstractCategoryItemRenderer.java
/** * Draws a line perpendicular to the range axis. * /*from w w w . jav a 2s . co m*/ * @param g2 * the graphics device. * @param plot * the plot. * @param axis * the value axis. * @param dataArea * the area for plotting data (not yet adjusted for any 3D * effect). * @param value * the value at which the grid line should be drawn. * @param paint * the paint (<code>null</code> not permitted). * @param stroke * the stroke (<code>null</code> not permitted). * * @see #drawRangeGridline * * @since 1.0.13 */ public void drawRangeLine(Canvas g2, CategoryPlot plot, ValueAxis axis, Rectangle2D dataArea, double value, Paint paint, float stroke) { // TODO: In JFreeChart 1.2.0, put this method in the // CategoryItemRenderer interface Range range = axis.getRange(); if (!range.contains(value)) { return; } PlotOrientation orientation = plot.getOrientation(); Line2D line = null; double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge()); 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.setStrokeWidth(stroke); g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(), (float) line.getY2(), paint); }
From source file:net.droidsolutions.droidcharts.core.renderer.AbstractCategoryItemRenderer.java
/** * Draws a marker for the domain axis./*from w ww .j a va2 s . c om*/ * * @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 #drawRangeMarker(Graphics2D, CategoryPlot, ValueAxis, Marker, * Rectangle2D) */ public void drawDomainMarker(Canvas g2, CategoryPlot plot, CategoryAxis axis, CategoryMarker marker, Rectangle2D dataArea) { Comparable category = marker.getKey(); CategoryDataset dataset = plot.getDataset(plot.getIndexOf(this)); int columnIndex = dataset.getColumnIndex(category); if (columnIndex < 0) { return; } Paint paint = marker.getPaint(); paint.setAlpha(marker.getAlpha()); PlotOrientation orientation = plot.getOrientation(); Rectangle2D bounds = null; if (marker.getDrawAsLine()) { double v = axis.getCategoryMiddle(columnIndex, dataset.getColumnCount(), dataArea, plot.getDomainAxisEdge()); Line2D line = null; if (orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY()); } paint.setStrokeWidth(marker.getStroke()); g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(), (float) line.getY2(), paint); bounds = line.getBounds2D(); } else { double v0 = axis.getCategoryStart(columnIndex, dataset.getColumnCount(), dataArea, plot.getDomainAxisEdge()); double v1 = axis.getCategoryEnd(columnIndex, dataset.getColumnCount(), dataArea, plot.getDomainAxisEdge()); Rectangle2D area = null; if (orientation == PlotOrientation.HORIZONTAL) { area = new Rectangle2D.Double(dataArea.getMinX(), v0, dataArea.getWidth(), (v1 - v0)); } else if (orientation == PlotOrientation.VERTICAL) { area = new Rectangle2D.Double(v0, dataArea.getMinY(), (v1 - v0), dataArea.getHeight()); } Paint p = marker.getPaint(); p.setStyle(Paint.Style.FILL); g2.drawRect((float) area.getMinX(), (float) area.getMinY(), (float) area.getMaxX(), (float) area.getMaxY(), p); bounds = area; } String label = marker.getLabel(); RectangleAnchor anchor = marker.getLabelAnchor(); if (label != null) { Font labelFont = marker.getLabelFont(); // g2.setFont(labelFont); // g2.setPaint(marker.getLabelPaint()); Point2D coordinates = calculateDomainMarkerTextAnchorPoint(g2, orientation, dataArea, bounds, marker.getLabelOffset(), marker.getLabelOffsetType(), anchor); TextUtilities.drawAlignedString(label, g2, (float) coordinates.getX(), (float) coordinates.getY(), marker.getLabelTextAnchor(), marker.getLabelPaint()); } // g2.setComposite(savedComposite); }