Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5a9b0b0c authored by Winson Chung's avatar Winson Chung
Browse files

Enabling clipping on task views.

Change-Id: I2a4b8fe06ae379364081534bd5b02f52b27e4ff2
parent 193909da
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ public class Constants {
            // Enables the filtering of tasks according to their grouping
            public static final boolean EnableTaskFiltering = false;
            // Enables clipping of tasks against each other
            public static final boolean EnableTaskStackClipping = false;
            public static final boolean EnableTaskStackClipping = true;
            // Enables the use of theme colors as the task bar background
            public static final boolean EnableTaskBarThemeColors = true;
            // Enables app-info pane on long-pressing the icon
+29 −8
Original line number Diff line number Diff line
@@ -592,18 +592,27 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
    @Override
    protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
        if (Constants.DebugFlags.App.EnableTaskStackClipping) {
            RecentsConfiguration config = RecentsConfiguration.getInstance();
            TaskView tv = (TaskView) child;
            TaskView nextTv = null;
            TaskView tmpTv = null;
            if (tv.shouldClipViewInStack()) {
                int curIndex = indexOfChild(tv);
            if ((curIndex > -1) && (curIndex < (getChildCount() - 1))) {

                // Find the next view to clip against
                while (nextTv == null && curIndex < getChildCount()) {
                    tmpTv = (TaskView) getChildAt(++curIndex);
                    if (tmpTv != null && tmpTv.shouldClipViewInStack()) {
                        nextTv = tmpTv;
                    }
                }

                // Clip against the next view (if we aren't animating its alpha)
                nextTv = (TaskView) getChildAt(curIndex + 1);
                if (nextTv.getAlpha() == 1f) {
                if (nextTv != null && nextTv.getAlpha() == 1f) {
                    Rect curRect = tv.getClippingRect(mTmpRect);
                    Rect nextRect = nextTv.getClippingRect(mTmpRect2);
                    RecentsConfiguration config = RecentsConfiguration.getInstance();
                    // The hit rects are relative to the task view, which needs to be offset by the
                    // system bar height
                    // The hit rects are relative to the task view, which needs to be offset by
                    // the system bar height
                    curRect.offset(0, config.systemInsets.top);
                    nextRect.offset(0, config.systemInsets.top);
                    // Compute the clip region
@@ -1048,6 +1057,10 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
            }
        }

        // Sanity check, the task view should always be clipping against the stack at this point,
        // but just in case, re-enable it here
        tv.setClipViewInStack(true);

        // Add/attach the view to the hierarchy
        if (Console.Enabled) {
            Console.log(Constants.Log.ViewPool.PoolCallbacks, "  [TaskStackView|insertIndex]",
@@ -1500,6 +1513,9 @@ class TaskStackViewTouchHandler implements SwipeHelper.Callback {
    public void onBeginDrag(View v) {
        // Enable HW layers
        mSv.addHwLayersRefCount("swipeBegin");
        // Disable clipping with the stack while we are swiping
        TaskView tv = (TaskView) v;
        tv.setClipViewInStack(false);
        // Disallow parents from intercepting touch events
        final ViewParent parent = mSv.getParent();
        if (parent != null) {
@@ -1512,13 +1528,18 @@ class TaskStackViewTouchHandler implements SwipeHelper.Callback {
        TaskView tv = (TaskView) v;
        mSv.onTaskDismissed(tv);

        // Re-enable clipping with the stack (we will reuse this view)
        tv.setClipViewInStack(true);

        // Disable HW layers
        mSv.decHwLayersRefCount("swipeComplete");
    }

    @Override
    public void onSnapBackCompleted(View v) {
        // Do Nothing
        // Re-enable clipping with the stack
        TaskView tv = (TaskView) v;
        tv.setClipViewInStack(true);
    }

    @Override
+30 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ public class TaskView extends FrameLayout implements Task.TaskCallbacks, View.On
    Task mTask;
    boolean mTaskDataLoaded;
    boolean mIsFocused;
    boolean mClipViewInStack;
    Point mLastTouchDown = new Point();
    Path mRoundedRectClipPath = new Path();

@@ -87,6 +88,9 @@ public class TaskView extends FrameLayout implements Task.TaskCallbacks, View.On
        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 @@ public class TaskView extends FrameLayout implements Task.TaskCallbacks, View.On

    /** 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 @@ public class TaskView extends FrameLayout implements Task.TaskCallbacks, View.On
                @Override
                public void run() {
                    post(r);

                    // Re-enable clipping with the stack (we will reuse this view)
                    setClipViewInStack(false);
                }
            })
            .start();
@@ -285,6 +295,26 @@ public class TaskView extends FrameLayout implements Task.TaskCallbacks, View.On
        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;