@@ -273,38 +273,36 @@ static class PasswordCharacter {
273
273
maskToTextScale = Math .max (1f , bounds .width () / maskCharDiameter );
274
274
// scale text from it's height down to the mask character height
275
275
textToMaskScale = Math .min (0f , 1f / (bounds .height () / maskCharDiameter ));
276
- // offset the mask center from the character center
276
+ // difference between mask & character center
277
277
textOffsetY = maskCenterY - bounds .exactCenterY ();
278
278
}
279
279
280
280
281
281
/**
282
- * Progress through the morph: 0 = character, 1 = •.
282
+ * Progress through the morph: 0 = character, 1 = •
283
283
*/
284
284
void draw (Canvas canvas , TextPaint paint , CharSequence password ,
285
285
int index , float charWidth , float progress ) {
286
- final int alpha = paint .getAlpha ();
286
+ int alpha = paint .getAlpha ();
287
+ float x = charWidth * index ;
287
288
288
289
// draw the character
289
290
canvas .save ();
290
- canvas .translate (charWidth * index , 0 );
291
291
float textScale = lerp (1f , textToMaskScale , progress );
292
292
// 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 ());
294
294
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 );
296
296
canvas .restore ();
297
297
298
298
// draw the mask
299
299
canvas .save ();
300
- float dy = lerp (textOffsetY , 0f , progress );
301
- // move the mask: character center ↔ mask center
302
- canvas .translate (charWidth * index , -dy );
303
300
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 ());
306
303
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 );
308
306
canvas .restore ();
309
307
paint .setAlpha (alpha );
310
308
}
0 commit comments