Skip to content

Commit 8013290

Browse files
Fabrice Di MeglioAndroid (Google) Code Review
authored andcommitted
Merge "Fix bug #5366547 TruncateAt.MARQUEE should be replaces with "two dot" ellipsis on hardware that dont support MARQUEE"
2 parents 8eb34ed + cb33264 commit 8013290

File tree

4 files changed

+37
-22
lines changed

4 files changed

+37
-22
lines changed

core/java/android/text/StaticLayout.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,8 @@ private void calculateEllipsis(int lineStart, int lineEnd,
763763
return;
764764
}
765765

766-
float ellipsisWidth = paint.measureText(HORIZONTAL_ELLIPSIS);
766+
float ellipsisWidth = paint.measureText(
767+
(where == TextUtils.TruncateAt.END_SMALL) ? ELLIPSIS_TWO_DOTS : ELLIPSIS_NORMAL);
767768
int ellipsisStart = 0;
768769
int ellipsisCount = 0;
769770
int len = lineEnd - lineStart;
@@ -791,7 +792,8 @@ private void calculateEllipsis(int lineStart, int lineEnd,
791792
Log.w(TAG, "Start Ellipsis only supported with one line");
792793
}
793794
}
794-
} else if (where == TextUtils.TruncateAt.END || where == TextUtils.TruncateAt.MARQUEE) {
795+
} else if (where == TextUtils.TruncateAt.END || where == TextUtils.TruncateAt.MARQUEE ||
796+
where == TextUtils.TruncateAt.END_SMALL) {
795797
float sum = 0;
796798
int i;
797799

@@ -1001,7 +1003,9 @@ void finish() {
10011003
private static final char CHAR_HYPHEN = '-';
10021004

10031005
private static final double EXTRA_ROUNDING = 0.5;
1004-
private static final String HORIZONTAL_ELLIPSIS = "\u2026"; // this is "..."
1006+
1007+
private static final String ELLIPSIS_NORMAL = "\u2026"; // this is "..."
1008+
private static final String ELLIPSIS_TWO_DOTS = "\u2025"; // this is ".."
10051009

10061010
private static final int CHAR_FIRST_HIGH_SURROGATE = 0xD800;
10071011
private static final int CHAR_LAST_LOW_SURROGATE = 0xDFFF;

core/java/android/text/TextUtils.java

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@
5353
import java.util.regex.Pattern;
5454

5555
public class TextUtils {
56-
private TextUtils() { /* cannot be instantiated */ }
5756

58-
private static String[] EMPTY_STRING_ARRAY = new String[]{};
57+
private TextUtils() { /* cannot be instantiated */ }
5958

6059
public static void getChars(CharSequence s, int start, int end,
6160
char[] dest, int destoff) {
@@ -1000,6 +999,10 @@ public enum TruncateAt {
1000999
MIDDLE,
10011000
END,
10021001
MARQUEE,
1002+
/**
1003+
* @hide
1004+
*/
1005+
END_SMALL
10031006
}
10041007

10051008
public interface EllipsizeCallback {
@@ -1010,8 +1013,6 @@ public interface EllipsizeCallback {
10101013
public void ellipsized(int start, int end);
10111014
}
10121015

1013-
private static String sEllipsis = null;
1014-
10151016
/**
10161017
* Returns the original text if it fits in the specified width
10171018
* given the properties of the specified Paint,
@@ -1042,7 +1043,8 @@ public static CharSequence ellipsize(CharSequence text,
10421043
boolean preserveLength,
10431044
EllipsizeCallback callback) {
10441045
return ellipsize(text, paint, avail, where, preserveLength, callback,
1045-
TextDirectionHeuristics.FIRSTSTRONG_LTR);
1046+
TextDirectionHeuristics.FIRSTSTRONG_LTR,
1047+
(where == TruncateAt.END_SMALL) ? ELLIPSIS_TWO_DOTS : ELLIPSIS_NORMAL);
10461048
}
10471049

10481050
/**
@@ -1063,11 +1065,7 @@ public static CharSequence ellipsize(CharSequence text,
10631065
float avail, TruncateAt where,
10641066
boolean preserveLength,
10651067
EllipsizeCallback callback,
1066-
TextDirectionHeuristic textDir) {
1067-
if (sEllipsis == null) {
1068-
Resources r = Resources.getSystem();
1069-
sEllipsis = r.getString(R.string.ellipsis);
1070-
}
1068+
TextDirectionHeuristic textDir, String ellipsis) {
10711069

10721070
int len = text.length();
10731071

@@ -1085,7 +1083,7 @@ public static CharSequence ellipsize(CharSequence text,
10851083

10861084
// XXX assumes ellipsis string does not require shaping and
10871085
// is unaffected by style
1088-
float ellipsiswid = paint.measureText(sEllipsis);
1086+
float ellipsiswid = paint.measureText(ellipsis);
10891087
avail -= ellipsiswid;
10901088

10911089
int left = 0;
@@ -1094,7 +1092,7 @@ public static CharSequence ellipsize(CharSequence text,
10941092
// it all goes
10951093
} else if (where == TruncateAt.START) {
10961094
right = len - mt.breakText(0, len, false, avail);
1097-
} else if (where == TruncateAt.END) {
1095+
} else if (where == TruncateAt.END || where == TruncateAt.END_SMALL) {
10981096
left = mt.breakText(0, len, true, avail);
10991097
} else {
11001098
right = len - mt.breakText(0, len, false, avail / 2);
@@ -1112,10 +1110,10 @@ public static CharSequence ellipsize(CharSequence text,
11121110
int remaining = len - (right - left);
11131111
if (preserveLength) {
11141112
if (remaining > 0) { // else eliminate the ellipsis too
1115-
buf[left++] = '\u2026';
1113+
buf[left++] = ellipsis.charAt(0);
11161114
}
11171115
for (int i = left; i < right; i++) {
1118-
buf[i] = '\uFEFF';
1116+
buf[i] = ZWNBS_CHAR;
11191117
}
11201118
String s = new String(buf, 0, len);
11211119
if (sp == null) {
@@ -1131,16 +1129,16 @@ public static CharSequence ellipsize(CharSequence text,
11311129
}
11321130

11331131
if (sp == null) {
1134-
StringBuilder sb = new StringBuilder(remaining + sEllipsis.length());
1132+
StringBuilder sb = new StringBuilder(remaining + ellipsis.length());
11351133
sb.append(buf, 0, left);
1136-
sb.append(sEllipsis);
1134+
sb.append(ellipsis);
11371135
sb.append(buf, right, len - right);
11381136
return sb.toString();
11391137
}
11401138

11411139
SpannableStringBuilder ssb = new SpannableStringBuilder();
11421140
ssb.append(text, 0, left);
1143-
ssb.append(sEllipsis);
1141+
ssb.append(ellipsis);
11441142
ssb.append(text, right, len);
11451143
return ssb;
11461144
} finally {
@@ -1664,4 +1662,13 @@ public static <T> T[] removeEmptySpans(T[] spans, Spanned spanned, Class<T> klas
16641662

16651663
private static Object sLock = new Object();
16661664
private static char[] sTemp = null;
1665+
1666+
private static String[] EMPTY_STRING_ARRAY = new String[]{};
1667+
1668+
private static final char ZWNBS_CHAR = '\uFEFF';
1669+
1670+
private static final String ELLIPSIS_NORMAL = Resources.getSystem().getString(
1671+
R.string.ellipsis);
1672+
private static final String ELLIPSIS_TWO_DOTS = Resources.getSystem().getString(
1673+
R.string.ellipsis_two_dots);
16671674
}

core/java/android/widget/TextView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6141,7 +6141,7 @@ protected void makeNewLayout(int w, int hintWidth,
61416141
TruncateAt effectiveEllipsize = mEllipsize;
61426142
if (mEllipsize == TruncateAt.MARQUEE &&
61436143
mMarqueeFadeMode == MARQUEE_FADE_SWITCH_SHOW_ELLIPSIS) {
6144-
effectiveEllipsize = TruncateAt.END;
6144+
effectiveEllipsize = TruncateAt.END_SMALL;
61456145
}
61466146

61476147
if (mTextDir == null) {

core/res/res/values/strings.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,13 @@
4141
<string name="untitled">&lt;untitled&gt;</string>
4242

4343
<!-- Used to replace a range of characters in text that is too wide
44-
for the space allocated to it. -->
44+
for the space allocated to it (three dots). -->
4545
<string name="ellipsis">\u2026</string>
4646

47+
<!-- Used to replace a range of characters in text that is too wide
48+
for the space allocated to it (two dots). -->
49+
<string name="ellipsis_two_dots">\u2025</string>
50+
4751
<!-- How to display the lack of a phone number -->
4852
<string name="emptyPhoneNumber">(No phone number)</string>
4953

0 commit comments

Comments
 (0)