Defer calling the stack task removed callbacks.
- When updating a TaskStack, defer calling any callbacks until the stack is updated. Otherwise, the handler may incorrectly check the size of the stack to be empty, which triggers Recents to go home. - This CL also removes an erroneous double call to onStackTaskRemoved() when updating, one explicit call and the call that is made internally in removeTask(). Bug: 28941269 Change-Id: I37b93bd959a625096925a16a426269a0c79de4e7
This commit is contained in:
@@ -228,8 +228,8 @@ public class TaskStack {
|
|||||||
/**
|
/**
|
||||||
* Notifies when a task has been removed from the stack.
|
* Notifies when a task has been removed from the stack.
|
||||||
*/
|
*/
|
||||||
void onStackTaskRemoved(TaskStack stack, Task removedTask, boolean wasFrontMostTask,
|
void onStackTaskRemoved(TaskStack stack, Task removedTask, Task newFrontMostTask,
|
||||||
Task newFrontMostTask, AnimationProps animation, boolean fromDockGesture);
|
AnimationProps animation, boolean fromDockGesture);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notifies when all tasks have been removed from the stack.
|
* Notifies when all tasks have been removed from the stack.
|
||||||
@@ -609,12 +609,11 @@ public class TaskStack {
|
|||||||
*/
|
*/
|
||||||
public void removeTask(Task t, AnimationProps animation, boolean fromDockGesture) {
|
public void removeTask(Task t, AnimationProps animation, boolean fromDockGesture) {
|
||||||
if (mStackTaskList.contains(t)) {
|
if (mStackTaskList.contains(t)) {
|
||||||
boolean wasFrontMostTask = (getStackFrontMostTask(false /* includeFreeform */) == t);
|
|
||||||
removeTaskImpl(mStackTaskList, t);
|
removeTaskImpl(mStackTaskList, t);
|
||||||
Task newFrontMostTask = getStackFrontMostTask(false /* includeFreeform */);
|
Task newFrontMostTask = getStackFrontMostTask(false /* includeFreeform */);
|
||||||
if (mCb != null) {
|
if (mCb != null) {
|
||||||
// Notify that a task has been removed
|
// Notify that a task has been removed
|
||||||
mCb.onStackTaskRemoved(this, t, wasFrontMostTask, newFrontMostTask, animation,
|
mCb.onStackTaskRemoved(this, t, newFrontMostTask, animation,
|
||||||
fromDockGesture);
|
fromDockGesture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -648,6 +647,7 @@ public class TaskStack {
|
|||||||
ArrayMap<Task.TaskKey, Task> currentTasksMap = createTaskKeyMapFromList(mRawTaskList);
|
ArrayMap<Task.TaskKey, Task> currentTasksMap = createTaskKeyMapFromList(mRawTaskList);
|
||||||
ArrayMap<Task.TaskKey, Task> newTasksMap = createTaskKeyMapFromList(tasks);
|
ArrayMap<Task.TaskKey, Task> newTasksMap = createTaskKeyMapFromList(tasks);
|
||||||
ArrayList<Task> addedTasks = new ArrayList<>();
|
ArrayList<Task> addedTasks = new ArrayList<>();
|
||||||
|
ArrayList<Task> removedTasks = new ArrayList<>();
|
||||||
ArrayList<Task> allTasks = new ArrayList<>();
|
ArrayList<Task> allTasks = new ArrayList<>();
|
||||||
|
|
||||||
// Disable notifications if there are no callbacks
|
// Disable notifications if there are no callbacks
|
||||||
@@ -661,11 +661,7 @@ public class TaskStack {
|
|||||||
Task task = mRawTaskList.get(i);
|
Task task = mRawTaskList.get(i);
|
||||||
if (!newTasksMap.containsKey(task.key)) {
|
if (!newTasksMap.containsKey(task.key)) {
|
||||||
if (notifyStackChanges) {
|
if (notifyStackChanges) {
|
||||||
// If we are notifying, then remove the task now, otherwise the raw task list
|
removedTasks.add(task);
|
||||||
// will be reset at the end of this method
|
|
||||||
removeTask(task, AnimationProps.IMMEDIATE, false /* fromDockGesture */);
|
|
||||||
mCb.onStackTaskRemoved(this, task, i == (taskCount - 1), null,
|
|
||||||
AnimationProps.IMMEDIATE, false /* fromDockGesture */);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
task.setGroup(null);
|
task.setGroup(null);
|
||||||
@@ -699,6 +695,14 @@ public class TaskStack {
|
|||||||
// Update the affiliated groupings
|
// Update the affiliated groupings
|
||||||
createAffiliatedGroupings(context);
|
createAffiliatedGroupings(context);
|
||||||
|
|
||||||
|
// Only callback for the removed tasks after the stack has updated
|
||||||
|
int removedTaskCount = removedTasks.size();
|
||||||
|
Task newFrontMostTask = getStackFrontMostTask(false);
|
||||||
|
for (int i = 0; i < removedTaskCount; i++) {
|
||||||
|
mCb.onStackTaskRemoved(this, removedTasks.get(i), newFrontMostTask,
|
||||||
|
AnimationProps.IMMEDIATE, false /* fromDockGesture */);
|
||||||
|
}
|
||||||
|
|
||||||
// Only callback for the newly added tasks after this stack has been updated
|
// Only callback for the newly added tasks after this stack has been updated
|
||||||
int addedTaskCount = addedTasks.size();
|
int addedTaskCount = addedTasks.size();
|
||||||
for (int i = 0; i < addedTaskCount; i++) {
|
for (int i = 0; i < addedTaskCount; i++) {
|
||||||
|
|||||||
@@ -181,8 +181,8 @@ public class TaskStackHorizontalGridView extends HorizontalGridView implements T
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStackTaskRemoved(TaskStack stack, Task removedTask, boolean wasFrontMostTask,
|
public void onStackTaskRemoved(TaskStack stack, Task removedTask, Task newFrontMostTask,
|
||||||
Task newFrontMostTask, AnimationProps animation, boolean fromDockGesture) {
|
AnimationProps animation, boolean fromDockGesture) {
|
||||||
((TaskStackHorizontalViewAdapter) getAdapter()).removeTask(removedTask);
|
((TaskStackHorizontalViewAdapter) getAdapter()).removeTask(removedTask);
|
||||||
if (mFocusedTask == removedTask) {
|
if (mFocusedTask == removedTask) {
|
||||||
resetFocusedTask(removedTask);
|
resetFocusedTask(removedTask);
|
||||||
|
|||||||
@@ -1400,8 +1400,8 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
|
|||||||
* We expect that the {@link TaskView} associated with the removed task is already hidden.
|
* We expect that the {@link TaskView} associated with the removed task is already hidden.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onStackTaskRemoved(TaskStack stack, Task removedTask, boolean wasFrontMostTask,
|
public void onStackTaskRemoved(TaskStack stack, Task removedTask, Task newFrontMostTask,
|
||||||
Task newFrontMostTask, AnimationProps animation, boolean fromDockGesture) {
|
AnimationProps animation, boolean fromDockGesture) {
|
||||||
if (mFocusedTask == removedTask) {
|
if (mFocusedTask == removedTask) {
|
||||||
resetFocusedTask(removedTask);
|
resetFocusedTask(removedTask);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user