List of usage examples for android.graphics Canvas drawText
public void drawText(@NonNull String text, float x, float y, @NonNull Paint paint)
From source file:io.doist.datetimepicker.time.RadialTimePickerView.java
/** * Draw the 12 text values at the positions specified by the textGrid parameters. */// w w w . j a v a 2 s .com private void drawTextElements(Canvas canvas, float textSize, Typeface typeface, String[] texts, float[] textGridWidths, float[] textGridHeights, Paint paint, int color, int alpha) { paint.setTextSize(textSize); paint.setTypeface(typeface); paint.setColor(color); paint.setAlpha(getMultipliedAlpha(color, alpha)); canvas.drawText(texts[0], textGridWidths[3], textGridHeights[0], paint); canvas.drawText(texts[1], textGridWidths[4], textGridHeights[1], paint); canvas.drawText(texts[2], textGridWidths[5], textGridHeights[2], paint); canvas.drawText(texts[3], textGridWidths[6], textGridHeights[3], paint); canvas.drawText(texts[4], textGridWidths[5], textGridHeights[4], paint); canvas.drawText(texts[5], textGridWidths[4], textGridHeights[5], paint); canvas.drawText(texts[6], textGridWidths[3], textGridHeights[6], paint); canvas.drawText(texts[7], textGridWidths[2], textGridHeights[5], paint); canvas.drawText(texts[8], textGridWidths[1], textGridHeights[4], paint); canvas.drawText(texts[9], textGridWidths[0], textGridHeights[3], paint); canvas.drawText(texts[10], textGridWidths[1], textGridHeights[2], paint); canvas.drawText(texts[11], textGridWidths[2], textGridHeights[1], paint); }
From source file:piuk.blockchain.android.util.ViewPagerTabs.java
@Override protected void onDraw(final Canvas canvas) { super.onDraw(canvas); final int viewWidth = getWidth(); final int viewHalfWidth = viewWidth / 2; final int viewBottom = getHeight(); final float density = getResources().getDisplayMetrics().density; final float spacing = 32 * density; final Path path = new Path(); path.moveTo(viewHalfWidth, viewBottom - 5 * density); path.lineTo(viewHalfWidth + 5 * density, viewBottom); path.lineTo(viewHalfWidth - 5 * density, viewBottom); path.close();//www . j a va 2 s . c o m paint.setColor(Color.WHITE); canvas.drawPath(path, paint); paint.setTypeface(Typeface.DEFAULT_BOLD); final float y = getPaddingTop() + -paint.getFontMetrics().top; for (int i = 0; i < labels.size(); i++) { final String label = labels.get(i); paint.setTypeface(i == pagePosition ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT); paint.setColor(i == pagePosition ? Color.BLACK : Color.DKGRAY); final float x = viewHalfWidth + (maxWidth + spacing) * (i - pageOffset); final float labelWidth = paint.measureText(label); final float labelHalfWidth = labelWidth / 2; final float labelLeft = x - labelHalfWidth; final float labelVisibleLeft = labelLeft >= 0 ? 1f : 1f - (-labelLeft / labelWidth); final float labelRight = x + labelHalfWidth; final float labelVisibleRight = labelRight < viewWidth ? 1f : 1f - ((labelRight - viewWidth) / labelWidth); final float labelVisible = Math.min(labelVisibleLeft, labelVisibleRight); paint.setAlpha((int) (labelVisible * 255)); canvas.drawText(label, labelLeft, y, paint); } }
From source file:com.ultramegatech.ey.widget.PeriodicTableView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawRect(0, 0, getRight(), getBottom(), mBgPaint); mRect.top = (int) (mBlockSize * 1.3) + mContentRect.top + mContentOffset.y; mRect.left = mBlockSize * 3 + mContentRect.left + mContentOffset.x; mRect.bottom = mRect.top + mBlockSize * 2; mRect.right = mRect.left + mBlockSize * 9; mLegend.drawLegend(canvas, mRect);/*w w w . j ava 2s .com*/ writeHeaders(canvas); writeTitle(canvas); for (PeriodicTableBlock block : mPeriodicTableBlocks) { findBlockPosition(block); if (!isBlockVisible(mRect)) { continue; } mBlockPaint.setColor(block.color); canvas.drawRect(mRect, mBlockPaint); canvas.drawText(block.element.symbol, mRect.left + mBlockSize / 2, mRect.bottom - (int) (mBlockSize / 2.8), mSymbolPaint); canvas.drawText(String.valueOf(block.element.number), mRect.left + mBlockSize / 20, mRect.top + mNumberPaint.getTextSize(), mNumberPaint); canvas.drawText(block.subtext, mRect.left + mBlockSize / 2, mRect.bottom - mBlockSize / 20, mSmallTextPaint); } if (mBlockSelected != null) { mSelectedPaint.setStrokeWidth(mBlockSize / 10); findBlockPosition(mBlockSelected); canvas.drawRect(mRect, mSelectedPaint); } drawEdgeEffects(canvas); }
From source file:com.jjoe64.graphview.GridLabelRenderer.java
/** * draws the horizontal axis title if//w w w . j av a2 s .c o m * it is set * @param canvas canvas */ protected void drawHorizontalAxisTitle(Canvas canvas) { if (mHorizontalAxisTitle != null && mHorizontalAxisTitle.length() > 0) { mPaintAxisTitle.setColor(getHorizontalAxisTitleColor()); mPaintAxisTitle.setTextSize(getHorizontalAxisTitleTextSize()); float x = canvas.getWidth() / 2; float y = canvas.getHeight() - mStyles.padding; canvas.drawText(mHorizontalAxisTitle, x, y, mPaintAxisTitle); } }
From source file:biz.wiz.android.wallet.util.ViewPagerTabs.java
@Override protected void onDraw(final Canvas canvas) { super.onDraw(canvas); final int viewWidth = getWidth(); final int viewHalfWidth = viewWidth / 2; final int viewBottom = getHeight(); final float density = getResources().getDisplayMetrics().density; final float spacing = 32 * density; path.reset();/*w ww . ja va 2 s . c om*/ path.moveTo(viewHalfWidth, viewBottom - 5 * density); path.lineTo(viewHalfWidth + 5 * density, viewBottom); path.lineTo(viewHalfWidth - 5 * density, viewBottom); path.close(); paint.setColor(Color.WHITE); canvas.drawPath(path, paint); paint.setTypeface(Typeface.DEFAULT_BOLD); final float y = getPaddingTop() + -paint.getFontMetrics().top; for (int i = 0; i < labels.size(); i++) { final String label = labels.get(i); paint.setTypeface(i == pagePosition ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT); paint.setColor(i == pagePosition ? Color.BLACK : Color.DKGRAY); final float x = viewHalfWidth + (maxWidth + spacing) * (i - pageOffset); final float labelWidth = paint.measureText(label); final float labelHalfWidth = labelWidth / 2; final float labelLeft = x - labelHalfWidth; final float labelVisibleLeft = labelLeft >= 0 ? 1f : 1f - (-labelLeft / labelWidth); final float labelRight = x + labelHalfWidth; final float labelVisibleRight = labelRight < viewWidth ? 1f : 1f - ((labelRight - viewWidth) / labelWidth); final float labelVisible = Math.min(labelVisibleLeft, labelVisibleRight); paint.setAlpha((int) (labelVisible * 255)); canvas.drawText(label, labelLeft, y, paint); } }
From source file:com.lt.adamlee.aagame.GameView.java
public void about(Canvas c) { int textsize = (int) F.hf(20.0f); Paint p3 = new Paint(); p3.setTypeface(tf);/* w w w . j av a 2s . co m*/ p3.setColor(ViewCompat.MEASURED_STATE_MASK); p3.setFlags(1); p3.setTextSize((float) textsize); Paint pagepaint = new Paint(); pagepaint.setColor(getResources().getColor(R.color.abc_secondary_text_material_light)); c.drawRect(0.0f, 0.0f, (float) screenW, (float) screenH, pagepaint); p3.setTextSize(F.hf(30.0f)); c.drawText(ctx.getString(R.string.about), ((float) (screenW / 2)) - (p3.measureText(ctx.getString(R.string.about)) / 2.0f), (float) (screenH / 4), p3); p3.setTextSize((float) textsize); c.drawText(ctx.getString(R.string.app_name), ((float) (screenW / 2)) - (p3.measureText(ctx.getString(R.string.app_name)) / 2.0f), (float) (((textsize * 2) + 1) + ((screenH - (textsize * 7)) / 2)), p3); c.drawText("License Version 1.7", ((float) (screenW / 2)) - (p3.measureText("License Version 1.7") / 2.0f), (float) (((textsize * 3) + 1) + ((screenH - (textsize * 7)) / 2)), p3); p3.setTextSize(F.hf(17.0f)); c.drawText("Powered by Map Game Studio", ((float) (screenW / 2)) - (p3.measureText("Powered by Map Game Studio") / 2.0f), (float) (((textsize * 4) + 1) + ((screenH - (textsize * 7)) / 2)), p3); p3.setTextSize(F.hf(17.0f)); c.drawText("Email:mapgamestudio@gmail.com", ((float) (screenW / 2)) - (p3.measureText("Email:mapgamestudio@gmail.com") / 2.0f), (float) (((textsize * 5) + 1) + ((screenH - (textsize * 7)) / 2)), p3); }
From source file:com.simadanesh.isatis.ScreenSlideActivity.java
void makeBMP(CalculationResult res) { Bitmap bmp = Bitmap.createBitmap(400, 800, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmp); //canvas.drawARGB(155, 253, 255, 253); canvas.drawARGB(255, 255, 255, 255); Paint p = new Paint(); p.setTypeface(Utility.getNazaninFont()); p.setTextSize(25);//from w w w. ja v a 2 s . c om p.setAntiAlias(true); int y = 20; Drawable d = getResources().getDrawable(R.drawable.abfa); d.setBounds(100, 10, 300, 210); d.draw(canvas); p.setTextAlign(Paint.Align.CENTER); y += 210; canvas.drawText(" ? ", 200, y, p); y += 40; canvas.drawText(" ", 200, y, p); y += 40; canvas.drawText(" ", 200, y, p); y += 40; canvas.drawText(":" + Utility.NowDate(), 200, y, p); y += 40; canvas.drawText("___________________________", 200, y, p); y += 40; canvas.drawText(" :" + res.CustomerNumber, 200, y, p); y += 40; canvas.drawText(" :" + res.Title, 200, y, p); y += 40; canvas.drawText(" :" + Seprate3(res.BillAmount), 200, y, p); y += 40; canvas.drawText(" :" + Seprate3(res.PreviousDebt), 200, y, p); y += 40; Paint p1 = new Paint(); p1.setTypeface(Utility.getNazaninFont()); p1.setARGB(255, 0, 0, 0); p1.setAntiAlias(true); p1.setStrokeWidth(40); p1.setStyle(Paint.Style.STROKE); canvas.drawLine(10, y, 390, y, p1); p.setARGB(255, 255, 255, 255); canvas.drawText(" :" + Seprate3(res.TotalAmount) + " ", 200, y, p); p.setARGB(255, 0, 0, 0); y += 40; canvas.drawText("__________________________", 200, y, p); y += 40; canvas.drawText(" :" + res.BillIdentifier, 200, y, p); y += 40; canvas.drawText(" :" + res.PaymentIdentifier, 200, y, p); /* Path pth = new Path(); pth.addArc(10, 20, 390, 790, 0, 360); p.setColor(Color.argb(20, 10, 10, 10)); p.setTextSize(30); String watermark = ""; for (int i = 0; i < 15; i++) { watermark += " "; } canvas.drawTextOnPath(watermark, pth, 0, 0, p);*/ //File file = new File(getCacheDir()+ "/billing.png"); File file = new File("/sdcard/billing.png"); FileOutputStream outfile; try { outfile = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.PNG, 100, outfile); Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "image/*"); startActivity(intent); } catch (Exception ex) { Log.e("error", ex.toString()); } }
From source file:com.kncwallet.wallet.util.ViewPagerTabs.java
@Override protected void onDraw(final Canvas canvas) { super.onDraw(canvas); final int viewWidth = getWidth(); final int viewHalfWidth = viewWidth / 2; final int viewBottom = getHeight(); final float density = getResources().getDisplayMetrics().density; final float spacing = 32 * density; path.reset();//from www . j av a 2 s . c om path.moveTo(viewHalfWidth, viewBottom - 5 * density); path.lineTo(viewHalfWidth + 5 * density, viewBottom); path.lineTo(viewHalfWidth - 5 * density, viewBottom); path.close(); paint.setColor(Color.TRANSPARENT); canvas.drawPath(path, paint); paint.setTypeface(Typeface.DEFAULT_BOLD); final float y = getPaddingTop() + -paint.getFontMetrics().top; for (int i = 0; i < labels.size(); i++) { final String label = labels.get(i); paint.setTypeface(i == pagePosition ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT); paint.setColor(i == pagePosition ? Color.WHITE : Color.WHITE); final float x = viewHalfWidth + (maxWidth + spacing) * (i - pageOffset); final float labelWidth = paint.measureText(label); final float labelHalfWidth = labelWidth / 2; final float labelLeft = x - labelHalfWidth; final float labelVisibleLeft = labelLeft >= 0 ? 1f : 1f - (-labelLeft / labelWidth); final float labelRight = x + labelHalfWidth; final float labelVisibleRight = labelRight < viewWidth ? 1f : 1f - ((labelRight - viewWidth) / labelWidth); final float labelVisible = Math.min(labelVisibleLeft, labelVisibleRight); paint.setAlpha((int) (labelVisible * 255)); canvas.drawText(label, labelLeft, y, paint); } }
From source file:com.simadanesh.isatis.ScreenSlideActivity.java
void makePDF(CalculationResult res) { PdfDocument doc = new PdfDocument(); PdfDocument.PageInfo inf = new PdfDocument.PageInfo.Builder(400, 800, 1).create(); PdfDocument.Page page = doc.startPage(inf); Canvas canvas = page.getCanvas(); //canvas.drawARGB(155, 253, 255, 253); canvas.drawARGB(255, 255, 255, 255); Paint p = new Paint(); p.setTypeface(Utility.getNazaninFont()); p.setTextSize(25);//from w w w . j ava 2 s.c o m p.setAntiAlias(true); int y = 20; Drawable d = getResources().getDrawable(R.drawable.abfa); d.setBounds(100, 10, 300, 210); d.draw(canvas); p.setTextAlign(Paint.Align.CENTER); y += 210; canvas.drawText(" ? ", 200, y, p); y += 40; canvas.drawText(" ", 200, y, p); y += 40; canvas.drawText(" ", 200, y, p); y += 40; canvas.drawText(":" + Utility.NowDate(), 200, y, p); y += 40; canvas.drawText("___________________________", 200, y, p); y += 40; canvas.drawText(" :" + res.CustomerNumber, 200, y, p); y += 40; canvas.drawText(" :" + res.Title, 200, y, p); y += 40; canvas.drawText(" :" + Seprate3(res.BillAmount), 200, y, p); y += 40; canvas.drawText(" :" + Seprate3(res.PreviousDebt), 200, y, p); y += 40; Paint p1 = new Paint(); p1.setTypeface(Utility.getNazaninFont()); p1.setARGB(255, 0, 0, 0); p1.setAntiAlias(true); p1.setStrokeWidth(40); p1.setStyle(Paint.Style.STROKE); canvas.drawLine(10, y, 390, y, p1); p.setARGB(255, 255, 255, 255); canvas.drawText(" :" + Seprate3(res.TotalAmount) + " ", 200, y, p); p.setARGB(255, 0, 0, 0); y += 40; canvas.drawText("__________________________", 200, y, p); y += 40; canvas.drawText(" :" + res.BillIdentifier, 200, y, p); y += 40; canvas.drawText(" :" + res.PaymentIdentifier, 200, y, p); doc.finishPage(page); //File file = new File(getCacheDir()+ "/billing.png"); File file = new File("/sdcard/billing.pdf"); FileOutputStream outfile; try { outfile = new FileOutputStream(file); //bmp.compress(Bitmap.CompressFormat.PNG, 100, outfile); doc.writeTo(outfile); doc.close(); Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); //intent.setDataAndType(Uri.fromFile(file), "image/*"); intent.setDataAndType(Uri.fromFile(file), "application/pdf"); startActivity(intent); //new RetrieveFeedTask().execute(bmp); } catch (Exception ex) { Log.e("error", ex.toString()); new AlertDialog.Builder(this).setMessage( " ? pdf ? \n https://cafebazaar.ir/app/com.kdanmobile.android.pdfreader.google.pad/?l=fa ") .show(); } }
From source file:org.florescu.android.rangeseekbar.RangeSeekBar.java
/** * Draws the widget on the given canvas. *//*from w w w. j a v a2 s .c om*/ @Override protected synchronized void onDraw(@NonNull Canvas canvas) { super.onDraw(canvas); paint.setTextSize(mTextSize); paint.setStyle(Style.FILL); paint.setColor(mDefaultColor); paint.setAntiAlias(true); float minMaxLabelSize = 0; if (mShowLabels) { // draw min and max labels String minLabel = getContext().getString(R.string.demo_min_label); String maxLabel = getContext().getString(R.string.demo_max_label); minMaxLabelSize = Math.max(paint.measureText(minLabel), paint.measureText(maxLabel)); float minMaxHeight = mTextOffset + mThumbHalfHeight + mTextSize / 3; canvas.drawText(minLabel, 0, minMaxHeight, paint); canvas.drawText(maxLabel, getWidth() - minMaxLabelSize, minMaxHeight, paint); } padding = mInternalPad + minMaxLabelSize; // draw seek bar background line mRect.left = padding; mRect.right = getWidth() - padding; canvas.drawRect(mRect, paint); padding = mThumbHalfWidth + minMaxLabelSize; boolean selectedValuesAreDefault = (getSelectedMinValue().equals(getAbsoluteMinValue()) && getSelectedMaxValue().equals(getAbsoluteMaxValue())); int colorToUseForButtonsAndHighlightedLine = !isEnabled() ? mDefaultColor : (!mAlwaysActive && !mActivateOnDefaultValues && selectedValuesAreDefault ? mDefaultColor : // default values mActiveColor); // non default, filter is active padding = mInternalPad + minMaxLabelSize + (mThumbHalfWidth * 2); // draw seek bar active range line mRect.left = normalizedToScreen(normalizedMinValue) - mThumbHalfWidth; mRect.right = normalizedToScreen(normalizedMaxValue) + mThumbHalfWidth; paint.setColor(colorToUseForButtonsAndHighlightedLine); canvas.drawRect(mRect, paint); // draw minimum thumb (& shadow if requested) if not a single thumb control if (!mSingleThumb) { if (mThumbShadow) { drawThumbShadow(normalizedToScreen(normalizedMinValue), canvas); } drawThumb(normalizedToScreen(normalizedMinValue), Thumb.MIN.equals(pressedThumb), canvas, selectedValuesAreDefault, false); } // draw maximum thumb & shadow (if necessary) if (mThumbShadow) { drawThumbShadow(normalizedToScreen(normalizedMaxValue), canvas); } drawThumb(normalizedToScreen(normalizedMaxValue), Thumb.MAX.equals(pressedThumb), canvas, selectedValuesAreDefault, true); // draw the text if (mShowTextAboveThumbs) { paint.setTextSize(mTextSize); paint.setColor(mTextAboveThumbsColor); drawThumbText(canvas); } }