@@ -712,17 +712,6 @@ private void calculateOffsets(final float fraction) {
712
712
textPaint .setColor (getCurrentCollapsedTextColor ());
713
713
}
714
714
715
- if (collapsedLetterSpacing != expandedLetterSpacing ) {
716
- textPaint .setLetterSpacing (
717
- lerp (
718
- expandedLetterSpacing ,
719
- collapsedLetterSpacing ,
720
- fraction ,
721
- AnimationUtils .FAST_OUT_SLOW_IN_INTERPOLATOR ));
722
- } else {
723
- textPaint .setLetterSpacing (collapsedLetterSpacing );
724
- }
725
-
726
715
// Calculates paint parameters for shadow layer.
727
716
currentShadowRadius = lerp (expandedShadowRadius , collapsedShadowRadius , fraction , null );
728
717
currentShadowDx = lerp (expandedShadowDx , collapsedShadowDx , fraction , null );
@@ -1099,7 +1088,6 @@ private void calculateUsingTextSize(final float fraction, boolean forceRecalcula
1099
1088
newTypeface = collapsedTypeface ;
1100
1089
} else {
1101
1090
newTextSize = expandedTextSize ;
1102
- newLetterSpacing = expandedLetterSpacing ;
1103
1091
newTypeface = expandedTypeface ;
1104
1092
if (isClose (fraction , /* targetValue= */ 0 )) {
1105
1093
// If we're close to the expanded text size, snap to it and use a scale of 1
@@ -1111,6 +1099,11 @@ private void calculateUsingTextSize(final float fraction, boolean forceRecalcula
1111
1099
/ expandedTextSize ;
1112
1100
}
1113
1101
1102
+ newLetterSpacing = lerp (
1103
+ expandedLetterSpacing , collapsedLetterSpacing ,
1104
+ 1f , collapsedTextSize / expandedTextSize ,
1105
+ scale );
1106
+
1114
1107
float textSizeRatio = collapsedTextSize / expandedTextSize ;
1115
1108
// This is the size of the expanded bounds when it is scaled to match the
1116
1109
// collapsed text size
@@ -1320,11 +1313,11 @@ public void setStaticLayoutBuilderConfigurer(
1320
1313
}
1321
1314
1322
1315
/**
1323
- * Returns true if {@code value } is 'close' to it's closest decimal value . Close is currently
1316
+ * Returns true if {@code value1 } is 'close' to {@code value2} . Close is currently
1324
1317
* defined as it's difference being < 0.00001.
1325
1318
*/
1326
- private static boolean isClose (float value , float targetValue ) {
1327
- return Math .abs (value - targetValue ) < 0.00001f ;
1319
+ private static boolean isClose (float value1 , float value2 ) {
1320
+ return Math .abs (value1 - value2 ) < 0.00001f ;
1328
1321
}
1329
1322
1330
1323
public ColorStateList getExpandedTextColor () {
@@ -1367,6 +1360,22 @@ private static float lerp(
1367
1360
return AnimationUtils .lerp (startValue , endValue , fraction );
1368
1361
}
1369
1362
1363
+ private static float lerp (
1364
+ float outputStart , float outputEnd ,
1365
+ float inputStart , float inputEnd ,
1366
+ float inputValue ) {
1367
+ if (isClose (inputEnd , inputStart )) {
1368
+ if (isClose (outputEnd , outputStart )) {
1369
+ return outputStart ;
1370
+ } else {
1371
+ throw new RuntimeException ("\" input\" range is empty, but \" output\" is not" );
1372
+ }
1373
+ }
1374
+
1375
+ float value = (inputValue - inputStart ) / (inputEnd - inputStart );
1376
+ return outputStart + (outputEnd - outputStart ) * value ;
1377
+ }
1378
+
1370
1379
private static boolean rectEquals (@ NonNull Rect r , int left , int top , int right , int bottom ) {
1371
1380
return !(r .left != left || r .top != top || r .right != right || r .bottom != bottom );
1372
1381
}
0 commit comments