summaryrefslogtreecommitdiff
path: root/core/java/android/widget/SelectionActionModeHelper.java
diff options
context:
space:
mode:
authorAbodunrinwa Toki <toki@google.com>2017-09-19 23:18:40 +0100
committerAbodunrinwa Toki <toki@google.com>2017-10-12 23:50:53 +0100
commit0e6b43ed58074725d8021401ded8e22a685d15e1 (patch)
treec22bf024ca556e6c7972b286718981348b141226 /core/java/android/widget/SelectionActionModeHelper.java
parent24f519007d734adc8f425cb5f954b54d0c62c5a8 (diff)
Flags to enable/disable smart selection in EditText
1. smart_selection_enabled_for_edit_text Disables smart selection for editable text. 2. smart_selection_dark_launch Dark launch TextClassifierImpl.suggestSelection(...) In this mode we run the method, but never change the user's selection to measure the quality of the results based on what the user actually wanted. Bug: 65959640 Test: Manually tested flags turn on/off feature with 'adb shell settings put global' and GServices override. Test: bit FrameworksCoreTests:android.provider.SettingsBackupTest Change-Id: Iacc561c8ee004b0123de66ad1ee06b1f56b4e4b4
Diffstat (limited to 'core/java/android/widget/SelectionActionModeHelper.java')
-rw-r--r--core/java/android/widget/SelectionActionModeHelper.java30
1 files changed, 20 insertions, 10 deletions
diff --git a/core/java/android/widget/SelectionActionModeHelper.java b/core/java/android/widget/SelectionActionModeHelper.java
index 3be42a5b17c5..5e22650a83cc 100644
--- a/core/java/android/widget/SelectionActionModeHelper.java
+++ b/core/java/android/widget/SelectionActionModeHelper.java
@@ -95,11 +95,15 @@ public final class SelectionActionModeHelper {
}
public void startActionModeAsync(boolean adjustSelection) {
+ // Check if the smart selection should run for editable text.
+ adjustSelection &= !mTextView.isTextEditable()
+ || mTextView.getTextClassifier().getSettings()
+ .isSuggestSelectionEnabledForEditableText();
+
mSelectionTracker.onOriginalSelection(
getText(mTextView),
mTextView.getSelectionStart(),
- mTextView.getSelectionEnd(),
- mTextView.isTextEditable());
+ mTextView.getSelectionEnd());
cancelAsyncTask();
if (skipTextClassification()) {
startActionMode(null);
@@ -196,7 +200,10 @@ public final class SelectionActionModeHelper {
private void startActionMode(@Nullable SelectionResult result) {
final CharSequence text = getText(mTextView);
if (result != null && text instanceof Spannable) {
- Selection.setSelection((Spannable) text, result.mStart, result.mEnd);
+ // Do not change the selection if TextClassifier should be dark launched.
+ if (!mTextView.getTextClassifier().getSettings().isDarkLaunch()) {
+ Selection.setSelection((Spannable) text, result.mStart, result.mEnd);
+ }
mTextClassification = result.mClassification;
} else {
mTextClassification = null;
@@ -377,7 +384,7 @@ public final class SelectionActionModeHelper {
}
private void resetTextClassificationHelper() {
- mTextClassificationHelper.reset(
+ mTextClassificationHelper.init(
mTextView.getTextClassifier(),
getText(mTextView),
mTextView.getSelectionStart(), mTextView.getSelectionEnd(),
@@ -415,8 +422,7 @@ public final class SelectionActionModeHelper {
/**
* Called when the original selection happens, before smart selection is triggered.
*/
- public void onOriginalSelection(
- CharSequence text, int selectionStart, int selectionEnd, boolean editableText) {
+ public void onOriginalSelection(CharSequence text, int selectionStart, int selectionEnd) {
// If we abandoned a selection and created a new one very shortly after, we may still
// have a pending request to log ABANDON, which we flush here.
mDelayedLogAbandon.flush();
@@ -812,11 +818,11 @@ public final class SelectionActionModeHelper {
TextClassificationHelper(TextClassifier textClassifier,
CharSequence text, int selectionStart, int selectionEnd, LocaleList locales) {
- reset(textClassifier, text, selectionStart, selectionEnd, locales);
+ init(textClassifier, text, selectionStart, selectionEnd, locales);
}
@UiThread
- public void reset(TextClassifier textClassifier,
+ public void init(TextClassifier textClassifier,
CharSequence text, int selectionStart, int selectionEnd, LocaleList locales) {
mTextClassifier = Preconditions.checkNotNull(textClassifier);
mText = Preconditions.checkNotNull(text).toString();
@@ -839,8 +845,12 @@ public final class SelectionActionModeHelper {
trimText();
final TextSelection selection = mTextClassifier.suggestSelection(
mTrimmedText, mRelativeStart, mRelativeEnd, mLocales);
- mSelectionStart = Math.max(0, selection.getSelectionStartIndex() + mTrimStart);
- mSelectionEnd = Math.min(mText.length(), selection.getSelectionEndIndex() + mTrimStart);
+ // Do not classify new selection boundaries if TextClassifier should be dark launched.
+ if (!mTextClassifier.getSettings().isDarkLaunch()) {
+ mSelectionStart = Math.max(0, selection.getSelectionStartIndex() + mTrimStart);
+ mSelectionEnd = Math.min(
+ mText.length(), selection.getSelectionEndIndex() + mTrimStart);
+ }
return performClassification(selection);
}