diff options
| author | Abodunrinwa Toki <toki@google.com> | 2017-09-29 14:21:32 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-09-29 14:21:32 +0000 |
| commit | cbf064d3bc420d8331224eb231da5f487a610a96 (patch) | |
| tree | 8e1f75f481fca4320b787e076f88f0231952d3d3 /core/java/android/widget/SelectionActionModeHelper.java | |
| parent | d8d53aa5be31cbd6011e12414a07c0e2d9edf82f (diff) | |
| parent | 3521f3f4306735ddedf560531b0639348d96a89f (diff) | |
Merge "Increase the duration allowed for a TC result."
Diffstat (limited to 'core/java/android/widget/SelectionActionModeHelper.java')
| -rw-r--r-- | core/java/android/widget/SelectionActionModeHelper.java | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/core/java/android/widget/SelectionActionModeHelper.java b/core/java/android/widget/SelectionActionModeHelper.java index c7f22e6e8465..f713ae8eb21d 100644 --- a/core/java/android/widget/SelectionActionModeHelper.java +++ b/core/java/android/widget/SelectionActionModeHelper.java @@ -60,12 +60,6 @@ public final class SelectionActionModeHelper { private static final String LOG_TAG = "SelectActionModeHelper"; - /** - * Maximum time (in milliseconds) to wait for a result before timing out. - */ - // TODO: Consider making this a ViewConfiguration. - private static final int TIMEOUT_DURATION = 200; - private static final boolean SMART_SELECT_ANIMATION_ENABLED = true; private final Editor mEditor; @@ -111,7 +105,7 @@ public final class SelectionActionModeHelper { resetTextClassificationHelper(); mTextClassificationAsyncTask = new TextClassificationAsyncTask( mTextView, - TIMEOUT_DURATION, + mTextClassificationHelper.getTimeoutDuration(), adjustSelection ? mTextClassificationHelper::suggestSelection : mTextClassificationHelper::classifyText, @@ -130,7 +124,7 @@ public final class SelectionActionModeHelper { resetTextClassificationHelper(); mTextClassificationAsyncTask = new TextClassificationAsyncTask( mTextView, - TIMEOUT_DURATION, + mTextClassificationHelper.getTimeoutDuration(), mTextClassificationHelper::classifyText, this::invalidateActionMode) .execute(); @@ -258,6 +252,7 @@ public final class SelectionActionModeHelper { return result; } + // TODO: Move public pure functions out of this class and make it package-private. /** * Merges a {@link RectF} into an existing list of rectangles. While merging, this method * makes sure that: @@ -789,6 +784,9 @@ public final class SelectionActionModeHelper { private LocaleList mLastClassificationLocales; private SelectionResult mLastClassificationResult; + /** Whether the TextClassifier has been initialized. */ + private boolean mHot; + TextClassificationHelper(TextClassifier textClassifier, CharSequence text, int selectionStart, int selectionEnd, LocaleList locales) { reset(textClassifier, text, selectionStart, selectionEnd, locales); @@ -808,11 +806,13 @@ public final class SelectionActionModeHelper { @WorkerThread public SelectionResult classifyText() { + mHot = true; return performClassification(null /* selection */); } @WorkerThread public SelectionResult suggestSelection() { + mHot = true; trimText(); final TextSelection selection = mTextClassifier.suggestSelection( mTrimmedText, mRelativeStart, mRelativeEnd, mLocales); @@ -821,6 +821,22 @@ public final class SelectionActionModeHelper { return performClassification(selection); } + /** + * Maximum time (in milliseconds) to wait for a textclassifier result before timing out. + */ + // TODO: Consider making this a ViewConfiguration. + public int getTimeoutDuration() { + if (mHot) { + return 200; + } else { + // Return a slightly larger number than usual when the TextClassifier is first + // initialized. Initialization would usually take longer than subsequent calls to + // the TextClassifier. The impact of this on the UI is that we do not show the + // selection handles or toolbar until after this timeout. + return 500; + } + } + private SelectionResult performClassification(@Nullable TextSelection selection) { if (!Objects.equals(mText, mLastClassificationText) || mSelectionStart != mLastClassificationSelectionStart |
