Skip to content

Commit

Permalink
[CollapsingToolbarLayout] Constrain adjusted font weight to acceptabl…
Browse files Browse the repository at this point in the history
…e values

PiperOrigin-RevId: 425438646
  • Loading branch information
Material Design Team authored and pekingme committed Feb 1, 2022
1 parent b3db1cc commit 5dce006
Showing 1 changed file with 9 additions and 5 deletions.
Expand Up @@ -523,16 +523,20 @@ public void maybeUpdateFontWeightAdjustment(@NonNull Configuration configuration
}

private boolean shouldUseBoldTypefaces() {
return VERSION.SDK_INT >= VERSION_CODES.S && fontWeightAdjustment >= FontStyle.FONT_WEIGHT_MIN;
return VERSION.SDK_INT >= VERSION_CODES.S
&& fontWeightAdjustment != Configuration.FONT_WEIGHT_ADJUSTMENT_UNDEFINED
&& fontWeightAdjustment != 0;
}

@Nullable
private Typeface maybeCloneWithAdjustment(@NonNull Typeface typeface) {
if (shouldUseBoldTypefaces()) {
return Typeface.create(
typeface,
typeface.getWeight() + fontWeightAdjustment,
typeface.isItalic());
int adjustedWeight =
MathUtils.clamp(
typeface.getWeight() + fontWeightAdjustment,
FontStyle.FONT_WEIGHT_MIN,
FontStyle.FONT_WEIGHT_MAX);
return Typeface.create(typeface, adjustedWeight, typeface.isItalic());
}
return null;
}
Expand Down

0 comments on commit 5dce006

Please sign in to comment.