OSDN Git Service

Always enable HW layers on task views. (Bug 15986310)
authorWinson Chung <winsonc@google.com>
Tue, 22 Jul 2014 23:30:37 +0000 (16:30 -0700)
committerWinson Chung <winsonc@google.com>
Tue, 22 Jul 2014 23:33:06 +0000 (23:33 +0000)
- Use color filter to apply dim to the task view layer
- Fixing bug where you would see a flash of the task view when animating out of Recents.

packages/SystemUI/src/com/android/systemui/recents/views/TaskBarView.java
packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java
packages/SystemUI/src/com/android/systemui/recents/views/TaskStackViewTouchHandler.java
packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java
packages/SystemUI/src/com/android/systemui/recents/views/TaskViewTransform.java

index fbfad5c..fd636ed 100644 (file)
@@ -22,6 +22,7 @@ import android.graphics.Canvas;
 import android.graphics.Paint;
 import android.graphics.PorterDuff;
 import android.graphics.PorterDuffXfermode;
+import android.graphics.drawable.ColorDrawable;
 import android.graphics.drawable.Drawable;
 import android.graphics.drawable.RippleDrawable;
 import android.util.AttributeSet;
@@ -52,7 +53,6 @@ class TaskBarView extends FrameLayout {
 
     boolean mIsFullscreen;
 
-    Paint mLayerPaint = new Paint();
     static Paint sHighlightPaint;
 
     public TaskBarView(Context context) {
@@ -167,7 +167,11 @@ class TaskBarView extends FrameLayout {
             mActivityDescription.setText(t.activityLabel);
         }
         // Try and apply the system ui tint
-        setBackgroundColor(t.colorPrimary);
+        int existingBgColor = (getBackground() instanceof ColorDrawable) ?
+                ((ColorDrawable) getBackground()).getColor() : 0;
+        if (existingBgColor != t.colorPrimary) {
+            setBackgroundColor(t.colorPrimary);
+        }
         mActivityDescription.setTextColor(t.useLightOnPrimaryColor ?
                 mConfig.taskBarViewLightTextColor : mConfig.taskBarViewDarkTextColor);
         mDismissButton.setImageDrawable(t.useLightOnPrimaryColor ?
@@ -252,14 +256,4 @@ class TaskBarView extends FrameLayout {
             mDismissButton.setAlpha(1f);
         }
     }
-
-    /** Enable the hw layers on this task view */
-    void enableHwLayers() {
-        mDismissButton.setLayerType(View.LAYER_TYPE_HARDWARE, mLayerPaint);
-    }
-
-    /** Disable the hw layers on this task view */
-    void disableHwLayers() {
-        mDismissButton.setLayerType(View.LAYER_TYPE_NONE, mLayerPaint);
-    }
 }
index d84a40f..1c8ae31 100644 (file)
@@ -100,13 +100,15 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
     LayoutInflater mInflater;
 
     // A convenience runnable to return all views to the pool
-    // XXX: After this is set, we should mark this task stack view as disabled and check that in synchronize model
     Runnable mReturnAllViewsToPoolRunnable = new Runnable() {
         @Override
         public void run() {
             int childCount = getChildCount();
             for (int i = childCount - 1; i >= 0; i--) {
-                mViewPool.returnViewToPool((TaskView) getChildAt(i));
+                TaskView tv = (TaskView) getChildAt(i);
+                mViewPool.returnViewToPool(tv);
+                // Also hide the view since we don't need it anymore
+                tv.setVisibility(View.INVISIBLE);
             }
         }
     };
@@ -133,33 +135,6 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
                 }
             }
         });
-        mHwLayersTrigger = new ReferenceCountedTrigger(getContext(), new Runnable() {
-            @Override
-            public void run() {
-                // Enable hw layers on each of the children
-                int childCount = getChildCount();
-                for (int i = 0; i < childCount; i++) {
-                    TaskView tv = (TaskView) getChildAt(i);
-                    tv.enableHwLayers();
-                }
-            }
-        }, new Runnable() {
-            @Override
-            public void run() {
-                // Disable hw layers on each of the children
-                int childCount = getChildCount();
-                for (int i = 0; i < childCount; i++) {
-                    TaskView tv = (TaskView) getChildAt(i);
-                    tv.disableHwLayers();
-                }
-            }
-        }, new Runnable() {
-            @Override
-            public void run() {
-                new Throwable("Invalid hw layers ref count").printStackTrace();
-                Console.logError(getContext(), "Invalid HW layers ref count");
-            }
-        });
     }
 
     /** Sets the callbacks */
