5353import java .util .regex .Pattern ;
5454
5555public 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}
0 commit comments