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