use of android.text.TextPaint in project Jota-Text-Editor-old by jiro-aqua.
the class BoringLayout method init.
/* package */
void init(CharSequence source, TextPaint paint, int outerwidth, Alignment align, float spacingmult, float spacingadd, BoringLayout.Metrics metrics, boolean includepad, boolean trustWidth) {
int spacing;
if (source instanceof String && align == Layout.Alignment.ALIGN_NORMAL) {
mDirect = source.toString();
} else {
mDirect = null;
}
mPaint = paint;
if (includepad) {
spacing = metrics.bottom - metrics.top;
} else {
spacing = metrics.descent - metrics.ascent;
}
if (spacingmult != 1 || spacingadd != 0) {
spacing = (int) (spacing * spacingmult + spacingadd + 0.5f);
}
mBottom = spacing;
if (includepad) {
mDesc = spacing + metrics.top;
} else {
mDesc = spacing + metrics.ascent;
}
if (trustWidth) {
mMax = metrics.width;
} else {
/*
* If we have ellipsized, we have to actually calculate the
* width because the width that was passed in was for the
* full text, not the ellipsized form.
*/
synchronized (sTemp) {
mMax = (int) (FloatMath.ceil(Styled.measureText(paint, sTemp, source, 0, source.length(), null)));
}
}
if (includepad) {
mTopPadding = metrics.top - metrics.ascent;
mBottomPadding = metrics.bottom - metrics.descent;
}
}
use of android.text.TextPaint in project UltimateAndroid by cymcsg.
the class CreditsRollView method initTextPaint.
private void initTextPaint() {
mTextPaint = new TextPaint();
// Set up a default TextPaint object
mTextPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
// Update TextPaint and text measurements
mTextPaint.setTextSize(getTextSize());
mTextPaint.setColor(mTextColor);
}
use of android.text.TextPaint in project philm by chrisbanes.
the class AutofitTextView method init.
private void init(Context context, AttributeSet attrs, int defStyle) {
float scaledDensity = context.getResources().getDisplayMetrics().scaledDensity;
boolean sizeToFit = true;
int minTextSize = (int) scaledDensity * DEFAULT_MIN_TEXT_SIZE;
float precision = PRECISION;
if (attrs != null) {
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.AutofitTextView, defStyle, 0);
sizeToFit = ta.getBoolean(R.styleable.AutofitTextView_sizeToFit, sizeToFit);
minTextSize = ta.getDimensionPixelSize(R.styleable.AutofitTextView_minTextSize, minTextSize);
precision = ta.getFloat(R.styleable.AutofitTextView_precision, precision);
ta.recycle();
}
mPaint = new TextPaint();
setSizeToFit(sizeToFit);
setRawTextSize(super.getTextSize());
setRawMinTextSize(minTextSize);
setPrecision(precision);
}
use of android.text.TextPaint in project plaid by nickbutcher.
the class DynamicTextView method fitMultiline.
private void fitMultiline() {
int targetWidth = getWidth() - getPaddingLeft() - getPaddingRight();
int targetHeight = getHeight() - getPaddingTop() - getPaddingBottom();
if (targetWidth > 0 && targetHeight > 0) {
int textSize = mMaxTextSize;
TextPaint paint = getPaint();
paint.setTextSize(textSize);
StaticLayout staticLayout = new StaticLayout(getText(), paint, targetWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true);
int currentHeight = staticLayout.getHeight();
while (currentHeight > targetHeight && textSize > mMinTextSize) {
textSize--;
paint.setTextSize(textSize);
staticLayout = new StaticLayout(getText(), paint, targetWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true);
currentHeight = staticLayout.getHeight();
}
setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
setTextAlignment(TEXT_ALIGNMENT_TEXT_START);
mCalculated = true;
}
}
use of android.text.TextPaint in project plaid by nickbutcher.
the class DynamicTextView method fitSnappedMultiLine.
private void fitSnappedMultiLine() {
int targetWidth = getWidth() - getPaddingLeft() - getPaddingRight();
int targetHeight = getHeight() - getPaddingTop() - getPaddingBottom();
if (targetWidth > 0 && targetHeight > 0) {
int style = 0;
MaterialTypeStyle currentStyle = mStyles[style];
TextPaint paint = getPaint();
StaticLayout staticLayout = null;
int currentHeight = Integer.MAX_VALUE;
int lines = 0;
boolean maxLinesSet = getMaxLines() != Integer.MAX_VALUE;
while ((currentHeight > targetHeight || (maxLinesSet && lines > getMaxLines())) && style <= mStyles.length - 1 && currentStyle.size * scaledDensity >= mMinTextSize && currentStyle.size * scaledDensity <= mMaxTextSize) {
currentStyle = mStyles[style];
paint.setTextSize(currentStyle.size * scaledDensity);
paint.setTypeface(Typeface.create(currentStyle.fontFamily, Typeface.NORMAL));
staticLayout = new StaticLayout(getText(), paint, targetWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true);
currentHeight = staticLayout.getHeight();
lines = staticLayout.getLineCount();
style++;
}
super.setTextSize(TypedValue.COMPLEX_UNIT_SP, currentStyle.size);
setTypeface(Typeface.create(currentStyle.fontFamily, Typeface.NORMAL));
int currentColour = getCurrentTextColor();
setTextColor(Color.argb(currentStyle.opacity, Color.red(currentColour), Color.green(currentColour), Color.blue(currentColour)));
if (style == mStyles.length) {
setEllipsize(TextUtils.TruncateAt.END);
}
if (currentStyle.size * scaledDensity < mMinTextSize) {
// wanted to make text smaller but hit min text size. Need to set max lines.
setMaxLines((int) Math.floor((((float) targetHeight / (float) currentHeight) * lines)));
setEllipsize(TextUtils.TruncateAt.END);
}
setTextAlignment(TEXT_ALIGNMENT_TEXT_START);
mCalculated = true;
}
}
Aggregations