List of usage examples for android.graphics Paint setColor
public void setColor(@ColorInt int color)
From source file:de.madvertise.android.sdk.MadView.java
/** * Draw the ad background for a text banner * /*from w ww . ja v a 2s . co m*/ * @param canvas * @param rectangle * @param backgroundColor * @param textColor */ private void drawTextBannerBackground(Canvas canvas, Rect rectangle, int backgroundColor, int shineColor) { Paint paint = new Paint(); paint.setColor(backgroundColor); paint.setAntiAlias(true); canvas.drawRect(rectangle, paint); int upperColor = Color.argb(GRADIENT_TOP_ALPHA, Color.red(shineColor), Color.green(shineColor), Color.blue(shineColor)); int[] gradientColors = { upperColor, shineColor }; GradientDrawable gradientDrawable = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, gradientColors); int stop = (int) (rectangle.height() * GRADIENT_STOP) + rectangle.top; gradientDrawable.setBounds(rectangle.left, rectangle.top, rectangle.right, stop); gradientDrawable.draw(canvas); Rect shadowRect = new Rect(rectangle.left, stop, rectangle.right, rectangle.bottom); Paint shadowPaint = new Paint(); shadowPaint.setColor(shineColor); canvas.drawRect(shadowRect, shadowPaint); }
From source file:com.github.kubatatami.RoundedView.java
private void drawText(Canvas canvas) { Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextSize(getResources().getDimension(R.dimen.item_circle_text_size)); Rect areaRect = new Rect(0, 0, canvas.getWidth(), canvas.getHeight()); RectF bounds = new RectF(areaRect); bounds.right = paint.measureText(text, 0, text.length()); bounds.bottom = paint.descent() - paint.ascent(); bounds.left += (areaRect.width() - bounds.right) / 2.0f; bounds.top += (areaRect.height() - bounds.bottom) / 2.0f; paint.setColor(Color.WHITE); canvas.drawText(text, bounds.left, bounds.top - paint.ascent(), paint); }
From source file:com.codetroopers.shakemytours.ui.activity.TripActivity.java
private Bitmap createMarker(int radius, int strokeWidth, String letter, int strokeColor, int backgroundColor) { int width = (radius * 2) + (strokeWidth * 2); Bitmap marker = Bitmap.createBitmap(width, width, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(marker); Paint strokePaint = new Paint(Paint.ANTI_ALIAS_FLAG); strokePaint.setColor(strokeColor); strokePaint.setShadowLayer(strokeWidth, 1.0f, 1.0f, Color.BLACK); canvas.drawCircle(width / 2, width / 2, radius, strokePaint); Paint backgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG); backgroundPaint.setColor(backgroundColor); canvas.drawCircle(width / 2, width / 2, radius - strokeWidth, backgroundPaint); if (letter != null) { Rect result = new Rect(); Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG); textPaint.setTextAlign(Paint.Align.CENTER); textPaint.setTextSize(getResources().getDimensionPixelSize(R.dimen.map_marker_text_size)); textPaint.setColor(strokeColor); textPaint.getTextBounds(letter, 0, letter.length(), result); int yOffset = result.height() / 2; canvas.drawText(letter, width / 2, (width / 2) + yOffset, textPaint); }/* www . j a va2s .c o m*/ return marker; }
From source file:com.mn.tiger.widget.viewpager.TGPagerSlidingTabStrip.java
/** * //from w w w .j a v a2 s .c o m * @param canvas */ protected void onDrawIndicator(Canvas canvas, Paint rectPaint, float lineLeft, float lineRight) { // draw indicator line rectPaint.setColor(indicatorColor); canvas.drawRect(lineLeft, getHeight() - indicatorHeight, lineRight, getHeight(), rectPaint); }
From source file:com.forrestguice.suntimeswidget.LightMapView.java
private void drawPoint(Calendar calendar, int radius, Canvas c, Paint p) { if (calendar != null) { int w = c.getWidth(); int h = c.getHeight(); double minute = calendar.get(Calendar.HOUR_OF_DAY) * 60 + calendar.get(Calendar.MINUTE); int x = (int) Math.round((minute / MINUTES_IN_DAY) * w); int y = h / 2; p.setStyle(Paint.Style.FILL); p.setColor(colorPointFill); c.drawCircle(x, y, radius, p);/*from w w w .j av a2s.c o m*/ p.setStyle(Paint.Style.STROKE); p.setStrokeWidth(pointStrokeWidth); p.setColor(colorPointStroke); c.drawCircle(x, y, radius, p); } }
From source file:sandra.examples.oneshot.voicelaunch.VoiceLaunch.java
/** * Writes a text in a drawable. We will use this method to show the similarity value in the seekbar * See stackoverflow http://stackoverflow.com/questions/6264543/draw-on-drawable?rq=1 */// www.j a va2 s.c o m @SuppressWarnings("deprecation") private BitmapDrawable writeOnDrawable(int drawableId, String text) { Bitmap bm = BitmapFactory.decodeResource(getResources(), drawableId).copy(Bitmap.Config.ARGB_8888, true); Paint paint = new Paint(); paint.setStyle(Style.FILL); paint.setColor(Color.BLACK); paint.setTextSize(10); Canvas canvas = new Canvas(bm); canvas.drawText(text, bm.getWidth() / 4, bm.getHeight() / 2, paint); return new BitmapDrawable(bm); }
From source file:ggikko.me.steppertest.stepper.RoundedView.java
private void drawText(Canvas canvas) { Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextSize(getResources().getDimension(R.dimen.item_circle_text_size)); Rect areaRect = new Rect(0, 0, canvas.getWidth(), canvas.getHeight()); RectF bounds = new RectF(areaRect); bounds.right = paint.measureText(text, 0, text.length()); bounds.bottom = paint.descent() - paint.ascent(); bounds.left += (areaRect.width() - bounds.right) / 2.0f; bounds.top += (areaRect.height() - bounds.bottom) / 2.0f; paint.setColor(Color.WHITE); canvas.drawText(text, bounds.left, bounds.top - paint.ascent(), paint); }
From source file:github.daneren2005.dsub.util.ImageLoader.java
private Bitmap createUnknownImage(int size, int primaryColor, String topText, String bottomText) { Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Paint color = new Paint(); color.setColor(primaryColor); canvas.drawRect(0, 0, size, size * 2.0f / 3.0f, color); color.setShader(new LinearGradient(0, 0, 0, size / 3.0f, Color.rgb(82, 82, 82), Color.BLACK, Shader.TileMode.MIRROR));//from w w w . j a v a 2 s. c o m canvas.drawRect(0, size * 2.0f / 3.0f, size, size, color); if (topText != null || bottomText != null) { Paint font = new Paint(); font.setFlags(Paint.ANTI_ALIAS_FLAG); font.setColor(Color.WHITE); font.setTextSize(3.0f + size * 0.07f); if (topText != null) { canvas.drawText(topText, size * 0.05f, size * 0.6f, font); } if (bottomText != null) { canvas.drawText(bottomText, size * 0.05f, size * 0.8f, font); } } return bitmap; }
From source file:com.semfapp.adamdilger.semf.Take5PdfDocument.java
/** * Draw Section titles for sec 1 and 2/* w w w. j a va 2 s .co m*/ * @param xLoc left location * @param yLoc top location * @param width size from xLoc, to middle of end circle * @param string header string * @param index header number */ private void drawHeader1(int xLoc, int yLoc, int width, String string, int index) { int RADIUS = 14; float INNER_RADIUS = 13; int centre = yLoc + RADIUS; width = xLoc + width; int middle = width - 54; Paint paint = new Paint(); Paint paintW = new Paint(); paintW.setTypeface(impact); paint.setTypeface(impact); paintW.setColor(Color.WHITE); paintW.setTextSize(FONT12); paint.setTextSize(FONT12); can.drawCircle(xLoc + RADIUS, centre, RADIUS, paint); can.drawRect(xLoc + RADIUS, centre - RADIUS, width, centre + RADIUS, paint); can.drawCircle(width, centre, RADIUS, paint); can.drawCircle(xLoc + RADIUS, centre, INNER_RADIUS, paintW); can.drawCircle(width, centre, INNER_RADIUS, paintW); can.drawRect(middle, centre - INNER_RADIUS, width, centre + INNER_RADIUS, paintW); can.drawCircle(middle, centre, RADIUS, paint); can.drawText(string, xLoc + 31, centre + 5, paintW); can.drawText("YES NO", width - 35, centre + 5, paint); paint.setTextSize(FONT16); can.drawText(String.valueOf(index), xLoc + RADIUS - 4, centre + 6, paint); }
From source file:app.axe.imooc.zxing.app.CaptureActivity.java
/** * Superimpose a line for 1D or dots for 2D to highlight the key features of * the barcode.//from w ww .ja va2 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().equals(BarcodeFormat.UPC_A)) || (rawResult.getBarcodeFormat().equals(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); } } } }