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

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

Merge "Pixel were missing on the last line of text when using MaxLines." into honeycomb

parents 2a7ade6d 0a4db3c5
Loading
Loading
Loading
Loading
+8 −14
Original line number Diff line number Diff line
@@ -92,7 +92,7 @@ extends Layout
        } else {
            mInts = new PackedIntVector(COLUMNS_NORMAL);
            mEllipsizedWidth = width;
            mEllipsizeAt = ellipsize;
            mEllipsizeAt = null;
        }

        mObjects = new PackedObjectVector<Directions>(1);
@@ -261,8 +261,7 @@ extends Layout
        reflowed.generate(text, where, where + after,
                getPaint(), getWidth(), getAlignment(),
                getSpacingMultiplier(), getSpacingAdd(),
                                      false, true, mEllipsize,
                                      mEllipsizedWidth, mEllipsizeAt);
                false, true, mEllipsizedWidth, mEllipsizeAt);
        int n = reflowed.getLineCount();

        // If the new layout has a blank line at the end, but it is not
@@ -391,9 +390,7 @@ extends Layout
        return mEllipsizedWidth;
    }

    private static class ChangeWatcher
    implements TextWatcher, SpanWatcher
    {
    private static class ChangeWatcher implements TextWatcher, SpanWatcher {
        public ChangeWatcher(DynamicLayout layout) {
            mLayout = new WeakReference<DynamicLayout>(layout);
        }
@@ -407,12 +404,10 @@ extends Layout
                ((Spannable) s).removeSpan(this);
        }

        public void beforeTextChanged(CharSequence s,
                                      int where, int before, int after) {
        public void beforeTextChanged(CharSequence s, int where, int before, int after) {
        }

        public void onTextChanged(CharSequence s,
                                  int where, int before, int after) {
        public void onTextChanged(CharSequence s, int where, int before, int after) {
            reflow(s, where, before, after);
        }

@@ -429,8 +424,7 @@ extends Layout
                reflow(s, start, end - start, end - start);
        }

        public void onSpanChanged(Spannable s, Object o, int start, int end,
                                  int nstart, int nend) {
        public void onSpanChanged(Spannable s, Object o, int start, int end, int nstart, int nend) {
            if (o instanceof UpdateLayout) {
                reflow(s, start, end - start, end - start);
                reflow(s, nstart, nend - nstart, nend - nstart);
+11 −0
Original line number Diff line number Diff line
@@ -1764,4 +1764,15 @@ public abstract class Layout {
        new Directions(new int[] { 0, RUN_LENGTH_MASK });
    /* package */ static final Directions DIRS_ALL_RIGHT_TO_LEFT =
        new Directions(new int[] { 0, RUN_LENGTH_MASK | RUN_RTL_FLAG });

    /**
     * Inform this layout that not all of its lines will be displayed, because a maximum number of
     * lines has been set on the associated TextView.
     *
     * A non positive value means that all lines are displayed.
     *
     * @param line line number of the last visible line (line numbers start at 1 for the first line)
     * @hide
     */
    public void setMaximumVisibleLineCount(int line) {}
}
+39 −21
Original line number Diff line number Diff line
@@ -98,7 +98,7 @@ public class StaticLayout extends Layout

        generate(source, bufstart, bufend, paint, outerwidth, align,
                 spacingmult, spacingadd, includepad, includepad,
                 ellipsize != null, ellipsizedWidth, ellipsize);
                 ellipsizedWidth, ellipsize);

        mMeasured = MeasuredText.recycle(mMeasured);
        mFontMetricsInt = null;
@@ -119,8 +119,7 @@ public class StaticLayout extends Layout
                        Alignment align,
                        float spacingmult, float spacingadd,
                        boolean includepad, boolean trackpad,
                        boolean breakOnlyAtSpaces,
                        float ellipsizedWidth, TextUtils.TruncateAt where) {
                        float ellipsizedWidth, TextUtils.TruncateAt ellipsize) {
        mLineCount = 0;

        int v = 0;
@@ -281,8 +280,7 @@ public class StaticLayout extends Layout
                        int emoji = Character.codePointAt(chs, j - paraStart);

                        if (emoji >= MIN_EMOJI && emoji <= MAX_EMOJI) {
                            Bitmap bm = EMOJI_FACTORY.
                                getBitmapFromAndroidPua(emoji);
                            Bitmap bm = EMOJI_FACTORY.getBitmapFromAndroidPua(emoji);

                            if (bm != null) {
                                Paint whichPaint;
@@ -362,7 +360,8 @@ public class StaticLayout extends Layout
                                okbottom = fitbottom;
                        }
                    } else {
                        if (breakOnlyAtSpaces) {
                        if (ellipsize != null) {
                            // Break only at spaces using ok indexes.
                            if (ok != here) {
                                // Log.e("text", "output ok " + here + " to " +ok);

@@ -379,7 +378,7 @@ public class StaticLayout extends Layout
                                        needMultiply, paraStart, chdirs, dir, easy,
                                        ok == bufend, includepad, trackpad,
                                        chs, widths, here - paraStart,
                                        where, ellipsizedWidth, okwidth,
                                        ellipsize, ellipsizedWidth, okwidth,
                                        paint);

                                here = ok;
@@ -415,7 +414,7 @@ public class StaticLayout extends Layout
                                        needMultiply, paraStart, chdirs, dir, easy,
                                        ok == bufend, includepad, trackpad,
                                        chs, widths, here - paraStart,
                                        where, ellipsizedWidth, okwidth,
                                        ellipsize, ellipsizedWidth, okwidth,
                                        paint);

                                here = ok;
@@ -431,7 +430,7 @@ public class StaticLayout extends Layout
                                        needMultiply, paraStart, chdirs, dir, easy,
                                        fit == bufend, includepad, trackpad,
                                        chs, widths, here - paraStart,
                                        where, ellipsizedWidth, fitwidth,
                                        ellipsize, ellipsizedWidth, fitwidth,
                                        paint);

                                here = fit;
@@ -453,7 +452,7 @@ public class StaticLayout extends Layout
                                        here + 1 == bufend, includepad,
                                        trackpad,
                                        chs, widths, here - paraStart,
                                        where, ellipsizedWidth,
                                        ellipsize, ellipsizedWidth,
                                        widths[here - paraStart], paint);

                                here = here + 1;
@@ -502,7 +501,7 @@ public class StaticLayout extends Layout
                        needMultiply, paraStart, chdirs, dir, easy,
                        paraEnd == bufend, includepad, trackpad,
                        chs, widths, here - paraStart,
                        where, ellipsizedWidth, w, paint);
                        ellipsize, ellipsizedWidth, w, paint);
            }

            paraStart = paraEnd;
@@ -525,7 +524,7 @@ public class StaticLayout extends Layout
                    needMultiply, bufend, null, DEFAULT_DIR, true,
                    true, includepad, trackpad,
                    null, null, bufstart,
                    where, ellipsizedWidth, 0, paint);
                    ellipsize, ellipsizedWidth, 0, paint);
        }
    }

