List of usage examples for android.text TextPaint TextPaint
public TextPaint()
From source file:Main.java
public static int GetTextWidth(String text, float Size) { TextPaint FontPaint = new TextPaint(); FontPaint.setTextSize(Size);//from ww w. ja v a 2 s. c o m return (int) FontPaint.measureText(text); }
From source file:Main.java
public static int getFontHeight(Context context, float fontSize) { TextPaint paint = new TextPaint(); setTextSize(context, paint, fontSize); FontMetrics fm = paint.getFontMetrics(); return (int) Math.ceil(fm.descent - fm.ascent); }
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 ww . java 2s. 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; 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.jjoe64.graphview.series.TitleLineGraphSeries.java
public TitleLineGraphSeries(E[] data) { super(data);//w w w .ja v a 2 s . c om paint = new Paint(); paint.setStrokeCap(Paint.Cap.ROUND); paint.setStyle(Paint.Style.STROKE); paintTitle = new TextPaint(); paintTitle.setTextAlign(Paint.Align.CENTER); paintBackground = new Paint(); path = new Path(); pathBackground = new Path(); }
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);//w w w . j a va2 s . com 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; }
From source file:com.achillesrasquinha.biblegenerator.ImageGenerator.java
public ImageGenerator(Context context) { mContext = context;// w w w .j a v a 2 s . com DisplayMetrics m = mContext.getResources().getDisplayMetrics(); mImageSize = new Point(); mImageSize.x = m.widthPixels; mImageSize.y = mImageSize.x; mX = Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, m)); mSizeTitle = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 24, m); mYTitle = Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, m) + mSizeTitle); mSizeSubtitle = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 14, m); mYSubtitle = Math .round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 12, m) + mYTitle + mSizeSubtitle); mLineSpacing = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, m); mTextPaint = new TextPaint(); mTextPaint.setAntiAlias(true); mTextPaint.setTextAlign(TextPaint.Align.LEFT); mTextPaint.setTypeface(Typeface.createFromAsset(mContext.getAssets(), "fonts/Roboto/Roboto-Medium.ttf")); mColor1 = ContextCompat.getColor(mContext, R.color.primary_text_default_material_light); mColor2 = ContextCompat.getColor(mContext, R.color.primary_text_disabled_material_light); mColor3 = ContextCompat.getColor(mContext, R.color.secondary_text_default_material_light); }
From source file:com.mobisci_lab.virtualkeyboard.softkeyboard.LatinKeyboardView.java
@Override public void onDraw(Canvas canvas) { super.onDraw(canvas); TextPaint paint = new TextPaint(); paint.setAntiAlias(true);/*from w w w . j a va 2 s . co m*/ paint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD)); paint.setTextSize(11 * getResources().getDisplayMetrics().density); paint.setColor(ContextCompat.getColor(this.getContext(), R.color.candidate_other)); List<Key> keys = getKeyboard().getKeys(); for (Key key : keys) { float x = key.x + key.width / 2 + key.width / 5; float y = key.y + key.width / 2; String text = ""; switch (key.codes[0]) { case 113: text = "1"; break; case 119: text = "2"; break; case 101: text = "3"; break; case 114: text = "4"; break; case 116: text = "5"; break; case 121: text = "6"; break; case 117: text = "7"; break; case 105: text = "8"; break; case 111: text = "9"; break; case 112: text = "0"; break; } canvas.drawText(text, x, y, paint); } }
From source file:com.lamcreations.scaffold.common.utils.CollapsingTextHelper.java
public CollapsingTextHelper(View view) { this.mView = view; this.mTextPaint = new TextPaint(); this.mTextPaint.setAntiAlias(true); this.mCollapsedBounds = new Rect(); this.mExpandedBounds = new Rect(); }
From source file:com.cocosw.accessory.views.layout.CollapsingTitleLayout.java
public CollapsingTitleLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mTextPaint = new TextPaint(); mTextPaint.setAntiAlias(true);/* ww w . j a v a2 s . c o m*/ mMinTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_MIN_TEXT_SIZE, getResources().getDisplayMetrics()); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CollapsingTitleLayout); mExpandedMargin = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMargin, 0); mRequestedExpandedTitleTextSize = a .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedTextSize, 0); mRequestedCollapsedTitleTextSize = a .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_collapsedTextSize, 0); mTextPaint.setColor(a.getColor(R.styleable.CollapsingTitleLayout_android_textColor, Color.WHITE)); final int defaultMinTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_MIN_TEXT_SIZE, getResources().getDisplayMetrics()); mMinTextSize = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_minTextSize, defaultMinTextSize); a.recycle(); mTextPaintBounds = new Rect(); mDrawnTextBounds = new Rect(); mToolbarContentBounds = new Rect(); setWillNotDraw(false); }
From source file:net.xpece.commons.android.widget.CollapsingTitleLayout.java
public CollapsingTitleLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mTextPaint = new TextPaint(); mTextPaint.setAntiAlias(true);//from w ww .ja v a 2 s . com if (AndroidUtils.API_21) { Typeface tf = Typeface.create("sans-serif-medium", Typeface.NORMAL); mTextPaint.setTypeface(tf); } else { Typeface tf = Typeface.create("sans-serif", Typeface.NORMAL); mTextPaint.setTypeface(tf); } TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CollapsingTitleLayout); mExpandedMarginLeft = mExpandedMarginRight = mExpandedMarginBottom = a .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMargin, 0); final boolean isRtl = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL; if (a.hasValue(R.styleable.CollapsingTitleLayout_expandedMarginStart)) { final int marginStart = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMarginStart, 0); if (isRtl) { mExpandedMarginRight = marginStart; } else { mExpandedMarginLeft = marginStart; } } if (a.hasValue(R.styleable.CollapsingTitleLayout_expandedMarginEnd)) { final int marginEnd = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMarginEnd, 0); if (isRtl) { mExpandedMarginLeft = marginEnd; } else { mExpandedMarginRight = marginEnd; } } if (a.hasValue(R.styleable.CollapsingTitleLayout_expandedMarginBottom)) { mExpandedMarginBottom = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMarginBottom, 0); } final int tp = a.getResourceId(R.styleable.CollapsingTitleLayout_android_textAppearance, android.R.style.TextAppearance); setTextAppearance(tp); if (a.hasValue(R.styleable.CollapsingTitleLayout_collapsedTextSize)) { mCollapsedTitleTextSize = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_collapsedTextSize, 0); } mRequestedExpandedTitleTextSize = a .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedTextSize, mCollapsedTitleTextSize); final int interpolatorId = a.getResourceId(R.styleable.CollapsingTitleLayout_textSizeInterpolator, android.R.anim.accelerate_interpolator); mTextSizeInterpolator = AnimationUtils.loadInterpolator(context, interpolatorId); a.recycle(); mToolbarContentBounds = new Rect(); setWillNotDraw(false); }