@@ -696,17 +696,6 @@ private void calculateOffsets(final float fraction) {
696
696
textPaint .setColor (getCurrentCollapsedTextColor ());
697
697
}
698
698
699
- if (collapsedLetterSpacing != expandedLetterSpacing ) {
700
- textPaint .setLetterSpacing (
701
- lerp (
702
- expandedLetterSpacing ,
703
- collapsedLetterSpacing ,
704
- fraction ,
705
- AnimationUtils .FAST_OUT_SLOW_IN_INTERPOLATOR ));
706
- } else {
707
- textPaint .setLetterSpacing (collapsedLetterSpacing );
708
- }
709
-
710
699
// Calculates paint parameters for shadow layer.
711
700
currentShadowRadius = lerp (expandedShadowRadius , collapsedShadowRadius , fraction , null );
712
701
currentShadowDx = lerp (expandedShadowDx , collapsedShadowDx , fraction , null );
@@ -1068,7 +1057,6 @@ private void calculateUsingTextSize(final float fraction, boolean forceRecalcula
1068
1057
newTypeface = collapsedTypeface ;
1069
1058
} else {
1070
1059
newTextSize = expandedTextSize ;
1071
- newLetterSpacing = expandedLetterSpacing ;
1072
1060
newTypeface = expandedTypeface ;
1073
1061
if (isClose (fraction , /* targetValue= */ 0 )) {
1074
1062
// If we're close to the expanded text size, snap to it and use a scale of 1
@@ -1080,6 +1068,11 @@ private void calculateUsingTextSize(final float fraction, boolean forceRecalcula
1080
1068
/ expandedTextSize ;
1081
1069
}
1082
1070
1071
+ newLetterSpacing = lerp (
1072
+ expandedLetterSpacing , collapsedLetterSpacing ,
1073
+ 1f , collapsedTextSize / expandedTextSize ,
1074
+ scale );
1075
+
1083
1076
float textSizeRatio = collapsedTextSize / expandedTextSize ;
1084
1077
// This is the size of the expanded bounds when it is scaled to match the
1085
1078
// collapsed text size
@@ -1289,11 +1282,11 @@ public void setStaticLayoutBuilderConfigurer(
1289
1282
}
1290
1283
1291
1284
/**
1292
- * Returns true if {@code value } is 'close' to it's closest decimal value . Close is currently
1285
+ * Returns true if {@code value1 } is 'close' to {@code value2} . Close is currently
1293
1286
* defined as it's difference being < 0.00001.
1294
1287
*/
1295
- private static boolean isClose (float value , float targetValue ) {
1296
- return Math .abs (value - targetValue ) < 0.00001f ;
1288
+ private static boolean isClose (float value1 , float value2 ) {
1289
+ return Math .abs (value1 - value2 ) < 0.00001f ;
1297
1290
}
1298
1291
1299
1292
public ColorStateList getExpandedTextColor () {
@@ -1336,6 +1329,22 @@ private static float lerp(
1336
1329
return AnimationUtils .lerp (startValue , endValue , fraction );
1337
1330
}
1338
1331
1332
+ private static float lerp (
1333
+ float outputStart , float outputEnd ,
1334
+ float inputStart , float inputEnd ,
1335
+ float inputValue ) {
1336
+ if (isClose (inputEnd , inputStart )) {
1337
+ if (isClose (outputEnd , outputStart )) {
1338
+ return outputStart ;
1339
+ } else {
1340
+ throw new RuntimeException ("\" input\" range is empty, but \" output\" is not" );
1341
+ }
1342
+ }
1343
+
1344
+ float value = (inputValue - inputStart ) / (inputEnd - inputStart );
1345
+ return outputStart + (outputEnd - outputStart ) * value ;
1346
+ }
1347
+
1339
1348
private static boolean rectEquals (@ NonNull Rect r , int left , int top , int right , int bottom ) {
1340
1349
return !(r .left != left || r .top != top || r .right != right || r .bottom != bottom );
1341
1350
}
0 commit comments