Merge "Fix translation animation flash for the same translation" into sc-v2-dev
This commit is contained in:
@@ -435,7 +435,10 @@ public class UiTranslationController {
|
|||||||
if (view.getViewTranslationResponse() != null
|
if (view.getViewTranslationResponse() != null
|
||||||
&& view.getViewTranslationResponse().equals(response)) {
|
&& view.getViewTranslationResponse().equals(response)) {
|
||||||
if (callback instanceof TextViewTranslationCallback) {
|
if (callback instanceof TextViewTranslationCallback) {
|
||||||
if (((TextViewTranslationCallback) callback).isShowingTranslation()) {
|
TextViewTranslationCallback textViewCallback =
|
||||||
|
(TextViewTranslationCallback) callback;
|
||||||
|
if (textViewCallback.isShowingTranslation()
|
||||||
|
|| textViewCallback.isAnimationRunning()) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "Duplicate ViewTranslationResponse for " + autofillId
|
Log.d(TAG, "Duplicate ViewTranslationResponse for " + autofillId
|
||||||
+ ". Ignoring.");
|
+ ". Ignoring.");
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ public class TextViewTranslationCallback implements ViewTranslationCallback {
|
|||||||
|
|
||||||
private TranslationTransformationMethod mTranslationTransformation;
|
private TranslationTransformationMethod mTranslationTransformation;
|
||||||
private boolean mIsShowingTranslation = false;
|
private boolean mIsShowingTranslation = false;
|
||||||
|
private boolean mAnimationRunning = false;
|
||||||
private boolean mIsTextPaddingEnabled = false;
|
private boolean mIsTextPaddingEnabled = false;
|
||||||
private CharSequence mPaddedText;
|
private CharSequence mPaddedText;
|
||||||
private int mAnimationDurationMillis = 250; // default value
|
private int mAnimationDurationMillis = 250; // default value
|
||||||
@@ -92,6 +93,7 @@ public class TextViewTranslationCallback implements ViewTranslationCallback {
|
|||||||
(TextView) view,
|
(TextView) view,
|
||||||
() -> {
|
() -> {
|
||||||
mIsShowingTranslation = true;
|
mIsShowingTranslation = true;
|
||||||
|
mAnimationRunning = false;
|
||||||
// TODO(b/178353965): well-handle setTransformationMethod.
|
// TODO(b/178353965): well-handle setTransformationMethod.
|
||||||
((TextView) view).setTransformationMethod(transformation);
|
((TextView) view).setTransformationMethod(transformation);
|
||||||
});
|
});
|
||||||
@@ -124,6 +126,7 @@ public class TextViewTranslationCallback implements ViewTranslationCallback {
|
|||||||
(TextView) view,
|
(TextView) view,
|
||||||
() -> {
|
() -> {
|
||||||
mIsShowingTranslation = false;
|
mIsShowingTranslation = false;
|
||||||
|
mAnimationRunning = false;
|
||||||
((TextView) view).setTransformationMethod(transformation);
|
((TextView) view).setTransformationMethod(transformation);
|
||||||
});
|
});
|
||||||
if (!TextUtils.isEmpty(mContentDescription)) {
|
if (!TextUtils.isEmpty(mContentDescription)) {
|
||||||
@@ -162,6 +165,13 @@ public class TextViewTranslationCallback implements ViewTranslationCallback {
|
|||||||
return mIsShowingTranslation;
|
return mIsShowingTranslation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the view is running animation to show or hide the translation.
|
||||||
|
*/
|
||||||
|
public boolean isAnimationRunning() {
|
||||||
|
return mAnimationRunning;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enableContentPadding() {
|
public void enableContentPadding() {
|
||||||
mIsTextPaddingEnabled = true;
|
mIsTextPaddingEnabled = true;
|
||||||
@@ -230,6 +240,7 @@ public class TextViewTranslationCallback implements ViewTranslationCallback {
|
|||||||
mAnimator.end();
|
mAnimator.end();
|
||||||
// Note: mAnimator is now null; do not use again here.
|
// Note: mAnimator is now null; do not use again here.
|
||||||
}
|
}
|
||||||
|
mAnimationRunning = true;
|
||||||
int fadedOutColor = colorWithAlpha(view.getCurrentTextColor(), 0);
|
int fadedOutColor = colorWithAlpha(view.getCurrentTextColor(), 0);
|
||||||
mAnimator = ValueAnimator.ofArgb(view.getCurrentTextColor(), fadedOutColor);
|
mAnimator = ValueAnimator.ofArgb(view.getCurrentTextColor(), fadedOutColor);
|
||||||
mAnimator.addUpdateListener(
|
mAnimator.addUpdateListener(
|
||||||
|
|||||||
Reference in New Issue
Block a user