List of usage examples for android.graphics Paint setColor
public void setColor(@ColorInt int color)
From source file:de.uni_weimar.mheinz.androidtouchscope.display.ScopeView.java
private void initText(Paint paint, int height, int color, Paint.Align align) { paint.setColor(color); paint.setTextSize(height);/*from w w w. j ava 2s . c om*/ paint.setTextAlign(align); }
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);//from w w w . j a va 2 s . c om 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; } 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: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 w w . j a v a2 s. 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:com.smp.musicspeed.MainActivity.java
private void addBarGraphRenderers() { Paint paint = new Paint(); paint.setStrokeWidth(10.5f);/*from w w w . j a va2s.co m*/ paint.setAntiAlias(true); paint.setColor(Color.argb(255, 144, 202, 249)); BarGraphRenderer barGraphRendererBottom = new BarGraphRenderer(4, paint, false); visualizerView.addRenderer(barGraphRendererBottom); }
From source file:org.mariotaku.twidere.text.OriginalStatusSpan.java
@Override public void draw(final Canvas canvas, final CharSequence text, final int start, final int end, final float x, final int top, final int y, final int bottom, final Paint paint) { if (!(paint instanceof TextPaint)) return;/*from w w w.j av a2 s . c o m*/ final TextPaint tp = (TextPaint) paint; mBounds.left = x; mBounds.right = x + paint.measureText(text, start, end) + mPadding * 2; mBounds.top = top; mBounds.bottom = bottom; final int innerTextColor = TwidereColorUtils.getContrastYIQ(tp.linkColor, ThemeUtils.ACCENT_COLOR_THRESHOLD, mDarkLightColors[0], mDarkLightColors[1]); mPaint.setStyle(Paint.Style.FILL); mPaint.setColor(tp.linkColor); mBounds.inset(mPaint.getStrokeWidth() / 2, mPaint.getStrokeWidth() / 2); canvas.drawRoundRect(mBounds, mCornerRadius, mCornerRadius, mPaint); mBounds.inset(-mPaint.getStrokeWidth() / 2, -mPaint.getStrokeWidth() / 2); mPaint.setStyle(Paint.Style.STROKE); mPaint.setColor( ColorUtils.compositeColors(ColorUtils.setAlphaComponent(innerTextColor, 0x80), tp.linkColor)); mBounds.inset(mPaint.getStrokeWidth() / 2, mPaint.getStrokeWidth() / 2); canvas.drawRoundRect(mBounds, mCornerRadius, mCornerRadius, mPaint); paint.setColor(innerTextColor); canvas.drawText(text, start, end, x + mPadding, top + (bottom - top) / 2 - (paint.descent() + paint.ascent()) / 2, paint); }
From source file:com.nextgis.maplibui.overlay.EditLayerOverlay.java
protected Bitmap getMarker() { float scaledDensity = mContext.getResources().getDisplayMetrics().scaledDensity; int size = (int) (12 * scaledDensity); Bitmap marker = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(marker); Paint p = new Paint(Paint.ANTI_ALIAS_FLAG); //noinspection deprecation p.setColor(mContext.getResources().getColor(R.color.accent)); p.setAlpha(128);//from ww w . ja va 2s . c o m c.drawOval(new RectF(0, 0, size * 3 / 4, size * 3 / 4), p); return marker; }
From source file:com.diedrico.diedricoapp.PicMenuActivity.java
License:asdf
private PicAnalyzer.AsyncResponse analyzerFinished() { //We receive the important points and lines, we have to paint them return new PicAnalyzer.AsyncResponse() { @Override/*from w w w . java 2 s. co m*/ public void processFinish(List<PointVector> points, List<LineVector> lines, List<Double> planos) { //Set that the analyzer finished analyzerFinished = Boolean.TRUE; //Save the points in another var, if the user select that there are errors in the scan, he can select the points and lines manually allPoints = points; allLines = lines; //First we have to delete the short lines, we get the top module and then we discard the short ones Collections.sort(lines, new Comparator<LineVector>() { @Override public int compare(LineVector line1, LineVector line2) { return (line1.getModuleTwoDimensionalVector() - line2.getModuleTwoDimensionalVector() >= 0) ? -1 : 1; } }); landLine = lines.get(0); //This is the landLine double minModule = lines.get(0).getModuleTwoDimensionalVector() / 6; for (LineVector linevector : new ArrayList<>(lines)) { if (linevector.getModuleTwoDimensionalVector() < minModule) { lines.remove(linevector); } } pointDiedrico = new ArrayList<>(); lineDiedrico = new ArrayList<>(); ////Delete the wrong lines, the ones that don't have x's view and y's view respectively (cota and alejamiento). Then we differ between if it is a line(in diedrico) or a plane for (int j = 1; j < lines.size(); j++) { //Start in 1 because in 0 the line is the landLine LineVector line1 = lines.get(j); for (int k = 1; k < lines.size(); k++) { LineVector line2 = lines.get(k); if (line1.equals(line2)) { if (k == lines.size() - 1) { //The last line of the list lines.remove(k); j--; break; } continue; } if (line1.getLineYA() > lines.get(0).getYEquation(line1.getLineXA()) && line2.getLineYA() < lines.get(0).getYEquation(line1.getLineXA()) || line2.getLineYA() > lines.get(0).getYEquation(line1.getLineXA()) && line1.getLineYA() < lines.get(0).getYEquation(line1.getLineXA())) { if (line1.getLineXA() > line2.getLineXA() - 50 && line1.getLineXA() < line2.getLineXA() + 50) { //Has found a result, then we delete the points from the list, and put them in pointDiedricoList and we continue if (line1.getLineYA() > landLine.getLineYA()) {//We store the cota and alejamiento, the cota is the line over the landline lineDiedrico.add(new LineDiedrico(line1, line2)); } else { lineDiedrico.add(new LineDiedrico(line2, line1)); } lines.remove(k); lines.remove(j); j--; break; } } if (k == lines.size() - 1) { //The line doesn't have a couple lines.remove(j); j--; } } } //Also, boofcv finds a lot of useless points near the lines, so we have to delete them Iterator<LineVector> lineVectorIterator = lines.iterator(); while (lineVectorIterator.hasNext()) { LineVector lineVector = lineVectorIterator.next(); points = Stream.of(points) .filter((PointVector point) -> point .getPointY() < lineVector.getYEquation(point.getPointX()) - 15 || point.getPointY() > lineVector.getYEquation(point.getPointX()) + 15) .toList(); } //Then we have to delete the groups of points and take only one of them for (int j = 0; j < points.size(); j++) { PointVector point1 = points.get(j); for (int k = 0; k < points.size(); k++) { PointVector point2 = points.get(k); if (point1.equals(point2)) { continue; } if (point1.getPointX() > point2.getPointX() - 20 && point1.getPointX() < point2.getPointX() + 20 && point1.getPointY() > point2.getPointY() - 20 && point1.getPointY() < point2.getPointY() + 20) { //Has found a result, then we delete the points from the list points.remove(k); k--; } } } //Delete the wrong point, the ones that don't have x's view and y's view respectively (cota and alejamiento). The correct points will be in pointDiedrico for (int j = 0; j < points.size(); j++) { PointVector point1 = points.get(j); for (int k = 0; k < points.size(); k++) { PointVector point2 = points.get(k); if (point1.equals(point2)) { if (k == points.size() - 1) { //The last point of the list points.remove(k); j--; break; } continue; } if (point1.getPointY() > lines.get(0).getYEquation(point1.getPointX()) && point2.getPointY() < lines.get(0).getYEquation(point2.getPointX()) || point2.getPointY() > lines.get(0).getYEquation(point2.getPointX()) && point1.getPointY() < lines.get(0).getYEquation(point1.getPointX())) { if (point1.getPointX() > point2.getPointX() - 15 && point1.getPointX() < point2.getPointX() + 15) { //Has found a result, then we delete the points from the list, and put them in pointDiedricoList and we continue if (point1.getPointY() > lines.get(0).getYEquation(point1.getPointX())) { //We store the cota and alejamiento, the cota is the point over the landline pointDiedrico.add(new PointDiedrico(point1, point2)); } else { pointDiedrico.add(new PointDiedrico(point2, point1)); } points.remove(k); points.remove(j); j--; break; } } if (k == points.size() - 1) { //The point doesn't have a couple points.remove(j); j--; } } } int indexColors = 0; //Counter for the color array int[] colors = context.getResources().getIntArray(R.array.rainbow); Paint paintMax; paintMax = new Paint(); paintMax.setStyle(Paint.Style.FILL); Canvas canvas = new Canvas(thresholdingBitmap); for (int i = 0; i < pointDiedrico.size(); i++) { paintMax.setColor(colors[indexColors++]); if (indexColors >= colors.length) indexColors = 0; canvas.drawCircle(pointDiedrico.get(i).getX().getPointX(), pointDiedrico.get(i).getX().getPointY(), 3, paintMax); canvas.drawCircle(pointDiedrico.get(i).getY().getPointX(), pointDiedrico.get(i).getY().getPointY(), 3, paintMax); } //Paint the landLine with color blue paintMax.setColor(Color.BLUE); canvas.drawLine(lines.get(0).getLineXA(), lines.get(0).getLineYA(), lines.get(0).getLineXB(), lines.get(0).getLineYB(), paintMax); //Paint the interesting lines for (int i = 0; i < lineDiedrico.size(); i++) { paintMax.setColor(colors[indexColors++]); if (indexColors >= colors.length) indexColors = 0; canvas.drawLine(lineDiedrico.get(i).getX().getLineXA(), lineDiedrico.get(i).getX().getLineYA(), lineDiedrico.get(i).getX().getLineXB(), lineDiedrico.get(i).getX().getLineYB(), paintMax); canvas.drawLine(lineDiedrico.get(i).getY().getLineXA(), lineDiedrico.get(i).getY().getLineYA(), lineDiedrico.get(i).getY().getLineXB(), lineDiedrico.get(i).getY().getLineYB(), paintMax); } imageView.setImageBitmap(thresholdingBitmap); } }; }
From source file:com.android.launcher3.Utilities.java
/** * @param scale the scale to apply before drawing {@param icon} on the canvas */// w w w .j a v a 2 s.c om public static Bitmap createIconBitmap(Drawable icon, Context context, float scale) { synchronized (sCanvas) { final int iconBitmapSize = getIconBitmapSize(); int width = iconBitmapSize; int height = iconBitmapSize; if (icon instanceof PaintDrawable) { PaintDrawable painter = (PaintDrawable) icon; painter.setIntrinsicWidth(width); painter.setIntrinsicHeight(height); } else if (icon instanceof BitmapDrawable) { // Ensure the bitmap has a density. BitmapDrawable bitmapDrawable = (BitmapDrawable) icon; Bitmap bitmap = bitmapDrawable.getBitmap(); if (bitmap != null && bitmap.getDensity() == Bitmap.DENSITY_NONE) { bitmapDrawable.setTargetDensity(context.getResources().getDisplayMetrics()); } } int sourceWidth = icon.getIntrinsicWidth(); int sourceHeight = icon.getIntrinsicHeight(); if (sourceWidth > 0 && sourceHeight > 0) { // Scale the icon proportionally to the icon dimensions final float ratio = (float) sourceWidth / sourceHeight; if (sourceWidth > sourceHeight) { height = (int) (width / ratio); } else if (sourceHeight > sourceWidth) { width = (int) (height * ratio); } } // no intrinsic size --> use default size int textureWidth = iconBitmapSize; int textureHeight = iconBitmapSize; final Bitmap bitmap = Bitmap.createBitmap(textureWidth, textureHeight, Bitmap.Config.ARGB_8888); final Canvas canvas = sCanvas; canvas.setBitmap(bitmap); final int left = (textureWidth - width) / 2; final int top = (textureHeight - height) / 2; @SuppressWarnings("all") // suppress dead code warning final boolean debug = false; if (debug) { // draw a big box for the icon for debugging canvas.drawColor(sColors[sColorIndex]); if (++sColorIndex >= sColors.length) sColorIndex = 0; Paint debugPaint = new Paint(); debugPaint.setColor(0xffcccc00); canvas.drawRect(left, top, left + width, top + height, debugPaint); } sOldBounds.set(icon.getBounds()); icon.setBounds(left, top, left + width, top + height); canvas.save(Canvas.MATRIX_SAVE_FLAG); canvas.scale(scale, scale, textureWidth / 2, textureHeight / 2); icon.draw(canvas); canvas.restore(); icon.setBounds(sOldBounds); canvas.setBitmap(null); return bitmap; } }
From source file:com.olacabs.customer.ui.TrackRideActivity.java
private Bitmap m13911a(int i, String str) { int i2 = 50;/*from w w w . j a v a 2s .c o m*/ Typeface createFromAsset = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf"); int i3 = (int) getResources().getDisplayMetrics().scaledDensity; int i4 = i3 * 60; int i5 = i3 * 76; Config config = Config.ARGB_8888; if (i4 <= 0) { i4 = 50; } if (i5 > 0) { i2 = i5; } Bitmap createScaledBitmap = Bitmap .createScaledBitmap(BitmapFactoryInstrumentation.decodeResource(getResources(), i), i4, i2, true); Canvas canvas = new Canvas(createScaledBitmap); float f = (float) (i4 / 2); float f2 = (float) (i4 / 2); Paint paint = new Paint(1); paint.setColor(Color.parseColor("#d4db28")); paint.setStyle(Style.FILL); paint.setTextSize((float) (i3 * 18)); paint.setTypeface(createFromAsset); if (str.length() == 3) { canvas.drawText(str, f - ((float) (i3 * 15)), f2, paint); } else if (str.length() == 2) { canvas.drawText(str, f - ((float) (i3 * 10)), f2, paint); } else if (str.length() == 1) { canvas.drawText(str, f - ((float) (i3 * 6)), f2, paint); } paint.setTextSize((float) (i3 * 16)); canvas.drawText(" min ", f - ((float) (i3 * 18)), f2 + ((float) (i3 * 15)), paint); return createScaledBitmap; }
From source file:com.jjoe64.graphview.Viewport.java
/** * will be first called in order to draw * the canvas//w ww . ja v a 2 s .co m * Used to draw the background * * @param c canvas. */ public void drawFirst(Canvas c) { // draw background if (mBackgroundColor != Color.TRANSPARENT) { mPaint.setColor(mBackgroundColor); c.drawRect(mGraphView.getGraphContentLeft(), mGraphView.getGraphContentTop(), mGraphView.getGraphContentLeft() + mGraphView.getGraphContentWidth(), mGraphView.getGraphContentTop() + mGraphView.getGraphContentHeight(), mPaint); } if (mDrawBorder) { Paint p; if (mBorderPaint != null) { p = mBorderPaint; } else { p = mPaint; p.setColor(getBorderColor()); } c.drawLine(mGraphView.getGraphContentLeft(), mGraphView.getGraphContentTop(), mGraphView.getGraphContentLeft(), mGraphView.getGraphContentTop() + mGraphView.getGraphContentHeight(), p); c.drawLine(mGraphView.getGraphContentLeft(), mGraphView.getGraphContentTop() + mGraphView.getGraphContentHeight(), mGraphView.getGraphContentLeft() + mGraphView.getGraphContentWidth(), mGraphView.getGraphContentTop() + mGraphView.getGraphContentHeight(), p); // on the right side if we have second scale if (mGraphView.mSecondScale != null) { c.drawLine(mGraphView.getGraphContentLeft() + mGraphView.getGraphContentWidth(), mGraphView.getGraphContentTop(), mGraphView.getGraphContentLeft() + mGraphView.getGraphContentWidth(), mGraphView.getGraphContentTop() + mGraphView.getGraphContentHeight(), p); } } }