List of usage examples for android.text TextPaint setStyle
public void setStyle(Style style)
From source file:org.wikipedia.page.shareafact.SnippetImage.java
@NonNull private static Layout drawTextSnippet(@NonNull Canvas canvas, @NonNull CharSequence textSnippet) { final int top = TOP_PADDING; final int maxHeight = 225; final int maxLines = 5; final float maxFontSize = 195.0f; final float minFontSize = 32.0f; TextPaint textPaint = new TextPaint(); textPaint.setAntiAlias(true);//from w ww. j a va2 s . c o m textPaint.setColor(Color.WHITE); textPaint.setTextSize(maxFontSize); textPaint.setStyle(Paint.Style.FILL); textPaint.setTypeface(Typeface.DEFAULT_BOLD); textPaint.setShadowLayer(1.0f, 1.0f, 1.0f, Color.GRAY); StaticLayout textLayout = optimizeTextSize( new TextLayoutParams(textSnippet, textPaint, TEXT_WIDTH, SPACING_MULTIPLIER), maxHeight, maxLines, maxFontSize, minFontSize); canvas.save(); int horizontalCenterOffset = top + (maxHeight - textLayout.getHeight()) / QUARTER; canvas.translate(HORIZONTAL_PADDING, horizontalCenterOffset); textLayout.draw(canvas); canvas.restore(); return textLayout; }
From source file:org.wikipedia.page.shareafact.SnippetImage.java
private static int drawDescription(@NonNull Canvas canvas, @Nullable String description, int top, boolean isArticleRTL) { final int marginBottom = 5; final int maxHeight = 23; final int maxLines = 2; final float maxFontSize = 15.0f; final float minFontSize = 10.0f; if (TextUtils.isEmpty(description)) { return top - marginBottom; }//from ww w. j a va 2s . co m TextPaint textPaint = new TextPaint(); textPaint.setAntiAlias(true); textPaint.setColor(Color.WHITE); textPaint.setTextSize(maxFontSize); textPaint.setStyle(Paint.Style.FILL); textPaint.setShadowLayer(1.0f, 0.0f, 0.0f, Color.GRAY); StaticLayout textLayout = optimizeTextSize( new TextLayoutParams(description, textPaint, DESCRIPTION_WIDTH, SPACING_MULTIPLIER), maxHeight, maxLines, maxFontSize, minFontSize); int left = HORIZONTAL_PADDING; if (isArticleRTL) { left = WIDTH - HORIZONTAL_PADDING - textLayout.getWidth(); } top = top - marginBottom - textLayout.getHeight(); canvas.save(); canvas.translate(left, top); textLayout.draw(canvas); canvas.restore(); return top; }
From source file:org.wikipedia.page.shareafact.SnippetImage.java
private static void drawTitle(@NonNull Canvas canvas, @NonNull String title, int top, boolean isArticleRTL) { final int marginBottom = 0; final int maxHeight = 70; final int maxLines = 2; final float maxFontSize = 30.0f; final float spacingMultiplier = 0.7f; TextPaint textPaint = new TextPaint(); textPaint.setAntiAlias(true);/*from ww w . j a v a2 s .co m*/ textPaint.setColor(Color.WHITE); textPaint.setTextSize(maxFontSize); textPaint.setStyle(Paint.Style.FILL); textPaint.setTypeface(SERIF); textPaint.setShadowLayer(1.0f, 0.0f, 1.0f, Color.GRAY); StaticLayout textLayout = optimizeTextSize( new TextLayoutParams(title, textPaint, DESCRIPTION_WIDTH, spacingMultiplier), maxHeight, maxLines, maxFontSize, maxFontSize); int left = HORIZONTAL_PADDING; if (isArticleRTL) { left = WIDTH - HORIZONTAL_PADDING - textLayout.getWidth(); } int marginBottomTotal = marginBottom; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { // versions < 5.0 don't compensate for bottom margin correctly when line // spacing is less than 1.0, so we'll compensate ourselves final int marginBoost = 10; marginBottomTotal += marginBoost; } top = top - marginBottomTotal - textLayout.getHeight(); canvas.save(); canvas.translate(left, top); textLayout.draw(canvas); canvas.restore(); }
From source file:com.busdrone.android.ui.VehicleMarkerRenderer.java
private Bitmap render(int color, String text) { TextPaint textPaint = new TextPaint(); textPaint.setColor(Color.WHITE); textPaint.setStyle(Paint.Style.FILL); textPaint.setAntiAlias(true);// ww w. j av a 2 s.c om textPaint.setTextSize(mTextSize); Rect textBounds = new Rect(); textPaint.getTextBounds(text, 0, text.length(), textBounds); int width = mPadding + textBounds.width() + mPadding; int height = mPadding + textBounds.height() + mPadding; Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(color); canvas.drawRoundRect(new RectF(0, 0, width, height), mCornerRadius, mCornerRadius, paint); canvas.drawText(text, (width / 2f) - (textBounds.width() / 2f), (height / 2f) + (textBounds.height() / 2f), textPaint); return bitmap; }