In CollapsingTextHelper we are checking both the expanded bound and the collapsed bound to be larger than 0 to decide if we are going to draw the collapsing text. However this can result in a situation that when there's no space to display expanded hint, the collapsed hint won't be drawn either, even if the hint is not expandable at all.
This CL fixes the issue in a more generic way - whenever draw() is called, we check if the current bound (should be calculated whenever the collapsing fraction is changed) is larger than 0 to decide if we need to draw the collapsing text.
This CL also adds the logic to ensure the cutout bound will never be larger than the collapsed bound.
Resolves https://github.com/material-components/material-components-android/issues/2573
PiperOrigin-RevId: 449597658
When the collapsing title is fully expanded, the current logic won't update the linear text setting correctly to false, which may result in the issue that the type face is not updated correctly. Fixes this by always updating linear text settings when the available text width is not 0.
Also refactors the typeface relevant logic so we will decide if we should recreate the static text layout in a consistent way.
Resolves https://github.com/material-components/material-components-android/issues/2463
PiperOrigin-RevId: 446735260
Includes two main fixes:
1. Applied a workaround for alpha issue of shadow layer in Paint for API 31(+).
- Issue: For API 31 and plus, Paint doesn't apply the correct alpha value to the shadow layer. When the shadow color is opaque (alpha=255), the alpha of shadow should use the alpha of the Paint. But it seems the inverse alpha (255-alpha) is applied to the shadow layer.
- Solution: Added a workaround to set shadow color with a real-time alpha value, Paint still respects to the shadow color's alpha when it's not opaque.
2. Fixed rounding issue when blending shadow color for API 30(-).
- Issue: The rounding of alpha value in removed blendColors() function is casting (round down). This causes the shadow color occasionally becomes non-opaque. Then Paint stops to apply the alpha value to it.
- Solution: When blending colors, round values with Math.round() (round to nearest).
Note: Fix (1) covers fix (2). But fix (2) is still worth to keep, if issue (1) is fixed in the framework in future and workaround is removed.
Resolves: https://github.com/material-components/material-components-android/issues/2545
PiperOrigin-RevId: 427812326
In the original logic we compares interpolated text size to decide if the available width should be the collapsed one or the expanded one. This logic wouldn't work if the collapsed text size and the expanded text size are the same. Refactors the logic to make the decision by interpolating fraction directly.
Resolves https://github.com/material-components/material-components-android/issues/2459
PiperOrigin-RevId: 410901171
After letter spacing is correctly set in CollapsingTextHelper.calculateUsingTextSize(), we no longer need to set letter spacing separately for collapsed and expanded titles. Also this enhances the logic by using textPaint consistently in CollapsingTextHelper.calculateBaseOffsets(), which was not the case before the change. (We got text height from textPaint and text width from tmpPaint.)
PiperOrigin-RevId: 410888232
We recreated title text layout when expanding from the collapsed state but didn't correctly set the letter spacing to the expanded one. The letter spacing being used will be a interpolated value between collapsed and expanded letter spacing (close to the collapsed one due to the implementation). This will cause the text layout incorrectly calculate the line count from the wrong letter spacing and result in a broken layout.
Correctly sets the letter spacing to fix the issue.
Resolves https://github.com/material-components/material-components-android/issues/2463
PiperOrigin-RevId: 408910555
We changes letter spacing during expanding/collapsing animations, which causes us use letter spacing during animation while calculating final expanded/collapsed offset instead of final letter spacing. This in turn causes hints be drawn at the wrong positions. Uses final letter spacing during calculating offset instead to fix the problem.
Resolves https://github.com/material-components/material-components-android/issues/2277
PiperOrigin-RevId: 408904991
In single line mode, we implement the expanded title alignment by calculating the expected x-coordinate of expanded title and translate the canvas so the title will be aligned. However, when maxLines > 1, the static layout will always occupy the full available width, therefore the text alignment need to be done by the static layout instead.
Provides text alignment other than NORMAL when it's in multi-line mode to solve the issue.
Resolves https://github.com/material-components/material-components-android/issues/1276
PiperOrigin-RevId: 408895140
When a collapsed label is showing, we cutout part of the border of an outlined text input box according to the exact stroke width. However when using rounded corners, there can be slight offsets from where the border is really drawn. Also, if the corner size is large, the part of border we need to cutout might not just be a straight line but contains part of the corner.
However, with the existing cutout logic, we cannot just cutout the whole label area, which will cause the area inside the border also gets cutout, if it has color. This CL changes the cutout drawing logic to only apply the cutout on stroke drawing to fix the issue.
This CL also fixes the bug that when the label is too long, we didn't take the ellipsized text length into account. Creates a variable to store the calculated collapsed text width to fix the issue.
Resolves https://github.com/material-components/material-components-android/issues/2145
PiperOrigin-RevId: 402316057
Flinging the AppBarLayout can cause a negative number to be passed to CollapsingTextHelper#calculateOffsets, causing the collapsed title in fade mode to be positioned incorrectly.
PiperOrigin-RevId: 374704850