Skip to content

Commit

Permalink
fixed rare issue of wrapping characters:
Browse files Browse the repository at this point in the history
  • Loading branch information
AndroidDeveloperLB committed Jul 12, 2016
1 parent dc958f8 commit 94239c0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
5 changes: 1 addition & 4 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

6 changes: 3 additions & 3 deletions AutoFitTextViewLibrary/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 23
compileSdkVersion 24
buildToolsVersion "23.0.3"

defaultConfig {
minSdkVersion 9
targetSdkVersion 23
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
Expand All @@ -31,5 +31,5 @@ android {
}

dependencies {
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:appcompat-v7:24.0.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public AutoResizeTextView(final Context context, final AttributeSet attrs, final
// prepare size tester:
_sizeTester = new SizeTester() {
final RectF textRect = new RectF();

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public int onTestSize(final int suggestedSize, final RectF availableSpace) {
Expand All @@ -82,9 +83,17 @@ public int onTestSize(final int suggestedSize, final RectF availableSpace) {
return 1;
textRect.bottom = layout.getHeight();
int maxWidth = -1;
for (int i = 0; i < layout.getLineCount(); i++)
int lineCount = layout.getLineCount();
for (int i = 0; i < lineCount; i++) {
int end = layout.getLineEnd(i);
if (i < lineCount - 1 && end > 0 && !isValidWordWrap(text.charAt(end - 1), text.charAt(end)))
return 1;
if (maxWidth < layout.getLineRight(i) - layout.getLineLeft(i))
maxWidth = (int) layout.getLineRight(i) - (int) layout.getLineLeft(i);
}
//for (int i = 0; i < layout.getLineCount(); i++)
// if (maxWidth < layout.getLineRight(i) - layout.getLineLeft(i))
// maxWidth = (int) layout.getLineRight(i) - (int) layout.getLineLeft(i);
textRect.right = maxWidth;
}
textRect.offsetTo(0, 0);
Expand All @@ -98,6 +107,10 @@ public int onTestSize(final int suggestedSize, final RectF availableSpace) {
_initialized = true;
}

public boolean isValidWordWrap(char before, char after) {
return before == ' ' || before == '-';
}

@Override
public void setAllCaps(boolean allCaps) {
super.setAllCaps(allCaps);
Expand Down
4 changes: 2 additions & 2 deletions AutoFitTextViewSample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
compileSdkVersion 24
buildToolsVersion "23.0.3"

defaultConfig {
applicationId "com.example.autofittextviewsample"
minSdkVersion 16
targetSdkVersion 23
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
Expand Down

0 comments on commit 94239c0

Please sign in to comment.