diff options
| author | Presubmit Automerger Backend <android-build-presubmit-automerger-backend@system.gserviceaccount.com> | 2022-03-24 07:20:13 +0000 |
|---|---|---|
| committer | Presubmit Automerger Backend <android-build-presubmit-automerger-backend@system.gserviceaccount.com> | 2022-03-24 07:20:13 +0000 |
| commit | fd025bac1b8f16cd6761f74963ce59263e0f0fcf (patch) | |
| tree | 8e13d784ed471bdee653b5573f6f3ae58809a135 /core/java | |
| parent | 69b351e50895ea9dbb85ae406fdad9d6aec8ad5d (diff) | |
| parent | 880a59217d4780d21ecf27c168d5d7a1c24df954 (diff) | |
[automerge] Fix the translation not work if the animation is off 2p: 880a59217d
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17312465
Bug: 215386127
Change-Id: I21f5af8a13b89c2e68441cae002ee6b297bf051d
Merged-In: Id0d02c422100effcf842209971052f4d6e9b0bd2
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/view/translation/UiTranslationManager.java | 8 | ||||
| -rw-r--r-- | core/java/android/widget/TextViewTranslationCallback.java | 18 |
2 files changed, 16 insertions, 10 deletions
diff --git a/core/java/android/view/translation/UiTranslationManager.java b/core/java/android/view/translation/UiTranslationManager.java index 3012e9344a1b..b57134b3ec44 100644 --- a/core/java/android/view/translation/UiTranslationManager.java +++ b/core/java/android/view/translation/UiTranslationManager.java @@ -101,26 +101,26 @@ public final class UiTranslationManager { public static final String LOG_TAG = "UiTranslation"; /** - * The state caller request to disable utranslation,, it is no longer need to ui translation. + * The state the caller requests to enable UI translation. * * @hide */ public static final int STATE_UI_TRANSLATION_STARTED = 0; /** - * The state caller request to pause ui translation, it will switch back to the original text. + * The state caller requests to pause UI translation. It will switch back to the original text. * * @hide */ public static final int STATE_UI_TRANSLATION_PAUSED = 1; /** - * The state caller request to resume the paused ui translation, it will show the translated + * The state caller requests to resume the paused UI translation. It will show the translated * text again if the text had been translated. * * @hide */ public static final int STATE_UI_TRANSLATION_RESUMED = 2; /** - * The state the caller request to enable ui translation. + * The state the caller requests to disable UI translation when it no longer needs translation. * * @hide */ diff --git a/core/java/android/widget/TextViewTranslationCallback.java b/core/java/android/widget/TextViewTranslationCallback.java index 942be21b1ade..1713d842560b 100644 --- a/core/java/android/widget/TextViewTranslationCallback.java +++ b/core/java/android/widget/TextViewTranslationCallback.java @@ -89,7 +89,7 @@ public class TextViewTranslationCallback implements ViewTranslationCallback { originalTranslationMethod); } final TransformationMethod transformation = mTranslationTransformation; - runWithAnimation( + runChangeTextWithAnimationIfNeeded( (TextView) view, () -> { mIsShowingTranslation = true; @@ -122,7 +122,7 @@ public class TextViewTranslationCallback implements ViewTranslationCallback { if (mTranslationTransformation != null) { final TransformationMethod transformation = mTranslationTransformation.getOriginalTransformationMethod(); - runWithAnimation( + runChangeTextWithAnimationIfNeeded( (TextView) view, () -> { mIsShowingTranslation = false; @@ -232,10 +232,16 @@ public class TextViewTranslationCallback implements ViewTranslationCallback { * Applies a simple text alpha animation when toggling between original and translated text. The * text is fully faded out, then swapped to the new text, then the fading is reversed. * - * @param runnable the operation to run on the view after the text is faded out, to change to - * displaying the original or translated text. + * @param changeTextRunnable the operation to run on the view after the text is faded out, to + * change to displaying the original or translated text. */ - private void runWithAnimation(TextView view, Runnable runnable) { + private void runChangeTextWithAnimationIfNeeded(TextView view, Runnable changeTextRunnable) { + boolean areAnimatorsEnabled = ValueAnimator.areAnimatorsEnabled(); + if (!areAnimatorsEnabled) { + // The animation is disabled, just change display text + changeTextRunnable.run(); + return; + } if (mAnimator != null) { mAnimator.end(); // Note: mAnimator is now null; do not use again here. @@ -269,7 +275,7 @@ public class TextViewTranslationCallback implements ViewTranslationCallback { @Override public void onAnimationRepeat(Animator animation) { - runnable.run(); + changeTextRunnable.run(); } }); mAnimator.start(); |
