List of usage examples for android.graphics Paint setTextSize
public void setTextSize(float textSize)
From source file:com.appeaser.sublimepickerlibrary.timepicker.RadialTimePickerView.java
/** * Using the trigonometric Unit Circle, calculate the positions that the text will need to be * drawn at based on the specified circle radius. Place the values in the textGridHeights and * textGridWidths parameters.//from www .j av a 2 s.c o m */ private static void calculatePositions(Paint paint, float radius, float xCenter, float yCenter, float textSize, float[] x, float[] y) { // Adjust yCenter to account for the text's baseline. paint.setTextSize(textSize); yCenter -= (paint.descent() + paint.ascent()) / 2; for (int i = 0; i < NUM_POSITIONS; i++) { x[i] = xCenter - radius * COS_30[i]; y[i] = yCenter - radius * SIN_30[i]; } }
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 . ja v a 2s. co m*/ // 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:com.longle1.facedetection.MainActivity.java
@Override protected void onDraw(Canvas canvas) { Paint paint = new Paint(); paint.setColor(Color.GREEN);//from w w w. j a va 2s .c o 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.metinkale.prayerapp.vakit.fragments.MainFragment.java
private void export(int csvpdf, LocalDate from, LocalDate to) throws IOException { File outputDir = getActivity().getCacheDir(); if (!outputDir.exists()) outputDir.mkdirs();/*w ww .jav a2 s . c o m*/ File outputFile = new File(outputDir, mTimes.getName().replace(" ", "_") + (csvpdf == 0 ? ".csv" : ".pdf")); if (outputDir.exists()) outputFile.delete(); FileOutputStream outputStream; outputStream = new FileOutputStream(outputFile); if (csvpdf == 0) { outputStream.write("Date;Fajr;Shuruq;Dhuhr;Asr;Maghrib;Ishaa\n".getBytes()); do { outputStream.write((from.toString("yyyy-MM-dd") + ";").getBytes()); outputStream.write((mTimes.getTime(from, 0) + ";").getBytes()); outputStream.write((mTimes.getTime(from, 1) + ";").getBytes()); outputStream.write((mTimes.getTime(from, 2) + ";").getBytes()); outputStream.write((mTimes.getTime(from, 3) + ";").getBytes()); outputStream.write((mTimes.getTime(from, 4) + ";").getBytes()); outputStream.write((mTimes.getTime(from, 5) + "\n").getBytes()); } while (!(from = from.plusDays(1)).isAfter(to)); outputStream.close(); } else { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { PdfDocument document = new PdfDocument(); PdfDocument.PageInfo pageInfo = null; int pw = 595; int ph = 842; pageInfo = new PdfDocument.PageInfo.Builder(pw, ph, 1).create(); PdfDocument.Page page = document.startPage(pageInfo); Drawable launcher = Drawable.createFromStream(getActivity().getAssets().open("pdf/launcher.png"), null); Drawable qr = Drawable.createFromStream(getActivity().getAssets().open("pdf/qrcode.png"), null); Drawable badge = Drawable.createFromStream( getActivity().getAssets().open("pdf/badge_" + Prefs.getLanguage() + ".png"), null); launcher.setBounds(30, 30, 30 + 65, 30 + 65); qr.setBounds(pw - 30 - 65, 30 + 65 + 5, pw - 30, 30 + 65 + 5 + 65); int w = 100; int h = w * badge.getIntrinsicHeight() / badge.getIntrinsicWidth(); badge.setBounds(pw - 30 - w, 30 + (60 / 2 - h / 2), pw - 30, 30 + (60 / 2 - h / 2) + h); Canvas canvas = page.getCanvas(); Paint paint = new Paint(); paint.setARGB(255, 0, 0, 0); paint.setTextSize(10); paint.setTextAlign(Paint.Align.CENTER); canvas.drawText("com.metinkale.prayer", pw - 30 - w / 2, 30 + (60 / 2 - h / 2) + h + 10, paint); launcher.draw(canvas); qr.draw(canvas); badge.draw(canvas); paint.setARGB(255, 61, 184, 230); canvas.drawRect(30, 30 + 60, pw - 30, 30 + 60 + 5, paint); if (mTimes.getSource().resId != 0) { Drawable source = getResources().getDrawable(mTimes.getSource().resId); h = 65; w = h * source.getIntrinsicWidth() / source.getIntrinsicHeight(); source.setBounds(30, 30 + 65 + 5, 30 + w, 30 + 65 + 5 + h); source.draw(canvas); } paint.setARGB(255, 0, 0, 0); paint.setTextSize(40); paint.setTextAlign(Paint.Align.LEFT); canvas.drawText(getText(R.string.appName).toString(), 30 + 65 + 5, 30 + 50, paint); paint.setTextAlign(Paint.Align.CENTER); paint.setFakeBoldText(true); canvas.drawText(mTimes.getName(), pw / 2.0f, 30 + 65 + 50, paint); paint.setTextSize(12); int y = 30 + 65 + 5 + 65 + 30; int p = 30; int cw = (pw - p - p) / 7; canvas.drawText(getString(R.string.date), 30 + (0.5f * cw), y, paint); canvas.drawText(Vakit.IMSAK.getString(), 30 + (1.5f * cw), y, paint); canvas.drawText(Vakit.GUNES.getString(), 30 + (2.5f * cw), y, paint); canvas.drawText(Vakit.OGLE.getString(), 30 + (3.5f * cw), y, paint); canvas.drawText(Vakit.IKINDI.getString(), 30 + (4.5f * cw), y, paint); canvas.drawText(Vakit.AKSAM.getString(), 30 + (5.5f * cw), y, paint); canvas.drawText(Vakit.YATSI.getString(), 30 + (6.5f * cw), y, paint); paint.setFakeBoldText(false); do { y += 20; canvas.drawText((from.toString("dd.MM.yyyy")), 30 + (0.5f * cw), y, paint); canvas.drawText((mTimes.getTime(from, 0)), 30 + (1.5f * cw), y, paint); canvas.drawText((mTimes.getTime(from, 1)), 30 + (2.5f * cw), y, paint); canvas.drawText((mTimes.getTime(from, 2)), 30 + (3.5f * cw), y, paint); canvas.drawText((mTimes.getTime(from, 3)), 30 + (4.5f * cw), y, paint); canvas.drawText((mTimes.getTime(from, 4)), 30 + (5.5f * cw), y, paint); canvas.drawText((mTimes.getTime(from, 5)), 30 + (6.5f * cw), y, paint); } while (!(from = from.plusDays(1)).isAfter(to)); document.finishPage(page); document.writeTo(outputStream); // close the document document.close(); } else { Toast.makeText(getActivity(), R.string.versionNotSupported, Toast.LENGTH_LONG).show(); } } Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.setType(csvpdf == 0 ? "text/csv" : "application/pdf"); Uri uri = FileProvider.getUriForFile(getActivity(), "com.metinkale.prayer.fileprovider", outputFile); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.export))); }
From source file:com.gruporaido.tasker_library.util.Helper.java
/** * @param drawableId//w w w .j ava 2s.c o m * @param text * @param textSize * @param offsetX * @param offsetY * @return */ public Bitmap drawTextOnDrawable(int drawableId, String text, int textSize, int offsetX, int offsetY) { Bitmap bm = BitmapFactory.decodeResource(mContext.getResources(), drawableId).copy(Bitmap.Config.ARGB_8888, true); Typeface tf = Typeface.create("Helvetica", Typeface.BOLD); Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.WHITE); paint.setTypeface(tf); paint.setTextAlign(Paint.Align.CENTER); paint.setTextSize(dpToPx(textSize)); Rect textRect = new Rect(); paint.getTextBounds(text, 0, text.length(), textRect); Canvas canvas = new Canvas(bm); //If the text is bigger than the canvas , reduce the font size if (textRect.width() >= (canvas.getWidth() - 4)) //the padding on either sides is considered as 4, so as to appropriately fit in the text paint.setTextSize(dpToPx(textSize / 2)); //Scaling needs to be used for different dpi's //Calculate the positions int xPos = (canvas.getWidth() / 2) - 2 + dpToPx(offsetX); //-2 is for regulating the x position offset //"- ((paint.descent() + paint.ascent()) / 2)" is the distance from the baseline to the center. int yPos = (int) ((canvas.getHeight() / 2) - ((paint.descent() + paint.ascent()) / 2)) + dpToPx(offsetY); canvas.drawText(text, xPos, yPos, paint); return bm; }
From source file:es.usc.citius.servando.calendula.activities.CalendarActivity.java
public CharSequence addPickupList(CharSequence msg, List<PickupInfo> pks) { Paint textPaint = new Paint(); //obviously, we have to set textSize into Paint object textPaint.setTextSize(getResources().getDimensionPixelOffset(R.dimen.medium_font_size)); Paint.FontMetricsInt fontMetrics = textPaint.getFontMetricsInt(); for (PickupInfo p : pks) { Patient patient = pickupUtils.getPatient(p); int color = patient.color(); String str = " " + p.medicine().name() + " (" + dtf2.format(p.from().toDate()) + " - " + dtf2.format(p.to().toDate()) + ")\n"; Spannable text = new SpannableString(str); text.setSpan(new ForegroundColorSpan(color), 0, str.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); Drawable d = getResources().getDrawable(AvatarMgr.res(patient.avatar())); d.setBounds(0, 0, fontMetrics.bottom, fontMetrics.bottom); ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE); text.setSpan(span, 0, 5, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); msg = TextUtils.concat(msg, text); }//from w w w . j a va2 s. c om return msg; }
From source file:fr.magistry.taigime.CandidateView.java
private float reduceTextSizeFromWidth(Paint p, String str, float maxWidth) { float size = p.getTextSize(); if (str.length() == 0) return size; while (p.measureText(str) > maxWidth) { p.setTextSize(--size); }/* ww w . j a va 2 s. com*/ return size; }
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 www . 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:com.codetroopers.shakemytours.ui.activity.TripActivity.java
private Bitmap createMarker(int radius, int strokeWidth, String letter, int strokeColor, int backgroundColor) { int width = (radius * 2) + (strokeWidth * 2); Bitmap marker = Bitmap.createBitmap(width, width, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(marker); Paint strokePaint = new Paint(Paint.ANTI_ALIAS_FLAG); strokePaint.setColor(strokeColor);/*from w ww . ja v a 2s. c o m*/ strokePaint.setShadowLayer(strokeWidth, 1.0f, 1.0f, Color.BLACK); canvas.drawCircle(width / 2, width / 2, radius, strokePaint); Paint backgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG); backgroundPaint.setColor(backgroundColor); canvas.drawCircle(width / 2, width / 2, radius - strokeWidth, backgroundPaint); if (letter != null) { Rect result = new Rect(); Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG); textPaint.setTextAlign(Paint.Align.CENTER); textPaint.setTextSize(getResources().getDimensionPixelSize(R.dimen.map_marker_text_size)); textPaint.setColor(strokeColor); textPaint.getTextBounds(letter, 0, letter.length(), result); int yOffset = result.height() / 2; canvas.drawText(letter, width / 2, (width / 2) + yOffset, textPaint); } return marker; }
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 ww .j a v a2 s .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); }