Loading core/java/android/text/TextUtils.java +22 −5 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.annotation.PluralsRes; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; import android.content.res.Resources; import android.graphics.Typeface; import android.icu.lang.UCharacter; import android.icu.text.CaseMap; import android.icu.text.Edits; Loading Loading @@ -2481,15 +2482,31 @@ public class TextUtils { if (ellipsizeDip == 0) { return gettingCleaned.toString(); } else { final float assumedFontSizePx = 42; if (Typeface.getSystemFontMap().isEmpty()) { // In the system server, the font files may not be loaded, so unable to perform // ellipsize, so use the estimated char count for the ellipsize. // The median of glyph widths of the Roboto is 0.57em, so use it as a reference // of the glyph width. final float assumedCharWidthInEm = 0.57f; final float assumedCharWidthInPx = assumedFontSizePx * assumedCharWidthInEm; // Even if the argument name is `ellipsizeDip`, the unit of this argument is pixels. final int charCount = (int) ((ellipsizeDip + 0.5f) / assumedCharWidthInPx); return TextUtils.trimToSize(gettingCleaned.toString(), charCount) + getEllipsisString(TruncateAt.END); } else { // Truncate final TextPaint paint = new TextPaint(); paint.setTextSize(42); paint.setTextSize(assumedFontSizePx); return TextUtils.ellipsize(gettingCleaned.toString(), paint, ellipsizeDip, TextUtils.TruncateAt.END); } } } /** * A special string manipulation class. Just records removals and executes the when onString() Loading Loading
core/java/android/text/TextUtils.java +22 −5 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.annotation.PluralsRes; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; import android.content.res.Resources; import android.graphics.Typeface; import android.icu.lang.UCharacter; import android.icu.text.CaseMap; import android.icu.text.Edits; Loading Loading @@ -2481,15 +2482,31 @@ public class TextUtils { if (ellipsizeDip == 0) { return gettingCleaned.toString(); } else { final float assumedFontSizePx = 42; if (Typeface.getSystemFontMap().isEmpty()) { // In the system server, the font files may not be loaded, so unable to perform // ellipsize, so use the estimated char count for the ellipsize. // The median of glyph widths of the Roboto is 0.57em, so use it as a reference // of the glyph width. final float assumedCharWidthInEm = 0.57f; final float assumedCharWidthInPx = assumedFontSizePx * assumedCharWidthInEm; // Even if the argument name is `ellipsizeDip`, the unit of this argument is pixels. final int charCount = (int) ((ellipsizeDip + 0.5f) / assumedCharWidthInPx); return TextUtils.trimToSize(gettingCleaned.toString(), charCount) + getEllipsisString(TruncateAt.END); } else { // Truncate final TextPaint paint = new TextPaint(); paint.setTextSize(42); paint.setTextSize(assumedFontSizePx); return TextUtils.ellipsize(gettingCleaned.toString(), paint, ellipsizeDip, TextUtils.TruncateAt.END); } } } /** * A special string manipulation class. Just records removals and executes the when onString() Loading