List of usage examples for android.text TextPaint setTextSize
public void setTextSize(float textSize)
From source file:io.plaidapp.core.ui.transitions.ReflowText.java
private Layout createLayout(ReflowData data, Context context, boolean enforceMaxLines) { TextPaint paint = new TextPaint(Paint.ANTI_ALIAS_FLAG); paint.setTextSize(data.textSize); paint.setColor(data.textColor);/*from w ww.jav a 2 s .com*/ paint.setLetterSpacing(data.letterSpacing); if (data.fontResId != 0) { try { Typeface font = ResourcesCompat.getFont(context, data.fontResId); if (font != null) { paint.setTypeface(font); } } catch (Resources.NotFoundException nfe) { } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { StaticLayout.Builder builder = StaticLayout.Builder .obtain(data.text, 0, data.text.length(), paint, data.textWidth) .setLineSpacing(data.lineSpacingAdd, data.lineSpacingMult).setBreakStrategy(data.breakStrategy); if (enforceMaxLines && data.maxLines != -1) { builder.setMaxLines(data.maxLines); builder.setEllipsize(TextUtils.TruncateAt.END); } return builder.build(); } else { return new StaticLayout(data.text, paint, data.textWidth, Layout.Alignment.ALIGN_NORMAL, data.lineSpacingMult, data.lineSpacingAdd, true); } }
From source file:com.mjhram.geodata.GpsMainActivity.java
public Bitmap drawMultilineTextToBitmap(Context gContext, Bitmap bitmap, String gText) { // prepare canvas Resources resources = gContext.getResources(); float scale = resources.getDisplayMetrics().density; //Bitmap bitmap = BitmapFactory.decodeResource(resources, gResId); android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig(); // set default bitmap config if none if (bitmapConfig == null) { bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888; }/*from w w w.ja v a 2 s . c o m*/ // resource bitmaps are imutable, // so we need to convert it to mutable one bitmap = bitmap.copy(bitmapConfig, true); Canvas canvas = new Canvas(bitmap); // new antialiased Paint TextPaint paint = new TextPaint(Paint.ANTI_ALIAS_FLAG); // text color - #3D3D3D paint.setColor(Color.rgb(61, 61, 61)); // text size in pixels paint.setTextSize((int) (20 * scale)); // text shadow paint.setShadowLayer(1f, 0f, 1f, Color.WHITE); //canvas.drawText("This is", 100, 100, paint); //canvas.drawText("multi-line", 100, 150, paint); //canvas.drawText("text", 100, 200, paint); // set text width to canvas width minus 16dp padding int textWidth = canvas.getWidth() - (int) (16 * scale); // init StaticLayout for text StaticLayout textLayout = new StaticLayout(gText, paint, textWidth, Layout.Alignment.ALIGN_CENTER, 1.0f, 0.0f, false); // get height of multiline text int textHeight = textLayout.getHeight(); // get position of text's top left corner float x = (bitmap.getWidth() - textWidth) / 2; float y = bitmap.getHeight() - textHeight; // draw text to the Canvas center canvas.save(); canvas.translate(x, y); textLayout.draw(canvas); canvas.restore(); return bitmap; }
From source file:com.android.ex.chips.RecipientEditTextView.java
private CharSequence ellipsizeText(final CharSequence text, final TextPaint paint, final float maxWidth) { paint.setTextSize(mChipFontSize); if (maxWidth <= 0 && Log.isLoggable(TAG, Log.DEBUG)) Log.d(TAG, "Max width is negative: " + maxWidth); final CharSequence ellipsize = TextUtils.ellipsize(text, paint, maxWidth, TextUtils.TruncateAt.END); return ellipsize; }
From source file:com.android.ex.chips.RecipientEditTextView.java
private MoreImageSpan createMoreSpan(final int count) { final String moreText = String.format(mMoreItem.getText().toString(), count); final TextPaint morePaint = new TextPaint(getPaint()); morePaint.setTextSize(mMoreItem.getTextSize()); morePaint.setColor(mMoreItem.getCurrentTextColor()); final int width = (int) morePaint.measureText(moreText) + mMoreItem.getPaddingLeft() + mMoreItem.getPaddingRight(); final int height = getLineHeight(); final Bitmap drawable = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(drawable); int adjustedHeight = height; final Layout layout = getLayout(); if (layout != null) adjustedHeight -= layout.getLineDescent(0); canvas.drawText(moreText, 0, moreText.length(), 0, adjustedHeight, morePaint); final Drawable result = new BitmapDrawable(getResources(), drawable); result.setBounds(0, 0, width, height); return new MoreImageSpan(result); }
From source file:com.android.ex.chips.RecipientEditTextView.java
private DrawableRecipientChip constructChipSpan(final RecipientEntry contact, final boolean pressed, final boolean leaveIconSpace) throws NullPointerException { if (mChipBackground == null) throw new NullPointerException("Unable to render any chips as setChipDimensions was not called."); final TextPaint paint = getPaint(); final float defaultSize = paint.getTextSize(); final int defaultColor = paint.getColor(); Bitmap tmpBitmap;//w w w. j a v a 2 s . c om if (pressed) tmpBitmap = createSelectedChip(contact, paint); else tmpBitmap = createUnselectedChip(contact, paint, leaveIconSpace); // Pass the full text, un-ellipsized, to the chip. final Drawable result = new BitmapDrawable(getResources(), tmpBitmap); result.setBounds(0, 0, tmpBitmap.getWidth(), tmpBitmap.getHeight()); final DrawableRecipientChip recipientChip = new VisibleRecipientChip(result, contact); // Return text to the original size. paint.setTextSize(defaultSize); paint.setColor(defaultColor); return recipientChip; }
From source file:org.telegram.ui.ArticleViewer.java
private TextPaint getTextPaint(TLRPC.RichText parentRichText, TLRPC.RichText richText, TLRPC.PageBlock parentBlock) {/*from www .ja v a2 s . c o m*/ int flags = getTextFlags(richText); HashMap<Integer, TextPaint> currentMap = null; int textSize = AndroidUtilities.dp(14); int textColor = 0xffff0000; if (parentBlock instanceof TLRPC.TL_pageBlockPhoto) { currentMap = captionTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff838c96; } else if (parentBlock instanceof TLRPC.TL_pageBlockTitle) { currentMap = titleTextPaints; textSize = AndroidUtilities.dp(24); textColor = 0xff000000; } else if (parentBlock instanceof TLRPC.TL_pageBlockAuthorDate) { currentMap = authorTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff838c96; } else if (parentBlock instanceof TLRPC.TL_pageBlockFooter) { currentMap = footerTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff838c96; } else if (parentBlock instanceof TLRPC.TL_pageBlockSubtitle) { currentMap = subtitleTextPaints; textSize = AndroidUtilities.dp(21); textColor = 0xff000000; } else if (parentBlock instanceof TLRPC.TL_pageBlockHeader) { currentMap = headerTextPaints; textSize = AndroidUtilities.dp(21); textColor = 0xff000000; } else if (parentBlock instanceof TLRPC.TL_pageBlockSubheader) { currentMap = subheaderTextPaints; textSize = AndroidUtilities.dp(18); textColor = 0xff000000; } else if (parentBlock instanceof TLRPC.TL_pageBlockBlockquote || parentBlock instanceof TLRPC.TL_pageBlockPullquote) { if (parentBlock.text == parentRichText) { currentMap = quoteTextPaints; textSize = AndroidUtilities.dp(15); textColor = 0xff000000; } else if (parentBlock.caption == parentRichText) { currentMap = subquoteTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff838c96; } } else if (parentBlock instanceof TLRPC.TL_pageBlockPreformatted) { currentMap = preformattedTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff000000; } else if (parentBlock instanceof TLRPC.TL_pageBlockParagraph) { if (parentBlock.caption == parentRichText) { currentMap = embedPostCaptionTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff838c96; } else { currentMap = paragraphTextPaints; textSize = AndroidUtilities.dp(16); textColor = 0xff000000; } } else if (parentBlock instanceof TLRPC.TL_pageBlockList) { currentMap = listTextPaints; textSize = AndroidUtilities.dp(15); textColor = 0xff000000; } else if (parentBlock instanceof TLRPC.TL_pageBlockEmbed) { currentMap = embedTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff838c96; } else if (parentBlock instanceof TLRPC.TL_pageBlockSlideshow) { currentMap = slideshowTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff838c96; } else if (parentBlock instanceof TLRPC.TL_pageBlockEmbedPost) { if (richText != null) { currentMap = embedPostTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff000000; } } else if (parentBlock instanceof TLRPC.TL_pageBlockVideo) { currentMap = videoTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff000000; } if (currentMap == null) { if (errorTextPaint == null) { errorTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); errorTextPaint.setColor(0xffff0000); } errorTextPaint.setTextSize(AndroidUtilities.dp(14)); return errorTextPaint; } TextPaint paint = currentMap.get(flags); if (paint == null) { paint = new TextPaint(Paint.ANTI_ALIAS_FLAG); if ((flags & TEXT_FLAG_MONO) != 0) { paint.setTypeface(AndroidUtilities.getTypeface("fonts/rmono.ttf")); } else { if (parentBlock instanceof TLRPC.TL_pageBlockTitle || parentBlock instanceof TLRPC.TL_pageBlockHeader || parentBlock instanceof TLRPC.TL_pageBlockSubtitle || parentBlock instanceof TLRPC.TL_pageBlockSubheader) { if ((flags & TEXT_FLAG_MEDIUM) != 0 && (flags & TEXT_FLAG_ITALIC) != 0) { paint.setTypeface(Typeface.create("serif", Typeface.BOLD_ITALIC)); } else if ((flags & TEXT_FLAG_MEDIUM) != 0) { paint.setTypeface(Typeface.create("serif", Typeface.BOLD)); } else if ((flags & TEXT_FLAG_ITALIC) != 0) { paint.setTypeface(Typeface.create("serif", Typeface.ITALIC)); } else { paint.setTypeface(Typeface.create("serif", Typeface.NORMAL)); } } else { if ((flags & TEXT_FLAG_MEDIUM) != 0 && (flags & TEXT_FLAG_ITALIC) != 0) { paint.setTypeface(AndroidUtilities.getTypeface("fonts/rmediumitalic.ttf")); } else if ((flags & TEXT_FLAG_MEDIUM) != 0) { paint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); } else if ((flags & TEXT_FLAG_ITALIC) != 0) { paint.setTypeface(AndroidUtilities.getTypeface("fonts/ritalic.ttf")); } } } if ((flags & TEXT_FLAG_STRIKE) != 0) { paint.setFlags(paint.getFlags() | TextPaint.STRIKE_THRU_TEXT_FLAG); } if ((flags & TEXT_FLAG_UNDERLINE) != 0) { paint.setFlags(paint.getFlags() | TextPaint.UNDERLINE_TEXT_FLAG); } if ((flags & TEXT_FLAG_URL) != 0) { textColor = 0xff4d83b3; } paint.setColor(textColor); currentMap.put(flags, paint); } paint.setTextSize(textSize); return paint; }