Skip to content

Commit

Permalink
fix(android): ellipsing fix
Browse files Browse the repository at this point in the history
  • Loading branch information
farfromrefug committed Mar 13, 2021
1 parent 38d6485 commit a1339a5
Showing 1 changed file with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class EllipsizingTextView extends AppCompatTextView {
final static String TAG = "EllipsizingTextView";

private TextUtils.TruncateAt ellipsize = null;
private TextUtils.TruncateAt multiLineEllipsize = null;
// private TextUtils.TruncateAt multiLineEllipsize = null;
private boolean isEllipsized = false;
private boolean needsEllipsing = false;
private boolean needsResizing = false;
Expand Down Expand Up @@ -380,7 +380,7 @@ public void setText(CharSequence text, BufferType type) {

private void updateShouldEllipsize() {
// log("EllipsizingTextView updateShouldEllipsize");
needsEllipsize = (ellipsize != null || multiLineEllipsize != null) && fullText != null && fullText.length() > 0;
needsEllipsize = (ellipsize != null) && fullText != null && fullText.length() > 0;

}

Expand Down Expand Up @@ -418,16 +418,16 @@ protected void onTextChanged(final CharSequence text, final int start, final int
}
}

public void setMultiLineEllipsize(TextUtils.TruncateAt where) {
// log("EllipsizingTextView setMultiLineEllipsize");
multiLineEllipsize = where;
updateShouldEllipsize();
updateEllipsize();
}
// public void setMultiLineEllipsize(TextUtils.TruncateAt where) {
// // log("EllipsizingTextView setMultiLineEllipsize");
// multiLineEllipsize = where;
// updateShouldEllipsize();
// updateEllipsize();
// }

public TextUtils.TruncateAt getMultiLineEllipsize() {
return multiLineEllipsize;
}
// public TextUtils.TruncateAt getMultiLineEllipsize() {
// return multiLineEllipsize;
// }

private void refitText(String text, int textWidth) {
// log("EllipsizingTextView refitText");
Expand Down Expand Up @@ -520,7 +520,7 @@ private void ellipseText(int width, int height) {

if (fullText instanceof Spanned) {
SpannableStringBuilder htmlWorkingText = new SpannableStringBuilder(fullText);
if (this.singleline == false && multiLineEllipsize != null) {
if (this.singleline == false) {
SpannableStringBuilder newText = new SpannableStringBuilder();
String str = htmlWorkingText.toString();
String[] separated = str.split("\n");
Expand Down Expand Up @@ -554,7 +554,7 @@ private void ellipseText(int width, int height) {

CharSequence lastLine = newText.subSequence(newStart, newStart + lineSpanned.length());
if (createWorkingLayout(lastLine, width).getLineCount() > 1)
lastLine = getEllipsedTextForOneLine(lastLine, multiLineEllipsize, width);
lastLine = getEllipsedTextForOneLine(lastLine, ellipsize, width);

newText.replace(newStart, newStart + lineSpanned.length(), lastLine);
}
Expand All @@ -564,7 +564,7 @@ private void ellipseText(int width, int height) {
newStart = newText.length();
}
workingText = newText;
} else {
} else{
Layout layout = createWorkingLayout(workingText, width);
int linesCount = getLinesCount(layout, height);
if (layout.getLineCount() > linesCount && ellipsize != null) {
Expand All @@ -584,15 +584,15 @@ private void ellipseText(int width, int height) {
}
}
} else {
if (this.singleline == false && multiLineEllipsize != null) {
if (this.singleline == false) {
String str = workingText.toString();
String newText = new String();
String[] separated = str.split("\n");
for (int i = 0; i < separated.length; i++) {
String linestr = separated[i];
if (linestr.length() > 0) {
if (createWorkingLayout(linestr, width).getLineCount() > 1)
newText += getEllipsedTextForOneLine(linestr, multiLineEllipsize, width);
newText += getEllipsedTextForOneLine(linestr, ellipsize, width);
else
newText += linestr;
}
Expand Down

0 comments on commit a1339a5

Please sign in to comment.