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:com.android.datetimepicker.time.RadialTextsView.java
/** * Draw the 12 text values at the positions specified by the textGrid parameters. *//*from ww w . jav a 2 s .c om*/ private void drawTexts(Canvas canvas, float textSize, Typeface typeface, String[] texts, float[] textGridWidths, float[] textGridHeights) { mPaint.setTextSize(textSize); mPaint.setTypeface(typeface); Paint[] textPaints = assignTextColors(texts); canvas.drawText(texts[0], textGridWidths[3], textGridHeights[0], textPaints[0]); canvas.drawText(texts[1], textGridWidths[4], textGridHeights[1], textPaints[1]); canvas.drawText(texts[2], textGridWidths[5], textGridHeights[2], textPaints[2]); canvas.drawText(texts[3], textGridWidths[6], textGridHeights[3], textPaints[3]); canvas.drawText(texts[4], textGridWidths[5], textGridHeights[4], textPaints[4]); canvas.drawText(texts[5], textGridWidths[4], textGridHeights[5], textPaints[5]); canvas.drawText(texts[6], textGridWidths[3], textGridHeights[6], textPaints[6]); canvas.drawText(texts[7], textGridWidths[2], textGridHeights[5], textPaints[7]); canvas.drawText(texts[8], textGridWidths[1], textGridHeights[4], textPaints[8]); canvas.drawText(texts[9], textGridWidths[0], textGridHeights[3], textPaints[9]); canvas.drawText(texts[10], textGridWidths[1], textGridHeights[2], textPaints[10]); canvas.drawText(texts[11], textGridWidths[2], textGridHeights[1], textPaints[11]); }
From source file:com.silentcircle.contacts.ContactPhotoManager.java
/** * If necessary, decodes bytes stored in the holder to Bitmap. As long as the * bitmap is held either by {@link #mBitmapCache} or by a soft reference in * the holder, it will not be necessary to decode the bitmap. */// www.j a va2s .c o m private static void inflateBitmap(BitmapHolder holder, int requestedExtent) { final int sampleSize = BitmapUtil.findOptimalSampleSize(holder.originalSmallerExtent, requestedExtent); byte[] bytes = holder.bytes; if (bytes == null || bytes.length == 0) { return; } if (sampleSize == holder.decodedSampleSize) { // Check the soft reference. If will be retained if the bitmap is also // in the LRU cache, so we don't need to check the LRU cache explicitly. if (holder.bitmapRef != null) { holder.bitmap = holder.bitmapRef.get(); if (holder.bitmap != null) { return; } } } try { Bitmap bitmap = BitmapUtil.decodeBitmapFromBytes(bytes, sampleSize); // make bitmap mutable and draw size onto it if (DEBUG_SIZES) { Bitmap original = bitmap; bitmap = bitmap.copy(bitmap.getConfig(), true); original.recycle(); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setTextSize(16); paint.setColor(Color.BLUE); paint.setStyle(Style.FILL); canvas.drawRect(0.0f, 0.0f, 50.0f, 20.0f, paint); paint.setColor(Color.WHITE); paint.setAntiAlias(true); canvas.drawText(bitmap.getWidth() + "/" + sampleSize, 0, 15, paint); } holder.decodedSampleSize = sampleSize; holder.bitmap = bitmap; holder.bitmapRef = new SoftReference<Bitmap>(bitmap); if (DEBUG) { int bCount = (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1) ? bitmap.getRowBytes() * bitmap.getHeight() : bitmap.getByteCount(); Log.d(TAG, "inflateBitmap " + btk(bytes.length) + " -> " + bitmap.getWidth() + "x" + bitmap.getHeight() + ", " + btk(bCount)); } } catch (OutOfMemoryError e) { // Do nothing - the photo will appear to be missing } }
From source file:it.jaschke.alexandria.BarcodeTrackerFactory.java
/** * Draws the barcode annotations for position, size, and raw value on the supplied canvas. *//*w ww. j av a 2 s . c om*/ @Override public void draw(Canvas canvas) { Barcode barcode = mBarcode; if (barcode == null) { return; } // Draws the bounding box around the barcode. RectF rect = new RectF(barcode.getBoundingBox()); rect.left = translateX(rect.left); //rect.top = translateY(rect.top); //rect.right = translateX(rect.right); rect.bottom = translateY(rect.bottom); //canvas.drawRect(rect, mRectPaint); // Draws a label at the bottom of the barcode indicate the barcode value that was detected. canvas.drawText(barcode.rawValue, rect.left, rect.bottom, mTextPaint); sendMessage(barcode.rawValue); }
From source file:com.mojtaba.materialdatetimepicker.time.RadialTextsView.java
/** * Draw the 12 text values at the positions specified by the textGrid parameters. *//*from w w w.j a va 2 s. c o m*/ private void drawTexts(Canvas canvas, float textSize, Typeface typeface, String[] texts, float[] textGridWidths, float[] textGridHeights) { mPaint.setTextSize(textSize); mPaint.setTypeface(typeface); Paint[] textPaints = assignTextColors(LanguageUtils.getPersianNumbers(texts)); canvas.drawText(texts[0], textGridWidths[3], textGridHeights[0], textPaints[0]); canvas.drawText(texts[1], textGridWidths[4], textGridHeights[1], textPaints[1]); canvas.drawText(texts[2], textGridWidths[5], textGridHeights[2], textPaints[2]); canvas.drawText(texts[3], textGridWidths[6], textGridHeights[3], textPaints[3]); canvas.drawText(texts[4], textGridWidths[5], textGridHeights[4], textPaints[4]); canvas.drawText(texts[5], textGridWidths[4], textGridHeights[5], textPaints[5]); canvas.drawText(texts[6], textGridWidths[3], textGridHeights[6], textPaints[6]); canvas.drawText(texts[7], textGridWidths[2], textGridHeights[5], textPaints[7]); canvas.drawText(texts[8], textGridWidths[1], textGridHeights[4], textPaints[8]); canvas.drawText(texts[9], textGridWidths[0], textGridHeights[3], textPaints[9]); canvas.drawText(texts[10], textGridWidths[1], textGridHeights[2], textPaints[10]); canvas.drawText(texts[11], textGridWidths[2], textGridHeights[1], textPaints[11]); }
From source file:cc.chenghong.vkagetorder.material.CircleProgressBar.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mIfDrawText) { String text = String.format("%s%%", mProgress); int x = getWidth() / 2 - text.length() * mTextSize / 4; int y = getHeight() / 2 + mTextSize / 4; canvas.drawText(text, x, y, mTextPaint); }/*from w ww.ja va 2 s . c om*/ }
From source file:com.github.kubatatami.RoundedView.java
private void drawText(Canvas canvas) { Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextSize(getResources().getDimension(R.dimen.item_circle_text_size)); Rect areaRect = new Rect(0, 0, canvas.getWidth(), canvas.getHeight()); RectF bounds = new RectF(areaRect); bounds.right = paint.measureText(text, 0, text.length()); bounds.bottom = paint.descent() - paint.ascent(); bounds.left += (areaRect.width() - bounds.right) / 2.0f; bounds.top += (areaRect.height() - bounds.bottom) / 2.0f; paint.setColor(Color.WHITE);/* w w w . j a v a 2s .c o m*/ canvas.drawText(text, bounds.left, bounds.top - paint.ascent(), paint); }
From source file:pl.mg6.newmaps.demo.MarkersExampleActivity.java
private Bitmap prepareBitmap() { Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.arrow_left); bitmap = bitmap.copy(Config.ARGB_8888, true); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setAntiAlias(true);/*from www. jav a 2 s. c o m*/ paint.setColor(Color.WHITE); paint.setTextAlign(Align.CENTER); paint.setTextSize(getResources().getDimension(R.dimen.text_size)); String text = "mg6"; Rect bounds = new Rect(); paint.getTextBounds(text, 0, text.length(), bounds); float x = bitmap.getWidth() / 2.0f; float y = (bitmap.getHeight() - bounds.height()) / 2.0f - bounds.top; canvas.drawText(text, x, y, paint); return bitmap; }
From source file:com.longle1.facedetection.MainActivity.java
@Override protected void onDraw(Canvas canvas) { Paint paint = new Paint(); paint.setColor(Color.GREEN);//from w w w. j av a 2 s. co m paint.setTextSize(20); String s = "FacePreview - This side up."; float textWidth = paint.measureText(s); canvas.drawText(s, (getWidth() - textWidth) / 2, 20, paint); if (faces != null) { paint.setStrokeWidth(5); paint.setStyle(Paint.Style.STROKE); float scaleX = (float) getWidth() / grayImage.width(); float scaleY = (float) getHeight() / grayImage.height(); int total = faces.total(); for (int i = 0; i < total; i++) { CvRect r = new CvRect(cvGetSeqElem(faces, i)); int x = r.x(), y = r.y(), w = r.width(), h = r.height(); canvas.drawRect(x * scaleX, y * scaleY, (x + w) * scaleX, (y + h) * scaleY, paint); } } }
From source file:com.hgdendi.contactslist.common.IndexBar.java
protected void onDraw(Canvas canvas) { super.onDraw(canvas); int height = getHeight(); int width = getWidth(); if (height == 0) { return;/*from w w w . j a va 2s . com*/ } int singleHeight = height / mNavigators.size(); for (int i = 0; i < mNavigators.size(); i++) { float xPos = width / 2 - mPaint.measureText(mNavigators.get(i)) / 2; float yPos = singleHeight * (i + 1); if (i == mFocusIndex) { canvas.drawText(mNavigators.get(i), xPos, yPos - mBaseLineHeight, mFocusPaint); } else { canvas.drawText(mNavigators.get(i), xPos, yPos - mBaseLineHeight, mPaint); } } }
From source file:com.google.android.gms.samples.vision.face.facetracker.FaceGraphic.java
/** * Draws the face annotations for position on the supplied canvas. */// w w w.j a v a2 s . co m @Override public void draw(Canvas canvas) { Face face = mFace; if (face == null) { return; } // Draws a circle at the position of the detected face, with the face's track id below. float x = translateX(face.getPosition().x + face.getWidth() / 2); float y = translateY(face.getPosition().y + face.getHeight() / 2); canvas.drawCircle(x, y, FACE_POSITION_RADIUS, mFacePositionPaint); canvas.drawText("id: " + mFaceId, x + ID_X_OFFSET, y + ID_Y_OFFSET, mIdPaint); canvas.drawText("happiness: " + String.format("%.2f", face.getIsSmilingProbability()), x - ID_X_OFFSET, y - ID_Y_OFFSET, mIdPaint); canvas.drawText("right eye: " + String.format("%.2f", face.getIsRightEyeOpenProbability()), x + ID_X_OFFSET * 2, y + ID_Y_OFFSET * 2, mIdPaint); canvas.drawText("left eye: " + String.format("%.2f", face.getIsLeftEyeOpenProbability()), x - ID_X_OFFSET * 2, y - ID_Y_OFFSET * 2, mIdPaint); try { Thread.sleep(1000); } catch (Exception e) { System.out.println("SLEEP EXCEPTION: " + e.getMessage()); } String happiness = String.format("%.2f", face.getIsSmilingProbability()); new RetrieveFeedTask().execute(happiness); // Draws a bounding box around the face. float xOffset = scaleX(face.getWidth() / 2.0f); float yOffset = scaleY(face.getHeight() / 2.0f); float left = x - xOffset; float top = y - yOffset; float right = x + xOffset; float bottom = y + yOffset; canvas.drawRect(left, top, right, bottom, mBoxPaint); }