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:im.ene.ribbon.FixedActionTabView.java
@Override protected void onDraw(final Canvas canvas) { super.onDraw(canvas); canvas.save();/* www .j ava 2s.c om*/ canvas.translate(0, iconTranslation); icon.draw(canvas); drawBadge(canvas); canvas.restore(); canvas.save(); canvas.scale(canvasTextScale, canvasTextScale, textCenterX, textCenterY); canvas.drawText(getAction().getTitle(), textX, textY, textPaint); canvas.restore(); }
From source file:com.nick.documents.widget.FlexibleImageView.java
@Override protected void onDraw(@NonNull Canvas canvas) { super.onDraw(canvas); if (mHasText) { 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 . j a va 2s.c om }
From source file:jp.co.ipublishing.esnavi.views.MarqueeView.java
/** * ???/*from w ww. j a v a2s . c om*/ * * @param canvas ? */ @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); final int ascent = (int) mTextPaint.ascent(); final int x = getPaddingLeft() + mCurrentX; final int y = getPaddingTop() - ascent; canvas.drawText(mText, x, y, mTextPaint); }
From source file:net.networksaremadeofstring.rhybudd.ZenossWidgetGraph.java
@SuppressWarnings("unused") private Bitmap RenderLineGraph() { Bitmap emptyBmap = Bitmap.createBitmap(290, 150, Config.ARGB_8888); int width = emptyBmap.getWidth(); int height = emptyBmap.getHeight(); Bitmap charty = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(charty); final int color = 0xff0B0B61; final Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.WHITE);/* w ww . j a va 2s . c o m*/ //if(warningEvents > ) canvas.drawText("100", 0, 10, paint); //y canvas.drawLine(25, 0, 25, 289, paint); //x canvas.drawLine(25, 149, 289, 149, paint); int CritArray[] = { 5, 4, 6, 10, 10, 6, 4, 4 }; int curX = 25; int divisor = 148 / 10; paint.setColor(Color.RED); int curY = 148 - (CritArray[0] * divisor); for (int a : CritArray) { canvas.drawLine(curX, curY, curX + 32, (148 - (a * divisor)), paint); curX += 32; curY = 148 - (a * divisor); } int ErrArray[] = { 1, 2, 2, 2, 4, 2, 1, 0 }; curX = 25; paint.setColor(Color.rgb(255, 102, 0)); curY = 148 - (ErrArray[0] * divisor); for (int a : ErrArray) { canvas.drawLine(curX, curY, curX + 32, (148 - (a * divisor)), paint); curX += 32; curY = 148 - (a * divisor); } int WarnArray[] = { 0, 2, 4, 8, 10, 4, 2, 2 }; curX = 25; paint.setColor(Color.YELLOW); curY = 148 - (WarnArray[0] * divisor); Path myPath = new Path(); for (int a : WarnArray) { canvas.drawLine(curX, curY, curX + 32, (148 - (a * divisor)), paint); curX += 32; curY = 148 - (a * divisor); } ByteArrayOutputStream out = new ByteArrayOutputStream(); charty.compress(CompressFormat.PNG, 50, out); return BitmapFactory.decodeByteArray(out.toByteArray(), 0, out.size()); }
From source file:iSoron.HistoryChart.java
private void drawAxis(Canvas canvas, RectF location) { float verticalOffset = pTextHeader.getFontSpacing() * 0.4f; for (String day : DateUtils.getLocaleDayNames(Calendar.SHORT)) { location.offset(0, columnWidth); canvas.drawText(day, location.left + headerTextOffset, location.centerY() + verticalOffset, pTextHeader);//from w w w . ja va 2 s . c o m } }
From source file:foam.starwisp.DrawableMap.java
public Marker AddText(final LatLng location, final String text, final int padding, final int fontSize, int colour) { Marker marker = null;/* w w w . j a va 2 s . co m*/ final TextView textView = new TextView(m_Context); textView.setText(text); textView.setTextSize(fontSize); textView.setTypeface(m_Context.m_Typeface); final Paint paintText = textView.getPaint(); final Rect boundsText = new Rect(); paintText.getTextBounds(text, 0, textView.length(), boundsText); paintText.setTextAlign(Paint.Align.CENTER); final Bitmap.Config conf = Bitmap.Config.ARGB_8888; final Bitmap bmpText = Bitmap.createBitmap(boundsText.width() + 2 * padding, boundsText.height() + 2 * padding, conf); final Canvas canvasText = new Canvas(bmpText); paintText.setColor(Color.BLACK); canvasText.drawText(text, (canvasText.getWidth() / 2) + 3, (canvasText.getHeight() - padding - boundsText.bottom) + 3, paintText); paintText.setColor(colour); canvasText.drawText(text, canvasText.getWidth() / 2, canvasText.getHeight() - padding - boundsText.bottom, paintText); final MarkerOptions markerOptions = new MarkerOptions().position(location) .icon(BitmapDescriptorFactory.fromBitmap(bmpText)).anchor(0.5f, 1); marker = map.addMarker(markerOptions); return marker; }
From source file:foam.jellyfish.StarwispCanvas.java
public void DrawText(Canvas canvas, JSONArray prim, float sx, float sy) { try {//from ww w.j a va 2 s .co m canvas.save(); if (prim.getString(6).equals("vertical")) canvas.rotate(-90, prim.getInt(2) * sx, prim.getInt(3) * sy); Paint myPaint = new Paint(); JSONArray c = prim.getJSONArray(4); myPaint.setColor(Color.rgb(c.getInt(0), c.getInt(1), c.getInt(2))); myPaint.setTextSize(prim.getInt(5)); myPaint.setTypeface(m_Typeface); canvas.drawText(prim.getString(1), prim.getInt(2) * sx, prim.getInt(3) * sy, myPaint); canvas.restore(); } catch (JSONException e) { Log.e("starwisp", "Error parsing data " + e.toString()); } }
From source file:com.layer_net.stepindicator.StepIndicator.java
private void drawTextCentred(Canvas canvas, Paint paint, String text, float cx, float cy) { paint.getTextBounds(text, 0, text.length(), textBounds); canvas.drawText(text, cx, cy - textBounds.exactCenterY(), paint); }
From source file:com.samebits.beacon.locator.ui.view.RadarScanView.java
private void addText(Canvas canvas, String str, int x, int y) { mGridPaint.getTextBounds(str, 0, str.length(), mTextBounds); mTextBounds.offset(x - (mTextBounds.width() >> 1), y); mTextBounds.inset(-2, -2);/*from w ww.j a va 2 s.c o m*/ canvas.drawRect(mTextBounds, mErasePaint); canvas.drawText(str, x, y, mGridPaint); }
From source file:sandra.examples.oneshot.voicelaunch.VoiceLaunch.java
/** * Writes a text in a drawable. We will use this method to show the similarity value in the seekbar * See stackoverflow http://stackoverflow.com/questions/6264543/draw-on-drawable?rq=1 *///from w w w . j av a 2s.c o m @SuppressWarnings("deprecation") private BitmapDrawable writeOnDrawable(int drawableId, String text) { Bitmap bm = BitmapFactory.decodeResource(getResources(), drawableId).copy(Bitmap.Config.ARGB_8888, true); Paint paint = new Paint(); paint.setStyle(Style.FILL); paint.setColor(Color.BLACK); paint.setTextSize(10); Canvas canvas = new Canvas(bm); canvas.drawText(text, bm.getWidth() / 4, bm.getHeight() / 2, paint); return new BitmapDrawable(bm); }