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.jjoe64.graphview.GridLabelRenderer.java
/** * draws the vertical axis title if// w w w . j a v a2 s. co m * it is set * @param canvas canvas */ protected void drawVerticalAxisTitle(Canvas canvas) { if (mVerticalAxisTitle != null && mVerticalAxisTitle.length() > 0) { mPaintAxisTitle.setColor(getVerticalAxisTitleColor()); mPaintAxisTitle.setTextSize(getVerticalAxisTitleTextSize()); float x = getVerticalAxisTitleWidth(); float y = canvas.getHeight() / 2; canvas.save(); canvas.rotate(-90, x, y); canvas.drawText(mVerticalAxisTitle, x, y, mPaintAxisTitle); canvas.restore(); } }
From source file:de.uni_weimar.mheinz.androidtouchscope.display.ScopeView.java
@Override protected void onDraw(Canvas canvas) { mDrawableChan1.getPaint().clearShadowLayer(); mDrawableChan1.getPaint().setStrokeWidth(1); mDrawableChan2.getPaint().clearShadowLayer(); mDrawableChan2.getPaint().setStrokeWidth(1); switch (mSelectedPath) { case 1:/*from ww w . j av a 2s .c om*/ mDrawableChan1.getPaint().setShadowLayer(10f, 0f, 0f, HostView.CHAN1_COLOR); mDrawableChan1.getPaint().setStrokeWidth(1.5f); break; case 2: mDrawableChan2.getPaint().setShadowLayer(10f, 0f, 0f, HostView.CHAN2_COLOR); mDrawableChan2.getPaint().setStrokeWidth(1.5f); break; default: break; } mDrawableChan1.draw(canvas); mDrawableChan2.draw(canvas); mDrawableGridH.draw(canvas); mDrawableGridV.draw(canvas); canvas.drawText(mChan1Text, mTextPos.x, mTextPos.y, mChan1TextPaint); canvas.drawText(mChan1OffsetText, mTextPos.x, mTextPos.y - 20, mChan1TextPaint); canvas.drawText(mChan2Text, mTextPos.x + 150, mTextPos.y, mChan2TextPaint); canvas.drawText(mChan2OffsetText, mTextPos.x + 150, mTextPos.y - 20, mChan2TextPaint); canvas.drawText(mTimeOffsetText, mContentWidth - 5, mTextPos.y, mTimeOffsetTextPaint); canvas.drawText(mTimeText, mContentWidth - 100, mTextPos.y, mTimeTextPaint); if (mPrevTrig != null) { if (mPrevTrig.source == TriggerData.TriggerSrc.CHAN1) mTriggerTextPaint.setColor(HostView.CHAN1_COLOR); else if (mPrevTrig.source == TriggerData.TriggerSrc.CHAN2) mTriggerTextPaint.setColor(HostView.CHAN2_COLOR); else mTriggerTextPaint.setColor(HostView.TRIGGER_COLOR); } canvas.drawText(mTriggerText, mContentWidth - 5, 20, mTriggerTextPaint); canvas.drawText(mCursorText, mTextPos.x, 20, mCursorTextPaint); super.onDraw(canvas); }
From source file:com.appeaser.sublimepickerlibrary.datepicker.SimpleMonthView.java
private void drawDaysOfWeek(Canvas canvas) { final TextPaint p = mDayOfWeekPaint; final int headerHeight = mMonthHeight; final int rowHeight = mDayOfWeekHeight; final int colWidth = mCellWidth; // Text is vertically centered within the day of week height. final float halfLineHeight = (p.ascent() + p.descent()) / 2f; final int rowCenter = headerHeight + rowHeight / 2; for (int col = 0; col < DAYS_IN_WEEK; col++) { final int colCenter = colWidth * col + colWidth / 2; final int colCenterRtl; if (SUtils.isLayoutRtlCompat(this)) { colCenterRtl = mPaddedWidth - colCenter; } else {//from ww w. j a va 2 s . co m colCenterRtl = colCenter; } final int dayOfWeek = (col + mWeekStart) % DAYS_IN_WEEK; final String label = getDayOfWeekLabel(dayOfWeek); canvas.drawText(label, colCenterRtl, rowCenter - halfLineHeight, p); } }
From source file:com.lt.adamlee.aagame.GameView.java
public void help(Canvas c) { String x = ""; float textsize = F.hf(19.0f); Paint p4 = new Paint(); Paint p5 = new Paint(); Paint p6 = new Paint(); String text = ctx.getString(R.string.helptext); p4.setColor(getResources().getColor(R.color.bright_foreground_inverse_material_light)); p4.setFlags(1);//from w ww .ja va2 s . c om p5.setTypeface(tf); p5.setTextSize(F.hf(30.0f)); p6.setTextSize(textsize); p5.setColor(ViewCompat.MEASURED_STATE_MASK); c.drawRect(0.0f, 0.0f, (float) screenW, (float) screenH, p4); c.drawText(ctx.getString(R.string.help), ((float) (screenW / 2)) - (p5.measureText(ctx.getString(R.string.help)) / 2.0f), (float) (screenH / 8), p5); int i = 0; int xv1 = 0; int yv1 = (int) textsize; while (i < ctx.getString(R.string.helptext).length()) { if (text.charAt(i) != '$') { c.drawText(" " + ctx.getString(R.string.helptext).charAt(i), (float) xv1, ((float) ((screenH / 8) + yv1)) + (4.0f * textsize), p6); xv1 = (int) (((float) xv1) + p6.measureText(Character.toString(ctx.getString(R.string.helptext).charAt(i)))); } if (ctx.getString(R.string.helptext).charAt(i) == '$') { i++; x = " "; yv1 = (int) (((float) yv1) + textsize); xv1 = 0; } i++; } }
From source file:net.networksaremadeofstring.rhybudd.RhybuddDock.java
private void drawScale(Canvas canvas, Boolean Colors, int Count, int Max) { RectF faceRect = new RectF(); faceRect.set(10, 10, 190, 190);/*from w w w .ja v a 2s . c o m*/ Paint scalePaint = new Paint(); scalePaint.setStyle(Paint.Style.STROKE); scalePaint.setColor(getResources().getColor(R.color.WarningGreen)); scalePaint.setStrokeWidth(1); scalePaint.setAntiAlias(true); scalePaint.setTextSize(12); scalePaint.setTypeface(Typeface.createFromAsset(this.getAssets(), "fonts/chivo.ttf")); scalePaint.setTextAlign(Paint.Align.CENTER); float scalePosition = 10; RectF scaleRect = new RectF(); scaleRect.set(faceRect.left + scalePosition, faceRect.top + scalePosition, faceRect.right - scalePosition, faceRect.bottom - scalePosition); if (!Colors) scalePaint.setColor(Color.WHITE); scalePaint.setStrokeWidth(2); canvas.save(Canvas.MATRIX_SAVE_FLAG); for (int i = 0; i < Max; ++i) { if (Colors) { if (i > 20) scalePaint.setColor(getResources().getColor(R.color.WarningYellow)); if (i > 40) scalePaint.setColor(getResources().getColor(R.color.WarningOrange)); if (i > 60) scalePaint.setColor(getResources().getColor(R.color.WarningRed)); } canvas.drawLine(100, 20, 100, 18, scalePaint); int divisor = 5; if (Max > 100) divisor = 25; if (i % divisor == 0) { canvas.drawText(Integer.toString(i), 100, 16, scalePaint); } canvas.rotate((360.0f / Max), 100, 100); } canvas.restore(); }
From source file:cn.com.hgh.view.SlideSwitch.java
@Override protected void onDraw(Canvas canvas) { if (shape == SHAPE_RECT) { // paint.setColor(Color.GRAY); paint.setColor(0xffededed);// canvas.drawRect(backRect, paint); paint.setColor(color_theme);/* w ww . ja v a2 s. c om*/ paint.setAlpha(alpha); canvas.drawRect(backRect, paint); frontRect.set(frontRect_left, RIM_SIZE, frontRect_left + getMeasuredWidth() / 2 - RIM_SIZE, getMeasuredHeight() - RIM_SIZE); paint.setColor(Color.WHITE); canvas.drawRect(frontRect, paint); } else { int radius; radius = backRect.height() / 2 - RIM_SIZE; // paint.setColor(Color.GRAY);// paint.setColor(0xffededed);// backCircleRect.set(backRect); canvas.drawRoundRect(backCircleRect, radius, radius, paint); paint.setColor(Color.BLACK); paint.setTextSize(AbViewUtil.sp2px(getContext(), 15)); // paint.setAlpha(alpha); frontRect.set(frontRect_left, RIM_SIZE, frontRect_left + getMeasuredWidth() / 2 - RIM_SIZE, getMeasuredHeight() - RIM_SIZE); frontCircleRect.set(frontRect); paint.setColor(Color.WHITE); canvas.drawRoundRect(frontCircleRect, radius, radius, paint); if (isOpen) { // canvas.drawText("?", radius, radius + 23, paint);// paint.setColor(Color.BLACK); paint.setTextAlign(Paint.Align.CENTER); canvas.drawText("?", width / 4 - RIM_SIZE, radius + 23, paint);// } else { // canvas.drawText("?", getMeasuredWidth() - radius - 40 * 3,radius + 23, paint); paint.setColor(Color.BLACK); paint.setTextAlign(Paint.Align.CENTER); canvas.drawText("?", width - frontCircleRect.width() / 2 - RIM_SIZE, radius + 23, paint); } if (isOpen) { paint.setColor(0xff14c4c4); paint.setTextAlign(Paint.Align.CENTER); paint.getTextBounds("?", 0, "?".length(), frontRect); paint.setTextSize(AbViewUtil.sp2px(getContext(), 15)); // paint.setAlpha(alpha1); // canvas.drawText("?", getMeasuredWidth() - radius - 40 * 3,radius + 23, paint); canvas.drawText("?", frontCircleRect.centerX(), radius + 23, paint); } else { paint.setColor(0xff14c4c4); paint.setTextAlign(Paint.Align.CENTER); paint.getTextBounds("?", 0, "?".length(), frontRect); paint.setTextSize(AbViewUtil.sp2px(getContext(), 15)); // paint.setAlpha(alpha1); // canvas.drawText("?", radius, radius + 23, paint); canvas.drawText("?", frontCircleRect.centerX(), radius + 23, paint); } } }
From source file:ir.hatamiarash.calendar.view.QiblaCompassView.java
public void drawDial(Canvas canvas) { // over here//from ww w. j ava2s .c om circlePaint.reset(); circlePaint.setColor(ContextCompat.getColor(getContext(), R.color.qibla_color)); circlePaint.setStrokeWidth(1); circlePaint.setStyle(Paint.Style.STROKE); // Sadece Cember ciziyor. int textHeight = (int) textPaint.measureText("yY"); markerPaint.reset(); markerPaint.setColor(ContextCompat.getColor(getContext(), R.color.qibla_color)); // Draw the background canvas.drawCircle(px, py, Radius, circlePaint); canvas.drawCircle(px, py, Radius - 20, circlePaint); // Rotate our perspective so that the "top" is // facing the current bearing. int textWidth = (int) textPaint.measureText("W"); int cardinalX = px - textWidth / 2; int cardinalY = py - Radius + textHeight; // Draw the marker every 15 degrees and text every 45. for (int i = 0; i < 24; i++) { // Draw a marker. canvas.drawLine(px, py - Radius, px, py - Radius + 10, markerPaint); canvas.save(); canvas.translate(0, textHeight); // Draw the cardinal points if (i % 6 == 0) { String dirString = ""; switch (i) { case (0): { dirString = northString; break; } case (6): dirString = eastString; break; case (12): dirString = southString; break; case (18): dirString = westString; break; } canvas.drawText(dirString, cardinalX, cardinalY, textPaint); } else if (i % 3 == 0) { // Draw the text every alternate 45deg String angle = String.valueOf(i * 15); float angleTextWidth = textPaint.measureText(angle); int angleTextX = (int) (px - angleTextWidth / 2); int angleTextY = py - Radius + textHeight; canvas.drawText(angle, angleTextX, angleTextY, textPaint); } canvas.restore(); canvas.rotate(15, px, py); } }
From source file:com.byagowi.persiancalendar.view.QiblaCompassView.java
public void drawDial(Canvas canvas) { // over here// w ww . jav a 2s . c o m circlePaint.reset(); circlePaint.setColor(ContextCompat.getColor(getContext(), R.color.qibla_color)); circlePaint.setStrokeWidth(1); circlePaint.setStyle(Paint.Style.STROKE); // Sadece Cember ciziyor. int textHeight = (int) textPaint.measureText("yY"); markerPaint.reset(); markerPaint.setColor(ContextCompat.getColor(getContext(), R.color.qibla_color)); // Draw the background canvas.drawCircle(px, py, Radius, circlePaint); canvas.drawCircle(px, py, Radius - 20, circlePaint); // Rotate our perspective so that the "top" is // facing the current bearing. int textWidth = (int) textPaint.measureText("W"); int cardinalX = px - textWidth / 2; int cardinalY = py - Radius + textHeight; // Draw the marker every 15 degrees and text every 45. for (int i = 0; i < 24; i++) { // Draw a marker. canvas.drawLine(px, py - Radius, px, py - Radius + 10, markerPaint); canvas.save(); canvas.translate(0, textHeight); // Draw the cardinal points if (i % 6 == 0) { String dirString = ""; switch (i) { case (0): { dirString = northString; break; } case (6): dirString = eastString; break; case (12): dirString = southString; break; case (18): dirString = westString; break; } canvas.drawText(dirString, cardinalX, cardinalY, textPaint); } else if (i % 3 == 0) { // Draw the text every alternate 45deg String angle = String.valueOf(i * 15); float angleTextWidth = textPaint.measureText(angle); int angleTextX = (int) (px - angleTextWidth / 2); int angleTextY = py - Radius + textHeight; canvas.drawText(angle, angleTextX, angleTextY, textPaint); } canvas.restore(); canvas.rotate(15, px, py); } }
From source file:org.appspot.apprtc.util.ThumbnailsCacheManager.java
public static void LoadImage(final String url, ImageView image, final String displayname, final boolean rounded, boolean fromCache) { final WeakReference<ImageView> imageView = new WeakReference<ImageView>(image); final Handler uiHandler = new Handler(); final int FG_COLOR = 0xFFFAFAFA; final String name = displayname; if (fromCache) { Bitmap bitmap = ThumbnailsCacheManager.getBitmapFromDiskCache(url); if (bitmap != null) { if (rounded) { RoundedBitmapDrawable roundedBitmap = RoundedBitmapDrawableFactory .create(imageView.get().getResources(), bitmap); roundedBitmap.setCircular(true); imageView.get().setImageDrawable(roundedBitmap); } else { imageView.get().setImageBitmap(bitmap); }//from w w w . ja v a 2 s . co m imageView.get().setContentDescription(displayname); return; } } AsyncHttpURLConnection httpConnection = new AsyncHttpURLConnection("GET", url, "", new AsyncHttpURLConnection.AsyncHttpEvents() { @Override public void onHttpError(String errorMessage) { Log.d("LoadImage", errorMessage); } @Override public void onHttpComplete(String response) { int size = 96; Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); final String trimmedName = name == null ? "" : name.trim(); drawTile(canvas, trimmedName, 0, 0, size, size); ThumbnailsCacheManager.addBitmapToCache(url, bitmap); onHttpComplete(bitmap); } @Override public void onHttpComplete(final Bitmap response) { if (imageView != null && imageView.get() != null) { uiHandler.post(new Runnable() { @Override public void run() { if (imageView.get() != null) { if (rounded) { RoundedBitmapDrawable roundedBitmap = RoundedBitmapDrawableFactory .create(imageView.get().getResources(), response); roundedBitmap.setCircular(true); imageView.get().setImageDrawable(roundedBitmap); } else { imageView.get().setImageBitmap(response); } imageView.get().setContentDescription(displayname); } } }); } } private boolean drawTile(Canvas canvas, String letter, int tileColor, int left, int top, int right, int bottom) { letter = letter.toUpperCase(Locale.getDefault()); Paint tilePaint = new Paint(), textPaint = new Paint(); tilePaint.setColor(tileColor); textPaint.setFlags(Paint.ANTI_ALIAS_FLAG); textPaint.setColor(FG_COLOR); textPaint.setTypeface(Typeface.create("sans-serif-light", Typeface.NORMAL)); textPaint.setTextSize((float) ((right - left) * 0.8)); Rect rect = new Rect(); canvas.drawRect(new Rect(left, top, right, bottom), tilePaint); textPaint.getTextBounds(letter, 0, 1, rect); float width = textPaint.measureText(letter); canvas.drawText(letter, (right + left) / 2 - width / 2, (top + bottom) / 2 + rect.height() / 2, textPaint); return true; } private boolean drawTile(Canvas canvas, String name, int left, int top, int right, int bottom) { if (name != null) { final String letter = getFirstLetter(name); final int color = ThumbnailsCacheManager.getColorForName(name); drawTile(canvas, letter, color, left, top, right, bottom); return true; } return false; } }); httpConnection.setBitmap(); httpConnection.send(); }
From source file:com.cssweb.android.view.TrendView.java
private void drawTimeX(Canvas canvas) { mpaint.setColor(GlobalColor.colorLabelName); mpaint.setTextAlign(Paint.Align.LEFT); if ("hk".equals(exchange)) { stime = "09:30"; etime = "16:00"; } else if ("cf".equals(exchange)) { stime = "09:15"; etime = "15:15"; } else if ("dc".equals(exchange) || "sf".equals(exchange) || "cz".equals(exchange)) { stime = "09:00"; etime = "15:00"; } else {//from w w w.j av a 2s .c om stime = "09:30"; etime = "15:00"; } canvas.drawText(stime, LSpace, graphicsQuoteHeight + topTitleHeight + axisLabelHeight, mpaint); //mpaint.setTextAlign(Paint.Align.CENTER); //canvas.drawText("11:30", graphicsQuoteWidth/2 + LSpace, graphicsQuoteHeight + topTitleHeight + axisLabelHeight, mpaint); mpaint.setTextAlign(Paint.Align.RIGHT); canvas.drawText(etime, width, graphicsQuoteHeight + topTitleHeight + axisLabelHeight, mpaint); }