List of usage examples for android.text TextPaint setTextAlign
public void setTextAlign(Align align)
From source file:com.irccloud.android.data.model.Avatar.java
public static Bitmap generateBitmap(String text, int textColor, int bgColor, boolean isDarkTheme, int size, boolean round) { Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); if (bitmap != null) { Canvas c = new Canvas(bitmap); Paint p = new Paint(Paint.ANTI_ALIAS_FLAG); p.setStyle(Paint.Style.FILL); if (isDarkTheme || !round) { p.setColor(bgColor);//from w w w . ja v a2s. c om if (round) c.drawCircle(size / 2, size / 2, size / 2, p); else c.drawColor(bgColor); } else { float[] hsv = new float[3]; Color.colorToHSV(bgColor, hsv); hsv[2] *= 0.8f; p.setColor(Color.HSVToColor(hsv)); c.drawCircle(size / 2, size / 2, (size / 2) - 2, p); p.setColor(bgColor); c.drawCircle(size / 2, (size / 2) - 2, (size / 2) - 2, p); } TextPaint tp = new TextPaint(Paint.ANTI_ALIAS_FLAG); tp.setTextAlign(Paint.Align.CENTER); tp.setTypeface(font); tp.setTextSize((int) (size * 0.65)); tp.setColor(textColor); if (isDarkTheme || !round) { c.drawText(text, size / 2, (size / 2) - ((tp.descent() + tp.ascent()) / 2), tp); } else { c.drawText(text, size / 2, (size / 2) - 4 - ((tp.descent() + tp.ascent()) / 2), tp); } return bitmap; } else { return null; } }
From source file:com.ecuamobi.deckwallet.util.Renderer.java
public static void printQR(final Activity context, final String addressUri) { new AsyncTask<Void, Void, Bitmap>() { @Override/* www . ja v a 2 s. c o m*/ protected Bitmap doInBackground(Void... params) { TextPaint textPaint = new TextPaint(); textPaint.setAntiAlias(true); textPaint.setColor(0xFF000000); final int bitmapMargin = 100;//big margin is to prevent possible clipping final int textHeight = 28; textPaint.setTextSize(textHeight); textPaint.setTextAlign(Paint.Align.CENTER); final int qrCodePadding = (int) (textPaint.descent() * 2); int textWidth = getTextWidth(addressUri, textPaint); QRCode addressQrCode = QRCode.getMinimumQRCode(addressUri, ErrorCorrectLevel.M); Bitmap addressQrCodeBitmap = addressQrCode.createImage(textWidth); Bitmap bmp = Bitmap.createBitmap(textWidth + bitmapMargin * 2, addressQrCodeBitmap.getHeight() + qrCodePadding * 2 + bitmapMargin * 2, Bitmap.Config.RGB_565); Canvas canvas = new Canvas(bmp); Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setARGB(0xFF, 0xFF, 0xFF, 0xFF); paint.setAntiAlias(false); canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), paint); int centerXForAddress = bitmapMargin + textWidth / 2; int y = bitmapMargin + qrCodePadding; Paint qrCodePaint = new Paint(); qrCodePaint.setAntiAlias(false); qrCodePaint.setDither(false); canvas.drawBitmap(addressQrCodeBitmap, centerXForAddress - addressQrCodeBitmap.getWidth() / 2, y, qrCodePaint); y += qrCodePadding - textPaint.ascent(); canvas.drawText(addressUri, centerXForAddress, y + addressQrCodeBitmap.getHeight(), textPaint); return bmp; } @Override protected void onPostExecute(final Bitmap bitmap) { if (bitmap != null) { //DEBUG // android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(context); // android.widget.ImageView view = new android.widget.ImageView(context); // view.setImageBitmap(bitmap); // builder.setView(view); // builder.setPositiveButton(android.R.string.ok, null); // builder.show(); PrintHelper printHelper = new PrintHelper(context); printHelper.setScaleMode(PrintHelper.SCALE_MODE_FIT); printHelper.printBitmap(addressUri, bitmap); } } }.execute(); }
From source file:com.ecuamobi.deckwallet.util.Renderer.java
static void printWallet(final Activity context, final String label, final String addressUri, final String privateKey) { new AsyncTask<Void, Void, Bitmap>() { @Override//from w w w .j a v a 2s .c om protected Bitmap doInBackground(Void... params) { TextPaint textPaint = new TextPaint(); textPaint.setAntiAlias(true); textPaint.setColor(0xFF000000); final int bitmapMargin = 100;//big margin is to prevent possible clipping final int textHeight = 28; final int spaceBetweenQrCodes = 60; textPaint.setTextSize(textHeight); textPaint.setTextAlign(Paint.Align.CENTER); final int qrCodePadding = (int) (textPaint.descent() * 2); Rect bounds = new Rect(); textPaint.getTextBounds(privateKey, 0, privateKey.length(), bounds); int textWidth = getTextWidth(privateKey, textPaint); ArrayList<String> labelLinesRelaxed = wrap(label, textWidth, false, textPaint); for (String titleLine : labelLinesRelaxed) { textWidth = Math.max(textWidth, getTextWidth(titleLine, textPaint)); } textWidth = Math.max(textWidth, getTextWidth(addressUri, textPaint)); QRCode privateKeyQrCode = QRCode.getMinimumQRCode(privateKey, ErrorCorrectLevel.M); Bitmap privateKeyQrCodeBitmap = privateKeyQrCode.createImage(textWidth); QRCode addressQrCode = QRCode.getMinimumQRCode(addressUri, ErrorCorrectLevel.M); Bitmap addressQrCodeBitmap = addressQrCode.createImage(textWidth); ArrayList<String> labelLines = wrap(label, textWidth, true, textPaint); Bitmap bmp = Bitmap.createBitmap( textWidth * 2 + bitmapMargin * 2 + spaceBetweenQrCodes, privateKeyQrCodeBitmap.getHeight() + textHeight * (labelLines.size() + 1) + qrCodePadding * 2 + bitmapMargin * 2, Bitmap.Config.RGB_565); Canvas canvas = new Canvas(bmp); Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setARGB(0xFF, 0xFF, 0xFF, 0xFF); paint.setAntiAlias(false); canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), paint); int centerXForAddress = bitmapMargin + textWidth / 2; int centerXForPrivateKey = bitmapMargin + textWidth + spaceBetweenQrCodes + textWidth / 2; int y = (int) (bitmapMargin - textPaint.ascent()); for (int i = 0; i < labelLines.size(); i++) { canvas.drawText(labelLines.get(i), centerXForPrivateKey, y + i * textHeight, textPaint); } y = bitmapMargin + labelLines.size() * textHeight + qrCodePadding; Paint qrCodePaint = new Paint(); qrCodePaint.setAntiAlias(false); qrCodePaint.setDither(false); canvas.drawBitmap(addressQrCodeBitmap, centerXForAddress - addressQrCodeBitmap.getWidth() / 2, y, qrCodePaint); canvas.drawBitmap(privateKeyQrCodeBitmap, centerXForPrivateKey - privateKeyQrCodeBitmap.getWidth() / 2, y, qrCodePaint); y += qrCodePadding - textPaint.ascent(); canvas.drawText(addressUri, centerXForAddress, y + addressQrCodeBitmap.getHeight(), textPaint); canvas.drawText(privateKey, centerXForPrivateKey, y + privateKeyQrCodeBitmap.getHeight(), textPaint); return bmp; } @Override protected void onPostExecute(final Bitmap bitmap) { if (bitmap != null) { //DEBUG // android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(context); // android.widget.ImageView view = new android.widget.ImageView(context); // view.setImageBitmap(bitmap); // builder.setView(view); // builder.setPositiveButton(android.R.string.ok, null); // builder.show(); PrintHelper printHelper = new PrintHelper(context); printHelper.setScaleMode(PrintHelper.SCALE_MODE_FIT); printHelper.printBitmap(label, bitmap); } } }.execute(); }
From source file:com.grarak.kerneladiutor.elements.SplashView.java
private void draw(Canvas canvas, int x, int y, int radius) { if (radius > 0) canvas.drawCircle(x / 2, y / 2, radius, mPaintCircle); matrix.postRotate(rotate);/*from ww w . ja va 2s. c o m*/ Bitmap iconRotate = Bitmap.createBitmap(icon, 0, 0, icon.getWidth(), icon.getHeight(), matrix, false); canvas.drawBitmap(iconRotate, x / 2 - iconRotate.getWidth() / 2, y / 2 - iconRotate.getHeight() / 2, mPaintCircle); TextPaint textPaint = new TextPaint(); textPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD)); textPaint.setColor(textColor); textPaint.setAntiAlias(true); textPaint.setTextAlign(Paint.Align.CENTER); textPaint.setTextSize(textSize); float textHeight = textPaint.descent() - textPaint.ascent(); float textOffset = (textHeight / 2) - textPaint.descent(); canvas.drawText(getResources().getString(R.string.root_waiting), x / 2, y - textOffset - y / 4, textPaint); }
From source file:com.raspi.chatapp.util.Notification.java
private Bitmap getLargeIcon(int bgColor, char letter, float width, boolean round) { Bitmap b = Bitmap.createBitmap((int) width, (int) width, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); RectF mInnerRectF = new RectF(); mInnerRectF.set(0, 0, width, width); mInnerRectF.offset(0, 0);/*from w w w . j a v a2s. c o m*/ Paint mBgPaint = new Paint(); mBgPaint.setFlags(Paint.ANTI_ALIAS_FLAG); mBgPaint.setStyle(Paint.Style.FILL); mBgPaint.setColor(bgColor); TextPaint mTitleTextPaint = new TextPaint(); mTitleTextPaint.setFlags(Paint.ANTI_ALIAS_FLAG); mTitleTextPaint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); mTitleTextPaint.setTextAlign(Paint.Align.CENTER); mTitleTextPaint.setLinearText(true); mTitleTextPaint.setColor(Color.WHITE); mTitleTextPaint.setTextSize(width * 0.8f); float centerX = mInnerRectF.centerX(); float centerY = mInnerRectF.centerY(); int xPos = (int) centerX; int yPos = (int) (centerY - (mTitleTextPaint.descent() + mTitleTextPaint.ascent()) / 2); if (round) c.drawOval(mInnerRectF, mBgPaint); else c.drawRect(mInnerRectF, mBgPaint); c.drawText(String.valueOf(letter), xPos, yPos, mTitleTextPaint); return b; }
From source file:org.ciasaboark.tacere.manager.NotificationManagerWrapper.java
private Bitmap createMarkerIcon(Drawable backgroundImage, String text, int width, int height) { Bitmap canvasBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); // Create a canvas, that will draw on to canvasBitmap. Canvas imageCanvas = new Canvas(canvasBitmap); // Draw the image to our canvas backgroundImage.draw(imageCanvas);/*from w w w . ja v a 2 s . co m*/ // Set up the paint for use with our Canvas TextPaint textPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG | TextPaint.LINEAR_TEXT_FLAG); textPaint.setTextAlign(TextPaint.Align.CENTER); textPaint.setTypeface(Typeface.DEFAULT); textPaint.setTextSize(100f); textPaint.setColor(context.getResources().getColor(android.R.color.white)); int xPos = (imageCanvas.getWidth() / 2); int yPos = (int) ((imageCanvas.getHeight() / 2) - ((textPaint.descent() + textPaint.ascent()) / 2)); Rect r = new Rect(); textPaint.getTextBounds(text, 0, text.length(), r); // yPos += (Math.abs(r.height()))/2; // Draw the text on top of our image imageCanvas.drawText(text, xPos, yPos, textPaint); // Combine background and text to a LayerDrawable LayerDrawable layerDrawable = new LayerDrawable( new Drawable[] { backgroundImage, new BitmapDrawable(canvasBitmap) }); Bitmap newBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); layerDrawable.setBounds(0, 0, width, height); layerDrawable.draw(new Canvas(newBitmap)); return newBitmap; }