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