summaryrefslogtreecommitdiff
path: root/core/java/android/widget/TextViewTranslationCallback.java
diff options
context:
space:
mode:
authorJoanne Chung <joannechung@google.com>2021-04-09 12:17:19 +0800
committerJoanne Chung <joannechung@google.com>2021-04-20 11:14:22 +0800
commitf6a52811a1a30784b99c3caeec3225062092219d (patch)
treedffc7a7419c9054f373e54e4bff66cb9d5325a32 /core/java/android/widget/TextViewTranslationCallback.java
parent62d25e0eb9a18a1ace9c746ca95a449d0ee9023e (diff)
API feedback: Translation View API refinement.
Bug: 178046780 Test: manual Test: atest android.translation.cts.UiTranslationManagerTest CTS-Coverage-Bug: 177960696 Change-Id: I557ca4b3b4e7324af12e81dd8b5ac8a04a17b6b8
Diffstat (limited to 'core/java/android/widget/TextViewTranslationCallback.java')
-rw-r--r--core/java/android/widget/TextViewTranslationCallback.java13
1 files changed, 13 insertions, 0 deletions
diff --git a/core/java/android/widget/TextViewTranslationCallback.java b/core/java/android/widget/TextViewTranslationCallback.java
index 73f19a7a48c0..037606115521 100644
--- a/core/java/android/widget/TextViewTranslationCallback.java
+++ b/core/java/android/widget/TextViewTranslationCallback.java
@@ -79,6 +79,11 @@ public class TextViewTranslationCallback implements ViewTranslationCallback {
@Override
public boolean onShowTranslation(@NonNull View view) {
mIsShowingTranslation = true;
+ if (view.getViewTranslationResponse() == null) {
+ Log.wtf(TAG, "onShowTranslation() shouldn't be called before "
+ + "onViewTranslationResponse().");
+ return false;
+ }
if (mTranslationTransformation != null) {
((TextView) view).setTransformationMethod(mTranslationTransformation);
} else {
@@ -86,6 +91,7 @@ public class TextViewTranslationCallback implements ViewTranslationCallback {
// TODO(b/182433547): remove before S release
Log.w(TAG, "onShowTranslation(): no translated text.");
}
+ return false;
}
return true;
}
@@ -96,6 +102,11 @@ public class TextViewTranslationCallback implements ViewTranslationCallback {
@Override
public boolean onHideTranslation(@NonNull View view) {
mIsShowingTranslation = false;
+ if (view.getViewTranslationResponse() == null) {
+ Log.wtf(TAG, "onHideTranslation() shouldn't be called before "
+ + "onViewTranslationResponse().");
+ return false;
+ }
// Restore to original text content.
if (mTranslationTransformation != null) {
((TextView) view).setTransformationMethod(
@@ -105,6 +116,7 @@ public class TextViewTranslationCallback implements ViewTranslationCallback {
// TODO(b/182433547): remove before S release
Log.w(TAG, "onHideTranslation(): no translated text.");
}
+ return false;
}
return true;
}
@@ -124,6 +136,7 @@ public class TextViewTranslationCallback implements ViewTranslationCallback {
// TODO(b/182433547): remove before S release
Log.w(TAG, "onClearTranslation(): no translated text.");
}
+ return false;
}
return true;
}