下面列出了android.text.TextPaint#getAlpha ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void initPaintObjects()
{
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
textPaint.setTextSize(hintTextSize);
if (typeface != null)
{
textPaint.setTypeface(typeface);
}
textPaint.setColor(baseColor);
baseAlpha = textPaint.getAlpha();
selectorPath = new Path();
selectorPath.setFillType(Path.FillType.EVEN_ODD);
selectorPoints = new Point[3];
for (int i = 0; i < 3; i++)
{
selectorPoints[i] = new Point();
}
}
private void initPaintObjects() {
int labelTextSize = getResources().getDimensionPixelSize(R.dimen.label_text_size);
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
textPaint.setTextSize(labelTextSize);
if (typeface != null) {
textPaint.setTypeface(typeface);
}
textPaint.setColor(baseColor);
baseAlpha = textPaint.getAlpha();
selectorPath = new Path();
selectorPath.setFillType(Path.FillType.EVEN_ODD);
selectorPoints = new Point[3];
for (int i = 0; i < 3; i++) {
selectorPoints[i] = new Point();
}
}
private void initPaintObjects() {
int labelTextSize = getResources().getDimensionPixelSize(R.dimen.label_text_size);
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
textPaint.setTextSize(labelTextSize);
if (typeface != null) {
textPaint.setTypeface(typeface);
}
textPaint.setColor(baseColor);
baseAlpha = textPaint.getAlpha();
selectorPath = new Path();
selectorPath.setFillType(Path.FillType.EVEN_ODD);
selectorPoints = new Point[3];
for (int i = 0; i < 3; i++) {
selectorPoints[i] = new Point();
}
}
private void initPaintObjects() {
int labelTextSize = getResources().getDimensionPixelSize(R.dimen.label_text_size);
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
textPaint.setTextSize(labelTextSize);
if (typeface != null) {
textPaint.setTypeface(typeface);
}
textPaint.setColor(baseColor);
baseAlpha = textPaint.getAlpha();
selectorPath = new Path();
selectorPath.setFillType(Path.FillType.EVEN_ODD);
selectorPoints = new Point[3];
for (int i = 0; i < 3; i++) {
selectorPoints[i] = new Point();
}
}
private TextProgressDrawable(Builder builder) {
mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
mTextPaint.setStyle(Paint.Style.FILL);
mTextPaint.setColor(builder.mTextColor);
mTextPaint.setTextSize(builder.mTextSize);
Paint.FontMetrics fm = mTextPaint.getFontMetrics();
mText = builder.mText;
mTextHeight = Math.round(fm.descent - fm.ascent);
mTextWidth = Math.round(mTextPaint.measureText(mText, 0, mText.length()));
mMaxAlpha = mTextPaint.getAlpha();
mFBounds = new Rect();
mAlphaAnimator = ValueAnimator.ofFloat(1f, 0f, 1f);
mAlphaAnimator.setDuration(builder.mDuration);
mAlphaAnimator.setRepeatCount(ValueAnimator.INFINITE);
mAlphaAnimator.addUpdateListener(this);
}
/**
* Progress through the morph: 0 = character, 1 = •
*/
void draw(Canvas canvas, TextPaint paint, CharSequence password,
int index, float charWidth, float progress) {
int alpha = paint.getAlpha();
float x = charWidth * index;
// draw the character
canvas.save();
float textScale = lerp(1f, textToMaskScale, progress);
// scale character: shrinks to/grows from the mask's height
canvas.scale(textScale, textScale, x + bounds.exactCenterX(), bounds.exactCenterY());
// cross fade between the character/mask
paint.setAlpha((int) lerp(alpha, 0, progress));
// vertically move the character center toward/from the mask center
canvas.drawText(password, index, index + 1,
x, lerp(0f, textOffsetY, progress) / textScale, paint);
canvas.restore();
// draw the mask
canvas.save();
float maskScale = lerp(maskToTextScale, 1f, progress);
// scale the mask: down from/up to the character width
canvas.scale(maskScale, maskScale, x + bounds.exactCenterX(), bounds.exactCenterY());
// cross fade between the mask/character
paint.setAlpha((int) AnimUtils.lerp(0, alpha, progress));
// vertically move the mask center from/toward the character center
canvas.drawText(PASSWORD_MASK, 0, 1, x, -lerp(textOffsetY, 0f, progress), paint);
canvas.restore();
// restore the paint to how we found it
paint.setAlpha(alpha);
}