Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3a6037d1 authored by Joanne Chung's avatar Joanne Chung Committed by Automerger Merge Worker
Browse files

Merge "Fix translation animation flash for the same translation" into...

Merge "Fix translation animation flash for the same translation" into sc-v2-dev am: 1ff5a29a am: 5c32e894

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16432382

Change-Id: Ifb0b11a3afe6591d0651d4ea2949ed691b1bc756
parents 2a32ff7e 5c32e894
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -437,7 +437,10 @@ public class UiTranslationController {
                    if (view.getViewTranslationResponse() != null
                            && view.getViewTranslationResponse().equals(response)) {
                        if (callback instanceof TextViewTranslationCallback) {
                            if (((TextViewTranslationCallback) callback).isShowingTranslation()) {
                            TextViewTranslationCallback textViewCallback =
                                    (TextViewTranslationCallback) callback;
                            if (textViewCallback.isShowingTranslation()
                                    || textViewCallback.isAnimationRunning()) {
                                if (DEBUG) {
                                    Log.d(TAG, "Duplicate ViewTranslationResponse for " + autofillId
                                            + ". Ignoring.");
+11 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ public class TextViewTranslationCallback implements ViewTranslationCallback {

    private TranslationTransformationMethod mTranslationTransformation;
    private boolean mIsShowingTranslation = false;
    private boolean mAnimationRunning = false;
    private boolean mIsTextPaddingEnabled = false;
    private CharSequence mPaddedText;
    private int mAnimationDurationMillis = 250; // default value
@@ -92,6 +93,7 @@ public class TextViewTranslationCallback implements ViewTranslationCallback {
                (TextView) view,
                () -> {
                    mIsShowingTranslation = true;
                    mAnimationRunning = false;
                    // TODO(b/178353965): well-handle setTransformationMethod.
                    ((TextView) view).setTransformationMethod(transformation);
                });
@@ -124,6 +126,7 @@ public class TextViewTranslationCallback implements ViewTranslationCallback {
                    (TextView) view,
                    () -> {
                        mIsShowingTranslation = false;
                        mAnimationRunning = false;
                        ((TextView) view).setTransformationMethod(transformation);
                    });
            if (!TextUtils.isEmpty(mContentDescription)) {
@@ -162,6 +165,13 @@ public class TextViewTranslationCallback implements ViewTranslationCallback {
        return mIsShowingTranslation;
    }

    /**
     * Returns whether the view is running animation to show or hide the translation.
     */
    public boolean isAnimationRunning() {
        return mAnimationRunning;
    }

    @Override
    public void enableContentPadding() {
        mIsTextPaddingEnabled = true;
@@ -230,6 +240,7 @@ public class TextViewTranslationCallback implements ViewTranslationCallback {
            mAnimator.end();
            // Note: mAnimator is now null; do not use again here.
        }
        mAnimationRunning = true;
        int fadedOutColor = colorWithAlpha(view.getCurrentTextColor(), 0);
        mAnimator = ValueAnimator.ofArgb(view.getCurrentTextColor(), fadedOutColor);
        mAnimator.addUpdateListener(