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

Commit 957c800a authored by Gilles Debunne's avatar Gilles Debunne Committed by Android (Google) Code Review
Browse files

Merge "Ellipsize avoids spaces and starts right after text"

parents dbaf2cc1 c70e7a0b
Loading
Loading
Loading
Loading
+15 −11
Original line number Diff line number Diff line
@@ -222,23 +222,27 @@ class MeasuredText {
        return wid;
    }

    int breakText(int start, int limit, boolean forwards, float width) {
    int breakText(int limit, boolean forwards, float width) {
        float[] w = mWidths;
        if (forwards) {
            for (int i = start; i < limit; ++i) {
                if ((width -= w[i]) < 0) {
                    return i - start;
                }
            }
            int i = 0;
            while (i < limit) {
                width -= w[i];
                if (width < 0.0f) break;
                i++;
            }
            while (i > 0 && mChars[i - 1] == ' ') i--;
            return i;
        } else {
            for (int i = limit; --i >= start;) {
                if ((width -= w[i]) < 0) {
                    return limit - i -1;
                }
            int i = limit - 1;
            while (i >= 0) {
                width -= w[i];
                if (width < 0.0f) break;
                i--;
            }
            while (i < limit - 1 && mChars[i + 1] == ' ') i++;
            return limit - i - 1;
        }

        return limit - start;
    }

    float measure(int start, int limit) {
+4 −4
Original line number Diff line number Diff line
@@ -1091,13 +1091,13 @@ public class TextUtils {
            if (avail < 0) {
                // it all goes
            } else if (where == TruncateAt.START) {
                right = len - mt.breakText(0, len, false, avail);
                right = len - mt.breakText(len, false, avail);
            } else if (where == TruncateAt.END || where == TruncateAt.END_SMALL) {
                left = mt.breakText(0, len, true, avail);
                left = mt.breakText(len, true, avail);
            } else {
                right = len - mt.breakText(0, len, false, avail / 2);
                right = len - mt.breakText(len, false, avail / 2);
                avail -= mt.measure(right, len);
                left = mt.breakText(0, right, true, avail);
                left = mt.breakText(right, true, avail);
            }

            if (callback != null) {