summaryrefslogtreecommitdiffstats
path: root/core/java/android/widget
diff options
context:
space:
mode:
authorClara Bayarri <clarabayarri@google.com>2015-03-02 16:09:09 +0000
committerClara Bayarri <clarabayarri@google.com>2015-03-12 10:31:11 +0000
commitf84a9724f1a915c782ac9d9c6465e13f8e9a42c9 (patch)
tree0f24c40b0d6549d81630a5a4b0bb874ba6eda8be /core/java/android/widget
parent216ce5d7b2b0c10305c8e109d5b5197c67cd76ab (diff)
downloadframeworks_base-f84a9724f1a915c782ac9d9c6465e13f8e9a42c9.zip
frameworks_base-f84a9724f1a915c782ac9d9c6465e13f8e9a42c9.tar.gz
frameworks_base-f84a9724f1a915c782ac9d9c6465e13f8e9a42c9.tar.bz2
Move the "Replace" popup option to the Text Selection ActionMode.
As a first step in unifying the cut/copy/paste ActionMode in Editor with the paste/replace popup, I'm moving the replace option to the CAB ActionMode. Paste is already there, so for now all options are together. Missing things to address in upcoming CLs: - Invoke the ActionMode in all cases where the popup shows up now, ensuring only the options that are currently available show up. - Get rid of the current popup - Make the ActionMode a floating toolbar (pending feature completion) - Define a keyboard shortcut for replace? Note that since the ActionMode still shows up in the ActionBar and replace has no icon it now appears as text and takes up lots of space. This will improve when we can switch to using a floating toolbar. Change-Id: Ib6b60bae9b58e4db96b9c4cee556e19d3f1bb466
Diffstat (limited to 'core/java/android/widget')
-rw-r--r--core/java/android/widget/Editor.java22
-rw-r--r--core/java/android/widget/TextView.java1
2 files changed, 19 insertions, 4 deletions
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java
index cc44577..81d9d56 100644
--- a/core/java/android/widget/Editor.java
+++ b/core/java/android/widget/Editor.java
@@ -2969,6 +2969,12 @@ public class Editor {
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
}
+ if (mTextView.isSuggestionsEnabled() && isCursorInsideSuggestionSpan()) {
+ menu.add(0, TextView.ID_REPLACE, 0, com.android.internal.R.string.replace).
+ setShowAsAction(
+ MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
+ }
+
styledAttributes.recycle();
if (mCustomSelectionActionModeCallback != null) {
@@ -3000,6 +3006,10 @@ public class Editor {
mCustomSelectionActionModeCallback.onActionItemClicked(mode, item)) {
return true;
}
+ if (item.getItemId() == TextView.ID_REPLACE) {
+ onReplace();
+ return true;
+ }
return mTextView.onTextContextMenuItem(item.getItemId());
}
@@ -3028,6 +3038,13 @@ public class Editor {
}
}
+ private void onReplace() {
+ int middle = (mTextView.getSelectionStart() + mTextView.getSelectionEnd()) / 2;
+ stopSelectionActionMode();
+ Selection.setSelection((Spannable) mTextView.getText(), middle);
+ showSuggestions();
+ }
+
private class ActionPopupWindow extends PinnedPopupWindow implements OnClickListener {
private static final int POPUP_TEXT_LAYOUT =
com.android.internal.R.layout.text_edit_action_popup_text;
@@ -3086,10 +3103,7 @@ public class Editor {
mTextView.onTextContextMenuItem(TextView.ID_PASTE);
hide();
} else if (view == mReplaceTextView) {
- int middle = (mTextView.getSelectionStart() + mTextView.getSelectionEnd()) / 2;
- stopSelectionActionMode();
- Selection.setSelection((Spannable) mTextView.getText(), middle);
- showSuggestions();
+ onReplace();
}
}
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index faf1c40..628833d 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -8818,6 +8818,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
static final int ID_COPY = android.R.id.copy;
static final int ID_PASTE = android.R.id.paste;
static final int ID_PASTE_AS_PLAIN_TEXT = android.R.id.pasteAsPlainText;
+ static final int ID_REPLACE = android.R.id.replaceText;
/**
* Called when a context menu option for the text view is selected. Currently