Fix for blue screen of death
The AnimatorSet can get interrupted and stop running if the activity
is paused. Make sure to cancel it to reset the views to their correct
state in onResume
Bug: 17260258
Change-Id: I7067892fe85db5d137554614c3092e6bb7787abd
diff --git a/InCallUI/src/com/android/incallui/CallCardFragment.java b/InCallUI/src/com/android/incallui/CallCardFragment.java
index 600689c..8ae01e2 100644
--- a/InCallUI/src/com/android/incallui/CallCardFragment.java
+++ b/InCallUI/src/com/android/incallui/CallCardFragment.java
@@ -33,6 +33,7 @@
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
+import android.view.View.OnLayoutChangeListener;
import android.view.ViewAnimationUtils;
import android.view.ViewGroup;
import android.view.ViewPropertyAnimator;
@@ -56,6 +57,7 @@
public class CallCardFragment extends BaseFragment<CallCardPresenter, CallCardPresenter.CallCardUi>
implements CallCardPresenter.CallCardUi {
+ private AnimatorSet mAnimatorSet;
private int mRevealAnimationDuration;
private int mShrinkAnimationDuration;
private int mFabNormalDiameter;
@@ -912,22 +914,15 @@
final Animator shrinkAnimator =
getShrinkAnimator(parent.getHeight(), originalHeight);
- final AnimatorSet set = new AnimatorSet();
- set.playSequentially(revealAnimator, shrinkAnimator);
- set.addListener(new AnimatorListenerAdapter() {
- @Override
- public void onAnimationCancel(Animator animation) {
- mPrimaryCallCardContainer.removeOnLayoutChangeListener(listener);
- mFloatingActionButtonController.scaleIn();
- }
-
+ mAnimatorSet = new AnimatorSet();
+ mAnimatorSet.playSequentially(revealAnimator, shrinkAnimator);
+ mAnimatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
- mPrimaryCallCardContainer.removeOnLayoutChangeListener(listener);
- mFloatingActionButtonController.scaleIn();
+ setViewStatePostAnimation(listener);
}
});
- set.start();
+ mAnimatorSet.start();
}
});
}
@@ -954,6 +949,16 @@
mIsDialpadShowing ? mFabSmallDiameter : mFabNormalDiameter, true);
}
+ @Override
+ public void onResume() {
+ super.onResume();
+ // If the previous launch animation is still running, cancel it so that we don't get
+ // stuck in an intermediate animation state.
+ if (mAnimatorSet != null && mAnimatorSet.isRunning()) {
+ mAnimatorSet.cancel();
+ }
+ }
+
/**
* Adds a global layout listener to update the FAB's positioning on the next layout. This allows
* us to position the FAB after the secondary call info's height has been calculated.
@@ -1027,6 +1032,23 @@
.setDuration(mShrinkAnimationDuration).setInterpolator(AnimUtils.EASE_IN);
}
+ private void setViewStatePostAnimation(View view) {
+ view.setTranslationY(0);
+ view.setAlpha(1);
+ }
+
+ private void setViewStatePostAnimation(OnLayoutChangeListener layoutChangeListener) {
+ setViewStatePostAnimation(mCallButtonsContainer);
+ setViewStatePostAnimation(mCallStateLabel);
+ setViewStatePostAnimation(mPrimaryName);
+ setViewStatePostAnimation(mCallTypeLabel);
+ setViewStatePostAnimation(mCallNumberAndLabel);
+ setViewStatePostAnimation(mCallStateIcon);
+
+ mPrimaryCallCardContainer.removeOnLayoutChangeListener(layoutChangeListener);
+ mFloatingActionButtonController.scaleIn();
+ }
+
private final class LayoutIgnoringListener implements View.OnLayoutChangeListener {
@Override
public void onLayoutChange(View v,