summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-10-09 23:06:28 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-10-09 23:06:28 +0000
commitd442a794708c487a07ae03a2e082a4cdb716b31b (patch)
treefd96a7947762acc175ca2048e5de6dfcfb9b1fd7 /core/java
parentdb4bc39713e23953d9986cd9d912824096d5f4a0 (diff)
parente82a38a8eed9b4b0a0daf7b36c978b685e659dc7 (diff)
Snap for 7809314 from e82a38a8eed9b4b0a0daf7b36c978b685e659dc7 to sc-qpr1-release
Change-Id: I5f73590196fcdf776944ca606fd1d9a5676a4fe6
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/view/translation/UiTranslationController.java14
-rw-r--r--core/java/android/widget/TextViewTranslationCallback.java8
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;
}