Skip to content

Commit 4944aba

Browse files
committed
check for textAllCaps
when property of layout textAllCaps was set to true, the string got fit to view before the caps were applied. This fix checks if the property is set, makes the string upper case if true, and then performs the fit.
1 parent ddd35ca commit 4944aba

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

AutoFitTextViewLibrary/src/com/lb/auto_fit_textview/AutoResizeTextView.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public class AutoResizeTextView extends TextView {
2828
private int _widthLimit, _maxLines;
2929
private boolean _initialized = false;
3030
private TextPaint _paint;
31-
31+
private boolean _allCaps = false;
32+
3233
private interface SizeTester {
3334
/**
3435
* @param suggestedSize Size of text to be tested
@@ -50,6 +51,9 @@ public AutoResizeTextView(final Context context, final AttributeSet attrs) {
5051

5152
public AutoResizeTextView(final Context context, final AttributeSet attrs, final int defStyle) {
5253
super(context, attrs, defStyle);
54+
55+
_allCaps = attrs.getAttributeBooleanValue("http://schemas.android.com/apk/res/android", "textAllCaps", false);
56+
5357
// using the minimal recommended font size
5458
_minTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12, getResources().getDisplayMetrics());
5559
_maxTextSize = getTextSize();
@@ -93,6 +97,12 @@ public int onTestSize(final int suggestedSize, final RectF availableSPace) {
9397
_initialized = true;
9498
}
9599

100+
@Override
101+
public void setText(CharSequence text, BufferType type) {
102+
if( _allCaps ) text = text.toString().toUpperCase();
103+
super.setText(text, type);
104+
}
105+
96106
@Override
97107
public void setTypeface(final Typeface tf) {
98108
super.setTypeface(tf);

0 commit comments

Comments
 (0)