diff options
author | Gilles Debunne <debunne@google.com> | 2011-10-27 11:10:14 -0700 |
---|---|---|
committer | Gilles Debunne <debunne@google.com> | 2011-11-29 17:48:19 -0800 |
commit | 70b34a1e0525c8e13f431c2e6c9d37d1954de1b2 (patch) | |
tree | 110a0402227d4327d0ef966aa10137e10a499744 /core/java/android/text/method | |
parent | 9b518d9304eb4ad17591944926231b661a3dfce0 (diff) | |
download | frameworks_base-70b34a1e0525c8e13f431c2e6c9d37d1954de1b2.zip frameworks_base-70b34a1e0525c8e13f431c2e6c9d37d1954de1b2.tar.gz frameworks_base-70b34a1e0525c8e13f431c2e6c9d37d1954de1b2.tar.bz2 |
Scroll performance improved in multiline TextEdit
Measuring line widths, glyph by glyph slows down the scrolling
process for long text (for some reason, width measure efficiency
is affectedi by text length, maybe because the whole text has to
be passed to JNI layers).
This optimization avoids this computation in the case where there
is no possible horizontal scroll.
This is a cherry pick of 145957 into ICS-MR1
Change-Id: I2082e3d0eedace1a86122a03e4b21f90f3bc8522
Diffstat (limited to 'core/java/android/text/method')
-rw-r--r-- | core/java/android/text/method/Touch.java | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/core/java/android/text/method/Touch.java b/core/java/android/text/method/Touch.java index 106a801..3dfd44d 100644 --- a/core/java/android/text/method/Touch.java +++ b/core/java/android/text/method/Touch.java @@ -35,22 +35,30 @@ public class Touch { * Y position. */ public static void scrollTo(TextView widget, Layout layout, int x, int y) { - final int verticalPadding = widget.getTotalPaddingTop() + widget.getTotalPaddingBottom(); - final int top = layout.getLineForVertical(y); - final int bottom = layout.getLineForVertical(y + widget.getHeight() - verticalPadding); + final int horizontalPadding = widget.getTotalPaddingLeft() + widget.getTotalPaddingRight(); + final int availableWidth = widget.getWidth() - horizontalPadding; - int left = Integer.MAX_VALUE; - int right = 0; + final int top = layout.getLineForVertical(y); Alignment a = layout.getParagraphAlignment(top); boolean ltr = layout.getParagraphDirection(top) > 0; - for (int i = top; i <= bottom; i++) { - left = (int) Math.min(left, layout.getLineLeft(i)); - right = (int) Math.max(right, layout.getLineRight(i)); + int left, right; + if (widget.getHorizontallyScrolling()) { + final int verticalPadding = widget.getTotalPaddingTop() + widget.getTotalPaddingBottom(); + final int bottom = layout.getLineForVertical(y + widget.getHeight() - verticalPadding); + + left = Integer.MAX_VALUE; + right = 0; + + for (int i = top; i <= bottom; i++) { + left = (int) Math.min(left, layout.getLineLeft(i)); + right = (int) Math.max(right, layout.getLineRight(i)); + } + } else { + left = 0; + right = availableWidth; } - final int hoizontalPadding = widget.getTotalPaddingLeft() + widget.getTotalPaddingRight(); - final int availableWidth = widget.getWidth() - hoizontalPadding; final int actualWidth = right - left; if (actualWidth < availableWidth) { @@ -166,16 +174,24 @@ public class Touch { return false; } + /** + * @param widget The text view. + * @param buffer The text buffer. + */ public static int getInitialScrollX(TextView widget, Spannable buffer) { DragState[] ds = buffer.getSpans(0, buffer.length(), DragState.class); return ds.length > 0 ? ds[0].mScrollX : -1; } - + + /** + * @param widget The text view. + * @param buffer The text buffer. + */ public static int getInitialScrollY(TextView widget, Spannable buffer) { DragState[] ds = buffer.getSpans(0, buffer.length(), DragState.class); return ds.length > 0 ? ds[0].mScrollY : -1; } - + private static class DragState implements NoCopySpan { public float mX; public float mY; |