List of usage examples for android.graphics Paint setARGB
public void setARGB(int a, int r, int g, int b)
From source file:ch.carteggio.ui.ConversationIconLoader.java
/** * Calculates a bitmap with a color and a capital letter for contacts without picture. *//*from w w w .j a va2 s. co m*/ private Bitmap calculateFallbackBitmap(String emails[]) { Bitmap result = Bitmap.createBitmap(mPictureSizeInPx, mPictureSizeInPx, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(result); int rgb = CONTACT_DUMMY_COLORS_ARGB[0]; if (emails.length > 0) { calcUnknownContactColor(emails[0]); } result.eraseColor(rgb); String letter = FALLBACK_CONTACT_LETTER; Paint paint = new Paint(); paint.setAntiAlias(true); paint.setStyle(Paint.Style.FILL); paint.setARGB(255, 255, 255, 255); paint.setTextSize(mPictureSizeInPx * 3 / 4); // just scale this down a bit Rect rect = new Rect(); paint.getTextBounds(letter, 0, 1, rect); float width = paint.measureText(letter); canvas.drawText(letter, (mPictureSizeInPx / 2f) - (width / 2f), (mPictureSizeInPx / 2f) + (rect.height() / 2f), paint); return result; }
From source file:com.metinkale.prayerapp.vakit.fragments.MainFragment.java
private void export(int csvpdf, LocalDate from, LocalDate to) throws IOException { File outputDir = getActivity().getCacheDir(); if (!outputDir.exists()) outputDir.mkdirs();//from w w w. j a v a2s . c om File outputFile = new File(outputDir, mTimes.getName().replace(" ", "_") + (csvpdf == 0 ? ".csv" : ".pdf")); if (outputDir.exists()) outputFile.delete(); FileOutputStream outputStream; outputStream = new FileOutputStream(outputFile); if (csvpdf == 0) { outputStream.write("Date;Fajr;Shuruq;Dhuhr;Asr;Maghrib;Ishaa\n".getBytes()); do { outputStream.write((from.toString("yyyy-MM-dd") + ";").getBytes()); outputStream.write((mTimes.getTime(from, 0) + ";").getBytes()); outputStream.write((mTimes.getTime(from, 1) + ";").getBytes()); outputStream.write((mTimes.getTime(from, 2) + ";").getBytes()); outputStream.write((mTimes.getTime(from, 3) + ";").getBytes()); outputStream.write((mTimes.getTime(from, 4) + ";").getBytes()); outputStream.write((mTimes.getTime(from, 5) + "\n").getBytes()); } while (!(from = from.plusDays(1)).isAfter(to)); outputStream.close(); } else { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { PdfDocument document = new PdfDocument(); PdfDocument.PageInfo pageInfo = null; int pw = 595; int ph = 842; pageInfo = new PdfDocument.PageInfo.Builder(pw, ph, 1).create(); PdfDocument.Page page = document.startPage(pageInfo); Drawable launcher = Drawable.createFromStream(getActivity().getAssets().open("pdf/launcher.png"), null); Drawable qr = Drawable.createFromStream(getActivity().getAssets().open("pdf/qrcode.png"), null); Drawable badge = Drawable.createFromStream( getActivity().getAssets().open("pdf/badge_" + Prefs.getLanguage() + ".png"), null); launcher.setBounds(30, 30, 30 + 65, 30 + 65); qr.setBounds(pw - 30 - 65, 30 + 65 + 5, pw - 30, 30 + 65 + 5 + 65); int w = 100; int h = w * badge.getIntrinsicHeight() / badge.getIntrinsicWidth(); badge.setBounds(pw - 30 - w, 30 + (60 / 2 - h / 2), pw - 30, 30 + (60 / 2 - h / 2) + h); Canvas canvas = page.getCanvas(); Paint paint = new Paint(); paint.setARGB(255, 0, 0, 0); paint.setTextSize(10); paint.setTextAlign(Paint.Align.CENTER); canvas.drawText("com.metinkale.prayer", pw - 30 - w / 2, 30 + (60 / 2 - h / 2) + h + 10, paint); launcher.draw(canvas); qr.draw(canvas); badge.draw(canvas); paint.setARGB(255, 61, 184, 230); canvas.drawRect(30, 30 + 60, pw - 30, 30 + 60 + 5, paint); if (mTimes.getSource().resId != 0) { Drawable source = getResources().getDrawable(mTimes.getSource().resId); h = 65; w = h * source.getIntrinsicWidth() / source.getIntrinsicHeight(); source.setBounds(30, 30 + 65 + 5, 30 + w, 30 + 65 + 5 + h); source.draw(canvas); } paint.setARGB(255, 0, 0, 0); paint.setTextSize(40); paint.setTextAlign(Paint.Align.LEFT); canvas.drawText(getText(R.string.appName).toString(), 30 + 65 + 5, 30 + 50, paint); paint.setTextAlign(Paint.Align.CENTER); paint.setFakeBoldText(true); canvas.drawText(mTimes.getName(), pw / 2.0f, 30 + 65 + 50, paint); paint.setTextSize(12); int y = 30 + 65 + 5 + 65 + 30; int p = 30; int cw = (pw - p - p) / 7; canvas.drawText(getString(R.string.date), 30 + (0.5f * cw), y, paint); canvas.drawText(Vakit.IMSAK.getString(), 30 + (1.5f * cw), y, paint); canvas.drawText(Vakit.GUNES.getString(), 30 + (2.5f * cw), y, paint); canvas.drawText(Vakit.OGLE.getString(), 30 + (3.5f * cw), y, paint); canvas.drawText(Vakit.IKINDI.getString(), 30 + (4.5f * cw), y, paint); canvas.drawText(Vakit.AKSAM.getString(), 30 + (5.5f * cw), y, paint); canvas.drawText(Vakit.YATSI.getString(), 30 + (6.5f * cw), y, paint); paint.setFakeBoldText(false); do { y += 20; canvas.drawText((from.toString("dd.MM.yyyy")), 30 + (0.5f * cw), y, paint); canvas.drawText((mTimes.getTime(from, 0)), 30 + (1.5f * cw), y, paint); canvas.drawText((mTimes.getTime(from, 1)), 30 + (2.5f * cw), y, paint); canvas.drawText((mTimes.getTime(from, 2)), 30 + (3.5f * cw), y, paint); canvas.drawText((mTimes.getTime(from, 3)), 30 + (4.5f * cw), y, paint); canvas.drawText((mTimes.getTime(from, 4)), 30 + (5.5f * cw), y, paint); canvas.drawText((mTimes.getTime(from, 5)), 30 + (6.5f * cw), y, paint); } while (!(from = from.plusDays(1)).isAfter(to)); document.finishPage(page); document.writeTo(outputStream); // close the document document.close(); } else { Toast.makeText(getActivity(), R.string.versionNotSupported, Toast.LENGTH_LONG).show(); } } Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.setType(csvpdf == 0 ? "text/csv" : "application/pdf"); Uri uri = FileProvider.getUriForFile(getActivity(), "com.metinkale.prayer.fileprovider", outputFile); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.export))); }
From source file:Main.java
public static byte[] makeFontBitmap(String font, String code, int size, float[] arrayOfPos) { Canvas c = new Canvas(); Paint p = new Paint(); float density = context.getResources().getDisplayMetrics().density; // Log.v(TAG, String.format("makeFontBitmap called(Java): font=%s code=%s density=%f", font, code, density)); p.setTextSize((float) size * density); p.setAntiAlias(true);//from ww w .j a va 2s . com Rect textBounds = new Rect(); p.getTextBounds(code, 0, code.length(), textBounds); // Log.v(TAG, String.format("makeFontBitmap textBounds: %d,%d,%d,%d", textBounds.left, textBounds.top, textBounds.right, textBounds.bottom)); Rect textBoundsAxA = new Rect(); String axa = String.format("A%sA", code); p.getTextBounds(axa, 0, axa.length(), textBoundsAxA); Rect textBoundsAA = new Rect(); String aa = "AA"; p.getTextBounds(aa, 0, aa.length(), textBoundsAA); // cache.distDelta = Vec2(0, 0); arrayOfPos[0] = textBounds.left; arrayOfPos[1] = textBounds.top; // cache.srcWidth = Vec2(16, 16); arrayOfPos[2] = textBounds.width(); arrayOfPos[3] = textBounds.height(); // cache.step = 16; // arrayOfPos[4] = textBounds.width() + 1; arrayOfPos[4] = textBoundsAxA.width() - textBoundsAA.width(); if (textBounds.width() == 0 || textBounds.height() == 0) { Log.v(TAG, "makeFontBitmap: empty"); return null; } Bitmap b = Bitmap.createBitmap(textBounds.width(), textBounds.height(), Bitmap.Config.ARGB_8888); c.setBitmap(b); Rect r = new Rect(0, 0, textBounds.width(), textBounds.height()); // p.setColor(Color.RED); p.setARGB(0, 0, 0, 0); c.drawRect(r, p); p.setARGB(255, 255, 255, 255); // Log.v(TAG, "makeFontBitmap: drawText"); c.drawText(code, -textBounds.left, -textBounds.top, p); // Log.v(TAG, String.format("makeFontBitmap: w=%.2f h=%.2f", arrayOfPos[2], arrayOfPos[3])); ByteBuffer buf = ByteBuffer.allocate(textBounds.width() * textBounds.height() * 4); // Log.v(TAG, String.format("makeFontBitmap: b.getRowBytes() %d", b.getRowBytes())); buf.position(0); b.copyPixelsToBuffer(buf); // Log.v(TAG, String.format("makeFontBitmap results: capacity=%d", buf.capacity())); return buf.array(); }
From source file:Main.java
public static byte[] makeFontBitmap(String font, String code, int size, float[] arrayOfPos) { Log.v(TAG, String.format("makeFontBitmap called(Java): font=%s code=%s", font, code)); Canvas c = new Canvas(); Paint p = new Paint(); // Log.v(TAG, "get density"); float density = context.getResources().getDisplayMetrics().density; Log.v(TAG, String.format("makeFontBitmap density: %f", density)); p.setTextSize((float) size * density); p.setAntiAlias(true);//from w w w .jav a 2 s. co m Rect textBounds = new Rect(); p.getTextBounds(code, 0, code.length(), textBounds); Log.v(TAG, String.format("makeFontBitmap textBounds: %d,%d,%d,%d", textBounds.left, textBounds.top, textBounds.right, textBounds.bottom)); Rect textBoundsAxA = new Rect(); String axa = String.format("A%sA", code); p.getTextBounds(axa, 0, axa.length(), textBoundsAxA); Rect textBoundsAA = new Rect(); String aa = "AA"; p.getTextBounds(aa, 0, aa.length(), textBoundsAA); // cache.distDelta = Vec2(0, 0); arrayOfPos[0] = textBounds.left; arrayOfPos[1] = textBounds.top; // cache.srcWidth = Vec2(16, 16); arrayOfPos[2] = textBounds.width(); arrayOfPos[3] = textBounds.height(); // cache.step = 16; // arrayOfPos[4] = textBounds.width() + 1; arrayOfPos[4] = textBoundsAxA.width() - textBoundsAA.width(); if (textBounds.width() == 0 || textBounds.height() == 0) { Log.v(TAG, "makeFontBitmap: empty"); return null; } Bitmap b = Bitmap.createBitmap(textBounds.width(), textBounds.height(), Bitmap.Config.ARGB_8888); c.setBitmap(b); Rect r = new Rect(0, 0, textBounds.width(), textBounds.height()); // p.setColor(Color.RED); p.setARGB(0, 0, 0, 0); c.drawRect(r, p); p.setARGB(255, 255, 255, 255); // Log.v(TAG, "makeFontBitmap: drawText"); c.drawText(code, -textBounds.left, -textBounds.top, p); Log.v(TAG, String.format("makeFontBitmap: w=%.2f h=%.2f", arrayOfPos[2], arrayOfPos[3])); ByteBuffer buf = ByteBuffer.allocate(textBounds.width() * textBounds.height() * 4); // ByteBuffer buf = ByteBuffer.allocate(b.getRowBytes()); Log.v(TAG, String.format("makeFontBitmap: b.getRowBytes() %d", b.getRowBytes())); buf.position(0); b.copyPixelsToBuffer(buf); Log.v(TAG, String.format("makeFontBitmap results: capacity=%d", buf.capacity())); // byte bytes[] = buf.array(); // for (int i = 0; i < size * size * 2; i++) // bytes[i] = (byte)(Math.random() * 255); return buf.array(); }
From source file:com.kmagic.solitaire.DrawMaster.java
/** * Draw card value and small suit below value * in both top left and bottom right corners * bottom right is reversed/upside down//w w w . j ava 2 s . com * @param paint paint styled for card value and small suit * @param canvas canvas to draw on * @param value card value * @param smallSuit small card suit * @param suitIdx suit index */ private void drawCardValue(final Paint paint, final Canvas canvas, final String value, final Bitmap smallSuit, final int suitIdx) { if ((suitIdx & 1) == 1) { paint.setARGB(255, 255, 0, 0); } else { paint.setARGB(255, 0, 0, 0); } canvas.drawText(value, mSuitsSize4th, mSuitsSize, paint); canvas.drawBitmap(smallSuit, mSuitsSize4th, mSuitsSize4th + mSuitsSize, mSuitPaint); canvas.save(); canvas.rotate(180, Card.WIDTH / 2, Card.HEIGHT / 2); canvas.drawBitmap(smallSuit, mSuitsSize4th, mSuitsSize4th + mSuitsSize, mSuitPaint); canvas.drawText(value, mSuitsSize4th, mSuitsSize, paint); canvas.restore(); }
From source file:org.navitproject.navit.NavitGraphics.java
protected void draw_polygon(Paint paint, int[] c) { paint.setStrokeWidth(c[0]);//from www . jav a 2 s. c om paint.setARGB(c[1], c[2], c[3], c[4]); paint.setStyle(Paint.Style.FILL); //paint.setAntiAlias(true); //paint.setStrokeWidth(0); Path path = new Path(); path.moveTo(c[5], c[6]); for (int i = 7; i < c.length; i += 2) { path.lineTo(c[i], c[i + 1]); } //global_path.close(); draw_canvas.drawPath(path, paint); }
From source file:org.navitproject.navit.NavitGraphics.java
protected void draw_polyline(Paint paint, int[] c) { paint.setStrokeWidth(c[0]);/*from w ww . j a v a 2 s . c om*/ paint.setARGB(c[1], c[2], c[3], c[4]); paint.setStyle(Paint.Style.STROKE); //paint.setAntiAlias(true); //paint.setStrokeWidth(0); int ndashes = c[5]; float[] intervals = new float[ndashes + (ndashes % 2)]; for (int i = 0; i < ndashes; i++) { intervals[i] = c[6 + i]; } if ((ndashes % 2) == 1) { intervals[ndashes] = intervals[ndashes - 1]; } if (ndashes > 0) { paint.setPathEffect(new android.graphics.DashPathEffect(intervals, 0.0f)); } Path path = new Path(); path.moveTo(c[6 + ndashes], c[7 + ndashes]); for (int i = 8 + ndashes; i < c.length; i += 2) { path.lineTo(c[i], c[i + 1]); } //global_path.close(); draw_canvas.drawPath(path, paint); paint.setPathEffect(null); }
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 ww.j av 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);// w w w. j a v a 2 s. 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); 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:com.android.app.MediaPlaybackActivity.java
/** * //w w w.j av a2 s .c o m * * @param src * @return */ private Bitmap createCircleBitmap(Bitmap src) { Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setARGB(255, 241, 239, 229); int width = src.getWidth(); int height = src.getHeight(); Bitmap target = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(target); canvas.drawCircle(width / 2, width / 2, width / 2, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(src, 0, 0, paint); return target; }