Loading core/java/android/text/DynamicLayout.java +8 −14 Original line number Diff line number Diff line Loading @@ -92,7 +92,7 @@ extends Layout } else { mInts = new PackedIntVector(COLUMNS_NORMAL); mEllipsizedWidth = width; mEllipsizeAt = ellipsize; mEllipsizeAt = null; } mObjects = new PackedObjectVector<Directions>(1); Loading Loading @@ -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 Loading Loading @@ -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); } Loading @@ -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); } Loading @@ -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); Loading core/java/android/text/Layout.java +11 −0 Original line number Diff line number Diff line Loading @@ -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) {} } core/java/android/text/StaticLayout.java +39 −21 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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); Loading @@ -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; Loading Loading @@ -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; Loading @@ -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; Loading @@ -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; Loading Loading @@ -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; Loading @@ -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); } } Loading Loading @@ -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)) { Loading @@ -745,7 +745,6 @@ public class StaticLayout extends Layout ellipsiswidth, ellipsize, j, textwidth, paint); } } mLineCount++; return v; Loading @@ -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! Loading @@ -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; Loading Loading @@ -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 Loading Loading @@ -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; Loading @@ -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; Loading core/java/android/widget/TextView.java +3 −4 Original line number Diff line number Diff line Loading @@ -5861,6 +5861,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } desired += pad; layout.setMaximumVisibleLineCount(0); if (mMaxMode == LINES) { /* Loading @@ -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); Loading Loading @@ -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); Loading @@ -6447,7 +6447,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (applyTransformation) { setTransformationMethod(null); } // TODO setState } } Loading Loading
core/java/android/text/DynamicLayout.java +8 −14 Original line number Diff line number Diff line Loading @@ -92,7 +92,7 @@ extends Layout } else { mInts = new PackedIntVector(COLUMNS_NORMAL); mEllipsizedWidth = width; mEllipsizeAt = ellipsize; mEllipsizeAt = null; } mObjects = new PackedObjectVector<Directions>(1); Loading Loading @@ -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 Loading Loading @@ -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); } Loading @@ -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); } Loading @@ -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); Loading
core/java/android/text/Layout.java +11 −0 Original line number Diff line number Diff line Loading @@ -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) {} }
core/java/android/text/StaticLayout.java +39 −21 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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); Loading @@ -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; Loading Loading @@ -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; Loading @@ -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; Loading @@ -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; Loading Loading @@ -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; Loading @@ -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); } } Loading Loading @@ -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)) { Loading @@ -745,7 +745,6 @@ public class StaticLayout extends Layout ellipsiswidth, ellipsize, j, textwidth, paint); } } mLineCount++; return v; Loading @@ -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! Loading @@ -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; Loading Loading @@ -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 Loading Loading @@ -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; Loading @@ -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; Loading
core/java/android/widget/TextView.java +3 −4 Original line number Diff line number Diff line Loading @@ -5861,6 +5861,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } desired += pad; layout.setMaximumVisibleLineCount(0); if (mMaxMode == LINES) { /* Loading @@ -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); Loading Loading @@ -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); Loading @@ -6447,7 +6447,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (applyTransformation) { setTransformationMethod(null); } // TODO setState } } Loading