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