List of usage examples for android.graphics Paint setTextSize
public void setTextSize(float textSize)
From source file:com.hippo.widget.Slider.java
@SuppressWarnings("deprecation") private void init(Context context, AttributeSet attrs) { mContext = context;// www .j av a 2s . c o m mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG); textPaint.setTextAlign(Paint.Align.CENTER); Resources resources = context.getResources(); mBubbleMinWidth = resources.getDimensionPixelOffset(R.dimen.slider_bubble_width); mBubbleMinHeight = resources.getDimensionPixelOffset(R.dimen.slider_bubble_height); mBubble = new BubbleView(context, textPaint); mBubble.setScaleX(0.0f); mBubble.setScaleY(0.0f); AbsoluteLayout absoluteLayout = new AbsoluteLayout(context); absoluteLayout.addView(mBubble); absoluteLayout.setBackgroundDrawable(null); mPopup = new PopupWindow(absoluteLayout); mPopup.setOutsideTouchable(false); mPopup.setTouchable(false); mPopup.setFocusable(false); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Slider); textPaint.setColor(a.getColor(R.styleable.Slider_textColor, Color.WHITE)); textPaint.setTextSize(a.getDimensionPixelSize(R.styleable.Slider_textSize, 12)); updateTextSize(); setRange(a.getInteger(R.styleable.Slider_start, 0), a.getInteger(R.styleable.Slider_end, 0)); setProgress(a.getInteger(R.styleable.Slider_slider_progress, 0)); mThickness = a.getDimension(R.styleable.Slider_thickness, 2); mRadius = a.getDimension(R.styleable.Slider_radius, 6); setColor(a.getColor(R.styleable.Slider_color, Color.BLACK)); mBgPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mBgPaint.setColor(a.getBoolean(R.styleable.Slider_dark, false) ? 0x4dffffff : 0x42000000); a.recycle(); mProgressAnimation = new ValueAnimator(); mProgressAnimation.setInterpolator(AnimationUtils.FAST_SLOW_INTERPOLATOR); mProgressAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(@NonNull ValueAnimator animation) { float value = (Float) animation.getAnimatedValue(); mDrawPercent = value; mDrawProgress = Math.round(MathUtils.lerp((float) mStart, mEnd, value)); updateBubblePosition(); mBubble.setProgress(mDrawProgress); invalidate(); } }); mBubbleScaleAnimation = new ValueAnimator(); mBubbleScaleAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(@NonNull ValueAnimator animation) { float value = (Float) animation.getAnimatedValue(); mDrawBubbleScale = value; mBubble.setScaleX(value); mBubble.setScaleY(value); invalidate(); } }); }
From source file:com.simadanesh.isatis.ScreenSlideActivity.java
void makeBMP(CalculationResult res) { Bitmap bmp = Bitmap.createBitmap(400, 800, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmp); //canvas.drawARGB(155, 253, 255, 253); canvas.drawARGB(255, 255, 255, 255); Paint p = new Paint(); p.setTypeface(Utility.getNazaninFont()); p.setTextSize(25); p.setAntiAlias(true);/*from w w w . j ava 2s.co m*/ int y = 20; Drawable d = getResources().getDrawable(R.drawable.abfa); d.setBounds(100, 10, 300, 210); d.draw(canvas); p.setTextAlign(Paint.Align.CENTER); y += 210; canvas.drawText(" ? ", 200, y, p); y += 40; canvas.drawText(" ", 200, y, p); y += 40; canvas.drawText(" ", 200, y, p); y += 40; canvas.drawText(":" + Utility.NowDate(), 200, y, p); y += 40; canvas.drawText("___________________________", 200, y, p); y += 40; canvas.drawText(" :" + res.CustomerNumber, 200, y, p); y += 40; canvas.drawText(" :" + res.Title, 200, y, p); y += 40; canvas.drawText(" :" + Seprate3(res.BillAmount), 200, y, p); y += 40; canvas.drawText(" :" + Seprate3(res.PreviousDebt), 200, y, p); y += 40; Paint p1 = new Paint(); p1.setTypeface(Utility.getNazaninFont()); p1.setARGB(255, 0, 0, 0); p1.setAntiAlias(true); p1.setStrokeWidth(40); p1.setStyle(Paint.Style.STROKE); canvas.drawLine(10, y, 390, y, p1); p.setARGB(255, 255, 255, 255); canvas.drawText(" :" + Seprate3(res.TotalAmount) + " ", 200, y, p); p.setARGB(255, 0, 0, 0); y += 40; canvas.drawText("__________________________", 200, y, p); y += 40; canvas.drawText(" :" + res.BillIdentifier, 200, y, p); y += 40; canvas.drawText(" :" + res.PaymentIdentifier, 200, y, p); /* Path pth = new Path(); pth.addArc(10, 20, 390, 790, 0, 360); p.setColor(Color.argb(20, 10, 10, 10)); p.setTextSize(30); String watermark = ""; for (int i = 0; i < 15; i++) { watermark += " "; } canvas.drawTextOnPath(watermark, pth, 0, 0, p);*/ //File file = new File(getCacheDir()+ "/billing.png"); File file = new File("/sdcard/billing.png"); FileOutputStream outfile; try { outfile = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.PNG, 100, outfile); Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "image/*"); startActivity(intent); } catch (Exception ex) { Log.e("error", ex.toString()); } }
From source file:com.simadanesh.isatis.ScreenSlideActivity.java
void makePDF(CalculationResult res) { PdfDocument doc = new PdfDocument(); PdfDocument.PageInfo inf = new PdfDocument.PageInfo.Builder(400, 800, 1).create(); PdfDocument.Page page = doc.startPage(inf); Canvas canvas = page.getCanvas(); //canvas.drawARGB(155, 253, 255, 253); canvas.drawARGB(255, 255, 255, 255); Paint p = new Paint(); p.setTypeface(Utility.getNazaninFont()); p.setTextSize(25); p.setAntiAlias(true);/*from w w w . j a va2 s . co m*/ int y = 20; Drawable d = getResources().getDrawable(R.drawable.abfa); d.setBounds(100, 10, 300, 210); d.draw(canvas); p.setTextAlign(Paint.Align.CENTER); y += 210; canvas.drawText(" ? ", 200, y, p); y += 40; canvas.drawText(" ", 200, y, p); y += 40; canvas.drawText(" ", 200, y, p); y += 40; canvas.drawText(":" + Utility.NowDate(), 200, y, p); y += 40; canvas.drawText("___________________________", 200, y, p); y += 40; canvas.drawText(" :" + res.CustomerNumber, 200, y, p); y += 40; canvas.drawText(" :" + res.Title, 200, y, p); y += 40; canvas.drawText(" :" + Seprate3(res.BillAmount), 200, y, p); y += 40; canvas.drawText(" :" + Seprate3(res.PreviousDebt), 200, y, p); y += 40; Paint p1 = new Paint(); p1.setTypeface(Utility.getNazaninFont()); p1.setARGB(255, 0, 0, 0); p1.setAntiAlias(true); p1.setStrokeWidth(40); p1.setStyle(Paint.Style.STROKE); canvas.drawLine(10, y, 390, y, p1); p.setARGB(255, 255, 255, 255); canvas.drawText(" :" + Seprate3(res.TotalAmount) + " ", 200, y, p); p.setARGB(255, 0, 0, 0); y += 40; canvas.drawText("__________________________", 200, y, p); y += 40; canvas.drawText(" :" + res.BillIdentifier, 200, y, p); y += 40; canvas.drawText(" :" + res.PaymentIdentifier, 200, y, p); doc.finishPage(page); //File file = new File(getCacheDir()+ "/billing.png"); File file = new File("/sdcard/billing.pdf"); FileOutputStream outfile; try { outfile = new FileOutputStream(file); //bmp.compress(Bitmap.CompressFormat.PNG, 100, outfile); doc.writeTo(outfile); doc.close(); Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); //intent.setDataAndType(Uri.fromFile(file), "image/*"); intent.setDataAndType(Uri.fromFile(file), "application/pdf"); startActivity(intent); //new RetrieveFeedTask().execute(bmp); } catch (Exception ex) { Log.e("error", ex.toString()); new AlertDialog.Builder(this).setMessage( " ? pdf ? \n https://cafebazaar.ir/app/com.kdanmobile.android.pdfreader.google.pad/?l=fa ") .show(); } }
From source file:com.inmobi.ultrapush.AnalyzeActivity.java
@SuppressWarnings("deprecation") private void setTextViewFontSize() { TextView tv = (TextView) findViewById(R.id.textview_cur); // At this point tv.getWidth(), tv.getLineCount() will return 0 Paint mTestPaint = new Paint(); mTestPaint.setTextSize(tv.getTextSize()); mTestPaint.setTypeface(Typeface.MONOSPACE); final String text = getString(R.string.textview_peak_text); Display display = getWindowManager().getDefaultDisplay(); // pixels left float px = display.getWidth() - getResources().getDimension(R.dimen.textview_RMS_layout_width) - 5; float fs = tv.getTextSize(); // size in pixel while (mTestPaint.measureText(text) > px && fs > 5) { fs -= 0.5;/*www . j av a2 s .c om*/ mTestPaint.setTextSize(fs); } ((TextView) findViewById(R.id.textview_cur)).setTextSize(fs / DPRatio); ((TextView) findViewById(R.id.textview_peak)).setTextSize(fs / DPRatio); }
From source file:com.inmobi.ultrapush.AnalyzeActivity.java
public PopupWindow popupMenuCreate(String[] popUpContents, int resId) { // initialize a pop up window type PopupWindow popupWindow = new PopupWindow(this); // the drop down list is a list view ListView listView = new ListView(this); // set our adapter and pass our pop up window contents ArrayAdapter<String> aa = popupMenuAdapter(popUpContents); listView.setAdapter(aa);//from ww w . j a v a2 s. c om // set the item click listener listView.setOnItemClickListener(this); listView.setTag(resId); // button res ID, so we can trace back which button is pressed // get max text width Paint mTestPaint = new Paint(); mTestPaint.setTextSize(listItemTextSize); float w = 0; float wi; // max text width in pixel for (int i = 0; i < popUpContents.length; i++) { String sts[] = popUpContents[i].split("::"); String st = sts[0]; if (sts.length == 2 && sts[1].equals("0")) { mTestPaint.setTextSize(listItemTitleTextSize); wi = mTestPaint.measureText(st); mTestPaint.setTextSize(listItemTextSize); } else { wi = mTestPaint.measureText(st); } if (w < wi) { w = wi; } } // left and right padding, at least +7, or the whole app will stop respond, don't know why w = w + 20 * DPRatio; if (w < 60) { w = 60; } // some other visual settings popupWindow.setFocusable(true); popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT); // Set window width according to max text width popupWindow.setWidth((int) w); // also set button width ((Button) findViewById(resId)).setWidth((int) (w + 4 * DPRatio)); // Set the text on button in updatePreferenceSaved() // set the list view as pop up window content popupWindow.setContentView(listView); return popupWindow; }
From source file:com.lt.adamlee.aagame.GameView.java
public void about(Canvas c) { int textsize = (int) F.hf(20.0f); Paint p3 = new Paint(); p3.setTypeface(tf);/*from ww w. j av a 2s .co m*/ p3.setColor(ViewCompat.MEASURED_STATE_MASK); p3.setFlags(1); p3.setTextSize((float) textsize); Paint pagepaint = new Paint(); pagepaint.setColor(getResources().getColor(R.color.abc_secondary_text_material_light)); c.drawRect(0.0f, 0.0f, (float) screenW, (float) screenH, pagepaint); p3.setTextSize(F.hf(30.0f)); c.drawText(ctx.getString(R.string.about), ((float) (screenW / 2)) - (p3.measureText(ctx.getString(R.string.about)) / 2.0f), (float) (screenH / 4), p3); p3.setTextSize((float) textsize); c.drawText(ctx.getString(R.string.app_name), ((float) (screenW / 2)) - (p3.measureText(ctx.getString(R.string.app_name)) / 2.0f), (float) (((textsize * 2) + 1) + ((screenH - (textsize * 7)) / 2)), p3); c.drawText("License Version 1.7", ((float) (screenW / 2)) - (p3.measureText("License Version 1.7") / 2.0f), (float) (((textsize * 3) + 1) + ((screenH - (textsize * 7)) / 2)), p3); p3.setTextSize(F.hf(17.0f)); c.drawText("Powered by Map Game Studio", ((float) (screenW / 2)) - (p3.measureText("Powered by Map Game Studio") / 2.0f), (float) (((textsize * 4) + 1) + ((screenH - (textsize * 7)) / 2)), p3); p3.setTextSize(F.hf(17.0f)); c.drawText("Email:mapgamestudio@gmail.com", ((float) (screenW / 2)) - (p3.measureText("Email:mapgamestudio@gmail.com") / 2.0f), (float) (((textsize * 5) + 1) + ((screenH - (textsize * 7)) / 2)), p3); }
From source file:com.android.launcher3.Utilities.java
public static Bitmap getNotificationBadgeIcon(Context context, Bitmap appIcon, int number) { Paint paint; Paint circlePaint;/* w ww .j av a 2 s .c om*/ String text = "" + String.valueOf(number); Bitmap canvasBitmap = Bitmap.createBitmap(appIcon.getWidth(), appIcon.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(canvasBitmap); paint = new Paint(); circlePaint = new Paint(); paint.setColor(Color.WHITE); paint.setTextSize(45); paint.setAntiAlias(true); paint.setTextAlign(Paint.Align.CENTER); Rect bounds = new Rect(); paint.getTextBounds(text, 0, text.length(), bounds); circlePaint.setColor(ContextCompat.getColor(context, R.color.colorPrimary)); circlePaint.setAntiAlias(true); canvas.drawCircle(appIcon.getWidth() / 4, appIcon.getHeight() / 4, 45, circlePaint); canvas.drawText(text, appIcon.getWidth() / 4, appIcon.getHeight() / 3, paint); return overlay(appIcon, canvasBitmap); }
From source file:io.doist.datetimepicker.time.RadialTimePickerView.java
/** * Draw the 12 text values at the positions specified by the textGrid parameters. */// w w w . j a v a 2 s . c o m private void drawTextElements(Canvas canvas, float textSize, Typeface typeface, String[] texts, float[] textGridWidths, float[] textGridHeights, Paint paint, int color, int alpha) { paint.setTextSize(textSize); paint.setTypeface(typeface); paint.setColor(color); paint.setAlpha(getMultipliedAlpha(color, alpha)); canvas.drawText(texts[0], textGridWidths[3], textGridHeights[0], paint); canvas.drawText(texts[1], textGridWidths[4], textGridHeights[1], paint); canvas.drawText(texts[2], textGridWidths[5], textGridHeights[2], paint); canvas.drawText(texts[3], textGridWidths[6], textGridHeights[3], paint); canvas.drawText(texts[4], textGridWidths[5], textGridHeights[4], paint); canvas.drawText(texts[5], textGridWidths[4], textGridHeights[5], paint); canvas.drawText(texts[6], textGridWidths[3], textGridHeights[6], paint); canvas.drawText(texts[7], textGridWidths[2], textGridHeights[5], paint); canvas.drawText(texts[8], textGridWidths[1], textGridHeights[4], paint); canvas.drawText(texts[9], textGridWidths[0], textGridHeights[3], paint); canvas.drawText(texts[10], textGridWidths[1], textGridHeights[2], paint); canvas.drawText(texts[11], textGridWidths[2], textGridHeights[1], paint); }
From source file:org.cryptsecure.Utility.java
/** * Cut text into one line.//from w w w. j a va 2 s.co m * * @param text * the text * @param maxWidth * the max width * @param textSize * the text size * @return the string */ public static String cutTextIntoOneLine(String text, int maxWidth, int textSize) { try { Paint paint = new Paint(); Rect bounds = new Rect(); int textWidth = 0; paint.setTypeface(Typeface.DEFAULT);// your preference here paint.setTextSize(textSize);// have this the same as your text size String outText = text; String outText2 = text; boolean modified = false; boolean cutDown = false; while (true) { if (modified) { paint.getTextBounds(outText2, 0, outText2.length(), bounds); } else { paint.getTextBounds(outText, 0, outText.length(), bounds); } textWidth = bounds.width(); if (textWidth <= maxWidth) { break; } else { modified = true; if (!cutDown) { cutDown = true; int estimatedLen = (outText.length() * maxWidth) / textWidth; estimatedLen += 20; // be carefull! if (estimatedLen > outText.length()) { estimatedLen = outText.length(); } outText = outText.substring(0, estimatedLen); outText2 = outText + "..."; } else { // reduce by one character outText = outText.substring(0, outText.length() - 1); outText2 = outText + "..."; } } } if (modified) { return outText2; } else { return outText; } } catch (Exception e) { e.printStackTrace(); } return ""; }
From source file:net.droidsolutions.droidcharts.core.renderer.xy.AbstractXYItemRenderer.java
/** * Draws a horizontal line across the chart to represent a 'range marker'. * * @param g2 the graphics device./*from ww w. ja va 2 s .co m*/ * @param plot the plot. * @param rangeAxis the range axis. * @param marker the marker line. * @param dataArea the axis data area. */ public void drawRangeMarker(Canvas g2, XYPlot plot, ValueAxis rangeAxis, Marker marker, Rectangle2D dataArea) { if (marker instanceof ValueMarker) { ValueMarker vm = (ValueMarker) marker; double value = vm.getValue(); Range range = rangeAxis.getRange(); if (!range.contains(value)) { return; } double v = rangeAxis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge()); PlotOrientation orientation = plot.getOrientation(); Line2D line = null; if (orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY()); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v); } Paint oPiant = marker.getPaint(); oPiant.setStyle(Paint.Style.STROKE); int oOldAlpha = oPiant.getAlpha(); oPiant.setAlpha(marker.getAlpha()); oPiant.setStrokeWidth(marker.getStroke()); g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(), (float) line.getY2(), oPiant); oPiant.setAlpha(oOldAlpha); String label = marker.getLabel(); RectangleAnchor anchor = marker.getLabelAnchor(); if (label != null) { Font labelFont = marker.getLabelFont(); Paint paint = marker.getLabelPaint(); paint.setTypeface(labelFont.getTypeFace()); paint.setTextSize(labelFont.getSize()); Point2D coordinates = calculateRangeMarkerTextAnchorPoint(g2, orientation, dataArea, line.getBounds2D(), marker.getLabelOffset(), LengthAdjustmentType.EXPAND, anchor); TextUtilities.drawAlignedString(label, g2, (float) coordinates.getX(), (float) coordinates.getY(), marker.getLabelTextAnchor(), paint); } } else if (marker instanceof IntervalMarker) { IntervalMarker im = (IntervalMarker) marker; double start = im.getStartValue(); double end = im.getEndValue(); Range range = rangeAxis.getRange(); if (!(range.intersects(start, end))) { return; } double start2d = rangeAxis.valueToJava2D(start, dataArea, plot.getRangeAxisEdge()); double end2d = rangeAxis.valueToJava2D(end, dataArea, plot.getRangeAxisEdge()); double low = Math.min(start2d, end2d); double high = Math.max(start2d, end2d); PlotOrientation orientation = plot.getOrientation(); Rectangle2D rect = null; if (orientation == PlotOrientation.HORIZONTAL) { // clip left and right bounds to data area low = Math.max(low, dataArea.getMinX()); high = Math.min(high, dataArea.getMaxX()); rect = new Rectangle2D.Double(low, dataArea.getMinY(), high - low, dataArea.getHeight()); } else if (orientation == PlotOrientation.VERTICAL) { // clip top and bottom bounds to data area low = Math.max(low, dataArea.getMinY()); high = Math.min(high, dataArea.getMaxY()); rect = new Rectangle2D.Double(dataArea.getMinX(), low, dataArea.getWidth(), high - low); } Paint p = marker.getPaint(); int oldAlpha = p.getAlpha(); p.setAlpha(marker.getAlpha()); p.setStyle(Paint.Style.FILL); g2.drawRect((float) rect.getMinX(), (float) rect.getMinY(), (float) rect.getMaxX(), (float) rect.getMaxY(), p); p.setAlpha(oldAlpha); // now draw the outlines, if visible... if (im.getOutlinePaint() != null && im.getOutlineStroke() != null) { if (orientation == PlotOrientation.VERTICAL) { Line2D line = new Line2D.Double(); double x0 = dataArea.getMinX(); double x1 = dataArea.getMaxX(); Paint oPiant = im.getOutlinePaint(); oPiant.setStyle(Paint.Style.STROKE); int oOldAlpha = oPiant.getAlpha(); oPiant.setAlpha(marker.getAlpha()); oPiant.setStrokeWidth(im.getOutlineStroke()); if (range.contains(start)) { line.setLine(x0, start2d, x1, start2d); g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(), (float) line.getY2(), oPiant); } if (range.contains(end)) { line.setLine(x0, end2d, x1, end2d); g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(), (float) line.getY2(), oPiant); } oPiant.setAlpha(oOldAlpha); } else { // PlotOrientation.HORIZONTAL Line2D line = new Line2D.Double(); double y0 = dataArea.getMinY(); double y1 = dataArea.getMaxY(); Paint oPiant = im.getOutlinePaint(); oPiant.setStyle(Paint.Style.STROKE); int oOldAlpha = oPiant.getAlpha(); oPiant.setAlpha(marker.getAlpha()); oPiant.setStrokeWidth(im.getOutlineStroke()); if (range.contains(start)) { line.setLine(start2d, y0, start2d, y1); g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(), (float) line.getY2(), oPiant); } if (range.contains(end)) { line.setLine(end2d, y0, end2d, y1); g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(), (float) line.getY2(), oPiant); } oPiant.setAlpha(oOldAlpha); } } String label = marker.getLabel(); RectangleAnchor anchor = marker.getLabelAnchor(); if (label != null) { Font labelFont = marker.getLabelFont(); Paint paint = marker.getLabelPaint(); paint.setTypeface(labelFont.getTypeFace()); paint.setTextSize(labelFont.getSize()); Point2D coordinates = calculateRangeMarkerTextAnchorPoint(g2, orientation, dataArea, rect, marker.getLabelOffset(), marker.getLabelOffsetType(), anchor); TextUtilities.drawAlignedString(label, g2, (float) coordinates.getX(), (float) coordinates.getY(), marker.getLabelTextAnchor(), paint); } } }