Skip to content

Commit 58d8953

Browse files
Gilles DebunneAndroid (Google) Code Review
authored andcommitted
Merge "Scroll performance improved in multiline TextEdit" into ics-mr1
2 parents eb189d3 + 70b34a1 commit 58d8953

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

core/java/android/text/method/Touch.java

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,30 @@ private Touch() { }
3535
* Y position.
3636
*/
3737
public static void scrollTo(TextView widget, Layout layout, int x, int y) {
38-
final int verticalPadding = widget.getTotalPaddingTop() + widget.getTotalPaddingBottom();
39-
final int top = layout.getLineForVertical(y);
40-
final int bottom = layout.getLineForVertical(y + widget.getHeight() - verticalPadding);
38+
final int horizontalPadding = widget.getTotalPaddingLeft() + widget.getTotalPaddingRight();
39+
final int availableWidth = widget.getWidth() - horizontalPadding;
4140

42-
int left = Integer.MAX_VALUE;
43-
int right = 0;
41+
final int top = layout.getLineForVertical(y);
4442
Alignment a = layout.getParagraphAlignment(top);
4543
boolean ltr = layout.getParagraphDirection(top) > 0;
4644

47-
for (int i = top; i <= bottom; i++) {
48-
left = (int) Math.min(left, layout.getLineLeft(i));
49-
right = (int) Math.max(right, layout.getLineRight(i));
45+
int left, right;
46+
if (widget.getHorizontallyScrolling()) {
47+
final int verticalPadding = widget.getTotalPaddingTop() + widget.getTotalPaddingBottom();
48+
final int bottom = layout.getLineForVertical(y + widget.getHeight() - verticalPadding);
49+
50+
left = Integer.MAX_VALUE;
51+
right = 0;
52+
53+
for (int i = top; i <= bottom; i++) {
54+
left = (int) Math.min(left, layout.getLineLeft(i));
55+
right = (int) Math.max(right, layout.getLineRight(i));
56+
}
57+
} else {
58+
left = 0;
59+
right = availableWidth;
5060
}
5161

52-
final int hoizontalPadding = widget.getTotalPaddingLeft() + widget.getTotalPaddingRight();
53-
final int availableWidth = widget.getWidth() - hoizontalPadding;
5462
final int actualWidth = right - left;
5563

5664
if (actualWidth < availableWidth) {
@@ -166,16 +174,24 @@ public static boolean onTouchEvent(TextView widget, Spannable buffer,
166174
return false;
167175
}
168176

177+
/**
178+
* @param widget The text view.
179+
* @param buffer The text buffer.
180+
*/
169181
public static int getInitialScrollX(TextView widget, Spannable buffer) {
170182
DragState[] ds = buffer.getSpans(0, buffer.length(), DragState.class);
171183
return ds.length > 0 ? ds[0].mScrollX : -1;
172184
}
173-
185+
186+
/**
187+
* @param widget The text view.
188+
* @param buffer The text buffer.
189+
*/
174190
public static int getInitialScrollY(TextView widget, Spannable buffer) {
175191
DragState[] ds = buffer.getSpans(0, buffer.length(), DragState.class);
176192
return ds.length > 0 ? ds[0].mScrollY : -1;
177193
}
178-
194+
179195
private static class DragState implements NoCopySpan {
180196
public float mX;
181197
public float mY;

core/java/android/widget/TextView.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2580,6 +2580,17 @@ public void setHorizontallyScrolling(boolean whether) {
25802580
}
25812581
}
25822582

2583+
/**
2584+
* Returns whether the text is allowed to be wider than the View is.
2585+
* If false, the text will be wrapped to the width of the View.
2586+
*
2587+
* @attr ref android.R.styleable#TextView_scrollHorizontally
2588+
* @hide
2589+
*/
2590+
public boolean getHorizontallyScrolling() {
2591+
return mHorizontallyScrolling;
2592+
}
2593+
25832594
/**
25842595
* Makes the TextView at least this many lines tall.
25852596
*

0 commit comments

Comments
 (0)