Enabling clipping on task views.

Change-Id: I2a4b8fe06ae379364081534bd5b02f52b27e4ff2
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 16a3f45..b423a3c 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java
@@ -57,6 +57,7 @@
     Task mTask;
     boolean mTaskDataLoaded;
     boolean mIsFocused;
+    boolean mClipViewInStack;
     Point mLastTouchDown = new Point();
     Path mRoundedRectClipPath = new Path();
 
@@ -87,6 +88,9 @@
         RecentsConfiguration config = RecentsConfiguration.getInstance();
         mMaxDim = config.taskStackMaxDim;
 
+        // By default, all views are clipped to other views in their stack
+        mClipViewInStack = true;
+
         // Bind the views
         mThumbnailView = (TaskThumbnailView) findViewById(R.id.task_view_thumbnail);
         mBarView = (TaskBarView) findViewById(R.id.task_view_bar);
@@ -250,6 +254,9 @@
 
     /** Animates the deletion of this task view */
     public void animateRemoval(final Runnable r) {
+        // Disabling clipping with the stack while the view is animating away
+        setClipViewInStack(false);
+
         RecentsConfiguration config = RecentsConfiguration.getInstance();
         animate().translationX(config.taskViewRemoveAnimTranslationXPx)
             .alpha(0f)
@@ -261,6 +268,9 @@
                 @Override
                 public void run() {
                     post(r);
+
+                    // Re-enable clipping with the stack (we will reuse this view)
+                    setClipViewInStack(false);
                 }
             })
             .start();
@@ -285,6 +295,26 @@
         mThumbnailView.setLayerType(View.LAYER_TYPE_NONE, null);
     }
 
+    /**
+     * Returns whether this view should be clipped, or any views below should clip against this
+     * view.
+     */
+    boolean shouldClipViewInStack() {
+        return mClipViewInStack;
+    }
+
+    /** Sets whether this view should be clipped, or clipped against. */
+    void setClipViewInStack(boolean clip) {
+        if (clip != mClipViewInStack) {
+            mClipViewInStack = clip;
+            if (getParent() instanceof View) {
+                Rect r = new Rect();
+                getHitRect(r);
+                ((View) getParent()).invalidate(r);
+            }
+        }
+    }
+
     /** Update the dim as a function of the scale of this view. */
     void updateDimOverlayFromScale() {
         float minScale = Constants.Values.TaskStackView.StackPeekMinScale;