Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a601ea29 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Stop ellipsize in system server" into main

parents 7b363c99 9a43e6cb
Loading
Loading
Loading
Loading
+22 −5
Original line number Diff line number Diff line
@@ -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;
@@ -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()