diff options
| author | Mark Punzalan <markpun@google.com> | 2022-05-19 09:26:51 +0000 |
|---|---|---|
| committer | Mark Punzalan <markpun@google.com> | 2022-05-25 20:03:10 +0000 |
| commit | 6758b3f7e768da925427deec4c60c0d5509fde55 (patch) | |
| tree | 8e842ad4dbd8655fdc59c47cb390be77693a32f8 /core/java/android/widget/TextView.java | |
| parent | 27a45d8ec3003009c0fdee717310a7d9c858e9d0 (diff) | |
Translate selectable TextViews by temporarily disabling selectable.
The text is not selectable while translated. Making translated text
selectable requires many more changes.
This was tested in Nextdoor in the feed/posts activity. When there is a
"Read more" link in the post, the link doesn't work while translated,
and doesn't behave the same way after translation is paused.
Bug: 202966891
Test: atest CtsTranslationTestCases
Test: Manually - with Nextdoor on feed and chat activities
Change-Id: I6e8f532d427d85ff22df0deb248d8416a15f4821
Diffstat (limited to 'core/java/android/widget/TextView.java')
| -rw-r--r-- | core/java/android/widget/TextView.java | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 93f72640bd3f..e745b8cf769b 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -14240,13 +14240,13 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener * Collects a {@link ViewTranslationRequest} which represents the content to be translated in * the view. * - * <p>NOTE: When overriding the method, it should not translate the password. If the subclass - * uses {@link TransformationMethod} to display the translated result, it's also not recommend - * to translate text is selectable or editable. + * <p>NOTE: When overriding the method, it should not collect a request to translate this + * TextView if it is displaying a password. * * @param supportedFormats the supported translation format. The value could be {@link * android.view.translation.TranslationSpec#DATA_FORMAT_TEXT}. - * @return the {@link ViewTranslationRequest} which contains the information to be translated. + * @param requestsCollector {@link Consumer} to receiver the {@link ViewTranslationRequest} + * which contains the information to be translated. */ @Override public void onCreateViewTranslationRequest(@NonNull int[] supportedFormats, @@ -14268,18 +14268,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener return; } boolean isPassword = isAnyPasswordInputType() || hasPasswordTransformationMethod(); - // TODO(b/177214256): support selectable text translation. - // We use the TransformationMethod to implement showing the translated text. The - // TextView does not support the text length change for TransformationMethod. If the - // text is selectable or editable, it will crash while selecting the text. To support - // it, it needs broader changes to text APIs, we only allow to translate non selectable - // and editable text in S. - if (isTextEditable() || isPassword || isTextSelectable()) { - if (UiTranslationController.DEBUG) { - Log.w(LOG_TAG, "Cannot create translation request. editable = " - + isTextEditable() + ", isPassword = " + isPassword + ", selectable = " - + isTextSelectable()); - } + if (isTextEditable() || isPassword) { + Log.w(LOG_TAG, "Cannot create translation request. editable = " + + isTextEditable() + ", isPassword = " + isPassword); return; } // TODO(b/176488462): apply the view's important for translation |
