Merge "Fix bug #5366547 TruncateAt.MARQUEE should be replaces with "two dot" ellipsis on hardware that dont support MARQUEE"

This commit is contained in:
Fabrice Di Meglio
2011-09-26 12:16:41 -07:00
committed by Android (Google) Code Review
4 changed files with 37 additions and 22 deletions

View File

@@ -763,7 +763,8 @@ public class StaticLayout extends Layout {
return; return;
} }
float ellipsisWidth = paint.measureText(HORIZONTAL_ELLIPSIS); float ellipsisWidth = paint.measureText(
(where == TextUtils.TruncateAt.END_SMALL) ? ELLIPSIS_TWO_DOTS : ELLIPSIS_NORMAL);
int ellipsisStart = 0; int ellipsisStart = 0;
int ellipsisCount = 0; int ellipsisCount = 0;
int len = lineEnd - lineStart; int len = lineEnd - lineStart;
@@ -791,7 +792,8 @@ public class StaticLayout extends Layout {
Log.w(TAG, "Start Ellipsis only supported with one line"); Log.w(TAG, "Start Ellipsis only supported with one line");
} }
} }
} else if (where == TextUtils.TruncateAt.END || where == TextUtils.TruncateAt.MARQUEE) { } else if (where == TextUtils.TruncateAt.END || where == TextUtils.TruncateAt.MARQUEE ||
where == TextUtils.TruncateAt.END_SMALL) {
float sum = 0; float sum = 0;
int i; int i;
@@ -1001,7 +1003,9 @@ public class StaticLayout extends Layout {
private static final char CHAR_HYPHEN = '-'; private static final char CHAR_HYPHEN = '-';
private static final double EXTRA_ROUNDING = 0.5; private static final double EXTRA_ROUNDING = 0.5;
private static final String HORIZONTAL_ELLIPSIS = "\u2026"; // this is "..."
private static final String ELLIPSIS_NORMAL = "\u2026"; // this is "..."
private static final String ELLIPSIS_TWO_DOTS = "\u2025"; // this is ".."
private static final int CHAR_FIRST_HIGH_SURROGATE = 0xD800; private static final int CHAR_FIRST_HIGH_SURROGATE = 0xD800;
private static final int CHAR_LAST_LOW_SURROGATE = 0xDFFF; private static final int CHAR_LAST_LOW_SURROGATE = 0xDFFF;

View File

@@ -53,9 +53,8 @@ import java.util.Iterator;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class TextUtils { public class TextUtils {
private TextUtils() { /* cannot be instantiated */ }
private static String[] EMPTY_STRING_ARRAY = new String[]{}; private TextUtils() { /* cannot be instantiated */ }
public static void getChars(CharSequence s, int start, int end, public static void getChars(CharSequence s, int start, int end,
char[] dest, int destoff) { char[] dest, int destoff) {
@@ -1000,6 +999,10 @@ public class TextUtils {
MIDDLE, MIDDLE,
END, END,
MARQUEE, MARQUEE,
/**
* @hide
*/
END_SMALL
} }
public interface EllipsizeCallback { public interface EllipsizeCallback {
@@ -1010,8 +1013,6 @@ public class TextUtils {
public void ellipsized(int start, int end); public void ellipsized(int start, int end);
} }
private static String sEllipsis = null;
/** /**
* Returns the original text if it fits in the specified width * Returns the original text if it fits in the specified width
* given the properties of the specified Paint, * given the properties of the specified Paint,
@@ -1042,7 +1043,8 @@ public class TextUtils {
boolean preserveLength, boolean preserveLength,
EllipsizeCallback callback) { EllipsizeCallback callback) {
return ellipsize(text, paint, avail, where, preserveLength, callback, return ellipsize(text, paint, avail, where, preserveLength, callback,
TextDirectionHeuristics.FIRSTSTRONG_LTR); TextDirectionHeuristics.FIRSTSTRONG_LTR,
(where == TruncateAt.END_SMALL) ? ELLIPSIS_TWO_DOTS : ELLIPSIS_NORMAL);
} }
/** /**
@@ -1063,11 +1065,7 @@ public class TextUtils {
float avail, TruncateAt where, float avail, TruncateAt where,
boolean preserveLength, boolean preserveLength,
EllipsizeCallback callback, EllipsizeCallback callback,
TextDirectionHeuristic textDir) { TextDirectionHeuristic textDir, String ellipsis) {
if (sEllipsis == null) {
Resources r = Resources.getSystem();
sEllipsis = r.getString(R.string.ellipsis);
}
int len = text.length(); int len = text.length();
@@ -1085,7 +1083,7 @@ public class TextUtils {
// XXX assumes ellipsis string does not require shaping and // XXX assumes ellipsis string does not require shaping and
// is unaffected by style // is unaffected by style
float ellipsiswid = paint.measureText(sEllipsis); float ellipsiswid = paint.measureText(ellipsis);
avail -= ellipsiswid; avail -= ellipsiswid;
int left = 0; int left = 0;
@@ -1094,7 +1092,7 @@ public class TextUtils {
// it all goes // it all goes
} else if (where == TruncateAt.START) { } else if (where == TruncateAt.START) {
right = len - mt.breakText(0, len, false, avail); right = len - mt.breakText(0, len, false, avail);
} else if (where == TruncateAt.END) { } else if (where == TruncateAt.END || where == TruncateAt.END_SMALL) {
left = mt.breakText(0, len, true, avail); left = mt.breakText(0, len, true, avail);
} else { } else {
right = len - mt.breakText(0, len, false, avail / 2); right = len - mt.breakText(0, len, false, avail / 2);
@@ -1112,10 +1110,10 @@ public class TextUtils {
int remaining = len - (right - left); int remaining = len - (right - left);
if (preserveLength) { if (preserveLength) {
if (remaining > 0) { // else eliminate the ellipsis too if (remaining > 0) { // else eliminate the ellipsis too
buf[left++] = '\u2026'; buf[left++] = ellipsis.charAt(0);
} }
for (int i = left; i < right; i++) { for (int i = left; i < right; i++) {
buf[i] = '\uFEFF'; buf[i] = ZWNBS_CHAR;
} }
String s = new String(buf, 0, len); String s = new String(buf, 0, len);
if (sp == null) { if (sp == null) {
@@ -1131,16 +1129,16 @@ public class TextUtils {
} }
if (sp == null) { if (sp == null) {
StringBuilder sb = new StringBuilder(remaining + sEllipsis.length()); StringBuilder sb = new StringBuilder(remaining + ellipsis.length());
sb.append(buf, 0, left); sb.append(buf, 0, left);
sb.append(sEllipsis); sb.append(ellipsis);
sb.append(buf, right, len - right); sb.append(buf, right, len - right);
return sb.toString(); return sb.toString();
} }
SpannableStringBuilder ssb = new SpannableStringBuilder(); SpannableStringBuilder ssb = new SpannableStringBuilder();
ssb.append(text, 0, left); ssb.append(text, 0, left);
ssb.append(sEllipsis); ssb.append(ellipsis);
ssb.append(text, right, len); ssb.append(text, right, len);
return ssb; return ssb;
} finally { } finally {
@@ -1664,4 +1662,13 @@ public class TextUtils {
private static Object sLock = new Object(); private static Object sLock = new Object();
private static char[] sTemp = null; private static char[] sTemp = null;
private static String[] EMPTY_STRING_ARRAY = new String[]{};
private static final char ZWNBS_CHAR = '\uFEFF';
private static final String ELLIPSIS_NORMAL = Resources.getSystem().getString(
R.string.ellipsis);
private static final String ELLIPSIS_TWO_DOTS = Resources.getSystem().getString(
R.string.ellipsis_two_dots);
} }

View File

@@ -6141,7 +6141,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
TruncateAt effectiveEllipsize = mEllipsize; TruncateAt effectiveEllipsize = mEllipsize;
if (mEllipsize == TruncateAt.MARQUEE && if (mEllipsize == TruncateAt.MARQUEE &&
mMarqueeFadeMode == MARQUEE_FADE_SWITCH_SHOW_ELLIPSIS) { mMarqueeFadeMode == MARQUEE_FADE_SWITCH_SHOW_ELLIPSIS) {
effectiveEllipsize = TruncateAt.END; effectiveEllipsize = TruncateAt.END_SMALL;
} }
if (mTextDir == null) { if (mTextDir == null) {

View File

@@ -41,9 +41,13 @@
<string name="untitled">&lt;untitled&gt;</string> <string name="untitled">&lt;untitled&gt;</string>
<!-- Used to replace a range of characters in text that is too wide <!-- Used to replace a range of characters in text that is too wide
for the space allocated to it. --> for the space allocated to it (three dots). -->
<string name="ellipsis">\u2026</string> <string name="ellipsis">\u2026</string>
<!-- Used to replace a range of characters in text that is too wide
for the space allocated to it (two dots). -->
<string name="ellipsis_two_dots">\u2025</string>
<!-- How to display the lack of a phone number --> <!-- How to display the lack of a phone number -->
<string name="emptyPhoneNumber">(No phone number)</string> <string name="emptyPhoneNumber">(No phone number)</string>