List of usage examples for android.graphics Paint setAntiAlias
public void setAntiAlias(boolean aa)
From source file:com.cssweb.android.view.PriceView.java
public void drawIndex(Canvas canvas) { //canvas.restore(); Paint paint = this.mPaint; paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true); tPaint.setColor(GlobalColor.clrLine); tPaint.setStyle(Paint.Style.STROKE); tPaint.setStrokeWidth(1);//from ww w.j av a 2 s.c o m this.x = 0; this.y = 0; startX = x + tips / 2; endX = width - tips / 2; canvas.drawRect(startX, DY + DY / 4, endX, height - DY / 4, tPaint); canvas.drawLine(startX, DY * 7 + DY / 2, endX, DY * 7 + DY / 2, tPaint); canvas.drawLine(startX, DY * 18 + DY / 4, endX, DY * 18 + DY / 4, tPaint); if (quoteData != null) { try { JSONArray jArr = quoteData.getJSONArray("data"); JSONObject jo = jArr.getJSONObject(0); double zrsp = jo.getDouble("zrsp"); paint.setTextSize(mTextSize); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.translate(0, DY * 2); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("???", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY * 1.5f); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("??", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("??", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(width, -DY * 15.5f); paint.setTextAlign(Paint.Align.RIGHT); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getDouble("a"), true), x - tips, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getDouble("b"), true), x - tips, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getDouble("govbond"), true), x - tips, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getDouble("fund"), true), x - tips, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getDouble("warrant"), true), x - tips, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getDouble("bond"), true), x - tips, y, paint); double zjcj = jo.getDouble("zjcj"); setColor(paint, zjcj, zrsp); canvas.translate(0, DY * 1.5f); canvas.drawText(Utils.dataFormation(zjcj, stockdigit), x - tips, y, paint); canvas.translate(0, DY); double jrkp = jo.getDouble("jrkp"); setColor(paint, jrkp, zrsp); canvas.drawText(Utils.dataFormation(jrkp, stockdigit), x - tips, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorLabelName); canvas.drawText(Utils.dataFormation(zrsp, stockdigit), x - tips, y, paint); double zhangd = jo.getDouble("zd"); if (zhangd < 0) { paint.setColor(GlobalColor.colorPriceDown); } else if (zhangd > 0) { paint.setColor(GlobalColor.colorpriceUp); } else { paint.setColor(GlobalColor.colorPriceEqual); } canvas.translate(0, DY); String zhangdie = Utils.dataFormation(zhangd, stockdigit); if (zhangdie.equals("-")) canvas.drawText("", x - tips, y, paint); else canvas.drawText(zhangdie, x - tips, y, paint); double zhangf = jo.getDouble("zf"); if (zhangf < 0) { paint.setColor(GlobalColor.colorPriceDown); } else if (zhangf > 0) { paint.setColor(GlobalColor.colorpriceUp); } else { paint.setColor(GlobalColor.colorPriceEqual); } canvas.translate(0, DY); String zhangfu = Utils.dataFormation(zhangf * 100, stockdigit); if (zhangfu.equals("-")) canvas.drawText("", x - tips, y, paint); else canvas.drawText(zhangfu + "%", x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("amp") * 100, 1) + "%", x - tips, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjsl"), true), x - tips, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), true), x - tips, y, paint); canvas.translate(0, DY); double zg = jo.getDouble("zgcj"); setColor(paint, zg, zrsp); canvas.drawText(Utils.dataFormation(zg, stockdigit), x - tips, y, paint); canvas.translate(0, DY); double zd = jo.getDouble("zdcj"); setColor(paint, zd, zrsp); canvas.drawText(Utils.dataFormation(zd, stockdigit), x - tips, y, paint); canvas.translate(-width, DY * 1.7f); paint.setTextSize(mTextSize); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("", x + tips, y, paint); paint.setTextAlign(Paint.Align.RIGHT); paint.setColor(GlobalColor.colorpriceUp); canvas.translate(width / 2, 0); canvas.drawText(String.valueOf(jo.getInt("zj")), x, y, paint); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("", x + tips, y, paint); paint.setTextAlign(Paint.Align.RIGHT); paint.setColor(GlobalColor.colorPriceDown); canvas.translate(width / 2, 0); canvas.drawText(String.valueOf(jo.getInt("dj")), x - tips, y, paint); } catch (JSONException e) { Log.e(TAG, e.toString()); } } }
From source file:com.android.gallery3d.filtershow.imageshow.ImageShow.java
public void drawCompareImage(Canvas canvas, Bitmap image) { MasterImage master = MasterImage.getImage(); boolean showsOriginal = master.showsOriginal(); if (!showsOriginal && !mTouchShowOriginal) return;//from www . j a v a 2s.c om canvas.save(); if (image != null) { if (mShowOriginalDirection == 0) { if (Math.abs(mTouch.y - mTouchDown.y) > Math.abs(mTouch.x - mTouchDown.x)) { mShowOriginalDirection = UNVEIL_VERTICAL; } else { mShowOriginalDirection = UNVEIL_HORIZONTAL; } } int px = 0; int py = 0; if (mShowOriginalDirection == UNVEIL_VERTICAL) { px = mImageBounds.width(); py = mTouch.y - mImageBounds.top; } else { px = mTouch.x - mImageBounds.left; py = mImageBounds.height(); if (showsOriginal) { px = mImageBounds.width(); } } Rect d = new Rect(mImageBounds.left, mImageBounds.top, mImageBounds.left + px, mImageBounds.top + py); if (mShowOriginalDirection == UNVEIL_HORIZONTAL) { if (mTouchDown.x - mTouch.x > 0) { d.set(mImageBounds.left + px, mImageBounds.top, mImageBounds.right, mImageBounds.top + py); } } else { if (mTouchDown.y - mTouch.y > 0) { d.set(mImageBounds.left, mImageBounds.top + py, mImageBounds.left + px, mImageBounds.bottom); } } canvas.clipRect(d); Matrix m = master.computeImageToScreen(image, 0, false); canvas.drawBitmap(image, m, mPaint); Paint paint = new Paint(); paint.setColor(Color.BLACK); paint.setStrokeWidth(3); if (mShowOriginalDirection == UNVEIL_VERTICAL) { canvas.drawLine(mImageBounds.left, mTouch.y, mImageBounds.right, mTouch.y, paint); } else { canvas.drawLine(mTouch.x, mImageBounds.top, mTouch.x, mImageBounds.bottom, paint); } Rect bounds = new Rect(); paint.setAntiAlias(true); paint.setTextSize(mOriginalTextSize); paint.getTextBounds(mOriginalText, 0, mOriginalText.length(), bounds); paint.setColor(Color.BLACK); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(3); canvas.drawText(mOriginalText, mImageBounds.left + mOriginalTextMargin, mImageBounds.top + bounds.height() + mOriginalTextMargin, paint); paint.setStyle(Paint.Style.FILL); paint.setStrokeWidth(1); paint.setColor(Color.WHITE); canvas.drawText(mOriginalText, mImageBounds.left + mOriginalTextMargin, mImageBounds.top + bounds.height() + mOriginalTextMargin, paint); } canvas.restore(); }
From source file:com.simadanesh.isatis.ScreenSlideActivity.java
void makeBMP(CalculationResult res) { Bitmap bmp = Bitmap.createBitmap(400, 800, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmp); //canvas.drawARGB(155, 253, 255, 253); canvas.drawARGB(255, 255, 255, 255); Paint p = new Paint(); p.setTypeface(Utility.getNazaninFont()); p.setTextSize(25);//from w w w.jav a 2s.co m p.setAntiAlias(true); int y = 20; Drawable d = getResources().getDrawable(R.drawable.abfa); d.setBounds(100, 10, 300, 210); d.draw(canvas); p.setTextAlign(Paint.Align.CENTER); y += 210; canvas.drawText(" ? ", 200, y, p); y += 40; canvas.drawText(" ", 200, y, p); y += 40; canvas.drawText(" ", 200, y, p); y += 40; canvas.drawText(":" + Utility.NowDate(), 200, y, p); y += 40; canvas.drawText("___________________________", 200, y, p); y += 40; canvas.drawText(" :" + res.CustomerNumber, 200, y, p); y += 40; canvas.drawText(" :" + res.Title, 200, y, p); y += 40; canvas.drawText(" :" + Seprate3(res.BillAmount), 200, y, p); y += 40; canvas.drawText(" :" + Seprate3(res.PreviousDebt), 200, y, p); y += 40; Paint p1 = new Paint(); p1.setTypeface(Utility.getNazaninFont()); p1.setARGB(255, 0, 0, 0); p1.setAntiAlias(true); p1.setStrokeWidth(40); p1.setStyle(Paint.Style.STROKE); canvas.drawLine(10, y, 390, y, p1); p.setARGB(255, 255, 255, 255); canvas.drawText(" :" + Seprate3(res.TotalAmount) + " ", 200, y, p); p.setARGB(255, 0, 0, 0); y += 40; canvas.drawText("__________________________", 200, y, p); y += 40; canvas.drawText(" :" + res.BillIdentifier, 200, y, p); y += 40; canvas.drawText(" :" + res.PaymentIdentifier, 200, y, p); /* Path pth = new Path(); pth.addArc(10, 20, 390, 790, 0, 360); p.setColor(Color.argb(20, 10, 10, 10)); p.setTextSize(30); String watermark = ""; for (int i = 0; i < 15; i++) { watermark += " "; } canvas.drawTextOnPath(watermark, pth, 0, 0, p);*/ //File file = new File(getCacheDir()+ "/billing.png"); File file = new File("/sdcard/billing.png"); FileOutputStream outfile; try { outfile = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.PNG, 100, outfile); Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "image/*"); startActivity(intent); } catch (Exception ex) { Log.e("error", ex.toString()); } }
From source file:com.simadanesh.isatis.ScreenSlideActivity.java
void makePDF(CalculationResult res) { PdfDocument doc = new PdfDocument(); PdfDocument.PageInfo inf = new PdfDocument.PageInfo.Builder(400, 800, 1).create(); PdfDocument.Page page = doc.startPage(inf); Canvas canvas = page.getCanvas(); //canvas.drawARGB(155, 253, 255, 253); canvas.drawARGB(255, 255, 255, 255); Paint p = new Paint(); p.setTypeface(Utility.getNazaninFont()); p.setTextSize(25);//from w ww. j ava2 s .c o m p.setAntiAlias(true); int y = 20; Drawable d = getResources().getDrawable(R.drawable.abfa); d.setBounds(100, 10, 300, 210); d.draw(canvas); p.setTextAlign(Paint.Align.CENTER); y += 210; canvas.drawText(" ? ", 200, y, p); y += 40; canvas.drawText(" ", 200, y, p); y += 40; canvas.drawText(" ", 200, y, p); y += 40; canvas.drawText(":" + Utility.NowDate(), 200, y, p); y += 40; canvas.drawText("___________________________", 200, y, p); y += 40; canvas.drawText(" :" + res.CustomerNumber, 200, y, p); y += 40; canvas.drawText(" :" + res.Title, 200, y, p); y += 40; canvas.drawText(" :" + Seprate3(res.BillAmount), 200, y, p); y += 40; canvas.drawText(" :" + Seprate3(res.PreviousDebt), 200, y, p); y += 40; Paint p1 = new Paint(); p1.setTypeface(Utility.getNazaninFont()); p1.setARGB(255, 0, 0, 0); p1.setAntiAlias(true); p1.setStrokeWidth(40); p1.setStyle(Paint.Style.STROKE); canvas.drawLine(10, y, 390, y, p1); p.setARGB(255, 255, 255, 255); canvas.drawText(" :" + Seprate3(res.TotalAmount) + " ", 200, y, p); p.setARGB(255, 0, 0, 0); y += 40; canvas.drawText("__________________________", 200, y, p); y += 40; canvas.drawText(" :" + res.BillIdentifier, 200, y, p); y += 40; canvas.drawText(" :" + res.PaymentIdentifier, 200, y, p); doc.finishPage(page); //File file = new File(getCacheDir()+ "/billing.png"); File file = new File("/sdcard/billing.pdf"); FileOutputStream outfile; try { outfile = new FileOutputStream(file); //bmp.compress(Bitmap.CompressFormat.PNG, 100, outfile); doc.writeTo(outfile); doc.close(); Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); //intent.setDataAndType(Uri.fromFile(file), "image/*"); intent.setDataAndType(Uri.fromFile(file), "application/pdf"); startActivity(intent); //new RetrieveFeedTask().execute(bmp); } catch (Exception ex) { Log.e("error", ex.toString()); new AlertDialog.Builder(this).setMessage( " ? pdf ? \n https://cafebazaar.ir/app/com.kdanmobile.android.pdfreader.google.pad/?l=fa ") .show(); } }
From source file:radialdemo.RadialMenuWidget.java
@Override protected void onDraw(Canvas c) { Paint paint = new Paint(); paint.setAntiAlias(true); paint.setStrokeWidth(3);//from w w w . ja v a 2s. co m // draws a dot at the source of the press if (showSource == true) { paint.setColor(outlineColor); paint.setAlpha(outlineAlpha); paint.setStyle(Paint.Style.STROKE); c.drawCircle(xSource, ySource, cRadius / 10, paint); paint.setColor(selectedColor); paint.setAlpha(selectedAlpha); paint.setStyle(Paint.Style.FILL); c.drawCircle(xSource, ySource, cRadius / 10, paint); } //inner for (int i = 0; i < Wedges.length; i++) { RadialMenuWedge f = Wedges[i]; paint.setColor(outlineColor); paint.setAlpha(outlineAlpha); paint.setStyle(Paint.Style.STROKE); c.drawPath(f, paint); if (f == enabled && Wedge2Shown == true) { paint.setColor(wedge2Color); paint.setAlpha(wedge2Alpha); paint.setStyle(Paint.Style.FILL); c.drawPath(f, paint); } else if (f != enabled && Wedge2Shown == true) { paint.setColor(disabledColor); paint.setAlpha(disabledAlpha); paint.setStyle(Paint.Style.FILL); c.drawPath(f, paint); } else if (f == enabled && Wedge2Shown == false) { paint.setColor(wedge2Color); paint.setAlpha(wedge2Alpha); paint.setStyle(Paint.Style.FILL); c.drawPath(f, paint); } else if (f == selected) { paint.setColor(wedge2Color); paint.setAlpha(wedge2Alpha); paint.setStyle(Paint.Style.FILL); c.drawPath(f, paint); } else { paint.setColor(defaultColor); paint.setAlpha(defaultAlpha); paint.setStyle(Paint.Style.FILL); c.drawPath(f, paint); } //button content Rect rf = iconRect[i]; if ((menuEntries.get(i).getIcon() != 0) && (menuEntries.get(i).getLabel() != null)) { // This will look for a "new line" and split into multiple lines String menuItemName = menuEntries.get(i).getLabel(); String[] stringArray = menuItemName.split("\n"); paint.setColor(textColor); if (f != enabled && Wedge2Shown == true) { paint.setAlpha(disabledAlpha); } else { paint.setAlpha(textAlpha); } paint.setStyle(Paint.Style.FILL); paint.setTextSize(textSize); Rect rect = new Rect(); float textHeight = 0; for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect); textHeight = textHeight + (rect.height() + 3); } Rect rf2 = new Rect(); rf2.set(rf.left, rf.top - ((int) textHeight / 2), rf.right, rf.bottom - ((int) textHeight / 2)); float textBottom = rf2.bottom; for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect); float textLeft = rf.centerX() - rect.width() / 2; textBottom = textBottom + (rect.height() + 3); c.drawText(stringArray[j], textLeft - rect.left, textBottom - rect.bottom, paint); } // Puts in the Icon Drawable drawable = getResources().getDrawable(menuEntries.get(i).getIcon()); drawable.setBounds(rf2); if (f != enabled && Wedge2Shown == true) { drawable.setAlpha(disabledAlpha); } else { drawable.setAlpha(pictureAlpha); } drawable.draw(c); // Icon Only } else if (menuEntries.get(i).getIcon() != 0) { // Puts in the Icon Drawable drawable = getResources().getDrawable(menuEntries.get(i).getIcon()); drawable.setBounds(rf); if (f != enabled && Wedge2Shown == true) { drawable.setAlpha(disabledAlpha); } else { drawable.setAlpha(pictureAlpha); } drawable.draw(c); // Text Only } else { // Puts in the Text if no Icon paint.setColor(textColor); if (f != enabled && Wedge2Shown == true) { paint.setAlpha(disabledAlpha); } else { paint.setAlpha(textAlpha); } paint.setStyle(Paint.Style.FILL); paint.setTextSize(textSize + 10); // This will look for a "new line" and split into multiple lines String menuItemName = menuEntries.get(i).getLabel(); String[] stringArray = menuItemName.split("\n"); // gets total height Rect rect = new Rect(); float textHeight = 0; for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect); textHeight = textHeight + (rect.height() + 3); } float textBottom = rf.centerY() - (textHeight / 2); for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect); float textLeft = rf.centerX() - rect.width() / 2; textBottom = textBottom + (rect.height() + 3); c.drawText(stringArray[j], textLeft - rect.left, textBottom - rect.bottom, paint); } } } // Animate the outer ring in/out if (animateOuterIn == true) { animateOuterWedges(ANIMATE_IN); } else if (animateOuterOut == true) { animateOuterWedges(ANIMATE_OUT); } //outer if (Wedge2Shown == true) { for (int i = 0; i < Wedges2.length; i++) { RadialMenuWedge f = Wedges2[i]; paint.setColor(outlineColor); paint.setAlpha(20); paint.setStyle(Paint.Style.STROKE); c.drawPath(f, paint); if (f == selected2) { paint.setColor(selectedColor); paint.setAlpha(selectedAlpha); paint.setStyle(Paint.Style.FILL); c.drawPath(f, paint); } else { paint.setColor(wedge2Color); paint.setAlpha(wedge2Alpha); paint.setStyle(Paint.Style.FILL); c.drawPath(f, paint); } Rect rf = iconRect2[i]; if ((wedge2Data.getChildren().get(i).getIcon() != 0) && (wedge2Data.getChildren().get(i).getLabel() != null)) { // This will look for a "new line" and split into multiple // lines String menuItemName = wedge2Data.getChildren().get(i).getLabel(); String[] stringArray = menuItemName.split("\n"); paint.setColor(textColor); paint.setAlpha(textAlpha); paint.setStyle(Paint.Style.FILL); paint.setTextSize(animateTextSize); Rect rect = new Rect(); float textHeight = 0; for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect); textHeight = textHeight + (rect.height() + 3); } Rect rf2 = new Rect(); rf2.set(rf.left, rf.top - ((int) textHeight / 2), rf.right, rf.bottom - ((int) textHeight / 2)); float textBottom = rf2.bottom; for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect); float textLeft = rf.centerX() - rect.width() / 2; textBottom = textBottom + (rect.height() + 3); c.drawText(stringArray[j], textLeft - rect.left, textBottom - rect.bottom, paint); } // Puts in the Icon Drawable drawable = getResources().getDrawable(wedge2Data.getChildren().get(i).getIcon()); drawable.setBounds(rf2); drawable.setAlpha(pictureAlpha); drawable.draw(c); // Icon Only } else if (wedge2Data.getChildren().get(i).getIcon() != 0) { // Puts in the Icon Drawable drawable = getResources().getDrawable(wedge2Data.getChildren().get(i).getIcon()); drawable.setBounds(rf); drawable.setAlpha(pictureAlpha); drawable.draw(c); // Text Only } else { // Puts in the Text if no Icon paint.setColor(textColor); paint.setAlpha(textAlpha); paint.setStyle(Paint.Style.FILL); paint.setTextSize(animateTextSize); // This will look for a "new line" and split into multiple // lines String menuItemName = wedge2Data.getChildren().get(i).getLabel(); String[] stringArray = menuItemName.split("\n"); // gets total height Rect rect = new Rect(); float textHeight = 0; for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect); textHeight = textHeight + (rect.height() + 3); } float textBottom = rf.centerY() - (textHeight / 2); for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect); float textLeft = rf.centerX() - rect.width() / 2; textBottom = textBottom + (rect.height() + 3); c.drawText(stringArray[j], textLeft - rect.left, textBottom - rect.bottom, paint); } } } } //Check if the user has given input for centre circle if (centerCircle != null) { // Draws the Middle Circle paint.setColor(outlineColor); paint.setAlpha(outlineAlpha); paint.setStyle(Paint.Style.STROKE); c.drawCircle(xPosition, yPosition, cRadius, paint); if (inCircle == true) { paint.setColor(selectedColor); paint.setAlpha(selectedAlpha); paint.setStyle(Paint.Style.FILL); c.drawCircle(xPosition, yPosition, cRadius, paint); helper.onCloseAnimation(this, xPosition, yPosition, xSource, ySource); } else { paint.setColor(defaultColor); paint.setAlpha(defaultAlpha); paint.setStyle(Paint.Style.FILL); c.drawCircle(xPosition, yPosition, cRadius, paint); } // Draw the circle picture if ((centerCircle.getIcon() != 0) && (centerCircle.getLabel() != null)) { // This will look for a "new line" and split into multiple lines String menuItemName = centerCircle.getLabel(); String[] stringArray = menuItemName.split("\n"); paint.setColor(textColor); paint.setAlpha(textAlpha); paint.setStyle(Paint.Style.FILL); paint.setTextSize(textSize); Rect rectText = new Rect(); Rect rectIcon = new Rect(); Drawable drawable = getResources().getDrawable(centerCircle.getIcon()); int h = getIconSize(drawable.getIntrinsicHeight(), MinIconSize, MaxIconSize); int w = getIconSize(drawable.getIntrinsicWidth(), MinIconSize, MaxIconSize); rectIcon.set(xPosition - w / 2, yPosition - h / 2, xPosition + w / 2, yPosition + h / 2); float textHeight = 0; for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rectText); textHeight = textHeight + (rectText.height() + 3); } rectIcon.set(rectIcon.left, rectIcon.top - ((int) textHeight / 2), rectIcon.right, rectIcon.bottom - ((int) textHeight / 2)); float textBottom = rectIcon.bottom; for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rectText); float textLeft = xPosition - rectText.width() / 2; textBottom = textBottom + (rectText.height() + 3); c.drawText(stringArray[j], textLeft - rectText.left, textBottom - rectText.bottom, paint); } // Puts in the Icon drawable.setBounds(rectIcon); drawable.setAlpha(pictureAlpha); drawable.draw(c); // Icon Only } else if (centerCircle.getIcon() != 0) { Rect rect = new Rect(); Drawable drawable = getResources().getDrawable(centerCircle.getIcon()); int h = getIconSize(drawable.getIntrinsicHeight(), MinIconSize, MaxIconSize); int w = getIconSize(drawable.getIntrinsicWidth(), MinIconSize, MaxIconSize); rect.set(xPosition - w / 2, yPosition - h / 2, xPosition + w / 2, yPosition + h / 2); drawable.setBounds(rect); drawable.setAlpha(pictureAlpha); drawable.draw(c); // Text Only } else { // Puts in the Text if no Icon paint.setColor(textColor); paint.setAlpha(textAlpha); paint.setStyle(Paint.Style.FILL); paint.setTextSize(textSize); // This will look for a "new line" and split into multiple lines String menuItemName = centerCircle.getLabel(); String[] stringArray = menuItemName.split("\n"); // gets total height Rect rect = new Rect(); float textHeight = 0; for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect); textHeight = textHeight + (rect.height() + 3); } float textBottom = yPosition - (textHeight / 2); for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect); float textLeft = xPosition - rect.width() / 2; textBottom = textBottom + (rect.height() + 3); c.drawText(stringArray[j], textLeft - rect.left, textBottom - rect.bottom, paint); } } } // Draws Text in TextBox if (headerString != null) { paint.setTextSize(headerTextSize); paint.getTextBounds(headerString, 0, headerString.length(), this.textRect); if (HeaderBoxBounded == false) { determineHeaderBox(); HeaderBoxBounded = true; } paint.setColor(outlineColor); paint.setAlpha(outlineAlpha); paint.setStyle(Paint.Style.STROKE); c.drawRoundRect(this.textBoxRect, scalePX(5), scalePX(5), paint); paint.setColor(headerBackgroundColor); paint.setAlpha(headerBackgroundAlpha); paint.setStyle(Paint.Style.FILL); c.drawRoundRect(this.textBoxRect, scalePX(5), scalePX(5), paint); paint.setColor(headerTextColor); paint.setAlpha(headerTextAlpha); paint.setStyle(Paint.Style.FILL); paint.setTextSize(headerTextSize); c.drawText(headerString, headerTextLeft, headerTextBottom, paint); } }
From source file:com.android.launcher3.Utilities.java
public static Bitmap getNotificationBadgeIcon(Context context, Bitmap appIcon, int number) { Paint paint; Paint circlePaint;/*from ww w .j a va 2s . c o m*/ String text = "" + String.valueOf(number); Bitmap canvasBitmap = Bitmap.createBitmap(appIcon.getWidth(), appIcon.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(canvasBitmap); paint = new Paint(); circlePaint = new Paint(); paint.setColor(Color.WHITE); paint.setTextSize(45); paint.setAntiAlias(true); paint.setTextAlign(Paint.Align.CENTER); Rect bounds = new Rect(); paint.getTextBounds(text, 0, text.length(), bounds); circlePaint.setColor(ContextCompat.getColor(context, R.color.colorPrimary)); circlePaint.setAntiAlias(true); canvas.drawCircle(appIcon.getWidth() / 4, appIcon.getHeight() / 4, 45, circlePaint); canvas.drawText(text, appIcon.getWidth() / 4, appIcon.getHeight() / 3, paint); return overlay(appIcon, canvasBitmap); }
From source file:me.tb.player.SkeletonActivity.java
@Override public Bitmap getCircleBitmap(Bitmap bitmap) { final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(output); final int color = Color.RED; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0);//from w ww.ja v a 2 s . c o m paint.setColor(color); canvas.drawOval(rectF, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); bitmap.recycle(); return output; }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
public static Bitmap graphics_addWaterMarkToImage(Bitmap src, String watermark, Point location, int size, boolean underline) { Bitmap result = null;/*from w w w . j av a2 s .com*/ try { int w = src.getWidth(); int h = src.getHeight(); result = Bitmap.createBitmap(w, h, src.getConfig()); Canvas canvas = new Canvas(result); canvas.drawBitmap(src, 0, 0, null); Paint paint = new Paint(); paint.setColor(Color.RED); //paint.setAlpha(alpha); paint.setTextSize(size); paint.setAntiAlias(true); paint.setUnderlineText(underline); canvas.drawText(watermark, location.x, location.y, paint); } catch (Exception e) { result = null; if (LOG_ENABLE) Log.e(TAG, "ERROR: graphics_addWaterMarkToImage() [" + e.getMessage() + "]", e); } return result; }
From source file:com.cssweb.android.view.PriceView.java
private void drawQihuo(Canvas canvas) { //stockdigit = 0; Paint paint = this.mPaint; tPaint.setColor(GlobalColor.clrLine); tPaint.setStyle(Paint.Style.STROKE); tPaint.setStrokeWidth(1);/*from w ww . j ava2 s . c o m*/ this.x = 0; this.y = 0; startX = x + tips / 2; endX = width - tips / 2; canvas.drawRect(startX, DY / 4, endX, height - DY / 4, tPaint); canvas.drawLine(startX, DY * 2 + DY / 4, endX, DY * 2 + DY / 4, tPaint); canvas.drawLine(startX, DY * 8 + DY / 4, endX, DY * 8 + DY / 4, tPaint); canvas.drawLine(startX, DY * 11 + DY / 4, endX, DY * 11 + DY / 4, tPaint); //canvas.drawLine(startX, DY*16+DY/4, endX, DY*16+DY/4, tPaint); if (quoteData != null) { try { JSONArray jArr = quoteData.getJSONArray("data"); JSONObject jo = jArr.getJSONObject(0); String str = ""; double zrsp = jo.getDouble("zrsp"); canvas.translate(0, DY); paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true); paint.setTextSize(mTextSize); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); paint.setTextAlign(Paint.Align.RIGHT); canvas.translate(width / 2, -DY); double temp2 = jo.getDouble("sjw1"); setColor(paint, temp2, zrsp); str = Utils.dataFormation(temp2, stockdigit); canvas.drawText(str, x, y, paint); canvas.translate(0, DY); temp2 = jo.getDouble("bjw1"); setColor(paint, temp2, zrsp); str = Utils.dataFormation(temp2, stockdigit); canvas.drawText(str, x, y, paint); canvas.translate(0, -DY); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("??", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); paint.setColor(GlobalColor.colorStockName); paint.setTextAlign(Paint.Align.RIGHT); canvas.translate(width / 2, -DY); canvas.drawText(Utils.getAmountFormat(jo.getInt("ssl1"), true), x - tips, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getInt("bsl1"), true), x - tips, y, paint); canvas.translate(-width, DY); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(width / 2, -DY * 5); paint.setTextAlign(Paint.Align.RIGHT); double zjcj = jo.getDouble("zjcj"); setColor(paint, zjcj, zrsp); canvas.drawText(Utils.dataFormation(zjcj, stockdigit), x, y, paint); canvas.translate(0, DY); double zhangd = jo.getDouble("zd"); if (zhangd < 0) { paint.setColor(GlobalColor.colorPriceDown); } else if (zhangd > 0) { paint.setColor(GlobalColor.colorpriceUp); } else { paint.setColor(GlobalColor.colorPriceEqual); } String zhangdie = Utils.dataFormation(zhangd, stockdigit); if (zhangdie.equals("-")) canvas.drawText("", x, y, paint); else canvas.drawText(zhangdie, x, y, paint); double zhangf = jo.getDouble("zf"); if (zhangf < 0) { paint.setColor(GlobalColor.colorPriceDown); } else if (zhangf > 0) { paint.setColor(GlobalColor.colorpriceUp); } else { paint.setColor(GlobalColor.colorPriceEqual); } canvas.translate(0, DY); String zhangfu = Utils.dataFormation(zhangf * 100, 1); if (zhangfu.equals("-")) canvas.drawText("", x, y, paint); else canvas.drawText(zhangfu + "%", x, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("jrjs"), stockdigit), x, y, paint); paint.setColor(GlobalColor.colorpriceUp); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("wp"), true), x, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getInt("cjsl"), true), x, y, paint); canvas.translate(0, -DY * 5); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(width / 2, -DY * 5); paint.setTextAlign(Paint.Align.RIGHT); double jrkp = jo.getDouble("jrkp"); setColor(paint, jrkp, zrsp); canvas.drawText(Utils.dataFormation(jrkp, stockdigit), x - tips, y, paint); canvas.translate(0, DY); double zg = jo.getDouble("zgcj"); setColor(paint, zg, zrsp); canvas.drawText(Utils.dataFormation(zg, stockdigit), x - tips, y, paint); canvas.translate(0, DY); double zd = jo.getDouble("zdcj"); setColor(paint, zd, zrsp); canvas.drawText(Utils.dataFormation(zd, stockdigit), x - tips, y, paint); paint.setColor(GlobalColor.colorLabelName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("zrjs"), stockdigit), x - tips, y, paint); paint.setColor(GlobalColor.colorPriceDown); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("np"), true), x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), true), x - tips, y, paint); canvas.translate(-width, DY); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText(" ", x + tips, y, paint); canvas.translate(width / 2, -DY * 2); paint.setTextAlign(Paint.Align.RIGHT); double zt = jo.getDouble("zt"); setColor(paint, zt, zrsp); canvas.drawText(Utils.dataFormation(zt, stockdigit), x, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("jrcc"), 0), x, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("jrkc"), 0), x, y, paint); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.translate(0, -DY * 2); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText(" ", x + tips, y, paint); canvas.translate(width / 2, -DY * 2); paint.setTextAlign(Paint.Align.RIGHT); double dt = jo.getDouble("dt"); setColor(paint, dt, zrsp); canvas.drawText(Utils.dataFormation(dt, stockdigit), x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("zc"), 0), x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("jrpc"), 0), x - tips, y, paint); } catch (JSONException e) { Log.e(TAG, e.toString()); } } }