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