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

Commit a78a8f31 authored by Winson's avatar Winson
Browse files

Freeform workspace fixes

- Fixing issue with the wrong task view index being calculated for
  freeform workspace tasks causing them to be invisible when dragged
  to the stack
- Reducing unnecessary detach/reattach calls for freeform tasks
- Adding freeform workspace background to match exit to home animation

Change-Id: I8c00aba377601da92195ef301ba5da1ffb0045c5
parent 40149bfe
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -115,7 +115,6 @@ public class SystemServicesProxy {

    /** Private constructor */
    public SystemServicesProxy(Context context) {
        RecentsDebugFlags flags = Recents.getDebugFlags();
        mAccm = AccessibilityManager.getInstance(context);
        mAm = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        mIam = ActivityManagerNative.getDefault();
+16 −8
Original line number Diff line number Diff line
@@ -118,18 +118,21 @@ public class TaskStackLayoutAlgorithm {
     */
    public static class StackState {

        public static final StackState FREEFORM_ONLY = new StackState(1f);
        public static final StackState STACK_ONLY = new StackState(0f);
        public static final StackState SPLIT = new StackState(0.5f);
        public static final StackState FREEFORM_ONLY = new StackState(1f, 0);
        public static final StackState STACK_ONLY = new StackState(0f, 0);
        public static final StackState SPLIT = new StackState(0.5f, 255);

        public final float freeformHeightPct;
        public final int freeformBackgroundAlpha;

        /**
         * @param freeformHeightPct the percentage of the stack height (not including paddings) to
         *                          allocate to the freeform workspace
         * @param freeformBackgroundAlpha the background alpha for the freeform workspace
         */
        StackState(float freeformHeightPct) {
        StackState(float freeformHeightPct, int freeformBackgroundAlpha) {
            this.freeformHeightPct = freeformHeightPct;
            this.freeformBackgroundAlpha = freeformBackgroundAlpha;
        }

        /**
@@ -278,7 +281,6 @@ public class TaskStackLayoutAlgorithm {
    FreeformWorkspaceLayoutAlgorithm mFreeformLayoutAlgorithm;

    public TaskStackLayoutAlgorithm(Context context, TaskStackView stackView) {
        SystemServicesProxy ssp = Recents.getSystemServices();
        Resources res = context.getResources();
        mStackView = stackView;

@@ -309,9 +311,6 @@ public class TaskStackLayoutAlgorithm {
     */
    public void setSystemInsets(Rect systemInsets) {
        mSystemInsets.set(systemInsets);
        if (DEBUG) {
            Log.d(TAG, "setSystemInsets: " + systemInsets);
        }
    }

    /**
@@ -343,6 +342,7 @@ public class TaskStackLayoutAlgorithm {

        // The freeform height is the visible height (not including system insets) - padding above
        // freeform and below stack - gap between the freeform and stack
        mState = state;
        mStackTopOffset = mFocusedPeekHeight + heightPadding;
        mStackBottomOffset = mSystemInsets.bottom + heightPadding;
        state.computeRects(mFreeformRect, mStackRect, taskStackBounds, widthPadding, heightPadding,
@@ -513,6 +513,14 @@ public class TaskStackLayoutAlgorithm {
        return stackScroll + max;
    }

    /**
     *
     * Returns the current stack state.
     */
    public StackState getStackState() {
        return mState;
    }

    /**
     * Computes the maximum number of visible tasks and thumbnails when the scroll is at the initial
     * stack scroll.  Requires that update() is called first.
+88 −25
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.recents.views;

import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.ComponentName;
import android.content.Context;
@@ -23,8 +24,11 @@ import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.IntProperty;
import android.util.Log;
import android.util.Property;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@@ -90,6 +94,19 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
    private static final float SHOW_HISTORY_BUTTON_SCROLL_THRESHOLD = 0.3f;
    private static final float HIDE_HISTORY_BUTTON_SCROLL_THRESHOLD = 0.3f;

    public static final Property<ColorDrawable, Integer> COLOR_DRAWABLE_ALPHA =
            new IntProperty<ColorDrawable>("colorDrawableAlpha") {
                @Override
                public void setValue(ColorDrawable object, int alpha) {
                    object.setAlpha(alpha);
                }

                @Override
                public Integer get(ColorDrawable object) {
                    return object.getAlpha();
                }
            };

    /** The TaskView callbacks */
    interface TaskStackViewCallbacks {
        public void onTaskViewClicked(TaskStackView stackView, TaskView tv, TaskStack stack, Task t,
@@ -102,6 +119,7 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
    TaskStackViewTouchHandler mTouchHandler;
    TaskStackViewCallbacks mCb;
    ColorDrawable mFreeformWorkspaceBackground;
    ObjectAnimator mFreeformWorkspaceBackgroundAnimator;
    ViewPool<TaskView, Task> mViewPool;
    ArrayList<TaskViewTransform> mCurrentTaskTransforms = new ArrayList<>();
    DozeTrigger mUIDozeTrigger;
@@ -119,7 +137,6 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
    int[] mTmpVisibleRange = new int[2];
    Rect mTmpRect = new Rect();
    RectF mTmpTaskRect = new RectF();
    TaskViewTransform mTmpTransform = new TaskViewTransform();
    TaskViewTransform mTmpStackBackTransform = new TaskViewTransform();
    TaskViewTransform mTmpStackFrontTransform = new TaskViewTransform();
    HashMap<Task, TaskView> mTmpTaskViewMap = new HashMap<>();
@@ -185,6 +202,7 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
        setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);

        mFreeformWorkspaceBackground = new ColorDrawable(0x33000000);
        mFreeformWorkspaceBackground.setCallback(this);
    }

    /** Sets the callbacks */
@@ -463,20 +481,13 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
                    tv = mViewPool.pickUpViewFromPool(task, task);
                } else {
                    // Reattach it in the right z order
                    detachViewFromParent(tv);
                    int insertIndex = -1;
                    int taskIndex = mStack.indexOfStackTask(task);
                    taskViews = getTaskViews();
                    taskViewCount = taskViews.size();
                    for (int j = 0; j < taskViewCount; j++) {
                        Task tvTask = taskViews.get(j).getTask();
                        if (taskIndex <= mStack.indexOfStackTask(tvTask)) {
                            insertIndex = j;
                            break;
                        }
                    }
                    int insertIndex = findTaskViewInsertIndex(task, taskIndex);
                    if (insertIndex != getTaskViews().indexOf(tv)){
                        detachViewFromParent(tv);
                        attachViewToParent(tv, insertIndex, tv.getLayoutParams());
                    }
                }

                // Animate the task into place
                tv.updateViewPropertiesToTaskTransform(transform, transform.clipBottom,
@@ -606,7 +617,6 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
        SystemServicesProxy ssp = Recents.getSystemServices();
        if (ssp.hasFreeformWorkspaceSupport()) {
            mTmpRect.set(mLayoutAlgorithm.mFreeformRect);
            mFreeformWorkspaceBackground.setAlpha(255);
            mFreeformWorkspaceBackground.setBounds(mTmpRect);
        }

@@ -1021,6 +1031,11 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
            mStartEnterAnimationContext = null;
        }

        // Animate in the freeform workspace
        animateFreeformWorkspaceBackgroundAlpha(
                mLayoutAlgorithm.getStackState().freeformBackgroundAlpha, 150,
                mFastOutSlowInInterpolator);

        // Set the task focused state without requesting view focus, and leave the focus animations
        // until after the enter-animation
        RecentsConfiguration config = Recents.getConfiguration();
@@ -1100,6 +1115,11 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
        mStackScroller.stopBoundScrollAnimation();
        // Animate all the task views out of view
        ctx.offscreenTranslationY = mLayoutAlgorithm.mStackRect.bottom;
        // Dismiss the freeform workspace background
        int taskViewExitToHomeDuration = getResources().getInteger(
                R.integer.recents_task_exit_to_home_duration);
        animateFreeformWorkspaceBackgroundAlpha(0, taskViewExitToHomeDuration,
                mFastOutSlowInInterpolator);

        List<TaskView> taskViews = getTaskViews();
        int taskViewCount = taskViews.size();
@@ -1151,6 +1171,14 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
        super.dispatchDraw(canvas);
    }

    @Override
    protected boolean verifyDrawable(Drawable who) {
        if (who == mFreeformWorkspaceBackground) {
            return true;
        }
        return super.verifyDrawable(who);
    }

    /**
     * Launches the freeform tasks.
     */
@@ -1297,19 +1325,8 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
        tv.setNoUserInteractionState();

        // Find the index where this task should be placed in the stack
        int insertIndex = -1;
        int taskIndex = mStack.indexOfStackTask(task);
        if (taskIndex != -1) {
            List<TaskView> taskViews = getTaskViews();
            int taskViewCount = taskViews.size();
            for (int i = 0; i < taskViewCount; i++) {
                Task tvTask = taskViews.get(i).getTask();
                if (taskIndex < mStack.indexOfStackTask(tvTask)) {
                    insertIndex = i;
                    break;
                }
            }
        }
        int insertIndex = findTaskViewInsertIndex(task, taskIndex);

        // Add/attach the view to the hierarchy
        if (isNewView) {
@@ -1558,4 +1575,50 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
        // Remove the task from the stack
        mStack.removeTask(task);
    }

    /**
     * Starts an alpha animation on the freeform workspace background.
     */
    private void animateFreeformWorkspaceBackgroundAlpha(int targetAlpha, int duration,
            Interpolator interpolator) {
        if (mFreeformWorkspaceBackground.getAlpha() == targetAlpha) {
            return;
        }

        Utilities.cancelAnimationWithoutCallbacks(mFreeformWorkspaceBackgroundAnimator);
        mFreeformWorkspaceBackgroundAnimator = ObjectAnimator.ofInt(mFreeformWorkspaceBackground,
                COLOR_DRAWABLE_ALPHA, mFreeformWorkspaceBackground.getAlpha(), targetAlpha);
        mFreeformWorkspaceBackgroundAnimator.setDuration(duration);
        mFreeformWorkspaceBackgroundAnimator.setInterpolator(interpolator);
        mFreeformWorkspaceBackgroundAnimator.start();
    }

    /**
     * Returns the insert index for the task in the current set of task views.  If the given task
     * is already in the task view list, then this method returns the insert index assuming it
     * is first removed at the previous index.
     *
     * @param task the task we are finding the index for
     * @param taskIndex the index of the task in the stack
     */
    private int findTaskViewInsertIndex(Task task, int taskIndex) {
        if (taskIndex != -1) {
            List<TaskView> taskViews = getTaskViews();
            boolean foundTaskView = false;
            int taskViewCount = taskViews.size();
            for (int i = 0; i < taskViewCount; i++) {
                Task tvTask = taskViews.get(i).getTask();
                if (tvTask == task) {
                    foundTaskView = true;
                } else if (taskIndex < mStack.indexOfStackTask(tvTask)) {
                    if (foundTaskView) {
                        return i - 1;
                    } else {
                        return i;
                    }
                }
            }
        }
        return -1;
    }
}