summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClara Bayarri <clarabayarri@google.com>2015-04-10 15:35:31 +0100
committerClara Bayarri <clarabayarri@google.com>2015-04-14 16:49:25 +0100
commit578286fb321243e72a999b3e5fd4ef5f2e4b8682 (patch)
treeee978e259172fa4293c6446b314494dd57f82e82
parent4fc266bbef6129b5cefc910f0680eb9d61794faf (diff)
downloadframeworks_base-578286fb321243e72a999b3e5fd4ef5f2e4b8682.zip
frameworks_base-578286fb321243e72a999b3e5fd4ef5f2e4b8682.tar.gz
frameworks_base-578286fb321243e72a999b3e5fd4ef5f2e4b8682.tar.bz2
Editor: keep text selection when starting a process text intent.
This CL makes sure the selection is not cleared when a text processing intent starts, so that we can properly replace the selection when it comes back. It also fixes a related issue with the selection handles. The previous code assumed a text selection mode starts from touch and enters drag mode by default. This CL makes the code conscious of whether it should show the selection cursors or enter drag mode. BUG: 20148456 Change-Id: Ie8632e4a96f431dc6b2e4d0b4d3978eb55149172
-rw-r--r--core/java/android/widget/Editor.java36
-rw-r--r--core/java/android/widget/TextView.java1
2 files changed, 30 insertions, 7 deletions
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java
index 29073be..66b76d5 100644
--- a/core/java/android/widget/Editor.java
+++ b/core/java/android/widget/Editor.java
@@ -1008,14 +1008,14 @@ public class Editor {
stopSelectionActionMode();
} else {
stopSelectionActionMode();
- startSelectionActionModeWithSelection();
+ startSelectionActionModeWithSelectionAndStartDrag();
}
handled = true;
}
// Start a new selection
if (!handled) {
- handled = startSelectionActionModeWithSelection();
+ handled = startSelectionActionModeWithSelectionAndStartDrag();
}
return handled;
@@ -1680,9 +1680,34 @@ public class Editor {
}
/**
+ * Starts a Selection Action Mode with the current selection and enters drag mode. This should
+ * be used whenever the mode is started from a touch event.
+ *
+ * @return true if the selection mode was actually started.
+ */
+ private boolean startSelectionActionModeWithSelectionAndStartDrag() {
+ boolean selectionStarted = startSelectionActionModeWithSelectionInternal();
+ if (selectionStarted) {
+ getSelectionController().enterDrag();
+ }
+ return selectionStarted;
+ }
+
+ /**
+ * Starts a Selection Action Mode with the current selection and ensures the selection handles
+ * are shown. This should be used when the mode is started from a non-touch event.
+ *
* @return true if the selection mode was actually started.
*/
boolean startSelectionActionModeWithSelection() {
+ boolean selectionStarted = startSelectionActionModeWithSelectionInternal();
+ if (selectionStarted) {
+ getSelectionController().show();
+ }
+ return selectionStarted;
+ }
+
+ private boolean startSelectionActionModeWithSelectionInternal() {
if (mSelectionActionMode != null) {
// Selection action mode is already started
mSelectionActionMode.invalidate();
@@ -1721,10 +1746,6 @@ public class Editor {
imm.showSoftInput(mTextView, 0, null);
}
}
-
- if (selectionStarted) {
- getSelectionController().enterDrag();
- }
return selectionStarted;
}
@@ -3093,6 +3114,7 @@ public class Editor {
if (item.getIntent() != null
&& item.getIntent().getAction().equals(Intent.ACTION_PROCESS_TEXT)) {
item.getIntent().putExtra(Intent.EXTRA_PROCESS_TEXT, mTextView.getSelectedText());
+ mPreserveDetachedSelection = true;
mTextView.startActivityForResult(
item.getIntent(), TextView.PROCESS_TEXT_REQUEST_CODE);
return true;
@@ -4239,7 +4261,7 @@ public class Editor {
boolean stayedInArea = distanceSquared < doubleTapSlop * doubleTapSlop;
if (stayedInArea && isPositionOnText(x, y)) {
- startSelectionActionModeWithSelection();
+ startSelectionActionModeWithSelectionAndStartDrag();
mDiscardNextActionUp = true;
}
}
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 9bbf375..de4bada 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -9124,6 +9124,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
void replaceSelectionWithText(CharSequence text) {
((Editable) mText).replace(getSelectionStart(), getSelectionEnd(), text);
+ mEditor.startSelectionActionModeWithSelection();
}
/**