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