diff options
| author | 2015-11-24 18:48:28 +0900 | |
|---|---|---|
| committer | 2015-11-25 16:15:19 +0900 | |
| commit | c24c2bbb69634435d1d9fc97671229df245bd8d0 (patch) | |
| tree | 72d321f55b8c93d9ad760eed17d5b6b6da960fe4 | |
| parent | da79ee683d74f2ad7d29147a30f3da17dd0ea6e2 (diff) | |
Add selection handle multiline dragging tests.
Bug: 25730231
Change-Id: I23b9e35d7a5ea8d03d8634ffca0e186ea76ebc99
3 files changed, 42 insertions, 4 deletions
diff --git a/core/tests/coretests/src/android/widget/TextViewActivityTest.java b/core/tests/coretests/src/android/widget/TextViewActivityTest.java index b03552f9e908..2eb9cdb6a856 100644 --- a/core/tests/coretests/src/android/widget/TextViewActivityTest.java +++ b/core/tests/coretests/src/android/widget/TextViewActivityTest.java @@ -186,4 +186,29 @@ public class TextViewActivityTest extends ActivityInstrumentationTestCase2<TextV .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('k') + 1)); onView(withId(R.id.textview)).check(hasSelection("abcd efg hijk")); } + + @SmallTest + public void testSelectionHandles_multiLine() throws Exception { + final String text = "abcd\n" + "efg\n" + "hijk\n" + "lmn\n" + "opqr"; + onView(withId(R.id.textview)).perform(click()); + onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); + onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('i'))); + + final TextView textView = (TextView)getActivity().findViewById(R.id.textview); + onHandleView(com.android.internal.R.id.selection_start_handle) + .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('e'))); + onView(withId(R.id.textview)).check(hasSelection("efg\nhijk")); + + onHandleView(com.android.internal.R.id.selection_start_handle) + .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('a'))); + onView(withId(R.id.textview)).check(hasSelection("abcd\nefg\nhijk")); + + onHandleView(com.android.internal.R.id.selection_end_handle) + .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('n') + 1)); + onView(withId(R.id.textview)).check(hasSelection("abcd\nefg\nhijk\nlmn")); + + onHandleView(com.android.internal.R.id.selection_end_handle) + .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('r') + 1)); + onView(withId(R.id.textview)).check(hasSelection("abcd\nefg\nhijk\nlmn\nopqr")); + } } diff --git a/core/tests/coretests/src/android/widget/espresso/DragAction.java b/core/tests/coretests/src/android/widget/espresso/DragAction.java index 07a2067bf36b..c939217f89e9 100644 --- a/core/tests/coretests/src/android/widget/espresso/DragAction.java +++ b/core/tests/coretests/src/android/widget/espresso/DragAction.java @@ -252,9 +252,9 @@ public final class DragAction implements ViewAction { private static float[][] interpolate(float[] start, float[] end) { float[][] res = new float[DRAG_STEP_COUNT][2]; - for (int i = 1; i < DRAG_STEP_COUNT + 1; i++) { - res[i - 1][0] = start[0] + (end[0] - start[0]) * i / (DRAG_STEP_COUNT + 2f); - res[i - 1][1] = start[1] + (end[1] - start[1]) * i / (DRAG_STEP_COUNT + 2f); + for (int i = 0; i < DRAG_STEP_COUNT; i++) { + res[i][0] = start[0] + (end[0] - start[0]) * i / (DRAG_STEP_COUNT - 1f); + res[i][1] = start[1] + (end[1] - start[1]) * i / (DRAG_STEP_COUNT - 1f); } return res; diff --git a/core/tests/coretests/src/android/widget/espresso/TextViewActions.java b/core/tests/coretests/src/android/widget/espresso/TextViewActions.java index b84afff18d9b..32abc861587d 100644 --- a/core/tests/coretests/src/android/widget/espresso/TextViewActions.java +++ b/core/tests/coretests/src/android/widget/espresso/TextViewActions.java @@ -184,6 +184,8 @@ public final class TextViewActions { * text view. */ private static final class HandleCoordinates implements CoordinatesProvider { + // Must be larger than Editor#LINE_SLOP_MULTIPLIER_FOR_HANDLEVIEWS. + private final static float LINE_SLOP_MULTIPLIER = 0.6f; private final TextView mTextView; private final Handle mHandleType; private final int mIndex; @@ -213,6 +215,11 @@ public final class TextViewActions { private float[] locateHandlePointsTextIndex(View view) { final int currentOffset = mHandleType == Handle.SELECTION_START ? mTextView.getSelectionStart() : mTextView.getSelectionEnd(); + + final Layout layout = mTextView.getLayout(); + final int currentLine = layout.getLineForOffset(currentOffset); + final int targetLine = layout.getLineForOffset(mIndex); + final float[] currentCoordinates = (new TextCoordinates(currentOffset)).calculateCoordinates(mTextView); final float[] targetCoordinates = @@ -220,7 +227,13 @@ public final class TextViewActions { final Rect bounds = new Rect(); view.getBoundsOnScreen(bounds); final float diffX = bounds.centerX() - currentCoordinates[0]; - final float diffY = bounds.centerY() - currentCoordinates[1]; + final float verticalOffset = bounds.height() * 0.7f; + float diffY = bounds.top + verticalOffset - currentCoordinates[1]; + if (currentLine > targetLine) { + diffY -= mTextView.getLineHeight() * LINE_SLOP_MULTIPLIER; + } else if (currentLine < targetLine) { + diffY += mTextView.getLineHeight() * LINE_SLOP_MULTIPLIER; + } return new float[] {targetCoordinates[0] + diffX, targetCoordinates[1] + diffY}; } } |