From 058c4a2abd72752bd96a2e41790c1c5b8aff0622 Mon Sep 17 00:00:00 2001 From: Manu Cornet Date: Thu, 10 Nov 2016 18:53:08 -0800 Subject: [PATCH] Fix a bug where the wrong task was selected coming from home The following behavior was buggy: Home -> toggle recents -> toggle recents again. This reverts to using the same model (task stack where older tasks are first) as other Recents, and only reversing the order when placing views on screen. Then the same logic as existing Recents implementation can be used. Bug: 32101881 Test: Tested behavior locally on Ryu. Existing tests should cover. Change-Id: I52899af4581921902cd781dee707caea694d27e8 --- .../recents/grid/RecentsGridActivity.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/recents/grid/RecentsGridActivity.java b/packages/SystemUI/src/com/android/systemui/recents/grid/RecentsGridActivity.java index 2c874bf9a39fa..e804b52b5a8ad 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/grid/RecentsGridActivity.java +++ b/packages/SystemUI/src/com/android/systemui/recents/grid/RecentsGridActivity.java @@ -60,7 +60,6 @@ import com.android.systemui.recents.model.TaskStack; import com.android.systemui.recents.views.TaskView; import java.util.ArrayList; -import java.util.Collections; import java.util.List; /** @@ -177,9 +176,7 @@ public class RecentsGridActivity extends Activity implements ViewTreeObserver.On loadOpts.numVisibleTaskThumbnails = numVisibleTasks; loader.loadTasks(this, plan, loadOpts); - List stackTasks = mTaskStack.getStackTasks(); - Collections.reverse(stackTasks); - mTasks = stackTasks; + mTasks = mTaskStack.getStackTasks(); updateControlVisibility(); @@ -255,7 +252,10 @@ public class RecentsGridActivity extends Activity implements ViewTreeObserver.On removeTaskViews(); for (int i = 0; i < rects.size(); i++) { Rect rect = rects.get(i); - View taskView = mTaskViews.get(i); + // We keep the same ordering in the model as other Recents flavors (older tasks are + // first in the stack) so that the logic can be similar, but we reverse the order + // when placing views on the screen so that most recent tasks are displayed first. + View taskView = mTaskViews.get(rects.size() - 1 - i); taskView.setLayoutParams(new FrameLayout.LayoutParams(rect.width(), rect.height())); taskView.setTranslationX(rect.left); taskView.setTranslationY(rect.top); @@ -368,10 +368,7 @@ public class RecentsGridActivity extends Activity implements ViewTreeObserver.On public final void onBusEvent(LaunchNextTaskRequestEvent event) { if (mTaskStack.getTaskCount() > 0) { - // The task to launch is the second most recent, which is at index 1 given our ordering. - // If there is only one task, launch that one instead. - int launchTaskIndex = (mTaskStack.getStackTaskCount() > 1) ? 1 : 0; - Task launchTask = mTaskStack.getStackTasks().get(launchTaskIndex); + Task launchTask = mTaskStack.getNextLaunchTarget(); TaskView launchTaskView = getChildViewForTask(launchTask); if (launchTaskView != null) { EventBus.getDefault().send(new LaunchTaskEvent(launchTaskView,