@@ -435,17 +410,8 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
         int curScroll = getStackScroll();
         int newScroll = Math.max(mMinScroll, Math.min(mMaxScroll, curScroll));
         if (newScroll != curScroll) {
-            // Enable hw layers on the stack
-            addHwLayersRefCount("animateBoundScroll");
-
             // Start a new scroll animation
-            animateScroll(curScroll, newScroll, new Runnable() {
-                @Override
-                public void run() {
-                    // Disable hw layers on the stack
-                    decHwLayersRefCount("animateBoundScroll");
-                }
-            });
+            animateScroll(curScroll, newScroll, null);
         }
         return mScrollAnimator;
     }
@@ -490,8 +456,6 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
         if (!mScroller.isFinished()) {
             // Abort the scroller
             mScroller.abortAnimation();
-            // And disable hw layers on the stack
-            decHwLayersRefCount("flingScroll");
         }
     }
 
@@ -615,17 +579,6 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
         focusTask(mFocusedTaskIndex, true);
     }
 
-    /** Enables the hw layers and increments the hw layer requirement ref count */
-    void addHwLayersRefCount(String reason) {
-        mHwLayersTrigger.increment();
-    }
-
-    /** Decrements the hw layer requirement ref count and disables the hw layers when we don't
-        need them anymore. */
-    void decHwLayersRefCount(String reason) {
-        mHwLayersTrigger.decrement();
-    }
-
     @Override
     public boolean onInterceptTouchEvent(MotionEvent ev) {
         return mTouchHandler.onInterceptTouchEvent(ev);
@@ -641,11 +594,6 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
         if (mScroller.computeScrollOffset()) {
             setStackScroll(mScroller.getCurrY());
             invalidate();
-
-            // If we just finished scrolling, then disable the hw layers
-            if (mScroller.isFinished()) {
-                decHwLayersRefCount("finishedFlingScroll");
-            }
         }
     }
 
@@ -969,9 +917,6 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
         // Detach the view from the hierarchy
         detachViewFromParent(tv);
 
-        // Disable HW layers
-        tv.disableHwLayers();
-
         // Reset the view properties
         tv.resetViewProperties();
     }
@@ -1015,11 +960,6 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
         } else {
             attachViewToParent(tv, insertIndex, tv.getLayoutParams());
         }
-
-        // Enable hw layers on this view if hw layers are enabled on the stack
-        if (mHwLayersTrigger.getCount() > 0) {
-            tv.enableHwLayers();
-        }
     }
 
     @Override
index 191dc37..b83f9cc 100644 (file)
@@ -148,8 +148,6 @@ class TaskStackViewTouchHandler implements SwipeHelper.Callback {
                     if (parent != null) {
                         parent.requestDisallowInterceptTouchEvent(true);
                     }
-                    // Enable HW layers
-                    mSv.addHwLayersRefCount("stackScroll");
                 }
 
                 mLastMotionX = x;
