List of usage examples for android.text TextPaint ascent
public float ascent()
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 www .j a v a2s.c o m 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.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 www .j a v a2s. c om*/ 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);/* w ww . ja v a 2 s .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 ww w . j a va2 s.c om*/ // 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; }
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/* ww w. j av a 2 s .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; 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:connect.app.com.connect.calendar.SimpleMonthView.java
private void drawDaysOfWeek(Canvas canvas) { final TextPaint p = mDayOfWeekPaint; final int headerHeight = mMonthHeight; final int rowHeight = mDayOfWeekHeight; final int colWidth = mCellWidth; // Text is vertically centered within the day of week height. final float halfLineHeight = (p.ascent() + p.descent()) / 2f; final int rowCenter = headerHeight + rowHeight / 2; for (int col = 0; col < DAYS_IN_WEEK; col++) { final int colCenter = colWidth * col + colWidth / 2; final int colCenterRtl = colCenter; // if (isLayoutRtl()) { // colCenterRtl = mPaddedWidth - colCenter; // } else { // colCenterRtl = colCenter; // } final int dayOfWeek = (col + mWeekStart) % DAYS_IN_WEEK; final String label = getDayOfWeekLabel(dayOfWeek); canvas.drawText(label, colCenterRtl, rowCenter - halfLineHeight, p); }/*from www. j ava2s . c o m*/ }
From source file:com.tr4android.support.extension.picker.date.SimpleMonthView.java
private void drawDaysOfWeek(Canvas canvas) { final TextPaint p = mDayOfWeekPaint; final int headerHeight = mMonthHeight; final int rowHeight = mDayOfWeekHeight; final int colWidth = mCellWidth; // Text is vertically centered within the day of week height. final float halfLineHeight = (p.ascent() + p.descent()) / 2f; final int rowCenter = headerHeight + rowHeight / 2; for (int col = 0; col < DAYS_IN_WEEK; col++) { final int colCenter = colWidth * col + colWidth / 2; final int colCenterRtl; if (ViewCompatUtils.isLayoutRtl(this)) { colCenterRtl = mPaddedWidth - colCenter; } else {/* ww w . ja v a 2 s . c o m*/ colCenterRtl = colCenter; } final int dayOfWeek = (col + mWeekStart) % DAYS_IN_WEEK; final String label = getDayOfWeekLabel(dayOfWeek); canvas.drawText(label, colCenterRtl, rowCenter - halfLineHeight, p); } }
From source file:connect.app.com.connect.calendar.SimpleMonthView.java
/** * Draws the month days.//from w w w. j a v a2 s . c om */ private void drawDays(Canvas canvas) { final TextPaint p = mDayPaint; final int headerHeight = mMonthHeight + mDayOfWeekHeight; final int rowHeight = mDayHeight; final int colWidth = mCellWidth; // Text is vertically centered within the row height. final float halfLineHeight = (p.ascent() + p.descent()) / 2f; int rowCenter = headerHeight + rowHeight / 2; for (int day = 1, col = findDayOffset(); day <= mDaysInMonth; day++) { final int colCenter = colWidth * col + colWidth / 2; final int colCenterRtl = colCenter; // if (isLayoutRtl()) { // colCenterRtl = mPaddedWidth - colCenter; // } else { // colCenterRtl = colCenter; // } int stateMask = 0; final boolean isDayEnabled = isDayEnabled(day); // if (isDayEnabled) { // stateMask |= StateSet.VIEW_STATE_ENABLED; // } final boolean isDayActivated = mActivatedDay == day; if (isDayActivated) { // stateMask |= StateSet.VIEW_STATE_ACTIVATED; // Adjust the circle to be centered on the row. canvas.drawCircle(colCenterRtl, rowCenter, mDaySelectorRadius, mDaySelectorPaint); } else if (mTouchedItem == day) { // stateMask |= StateSet.VIEW_STATE_PRESSED; if (isDayEnabled) { // Adjust the circle to be centered on the row. canvas.drawCircle(colCenterRtl, rowCenter, mDaySelectorRadius, mDayHighlightPaint); } } final boolean isDayToday = mToday == day; int dayTextColor = 0; if (isDayToday && !isDayActivated) { dayTextColor = mDaySelectorPaint.getColor(); } else { // final int[] stateSet = StateSet.get(stateMask); // dayTextColor = mDayTextColor.getColorForState(stateSet, 0); } p.setColor(dayTextColor); canvas.drawText(mDayFormatter.format(day), colCenterRtl, rowCenter - halfLineHeight, p); col++; if (col == DAYS_IN_WEEK) { col = 0; rowCenter += rowHeight; } } }
From source file:com.tr4android.support.extension.picker.date.SimpleMonthView.java
/** * Draws the month days.//from w ww.j av a2 s . co m */ private void drawDays(Canvas canvas) { final TextPaint p = mDayPaint; final int headerHeight = mMonthHeight + mDayOfWeekHeight; final int rowHeight = mDayHeight; final int colWidth = mCellWidth; // Text is vertically centered within the row height. final float halfLineHeight = (p.ascent() + p.descent()) / 2f; int rowCenter = headerHeight + rowHeight / 2; for (int day = 1, col = findDayOffset(); day <= mDaysInMonth; day++) { final int colCenter = colWidth * col + colWidth / 2; final int colCenterRtl; if (ViewCompatUtils.isLayoutRtl(this)) { colCenterRtl = mPaddedWidth - colCenter; } else { colCenterRtl = colCenter; } int state = 0; final boolean isDayEnabled = isDayEnabled(day); final boolean isDayActivated = mActivatedDay == day; if (isDayActivated) { state = VIEW_STATE_SELECTED; // Adjust the circle to be centered on the row. canvas.drawCircle(colCenterRtl, rowCenter, mDaySelectorRadius, mDaySelectorPaint); } else if (mTouchedItem == day) { state = VIEW_STATE_PRESSED; if (isDayEnabled) { // Adjust the circle to be centered on the row. canvas.drawCircle(colCenterRtl, rowCenter, mDaySelectorRadius, mDayHighlightPaint); } } final boolean isDayToday = mToday == day; final int dayTextColor; if (isDayToday && !isDayActivated) { dayTextColor = mDaySelectorPaint.getColor(); } else { final int[] stateSet = buildState(isDayEnabled, state); dayTextColor = mDayTextColor.getColorForState(stateSet, 0); } p.setColor(dayTextColor); canvas.drawText(mDayFormatter.format(day), colCenterRtl, rowCenter - halfLineHeight, p); col++; if (col == DAYS_IN_WEEK) { col = 0; rowCenter += rowHeight; } } }
From source file:com.appeaser.sublimepickerlibrary.datepicker.SimpleMonthView.java
private void drawDaysOfWeek(Canvas canvas) { final TextPaint p = mDayOfWeekPaint; final int headerHeight = mMonthHeight; final int rowHeight = mDayOfWeekHeight; final int colWidth = mCellWidth; // Text is vertically centered within the day of week height. final float halfLineHeight = (p.ascent() + p.descent()) / 2f; final int rowCenter = headerHeight + rowHeight / 2; for (int col = 0; col < DAYS_IN_WEEK; col++) { final int colCenter = colWidth * col + colWidth / 2; final int colCenterRtl; if (SUtils.isLayoutRtlCompat(this)) { colCenterRtl = mPaddedWidth - colCenter; } else {//from w w w . ja va 2s .c o m colCenterRtl = colCenter; } final int dayOfWeek = (col + mWeekStart) % DAYS_IN_WEEK; final String label = getDayOfWeekLabel(dayOfWeek); canvas.drawText(label, colCenterRtl, rowCenter - halfLineHeight, p); } }