diff options
author | Seigo Nonaka <nona@google.com> | 2015-06-25 19:02:17 +0900 |
---|---|---|
committer | Seigo Nonaka <nona@google.com> | 2015-06-26 01:40:49 +0900 |
commit | 86d60cde91eb4216580fe9d1250dc27c17e86c70 (patch) | |
tree | 976db252b6b9031d108ca8c2252acfaae7ef8d71 | |
parent | d4d802be39c67bf207bbb693d32c6a59c78ed3bb (diff) | |
download | frameworks_base-86d60cde91eb4216580fe9d1250dc27c17e86c70.zip frameworks_base-86d60cde91eb4216580fe9d1250dc27c17e86c70.tar.gz frameworks_base-86d60cde91eb4216580fe9d1250dc27c17e86c70.tar.bz2 |
Fix crash due to reverse selection.
Selection start can be bigger than selection end and this kind
of selection is generated by mouse selection at least from L MR1.
To fix and support SHARE button for this kind of selection,
getSelectedText need to invert selection start and selection end
when the selection start is bigger than selection end.
Bug: 22065979
Change-Id: Ide4ac41e3f59d256033aca004450712ca0bb0f03
-rw-r--r-- | core/java/android/widget/TextView.java | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 207605e..dfe373f 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -7562,10 +7562,14 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } String getSelectedText() { - if (hasSelection()) { - return String.valueOf(mText.subSequence(getSelectionStart(), getSelectionEnd())); + if (!hasSelection()) { + return null; } - return null; + + final int start = getSelectionStart(); + final int end = getSelectionEnd(); + return String.valueOf( + start > end ? mText.subSequence(end, start) : mText.subSequence(start, end)); } /** |