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.gallery3d.data.UriImage.java
public Bitmap drawTextToBitmap(Context gContext, String gText, Bitmap bitmap) { Resources resources = gContext.getResources(); float scale = resources.getDisplayMetrics().density; android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig(); // set default bitmap config if none if (bitmapConfig == null) { bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888; }/* w ww . j a v a 2 s . c om*/ // resource bitmaps are imutable, // so we need to convert it to mutable one bitmap = bitmap.copy(bitmapConfig, true); Canvas canvas = new Canvas(bitmap); // new antialised Paint Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); // text color - #3D3D3D paint.setColor(Color.rgb(61, 61, 61)); // text size in pixels paint.setTextSize((int) (25 * scale)); // text shadow paint.setShadowLayer(1f, 0f, 1f, Color.WHITE); // draw text to the Canvas center Rect bounds = new Rect(); paint.setTextAlign(Align.CENTER); paint.getTextBounds(gText, 0, gText.length(), bounds); int x = (bitmap.getWidth() - bounds.width()) / 2; int y = (bitmap.getHeight() + bounds.height()) / 2; canvas.drawText(gText, x * scale, y * scale, paint); return bitmap; }
From source file:app.android.datetimepicker.date.SimpleMonthView.java
private void drawMonthDayLabels(Canvas canvas) { int y = MONTH_HEADER_SIZE - (MONTH_DAY_LABEL_TEXT_SIZE / 2); int dayWidthHalf = (mWidth - mPadding * 2) / (mNumDays * 2); for (int i = 0; i < mNumDays; i++) { int calendarDay = (i + mWeekStart) % mNumDays; int x = (2 * i + 1) * dayWidthHalf + mPadding; mDayLabelCalendar.set(Calendar.DAY_OF_WEEK, calendarDay); canvas.drawText( mDayLabelCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, Locale.getDefault()) .toUpperCase(Locale.getDefault()), x, y, mMonthDayLabelPaint); }/*from w ww. j a v a 2 s . c o m*/ }
From source file:net.networksaremadeofstring.rhybudd.RhybuddDock.java
private void drawGaugeTitle(Canvas canvas, String Title) { Paint titlePaint = new Paint(); titlePaint.setStyle(Paint.Style.FILL_AND_STROKE); titlePaint.setColor(Color.LTGRAY);//0x9f004d0f titlePaint.setStrokeWidth(1);//0.005f titlePaint.setAntiAlias(true);/*from w ww.j a v a 2 s .c o m*/ titlePaint.setTextSize(14); titlePaint.setTypeface(Typeface.createFromAsset(this.getAssets(), "fonts/chivo.ttf")); /*Path titlePath = new Path(); titlePath.addArc(new RectF(40, 90, 196, 155), -180.0f, -180.0f); canvas.drawTextOnPath(Title, titlePath, 0.0f,0.0f, titlePaint);*/ canvas.drawText(Title, 60, 160, titlePaint); }
From source file:hide.com.android.datetimepicker.date.SimpleMonthView.java
private void drawMonthDayLabels(Canvas canvas) { int y = MONTH_HEADER_SIZE - (MONTH_DAY_LABEL_TEXT_SIZE / 2); int dayWidthHalf = (mWidth - mPadding * 2) / (mNumDays * 2); for (int i = 0; i < mNumDays; i++) { int calendarDay = (i + mWeekStart) % mNumDays; int x = (2 * i + 1) * dayWidthHalf + mPadding; mDayLabelCalendar.set(Calendar.DAY_OF_WEEK, calendarDay); canvas.drawText(Utils.getShortDayOfWeekName(mDayLabelCalendar).toUpperCase(Locale.getDefault()), x, y, mMonthDayLabelPaint);//from ww w.java 2s . c o m } }
From source file:com.redinput.datetimepickercompat.date.SimpleMonthView.java
private void drawMonthDayLabels(Canvas canvas) { int y = MONTH_HEADER_SIZE - (MONTH_DAY_LABEL_TEXT_SIZE / 2); int dayWidthHalf = (mWidth - mPadding * 2) / (mNumDays * 2); for (int i = 0; i < mNumDays; i++) { int calendarDay = (i + mWeekStart) % mNumDays; int x = (2 * i + 1) * dayWidthHalf + mPadding; mDayLabelCalendar.set(Calendar.DAY_OF_WEEK, calendarDay); canvas.drawText( new DateFormatSymbols(Locale.getDefault()).getWeekdays()[mDayLabelCalendar .get(Calendar.DAY_OF_WEEK)].toUpperCase(Locale.getDefault()).substring(0, 3), x, y, mMonthDayLabelPaint); }/* w w w . ja v a 2 s . co m*/ }
From source file:com.android.yijiang.kzx.widget.betterpickers.calendardatepicker.SimpleMonthView.java
private void drawMonthDayLabels(Canvas canvas) { int y = sMonthHeaderSize - (sMonthDayLabelTextSize / 2); int dayWidthHalf = (mWidth - mPadding * 2) / (mNumDays * 2); for (int i = 0; i < mNumDays; i++) { int calendarDay = (i + mWeekStart) % mNumDays; int x = (2 * i + 1) * dayWidthHalf + mPadding; mDayLabelCalendar.set(Calendar.DAY_OF_WEEK, calendarDay); canvas.drawText( mDayLabelCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, Locale.getDefault()) .toUpperCase(Locale.getDefault()), x, y, mMonthDayLabelPaint); }// ww w. j ava 2s. co m }
From source file:nu.yona.app.customview.graph.TimeFrameGraph.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); RectF myRectum = new RectF(left, top, right, bottom); canvas.drawRect(myRectum, linePaint); //todraw text from height float heightDraw = bottom + (GraphUtils.MARGIN_TOP * scaleFactor); Bitmap moonBitmap = drawableToBitmap(ContextCompat.getDrawable(mContext, R.drawable.icon_moon)); float bitmapWidth = moonBitmap.getWidth() / 2; //draw graphics of sun and moon canvas.drawBitmap(moonBitmap, mStartPoint - (5 * scaleFactor), bottom + (5 * scaleFactor), null); canvas.drawBitmap(drawableToBitmap(ContextCompat.getDrawable(mContext, R.drawable.icn_sun)), mMiddlePoint - bitmapWidth, bottom + (5 * scaleFactor), null); float textPoint = (mMiddlePoint / 2) / 2; canvas.drawText(mContext.getString(R.string.four_hours), textPoint, heightDraw, getFontStyle()); float textPoint2 = textPoint * 2 + ((textPoint / 2)); canvas.drawText(mContext.getString(R.string.eight_hours), textPoint2, heightDraw, getFontStyle()); float textPoint3 = textPoint * 5; canvas.drawText(mContext.getString(R.string.sixteen_hours), textPoint3 - bitmapWidth, heightDraw, getFontStyle());/*from ww w .ja va2 s. c o m*/ float textPoint4 = textPoint * 6 + ((textPoint / 2)); canvas.drawText(mContext.getString(R.string.twenty_hours), textPoint4 - bitmapWidth, heightDraw, getFontStyle()); float textPoint5 = textPoint * 7 + ((textPoint / 2)) - (scaleFactor * 2); canvas.drawBitmap(drawableToBitmap(ContextCompat.getDrawable(mContext, R.drawable.icon_moon)), textPoint5, bottom + (5 * scaleFactor), null); for (GraphData graphData : graphDataList) { graphData.draw(canvas, top, bottom, endPoint); } }
From source file:com.cssweb.android.view.FinanceMini.java
public void drawHKIndex(Canvas canvas) { Paint paint = this.mPaint; paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true);// ww w. ja v a 2 s. co m if (quoteData != null) { try { JSONArray jArr = quoteData.getJSONArray("data"); JSONObject jo = jArr.getJSONObject(0); paint.setTextAlign(Paint.Align.LEFT); paint.setTextSize(mTextSize); paint.setColor(GlobalColor.colorLabelName); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); paint.setTextAlign(Paint.Align.RIGHT); canvas.translate(width, -DY * 3); paint.setColor(GlobalColor.colorpriceUp); canvas.translate(0, DY); canvas.drawText(String.valueOf(jo.getInt("zj")), x - tips, y, paint); paint.setColor(GlobalColor.colorPriceEqual); canvas.translate(0, DY); canvas.drawText(String.valueOf(jo.getInt("pj")), x - tips, y, paint); paint.setColor(GlobalColor.colorPriceDown); canvas.translate(0, DY); canvas.drawText(String.valueOf(jo.getInt("dj")), x - tips, y, paint); } catch (JSONException e) { Log.e(TAG, e.toString()); } } }
From source file:com.appyvet.rangebar.PinView.java
@Override public void draw(Canvas canvas) { canvas.drawCircle(mX, mY, mCircleRadiusPx, mCirclePaint); //Draw pin if pressed if (mPinRadiusPx > 0) { mBounds.set((int) mX - mPinRadiusPx, (int) mY - (mPinRadiusPx * 2) - (int) mPinPadding, (int) mX + mPinRadiusPx, (int) mY - (int) mPinPadding); mPin.setBounds(mBounds);//from w ww . j a v a2 s.c om String text = mValue; if (this.formatter != null) { text = formatter.format(text); } calibrateTextSize(mTextPaint, text, mBounds.width()); mTextPaint.getTextBounds(text, 0, text.length(), mBounds); mTextPaint.setTextAlign(Paint.Align.CENTER); mPin.setColorFilter(mPinFilter); mPin.draw(canvas); canvas.drawText(text, mX, mY - mPinRadiusPx - mPinPadding + mTextYPadding, mTextPaint); } super.draw(canvas); }
From source file:com.dgmltn.ranger.internal.PinView.java
@Override public void draw(Canvas canvas) { super.draw(canvas); canvas.drawCircle(mPosition.x, mPosition.y, mCircleRadiusPx, mCirclePaint); // Draw pin if pressed if (mPinRadiusPx > 0) { mBounds.set((int) mPosition.x - mPinRadiusPx, (int) mPosition.y - (mPinRadiusPx * 2) - (int) mPinPadding, (int) mPosition.x + mPinRadiusPx, (int) mPosition.y - (int) mPinPadding); mPin.setBounds(mBounds);/*from w w w.ja v a2 s . c om*/ String text = mLabel; calibrateTextSize(mTextPaint, text, mBounds.width()); mTextPaint.getTextBounds(text, 0, text.length(), mBounds); mTextPaint.setTextAlign(Paint.Align.CENTER); mPin.setColorFilter(mPinFilter); mPin.draw(canvas); canvas.drawText(text, mPosition.x, mPosition.y - mPinRadiusPx - mPinPadding + mTextYPadding, mTextPaint); } }