Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.recents; |
| 18 | |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 19 | import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; |
Vladislav Kaznacheev | 1f6b709 | 2016-05-04 17:18:56 -0700 | [diff] [blame] | 20 | import static android.app.ActivityManager.StackId.INVALID_STACK_ID; |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 21 | import static android.app.ActivityManager.StackId.isHomeOrRecentsStack; |
Winson | 94bc4f2 | 2016-04-07 14:22:12 -0700 | [diff] [blame] | 22 | import static android.view.View.MeasureSpec; |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 23 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 24 | import android.app.ActivityManager; |
Jorim Jaggi | fb9d78a | 2017-01-05 18:57:12 +0100 | [diff] [blame] | 25 | import android.app.ActivityManager.TaskSnapshot; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 26 | import android.app.ActivityOptions; |
Matthew Ng | 912c7f7 | 2017-08-02 22:12:04 +0000 | [diff] [blame] | 27 | import android.app.ActivityOptions.OnAnimationStartedListener; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 28 | import android.content.ActivityNotFoundException; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 29 | import android.content.Context; |
| 30 | import android.content.Intent; |
| 31 | import android.content.res.Resources; |
Winson Chung | aa7fa01 | 2017-05-24 15:50:06 -0700 | [diff] [blame] | 32 | import android.graphics.GraphicBuffer; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 33 | import android.graphics.Rect; |
Winson | 3150e57 | 2015-10-23 15:07:24 -0700 | [diff] [blame] | 34 | import android.graphics.RectF; |
Winson | 22574af | 2016-03-23 19:00:28 -0700 | [diff] [blame] | 35 | import android.graphics.drawable.Drawable; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 36 | import android.os.Handler; |
| 37 | import android.os.SystemClock; |
Winson Chung | 3e7e464 | 2017-08-22 10:08:06 -0700 | [diff] [blame] | 38 | import android.util.ArraySet; |
Winson | 1b58561 | 2015-11-06 09:16:26 -0800 | [diff] [blame] | 39 | import android.util.Log; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 40 | import android.util.MutableBoolean; |
Jorim Jaggi | ef496ea | 2017-05-13 23:16:44 +0200 | [diff] [blame] | 41 | import android.util.Pair; |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 42 | import android.view.AppTransitionAnimationSpec; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 43 | import android.view.LayoutInflater; |
Winson | b61e654 | 2016-02-04 14:37:18 -0800 | [diff] [blame] | 44 | import android.view.ViewConfiguration; |
Jorim Jaggi | db21bbd | 2016-04-18 15:32:07 -0700 | [diff] [blame] | 45 | import android.view.WindowManager; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 46 | |
Winson | 675c5d8 | 2016-08-23 17:12:22 -0700 | [diff] [blame] | 47 | import android.widget.Toast; |
Jorim Jaggi | ef496ea | 2017-05-13 23:16:44 +0200 | [diff] [blame] | 48 | |
| 49 | import com.google.android.collect.Lists; |
| 50 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 51 | import com.android.internal.logging.MetricsLogger; |
Jorim Jaggi | db21bbd | 2016-04-18 15:32:07 -0700 | [diff] [blame] | 52 | import com.android.internal.policy.DockedDividerUtils; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 53 | import com.android.systemui.R; |
| 54 | import com.android.systemui.SystemUIApplication; |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 55 | import com.android.systemui.recents.events.EventBus; |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 56 | import com.android.systemui.recents.events.activity.DockedTopTaskEvent; |
Winson | 1b58561 | 2015-11-06 09:16:26 -0800 | [diff] [blame] | 57 | import com.android.systemui.recents.events.activity.EnterRecentsWindowLastAnimationFrameEvent; |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 58 | import com.android.systemui.recents.events.activity.HideRecentsEvent; |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 59 | import com.android.systemui.recents.events.activity.IterateRecentsEvent; |
Manu Cornet | a96a617 | 2017-01-19 12:40:44 -0800 | [diff] [blame] | 60 | import com.android.systemui.recents.events.activity.LaunchMostRecentTaskRequestEvent; |
Winson | b61e654 | 2016-02-04 14:37:18 -0800 | [diff] [blame] | 61 | import com.android.systemui.recents.events.activity.LaunchNextTaskRequestEvent; |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 62 | import com.android.systemui.recents.events.activity.RecentsActivityStartingEvent; |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 63 | import com.android.systemui.recents.events.activity.ToggleRecentsEvent; |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 64 | import com.android.systemui.recents.events.component.ActivityPinnedEvent; |
| 65 | import com.android.systemui.recents.events.component.ActivityUnpinnedEvent; |
| 66 | import com.android.systemui.recents.events.component.HidePipMenuEvent; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 67 | import com.android.systemui.recents.events.component.RecentsVisibilityChangedEvent; |
| 68 | import com.android.systemui.recents.events.component.ScreenPinningRequestEvent; |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 69 | import com.android.systemui.recents.events.ui.DraggingInRecentsEndedEvent; |
| 70 | import com.android.systemui.recents.events.ui.DraggingInRecentsEvent; |
Jorim Jaggi | fb9d78a | 2017-01-05 18:57:12 +0100 | [diff] [blame] | 71 | import com.android.systemui.recents.events.ui.TaskSnapshotChangedEvent; |
Winson | 6b92c6e | 2015-11-06 13:11:16 -0800 | [diff] [blame] | 72 | import com.android.systemui.recents.misc.DozeTrigger; |
Winson | ab84fc5 | 2015-10-23 11:52:07 -0700 | [diff] [blame] | 73 | import com.android.systemui.recents.misc.ForegroundThread; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 74 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 75 | import com.android.systemui.recents.misc.SystemServicesProxy.TaskStackListener; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 76 | import com.android.systemui.recents.model.RecentsTaskLoadPlan; |
| 77 | import com.android.systemui.recents.model.RecentsTaskLoader; |
| 78 | import com.android.systemui.recents.model.Task; |
Winson Chung | 3e7e464 | 2017-08-22 10:08:06 -0700 | [diff] [blame] | 79 | import com.android.systemui.recents.model.Task.TaskKey; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 80 | import com.android.systemui.recents.model.TaskGrouping; |
| 81 | import com.android.systemui.recents.model.TaskStack; |
Winson Chung | 4624976 | 2017-06-09 14:38:39 -0700 | [diff] [blame] | 82 | import com.android.systemui.recents.model.ThumbnailData; |
Jorim Jaggi | ef496ea | 2017-05-13 23:16:44 +0200 | [diff] [blame] | 83 | import com.android.systemui.recents.views.RecentsTransitionHelper; |
| 84 | import com.android.systemui.recents.views.RecentsTransitionHelper.AppTransitionAnimationSpecsFuture; |
Winson | 36a5a2c | 2015-10-29 18:04:39 -0700 | [diff] [blame] | 85 | import com.android.systemui.recents.views.TaskStackLayoutAlgorithm; |
Jorim Jaggi | cdef591 | 2017-04-03 17:24:19 +0200 | [diff] [blame] | 86 | import com.android.systemui.recents.views.TaskStackLayoutAlgorithm.VisibilityReport; |
Winson | 1b58561 | 2015-11-06 09:16:26 -0800 | [diff] [blame] | 87 | import com.android.systemui.recents.views.TaskStackView; |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 88 | import com.android.systemui.recents.views.TaskStackViewScroller; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 89 | import com.android.systemui.recents.views.TaskViewHeader; |
| 90 | import com.android.systemui.recents.views.TaskViewTransform; |
Manu Cornet | de3cfb0 | 2017-01-25 18:31:01 +0900 | [diff] [blame] | 91 | import com.android.systemui.recents.views.grid.TaskGridLayoutAlgorithm; |
Jorim Jaggi | db21bbd | 2016-04-18 15:32:07 -0700 | [diff] [blame] | 92 | import com.android.systemui.stackdivider.DividerView; |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 93 | import com.android.systemui.statusbar.phone.NavigationBarGestureHelper; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 94 | import com.android.systemui.statusbar.phone.StatusBar; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 95 | |
| 96 | import java.util.ArrayList; |
| 97 | |
| 98 | /** |
| 99 | * An implementation of the Recents component for the current user. For secondary users, this can |
| 100 | * be called remotely from the system user. |
| 101 | */ |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 102 | public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 103 | |
| 104 | private final static String TAG = "RecentsImpl"; |
Winson | b61e654 | 2016-02-04 14:37:18 -0800 | [diff] [blame] | 105 | |
Winson | 6b92c6e | 2015-11-06 13:11:16 -0800 | [diff] [blame] | 106 | // The minimum amount of time between each recents button press that we will handle |
| 107 | private final static int MIN_TOGGLE_DELAY_MS = 350; |
Winson | b61e654 | 2016-02-04 14:37:18 -0800 | [diff] [blame] | 108 | |
Winson | 6b92c6e | 2015-11-06 13:11:16 -0800 | [diff] [blame] | 109 | // The duration within which the user releasing the alt tab (from when they pressed alt tab) |
| 110 | // that the fast alt-tab animation will run. If the user's alt-tab takes longer than this |
| 111 | // duration, then we will toggle recents after this duration. |
| 112 | private final static int FAST_ALT_TAB_DELAY_MS = 225; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 113 | |
Winson Chung | 3e7e464 | 2017-08-22 10:08:06 -0700 | [diff] [blame] | 114 | private final static ArraySet<TaskKey> EMPTY_SET = new ArraySet<>(); |
| 115 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 116 | public final static String RECENTS_PACKAGE = "com.android.systemui"; |
| 117 | public final static String RECENTS_ACTIVITY = "com.android.systemui.recents.RecentsActivity"; |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 118 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 119 | /** |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 120 | * An implementation of TaskStackListener, that allows us to listen for changes to the system |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 121 | * task stacks and update recents accordingly. |
| 122 | */ |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 123 | class TaskStackListenerImpl extends TaskStackListener { |
Winson Chung | f3cfa89 | 2017-04-24 12:23:47 -0700 | [diff] [blame] | 124 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 125 | @Override |
Winson Chung | f3cfa89 | 2017-04-24 12:23:47 -0700 | [diff] [blame] | 126 | public void onTaskStackChangedBackground() { |
Winson Chung | ee69756 | 2017-05-18 14:29:43 -0700 | [diff] [blame] | 127 | // Check this is for the right user |
| 128 | if (!checkCurrentUserId(mContext, false /* debug */)) { |
| 129 | return; |
| 130 | } |
| 131 | |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 132 | // Preloads the next task |
Jorim Jaggi | a0fdeec | 2016-01-07 14:42:28 +0100 | [diff] [blame] | 133 | RecentsConfiguration config = Recents.getConfiguration(); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 134 | if (config.svelteLevel == RecentsConfiguration.SVELTE_NONE) { |
Matthew Ng | a3d09db | 2017-08-29 14:06:37 -0700 | [diff] [blame] | 135 | Rect windowRect = getWindowRect(null /* windowRectOverride */); |
| 136 | if (windowRect.isEmpty()) { |
| 137 | return; |
| 138 | } |
| 139 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 140 | // Load the next task only if we aren't svelte |
Winson Chung | f3cfa89 | 2017-04-24 12:23:47 -0700 | [diff] [blame] | 141 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 142 | ActivityManager.RunningTaskInfo runningTaskInfo = ssp.getRunningTask(); |
| 143 | RecentsTaskLoader loader = Recents.getTaskLoader(); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 144 | RecentsTaskLoadPlan plan = loader.createLoadPlan(mContext); |
Winson | dfd7be0 | 2016-05-10 13:30:37 -0700 | [diff] [blame] | 145 | loader.preloadTasks(plan, -1, false /* includeFrontMostExcludedTask */); |
Winson Chung | 3e7e464 | 2017-08-22 10:08:06 -0700 | [diff] [blame] | 146 | TaskStack stack = plan.getTaskStack(); |
| 147 | RecentsActivityLaunchState launchState = new RecentsActivityLaunchState(); |
| 148 | RecentsTaskLoadPlan.Options launchOpts = new RecentsTaskLoadPlan.Options(); |
Winson Chung | f3cfa89 | 2017-04-24 12:23:47 -0700 | [diff] [blame] | 149 | |
Winson Chung | 3e7e464 | 2017-08-22 10:08:06 -0700 | [diff] [blame] | 150 | synchronized (mBackgroundLayoutAlgorithm) { |
| 151 | // This callback is made when a new activity is launched and the old one is |
| 152 | // paused so ignore the current activity and try and preload the thumbnail for |
| 153 | // the previous one. |
Matthew Ng | a3d09db | 2017-08-29 14:06:37 -0700 | [diff] [blame] | 154 | updateDummyStackViewLayout(mBackgroundLayoutAlgorithm, stack, windowRect); |
Winson Chung | f3cfa89 | 2017-04-24 12:23:47 -0700 | [diff] [blame] | 155 | |
| 156 | // Launched from app is always the worst case (in terms of how many |
| 157 | // thumbnails/tasks visible) |
Winson Chung | f3cfa89 | 2017-04-24 12:23:47 -0700 | [diff] [blame] | 158 | launchState.launchedFromApp = true; |
Winson Chung | 3e7e464 | 2017-08-22 10:08:06 -0700 | [diff] [blame] | 159 | mBackgroundLayoutAlgorithm.update(plan.getTaskStack(), EMPTY_SET, launchState); |
| 160 | VisibilityReport visibilityReport = |
| 161 | mBackgroundLayoutAlgorithm.computeStackVisibilityReport( |
| 162 | stack.getStackTasks()); |
Jorim Jaggi | cdef591 | 2017-04-03 17:24:19 +0200 | [diff] [blame] | 163 | |
Winson Chung | 3e7e464 | 2017-08-22 10:08:06 -0700 | [diff] [blame] | 164 | launchOpts.runningTaskId = runningTaskInfo != null ? runningTaskInfo.id : -1; |
| 165 | launchOpts.numVisibleTasks = visibilityReport.numVisibleTasks; |
| 166 | launchOpts.numVisibleTaskThumbnails = visibilityReport.numVisibleThumbnails; |
| 167 | launchOpts.onlyLoadForCache = true; |
| 168 | launchOpts.onlyLoadPausedActivities = true; |
| 169 | launchOpts.loadThumbnails = true; |
| 170 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 171 | loader.loadTasks(mContext, plan, launchOpts); |
| 172 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 173 | } |
Jorim Jaggi | fb9d78a | 2017-01-05 18:57:12 +0100 | [diff] [blame] | 174 | |
| 175 | @Override |
Winson Chung | 85d3c8a | 2017-09-15 15:41:00 -0700 | [diff] [blame] | 176 | public void onActivityPinned(String packageName, int userId, int taskId) { |
Winson Chung | ee69756 | 2017-05-18 14:29:43 -0700 | [diff] [blame] | 177 | // Check this is for the right user |
| 178 | if (!checkCurrentUserId(mContext, false /* debug */)) { |
| 179 | return; |
| 180 | } |
| 181 | |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 182 | // This time needs to be fetched the same way the last active time is fetched in |
| 183 | // {@link TaskRecord#touchActiveTime} |
| 184 | Recents.getConfiguration().getLaunchState().launchedFromPipApp = true; |
| 185 | Recents.getConfiguration().getLaunchState().launchedWithNextPipApp = false; |
| 186 | EventBus.getDefault().send(new ActivityPinnedEvent(taskId)); |
| 187 | consumeInstanceLoadPlan(); |
| 188 | sLastPipTime = System.currentTimeMillis(); |
| 189 | } |
| 190 | |
| 191 | @Override |
| 192 | public void onActivityUnpinned() { |
Winson Chung | ee69756 | 2017-05-18 14:29:43 -0700 | [diff] [blame] | 193 | // Check this is for the right user |
| 194 | if (!checkCurrentUserId(mContext, false /* debug */)) { |
| 195 | return; |
| 196 | } |
| 197 | |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 198 | EventBus.getDefault().send(new ActivityUnpinnedEvent()); |
| 199 | sLastPipTime = -1; |
| 200 | } |
| 201 | |
| 202 | @Override |
Jorim Jaggi | fb9d78a | 2017-01-05 18:57:12 +0100 | [diff] [blame] | 203 | public void onTaskSnapshotChanged(int taskId, TaskSnapshot snapshot) { |
Winson Chung | ee69756 | 2017-05-18 14:29:43 -0700 | [diff] [blame] | 204 | // Check this is for the right user |
| 205 | if (!checkCurrentUserId(mContext, false /* debug */)) { |
| 206 | return; |
| 207 | } |
| 208 | |
Winson Chung | 4624976 | 2017-06-09 14:38:39 -0700 | [diff] [blame] | 209 | EventBus.getDefault().send(new TaskSnapshotChangedEvent(taskId, |
| 210 | ThumbnailData.createFromTaskSnapshot(snapshot))); |
Jorim Jaggi | fb9d78a | 2017-01-05 18:57:12 +0100 | [diff] [blame] | 211 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Sid Soundararajan | 4bdb687 | 2016-03-18 13:42:10 -0700 | [diff] [blame] | 214 | protected static RecentsTaskLoadPlan sInstanceLoadPlan; |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 215 | // Stores the last pinned task time |
| 216 | protected static long sLastPipTime = -1; |
Matthew Ng | 912c7f7 | 2017-08-02 22:12:04 +0000 | [diff] [blame] | 217 | // Stores whether we are waiting for a transition to/from recents to start. During this time, |
| 218 | // we disallow the user from manually toggling recents until the transition has started. |
| 219 | private static boolean mWaitingForTransitionStart = false; |
| 220 | // Stores whether or not the user toggled while we were waiting for a transition to/from |
| 221 | // recents. In this case, we defer the toggle state until then and apply it immediately after. |
| 222 | private static boolean mToggleFollowingTransitionStart = true; |
| 223 | |
| 224 | private ActivityOptions.OnAnimationStartedListener mResetToggleFlagListener = |
| 225 | new OnAnimationStartedListener() { |
| 226 | @Override |
| 227 | public void onAnimationStarted() { |
| 228 | setWaitingForTransitionStart(false); |
| 229 | } |
| 230 | }; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 231 | |
Sid Soundararajan | 4bdb687 | 2016-03-18 13:42:10 -0700 | [diff] [blame] | 232 | protected Context mContext; |
| 233 | protected Handler mHandler; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 234 | TaskStackListenerImpl mTaskStackListener; |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 235 | boolean mDraggingInRecents; |
Jorim Jaggi | e161f08 | 2016-02-05 14:26:16 -0800 | [diff] [blame] | 236 | boolean mLaunchedWhileDocking; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 237 | |
| 238 | // Task launching |
Winson Chung | 3e7e464 | 2017-08-22 10:08:06 -0700 | [diff] [blame] | 239 | Rect mTmpBounds = new Rect(); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 240 | TaskViewTransform mTmpTransform = new TaskViewTransform(); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 241 | int mTaskBarHeight; |
| 242 | |
| 243 | // Header (for transition) |
| 244 | TaskViewHeader mHeaderBar; |
| 245 | final Object mHeaderBarLock = new Object(); |
Winson Chung | 3e7e464 | 2017-08-22 10:08:06 -0700 | [diff] [blame] | 246 | private TaskStackView mDummyStackView; |
| 247 | private TaskStackLayoutAlgorithm mBackgroundLayoutAlgorithm; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 248 | |
| 249 | // Variables to keep track of if we need to start recents after binding |
Sid Soundararajan | 4bdb687 | 2016-03-18 13:42:10 -0700 | [diff] [blame] | 250 | protected boolean mTriggeredFromAltTab; |
| 251 | protected long mLastToggleTime; |
Winson | 6b92c6e | 2015-11-06 13:11:16 -0800 | [diff] [blame] | 252 | DozeTrigger mFastAltTabTrigger = new DozeTrigger(FAST_ALT_TAB_DELAY_MS, new Runnable() { |
| 253 | @Override |
| 254 | public void run() { |
| 255 | // When this fires, then the user has not released alt-tab for at least |
| 256 | // FAST_ALT_TAB_DELAY_MS milliseconds |
Jorim Jaggi | 435b2e4 | 2015-11-24 15:09:30 -0800 | [diff] [blame] | 257 | showRecents(mTriggeredFromAltTab, false /* draggingInRecents */, true /* animate */, |
Jorim Jaggi | db21bbd | 2016-04-18 15:32:07 -0700 | [diff] [blame] | 258 | false /* reloadTasks */, false /* fromHome */, |
| 259 | DividerView.INVALID_RECENTS_GROW_TARGET); |
Winson | 6b92c6e | 2015-11-06 13:11:16 -0800 | [diff] [blame] | 260 | } |
| 261 | }); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 262 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 263 | public RecentsImpl(Context context) { |
| 264 | mContext = context; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 265 | mHandler = new Handler(); |
Winson Chung | 3e7e464 | 2017-08-22 10:08:06 -0700 | [diff] [blame] | 266 | mBackgroundLayoutAlgorithm = new TaskStackLayoutAlgorithm(context, null); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 267 | |
Winson | ab84fc5 | 2015-10-23 11:52:07 -0700 | [diff] [blame] | 268 | // Initialize the static foreground thread |
| 269 | ForegroundThread.get(); |
| 270 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 271 | // Register the task stack listener |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 272 | mTaskStackListener = new TaskStackListenerImpl(); |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 273 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 274 | ssp.registerTaskStackListener(mTaskStackListener); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 275 | |
| 276 | // Initialize the static configuration resources |
Winson | 670ea71 | 2016-04-12 17:02:26 -0700 | [diff] [blame] | 277 | mDummyStackView = new TaskStackView(mContext); |
Winson | 670ea71 | 2016-04-12 17:02:26 -0700 | [diff] [blame] | 278 | reloadResources(); |
Winson | 16ef39a | 2016-06-28 18:25:15 -0700 | [diff] [blame] | 279 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 280 | |
Winson Chung | 501d59d | 2016-10-05 17:49:09 +0000 | [diff] [blame] | 281 | public void onBootCompleted() { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 282 | // When we start, preload the data associated with the previous recent tasks. |
| 283 | // We can use a new plan since the caches will be the same. |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 284 | RecentsTaskLoader loader = Recents.getTaskLoader(); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 285 | RecentsTaskLoadPlan plan = loader.createLoadPlan(mContext); |
Winson | dfd7be0 | 2016-05-10 13:30:37 -0700 | [diff] [blame] | 286 | loader.preloadTasks(plan, -1, false /* includeFrontMostExcludedTask */); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 287 | RecentsTaskLoadPlan.Options launchOpts = new RecentsTaskLoadPlan.Options(); |
Winson Chung | 296278a | 2015-12-17 12:09:02 -0500 | [diff] [blame] | 288 | launchOpts.numVisibleTasks = loader.getIconCacheSize(); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 289 | launchOpts.numVisibleTaskThumbnails = loader.getThumbnailCacheSize(); |
| 290 | launchOpts.onlyLoadForCache = true; |
| 291 | loader.loadTasks(mContext, plan, launchOpts); |
| 292 | } |
| 293 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 294 | public void onConfigurationChanged() { |
Winson | 670ea71 | 2016-04-12 17:02:26 -0700 | [diff] [blame] | 295 | reloadResources(); |
Winson Chung | 3e7e464 | 2017-08-22 10:08:06 -0700 | [diff] [blame] | 296 | mDummyStackView.reloadOnConfigurationChange(); |
| 297 | synchronized (mBackgroundLayoutAlgorithm) { |
| 298 | mBackgroundLayoutAlgorithm.reloadOnConfigurationChange(mContext); |
Winson Chung | f3cfa89 | 2017-04-24 12:23:47 -0700 | [diff] [blame] | 299 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | /** |
| 303 | * This is only called from the system user's Recents. Secondary users will instead proxy their |
| 304 | * visibility change events through to the system user via |
| 305 | * {@link Recents#onBusEvent(RecentsVisibilityChangedEvent)}. |
| 306 | */ |
| 307 | public void onVisibilityChanged(Context context, boolean visible) { |
Winson | ab21660 | 2016-08-09 14:05:20 -0700 | [diff] [blame] | 308 | Recents.getSystemServices().setRecentsVisibility(visible); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | /** |
| 312 | * This is only called from the system user's Recents. Secondary users will instead proxy their |
| 313 | * visibility change events through to the system user via |
| 314 | * {@link Recents#onBusEvent(ScreenPinningRequestEvent)}. |
| 315 | */ |
Andrii Kulian | 0f051f5 | 2016-04-14 00:41:51 -0700 | [diff] [blame] | 316 | public void onStartScreenPinning(Context context, int taskId) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 317 | SystemUIApplication app = (SystemUIApplication) context; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 318 | StatusBar statusBar = app.getComponent(StatusBar.class); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 319 | if (statusBar != null) { |
Andrii Kulian | 0f051f5 | 2016-04-14 00:41:51 -0700 | [diff] [blame] | 320 | statusBar.showScreenPinningRequest(taskId, false); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 321 | } |
| 322 | } |
| 323 | |
Jorim Jaggi | bb42a46 | 2015-11-20 16:27:16 -0800 | [diff] [blame] | 324 | public void showRecents(boolean triggeredFromAltTab, boolean draggingInRecents, |
Jorim Jaggi | db21bbd | 2016-04-18 15:32:07 -0700 | [diff] [blame] | 325 | boolean animate, boolean launchedWhileDockingTask, boolean fromHome, |
| 326 | int growTarget) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 327 | mTriggeredFromAltTab = triggeredFromAltTab; |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 328 | mDraggingInRecents = draggingInRecents; |
Jorim Jaggi | e161f08 | 2016-02-05 14:26:16 -0800 | [diff] [blame] | 329 | mLaunchedWhileDocking = launchedWhileDockingTask; |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 330 | if (mFastAltTabTrigger.isAsleep()) { |
| 331 | // Fast alt-tab duration has elapsed, fall through to showing Recents and reset |
| 332 | mFastAltTabTrigger.stopDozing(); |
Winson | 6b92c6e | 2015-11-06 13:11:16 -0800 | [diff] [blame] | 333 | } else if (mFastAltTabTrigger.isDozing()) { |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 334 | // Fast alt-tab duration has not elapsed. If this is triggered by a different |
| 335 | // showRecents() call, then ignore that call for now. |
| 336 | // TODO: We can not handle quick tabs that happen between the initial showRecents() call |
| 337 | // that started the activity and the activity starting up. The severity of this |
| 338 | // is inversely proportional to the FAST_ALT_TAB_DELAY_MS duration though. |
Winson | 6b92c6e | 2015-11-06 13:11:16 -0800 | [diff] [blame] | 339 | if (!triggeredFromAltTab) { |
| 340 | return; |
| 341 | } |
| 342 | mFastAltTabTrigger.stopDozing(); |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 343 | } else if (triggeredFromAltTab) { |
| 344 | // The fast alt-tab detector is not yet running, so start the trigger and wait for the |
| 345 | // hideRecents() call, or for the fast alt-tab duration to elapse |
| 346 | mFastAltTabTrigger.startDozing(); |
| 347 | return; |
Winson | 6b92c6e | 2015-11-06 13:11:16 -0800 | [diff] [blame] | 348 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 349 | |
| 350 | try { |
| 351 | // Check if the top task is in the home stack, and start the recents activity |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 352 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Winson | d7cb517 | 2016-05-04 16:14:19 -0700 | [diff] [blame] | 353 | boolean forceVisible = launchedWhileDockingTask || draggingInRecents; |
| 354 | MutableBoolean isHomeStackVisible = new MutableBoolean(forceVisible); |
| 355 | if (forceVisible || !ssp.isRecentsActivityVisible(isHomeStackVisible)) { |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 356 | ActivityManager.RunningTaskInfo runningTask = ssp.getRunningTask(); |
| 357 | startRecentsActivity(runningTask, isHomeStackVisible.value || fromHome, animate, |
| 358 | growTarget); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 359 | } |
| 360 | } catch (ActivityNotFoundException e) { |
Winson | 1b58561 | 2015-11-06 09:16:26 -0800 | [diff] [blame] | 361 | Log.e(TAG, "Failed to launch RecentsActivity", e); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 362 | } |
| 363 | } |
| 364 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 365 | public void hideRecents(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) { |
Winson | 2799eca | 2016-02-25 12:10:42 -0800 | [diff] [blame] | 366 | if (triggeredFromAltTab && mFastAltTabTrigger.isDozing()) { |
| 367 | // The user has released alt-tab before the trigger has run, so just show the next |
| 368 | // task immediately |
| 369 | showNextTask(); |
Winson | 6b92c6e | 2015-11-06 13:11:16 -0800 | [diff] [blame] | 370 | |
Winson | 2799eca | 2016-02-25 12:10:42 -0800 | [diff] [blame] | 371 | // Cancel the fast alt-tab trigger |
| 372 | mFastAltTabTrigger.stopDozing(); |
Winson | 2799eca | 2016-02-25 12:10:42 -0800 | [diff] [blame] | 373 | return; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 374 | } |
Winson | 2799eca | 2016-02-25 12:10:42 -0800 | [diff] [blame] | 375 | |
| 376 | // Defer to the activity to handle hiding recents, if it handles it, then it must still |
| 377 | // be visible |
| 378 | EventBus.getDefault().post(new HideRecentsEvent(triggeredFromAltTab, |
| 379 | triggeredFromHomeKey)); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Jorim Jaggi | db21bbd | 2016-04-18 15:32:07 -0700 | [diff] [blame] | 382 | public void toggleRecents(int growTarget) { |
Winson Chung | ee70fbd | 2017-08-29 14:56:01 -0700 | [diff] [blame] | 383 | // Skip preloading if the task is locked |
| 384 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 385 | if (ssp.isScreenPinningActive()) { |
| 386 | return; |
| 387 | } |
| 388 | |
Winson | 6b92c6e | 2015-11-06 13:11:16 -0800 | [diff] [blame] | 389 | // Skip this toggle if we are already waiting to trigger recents via alt-tab |
| 390 | if (mFastAltTabTrigger.isDozing()) { |
| 391 | return; |
| 392 | } |
| 393 | |
Matthew Ng | 912c7f7 | 2017-08-02 22:12:04 +0000 | [diff] [blame] | 394 | if (mWaitingForTransitionStart) { |
| 395 | mToggleFollowingTransitionStart = true; |
| 396 | return; |
| 397 | } |
| 398 | |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 399 | mDraggingInRecents = false; |
Jorim Jaggi | e161f08 | 2016-02-05 14:26:16 -0800 | [diff] [blame] | 400 | mLaunchedWhileDocking = false; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 401 | mTriggeredFromAltTab = false; |
| 402 | |
| 403 | try { |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 404 | MutableBoolean isHomeStackVisible = new MutableBoolean(true); |
Winson | b61e654 | 2016-02-04 14:37:18 -0800 | [diff] [blame] | 405 | long elapsedTime = SystemClock.elapsedRealtime() - mLastToggleTime; |
| 406 | |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 407 | if (ssp.isRecentsActivityVisible(isHomeStackVisible)) { |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 408 | RecentsDebugFlags debugFlags = Recents.getDebugFlags(); |
Winson | 5da4347 | 2015-11-04 17:39:55 -0800 | [diff] [blame] | 409 | RecentsConfiguration config = Recents.getConfiguration(); |
| 410 | RecentsActivityLaunchState launchState = config.getLaunchState(); |
Winson Chung | ead5c0f | 2015-12-14 11:18:57 -0500 | [diff] [blame] | 411 | if (!launchState.launchedWithAltTab) { |
Manu Cornet | a96a617 | 2017-01-19 12:40:44 -0800 | [diff] [blame] | 412 | // Has the user tapped quickly? |
Matthew Ng | da3dd7c | 2017-04-28 17:33:22 -0700 | [diff] [blame] | 413 | boolean isQuickTap = elapsedTime < ViewConfiguration.getDoubleTapTimeout(); |
Manu Cornet | a96a617 | 2017-01-19 12:40:44 -0800 | [diff] [blame] | 414 | if (Recents.getConfiguration().isGridEnabled) { |
| 415 | if (isQuickTap) { |
| 416 | EventBus.getDefault().post(new LaunchNextTaskRequestEvent()); |
| 417 | } else { |
| 418 | EventBus.getDefault().post(new LaunchMostRecentTaskRequestEvent()); |
| 419 | } |
Winson | b61e654 | 2016-02-04 14:37:18 -0800 | [diff] [blame] | 420 | } else { |
Manu Cornet | a96a617 | 2017-01-19 12:40:44 -0800 | [diff] [blame] | 421 | if (!debugFlags.isPagingEnabled() || isQuickTap) { |
| 422 | // Launch the next focused task |
| 423 | EventBus.getDefault().post(new LaunchNextTaskRequestEvent()); |
| 424 | } else { |
| 425 | // Notify recents to move onto the next task |
| 426 | EventBus.getDefault().post(new IterateRecentsEvent()); |
| 427 | } |
Winson | b61e654 | 2016-02-04 14:37:18 -0800 | [diff] [blame] | 428 | } |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 429 | } else { |
| 430 | // If the user has toggled it too quickly, then just eat up the event here (it's |
| 431 | // better than showing a janky screenshot). |
| 432 | // NOTE: Ideally, the screenshot mechanism would take the window transform into |
| 433 | // account |
Winson | b61e654 | 2016-02-04 14:37:18 -0800 | [diff] [blame] | 434 | if (elapsedTime < MIN_TOGGLE_DELAY_MS) { |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 435 | return; |
| 436 | } |
| 437 | |
| 438 | EventBus.getDefault().post(new ToggleRecentsEvent()); |
| 439 | mLastToggleTime = SystemClock.elapsedRealtime(); |
| 440 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 441 | return; |
| 442 | } else { |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 443 | // If the user has toggled it too quickly, then just eat up the event here (it's |
| 444 | // better than showing a janky screenshot). |
| 445 | // NOTE: Ideally, the screenshot mechanism would take the window transform into |
| 446 | // account |
Winson | b61e654 | 2016-02-04 14:37:18 -0800 | [diff] [blame] | 447 | if (elapsedTime < MIN_TOGGLE_DELAY_MS) { |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 448 | return; |
| 449 | } |
| 450 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 451 | // Otherwise, start the recents activity |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 452 | ActivityManager.RunningTaskInfo runningTask = ssp.getRunningTask(); |
| 453 | startRecentsActivity(runningTask, isHomeStackVisible.value, true /* animate */, |
| 454 | growTarget); |
Winson | d8b1d63 | 2016-01-04 17:51:18 -0800 | [diff] [blame] | 455 | |
| 456 | // Only close the other system windows if we are actually showing recents |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 457 | ssp.sendCloseSystemWindows(StatusBar.SYSTEM_DIALOG_REASON_RECENT_APPS); |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 458 | mLastToggleTime = SystemClock.elapsedRealtime(); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 459 | } |
| 460 | } catch (ActivityNotFoundException e) { |
Winson | 1b58561 | 2015-11-06 09:16:26 -0800 | [diff] [blame] | 461 | Log.e(TAG, "Failed to launch RecentsActivity", e); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 462 | } |
| 463 | } |
| 464 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 465 | public void preloadRecents() { |
Winson Chung | ee70fbd | 2017-08-29 14:56:01 -0700 | [diff] [blame] | 466 | // Skip preloading if the task is locked |
| 467 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 468 | if (ssp.isScreenPinningActive()) { |
| 469 | return; |
| 470 | } |
| 471 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 472 | // Preload only the raw task list into a new load plan (which will be consumed by the |
Winson Chung | ebe1ba1 | 2017-05-18 15:47:14 -0700 | [diff] [blame] | 473 | // RecentsActivity) only if there is a task to animate to. Post this to ensure that we |
| 474 | // don't block the touch feedback on the nav bar button which triggers this. |
| 475 | mHandler.post(() -> { |
Winson Chung | ebe1ba1 | 2017-05-18 15:47:14 -0700 | [diff] [blame] | 476 | MutableBoolean isHomeStackVisible = new MutableBoolean(true); |
| 477 | if (!ssp.isRecentsActivityVisible(isHomeStackVisible)) { |
| 478 | ActivityManager.RunningTaskInfo runningTask = ssp.getRunningTask(); |
| 479 | if (runningTask == null) { |
| 480 | return; |
| 481 | } |
Winson Chung | 96b7a51 | 2017-02-08 12:20:00 -0800 | [diff] [blame] | 482 | |
Winson Chung | ebe1ba1 | 2017-05-18 15:47:14 -0700 | [diff] [blame] | 483 | RecentsTaskLoader loader = Recents.getTaskLoader(); |
| 484 | sInstanceLoadPlan = loader.createLoadPlan(mContext); |
| 485 | loader.preloadTasks(sInstanceLoadPlan, runningTask.id, !isHomeStackVisible.value); |
| 486 | TaskStack stack = sInstanceLoadPlan.getTaskStack(); |
| 487 | if (stack.getTaskCount() > 0) { |
| 488 | // Only preload the icon (but not the thumbnail since it may not have been taken |
| 489 | // for the pausing activity) |
| 490 | preloadIcon(runningTask.id); |
Winson | aeb298c | 2016-04-05 13:08:11 -0700 | [diff] [blame] | 491 | |
Winson Chung | ebe1ba1 | 2017-05-18 15:47:14 -0700 | [diff] [blame] | 492 | // At this point, we don't know anything about the stack state. So only |
| 493 | // calculate the dimensions of the thumbnail that we need for the transition |
| 494 | // into Recents, but do not draw it until we construct the activity options when |
| 495 | // we start Recents |
| 496 | updateHeaderBarLayout(stack, null /* window rect override*/); |
| 497 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 498 | } |
Winson Chung | ebe1ba1 | 2017-05-18 15:47:14 -0700 | [diff] [blame] | 499 | }); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 500 | } |
| 501 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 502 | public void cancelPreloadingRecents() { |
| 503 | // Do nothing |
| 504 | } |
| 505 | |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 506 | public void onDraggingInRecents(float distanceFromTop) { |
| 507 | EventBus.getDefault().sendOntoMainThread(new DraggingInRecentsEvent(distanceFromTop)); |
| 508 | } |
| 509 | |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 510 | public void onDraggingInRecentsEnded(float velocity) { |
| 511 | EventBus.getDefault().sendOntoMainThread(new DraggingInRecentsEndedEvent(velocity)); |
| 512 | } |
| 513 | |
Winson | 675c5d8 | 2016-08-23 17:12:22 -0700 | [diff] [blame] | 514 | public void onShowCurrentUserToast(int msgResId, int msgLength) { |
| 515 | Toast.makeText(mContext, msgResId, msgLength).show(); |
| 516 | } |
| 517 | |
Winson | 6b92c6e | 2015-11-06 13:11:16 -0800 | [diff] [blame] | 518 | /** |
| 519 | * Transitions to the next recent task in the stack. |
| 520 | */ |
| 521 | public void showNextTask() { |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 522 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Winson | 6b92c6e | 2015-11-06 13:11:16 -0800 | [diff] [blame] | 523 | RecentsTaskLoader loader = Recents.getTaskLoader(); |
| 524 | RecentsTaskLoadPlan plan = loader.createLoadPlan(mContext); |
Winson | dfd7be0 | 2016-05-10 13:30:37 -0700 | [diff] [blame] | 525 | loader.preloadTasks(plan, -1, false /* includeFrontMostExcludedTask */); |
Winson | 6b92c6e | 2015-11-06 13:11:16 -0800 | [diff] [blame] | 526 | TaskStack focusedStack = plan.getTaskStack(); |
| 527 | |
| 528 | // Return early if there are no tasks in the focused stack |
Winson | 4b057c6 | 2016-01-12 15:01:52 -0800 | [diff] [blame] | 529 | if (focusedStack == null || focusedStack.getTaskCount() == 0) return; |
Winson | 6b92c6e | 2015-11-06 13:11:16 -0800 | [diff] [blame] | 530 | |
Winson | 6b92c6e | 2015-11-06 13:11:16 -0800 | [diff] [blame] | 531 | // Return early if there is no running task |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 532 | ActivityManager.RunningTaskInfo runningTask = ssp.getRunningTask(); |
Winson | 6b92c6e | 2015-11-06 13:11:16 -0800 | [diff] [blame] | 533 | if (runningTask == null) return; |
Winson | 6b92c6e | 2015-11-06 13:11:16 -0800 | [diff] [blame] | 534 | |
| 535 | // Find the task in the recents list |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 536 | boolean isRunningTaskInHomeStack = SystemServicesProxy.isHomeStack(runningTask.stackId); |
Winson | 250608a | 2015-11-24 15:00:31 -0800 | [diff] [blame] | 537 | ArrayList<Task> tasks = focusedStack.getStackTasks(); |
Winson | 6b92c6e | 2015-11-06 13:11:16 -0800 | [diff] [blame] | 538 | Task toTask = null; |
| 539 | ActivityOptions launchOpts = null; |
| 540 | int taskCount = tasks.size(); |
| 541 | for (int i = taskCount - 1; i >= 1; i--) { |
| 542 | Task task = tasks.get(i); |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 543 | if (isRunningTaskInHomeStack) { |
Winson | e86deb8 | 2015-11-12 09:32:10 -0800 | [diff] [blame] | 544 | toTask = tasks.get(i - 1); |
| 545 | launchOpts = ActivityOptions.makeCustomAnimation(mContext, |
| 546 | R.anim.recents_launch_next_affiliated_task_target, |
| 547 | R.anim.recents_fast_toggle_app_home_exit); |
| 548 | break; |
| 549 | } else if (task.key.id == runningTask.id) { |
Winson | 6b92c6e | 2015-11-06 13:11:16 -0800 | [diff] [blame] | 550 | toTask = tasks.get(i - 1); |
| 551 | launchOpts = ActivityOptions.makeCustomAnimation(mContext, |
| 552 | R.anim.recents_launch_prev_affiliated_task_target, |
| 553 | R.anim.recents_launch_prev_affiliated_task_source); |
| 554 | break; |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | // Return early if there is no next task |
| 559 | if (toTask == null) { |
| 560 | ssp.startInPlaceAnimationOnFrontMostApplication( |
| 561 | ActivityOptions.makeCustomInPlaceAnimation(mContext, |
| 562 | R.anim.recents_launch_prev_affiliated_task_bounce)); |
| 563 | return; |
| 564 | } |
| 565 | |
| 566 | // Launch the task |
Vladislav Kaznacheev | 1f6b709 | 2016-05-04 17:18:56 -0700 | [diff] [blame] | 567 | ssp.startActivityFromRecents( |
Jorim Jaggi | 34795e3 | 2017-05-12 17:27:46 +0200 | [diff] [blame] | 568 | mContext, toTask.key, toTask.title, launchOpts, INVALID_STACK_ID, |
| 569 | null /* resultListener */); |
Winson | 6b92c6e | 2015-11-06 13:11:16 -0800 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | /** |
| 573 | * Transitions to the next affiliated task. |
| 574 | */ |
| 575 | public void showRelativeAffiliatedTask(boolean showNextTask) { |
| 576 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 577 | RecentsTaskLoader loader = Recents.getTaskLoader(); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 578 | RecentsTaskLoadPlan plan = loader.createLoadPlan(mContext); |
Winson | dfd7be0 | 2016-05-10 13:30:37 -0700 | [diff] [blame] | 579 | loader.preloadTasks(plan, -1, false /* includeFrontMostExcludedTask */); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 580 | TaskStack focusedStack = plan.getTaskStack(); |
| 581 | |
| 582 | // Return early if there are no tasks in the focused stack |
Winson | 4b057c6 | 2016-01-12 15:01:52 -0800 | [diff] [blame] | 583 | if (focusedStack == null || focusedStack.getTaskCount() == 0) return; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 584 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 585 | // Return early if there is no running task (can't determine affiliated tasks in this case) |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 586 | ActivityManager.RunningTaskInfo runningTask = ssp.getRunningTask(); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 587 | if (runningTask == null) return; |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 588 | // Return early if the running task is in the home/recents stack (optimization) |
| 589 | if (isHomeOrRecentsStack(runningTask.stackId)) return; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 590 | |
| 591 | // Find the task in the recents list |
Winson | 250608a | 2015-11-24 15:00:31 -0800 | [diff] [blame] | 592 | ArrayList<Task> tasks = focusedStack.getStackTasks(); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 593 | Task toTask = null; |
| 594 | ActivityOptions launchOpts = null; |
| 595 | int taskCount = tasks.size(); |
| 596 | int numAffiliatedTasks = 0; |
| 597 | for (int i = 0; i < taskCount; i++) { |
| 598 | Task task = tasks.get(i); |
| 599 | if (task.key.id == runningTask.id) { |
| 600 | TaskGrouping group = task.group; |
| 601 | Task.TaskKey toTaskKey; |
| 602 | if (showNextTask) { |
| 603 | toTaskKey = group.getNextTaskInGroup(task); |
| 604 | launchOpts = ActivityOptions.makeCustomAnimation(mContext, |
| 605 | R.anim.recents_launch_next_affiliated_task_target, |
| 606 | R.anim.recents_launch_next_affiliated_task_source); |
| 607 | } else { |
| 608 | toTaskKey = group.getPrevTaskInGroup(task); |
| 609 | launchOpts = ActivityOptions.makeCustomAnimation(mContext, |
| 610 | R.anim.recents_launch_prev_affiliated_task_target, |
| 611 | R.anim.recents_launch_prev_affiliated_task_source); |
| 612 | } |
| 613 | if (toTaskKey != null) { |
| 614 | toTask = focusedStack.findTaskWithId(toTaskKey.id); |
| 615 | } |
| 616 | numAffiliatedTasks = group.getTaskCount(); |
| 617 | break; |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | // Return early if there is no next task |
| 622 | if (toTask == null) { |
| 623 | if (numAffiliatedTasks > 1) { |
| 624 | if (showNextTask) { |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 625 | ssp.startInPlaceAnimationOnFrontMostApplication( |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 626 | ActivityOptions.makeCustomInPlaceAnimation(mContext, |
| 627 | R.anim.recents_launch_next_affiliated_task_bounce)); |
| 628 | } else { |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 629 | ssp.startInPlaceAnimationOnFrontMostApplication( |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 630 | ActivityOptions.makeCustomInPlaceAnimation(mContext, |
| 631 | R.anim.recents_launch_prev_affiliated_task_bounce)); |
| 632 | } |
| 633 | } |
| 634 | return; |
| 635 | } |
| 636 | |
| 637 | // Keep track of actually launched affiliated tasks |
| 638 | MetricsLogger.count(mContext, "overview_affiliated_task_launch", 1); |
| 639 | |
| 640 | // Launch the task |
Vladislav Kaznacheev | 1f6b709 | 2016-05-04 17:18:56 -0700 | [diff] [blame] | 641 | ssp.startActivityFromRecents( |
Jorim Jaggi | 34795e3 | 2017-05-12 17:27:46 +0200 | [diff] [blame] | 642 | mContext, toTask.key, toTask.title, launchOpts, INVALID_STACK_ID, |
| 643 | null /* resultListener */); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | public void showNextAffiliatedTask() { |
| 647 | // Keep track of when the affiliated task is triggered |
| 648 | MetricsLogger.count(mContext, "overview_affiliated_task_next", 1); |
| 649 | showRelativeAffiliatedTask(true); |
| 650 | } |
| 651 | |
| 652 | public void showPrevAffiliatedTask() { |
| 653 | // Keep track of when the affiliated task is triggered |
| 654 | MetricsLogger.count(mContext, "overview_affiliated_task_prev", 1); |
| 655 | showRelativeAffiliatedTask(false); |
| 656 | } |
| 657 | |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 658 | public void dockTopTask(int topTaskId, int dragMode, |
| 659 | int stackCreateMode, Rect initialBounds) { |
Jorim Jaggi | 75b2597 | 2015-10-21 14:51:10 +0200 | [diff] [blame] | 660 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 661 | |
| 662 | // Make sure we inform DividerView before we actually start the activity so we can change |
| 663 | // the resize mode already. |
Chong Zhang | e4fbd32 | 2016-03-01 14:44:03 -0800 | [diff] [blame] | 664 | if (ssp.moveTaskToDockedStack(topTaskId, stackCreateMode, initialBounds)) { |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 665 | EventBus.getDefault().send(new DockedTopTaskEvent(dragMode, initialBounds)); |
Chong Zhang | e4fbd32 | 2016-03-01 14:44:03 -0800 | [diff] [blame] | 666 | showRecents( |
| 667 | false /* triggeredFromAltTab */, |
| 668 | dragMode == NavigationBarGestureHelper.DRAG_MODE_RECENTS, |
| 669 | false /* animate */, |
Jorim Jaggi | 681fc7b | 2016-04-14 22:02:39 -0700 | [diff] [blame] | 670 | true /* launchedWhileDockingTask*/, |
Jorim Jaggi | db21bbd | 2016-04-18 15:32:07 -0700 | [diff] [blame] | 671 | false /* fromHome */, |
| 672 | DividerView.INVALID_RECENTS_GROW_TARGET); |
Chong Zhang | e4fbd32 | 2016-03-01 14:44:03 -0800 | [diff] [blame] | 673 | } |
Jorim Jaggi | 75b2597 | 2015-10-21 14:51:10 +0200 | [diff] [blame] | 674 | } |
| 675 | |
Matthew Ng | 912c7f7 | 2017-08-02 22:12:04 +0000 | [diff] [blame] | 676 | public void setWaitingForTransitionStart(boolean waitingForTransitionStart) { |
| 677 | if (mWaitingForTransitionStart == waitingForTransitionStart) { |
| 678 | return; |
| 679 | } |
| 680 | |
| 681 | mWaitingForTransitionStart = waitingForTransitionStart; |
| 682 | if (!waitingForTransitionStart && mToggleFollowingTransitionStart) { |
Matthew Ng | c57b7f6 | 2017-08-10 15:37:19 -0700 | [diff] [blame] | 683 | mHandler.post(() -> toggleRecents(DividerView.INVALID_RECENTS_GROW_TARGET)); |
Matthew Ng | 912c7f7 | 2017-08-02 22:12:04 +0000 | [diff] [blame] | 684 | } |
| 685 | mToggleFollowingTransitionStart = false; |
| 686 | } |
| 687 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 688 | /** |
| 689 | * Returns the preloaded load plan and invalidates it. |
| 690 | */ |
| 691 | public static RecentsTaskLoadPlan consumeInstanceLoadPlan() { |
| 692 | RecentsTaskLoadPlan plan = sInstanceLoadPlan; |
| 693 | sInstanceLoadPlan = null; |
| 694 | return plan; |
| 695 | } |
| 696 | |
| 697 | /** |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 698 | * @return the time at which a task last entered picture-in-picture. |
| 699 | */ |
| 700 | public static long getLastPipTime() { |
| 701 | return sLastPipTime; |
| 702 | } |
| 703 | |
| 704 | /** |
| 705 | * Clears the time at which a task last entered picture-in-picture. |
| 706 | */ |
| 707 | public static void clearLastPipTime() { |
| 708 | sLastPipTime = -1; |
| 709 | } |
| 710 | |
| 711 | /** |
Winson | 670ea71 | 2016-04-12 17:02:26 -0700 | [diff] [blame] | 712 | * Reloads all the resources for the current configuration. |
Winson | b94443d | 2016-01-07 15:34:13 -0800 | [diff] [blame] | 713 | */ |
Winson | 670ea71 | 2016-04-12 17:02:26 -0700 | [diff] [blame] | 714 | private void reloadResources() { |
Winson | b94443d | 2016-01-07 15:34:13 -0800 | [diff] [blame] | 715 | Resources res = mContext.getResources(); |
Winson | b94443d | 2016-01-07 15:34:13 -0800 | [diff] [blame] | 716 | |
Jorim Jaggi | 25160db | 2016-04-18 16:03:36 -0700 | [diff] [blame] | 717 | mTaskBarHeight = TaskStackLayoutAlgorithm.getDimensionForDevice(mContext, |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 718 | R.dimen.recents_task_view_header_height, |
| 719 | R.dimen.recents_task_view_header_height, |
| 720 | R.dimen.recents_task_view_header_height, |
| 721 | R.dimen.recents_task_view_header_height_tablet_land, |
| 722 | R.dimen.recents_task_view_header_height, |
Manu Cornet | f78b11d | 2016-12-16 19:50:55 -0800 | [diff] [blame] | 723 | R.dimen.recents_task_view_header_height_tablet_land, |
| 724 | R.dimen.recents_grid_task_view_header_height); |
Matthew Ng | 384e60e | 2016-10-31 16:44:01 -0700 | [diff] [blame] | 725 | |
| 726 | LayoutInflater inflater = LayoutInflater.from(mContext); |
| 727 | mHeaderBar = (TaskViewHeader) inflater.inflate(R.layout.recents_task_view_header, |
| 728 | null, false); |
| 729 | mHeaderBar.setLayoutDirection(res.getConfiguration().getLayoutDirection()); |
Winson | b94443d | 2016-01-07 15:34:13 -0800 | [diff] [blame] | 730 | } |
| 731 | |
Winson Chung | 3e7e464 | 2017-08-22 10:08:06 -0700 | [diff] [blame] | 732 | private void updateDummyStackViewLayout(TaskStackLayoutAlgorithm stackLayout, |
| 733 | TaskStack stack, Rect windowRect) { |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 734 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Winson | fc48b07 | 2016-04-21 11:20:11 -0700 | [diff] [blame] | 735 | Rect displayRect = ssp.getDisplayRect(); |
Jorim Jaggi | c6c89a8 | 2016-01-28 17:48:21 -0800 | [diff] [blame] | 736 | Rect systemInsets = new Rect(); |
| 737 | ssp.getStableInsets(systemInsets); |
Jorim Jaggi | cdef591 | 2017-04-03 17:24:19 +0200 | [diff] [blame] | 738 | |
Winson | cf9b832 | 2016-03-31 15:36:07 -0700 | [diff] [blame] | 739 | // When docked, the nav bar insets are consumed and the activity is measured without insets. |
| 740 | // However, the window bounds include the insets, so we need to subtract them here to make |
| 741 | // them identical. |
| 742 | if (ssp.hasDockedTask()) { |
| 743 | windowRect.bottom -= systemInsets.bottom; |
| 744 | systemInsets.bottom = 0; |
| 745 | } |
Jorim Jaggi | ef496ea | 2017-05-13 23:16:44 +0200 | [diff] [blame] | 746 | calculateWindowStableInsets(systemInsets, windowRect, displayRect); |
Jorim Jaggi | c6c89a8 | 2016-01-28 17:48:21 -0800 | [diff] [blame] | 747 | windowRect.offsetTo(0, 0); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 748 | |
Winson Chung | 3e7e464 | 2017-08-22 10:08:06 -0700 | [diff] [blame] | 749 | // Rebind the header bar and draw it for the transition |
| 750 | stackLayout.setSystemInsets(systemInsets); |
| 751 | if (stack != null) { |
| 752 | stackLayout.getTaskStackBounds(displayRect, windowRect, systemInsets.top, |
| 753 | systemInsets.left, systemInsets.right, mTmpBounds); |
| 754 | stackLayout.reset(); |
| 755 | stackLayout.initialize(displayRect, windowRect, mTmpBounds, |
| 756 | TaskStackLayoutAlgorithm.StackState.getStackStateForStack(stack)); |
Jorim Jaggi | cdef591 | 2017-04-03 17:24:19 +0200 | [diff] [blame] | 757 | } |
| 758 | } |
| 759 | |
| 760 | private Rect getWindowRect(Rect windowRectOverride) { |
| 761 | return windowRectOverride != null |
| 762 | ? new Rect(windowRectOverride) |
| 763 | : Recents.getSystemServices().getWindowRect(); |
| 764 | } |
| 765 | |
| 766 | /** |
| 767 | * Prepares the header bar layout for the next transition, if the task view bounds has changed |
| 768 | * since the last call, it will attempt to re-measure and layout the header bar to the new size. |
| 769 | * |
| 770 | * @param stack the stack to initialize the stack layout with |
| 771 | * @param windowRectOverride the rectangle to use when calculating the stack state which can |
| 772 | * be different from the current window rect if recents is resizing |
| 773 | * while being launched |
| 774 | */ |
| 775 | private void updateHeaderBarLayout(TaskStack stack, Rect windowRectOverride) { |
| 776 | Rect windowRect = getWindowRect(windowRectOverride); |
Winson Chung | f3cfa89 | 2017-04-24 12:23:47 -0700 | [diff] [blame] | 777 | int taskViewWidth = 0; |
Winson Chung | 3e7e464 | 2017-08-22 10:08:06 -0700 | [diff] [blame] | 778 | boolean useGridLayout = mDummyStackView.useGridLayout(); |
| 779 | updateDummyStackViewLayout(mDummyStackView.getStackAlgorithm(), stack, windowRect); |
| 780 | if (stack != null) { |
| 781 | TaskStackLayoutAlgorithm stackLayout = mDummyStackView.getStackAlgorithm(); |
| 782 | mDummyStackView.getStack().removeAllTasks(false /* notifyStackChanges */); |
| 783 | mDummyStackView.setTasks(stack, false /* allowNotifyStackChanges */); |
| 784 | // Get the width of a task view so that we know how wide to draw the header bar. |
| 785 | if (useGridLayout) { |
| 786 | TaskGridLayoutAlgorithm gridLayout = mDummyStackView.getGridAlgorithm(); |
| 787 | gridLayout.initialize(windowRect); |
| 788 | taskViewWidth = (int) gridLayout.getTransform(0 /* taskIndex */, |
| 789 | stack.getTaskCount(), new TaskViewTransform(), |
| 790 | stackLayout).rect.width(); |
| 791 | } else { |
| 792 | Rect taskViewBounds = stackLayout.getUntransformedTaskViewBounds(); |
| 793 | if (!taskViewBounds.isEmpty()) { |
| 794 | taskViewWidth = taskViewBounds.width(); |
Manu Cornet | de3cfb0 | 2017-01-25 18:31:01 +0900 | [diff] [blame] | 795 | } |
| 796 | } |
Winson Chung | f3cfa89 | 2017-04-24 12:23:47 -0700 | [diff] [blame] | 797 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 798 | |
Winson Chung | f3cfa89 | 2017-04-24 12:23:47 -0700 | [diff] [blame] | 799 | if (stack != null && taskViewWidth > 0) { |
| 800 | synchronized (mHeaderBarLock) { |
| 801 | if (mHeaderBar.getMeasuredWidth() != taskViewWidth || |
| 802 | mHeaderBar.getMeasuredHeight() != mTaskBarHeight) { |
| 803 | if (useGridLayout) { |
| 804 | mHeaderBar.setShouldDarkenBackgroundColor(true); |
| 805 | mHeaderBar.setNoUserInteractionState(); |
Winson | 94bc4f2 | 2016-04-07 14:22:12 -0700 | [diff] [blame] | 806 | } |
Winson Chung | f3cfa89 | 2017-04-24 12:23:47 -0700 | [diff] [blame] | 807 | mHeaderBar.forceLayout(); |
| 808 | mHeaderBar.measure( |
| 809 | MeasureSpec.makeMeasureSpec(taskViewWidth, MeasureSpec.EXACTLY), |
| 810 | MeasureSpec.makeMeasureSpec(mTaskBarHeight, MeasureSpec.EXACTLY)); |
Winson | aeb298c | 2016-04-05 13:08:11 -0700 | [diff] [blame] | 811 | } |
Winson Chung | f3cfa89 | 2017-04-24 12:23:47 -0700 | [diff] [blame] | 812 | mHeaderBar.layout(0, 0, taskViewWidth, mTaskBarHeight); |
| 813 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 814 | } |
| 815 | } |
| 816 | |
| 817 | /** |
Jorim Jaggi | c6c89a8 | 2016-01-28 17:48:21 -0800 | [diff] [blame] | 818 | * Given the stable insets and the rect for our window, calculates the insets that affect our |
| 819 | * window. |
| 820 | */ |
Jorim Jaggi | ef496ea | 2017-05-13 23:16:44 +0200 | [diff] [blame] | 821 | private void calculateWindowStableInsets(Rect inOutInsets, Rect windowRect, Rect displayRect) { |
Jorim Jaggi | c6c89a8 | 2016-01-28 17:48:21 -0800 | [diff] [blame] | 822 | |
| 823 | // Display rect without insets - available app space |
| 824 | Rect appRect = new Rect(displayRect); |
| 825 | appRect.inset(inOutInsets); |
| 826 | |
| 827 | // Our window intersected with available app space |
| 828 | Rect windowRectWithInsets = new Rect(windowRect); |
| 829 | windowRectWithInsets.intersect(appRect); |
| 830 | inOutInsets.left = windowRectWithInsets.left - windowRect.left; |
| 831 | inOutInsets.top = windowRectWithInsets.top - windowRect.top; |
| 832 | inOutInsets.right = windowRect.right - windowRectWithInsets.right; |
| 833 | inOutInsets.bottom = windowRect.bottom - windowRectWithInsets.bottom; |
| 834 | } |
| 835 | |
| 836 | /** |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 837 | * Preloads the icon of a task. |
| 838 | */ |
Winson | c4a038a | 2016-05-26 16:42:15 -0700 | [diff] [blame] | 839 | private void preloadIcon(int runningTaskId) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 840 | // Ensure that we load the running task's icon |
| 841 | RecentsTaskLoadPlan.Options launchOpts = new RecentsTaskLoadPlan.Options(); |
Winson | c4a038a | 2016-05-26 16:42:15 -0700 | [diff] [blame] | 842 | launchOpts.runningTaskId = runningTaskId; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 843 | launchOpts.loadThumbnails = false; |
| 844 | launchOpts.onlyLoadForCache = true; |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 845 | Recents.getTaskLoader().loadTasks(mContext, sInstanceLoadPlan, launchOpts); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | /** |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 849 | * Creates the activity options for a unknown state->recents transition. |
| 850 | */ |
Sid Soundararajan | 4bdb687 | 2016-03-18 13:42:10 -0700 | [diff] [blame] | 851 | protected ActivityOptions getUnknownTransitionActivityOptions() { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 852 | return ActivityOptions.makeCustomAnimation(mContext, |
| 853 | R.anim.recents_from_unknown_enter, |
| 854 | R.anim.recents_from_unknown_exit, |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 855 | mHandler, null); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | /** |
| 859 | * Creates the activity options for a home->recents transition. |
| 860 | */ |
Winson | 008ee15f | 2016-03-18 17:17:25 -0700 | [diff] [blame] | 861 | protected ActivityOptions getHomeTransitionActivityOptions() { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 862 | return ActivityOptions.makeCustomAnimation(mContext, |
| 863 | R.anim.recents_from_launcher_enter, |
| 864 | R.anim.recents_from_launcher_exit, |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 865 | mHandler, null); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | /** |
| 869 | * Creates the activity options for an app->recents transition. |
| 870 | */ |
Jorim Jaggi | ef496ea | 2017-05-13 23:16:44 +0200 | [diff] [blame] | 871 | private Pair<ActivityOptions, AppTransitionAnimationSpecsFuture> |
| 872 | getThumbnailTransitionActivityOptions(ActivityManager.RunningTaskInfo runningTask, |
| 873 | Rect windowOverrideRect) { |
Matthew Ng | c57b7f6 | 2017-08-10 15:37:19 -0700 | [diff] [blame] | 874 | final boolean isLowRamDevice = Recents.getConfiguration().isLowRamDevice; |
Winson | c4a038a | 2016-05-26 16:42:15 -0700 | [diff] [blame] | 875 | if (runningTask != null && runningTask.stackId == FREEFORM_WORKSPACE_STACK_ID) { |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 876 | ArrayList<AppTransitionAnimationSpec> specs = new ArrayList<>(); |
Winson Chung | 3e7e464 | 2017-08-22 10:08:06 -0700 | [diff] [blame] | 877 | ArrayList<Task> tasks = mDummyStackView.getStack().getStackTasks(); |
| 878 | TaskStackLayoutAlgorithm stackLayout = mDummyStackView.getStackAlgorithm(); |
| 879 | TaskStackViewScroller stackScroller = mDummyStackView.getScroller(); |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 880 | |
Winson Chung | 3e7e464 | 2017-08-22 10:08:06 -0700 | [diff] [blame] | 881 | mDummyStackView.updateLayoutAlgorithm(true /* boundScroll */); |
| 882 | mDummyStackView.updateToInitialState(); |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 883 | |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 884 | for (int i = tasks.size() - 1; i >= 0; i--) { |
| 885 | Task task = tasks.get(i); |
Winson | 387aac6 | 2015-11-25 11:18:56 -0800 | [diff] [blame] | 886 | if (task.isFreeformTask()) { |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 887 | mTmpTransform = stackLayout.getStackTransformScreenCoordinates(task, |
Jorim Jaggi | db21bbd | 2016-04-18 15:32:07 -0700 | [diff] [blame] | 888 | stackScroller.getStackScroll(), mTmpTransform, null, |
Jiaquan He | 26f637b | 2016-12-27 14:44:14 -0800 | [diff] [blame] | 889 | windowOverrideRect); |
Winson Chung | aa7fa01 | 2017-05-24 15:50:06 -0700 | [diff] [blame] | 890 | GraphicBuffer thumbnail = drawThumbnailTransitionBitmap(task, mTmpTransform); |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 891 | Rect toTaskRect = new Rect(); |
| 892 | mTmpTransform.rect.round(toTaskRect); |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 893 | specs.add(new AppTransitionAnimationSpec(task.key.id, thumbnail, toTaskRect)); |
| 894 | } |
| 895 | } |
| 896 | AppTransitionAnimationSpec[] specsArray = new AppTransitionAnimationSpec[specs.size()]; |
| 897 | specs.toArray(specsArray); |
Matthew Ng | 912c7f7 | 2017-08-02 22:12:04 +0000 | [diff] [blame] | 898 | |
Matthew Ng | c57b7f6 | 2017-08-10 15:37:19 -0700 | [diff] [blame] | 899 | // For low end ram devices, wait for transition flag is reset when Recents entrance |
| 900 | // animation is complete instead of when the transition animation starts |
Jorim Jaggi | ef496ea | 2017-05-13 23:16:44 +0200 | [diff] [blame] | 901 | return new Pair<>(ActivityOptions.makeThumbnailAspectScaleDownAnimation(mDummyStackView, |
Matthew Ng | c57b7f6 | 2017-08-10 15:37:19 -0700 | [diff] [blame] | 902 | specsArray, mHandler, isLowRamDevice ? null : mResetToggleFlagListener, this), |
| 903 | null); |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 904 | } else { |
| 905 | // Update the destination rect |
| 906 | Task toTask = new Task(); |
Winson Chung | f3cfa89 | 2017-04-24 12:23:47 -0700 | [diff] [blame] | 907 | TaskViewTransform toTransform = getThumbnailTransitionTransform(mDummyStackView, toTask, |
Jorim Jaggi | db21bbd | 2016-04-18 15:32:07 -0700 | [diff] [blame] | 908 | windowOverrideRect); |
Jorim Jaggi | ef496ea | 2017-05-13 23:16:44 +0200 | [diff] [blame] | 909 | |
| 910 | RectF toTaskRect = toTransform.rect; |
| 911 | AppTransitionAnimationSpecsFuture future = |
| 912 | new RecentsTransitionHelper(mContext).getAppTransitionFuture( |
| 913 | () -> { |
| 914 | Rect rect = new Rect(); |
| 915 | toTaskRect.round(rect); |
Winson Chung | aa7fa01 | 2017-05-24 15:50:06 -0700 | [diff] [blame] | 916 | GraphicBuffer thumbnail = drawThumbnailTransitionBitmap(toTask, |
| 917 | toTransform); |
Jorim Jaggi | ef496ea | 2017-05-13 23:16:44 +0200 | [diff] [blame] | 918 | return Lists.newArrayList(new AppTransitionAnimationSpec( |
| 919 | toTask.key.id, thumbnail, rect)); |
| 920 | }); |
Matthew Ng | 912c7f7 | 2017-08-02 22:12:04 +0000 | [diff] [blame] | 921 | |
Matthew Ng | c57b7f6 | 2017-08-10 15:37:19 -0700 | [diff] [blame] | 922 | // For low end ram devices, wait for transition flag is reset when Recents entrance |
| 923 | // animation is complete instead of when the transition animation starts |
Jorim Jaggi | ef496ea | 2017-05-13 23:16:44 +0200 | [diff] [blame] | 924 | return new Pair<>(ActivityOptions.makeMultiThumbFutureAspectScaleAnimation(mContext, |
Matthew Ng | c57b7f6 | 2017-08-10 15:37:19 -0700 | [diff] [blame] | 925 | mHandler, future.getFuture(), isLowRamDevice ? null : mResetToggleFlagListener, |
| 926 | false /* scaleUp */), future); |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 927 | } |
| 928 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 929 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 930 | /** |
| 931 | * Returns the transition rect for the given task id. |
| 932 | */ |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 933 | private TaskViewTransform getThumbnailTransitionTransform(TaskStackView stackView, |
Jorim Jaggi | db21bbd | 2016-04-18 15:32:07 -0700 | [diff] [blame] | 934 | Task runningTaskOut, Rect windowOverrideRect) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 935 | // Find the running task in the TaskStack |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 936 | TaskStack stack = stackView.getStack(); |
Winson | 65c851e | 2016-01-20 12:43:35 -0800 | [diff] [blame] | 937 | Task launchTask = stack.getLaunchTarget(); |
| 938 | if (launchTask != null) { |
| 939 | runningTaskOut.copyFrom(launchTask); |
| 940 | } else { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 941 | // If no task is specified or we can not find the task just use the front most one |
Winson | 35a8b04 | 2016-01-22 09:41:09 -0800 | [diff] [blame] | 942 | launchTask = stack.getStackFrontMostTask(true /* includeFreeform */); |
Winson | 65c851e | 2016-01-20 12:43:35 -0800 | [diff] [blame] | 943 | runningTaskOut.copyFrom(launchTask); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | // Get the transform for the running task |
Winson | 003eda6 | 2016-03-11 14:56:00 -0800 | [diff] [blame] | 947 | stackView.updateLayoutAlgorithm(true /* boundScroll */); |
Winson | 67c7957 | 2016-04-13 14:02:18 -0700 | [diff] [blame] | 948 | stackView.updateToInitialState(); |
Winson | 7845e8c | 2016-03-29 10:23:19 -0700 | [diff] [blame] | 949 | stackView.getStackAlgorithm().getStackTransformScreenCoordinates(launchTask, |
Jiaquan He | 26f637b | 2016-12-27 14:44:14 -0800 | [diff] [blame] | 950 | stackView.getScroller().getStackScroll(), mTmpTransform, null, windowOverrideRect); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 951 | return mTmpTransform; |
| 952 | } |
| 953 | |
| 954 | /** |
| 955 | * Draws the header of a task used for the window animation into a bitmap. |
| 956 | */ |
Winson Chung | aa7fa01 | 2017-05-24 15:50:06 -0700 | [diff] [blame] | 957 | private GraphicBuffer drawThumbnailTransitionBitmap(Task toTask, |
| 958 | TaskViewTransform toTransform) { |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 959 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Winson Chung | 91c5bb0 | 2017-07-24 13:52:49 -0700 | [diff] [blame] | 960 | int width = (int) toTransform.rect.width(); |
| 961 | int height = (int) toTransform.rect.height(); |
| 962 | if (toTransform != null && toTask.key != null && width > 0 && height > 0) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 963 | synchronized (mHeaderBarLock) { |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 964 | boolean disabledInSafeMode = !toTask.isSystemApp && ssp.isInSafeMode(); |
Winson Chung | aa7fa01 | 2017-05-24 15:50:06 -0700 | [diff] [blame] | 965 | mHeaderBar.onTaskViewSizeChanged(width, height); |
Winson | c742f97 | 2015-11-12 11:32:21 -0800 | [diff] [blame] | 966 | if (RecentsDebugFlags.Static.EnableTransitionThumbnailDebugMode) { |
Winson Chung | aa7fa01 | 2017-05-24 15:50:06 -0700 | [diff] [blame] | 967 | return RecentsTransitionHelper.drawViewIntoGraphicBuffer(width, mTaskBarHeight, |
| 968 | null, 1f, 0xFFff0000); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 969 | } else { |
Winson | 22574af | 2016-03-23 19:00:28 -0700 | [diff] [blame] | 970 | // Workaround for b/27815919, reset the callback so that we do not trigger an |
| 971 | // invalidate on the header bar as a result of updating the icon |
| 972 | Drawable icon = mHeaderBar.getIconView().getDrawable(); |
| 973 | if (icon != null) { |
| 974 | icon.setCallback(null); |
| 975 | } |
Winson | d2a0306 | 2016-04-15 11:19:07 -0700 | [diff] [blame] | 976 | mHeaderBar.bindToTask(toTask, false /* touchExplorationEnabled */, |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 977 | disabledInSafeMode); |
Winson | d2a0306 | 2016-04-15 11:19:07 -0700 | [diff] [blame] | 978 | mHeaderBar.onTaskDataLoaded(); |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 979 | mHeaderBar.setDimAlpha(toTransform.dimAlpha); |
Winson Chung | aa7fa01 | 2017-05-24 15:50:06 -0700 | [diff] [blame] | 980 | return RecentsTransitionHelper.drawViewIntoGraphicBuffer(width, mTaskBarHeight, |
| 981 | mHeaderBar, 1f, 0); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 982 | } |
| 983 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 984 | } |
| 985 | return null; |
| 986 | } |
| 987 | |
| 988 | /** |
| 989 | * Shows the recents activity |
| 990 | */ |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 991 | protected void startRecentsActivity(ActivityManager.RunningTaskInfo runningTask, |
| 992 | boolean isHomeStackVisible, boolean animate, int growTarget) { |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 993 | RecentsTaskLoader loader = Recents.getTaskLoader(); |
Winson | c5b12dd | 2016-03-23 20:25:12 -0700 | [diff] [blame] | 994 | RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState(); |
Winson | fc73eec | 2016-08-01 15:48:34 -0700 | [diff] [blame] | 995 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 996 | boolean isBlacklisted = (runningTask != null) |
| 997 | ? ssp.isBlackListedActivity(runningTask.baseActivity.getClassName()) |
| 998 | : false; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 999 | |
Winson | fc73eec | 2016-08-01 15:48:34 -0700 | [diff] [blame] | 1000 | int runningTaskId = !mLaunchedWhileDocking && !isBlacklisted && (runningTask != null) |
Winson | c4a038a | 2016-05-26 16:42:15 -0700 | [diff] [blame] | 1001 | ? runningTask.id |
| 1002 | : -1; |
| 1003 | |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 1004 | // In the case where alt-tab is triggered, we never get a preloadRecents() call, so we |
Jorim Jaggi | 435b2e4 | 2015-11-24 15:09:30 -0800 | [diff] [blame] | 1005 | // should always preload the tasks now. If we are dragging in recents, reload them as |
| 1006 | // the stacks might have changed. |
Winson | fc73eec | 2016-08-01 15:48:34 -0700 | [diff] [blame] | 1007 | if (mLaunchedWhileDocking || mTriggeredFromAltTab || sInstanceLoadPlan == null) { |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 1008 | // Create a new load plan if preloadRecents() was never triggered |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 1009 | sInstanceLoadPlan = loader.createLoadPlan(mContext); |
| 1010 | } |
Jorim Jaggi | e161f08 | 2016-02-05 14:26:16 -0800 | [diff] [blame] | 1011 | if (mLaunchedWhileDocking || mTriggeredFromAltTab || !sInstanceLoadPlan.hasTasks()) { |
Winson | c4a038a | 2016-05-26 16:42:15 -0700 | [diff] [blame] | 1012 | loader.preloadTasks(sInstanceLoadPlan, runningTaskId, !isHomeStackVisible); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 1013 | } |
Winson | c5b12dd | 2016-03-23 20:25:12 -0700 | [diff] [blame] | 1014 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 1015 | TaskStack stack = sInstanceLoadPlan.getTaskStack(); |
Winson | c5b12dd | 2016-03-23 20:25:12 -0700 | [diff] [blame] | 1016 | boolean hasRecentTasks = stack.getTaskCount() > 0; |
Winson | fc73eec | 2016-08-01 15:48:34 -0700 | [diff] [blame] | 1017 | boolean useThumbnailTransition = (runningTask != null) && !isHomeStackVisible && |
| 1018 | hasRecentTasks; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 1019 | |
Winson | aeb298c | 2016-04-05 13:08:11 -0700 | [diff] [blame] | 1020 | // Update the launch state that we need in updateHeaderBarLayout() |
Jorim Jaggi | c5887ea | 2016-05-13 18:21:48 -0700 | [diff] [blame] | 1021 | launchState.launchedFromHome = !useThumbnailTransition && !mLaunchedWhileDocking; |
Winson | aeb298c | 2016-04-05 13:08:11 -0700 | [diff] [blame] | 1022 | launchState.launchedFromApp = useThumbnailTransition || mLaunchedWhileDocking; |
Winson | fc73eec | 2016-08-01 15:48:34 -0700 | [diff] [blame] | 1023 | launchState.launchedFromBlacklistedApp = launchState.launchedFromApp && isBlacklisted; |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 1024 | launchState.launchedFromPipApp = false; |
| 1025 | launchState.launchedWithNextPipApp = |
| 1026 | stack.isNextLaunchTargetPip(RecentsImpl.getLastPipTime()); |
Winson | aeb298c | 2016-04-05 13:08:11 -0700 | [diff] [blame] | 1027 | launchState.launchedViaDockGesture = mLaunchedWhileDocking; |
| 1028 | launchState.launchedViaDragGesture = mDraggingInRecents; |
Winson | c4a038a | 2016-05-26 16:42:15 -0700 | [diff] [blame] | 1029 | launchState.launchedToTaskId = runningTaskId; |
Winson | aeb298c | 2016-04-05 13:08:11 -0700 | [diff] [blame] | 1030 | launchState.launchedWithAltTab = mTriggeredFromAltTab; |
| 1031 | |
Matthew Ng | 912c7f7 | 2017-08-02 22:12:04 +0000 | [diff] [blame] | 1032 | // Disable toggling of recents between starting the activity and it is visible and the app |
| 1033 | // has started its transition into recents. |
| 1034 | setWaitingForTransitionStart(useThumbnailTransition); |
| 1035 | |
Winson | aeb298c | 2016-04-05 13:08:11 -0700 | [diff] [blame] | 1036 | // Preload the icon (this will be a null-op if we have preloaded the icon already in |
| 1037 | // preloadRecents()) |
Winson | c4a038a | 2016-05-26 16:42:15 -0700 | [diff] [blame] | 1038 | preloadIcon(runningTaskId); |
Winson | aeb298c | 2016-04-05 13:08:11 -0700 | [diff] [blame] | 1039 | |
Winson | f0d1c44 | 2015-12-01 11:04:45 -0800 | [diff] [blame] | 1040 | // Update the header bar if necessary |
Jorim Jaggi | db21bbd | 2016-04-18 15:32:07 -0700 | [diff] [blame] | 1041 | Rect windowOverrideRect = getWindowRectOverride(growTarget); |
| 1042 | updateHeaderBarLayout(stack, windowOverrideRect); |
Winson | f0d1c44 | 2015-12-01 11:04:45 -0800 | [diff] [blame] | 1043 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 1044 | // Prepare the dummy stack for the transition |
Winson Chung | 3e7e464 | 2017-08-22 10:08:06 -0700 | [diff] [blame] | 1045 | TaskStackLayoutAlgorithm.VisibilityReport stackVr = |
| 1046 | mDummyStackView.computeStackVisibilityReport(); |
Jorim Jaggi | bb42a46 | 2015-11-20 16:27:16 -0800 | [diff] [blame] | 1047 | |
Winson | aeb298c | 2016-04-05 13:08:11 -0700 | [diff] [blame] | 1048 | // Update the remaining launch state |
Winson | c5b12dd | 2016-03-23 20:25:12 -0700 | [diff] [blame] | 1049 | launchState.launchedNumVisibleTasks = stackVr.numVisibleTasks; |
| 1050 | launchState.launchedNumVisibleThumbnails = stackVr.numVisibleThumbnails; |
Winson | c5b12dd | 2016-03-23 20:25:12 -0700 | [diff] [blame] | 1051 | |
Jorim Jaggi | bb42a46 | 2015-11-20 16:27:16 -0800 | [diff] [blame] | 1052 | if (!animate) { |
Jorim Jaggi | ef496ea | 2017-05-13 23:16:44 +0200 | [diff] [blame] | 1053 | startRecentsActivity(ActivityOptions.makeCustomAnimation(mContext, -1, -1), |
| 1054 | null /* future */); |
Jorim Jaggi | bb42a46 | 2015-11-20 16:27:16 -0800 | [diff] [blame] | 1055 | return; |
| 1056 | } |
| 1057 | |
Jorim Jaggi | ef496ea | 2017-05-13 23:16:44 +0200 | [diff] [blame] | 1058 | Pair<ActivityOptions, AppTransitionAnimationSpecsFuture> pair; |
Winson | fc73eec | 2016-08-01 15:48:34 -0700 | [diff] [blame] | 1059 | if (isBlacklisted) { |
Jorim Jaggi | ef496ea | 2017-05-13 23:16:44 +0200 | [diff] [blame] | 1060 | pair = new Pair<>(getUnknownTransitionActivityOptions(), null); |
Winson | fc73eec | 2016-08-01 15:48:34 -0700 | [diff] [blame] | 1061 | } else if (useThumbnailTransition) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 1062 | // Try starting with a thumbnail transition |
Jorim Jaggi | ef496ea | 2017-05-13 23:16:44 +0200 | [diff] [blame] | 1063 | pair = getThumbnailTransitionActivityOptions(runningTask, windowOverrideRect); |
Winson | aeb298c | 2016-04-05 13:08:11 -0700 | [diff] [blame] | 1064 | } else { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 1065 | // If there is no thumbnail transition, but is launching from home into recents, then |
Winson | 008ee15f | 2016-03-18 17:17:25 -0700 | [diff] [blame] | 1066 | // use a quick home transition |
Jorim Jaggi | ef496ea | 2017-05-13 23:16:44 +0200 | [diff] [blame] | 1067 | pair = new Pair<>(hasRecentTasks |
| 1068 | ? getHomeTransitionActivityOptions() |
| 1069 | : getUnknownTransitionActivityOptions(), null); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 1070 | } |
Jorim Jaggi | ef496ea | 2017-05-13 23:16:44 +0200 | [diff] [blame] | 1071 | startRecentsActivity(pair.first, pair.second); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 1072 | mLastToggleTime = SystemClock.elapsedRealtime(); |
| 1073 | } |
| 1074 | |
Jorim Jaggi | db21bbd | 2016-04-18 15:32:07 -0700 | [diff] [blame] | 1075 | private Rect getWindowRectOverride(int growTarget) { |
| 1076 | if (growTarget == DividerView.INVALID_RECENTS_GROW_TARGET) { |
Jorim Jaggi | ef496ea | 2017-05-13 23:16:44 +0200 | [diff] [blame] | 1077 | return SystemServicesProxy.getInstance(mContext).getWindowRect(); |
Jorim Jaggi | db21bbd | 2016-04-18 15:32:07 -0700 | [diff] [blame] | 1078 | } |
| 1079 | Rect result = new Rect(); |
| 1080 | Rect displayRect = Recents.getSystemServices().getDisplayRect(); |
| 1081 | DockedDividerUtils.calculateBoundsForPosition(growTarget, WindowManager.DOCKED_BOTTOM, |
| 1082 | result, displayRect.width(), displayRect.height(), |
| 1083 | Recents.getSystemServices().getDockedDividerSize(mContext)); |
| 1084 | return result; |
| 1085 | } |
| 1086 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 1087 | /** |
| 1088 | * Starts the recents activity. |
| 1089 | */ |
Jorim Jaggi | ef496ea | 2017-05-13 23:16:44 +0200 | [diff] [blame] | 1090 | private void startRecentsActivity(ActivityOptions opts, |
| 1091 | final AppTransitionAnimationSpecsFuture future) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 1092 | Intent intent = new Intent(); |
Sid Soundararajan | 4bdb687 | 2016-03-18 13:42:10 -0700 | [diff] [blame] | 1093 | intent.setClassName(RECENTS_PACKAGE, RECENTS_ACTIVITY); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 1094 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1095 | | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS |
| 1096 | | Intent.FLAG_ACTIVITY_TASK_ON_HOME); |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 1097 | HidePipMenuEvent hideMenuEvent = new HidePipMenuEvent(); |
| 1098 | hideMenuEvent.addPostAnimationCallback(() -> { |
Jorim Jaggi | ef496ea | 2017-05-13 23:16:44 +0200 | [diff] [blame] | 1099 | Recents.getSystemServices().startActivityAsUserAsync(intent, opts); |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 1100 | EventBus.getDefault().send(new RecentsActivityStartingEvent()); |
Jorim Jaggi | ef496ea | 2017-05-13 23:16:44 +0200 | [diff] [blame] | 1101 | if (future != null) { |
| 1102 | future.precacheSpecs(); |
| 1103 | } |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 1104 | }); |
| 1105 | EventBus.getDefault().send(hideMenuEvent); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 1106 | } |
| 1107 | |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 1108 | /**** OnAnimationFinishedListener Implementation ****/ |
Filip Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 1109 | |
| 1110 | @Override |
| 1111 | public void onAnimationFinished() { |
| 1112 | EventBus.getDefault().post(new EnterRecentsWindowLastAnimationFrameEvent()); |
| 1113 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 1114 | } |