diff options
| author | Gilles Debunne <debunne@google.com> | 2011-02-01 10:09:29 -0800 |
|---|---|---|
| committer | Android Git Automerger <android-git-automerger@android.com> | 2011-02-01 10:09:29 -0800 |
| commit | 15f16e3f860b28ef0767b08ae8d86dc08b6aac3b (patch) | |
| tree | 7fc63c8967b4020b532ba1e08f7a4297b650d3dd /core/java | |
| parent | 87793907c4c6cf6c0e96628c1b2d2555a5290af9 (diff) | |
| parent | 6538329258ee01b27586d8b0e46e96160d719a68 (diff) | |
| download | frameworks_base-15f16e3f860b28ef0767b08ae8d86dc08b6aac3b.zip frameworks_base-15f16e3f860b28ef0767b08ae8d86dc08b6aac3b.tar.gz frameworks_base-15f16e3f860b28ef0767b08ae8d86dc08b6aac3b.tar.bz2 | |
am 65383292: am 8f8aac5e: Merge "Pixel were missing on the last line of text when using MaxLines." into honeycomb
* commit '6538329258ee01b27586d8b0e46e96160d719a68':
Pixel were missing on the last line of text when using MaxLines.
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/text/DynamicLayout.java | 22 | ||||
| -rw-r--r-- | core/java/android/text/Layout.java | 11 | ||||
| -rw-r--r-- | core/java/android/text/StaticLayout.java | 60 | ||||
| -rw-r--r-- | core/java/android/widget/TextView.java | 7 |
4 files changed, 61 insertions, 39 deletions
diff --git a/core/java/android/text/DynamicLayout.java b/core/java/android/text/DynamicLayout.java index 403f20e..f196b34 100644 --- a/core/java/android/text/DynamicLayout.java +++ b/core/java/android/text/DynamicLayout.java @@ -92,7 +92,7 @@ extends Layout } else { mInts = new PackedIntVector(COLUMNS_NORMAL); mEllipsizedWidth = width; - mEllipsizeAt = ellipsize; + mEllipsizeAt = null; } mObjects = new PackedObjectVector<Directions>(1); @@ -259,10 +259,9 @@ extends Layout reflowed = new StaticLayout(true); reflowed.generate(text, where, where + after, - getPaint(), getWidth(), getAlignment(), - getSpacingMultiplier(), getSpacingAdd(), - false, true, mEllipsize, - mEllipsizedWidth, mEllipsizeAt); + getPaint(), getWidth(), getAlignment(), + getSpacingMultiplier(), getSpacingAdd(), + 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); diff --git a/core/java/android/text/Layout.java b/core/java/android/text/Layout.java index 3fe4f4c..8700af8 100644 --- a/core/java/android/text/Layout.java +++ b/core/java/android/text/Layout.java @@ -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) {} } diff --git a/core/java/android/text/StaticLayout.java b/core/java/android/text/StaticLayout.java index 43dce53..ac3df79 100644 --- a/core/java/android/text/StaticLayout.java +++ b/core/java/android/text/StaticLayout.java @@ -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,13 +737,13 @@ 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)) { - calculateEllipsis(start, end, widths, widstart, - ellipsiswidth, ellipsize, j, - textwidth, paint); - } + // If ellipsize is in marquee mode, do not apply ellipsis on the first line + if (ellipsize != null && (ellipsize != TextUtils.TruncateAt.MARQUEE || j != 0)) { + calculateEllipsis(start, end, widths, widstart, + ellipsiswidth, ellipsize, j, + textwidth, paint); } mLineCount++; @@ -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; diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 8cb725a..772eefd 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -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 } } |
