List of usage examples for android.graphics Paint Paint
public Paint(Paint paint)
From source file:Main.java
public static Bitmap createRoundedFramedImage(Drawable imageDrawable, int borderThickness, int color) { int size = Math.min(imageDrawable.getMinimumWidth(), imageDrawable.getMinimumHeight()); // Drawable imageDrawable = (image != null) ? new BitmapDrawable(image) : placeHolder; Bitmap output = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); RectF outerRect = new RectF(0, 0, size, size); float cornerRadius = size / 18f; Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(Color.RED);//from www .j av a2 s. com canvas.drawRoundRect(outerRect, cornerRadius, cornerRadius, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); imageDrawable.setBounds(0, 0, size, size); // Save the layer to apply the paint canvas.saveLayer(outerRect, paint, Canvas.ALL_SAVE_FLAG); imageDrawable.draw(canvas); canvas.restore(); // FRAMING THE PHOTO float border = size / 15f; // 1. Create offscreen bitmap link: http://www.youtube.com/watch?feature=player_detailpage&v=jF6Ad4GYjRU#t=1035s Bitmap framedOutput = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas framedCanvas = new Canvas(framedOutput); // End of Step 1 // Start - TODO IMPORTANT - this section shouldn't be included in the final code // It's needed here to differentiate step 2 (red) with the background color of the activity // It's should be commented out after the codes includes step 3 onwards // Paint squaredPaint = new Paint(Paint.ANTI_ALIAS_FLAG); // squaredPaint.setColor(Color.BLUE); // framedCanvas.drawRoundRect(outerRect, 0f, 0f, squaredPaint); // End // 2. Draw an opaque rounded rectangle link: // http://www.youtube.com/watch?feature=player_detailpage&v=jF6Ad4GYjRU#t=1044s RectF innerRect = new RectF(border, border, size - border, size - border); Paint innerPaint = new Paint(Paint.ANTI_ALIAS_FLAG); innerPaint.setColor(Color.RED); framedCanvas.drawRoundRect(innerRect, cornerRadius, cornerRadius, innerPaint); // 3. Set the Power Duff mode link: // http://www.youtube.com/watch?feature=player_detailpage&v=jF6Ad4GYjRU#t=1056s Paint outerPaint = new Paint(Paint.ANTI_ALIAS_FLAG); outerPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT)); // 4. Draw a translucent rounded rectangle link: // http://www.youtube.com/watch?feature=player_detailpage&v=jF6Ad4GYjRU outerPaint.setColor(color); framedCanvas.drawRoundRect(outerRect, cornerRadius, cornerRadius, outerPaint); // 5. Draw the frame on top of original bitmap canvas.drawBitmap(framedOutput, 0f, 0f, null); return output; }
From source file:android.support.design.widget.ShadowDrawableWrapper.java
public ShadowDrawableWrapper(Context context, Drawable content, float radius, float shadowSize, float maxShadowSize) { super(content); mShadowStartColor = ContextCompat.getColor(context, R.color.design_fab_shadow_start_color); mShadowMiddleColor = ContextCompat.getColor(context, R.color.design_fab_shadow_mid_color); mShadowEndColor = ContextCompat.getColor(context, R.color.design_fab_shadow_end_color); mCornerShadowPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG); mCornerShadowPaint.setStyle(Paint.Style.FILL); mCornerRadius = Math.round(radius); mContentBounds = new RectF(); mEdgeShadowPaint = new Paint(mCornerShadowPaint); mEdgeShadowPaint.setAntiAlias(false); setShadowSize(shadowSize, maxShadowSize); }
From source file:com.kabootar.GlassMemeGenerator.ImageOverlay.java
/** * Draws the given string centered, as big as possible, on either the top or * bottom 20% of the image given.//from w ww . j a v a2 s. com */ private static void drawStringCentered(Canvas g, String text, Bitmap image, boolean top, Context baseContext) throws InterruptedException { if (text == null) text = ""; int height = 0; int fontSize = MAX_FONT_SIZE; int maxCaptionHeight = image.getHeight() / 5; int maxLineWidth = image.getWidth() - SIDE_MARGIN * 2; String formattedString = ""; Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); Paint stkPaint = new Paint(Paint.ANTI_ALIAS_FLAG); stkPaint.setStyle(STROKE); stkPaint.setStrokeWidth(8); stkPaint.setColor(Color.BLACK); //Typeface tf = Typeface.create("Arial", Typeface.BOLD); Typeface tf = Typeface.createFromAsset(baseContext.getAssets(), "fonts/impact.ttf"); paint.setTypeface(tf); stkPaint.setTypeface(tf); do { paint.setTextSize(fontSize); // first inject newlines into the text to wrap properly StringBuilder sb = new StringBuilder(); int left = 0; int right = text.length() - 1; while (left < right) { String substring = text.substring(left, right + 1); Rect stringBounds = new Rect(); paint.getTextBounds(substring, 0, substring.length(), stringBounds); while (stringBounds.width() > maxLineWidth) { if (Thread.currentThread().isInterrupted()) { throw new InterruptedException(); } // look for a space to break the line boolean spaceFound = false; for (int i = right; i > left; i--) { if (text.charAt(i) == ' ') { right = i - 1; spaceFound = true; break; } } substring = text.substring(left, right + 1); paint.getTextBounds(substring, 0, substring.length(), stringBounds); // If we're down to a single word and we are still too wide, // the font is just too big. if (!spaceFound && stringBounds.width() > maxLineWidth) { break; } } sb.append(substring).append("\n"); left = right + 2; right = text.length() - 1; } formattedString = sb.toString(); // now determine if this font size is too big for the allowed height height = 0; for (String line : formattedString.split("\n")) { Rect stringBounds = new Rect(); paint.getTextBounds(line, 0, line.length(), stringBounds); height += stringBounds.height(); } fontSize--; } while (height > maxCaptionHeight); // draw the string one line at a time int y = 0; if (top) { y = TOP_MARGIN; } else { y = image.getHeight() - height - BOTTOM_MARGIN; } for (String line : formattedString.split("\n")) { // Draw each string twice for a shadow effect Rect stringBounds = new Rect(); paint.getTextBounds(line, 0, line.length(), stringBounds); //paint.setColor(Color.BLACK); //g.drawText(line, (image.getWidth() - (int) stringBounds.width()) / 2 + 2, y + stringBounds.height() + 2, paint); paint.setColor(Color.WHITE); g.drawText(line, (image.getWidth() - (int) stringBounds.width()) / 2, y + stringBounds.height(), paint); //stroke Rect strokeBounds = new Rect(); stkPaint.setTextSize(fontSize); stkPaint.getTextBounds(line, 0, line.length(), strokeBounds); g.drawText(line, (image.getWidth() - (int) strokeBounds.width()) / 2, y + strokeBounds.height(), stkPaint); y += stringBounds.height(); } }
From source file:com.cssweb.android.view.FTrendView.java
public void drawChart(Canvas canvas) throws JSONException { paint = new Paint(Paint.ANTI_ALIAS_FLAG); // paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(1);//from w ww . j a va 2 s. c om tPaint = new Paint(); tPaint.setStyle(Paint.Style.STROKE); tPaint.setTypeface(Typeface.DEFAULT_BOLD); tPaint.setAntiAlias(true); // dataPaint = new Paint(Paint.ANTI_ALIAS_FLAG); // dataPaint.setStyle(Paint.Style.STROKE); dataPaint.setStrokeWidth(3); tPaint.setTextSize(dTextSize); axisLabelHeight = Font.getFontHeight(dTextSize); axisLabelWidth = (int) tPaint.measureText("0.00000") + offSet; klineWidth = width - axisLabelWidth; klineHeight = height - axisLabelHeight * 2 - iSLowerScreen; klineX = axisLabelWidth; klineY = axisLabelHeight; SPACE = Arith.div(klineWidth, count); //klineWidth/count; scale = klineHeight / (highPrice - lowPrice); // double ratio = (highPrice - lowPrice) / rowNum; // rowHeight = klineHeight / rowNum; colWeight = klineWidth / colNum; tPaint.setColor(GlobalColor.colorLabelName); tPaint.setTextAlign(Paint.Align.LEFT); /** * */ canvas.drawText(":" + quoteData.getJSONArray(isTrackNumber).getString(0), axisLabelWidth, axisLabelHeight - 5, tPaint); canvas.drawText(":" + quoteData.getJSONArray(isTrackNumber).getDouble(3), axisLabelWidth + width / 2, axisLabelHeight - 5, tPaint); paint.setColor(GlobalColor.clrGrayLine); /** * */ tPaint.setTextAlign(Paint.Align.RIGHT); for (int i = 0; i <= rowNum; i++) { if (i == 0 || i == rowNum) { canvas.drawLine(klineX, klineY + rowHeight * i, klineX + klineWidth, klineY + rowHeight * i, paint); } else { Graphics.drawDashline(canvas, klineX, klineY + rowHeight * i, klineX + klineWidth, klineY + rowHeight * i, paint); } if (i == 0) { canvas.drawText(Utils.dataFormation(highPrice, 3), klineX, klineY + rowHeight * i + axisLabelHeight / 2, tPaint); } else if (i == rowNum) { canvas.drawText(Utils.dataFormation(lowPrice, 3), klineX, klineY + rowHeight * i, tPaint); } else { double AxisLabelPrice = highPrice - ratio * i; canvas.drawText(Utils.dataFormation(AxisLabelPrice, 3), klineX, klineY + rowHeight * i + axisLabelHeight / 2, tPaint); } } /** * */ for (int i = 0; i <= colNum; i++) { if (i == 0) { canvas.drawLine(klineX, klineY, klineX, klineY + klineHeight, paint); } else if (i == colNum) { canvas.drawLine(width - 1, klineY, width - 1, klineY + klineHeight, paint); } else { Graphics.drawDashline(canvas, klineX + colWeight * i, klineY, klineX + colWeight * i, klineY + klineHeight, paint); } } /** * ? */ double x1 = 0; double y1 = 0; double x2 = 0; double y2 = 0; double temp = 0; double tHeight = 0; dataPaint.setColor(GlobalColor.colorStockName); dataPaint.setStrokeWidth(3); for (int i = begin; i < (begin + count); i++) { temp = quoteData.getJSONArray(i).getDouble(3); if (i - begin == 0) { x1 = klineX + SPACE * (i - begin); x2 = klineX + SPACE * (i - begin + 1); tHeight = (temp - lowPrice) * scale; // tHeight = ( - ) * y1 = axisLabelHeight + klineHeight - tHeight; // - tHeight y2 = axisLabelHeight + klineHeight - tHeight; } else { canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, dataPaint); x1 = x2; x2 = klineX + SPACE * (i - begin + 1); tHeight = (temp - lowPrice) * scale; y1 = y2; y2 = axisLabelHeight + klineHeight - tHeight; } } /** * */ tPaint.setColor(GlobalColor.colorLabelName); tPaint.setTextAlign(Paint.Align.LEFT); canvas.drawText(quoteData.getJSONArray(begin).getString(0), axisLabelWidth, klineHeight + axisLabelHeight * 2 - 5, tPaint); canvas.drawText(quoteData.getJSONArray(begin + count - 1).getString(0), (float) (width - tPaint.measureText(quoteData.getJSONArray(begin + count - 1).getString(0))), klineHeight + axisLabelHeight * 2 - 5, tPaint); /** * */ if (isTrackStatus) { canvas.save(); //?? paint.setColor(GlobalColor.colorLine); canvas.drawLine(trackLineV, axisLabelHeight, trackLineV, klineHeight + axisLabelHeight, paint); canvas.restore(); } }
From source file:com.crs4.roodin.moduletester.CustomView.java
/** * @param canvas//from w w w.ja v a 2 s .c o m */ private void drawRadar(Canvas canvas) { Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(Color.RED); paint.setAlpha(100); float rotation = currentRotation; //gRotationZ_deg + initialMapRotation; for (int i = -35; i < 35; i = i + 2) { float arrowX1 = (float) (translateX - Math.sin(Math.toRadians(rotation + i)) * 45); float arrowY1 = (float) (translateY - Math.cos(Math.toRadians(rotation + i)) * 45); canvas.drawLine(translateX, translateY, arrowX1, arrowY1, paint); } paint.setAlpha(100); paint.setColor(Color.RED); canvas.drawCircle(translateX, translateY, 7, paint); paint.setColor(Color.YELLOW); canvas.drawCircle(translateX, translateY, 6, paint); paint.setColor(Color.RED); canvas.drawCircle(translateX, translateY, 1, paint); }
From source file:com.google.android.apps.santatracker.doodles.tilt.ColoredRectangleActor.java
public ColoredRectangleActor(Vector2D position, Vector2D dimens, String type) { super(position, Vector2D.get()); this.dimens = dimens; this.type = type; this.zIndex = -1; if (type.equals(FAIRWAY_GREEN)) { this.zIndex = -2; }//from w w w . j av a 2 s . c o m selectedDirection = Direction.NONE; paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(TYPE_TO_COLOR_MAP.get(type)); paint.setStyle(Style.FILL); midpointPaint = new Paint(Paint.ANTI_ALIAS_FLAG); midpointPaint.setColor(Color.WHITE); updateExtents(); }
From source file:com.nextgis.maplibui.formcontrol.Sign.java
protected void init() { //1. get clean int[] attrs = new int[] { R.attr.ic_clear }; TypedArray ta = getContext().obtainStyledAttributes(attrs); mCleanImage = ta.getDrawable(0);/*from w ww . ja v a2s. com*/ ta.recycle(); mClearBuff = (int) (getContext().getResources().getDisplayMetrics().density * CLEAR_BUFF_DP); mClearImageSize = (int) (getContext().getResources().getDisplayMetrics().density * CLEAR_IMAGE_SIZE_DP); mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeWidth(3); mPaint.setDither(true); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); boolean bDark = PreferenceManager.getDefaultSharedPreferences(getContext()) .getString(SettingsConstantsUI.KEY_PREF_THEME, "light").equals("dark"); if (bDark) mPaint.setColor(Color.WHITE); else mPaint.setColor(Color.BLACK); mPath = new Path(); mPaths.add(mPath); }
From source file:com.crs4.roodin.moduletester.CustomView.java
/** * @return/*from www .j a v a2 s. c o m*/ */ private Picture drawBarreds() { Picture pictureContent = new Picture(); Canvas canvasContent = pictureContent.beginRecording(getWidth(), getHeight()); Paint paintContent = new Paint(Paint.ANTI_ALIAS_FLAG); canvasContent.save(); paintContent.setColor(Color.BLUE); paintContent.setStyle(Style.STROKE); paintContent.setStrokeWidth(2); paintContent.setAlpha(50); try { cellDimension = block.getCellDimension(); JSONArray barred = block.getBarred(); int rows = block.getShape().getInt(0); int cols = block.getShape().getInt(1); // this code draws all the shape: for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { canvasContent.drawRect(cellDimension * j, cellDimension * i, cellDimension * j + cellDimension, cellDimension * i + cellDimension, paintContent); } } paintContent.setColor(Color.RED); paintContent.setStyle(Style.FILL); paintContent.setAlpha(50); for (int i = 0; i < barred.length(); i++) { JSONArray pos = barred.getJSONArray(i); canvasContent.drawRect(cellDimension * pos.getInt(1), cellDimension * pos.getInt(0), cellDimension * pos.getInt(1) + cellDimension, cellDimension * pos.getInt(0) + cellDimension, paintContent); } this.paintBoxList(canvasContent, paintContent); } catch (JSONException e) { e.printStackTrace(); Log.e("Exception in DrawComponents.drawBarreds", "" + e.getMessage()); } canvasContent.restore(); pictureContent.endRecording(); return pictureContent; }
From source file:com.nextgis.maplibui.util.ControlHelper.java
public static Drawable getIconByVectorType(Context context, int geometryType, int color, int defaultIcon, boolean syncable) { int drawableId; switch (geometryType) { case GTPoint: drawableId = R.drawable.ic_type_point; break;/*from www.j av a 2s . c om*/ case GTMultiPoint: drawableId = R.drawable.ic_type_multipoint; break; case GTLineString: drawableId = R.drawable.ic_type_line; break; case GTMultiLineString: drawableId = R.drawable.ic_type_multiline; break; case GTPolygon: drawableId = R.drawable.ic_type_polygon; break; case GTMultiPolygon: drawableId = R.drawable.ic_type_multipolygon; break; default: return ContextCompat.getDrawable(context, defaultIcon); } BitmapDrawable icon = (BitmapDrawable) ContextCompat.getDrawable(context, drawableId); if (icon != null) { Bitmap src = icon.getBitmap(); Bitmap bitmap = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig()); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); ColorFilter filter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP); paint.setColorFilter(filter); canvas.drawBitmap(src, 0, 0, paint); if (syncable) { int syncIconId = isDarkTheme(context) ? R.drawable.ic_action_refresh_dark : R.drawable.ic_action_refresh_light; ; src = BitmapFactory.decodeResource(context.getResources(), syncIconId); src = Bitmap.createScaledBitmap(src, bitmap.getWidth() / 2, bitmap.getWidth() / 2, true); canvas.drawBitmap(src, bitmap.getWidth() - bitmap.getWidth() / 2, bitmap.getWidth() - bitmap.getWidth() / 2, new Paint()); } icon = new BitmapDrawable(context.getResources(), bitmap); } return icon; }