summaryrefslogtreecommitdiff
path: root/core/java/android/widget/TextView.java
diff options
context:
space:
mode:
authorJoanne Chung <joannechung@google.com>2021-06-10 18:34:19 +0800
committerJoanne Chung <joannechung@google.com>2021-06-17 22:12:27 +0800
commita9da1722cc6994d32b5eb2ca5618dba7013d447b (patch)
treee657b0595068a545de4026b20911ac6afd3df1dd /core/java/android/widget/TextView.java
parent44e18a7ab7b67ffd82de27d567a676d4749b67fd (diff)
Bug fix: Move the implementation out from View.onTranslationResponse.
Keep onTranslationResponse() only to save TranslationResponse. We can move set TransformationMethod logic to TextViewTranslationCallback. With the current implementation, if the developers overrides onTranslationResponse(), they don't have a chance to use the TextView default ViewTranslationCallback implementation because they don't set the TranslationTransformation, they must implement their solution. If we move logic to TextViewViewTranslationCallback and the developers only overrides onTranslationResponse(), they still have a chance to use the default TextViewViewTranslationCallback if the developers set the TranslationResponse for View. Bug: 178353965 Test: manual to make sure translation still works. Test: atest CtsTranslationTestCases Change-Id: Iada7f3efbbc7705ecf962c78e275ed942816707f
Diffstat (limited to 'core/java/android/widget/TextView.java')
-rw-r--r--core/java/android/widget/TextView.java31
1 files changed, 0 insertions, 31 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 3c4fd5e93580..9032d62bbb49 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -129,7 +129,6 @@ import android.text.method.TextKeyListener;
import android.text.method.TimeKeyListener;
import android.text.method.TransformationMethod;
import android.text.method.TransformationMethod2;
-import android.text.method.TranslationTransformationMethod;
import android.text.method.WordIterator;
import android.text.style.CharacterStyle;
import android.text.style.ClickableSpan;
@@ -199,7 +198,6 @@ import android.view.translation.TranslationSpec;
import android.view.translation.UiTranslationController;
import android.view.translation.ViewTranslationCallback;
import android.view.translation.ViewTranslationRequest;
-import android.view.translation.ViewTranslationResponse;
import android.widget.RemoteViews.RemoteView;
import com.android.internal.annotations.VisibleForTesting;
@@ -13938,33 +13936,4 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
requestsCollector.accept(requestBuilder.build());
}
-
- /**
- *
- * Called when the content from {@link #onCreateViewTranslationRequest} had been translated by
- * the TranslationService. The default implementation will replace the current
- * {@link TransformationMethod} to transform the original text to the translated text display.
- *
- * @param response a {@link ViewTranslationResponse} that contains the translated information
- * which can be shown in the view.
- */
- @Override
- public void onViewTranslationResponse(@NonNull ViewTranslationResponse response) {
- // set ViewTranslationResponse
- super.onViewTranslationResponse(response);
- // TODO(b/178353965): move to ViewTranslationCallback.onShow()
- ViewTranslationCallback callback = getViewTranslationCallback();
- if (callback instanceof TextViewTranslationCallback) {
- TextViewTranslationCallback textViewDefaultCallback =
- (TextViewTranslationCallback) callback;
- TranslationTransformationMethod oldTranslationMethod =
- textViewDefaultCallback.getTranslationTransformation();
- TransformationMethod originalTranslationMethod = oldTranslationMethod != null
- ? oldTranslationMethod.getOriginalTransformationMethod() : mTransformation;
- TranslationTransformationMethod newTranslationMethod =
- new TranslationTransformationMethod(response, originalTranslationMethod);
- // TODO(b/178353965): well-handle setTransformationMethod.
- textViewDefaultCallback.setTranslationTransformation(newTranslationMethod);
- }
- }
}