private static void autofit(TextView view,TextPaint paint,float minTextSize,float maxTextSize,int maxLines,float precision){
  if (maxLines <= 0 || maxLines == Integer.MAX_VALUE) {
    return;
  }
  int targetWidth=view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
  if (targetWidth <= 0) {
    return;
  }
  CharSequence text=view.getText();
  TransformationMethod method=view.getTransformationMethod();
  if (method != null) {
    text=method.getTransformation(text,view);
  }
  Context context=view.getContext();
  Resources r=Resources.getSystem();
  DisplayMetrics displayMetrics;
  float size=maxTextSize;
  float high=size;
  float low=0;
  if (context != null) {
    r=context.getResources();
  }
  displayMetrics=r.getDisplayMetrics();
  paint.set(view.getPaint());
  paint.setTextSize(size);
  if ((maxLines == 1 && paint.measureText(text,0,text.length()) > targetWidth) || getLineCount(text,paint,size,targetWidth,displayMetrics) > maxLines) {
    size=getAutofitTextSize(text,paint,targetWidth,maxLines,low,high,precision,displayMetrics);
  }
  if (size < minTextSize) {
    size=minTextSize;
  }
  view.setTextSize(TypedValue.COMPLEX_UNIT_PX,size);
}

private static void autofit ( TextView view , TextPaint paint , float minTextSize , float maxTextSize , int maxLines , float precision ) { if ( maxLines <= 0 || maxLines == Integer . MAX_VALUE ) { return ; } int targetWidth = view . getWidth ( ) - view . getPaddingLeft ( ) - view . getPaddingRight ( ) ; if ( targetWidth <= 0 ) { return ; } CharSequence text = view . getText ( ) ; TransformationMethod method = view . getTransformationMethod ( ) ; if ( method != null ) { text = method . getTransformation ( text , view ) ; } Context context = view . getContext ( ) ; Resources r = Resources . getSystem ( ) ; DisplayMetrics displayMetrics ; float size = maxTextSize ; float high = size ; float low = 0 ; if ( context != null ) { r = context . getResources ( ) ; } displayMetrics = r . getDisplayMetrics ( ) ; paint . set ( view . getPaint ( ) ) ; paint . setTextSize ( size ) ; if ( ( maxLines == 1 && paint . measureText ( text , 0 , text . length ( ) ) > targetWidth ) || getLineCount ( text , paint , size , targetWidth , displayMetrics ) > maxLines ) { size = getAutofitTextSize ( text , paint , targetWidth , maxLines , low , high , precision , displayMetrics ) ; } if ( size < minTextSize ) { size = minTextSize ; } view . setTextSize ( TypedValue . COMPLEX_UNIT_PX , size ) ; }
re - sizes the textsize of the textview so that the text fits within the bounds of the view .
