diff options
| author | Fabrice Di Meglio <fdimeglio@google.com> | 2011-08-29 15:39:11 -0700 |
|---|---|---|
| committer | Fabrice Di Meglio <fdimeglio@google.com> | 2011-08-29 16:07:05 -0700 |
| commit | aef455fd5b4c667267deb050bc7997e737b7507e (patch) | |
| tree | 640d30ae708fdde500942a234fb91389296fc11d /core/java/android/text/StaticLayout.java | |
| parent | 3efc794f8563558b9792cc8ffa1ab9e81a0129ea (diff) | |
Fix bug #5197549 android.text.cts.StaticLayoutTest#testGetEllipsisCount fails on IRK49E mysid-userdebug
- make the ellipsizing condition easier to read
- allow ellipsizing only and only if
- not MARQUEE
- single line
- END only on the last visible line when multiple lines
Change-Id: I6b08e4a735ebc4875a208f0538d9cf937240316e
Diffstat (limited to 'core/java/android/text/StaticLayout.java')
| -rw-r--r-- | core/java/android/text/StaticLayout.java | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/core/java/android/text/StaticLayout.java b/core/java/android/text/StaticLayout.java index 788711d9ea88..e8b2045ef828 100644 --- a/core/java/android/text/StaticLayout.java +++ b/core/java/android/text/StaticLayout.java @@ -729,12 +729,22 @@ public class StaticLayout extends Layout { start - widthStart, end - start); } - // If ellipsize is in marquee mode, do not apply ellipsis on the first line - if (ellipsize != null && (ellipsize != TextUtils.TruncateAt.MARQUEE || j != 0)) { + if (ellipsize != null) { + // If there is only one line, then do any type of ellipsis except when it is MARQUEE + // if there are multiple lines, just allow END ellipsis on the last line + boolean firstLine = (j == 0); + boolean currentLineIsTheLastVisibleOne = (j + 1 == mMaximumVisibleLineCount); boolean forceEllipsis = moreChars && (mLineCount + 1 == mMaximumVisibleLineCount); - calculateEllipsis(start, end, widths, widthStart, - ellipsisWidth, ellipsize, j, - textWidth, paint, forceEllipsis); + + boolean doEllipsis = (firstLine && !moreChars && + ellipsize != TextUtils.TruncateAt.MARQUEE) || + (!firstLine && (currentLineIsTheLastVisibleOne || !moreChars) && + ellipsize == TextUtils.TruncateAt.END); + if (doEllipsis) { + calculateEllipsis(start, end, widths, widthStart, + ellipsisWidth, ellipsize, j, + textWidth, paint, forceEllipsis); + } } mLineCount++; @@ -797,8 +807,8 @@ public class StaticLayout extends Layout { ellipsisStart = i; ellipsisCount = len - i; - if (forceEllipsis && ellipsisCount == 0 && i > 0) { - ellipsisStart = i - 1; + if (forceEllipsis && ellipsisCount == 0 && len > 0) { + ellipsisStart = len - 1; ellipsisCount = 1; } } else { |
