From 9753899a97020f3402b9f409f3d133690ace03c4 Mon Sep 17 00:00:00 2001 From: Joanne Chung Date: Thu, 13 May 2021 23:02:12 +0800 Subject: Translate TextView content description if exist Screen reader(Talkback) will read content description first if the developers set. We only translate TextView text, this may cause the screen reader will not read the translated text if the developers set content description. To fix the issue, we also send the content description to translate. When the translated text is shown, we also set content description with translated content description and reset to original content description if show original text. Bug: 187134784 Test: atest CtsTranslationTestCases Change-Id: I6986384260627a0539780b7293d47666c442d852 --- core/java/android/widget/TextView.java | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'core/java/android/widget/TextView.java') diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 1a37b595287d..e0238b9bce13 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -13924,6 +13924,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener // TODO(b/176488462): apply the view's important for translation requestBuilder.setValue(ViewTranslationRequest.ID_TEXT, TranslationRequestValue.forText(mText)); + if (!TextUtils.isEmpty(getContentDescription())) { + requestBuilder.setValue(ViewTranslationRequest.ID_CONTENT_DESCRIPTION, + TranslationRequestValue.forText(getContentDescription())); + } } requestsCollector.accept(requestBuilder.build()); } -- cgit v1.2.3