2019-06-03 23:25:05 +02:00
|
|
|
package org.mian.gitnex.helpers;
|
|
|
|
|
2020-04-12 20:33:41 +02:00
|
|
|
import android.graphics.Paint;
|
|
|
|
import android.graphics.Rect;
|
|
|
|
import android.graphics.Typeface;
|
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
/**
|
|
|
|
* Author M M Arif
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class LabelWidthCalculator {
|
|
|
|
|
2020-04-12 20:33:41 +02:00
|
|
|
public static int calculateLabelWidth(String text, Typeface typeface, int textSize, int paddingLeftRight) {
|
|
|
|
|
|
|
|
Paint paint = new Paint();
|
|
|
|
Rect rect = new Rect();
|
|
|
|
|
|
|
|
paint.setTextSize(textSize);
|
|
|
|
paint.setTypeface(typeface);
|
|
|
|
paint.getTextBounds(text, 0, text.length(), rect);
|
|
|
|
|
|
|
|
return rect.width() + (paddingLeftRight * 2);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|