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