Skip to content

Commit 6fb89b3

Browse files
committed
Improved password mask anim efficiency.
1 parent 163f1aa commit 6fb89b3

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

Diff for: app/src/main/java/io/plaidapp/ui/widget/PasswordEntry.java

+10-12
Original file line numberDiff line numberDiff line change
@@ -273,38 +273,36 @@ static class PasswordCharacter {
273273
maskToTextScale = Math.max(1f, bounds.width() / maskCharDiameter);
274274
// scale text from it's height down to the mask character height
275275
textToMaskScale = Math.min(0f, 1f / (bounds.height() / maskCharDiameter));
276-
// offset the mask center from the character center
276+
// difference between mask & character center
277277
textOffsetY = maskCenterY - bounds.exactCenterY();
278278
}
279279

280280

281281
/**
282-
* Progress through the morph: 0 = character, 1 = •.
282+
* Progress through the morph: 0 = character, 1 = •
283283
*/
284284
void draw(Canvas canvas, TextPaint paint, CharSequence password,
285285
int index, float charWidth, float progress) {
286-
final int alpha = paint.getAlpha();
286+
int alpha = paint.getAlpha();
287+
float x = charWidth * index;
287288

288289
// draw the character
289290
canvas.save();
290-
canvas.translate(charWidth * index, 0);
291291
float textScale = lerp(1f, textToMaskScale, progress);
292292
// scale character: shrinks to/grows from the mask's height, remaining centered
293-
canvas.scale(textScale, textScale, bounds.exactCenterX(), bounds.exactCenterY());
293+
canvas.scale(textScale, textScale, x + bounds.exactCenterX(), bounds.exactCenterY());
294294
paint.setAlpha((int) lerp(alpha, 0, progress));
295-
canvas.drawText(password, index, index + 1, 0, 0, paint);
295+
canvas.drawText(password, index, index + 1, x, 0, paint);
296296
canvas.restore();
297297

298298
// draw the mask
299299
canvas.save();
300-
float dy = lerp(textOffsetY, 0f, progress);
301-
// move the mask: character center ↔ mask center
302-
canvas.translate(charWidth * index, -dy);
303300
float maskScale = lerp(maskToTextScale, 1f, progress);
304-
// scale the mask down from/up to the character size
305-
canvas.scale(maskScale, maskScale, bounds.exactCenterX(), bounds.exactCenterY() + dy);
301+
// scale the mask: down from/up to the character width
302+
canvas.scale(maskScale, maskScale, x + bounds.exactCenterX(), bounds.exactCenterY());
306303
paint.setAlpha((int) AnimUtils.lerp(0, alpha, progress));
307-
canvas.drawText(PASSWORD_MASK, 0, 1, 0, 0, paint);
304+
// vertically move the mask: character center ↔ mask center
305+
canvas.drawText(PASSWORD_MASK, 0, 1, x, -lerp(textOffsetY, 0f, progress), paint);
308306
canvas.restore();
309307
paint.setAlpha(alpha);
310308
}

0 commit comments

Comments
 (0)