use of android.text.TextPaint in project actor-platform by actorapp.
the class UserSpan method draw.
@Override
public void draw(Canvas canvas, CharSequence charSequence, int start, int end, float x, int top, int y, int bottom, Paint paint) {
int size = (int) textPaint.measureText(userText);
Paint debug = new Paint();
debug.setColor(0xffebebeb);
debug.setStyle(Paint.Style.FILL_AND_STROKE);
canvas.drawRoundRect(new RectF(x + Screen.dp(4), y - Screen.dp(20), x + size + Screen.dp(4 + 24), y + Screen.dp(8)), Screen.dp(14), Screen.dp(14), debug);
canvas.drawText(userText, x + Screen.dp(4 + 12), y, textPaint);
}
use of android.text.TextPaint in project CoCoin by Nightonke.
the class PaperButton method onDraw.
@Override
protected void onDraw(@NonNull Canvas canvas) {
super.onDraw(canvas);
int radius = 0;
int shadowColor = changeColorAlpha(mShadowColor, MIN_SHADOW_COLOR_ALPHA);
long elapsed = System.currentTimeMillis() - mStartTime;
switch(mState) {
case StateNormal:
shadowColor = changeColorAlpha(mShadowColor, MIN_SHADOW_COLOR_ALPHA);
break;
case StateTouchDown:
ripplePaint.setAlpha(255);
if (elapsed < ANIMATION_DURATION) {
radius = Math.round(elapsed * getWidth() / 2 / ANIMATION_DURATION);
float shadowAlpha = (MAX_SHADOW_COLOR_ALPHA - MIN_SHADOW_COLOR_ALPHA) * elapsed / ANIMATION_DURATION + MIN_SHADOW_COLOR_ALPHA;
shadowColor = changeColorAlpha(mShadowColor, shadowAlpha);
} else {
radius = getWidth() / 2;
shadowColor = changeColorAlpha(mShadowColor, MAX_SHADOW_COLOR_ALPHA);
}
postInvalidate();
break;
case StateTouchUp:
if (elapsed < ANIMATION_DURATION) {
int alpha = Math.round((ANIMATION_DURATION - elapsed) * 255 / ANIMATION_DURATION);
ripplePaint.setAlpha(alpha);
radius = getWidth() / 2 + Math.round(elapsed * getWidth() / 2 / ANIMATION_DURATION);
float shadowAlpha = (MAX_SHADOW_COLOR_ALPHA - MIN_SHADOW_COLOR_ALPHA) * (ANIMATION_DURATION - elapsed) / ANIMATION_DURATION + MIN_SHADOW_COLOR_ALPHA;
shadowColor = changeColorAlpha(mShadowColor, shadowAlpha);
} else {
mState = StateNormal;
radius = 0;
ripplePaint.setAlpha(0);
shadowColor = changeColorAlpha(mShadowColor, MIN_SHADOW_COLOR_ALPHA);
}
postInvalidate();
break;
}
backgroundPaint.setShadowLayer(mShadowRadius, mShadowOffsetX, mShadowOffsetY, shadowColor);
canvas.drawRoundRect(getRectF(), mCornerRadius, mCornerRadius, backgroundPaint);
canvas.save();
if (mState == StateTouchDown || mState == StateTouchUp) {
if (rippleClipPath == null) {
rippleClipPath = new Path();
rippleClipPath.addRoundRect(getRectF(), mCornerRadius, mCornerRadius, Path.Direction.CW);
}
canvas.clipPath(rippleClipPath);
}
canvas.drawCircle(mTouchPoint.x, mTouchPoint.y, radius, ripplePaint);
canvas.restore();
if (mText != null && mText.length() > 0) {
int y = (int) (getHeight() / 2 - ((textPaint.descent() + textPaint.ascent()) / 2));
canvas.drawText(mText.toString(), getWidth() / 2, y, textPaint);
}
}
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 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