summaryrefslogtreecommitdiffstats
path: root/core/java
diff options
context:
space:
mode:
authorClara Bayarri <clarabayarri@google.com>2015-04-10 10:02:19 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-04-10 10:02:21 +0000
commit4c42bc045daccb293198559334df6fc6232fff6a (patch)
treeb6ca3c867568e920b529298cdcf87e0dcc7b505f /core/java
parent7f062245f633b8b987ef79ed5d49ead58ca2f562 (diff)
parent13152d1c725c6310a697ebc521cf8b57a52490ac (diff)
downloadframeworks_base-4c42bc045daccb293198559334df6fc6232fff6a.zip
frameworks_base-4c42bc045daccb293198559334df6fc6232fff6a.tar.gz
frameworks_base-4c42bc045daccb293198559334df6fc6232fff6a.tar.bz2
Merge "Editor: Allow invalidation of the Text Selection Action Mode"
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/widget/Editor.java69
1 files changed, 45 insertions, 24 deletions
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java
index 0199f6d..5fb0c92 100644
--- a/core/java/android/widget/Editor.java
+++ b/core/java/android/widget/Editor.java
@@ -1668,6 +1668,7 @@ public class Editor {
if (mSelectionActionMode != null) {
// Selection action mode is already started
// TODO: revisit invocations to minimize this case.
+ mSelectionActionMode.invalidate();
return false;
}
ActionMode.Callback actionModeCallback = new SelectionActionModeCallback();
@@ -1682,6 +1683,7 @@ public class Editor {
boolean startSelectionActionModeWithSelection() {
if (mSelectionActionMode != null) {
// Selection action mode is already started
+ mSelectionActionMode.invalidate();
return false;
}
@@ -2965,6 +2967,28 @@ public class Editor {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
+ mode.setTitle(mTextView.getContext().getString(
+ com.android.internal.R.string.textSelectionCABTitle));
+ mode.setSubtitle(null);
+ mode.setTitleOptionalHint(true);
+ populateMenuWithItems(menu);
+
+ if (mCustomSelectionActionModeCallback != null) {
+ if (!mCustomSelectionActionModeCallback.onCreateActionMode(mode, menu)) {
+ // The custom mode can choose to cancel the action mode
+ return false;
+ }
+ }
+
+ if (menu.hasVisibleItems() || mode.getCustomView() != null) {
+ mTextView.setHasTransientState(true);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ private void populateMenuWithItems(Menu menu) {
final boolean legacy = mTextView.getContext().getApplicationInfo().targetSdkVersion <
Build.VERSION_CODES.LOLLIPOP;
final Context context = !legacy && menu instanceof MenuBuilder ?
@@ -2973,11 +2997,6 @@ public class Editor {
final TypedArray styledAttributes = context.obtainStyledAttributes(
com.android.internal.R.styleable.SelectionModeDrawables);
- mode.setTitle(mTextView.getContext().getString(
- com.android.internal.R.string.textSelectionCABTitle));
- mode.setSubtitle(null);
- mode.setTitleOptionalHint(true);
-
if (mTextView.canCut()) {
menu.add(0, TextView.ID_CUT, 0, com.android.internal.R.string.cut).
setIcon(styledAttributes.getResourceId(
@@ -3012,37 +3031,33 @@ public class Editor {
setShowAsAction(
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);
- }
+ updateReplaceItem(menu);
styledAttributes.recycle();
-
- if (mCustomSelectionActionModeCallback != null) {
- if (!mCustomSelectionActionModeCallback.onCreateActionMode(mode, menu)) {
- // The custom mode can choose to cancel the action mode
- return false;
- }
- }
-
- if (menu.hasVisibleItems() || mode.getCustomView() != null) {
- mTextView.setHasTransientState(true);
- return true;
- } else {
- return false;
- }
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
+ updateReplaceItem(menu);
+
if (mCustomSelectionActionModeCallback != null) {
return mCustomSelectionActionModeCallback.onPrepareActionMode(mode, menu);
}
return true;
}
+ private void updateReplaceItem(Menu menu) {
+ boolean canReplace = mTextView.isSuggestionsEnabled() && isCursorInsideSuggestionSpan();
+ boolean replaceItemExists = menu.findItem(TextView.ID_REPLACE) != null;
+ if (canReplace && !replaceItemExists) {
+ 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);
+ } else if (!canReplace && replaceItemExists) {
+ menu.removeItem(TextView.ID_REPLACE);
+ }
+ }
+
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
if (mCustomSelectionActionModeCallback != null &&
@@ -3798,6 +3813,9 @@ public class Editor {
Selection.setSelection((Spannable) mTextView.getText(), offset,
mTextView.getSelectionEnd());
updateDrawable();
+ if (mSelectionActionMode != null) {
+ mSelectionActionMode.invalidate();
+ }
}
@Override
@@ -3900,6 +3918,9 @@ public class Editor {
public void updateSelection(int offset) {
Selection.setSelection((Spannable) mTextView.getText(),
mTextView.getSelectionStart(), offset);
+ if (mSelectionActionMode != null) {
+ mSelectionActionMode.invalidate();
+ }
updateDrawable();
}