@@ -738,6 +737,7 @@ public class StaticLayout extends Layout
        } else {
            mLineDirections[j] = AndroidBidi.directions(dir, chdirs, widstart, chs,
                    widstart, end - start);
        }

        // If ellipsize is in marquee mode, do not apply ellipsis on the first line
        if (ellipsize != null && (ellipsize != TextUtils.TruncateAt.MARQUEE || j != 0)) {
@@ -745,7 +745,6 @@ public class StaticLayout extends Layout
                    ellipsiswidth, ellipsize, j,
                    textwidth, paint);
        }
        }

        mLineCount++;
        return v;
@@ -755,7 +754,6 @@ public class StaticLayout extends Layout
                                   float[] widths, int widstart,
                                   float avail, TextUtils.TruncateAt where,
                                   int line, float textwidth, TextPaint paint) {
        int len = lineend - linestart;

        if (textwidth <= avail) {
            // Everything fits!
@@ -766,6 +764,7 @@ public class StaticLayout extends Layout

        float ellipsiswid = paint.measureText("\u2026");
        int ellipsisStart, ellipsisCount;
        int len = lineend - linestart;

        if (where == TextUtils.TruncateAt.START) {
            float sum = 0;
@@ -865,12 +864,22 @@ public class StaticLayout extends Layout

    @Override
    public int getLineTop(int line) {
        return mLines[mColumns * line + TOP];
        int top = mLines[mColumns * line + TOP];
        if (mMaximumVisibleLineCount > 0 && line >= mMaximumVisibleLineCount &&
                line != mLineCount) {
            top += getBottomPadding();
        }
        return top;
    }

    @Override
    public int getLineDescent(int line) {
        return mLines[mColumns * line + DESCENT];
        int descent = mLines[mColumns * line + DESCENT];
        if (mMaximumVisibleLineCount > 0 && line >= mMaximumVisibleLineCount - 1 &&
                line != mLineCount) {
            descent += getBottomPadding();
        }
        return descent;
    }

    @Override
@@ -926,6 +935,14 @@ public class StaticLayout extends Layout
        return mEllipsizedWidth;
    }

    /**
     * @hide
     */
    @Override
    public void setMaximumVisibleLineCount(int line) {
        mMaximumVisibleLineCount = line;
    }

    private int mLineCount;
    private int mTopPadding, mBottomPadding;
    private int mColumns;
@@ -943,6 +960,7 @@ public class StaticLayout extends Layout

    private int[] mLines;
    private Directions[] mLineDirections;
    private int mMaximumVisibleLineCount = 0;

    private static final int START_MASK = 0x1FFFFFFF;
    private static final int DIR_SHIFT  = 30;
+3 −4
Original line number Diff line number Diff line
@@ -5861,6 +5861,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        }

        desired += pad;
        layout.setMaximumVisibleLineCount(0);

        if (mMaxMode == LINES) {
            /*
@@ -5869,8 +5870,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
             */
            if (cap) {
                if (linecount > mMaximum) {
                    desired = layout.getLineTop(mMaximum) +
                              layout.getBottomPadding();
                    layout.setMaximumVisibleLineCount(mMaximum);
                    desired = layout.getLineTop(mMaximum);

                    if (dr != null) {
                        desired = Math.max(desired, dr.mDrawableHeightLeft);
@@ -6438,7 +6439,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            if (applyTransformation) {
                setTransformationMethod(SingleLineTransformationMethod.getInstance());
            }
            // TODO setState
        } else {
            if (changeMaxLines) {
                setMaxLines(Integer.MAX_VALUE);
@@ -6447,7 +6447,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            if (applyTransformation) {
                setTransformationMethod(null);
            }
            // TODO setState
        }
    }