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

Commit a0731a1a authored by Winson's avatar Winson
Browse files

Fixing crash when trying to reset focused task after removing task.

- Moving the focused state back into the stack, since the task view
  is transient and can be rebound.  Also ensuring that we update the
  task view focus state as we return and pick up views from the view
  pool
- Fixing issue where going back from recents would not go back home
- Properly calculating the task visibility (regression)

Bug: 25975225

Change-Id: Ica861f0d8996e4e254e875199a2d704a65bf8e58
parent 5b7dd536
Loading
Loading
Loading
Loading
+22 −4
Original line number Diff line number Diff line
@@ -283,6 +283,20 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
        return false;
    }

    /**
     * Dismisses recents back to the launch target task.
     */
    boolean dismissRecentsToLaunchTargetTaskOrHome() {
        SystemServicesProxy ssp = Recents.getSystemServices();
        if (ssp.isRecentsTopMost(ssp.getTopMostTask(), null)) {
            // If we have a focused Task, launch that Task now
            if (mRecentsView.launchPreviousTask()) return true;
            // If none of the other cases apply, then just go Home
            dismissRecentsToHome(true);
        }
        return false;
    }

    /**
     * Dismisses recents if we are already visible and the intent is to toggle the recents view.
     */
@@ -566,9 +580,8 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD

    @Override
    public void onBackPressed() {
        if (!dismissHistory()) {
            dismissRecentsToFocusedTaskOrHome();
        }
        // Back behaves like the recents button so just trigger a toggle event
        EventBus.getDefault().send(new ToggleRecentsEvent());
    }

    /**** RecentsResizeTaskDialog ****/
@@ -584,7 +597,12 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD

    public final void onBusEvent(ToggleRecentsEvent event) {
        if (!dismissHistory()) {
            dismissRecentsToFocusedTaskOrHome();
            RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState();
            if (launchState.launchedFromHome) {
                dismissRecentsToHome(true);
            } else {
                dismissRecentsToLaunchTargetTaskOrHome();
            }
        }
    }

+9 −4
Original line number Diff line number Diff line
@@ -199,8 +199,11 @@ public class TaskStack {
    /** Task stack callbacks */
    public interface TaskStackCallbacks {
        /* Notifies when a task has been removed from the stack */
        void onStackTaskRemoved(TaskStack stack, Task removedTask, boolean wasFrontMostTask,
                                       Task newFrontMostTask);
        void onStackTaskRemoved(TaskStack stack, Task removedTask, int removedTaskIndex,
                boolean wasFrontMostTask, Task newFrontMostTask);

        /* Notifies when a task has been removed from the history */
        void onHistoryTaskRemoved(TaskStack stack, Task removedTask);
    }

    /**
@@ -382,6 +385,7 @@ public class TaskStack {
    public void removeTask(Task t) {
        if (mStackTaskList.contains(t)) {
            boolean wasFrontMostTask = (getStackFrontMostTask() == t);
            int removedTaskIndex = indexOfStackTask(t);
            removeTaskImpl(mStackTaskList, t);
            Task newFrontMostTask = getStackFrontMostTask();
            if (newFrontMostTask != null && newFrontMostTask.lockToTaskEnabled) {
@@ -389,13 +393,14 @@ public class TaskStack {
            }
            if (mCb != null) {
                // Notify that a task has been removed
                mCb.onStackTaskRemoved(this, t, wasFrontMostTask, newFrontMostTask);
                mCb.onStackTaskRemoved(this, t, removedTaskIndex, wasFrontMostTask,
                        newFrontMostTask);
            }
        } else if (mHistoryTaskList.contains(t)) {
            removeTaskImpl(mHistoryTaskList, t);
            if (mCb != null) {
                // Notify that a task has been removed
                mCb.onStackTaskRemoved(this, t, false, null);
                mCb.onHistoryTaskRemoved(this, t);
            }
        }
    }
+0 −6
Original line number Diff line number Diff line
@@ -308,12 +308,6 @@ public class RecentsTransitionHelper {
     */
    private static AppTransitionAnimationSpec composeAnimationSpec(TaskView taskView,
            TaskViewTransform transform, boolean addHeaderBitmap) {
        // Disable any focused state before we draw the header
        // Upfront the processing of the thumbnail
        if (taskView.isFocusedTask()) {
            taskView.setFocusedState(false, false /* animated */, false /* requestViewFocus */);
        }

        Bitmap b = null;
        if (addHeaderBitmap) {
            float scale = transform.scale;
+15 −3
Original line number Diff line number Diff line
@@ -213,6 +213,21 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV
        return false;
    }

    /** Launches the task that recents was launched from if possible */
    public boolean launchPreviousTask() {
        if (mTaskStackView != null) {
            TaskStack stack = mTaskStackView.getStack();
            Task task = stack.getLaunchTarget();
            if (task != null) {
                TaskView taskView = mTaskStackView.getChildViewForTask(task);
                onTaskViewClicked(mTaskStackView, taskView, stack, task, false, null,
                        INVALID_STACK_ID);
                return true;
            }
        }
        return false;
    }

    /** Launches a given task. */
    public boolean launchTask(Task task, Rect taskBounds, int destinationStack) {
        if (mTaskStackView != null) {
@@ -471,9 +486,6 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV
            final TaskStack.DockState dockState = (TaskStack.DockState) event.dropTarget;

            // Remove the task after it is docked
            if (event.taskView.isFocusedTask()) {
                mTaskStackView.resetFocusedTask();
            }
            event.taskView.animate()
                    .alpha(0f)
                    .setDuration(150)
+2 −1
Original line number Diff line number Diff line
@@ -658,7 +658,8 @@ public class TaskStackLayoutAlgorithm {
        transformOut.rect.set(mTaskRect);
        transformOut.rect.offset(transformOut.translationX, transformOut.translationY);
        Utilities.scaleRectAboutCenter(transformOut.rect, transformOut.scale);
        transformOut.visible = true;
        transformOut.visible = (transformOut.rect.top < mStackRect.bottom) &&
                (frontTransform == null || transformOut.rect.top != frontTransform.rect.top);
        transformOut.clipBottom = 0;
        transformOut.clipRight = 0;
        transformOut.thumbnailScale = 1f;
Loading