Skip to content

Commit 94239c0

Browse files
fixed rare issue of wrapping characters:
#15 (comment)
1 parent dc958f8 commit 94239c0

File tree

5 files changed

+20
-16
lines changed

5 files changed

+20
-16
lines changed

.idea/misc.xml

+1-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

-6
This file was deleted.

AutoFitTextViewLibrary/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
apply plugin: 'com.android.library'
22

33
android {
4-
compileSdkVersion 23
4+
compileSdkVersion 24
55
buildToolsVersion "23.0.3"
66

77
defaultConfig {
88
minSdkVersion 9
9-
targetSdkVersion 23
9+
targetSdkVersion 24
1010
versionCode 1
1111
versionName "1.0"
1212
}
@@ -31,5 +31,5 @@ android {
3131
}
3232

3333
dependencies {
34-
compile 'com.android.support:appcompat-v7:23.3.0'
34+
compile 'com.android.support:appcompat-v7:24.0.0'
3535
}

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

+14-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public AutoResizeTextView(final Context context, final AttributeSet attrs, final
6161
// prepare size tester:
6262
_sizeTester = new SizeTester() {
6363
final RectF textRect = new RectF();
64+
6465
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
6566
@Override
6667
public int onTestSize(final int suggestedSize, final RectF availableSpace) {
@@ -82,9 +83,17 @@ public int onTestSize(final int suggestedSize, final RectF availableSpace) {
8283
return 1;
8384
textRect.bottom = layout.getHeight();
8485
int maxWidth = -1;
85-
for (int i = 0; i < layout.getLineCount(); i++)
86+
int lineCount = layout.getLineCount();
87+
for (int i = 0; i < lineCount; i++) {
88+
int end = layout.getLineEnd(i);
89+
if (i < lineCount - 1 && end > 0 && !isValidWordWrap(text.charAt(end - 1), text.charAt(end)))
90+
return 1;
8691
if (maxWidth < layout.getLineRight(i) - layout.getLineLeft(i))
8792
maxWidth = (int) layout.getLineRight(i) - (int) layout.getLineLeft(i);
93+
}
94+
//for (int i = 0; i < layout.getLineCount(); i++)
95+
// if (maxWidth < layout.getLineRight(i) - layout.getLineLeft(i))
96+
// maxWidth = (int) layout.getLineRight(i) - (int) layout.getLineLeft(i);
8897
textRect.right = maxWidth;
8998
}
9099
textRect.offsetTo(0, 0);
@@ -98,6 +107,10 @@ public int onTestSize(final int suggestedSize, final RectF availableSpace) {
98107
_initialized = true;
99108
}
100109

110+
public boolean isValidWordWrap(char before, char after) {
111+
return before == ' ' || before == '-';
112+
}
113+
101114
@Override
102115
public void setAllCaps(boolean allCaps) {
103116
super.setAllCaps(allCaps);

AutoFitTextViewSample/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 23
4+
compileSdkVersion 24
55
buildToolsVersion "23.0.3"
66

77
defaultConfig {
88
applicationId "com.example.autofittextviewsample"
99
minSdkVersion 16
10-
targetSdkVersion 23
10+
targetSdkVersion 24
1111
versionCode 1
1212
versionName "1.0"
1313
}

0 commit comments

Comments
 (0)