diff options
| author | 2022-03-24 13:15:40 +0000 | |
|---|---|---|
| committer | 2022-03-24 13:15:40 +0000 | |
| commit | 8121a43efde59f4b1b14f93607342960b5acfeb5 (patch) | |
| tree | 3f3d4e2af641c511ddb20d94aed59c89fd7f62b1 | |
| parent | 8eb1c121b69737198ba8ebb2fe975f8946754918 (diff) | |
| parent | fe6fddb4f086f9cf8e1c2bd84782496bd2992f8c (diff) | |
Merge "Fix the translation not work if the animation is off" into tm-dev
| -rw-r--r-- | core/java/android/widget/TextViewTranslationCallback.java | 18 |
1 files changed, 12 insertions, 6 deletions
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(); |