2020
2121import static androidx .annotation .RestrictTo .Scope .LIBRARY_GROUP ;
2222import static com .google .android .material .theme .overlay .MaterialThemeOverlay .wrap ;
23+ import static java .lang .Math .ceil ;
2324import static java .lang .Math .max ;
2425import static java .lang .Math .min ;
2526
@@ -613,24 +614,12 @@ private void updateIconPosition(int buttonWidth, int buttonHeight) {
613614 }
614615
615616 private int getTextLayoutWidth () {
616- int maxWidth = 0 ;
617+ float maxWidth = 0 ;
617618 int lineCount = getLineCount ();
618619 for (int line = 0 ; line < lineCount ; line ++) {
619- maxWidth = max (maxWidth , getTextWidth ( getTextInLine (line ) ));
620+ maxWidth = max (maxWidth , getLayout (). getLineWidth (line ));
620621 }
621- return maxWidth ;
622- }
623-
624- private int getTextWidth (CharSequence text ) {
625- Paint textPaint = getPaint ();
626- String buttonText = text .toString ();
627- if (getTransformationMethod () != null ) {
628- // if text is transformed, add that transformation to to ensure correct calculation
629- // of icon padding.
630- buttonText = getTransformationMethod ().getTransformation (buttonText , this ).toString ();
631- }
632-
633- return min ((int ) textPaint .measureText (buttonText ), getLayout ().getEllipsizedWidth ());
622+ return (int ) ceil (maxWidth );
634623 }
635624
636625 private int getTextHeight () {
@@ -652,12 +641,6 @@ private int getTextHeight() {
652641 return min (bounds .height (), getLayout ().getHeight ());
653642 }
654643
655- private CharSequence getTextInLine (int line ) {
656- int start = getLayout ().getLineStart (line );
657- int end = getLayout ().getLineEnd (line );
658- return getText ().subSequence (start , end );
659- }
660-
661644 private boolean isLayoutRTL () {
662645 return ViewCompat .getLayoutDirection (this ) == ViewCompat .LAYOUT_DIRECTION_RTL ;
663646 }
0 commit comments