List of usage examples for android.text TextPaint TextPaint
public TextPaint()
From source file:org.cocos2dx.lib.Cocos2dxBitmap.java
private static String getStringWithEllipsis(String originalText, float width, float fontSize) { if (TextUtils.isEmpty(originalText)) { return ""; }/*from w w w. ja v a 2s .c o m*/ TextPaint paint = new TextPaint(); paint.setTypeface(Typeface.DEFAULT); paint.setTextSize(fontSize); return TextUtils.ellipsize(originalText, paint, width, TextUtils.TruncateAt.valueOf("END")).toString(); }
From source file:com.semfapp.adamdilger.semf.Take5PdfDocument.java
public void drawText(String string, float xLoc, float yLoc, float textSize, Typeface typeface) { if (string != null) { TextPaint mTextPaint = new TextPaint(); mTextPaint.setTypeface(typeface); mTextPaint.setTextSize(textSize); StaticLayout mTextLayout = new StaticLayout(string, mTextPaint, ((int) (595 * 0.28)), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); can.save();/*from ww w . j a v a 2 s . c o m*/ // calculate x and y position where your text will be placed can.translate(xLoc, yLoc); mTextLayout.draw(can); can.restore(); } }
From source file:com.semfapp.adamdilger.semf.Take5PdfDocument.java
public float drawRiskElement(int height, Take5RiskElement element) { final float singleLineHeight = 12.5f; float totalItemHeight; TextPaint textPaint = new TextPaint(); textPaint.setTypeface(roboto);/*w w w . jav a2s . co m*/ textPaint.setTextSize(FONT11); textPaint.setColor(Color.BLACK); String oneString = ""; String twoString = ""; if (element.getOne() != null) { oneString = element.getOne(); } if (element.getTwo() != null) { twoString = element.getTwo(); } StaticLayout one = new StaticLayout(oneString, textPaint, 235, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); StaticLayout rating = new StaticLayout(element.getRating().toString(), textPaint, 100, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); StaticLayout two = new StaticLayout(twoString, textPaint, 250, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); if (one.getLineCount() > two.getLineCount()) { totalItemHeight = singleLineHeight * one.getLineCount(); } else { totalItemHeight = singleLineHeight * two.getLineCount(); } can.save(); can.translate(15, height); one.draw(can); can.restore(); can.save(); can.translate(320, height); two.draw(can); can.restore(); can.save(); can.translate(270, height); rating.draw(can); can.restore(); return totalItemHeight; }
From source file:android.support.v7.widget.AppCompatTextViewAutoSizeHelper.java
private boolean suggestedSizeFitsInSpace(int suggestedSizeInPx, RectF availableSpace) { CharSequence text = mTextView.getText(); TransformationMethod transformationMethod = mTextView.getTransformationMethod(); if (transformationMethod != null) { CharSequence transformedText = transformationMethod.getTransformation(text, mTextView); if (transformedText != null) { text = transformedText;/*from w w w . j a va 2 s . c om*/ } } final int maxLines = Build.VERSION.SDK_INT >= 16 ? mTextView.getMaxLines() : -1; if (mTempTextPaint == null) { mTempTextPaint = new TextPaint(); } else { mTempTextPaint.reset(); } mTempTextPaint.set(mTextView.getPaint()); mTempTextPaint.setTextSize(suggestedSizeInPx); // Needs reflection call due to being private. Layout.Alignment alignment = invokeAndReturnWithDefault(mTextView, "getLayoutAlignment", Layout.Alignment.ALIGN_NORMAL); final StaticLayout layout = Build.VERSION.SDK_INT >= 23 ? createStaticLayoutForMeasuring(text, alignment, Math.round(availableSpace.right), maxLines) : createStaticLayoutForMeasuringPre23(text, alignment, Math.round(availableSpace.right)); // Lines overflow. if (maxLines != -1 && (layout.getLineCount() > maxLines || (layout.getLineEnd(layout.getLineCount() - 1)) != text.length())) { return false; } // Height overflow. if (layout.getHeight() > availableSpace.bottom) { return false; } return true; }
From source file:de.vanita5.twittnuker.util.ThemeUtils.java
public static int getUserLinkTextColor(final Context context) { if (context == null) return new TextPaint().linkColor; final int themeColor = getUserAccentColor(context); final float[] hsv = new float[3]; Color.colorToHSV(themeColor, hsv); if (isDarkTheme(context)) { hsv[2] = MathUtils.clamp(hsv[2], 1, 0.5f); } else {//from ww w .j av a 2 s .c o m hsv[2] = MathUtils.clamp(hsv[2], 0.1f, 0.75f); } return Color.HSVToColor(hsv); }