Merge "Make app-controlled animations more robust" into ub-launcher3-master
diff --git a/quickstep/libs/sysui_shared.jar b/quickstep/libs/sysui_shared.jar
index 18ddeee..85b40d0 100644
--- a/quickstep/libs/sysui_shared.jar
+++ b/quickstep/libs/sysui_shared.jar
Binary files differ
diff --git a/quickstep/src/com/android/launcher3/LauncherAppTransitionManager.java b/quickstep/src/com/android/launcher3/LauncherAppTransitionManager.java
index dd05cfe..05044dd 100644
--- a/quickstep/src/com/android/launcher3/LauncherAppTransitionManager.java
+++ b/quickstep/src/com/android/launcher3/LauncherAppTransitionManager.java
@@ -29,6 +29,7 @@
 import android.graphics.Matrix;
 import android.graphics.Rect;
 import android.os.Bundle;
+import android.util.Log;
 import android.view.Surface;
 import android.view.View;
 import android.view.ViewGroup;
@@ -49,6 +50,7 @@
  */
 public class LauncherAppTransitionManager {
 
+    private static final String TAG = "LauncherTransition";
     private static final int REFRESH_RATE_MS = 16;
 
     private final DragLayer mDragLayer;
@@ -228,6 +230,13 @@
 
             @Override
             public void onAnimationUpdate(ValueAnimator animation) {
+                final Surface surface = getSurface(mFloatingView);
+                final long frameNumber = surface != null ? getNextFrameNumber(surface) : -1;
+                if (frameNumber == -1) {
+                    // Booo, not cool! Our surface got destroyed, so no reason to animate anything.
+                    Log.w(TAG, "Failed to animate, surface got destroyed.");
+                    return;
+                }
                 final float percent = animation.getAnimatedFraction();
                 final float easePercent = Interpolators.AGGRESSIVE_EASE.getInterpolation(percent);
 
@@ -273,9 +282,12 @@
                 for (RemoteAnimationTargetCompat target : targets) {
                     if (target.mode == RemoteAnimationTargetCompat.MODE_OPENING) {
                         t.setAlpha(target.leash, alpha);
+
+                        // TODO: This isn't correct at the beginning of the animation, but better
+                        // than nothing.
+                        matrix.postTranslate(target.position.x, target.position.y);
                         t.setMatrix(target.leash, matrix);
                         t.setWindowCrop(target.leash, crop);
-                        Surface surface = getSurface(mFloatingView);
                         t.deferTransactionUntil(target.leash, surface, getNextFrameNumber(surface));
                     }
                     if (isFirstFrame) {