Fixing random crash when transitioning to Recents, ensuring we don't update the TextView unnecessarily.

Change-Id: I93ab512642f6e95ee96e041614f063f46420bb39
diff --git a/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java b/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java
index c729432..0c28488 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java
@@ -292,20 +292,21 @@
         if (firstThumbnail != null) {
             // Update the destination rect
             Rect toTaskRect = getThumbnailTransitionRect(topTask.id);
-
-            // Create the new thumbnail for the animation down
-            // XXX: We should find a way to optimize this so we don't need to create a new bitmap
-            Bitmap thumbnail = Bitmap.createBitmap(toTaskRect.width(), toTaskRect.height(),
-                    Bitmap.Config.ARGB_8888);
-            int size = Math.min(firstThumbnail.getWidth(), firstThumbnail.getHeight());
-            Canvas c = new Canvas(thumbnail);
-            c.drawBitmap(firstThumbnail, new Rect(0, 0, size, size),
-                    new Rect(0, 0, toTaskRect.width(), toTaskRect.height()), null);
-            c.setBitmap(null);
-            // Recycle the old thumbnail
-            firstThumbnail.recycle();
-            return ActivityOptions.makeThumbnailScaleDownAnimation(mStatusBarView,
-                    thumbnail, toTaskRect.left, toTaskRect.top, this);
+            if (toTaskRect.width() > 0 && toTaskRect.height() > 0) {
+                // Create the new thumbnail for the animation down
+                // XXX: We should find a way to optimize this so we don't need to create a new bitmap
+                Bitmap thumbnail = Bitmap.createBitmap(toTaskRect.width(), toTaskRect.height(),
+                        Bitmap.Config.ARGB_8888);
+                int size = Math.min(firstThumbnail.getWidth(), firstThumbnail.getHeight());
+                Canvas c = new Canvas(thumbnail);
+                c.drawBitmap(firstThumbnail, new Rect(0, 0, size, size),
+                        new Rect(0, 0, toTaskRect.width(), toTaskRect.height()), null);
+                c.setBitmap(null);
+                // Recycle the old thumbnail
+                firstThumbnail.recycle();
+                return ActivityOptions.makeThumbnailScaleDownAnimation(mStatusBarView,
+                        thumbnail, toTaskRect.left, toTaskRect.top, this);
+            }
         }
 
         // If both the screenshot and thumbnail fails, then just fall back to the default transition
diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskBarView.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskBarView.java
index 4ed3b59..db84962 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskBarView.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskBarView.java
@@ -157,7 +157,9 @@
         } else if (t.applicationIcon != null) {
             mApplicationIcon.setImageDrawable(t.applicationIcon);
         }
-        mActivityDescription.setText(t.activityLabel);
+        if (!mActivityDescription.getText().toString().equals(t.activityLabel)) {
+            mActivityDescription.setText(t.activityLabel);
+        }
         // Try and apply the system ui tint
         setBackgroundColor(t.colorPrimary);
         mActivityDescription.setTextColor(Utilities.getIdealColorForBackgroundColorGreyscale(
@@ -171,7 +173,6 @@
     void unbindFromTask() {
         mTask = null;
         mApplicationIcon.setImageDrawable(null);
-        mActivityDescription.setText("");
     }
 
     /** Prepares this task view for the enter-recents animations.  This is called earlier in the
diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java
index 61101b1..f38c637 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java
@@ -372,7 +372,7 @@
     /** Computes the initial stack scroll for the stack. */
     int getInitialStackScroll() {
         if (mStack.getTaskCount() > 2) {
-            return mMaxScroll - mStackAlgorithm.mTaskRect.height() / 2;
+            return mMaxScroll - (int) (mStackAlgorithm.mTaskRect.height() * (3f/4f));
         }
         return mMaxScroll;
     }
diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java
index 8f4f235..1ba0560 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java
@@ -535,6 +535,15 @@
         }
     }
 
+    @Override
+    protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
+        if (mIsStub && (child == mThumbnailView)) {
+            // Skip the thumbnail view if we are in stub mode
+            return false;
+        }
+        return super.drawChild(canvas, child, drawingTime);
+    }
+
     /**
      * Sets the focused task explicitly. We need a separate flag because requestFocus() won't happen
      * if the view is not currently visible, or we are in touch state (where we still want to keep