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
This commit is contained in:
Joanne Chung
2021-10-09 02:42:24 +00:00
committed by Automerger Merge Worker
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 (DEBUG) { if (callback instanceof TextViewTranslationCallback) {
Log.d(TAG, "Duplicate ViewTranslationResponse for " + autofillId if (((TextViewTranslationCallback) callback).isShowingTranslation()) {
+ ". Ignoring."); if (DEBUG) {
Log.d(TAG, "Duplicate ViewTranslationResponse for " + autofillId
+ ". 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;
} }