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