List of usage examples for android.graphics Paint setStrokeWidth
public void setStrokeWidth(float width)
From source file:com.fillerino.wallet.ui.ScanActivity.java
public void handleResult(final Result scanResult, final Bitmap thumbnailImage, final float thumbnailScaleFactor) { vibrator.vibrate(VIBRATE_DURATION);//w w w . j a va2 s . c o m // superimpose dots to highlight the key features of the qr code final ResultPoint[] points = scanResult.getResultPoints(); if (points != null && points.length > 0) { final Paint paint = new Paint(); paint.setColor(getResources().getColor(com.fillerino.wallet.R.color.scan_result_dots)); paint.setStrokeWidth(10.0f); final Canvas canvas = new Canvas(thumbnailImage); canvas.scale(thumbnailScaleFactor, thumbnailScaleFactor); for (final ResultPoint point : points) canvas.drawPoint(point.getX(), point.getY(), paint); } scannerView.drawResultBitmap(thumbnailImage); final Intent result = new Intent(); result.putExtra(INTENT_EXTRA_RESULT, scanResult.getText()); setResult(RESULT_OK, result); // delayed finish new Handler().post(new Runnable() { @Override public void run() { finish(); } }); }
From source file:gov.sfmta.sfpark.AnnotationsOverlay.java
public void draw(Canvas canvas, MapView mapv, boolean shadow) { if (shadow) { return;//w w w .j a v a 2s . c o m } Projection projection = mapv.getProjection(); Point from = new Point(); Point to = new Point(); Paint mPaint = new Paint(); mPaint.setStyle(Style.STROKE); mPaint.setAntiAlias(true); mPaint.setStrokeWidth(6); mPaint.setStrokeCap(Paint.Cap.ROUND); // could have NPE: try { for (MyAnnotation a : MainScreenActivity.annotations) { if (a.onStreet) { projection.toPixels(a.nw, from); projection.toPixels(a.se, to); if (MainScreenActivity.showPrice) { mPaint.setColor(a.blockColorPrice); canvas.drawLine(from.x, from.y, to.x, to.y, mPaint); } else { // new: no more availability data on blockfaces. // mPaint.setColor(a.blockColorAvailability); } } } } catch (NullPointerException npe) { // oh sadface! just ignore. } super.draw(canvas, mapv, shadow); }
From source file:com.binu.LogarithmicGraph.DrawGraphAsyncTask.java
@Override protected Object doInBackground(Object[] params) { Bitmap bitmapBackground = Bitmap.createBitmap(mViewWidth, mViewHeight, Bitmap.Config.ARGB_8888); Canvas canvasBackground = new Canvas(bitmapBackground); Paint paint = new Paint(); paint.setStrokeWidth(1f); int starty = 0; int endy = mViewHeight; canvasBackground.drawColor(Color.BLACK); double ratio = Math.pow(Math.E, Math.log(MAX_FREQUENCY / MIN_FREQUENCY) / mViewWidth); mLogScaledX_values = new double[mViewWidth]; for (int i = 0; i < mViewWidth; i++) { if (i == 0) { mLogScaledX_values[i] = 20;/*from ww w. jav a 2 s . c o m*/ } else { mLogScaledX_values[i] = mLogScaledX_values[i - 1] * ratio; } } //Major lines for (int i = 0; i < MAJOR_GRIDLINE_POINTS.length; i++) { paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color)); float xStart = (float) findNearestNumberPosition(mLogScaledX_values, MAJOR_GRIDLINE_POINTS[i]); float textSize = (getPixelDensity(mContext) * mLabelTextSize) / 480; paint.setTextSize(textSize); Log.i("Density", "" + getPixelDensity(mContext)); if (Math.round(MAJOR_GRIDLINE_POINTS[i]) == 20) { if (isShowLabels()) canvasBackground.drawText(getFormattedLabel(MAJOR_GRIDLINE_POINTS[i]), xStart + (getPixelDensity(mContext) * 10) / 480, endy - (getPixelDensity(mContext) * 10) / 480, paint); } else if (Math.round(MAJOR_GRIDLINE_POINTS[i]) == 20000) { if (isShowLabels()) canvasBackground.drawText(getFormattedLabel(MAJOR_GRIDLINE_POINTS[i]), xStart - (getPixelDensity(mContext) * 70) / 480, endy - (getPixelDensity(mContext) * 10) / 480, paint); } else { if (isShowLabels()) canvasBackground.drawText(getFormattedLabel(MAJOR_GRIDLINE_POINTS[i]), xStart - (getPixelDensity(mContext) * 30) / 480, endy - (getPixelDensity(mContext) * 10) / 480, paint); canvasBackground.drawLine(xStart, starty, xStart + 1, endy, paint); } } //Minor lines for (int i = 0; i < MINOR_GRIDLINE_POINTS.length; i++) { paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color_dull)); float xStart = (float) findNearestNumberPosition(mLogScaledX_values, MINOR_GRIDLINE_POINTS[i]); canvasBackground.drawLine(xStart, starty, xStart + 1, endy, paint); if (isShowLabels()) { paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color)); if (MINOR_GRIDLINE_POINTS[i] == 50 || MINOR_GRIDLINE_POINTS[i] == 500 || MINOR_GRIDLINE_POINTS[i] == 5000) canvasBackground.drawText(getFormattedLabel(MINOR_GRIDLINE_POINTS[i]), xStart - (getPixelDensity(mContext) * 30) / 480, endy - (getPixelDensity(mContext) * 10) / 480, paint); } } float[] Y_points = calculateGraphYAxis(); float div = mViewHeight / (Y_points.length - 1); //Level lines for (int i = 0; i < Y_points.length - 1; i++) { paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color_dull)); canvasBackground.drawLine(0, div * (i + 1), mViewWidth, (div * (i + 1)) + 1, paint); } //Level labels if (isShowLabels()) { for (int i = 0; i < Y_points.length; i++) { paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color)); if (i == 0) canvasBackground.drawText("dB", 0, (div * i) + (getPixelDensity(mContext) * 50) / 480, paint); else if (i == Y_points.length - 1) canvasBackground.drawText("", 0, div * i, paint); else canvasBackground.drawText("" + Math.round(Y_points[i]), 0, div * i, paint); } } BitmapDrawable drawable = new BitmapDrawable(mContext.getResources(), bitmapBackground); mDrawableBackground = drawable; //Plotting the curve points Bitmap bitmapForeground = Bitmap.createBitmap(mViewWidth, mViewHeight, Bitmap.Config.ARGB_8888); Canvas canvasForeground = new Canvas(bitmapForeground); Paint plotPaint = new Paint(); plotPaint.setStyle(Paint.Style.STROKE); plotPaint.setStrokeCap(Paint.Cap.ROUND); plotPaint.setStrokeWidth(PLOT_THICKNESS); plotPaint.setAntiAlias(true); plotPaint.setColor(ContextCompat.getColor(mContext, R.color.graph_plot_color)); for (int i = 0; i < X_values.length; i++) { // canvasForeground.drawCircle(i, mViewHeight - mPlotPoint[i], 2f, plotPaint); /*float startX, float startY, float stopX, float stopY, @NonNull Paint paint*/ float startX = (float) getGetPixelValueForX(X_values[i]); float startY = mViewHeight - getPixelValueFromdB((int) GAIN_MAX, (int) GAIN_MIN, mViewHeight, Y_values[i]); float stopX; float stopY; if (i == X_values.length - 1) { stopX = (float) getGetPixelValueForX(X_values[i]); stopY = mViewHeight - getPixelValueFromdB((int) GAIN_MAX, (int) GAIN_MIN, mViewHeight, Y_values[i]); } else { stopX = (float) getGetPixelValueForX(X_values[i + 1]); stopY = mViewHeight - getPixelValueFromdB((int) GAIN_MAX, (int) GAIN_MIN, mViewHeight, Y_values[i + 1]); } canvasForeground.drawLine(startX, startY, stopX, stopY, plotPaint); } BitmapDrawable drawableFore = new BitmapDrawable(mContext.getResources(), bitmapForeground); mDrawableForeground = drawableFore; return null; }
From source file:co.jlabs.cersei_retailer.zxingfragmentlib.BarCodeScannerFragment.java
/** * Superimpose a line for 1D or dots for 2D to highlight the key features of the barcode. * * @param barcode A bitmap of the captured image. * @param scaleFactor amount by which thumbnail was scaled * @param rawResult The decoded results which contains the points to draw. *///from w ww .j a v a2 s . c o m private void drawResultPoints(Bitmap barcode, float scaleFactor, Result rawResult) { ResultPoint[] points = rawResult.getResultPoints(); if (points != null && points.length > 0 && barcode != null) { 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], scaleFactor); } 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], scaleFactor); drawLine(canvas, paint, points[2], points[3], scaleFactor); } else { paint.setStrokeWidth(10.0f); for (ResultPoint point : points) { canvas.drawPoint(scaleFactor * point.getX(), scaleFactor * point.getY(), paint); } } if (isPortrait()) { Log.d(TAG, "rotating results canvas"); canvas.rotate(90); } } }
From source file:piuk.blockchain.android.ui.zxing.CaptureActivity.java
/** * Superimpose a line for 1D or dots for 2D to highlight the key features of the barcode. * * @param barcode A bitmap of the captured image. * @param rawResult The decoded results which contains the points to draw. *//* w w w . jav a 2 s. c o m*/ 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(ContextCompat.getColor(this, R.color.primary_blue_accent)); 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:tw.jwzhuang.ipcamviewer.devices.CaptureActivity.java
/** * Superimpose a line for 1D or dots for 2D to highlight the key features of * the barcode.// ww w .j a va 2 s .com * * @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_image_border)); paint.setStrokeWidth(3.0f); paint.setStyle(Paint.Style.STROKE); Rect border = new Rect(2, 2, barcode.getWidth() - 2, barcode.getHeight() - 2); canvas.drawRect(border, 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:org.odk.collect.android.activities.GeoShapeOsmMapActivity.java
private void overlayPointPathListener() { overlayEvents = new MapEventsOverlay(receive); polyline = new Polyline(); polyline.setColor(Color.RED); Paint paint = polyline.getPaint(); paint.setStrokeWidth(stroke_width); map.getOverlays().add(polyline);/*www . ja v a2 s .co m*/ map.getOverlays().add(overlayEvents); map.invalidate(); }
From source file:net.networksaremadeofstring.rhybudd.RhybuddDock.java
private void drawGaugeTitle(Canvas canvas, String Title) { Paint titlePaint = new Paint(); titlePaint.setStyle(Paint.Style.FILL_AND_STROKE); titlePaint.setColor(Color.LTGRAY);//0x9f004d0f titlePaint.setStrokeWidth(1);//0.005f titlePaint.setAntiAlias(true);// w w w.j a v a2 s .co m titlePaint.setTextSize(14); titlePaint.setTypeface(Typeface.createFromAsset(this.getAssets(), "fonts/chivo.ttf")); /*Path titlePath = new Path(); titlePath.addArc(new RectF(40, 90, 196, 155), -180.0f, -180.0f); canvas.drawTextOnPath(Title, titlePath, 0.0f,0.0f, titlePaint);*/ canvas.drawText(Title, 60, 160, titlePaint); }
From source file:com.nextgis.maplibui.fragment.ReorderedLayerView.java
/** * Draws a black border over the screenshot of the view passed in. *//*from w w w .jav a 2 s . c om*/ protected Bitmap getBitmapWithBorder(View v) { Bitmap bitmap = getBitmapFromView(v); Canvas canvas = new Canvas(bitmap); Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); canvas.drawBitmap(bitmap, 0, 0, null); Paint paint = new Paint(); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(LINE_THICKNESS); int accentColor = ControlHelper.getColor(getContext(), R.attr.colorAccent); paint.setColor(accentColor); canvas.drawRect(rect, paint); return bitmap; }
From source file:net.networksaremadeofstring.rhybudd.RhybuddDock.java
private void drawGaugeNeedle(Canvas canvas, int count, int Scale) { canvas.save(Canvas.MATRIX_SAVE_FLAG); float divisor = 360.0f / Scale; canvas.rotate((float) (divisor * count), 100, 100); //Inside/*w ww . j av a 2 s. co m*/ Paint needleInsidePaint = new Paint(); needleInsidePaint.setStyle(Paint.Style.FILL_AND_STROKE); needleInsidePaint.setColor(Color.WHITE); needleInsidePaint.setStrokeWidth(4); needleInsidePaint.setAntiAlias(true); Paint needleEdgePaint = new Paint(); needleEdgePaint.setStyle(Paint.Style.STROKE); needleEdgePaint.setColor(Color.DKGRAY); needleEdgePaint.setStrokeWidth(0.5f); needleEdgePaint.setAntiAlias(true); canvas.drawOval(new RectF(95, 95, 105, 105), needleInsidePaint); canvas.drawOval(new RectF(95, 96, 105, 105), needleEdgePaint); Path needleInside = new Path(); needleInside.moveTo(98, 98); needleInside.lineTo(100, 20); needleInside.lineTo(102, 102); canvas.drawPath(needleInside, needleInsidePaint); Path needleEdge = new Path(); needleInside.moveTo(99, 99); needleInside.lineTo(99, 19); needleInside.lineTo(103, 103); canvas.drawPath(needleEdge, needleEdgePaint); canvas.restore(); }