2222public class AutoResizeTextView extends TextView
2323 {
2424 private static final int NO_LINE_LIMIT =-1 ;
25- private final RectF mAvailableSpaceRect =new RectF ();
26- private final SparseIntArray mTextCachedSizes =new SparseIntArray ();
27- private float mMaxTextSize ;
28- private float mSpacingMult = 1.0f ;
29- private float mSpacingAdd = 0 .0f ;
30- private float mMinTextSize ;
31- private int mWidthLimit ;
32- private int mMaxLines ;
33- private boolean mEnableSizeCache = true ;
34- private final SizeTester mSizeTester ;
35- private boolean mInitiallized =false ;
25+ private final RectF _availableSpaceRect =new RectF ();
26+ private final SparseIntArray _textCachedSizes =new SparseIntArray ();
27+ private final SizeTester _sizeTester ;
28+ private float _maxTextSize ;
29+ private float _spacingMult = 1 .0f ;
30+ private float _spacingAdd = 0.0f ;
31+ private float _minTextSize ;
32+ private int _widthLimit ;
33+ private int _maxLines ;
34+ private boolean _enableSizeCache = true ;
35+ private boolean _initiallized =false ;
3636
3737 private interface SizeTester
3838 {
@@ -62,14 +62,14 @@ public AutoResizeTextView(final Context context,final AttributeSet attrs,final i
6262 {
6363 super (context ,attrs ,defStyle );
6464 // using the minimal recommended font size
65- mMinTextSize =TypedValue .applyDimension (TypedValue .COMPLEX_UNIT_SP ,12 ,getResources ().getDisplayMetrics ());
66- mMaxTextSize =getTextSize ();
67- if (mMaxLines ==0 )
65+ _minTextSize =TypedValue .applyDimension (TypedValue .COMPLEX_UNIT_SP ,12 ,getResources ().getDisplayMetrics ());
66+ _maxTextSize =getTextSize ();
67+ if (_maxLines ==0 )
6868 // no value was assigned during construction
69- mMaxLines =NO_LINE_LIMIT ;
69+ _maxLines =NO_LINE_LIMIT ;
7070 // prepare size tester:
7171 final TextPaint paint =new TextPaint (getPaint ());
72- mSizeTester =new SizeTester ()
72+ _sizeTester =new SizeTester ()
7373 {
7474 final RectF textRect =new RectF ();
7575
@@ -87,7 +87,7 @@ public int onTestSize(final int suggestedSize,final RectF availableSPace)
8787 }
8888 else
8989 {
90- final StaticLayout layout =new StaticLayout (text ,paint ,mWidthLimit ,Alignment .ALIGN_NORMAL ,mSpacingMult , mSpacingAdd ,true );
90+ final StaticLayout layout =new StaticLayout (text ,paint ,_widthLimit ,Alignment .ALIGN_NORMAL ,_spacingMult , _spacingAdd ,true );
9191 // return early if we have more lines
9292 if (getMaxLines ()!=NO_LINE_LIMIT &&layout .getLineCount ()>getMaxLines ())
9393 return 1 ;
@@ -106,36 +106,36 @@ public int onTestSize(final int suggestedSize,final RectF availableSPace)
106106 return 1 ;
107107 }
108108 };
109- mInitiallized =true ;
109+ _initiallized =true ;
110110 }
111111
112112 @ Override
113113 public void setTextSize (final float size )
114114 {
115- mMaxTextSize =size ;
116- mTextCachedSizes .clear ();
115+ _maxTextSize =size ;
116+ _textCachedSizes .clear ();
117117 adjustTextSize ();
118118 }
119119
120120 @ Override
121121 public void setMaxLines (final int maxlines )
122122 {
123123 super .setMaxLines (maxlines );
124- mMaxLines =maxlines ;
124+ _maxLines =maxlines ;
125125 reAdjust ();
126126 }
127127
128128 @ Override
129129 public int getMaxLines ()
130130 {
131- return mMaxLines ;
131+ return _maxLines ;
132132 }
133133
134134 @ Override
135135 public void setSingleLine ()
136136 {
137137 super .setSingleLine ();
138- mMaxLines =1 ;
138+ _maxLines =1 ;
139139 reAdjust ();
140140 }
141141
@@ -144,16 +144,16 @@ public void setSingleLine(final boolean singleLine)
144144 {
145145 super .setSingleLine (singleLine );
146146 if (singleLine )
147- mMaxLines =1 ;
148- else mMaxLines =NO_LINE_LIMIT ;
147+ _maxLines =1 ;
148+ else _maxLines =NO_LINE_LIMIT ;
149149 reAdjust ();
150150 }
151151
152152 @ Override
153153 public void setLines (final int lines )
154154 {
155155 super .setLines (lines );
156- mMaxLines =lines ;
156+ _maxLines =lines ;
157157 reAdjust ();
158158 }
159159
@@ -165,17 +165,17 @@ public void setTextSize(final int unit,final float size)
165165 if (c ==null )
166166 r =Resources .getSystem ();
167167 else r =c .getResources ();
168- mMaxTextSize =TypedValue .applyDimension (unit ,size ,r .getDisplayMetrics ());
169- mTextCachedSizes .clear ();
168+ _maxTextSize =TypedValue .applyDimension (unit ,size ,r .getDisplayMetrics ());
169+ _textCachedSizes .clear ();
170170 adjustTextSize ();
171171 }
172172
173173 @ Override
174174 public void setLineSpacing (final float add ,final float mult )
175175 {
176176 super .setLineSpacing (add ,mult );
177- mSpacingMult =mult ;
178- mSpacingAdd =add ;
177+ _spacingMult =mult ;
178+ _spacingAdd =add ;
179179 }
180180
181181 /**
@@ -185,7 +185,7 @@ public void setLineSpacing(final float add,final float mult)
185185 */
186186 public void setMinTextSize (final float minTextSize )
187187 {
188- mMinTextSize =minTextSize ;
188+ _minTextSize =minTextSize ;
189189 reAdjust ();
190190 }
191191
@@ -196,14 +196,14 @@ private void reAdjust()
196196
197197 private void adjustTextSize ()
198198 {
199- if (!mInitiallized )
199+ if (!_initiallized )
200200 return ;
201- final int startSize =(int )mMinTextSize ;
201+ final int startSize =(int )_minTextSize ;
202202 final int heightLimit =getMeasuredHeight ()-getCompoundPaddingBottom ()-getCompoundPaddingTop ();
203- mWidthLimit =getMeasuredWidth ()-getCompoundPaddingLeft ()-getCompoundPaddingRight ();
204- mAvailableSpaceRect .right =mWidthLimit ;
205- mAvailableSpaceRect .bottom =heightLimit ;
206- super .setTextSize (TypedValue .COMPLEX_UNIT_PX ,efficientTextSizeSearch (startSize ,(int )mMaxTextSize , mSizeTester , mAvailableSpaceRect ));
203+ _widthLimit =getMeasuredWidth ()-getCompoundPaddingLeft ()-getCompoundPaddingRight ();
204+ _availableSpaceRect .right =_widthLimit ;
205+ _availableSpaceRect .bottom =heightLimit ;
206+ super .setTextSize (TypedValue .COMPLEX_UNIT_PX ,efficientTextSizeSearch (startSize ,(int )_maxTextSize , _sizeTester , _availableSpaceRect ));
207207 }
208208
209209 /**
@@ -217,22 +217,22 @@ private void adjustTextSize()
217217 */
218218 public void setEnableSizeCache (final boolean enable )
219219 {
220- mEnableSizeCache =enable ;
221- mTextCachedSizes .clear ();
220+ _enableSizeCache =enable ;
221+ _textCachedSizes .clear ();
222222 adjustTextSize ();
223223 }
224224
225225 private int efficientTextSizeSearch (final int start ,final int end ,final SizeTester sizeTester ,final RectF availableSpace )
226226 {
227- if (!mEnableSizeCache )
227+ if (!_enableSizeCache )
228228 return binarySearch (start ,end ,sizeTester ,availableSpace );
229229 final String text =getText ().toString ();
230230 final int key =text ==null ? 0 : text .length ();
231- int size =mTextCachedSizes .get (key );
231+ int size =_textCachedSizes .get (key );
232232 if (size !=0 )
233233 return size ;
234234 size =binarySearch (start ,end ,sizeTester ,availableSpace );
235- mTextCachedSizes .put (key ,size );
235+ _textCachedSizes .put (key ,size );
236236 return size ;
237237 }
238238
@@ -273,7 +273,7 @@ protected void onTextChanged(final CharSequence text,final int start,final int b
273273 @ Override
274274 protected void onSizeChanged (final int width ,final int height ,final int oldwidth ,final int oldheight )
275275 {
276- mTextCachedSizes .clear ();
276+ _textCachedSizes .clear ();
277277 super .onSizeChanged (width ,height ,oldwidth ,oldheight );
278278 if (width !=oldwidth ||height !=oldheight )
279279 reAdjust ();
0 commit comments