diff options
| author | Joanne Chung <joannechung@google.com> | 2021-10-09 02:42:24 +0000 |
|---|---|---|
| committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-10-09 02:42:24 +0000 |
| commit | d8b714a0eccbda548fa64c1cfdb0e399b8881fb8 (patch) | |
| tree | 1f49ac82ed45dedbf261afb7b5dadc45235b9faa /core/java | |
| parent | c000cd93728352305f925c3e6f5e648c530c24e3 (diff) | |
| parent | e82a38a8eed9b4b0a0daf7b36c978b685e659dc7 (diff) | |
Merge "Fix not show translation if call startTranslation after pauseTranslation" into sc-qpr1-dev am: e82a38a8ee
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16001112
Change-Id: I103defd38bad4cfd7fde80b2f9d629fc8bc93144
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/view/translation/UiTranslationController.java | 14 | ||||
| -rw-r--r-- | core/java/android/widget/TextViewTranslationCallback.java | 8 |
2 files changed, 16 insertions, 6 deletions
diff --git a/core/java/android/view/translation/UiTranslationController.java b/core/java/android/view/translation/UiTranslationController.java index f1c5a080a77b..d078c2cfbfd1 100644 --- a/core/java/android/view/translation/UiTranslationController.java +++ b/core/java/android/view/translation/UiTranslationController.java @@ -431,15 +431,19 @@ public class UiTranslationController { continue; } mActivity.runOnUiThread(() -> { + ViewTranslationCallback callback = view.getViewTranslationCallback(); if (view.getViewTranslationResponse() != null && view.getViewTranslationResponse().equals(response)) { - if (DEBUG) { - Log.d(TAG, "Duplicate ViewTranslationResponse for " + autofillId - + ". Ignoring."); + if (callback instanceof TextViewTranslationCallback) { + if (((TextViewTranslationCallback) callback).isShowingTranslation()) { + if (DEBUG) { + Log.d(TAG, "Duplicate ViewTranslationResponse for " + autofillId + + ". Ignoring."); + } + return; + } } - return; } - ViewTranslationCallback callback = view.getViewTranslationCallback(); if (callback == null) { if (view instanceof TextView) { // developer doesn't provide their override, we set the default TextView diff --git a/core/java/android/widget/TextViewTranslationCallback.java b/core/java/android/widget/TextViewTranslationCallback.java index 152405bf4d37..4a78f3ee6fac 100644 --- a/core/java/android/widget/TextViewTranslationCallback.java +++ b/core/java/android/widget/TextViewTranslationCallback.java @@ -64,6 +64,12 @@ public class TextViewTranslationCallback implements ViewTranslationCallback { */ @Override public boolean onShowTranslation(@NonNull View view) { + if (mIsShowingTranslation) { + if (DEBUG) { + Log.d(TAG, view + " is already showing translated text."); + } + return false; + } ViewTranslationResponse response = view.getViewTranslationResponse(); if (response == null) { Log.e(TAG, "onShowTranslation() shouldn't be called before " @@ -152,7 +158,7 @@ public class TextViewTranslationCallback implements ViewTranslationCallback { return true; } - boolean isShowingTranslation() { + public boolean isShowingTranslation() { return mIsShowingTranslation; } |