@@ -160,10 +158,6 @@ class TaskStackViewTouchHandler implements SwipeHelper.Callback {
             case MotionEvent.ACTION_UP: {
                 // Animate the scroll back if we've cancelled
                 mSv.animateBoundScroll();
-                // Disable HW layers
-                if (mIsScrolling) {
-                    mSv.decHwLayersRefCount("stackScroll");
-                }
                 // Reset the drag state and the velocity tracker
                 mIsScrolling = false;
                 mActivePointerId = INACTIVE_POINTER_ID;
@@ -241,8 +235,6 @@ class TaskStackViewTouchHandler implements SwipeHelper.Callback {
                         if (parent != null) {
                             parent.requestDisallowInterceptTouchEvent(true);
                         }
-                        // Enable HW layers
-                        mSv.addHwLayersRefCount("stackScroll");
                     }
                 }
                 if (mIsScrolling) {
@@ -271,8 +263,6 @@ class TaskStackViewTouchHandler implements SwipeHelper.Callback {
                 int velocity = (int) velocityTracker.getYVelocity(mActivePointerId);
 
                 if (mIsScrolling && (Math.abs(velocity) > mMinimumVelocity)) {
-                    // Enable HW layers on the stack
-                    mSv.addHwLayersRefCount("flingScroll");
                     // XXX: Make this animation a function of the velocity AND distance
                     int overscrollRange = (int) (Math.min(1f,
                             Math.abs((float) velocity / mMaximumVelocity)) *
@@ -291,10 +281,6 @@ class TaskStackViewTouchHandler implements SwipeHelper.Callback {
                     mSv.animateBoundScroll();
                 }
 
-                if (mIsScrolling) {
-                    // Disable HW layers
-                    mSv.decHwLayersRefCount("stackScroll");
-                }
                 mActivePointerId = INACTIVE_POINTER_ID;
                 mIsScrolling = false;
                 mTotalScrollMotion = 0;
@@ -315,10 +301,6 @@ class TaskStackViewTouchHandler implements SwipeHelper.Callback {
                 break;
             }
             case MotionEvent.ACTION_CANCEL: {
-                if (mIsScrolling) {
-                    // Disable HW layers
-                    mSv.decHwLayersRefCount("stackScroll");
-                }
                 if (mSv.isScrollOutOfBounds()) {
                     // Animate the scroll back into bounds
                     // XXX: Make this animation a function of the velocity OR distance
@@ -351,8 +333,6 @@ class TaskStackViewTouchHandler implements SwipeHelper.Callback {
         TaskView tv = (TaskView) v;
         // Disable clipping with the stack while we are swiping
         tv.setClipViewInStack(false);
-        // Enable HW layers on that task
-        tv.enableHwLayers();
         // Disallow touch events from this task view
         tv.setTouchEnabled(false);
         // Hide the footer
@@ -372,10 +352,6 @@ class TaskStackViewTouchHandler implements SwipeHelper.Callback {
     @Override
     public void onChildDismissed(View v) {
         TaskView tv = (TaskView) v;
-        // Disable HW layers on that task
-        if (mSv.mHwLayersTrigger.getCount() == 0) {
-            tv.disableHwLayers();
-        }
         // Re-enable clipping with the stack (we will reuse this view)
         tv.setClipViewInStack(true);
         // Re-enable touch events from this task view
@@ -387,10 +363,6 @@ class TaskStackViewTouchHandler implements SwipeHelper.Callback {
     @Override
     public void onSnapBackCompleted(View v) {
         TaskView tv = (TaskView) v;
-        // Disable HW layers on that task
-        if (mSv.mHwLayersTrigger.getCount() == 0) {
-            tv.disableHwLayers();
-        }
         // Re-enable clipping with the stack
         tv.setClipViewInStack(true);
         // Re-enable touch events from this task view
index d1b33f3..259706b 100644 (file)
@@ -22,7 +22,10 @@ import android.animation.ObjectAnimator;
 import android.animation.ValueAnimator;
 import android.content.Context;
 import android.graphics.Canvas;
+import android.graphics.Color;
 import android.graphics.Paint;
+import android.graphics.PorterDuff;
+import android.graphics.PorterDuffColorFilter;
 import android.graphics.Rect;
 import android.util.AttributeSet;
 import android.view.View;
@@ -34,8 +37,6 @@ import com.android.systemui.recents.Constants;
 import com.android.systemui.recents.RecentsConfiguration;
 import com.android.systemui.recents.model.Task;
 
-// XXX: In debug mode, we should override invalidate() and check the layout type (do this in TaskStackView as well)
-
 /* A task view */
 public class TaskView extends FrameLayout implements Task.TaskCallbacks,
         TaskFooterView.TaskFooterViewCallbacks, View.OnClickListener, View.OnLongClickListener {
@@ -53,6 +54,7 @@ public class TaskView extends FrameLayout implements Task.TaskCallbacks,
     int mDim;
     int mMaxDim;
     AccelerateInterpolator mDimInterpolator = new AccelerateInterpolator();
+    PorterDuffColorFilter mDimColorFilter = new PorterDuffColorFilter(0, PorterDuff.Mode.MULTIPLY);
 
     Task mTask;
     boolean mTaskDataLoaded;
@@ -96,9 +98,8 @@ public class TaskView extends FrameLayout implements Task.TaskCallbacks,
         mMaxDim = mConfig.taskStackMaxDim;
         mClipViewInStack = true;
         mViewBounds = new AnimateableViewBounds(this, mConfig.taskViewRoundedCornerRadiusPx);
-        setWillNotDraw(false);
-        setDim(getDim());
         setOutlineProvider(mViewBounds);
+        setDim(getDim());
     }
 
     /** Set callback */
@@ -164,7 +165,7 @@ public class TaskView extends FrameLayout implements Task.TaskCallbacks,
         }
 
         // Apply the transform
-        toTransform.applyToTaskView(this, duration, mConfig.fastOutSlowInInterpolator,
+        toTransform.applyToTaskView(this, duration, mConfig.fastOutSlowInInterpolator, false,
                 mUpdateDimListener);
     }
 
@@ -262,7 +263,6 @@ public class TaskView extends FrameLayout implements Task.TaskCallbacks,
                                 AlternateRecentsComponent.consumeLastScreenshot();
                             }
                         })
-                        .withLayer()
                         .start();
             } else {
                 // Otherwise, just enable the thumbnail clip
@@ -316,7 +316,6 @@ public class TaskView extends FrameLayout implements Task.TaskCallbacks,
                     .setUpdateListener(null)
                     .setInterpolator(mConfig.quintOutInterpolator)
                     .setDuration(mConfig.taskViewEnterFromHomeDuration)
-                    .withLayer()
                     .withEndAction(new Runnable() {
                         @Override
                         public void run() {
@@ -348,7 +347,6 @@ public class TaskView extends FrameLayout implements Task.TaskCallbacks,
                 .setUpdateListener(null)
                 .setInterpolator(mConfig.fastOutLinearInInterpolator)
                 .setDuration(mConfig.taskViewExitToHomeDuration)
-                .withLayer()
                 .withEndAction(ctx.postAnimationTrigger.decrementAsRunnable())
                 .start();
         ctx.postAnimationTrigger.increment();
@@ -384,7 +382,6 @@ public class TaskView extends FrameLayout implements Task.TaskCallbacks,
             .setUpdateListener(null)
             .setInterpolator(mConfig.fastOutSlowInInterpolator)
             .setDuration(mConfig.taskViewRemoveAnimDuration)
-            .withLayer()
             .withEndAction(new Runnable() {
                 @Override
                 public void run() {
@@ -466,7 +463,10 @@ public class TaskView extends FrameLayout implements Task.TaskCallbacks,
     /** Returns the current dim. */
     public void setDim(int dim) {
         mDim = dim;
-        postInvalidateOnAnimation();
+        int inverse = 255 - mDim;
+        mDimColorFilter.setColor(Color.argb(0xFF, inverse, inverse, inverse));
+        mLayerPaint.setColorFilter(mDimColorFilter);
+        setLayerType(LAYER_TYPE_HARDWARE, mLayerPaint);
     }
 
     /** Returns the current dim. */
@@ -491,16 +491,6 @@ public class TaskView extends FrameLayout implements Task.TaskCallbacks,
     /**** View drawing ****/
 
     @Override
-    public void draw(Canvas canvas) {
-        super.draw(canvas);
-
-        // Apply the dim if necessary
-        if (mDim > 0) {
-            canvas.drawColor(mDim << 24);
-        }
-    }
-
-    @Override
     protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
         if (mIsStub && (child != mBarView)) {
             // Skip the thumbnail view if we are in stub mode
@@ -509,20 +499,6 @@ public class TaskView extends FrameLayout implements Task.TaskCallbacks,
         return super.drawChild(canvas, child, drawingTime);
     }
 
-    /** Enable the hw layers on this task view */
-    void enableHwLayers() {
-        mThumbnailView.setLayerType(View.LAYER_TYPE_HARDWARE, mLayerPaint);
-        mBarView.enableHwLayers();
-        mFooterView.setLayerType(View.LAYER_TYPE_HARDWARE, mLayerPaint);
-    }
-
-    /** Disable the hw layers on this task view */
-    void disableHwLayers() {
-        mThumbnailView.setLayerType(View.LAYER_TYPE_NONE, mLayerPaint);
-        mBarView.disableHwLayers();
-        mFooterView.setLayerType(View.LAYER_TYPE_NONE, mLayerPaint);
-    }
-
     /**** View focus state ****/
 
     /**
@@ -640,7 +616,7 @@ public class TaskView extends FrameLayout implements Task.TaskCallbacks,
     /**** View.OnClickListener Implementation ****/
 
     @Override
-    public void onClick(final View v) {
+     public void onClick(final View v) {
         // We purposely post the handler delayed to allow for the touch feedback to draw
         final TaskView tv = this;
         postDelayed(new Runnable() {
index d583c20..aeb4fe4 100644 (file)
@@ -83,12 +83,12 @@ public class TaskViewTransform {
     }
 
     /** Applies this transform to a view. */
-    public void applyToTaskView(View v, int duration, Interpolator interp,
+    public void applyToTaskView(View v, int duration, Interpolator interp, boolean allowLayers,
                                 ValueAnimator.AnimatorUpdateListener scaleUpdateListener) {
         // Check to see if any properties have changed, and update the task view
         if (duration > 0) {
             ViewPropertyAnimator anim = v.animate();
-            boolean useLayers = false;
+            boolean requiresLayers = false;
 
             // Animate to the final state
             if (hasTranslationYChangedFrom(v.getTranslationY())) {
@@ -102,14 +102,14 @@ public class TaskViewTransform {
                 anim.scaleX(scale)
                     .scaleY(scale)
                     .setUpdateListener(scaleUpdateListener);
-                useLayers = true;
+                requiresLayers = true;
             }
             if (hasAlphaChangedFrom(v.getAlpha())) {
                 // Use layers if we animate alpha
                 anim.alpha(alpha);
-                useLayers = true;
+                requiresLayers = true;
             }
-            if (useLayers) {
+            if (requiresLayers && allowLayers) {
                 anim.withLayer();
             }
             anim.setStartDelay(startDelay)
@@ -146,7 +146,6 @@ public class TaskViewTransform {
         v.setScaleX(1f);
         v.setScaleY(1f);
         v.setAlpha(1f);
-        v.invalidate();
     }
 
     @Override