Loading core/java/android/view/translation/UiTranslationController.java +1 −1 Original line number Diff line number Diff line Loading @@ -424,7 +424,7 @@ public class UiTranslationController { if (callback == null) { if (view instanceof TextView) { // developer doesn't provide their override, we set the default TextView // implememtation. // implementation. callback = new TextViewTranslationCallback(); view.setViewTranslationCallback(callback); } else { Loading core/java/android/widget/TextView.java +0 −31 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -13946,33 +13944,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); } } } core/java/android/widget/TextViewTranslationCallback.java +24 −45 Original line number Diff line number Diff line Loading @@ -56,26 +56,6 @@ public class TextViewTranslationCallback implements ViewTranslationCallback { private CharSequence mContentDescription; /** * Invoked by the platform when receiving the successful {@link ViewTranslationResponse} for the * view that provides the translatable information by {@link View#createTranslationRequest} and * sent by the platform. */ void setTranslationTransformation(TranslationTransformationMethod method) { if (method == null) { if (DEBUG) { Log.w(TAG, "setTranslationTransformation: should not set null " + "TranslationTransformationMethod"); } return; } mTranslationTransformation = method; } TranslationTransformationMethod getTranslationTransformation() { return mTranslationTransformation; } private void clearTranslationTransformation() { if (DEBUG) { Log.v(TAG, "clearTranslationTransformation: " + mTranslationTransformation); Loading @@ -88,20 +68,26 @@ public class TextViewTranslationCallback implements ViewTranslationCallback { */ @Override public boolean onShowTranslation(@NonNull View view) { if (view.getViewTranslationResponse() == null) { Log.wtf(TAG, "onShowTranslation() shouldn't be called before " ViewTranslationResponse response = view.getViewTranslationResponse(); if (response == null) { Log.e(TAG, "onShowTranslation() shouldn't be called before " + "onViewTranslationResponse()."); return false; } if (mTranslationTransformation != null) { if (mTranslationTransformation == null) { TransformationMethod originalTranslationMethod = ((TextView) view).getTransformationMethod(); mTranslationTransformation = new TranslationTransformationMethod(response, originalTranslationMethod); } final TransformationMethod transformation = mTranslationTransformation; runWithAnimation( (TextView) view, () -> { mIsShowingTranslation = true; // TODO(b/178353965): well-handle setTransformationMethod. ((TextView) view).setTransformationMethod(transformation); }); ViewTranslationResponse response = view.getViewTranslationResponse(); if (response.getKeys().contains(ViewTranslationRequest.ID_CONTENT_DESCRIPTION)) { CharSequence translatedContentDescription = response.getValue(ViewTranslationRequest.ID_CONTENT_DESCRIPTION).getText(); Loading @@ -110,13 +96,6 @@ public class TextViewTranslationCallback implements ViewTranslationCallback { view.setContentDescription(translatedContentDescription); } } } else { if (DEBUG) { // TODO(b/182433547): remove before S release Log.w(TAG, "onShowTranslation(): no translated text."); } return false; } return true; } Loading @@ -126,7 +105,7 @@ public class TextViewTranslationCallback implements ViewTranslationCallback { @Override public boolean onHideTranslation(@NonNull View view) { if (view.getViewTranslationResponse() == null) { Log.wtf(TAG, "onHideTranslation() shouldn't be called before " Log.e(TAG, "onHideTranslation() shouldn't be called before " + "onViewTranslationResponse()."); return false; } Loading Loading
core/java/android/view/translation/UiTranslationController.java +1 −1 Original line number Diff line number Diff line Loading @@ -424,7 +424,7 @@ public class UiTranslationController { if (callback == null) { if (view instanceof TextView) { // developer doesn't provide their override, we set the default TextView // implememtation. // implementation. callback = new TextViewTranslationCallback(); view.setViewTranslationCallback(callback); } else { Loading
core/java/android/widget/TextView.java +0 −31 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -13946,33 +13944,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); } } }
core/java/android/widget/TextViewTranslationCallback.java +24 −45 Original line number Diff line number Diff line Loading @@ -56,26 +56,6 @@ public class TextViewTranslationCallback implements ViewTranslationCallback { private CharSequence mContentDescription; /** * Invoked by the platform when receiving the successful {@link ViewTranslationResponse} for the * view that provides the translatable information by {@link View#createTranslationRequest} and * sent by the platform. */ void setTranslationTransformation(TranslationTransformationMethod method) { if (method == null) { if (DEBUG) { Log.w(TAG, "setTranslationTransformation: should not set null " + "TranslationTransformationMethod"); } return; } mTranslationTransformation = method; } TranslationTransformationMethod getTranslationTransformation() { return mTranslationTransformation; } private void clearTranslationTransformation() { if (DEBUG) { Log.v(TAG, "clearTranslationTransformation: " + mTranslationTransformation); Loading @@ -88,20 +68,26 @@ public class TextViewTranslationCallback implements ViewTranslationCallback { */ @Override public boolean onShowTranslation(@NonNull View view) { if (view.getViewTranslationResponse() == null) { Log.wtf(TAG, "onShowTranslation() shouldn't be called before " ViewTranslationResponse response = view.getViewTranslationResponse(); if (response == null) { Log.e(TAG, "onShowTranslation() shouldn't be called before " + "onViewTranslationResponse()."); return false; } if (mTranslationTransformation != null) { if (mTranslationTransformation == null) { TransformationMethod originalTranslationMethod = ((TextView) view).getTransformationMethod(); mTranslationTransformation = new TranslationTransformationMethod(response, originalTranslationMethod); } final TransformationMethod transformation = mTranslationTransformation; runWithAnimation( (TextView) view, () -> { mIsShowingTranslation = true; // TODO(b/178353965): well-handle setTransformationMethod. ((TextView) view).setTransformationMethod(transformation); }); ViewTranslationResponse response = view.getViewTranslationResponse(); if (response.getKeys().contains(ViewTranslationRequest.ID_CONTENT_DESCRIPTION)) { CharSequence translatedContentDescription = response.getValue(ViewTranslationRequest.ID_CONTENT_DESCRIPTION).getText(); Loading @@ -110,13 +96,6 @@ public class TextViewTranslationCallback implements ViewTranslationCallback { view.setContentDescription(translatedContentDescription); } } } else { if (DEBUG) { // TODO(b/182433547): remove before S release Log.w(TAG, "onShowTranslation(): no translated text."); } return false; } return true; } Loading @@ -126,7 +105,7 @@ public class TextViewTranslationCallback implements ViewTranslationCallback { @Override public boolean onHideTranslation(@NonNull View view) { if (view.getViewTranslationResponse() == null) { Log.wtf(TAG, "onHideTranslation() shouldn't be called before " Log.e(TAG, "onHideTranslation() shouldn't be called before " + "onViewTranslationResponse()."); return false; } Loading