@@ -34,7 +34,7 @@ public class AutoResizeTextView extends TextView
3434 private int _maxLines ;
3535 private boolean _enableSizeCache =true ;
3636 private boolean _initiallized =false ;
37- private TextPaint paint ;
37+ private final TextPaint _paint ;
3838
3939 private interface SizeTester
4040 {
@@ -64,6 +64,7 @@ public AutoResizeTextView(final Context context,final AttributeSet attrs,final i
6464 // using the minimal recommended font size
6565 _minTextSize =TypedValue .applyDimension (TypedValue .COMPLEX_UNIT_SP ,12 ,getResources ().getDisplayMetrics ());
6666 _maxTextSize =getTextSize ();
67+ _paint = new TextPaint (getPaint ());
6768 if (_maxLines ==0 )
6869 // no value was assigned during construction
6970 _maxLines =NO_LINE_LIMIT ;
@@ -76,17 +77,17 @@ public AutoResizeTextView(final Context context,final AttributeSet attrs,final i
7677 @ Override
7778 public int onTestSize (final int suggestedSize ,final RectF availableSPace )
7879 {
79- paint .setTextSize (suggestedSize );
80+ _paint .setTextSize (suggestedSize );
8081 final String text =getText ().toString ();
8182 final boolean singleLine =getMaxLines ()==1 ;
8283 if (singleLine )
8384 {
84- textRect .bottom =paint .getFontSpacing ();
85- textRect .right =paint .measureText (text );
85+ textRect .bottom =_paint .getFontSpacing ();
86+ textRect .right =_paint .measureText (text );
8687 }
8788 else
8889 {
89- final StaticLayout layout =new StaticLayout (text ,paint ,_widthLimit ,Alignment .ALIGN_NORMAL ,_spacingMult ,_spacingAdd ,true );
90+ final StaticLayout layout =new StaticLayout (text ,_paint ,_widthLimit ,Alignment .ALIGN_NORMAL ,_spacingMult ,_spacingAdd ,true );
9091 // return early if we have more lines
9192 if (getMaxLines ()!=NO_LINE_LIMIT &&layout .getLineCount ()>getMaxLines ())
9293 return 1 ;
@@ -111,9 +112,7 @@ public int onTestSize(final int suggestedSize,final RectF availableSPace)
111112 @ Override
112113 public void setTypeface (final Typeface tf )
113114 {
114- if (paint ==null )
115- paint =new TextPaint (getPaint ());
116- paint .setTypeface (tf );
115+ _paint .setTypeface (tf );
117116 adjustTextSize ();
118117 super .setTypeface (tf );
119118 }
0 commit comments