Merge "Fix not show translation if call startTranslation after pauseTranslation" into sc-qpr1-dev

This commit is contained in:
Joanne Chung
2021-10-09 02:26:10 +00:00
committed by Android (Google) Code Review
2 changed files with 16 additions and 6 deletions

View File

@@ -431,15 +431,19 @@ public class UiTranslationController {
continue; continue;
} }
mActivity.runOnUiThread(() -> { mActivity.runOnUiThread(() -> {
ViewTranslationCallback callback = view.getViewTranslationCallback();
if (view.getViewTranslationResponse() != null if (view.getViewTranslationResponse() != null
&& view.getViewTranslationResponse().equals(response)) { && view.getViewTranslationResponse().equals(response)) {
if (callback instanceof TextViewTranslationCallback) {
if (((TextViewTranslationCallback) callback).isShowingTranslation()) {
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "Duplicate ViewTranslationResponse for " + autofillId Log.d(TAG, "Duplicate ViewTranslationResponse for " + autofillId
+ ". Ignoring."); + ". Ignoring.");
} }
return; return;
} }
ViewTranslationCallback callback = view.getViewTranslationCallback(); }
}
if (callback == null) { if (callback == null) {
if (view instanceof TextView) { if (view instanceof TextView) {
// developer doesn't provide their override, we set the default TextView // developer doesn't provide their override, we set the default TextView

View File

@@ -64,6 +64,12 @@ public class TextViewTranslationCallback implements ViewTranslationCallback {
*/ */
@Override @Override
public boolean onShowTranslation(@NonNull View view) { 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(); ViewTranslationResponse response = view.getViewTranslationResponse();
if (response == null) { if (response == null) {
Log.e(TAG, "onShowTranslation() shouldn't be called before " Log.e(TAG, "onShowTranslation() shouldn't be called before "
@@ -152,7 +158,7 @@ public class TextViewTranslationCallback implements ViewTranslationCallback {
return true; return true;
} }
boolean isShowingTranslation() { public boolean isShowingTranslation() {
return mIsShowingTranslation; return mIsShowingTranslation;
} }