RecentsImpl.java revision 670ea71f1b4ae59a0cd6608ae44b0fb78a1144c4
1190fe3bf88388fcb109af64571e3baa0d01f1c37Winson/* 2190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * Copyright (C) 2015 The Android Open Source Project 3190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * 4190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * Licensed under the Apache License, Version 2.0 (the "License"); 5190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * you may not use this file except in compliance with the License. 6190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * You may obtain a copy of the License at 7190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * 8190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * http://www.apache.org/licenses/LICENSE-2.0 9190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * 10190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * Unless required by applicable law or agreed to in writing, software 11190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * distributed under the License is distributed on an "AS IS" BASIS, 12190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * See the License for the specific language governing permissions and 14190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * limitations under the License. 15190fe3bf88388fcb109af64571e3baa0d01f1c37Winson */ 16190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 17190fe3bf88388fcb109af64571e3baa0d01f1c37Winsonpackage com.android.systemui.recents; 18190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 19e693aafe0511c2a7ffc571b22abeefba44046225Winsonimport static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; 2094bc4f2238d8eefb77c63a560aa0de1335ee57abWinsonimport static android.view.View.MeasureSpec; 21e693aafe0511c2a7ffc571b22abeefba44046225Winson 22190fe3bf88388fcb109af64571e3baa0d01f1c37Winsonimport android.app.ActivityManager; 23190fe3bf88388fcb109af64571e3baa0d01f1c37Winsonimport android.app.ActivityOptions; 24190fe3bf88388fcb109af64571e3baa0d01f1c37Winsonimport android.content.ActivityNotFoundException; 25190fe3bf88388fcb109af64571e3baa0d01f1c37Winsonimport android.content.Context; 26190fe3bf88388fcb109af64571e3baa0d01f1c37Winsonimport android.content.Intent; 27190fe3bf88388fcb109af64571e3baa0d01f1c37Winsonimport android.content.res.Resources; 28190fe3bf88388fcb109af64571e3baa0d01f1c37Winsonimport android.graphics.Bitmap; 29190fe3bf88388fcb109af64571e3baa0d01f1c37Winsonimport android.graphics.Canvas; 30190fe3bf88388fcb109af64571e3baa0d01f1c37Winsonimport android.graphics.Rect; 313150e574e6e903a17193e0b90433d69c0e20ae4cWinsonimport android.graphics.RectF; 3222574afa00b7e32b7c4c5a1b98deebd67751b364Winsonimport android.graphics.drawable.Drawable; 33190fe3bf88388fcb109af64571e3baa0d01f1c37Winsonimport android.os.Handler; 34190fe3bf88388fcb109af64571e3baa0d01f1c37Winsonimport android.os.SystemClock; 35190fe3bf88388fcb109af64571e3baa0d01f1c37Winsonimport android.os.UserHandle; 361b58561f66a9453754b1b419296899fdc08b4c93Winsonimport android.util.Log; 37190fe3bf88388fcb109af64571e3baa0d01f1c37Winsonimport android.util.MutableBoolean; 38d64ef3ef33c50a03b4be3b2baaa93aab7319fca8Filip Gruszczynskiimport android.view.AppTransitionAnimationSpec; 39190fe3bf88388fcb109af64571e3baa0d01f1c37Winsonimport android.view.LayoutInflater; 40b61e654b9a46e79827355104760a3ac5228380bcWinsonimport android.view.ViewConfiguration; 41c0d7058b14c24cd07912f5629c26b39b7b4673d5Winson 42190fe3bf88388fcb109af64571e3baa0d01f1c37Winsonimport com.android.internal.logging.MetricsLogger; 43190fe3bf88388fcb109af64571e3baa0d01f1c37Winsonimport com.android.systemui.R; 44190fe3bf88388fcb109af64571e3baa0d01f1c37Winsonimport com.android.systemui.SystemUIApplication; 45412e18058dc2cd5779d2451fce7fd74631f9e237Winsonimport com.android.systemui.recents.events.EventBus; 46899327f5cbbfb0eae5562b262ccea860c98f6bc4Jorim Jaggiimport com.android.systemui.recents.events.activity.DockedTopTaskEvent; 471b58561f66a9453754b1b419296899fdc08b4c93Winsonimport com.android.systemui.recents.events.activity.EnterRecentsWindowLastAnimationFrameEvent; 48412e18058dc2cd5779d2451fce7fd74631f9e237Winsonimport com.android.systemui.recents.events.activity.HideRecentsEvent; 490d14d4da91c3d8b1221269712d5abf43a7cf9f31Winsonimport com.android.systemui.recents.events.activity.IterateRecentsEvent; 50b61e654b9a46e79827355104760a3ac5228380bcWinsonimport com.android.systemui.recents.events.activity.LaunchNextTaskRequestEvent; 51cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggiimport com.android.systemui.recents.events.activity.RecentsActivityStartingEvent; 52412e18058dc2cd5779d2451fce7fd74631f9e237Winsonimport com.android.systemui.recents.events.activity.ToggleRecentsEvent; 53190fe3bf88388fcb109af64571e3baa0d01f1c37Winsonimport com.android.systemui.recents.events.component.RecentsVisibilityChangedEvent; 54190fe3bf88388fcb109af64571e3baa0d01f1c37Winsonimport com.android.systemui.recents.events.component.ScreenPinningRequestEvent; 55dd98d41e3a65b3bcb37007ea5b29371cf013f563Jorim Jaggiimport com.android.systemui.recents.events.ui.DraggingInRecentsEndedEvent; 56dd98d41e3a65b3bcb37007ea5b29371cf013f563Jorim Jaggiimport com.android.systemui.recents.events.ui.DraggingInRecentsEvent; 576b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinsonimport com.android.systemui.recents.misc.DozeTrigger; 58ab84fc56114c0963c6f701de9725f5413ab76da9Winsonimport com.android.systemui.recents.misc.ForegroundThread; 59190fe3bf88388fcb109af64571e3baa0d01f1c37Winsonimport com.android.systemui.recents.misc.SystemServicesProxy; 60938a50b424eb73ee96d34c96b5e2cbd11f733d7aJaewan Kimimport com.android.systemui.recents.misc.SystemServicesProxy.TaskStackListener; 61190fe3bf88388fcb109af64571e3baa0d01f1c37Winsonimport com.android.systemui.recents.model.RecentsTaskLoadPlan; 62190fe3bf88388fcb109af64571e3baa0d01f1c37Winsonimport com.android.systemui.recents.model.RecentsTaskLoader; 63190fe3bf88388fcb109af64571e3baa0d01f1c37Winsonimport com.android.systemui.recents.model.Task; 64190fe3bf88388fcb109af64571e3baa0d01f1c37Winsonimport com.android.systemui.recents.model.TaskGrouping; 65190fe3bf88388fcb109af64571e3baa0d01f1c37Winsonimport com.android.systemui.recents.model.TaskStack; 6636a5a2c7003ef8157f276b411c3fda47ad2f75e3Winsonimport com.android.systemui.recents.views.TaskStackLayoutAlgorithm; 671b58561f66a9453754b1b419296899fdc08b4c93Winsonimport com.android.systemui.recents.views.TaskStackView; 68e693aafe0511c2a7ffc571b22abeefba44046225Winsonimport com.android.systemui.recents.views.TaskStackViewScroller; 69190fe3bf88388fcb109af64571e3baa0d01f1c37Winsonimport com.android.systemui.recents.views.TaskViewHeader; 70190fe3bf88388fcb109af64571e3baa0d01f1c37Winsonimport com.android.systemui.recents.views.TaskViewTransform; 71d8b1d63f96580fe961e1751e7b4f56c90c1e0a76Winsonimport com.android.systemui.statusbar.BaseStatusBar; 72cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggiimport com.android.systemui.statusbar.phone.NavigationBarGestureHelper; 73190fe3bf88388fcb109af64571e3baa0d01f1c37Winsonimport com.android.systemui.statusbar.phone.PhoneStatusBar; 74190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 75190fe3bf88388fcb109af64571e3baa0d01f1c37Winsonimport java.util.ArrayList; 76190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 77190fe3bf88388fcb109af64571e3baa0d01f1c37Winson/** 78190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * An implementation of the Recents component for the current user. For secondary users, this can 79190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * be called remotely from the system user. 80190fe3bf88388fcb109af64571e3baa0d01f1c37Winson */ 81cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggipublic class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener { 82190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 83190fe3bf88388fcb109af64571e3baa0d01f1c37Winson private final static String TAG = "RecentsImpl"; 84b61e654b9a46e79827355104760a3ac5228380bcWinson 856b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson // The minimum amount of time between each recents button press that we will handle 866b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson private final static int MIN_TOGGLE_DELAY_MS = 350; 87b61e654b9a46e79827355104760a3ac5228380bcWinson 886b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson // The duration within which the user releasing the alt tab (from when they pressed alt tab) 896b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson // that the fast alt-tab animation will run. If the user's alt-tab takes longer than this 906b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson // duration, then we will toggle recents after this duration. 916b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson private final static int FAST_ALT_TAB_DELAY_MS = 225; 92190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 93190fe3bf88388fcb109af64571e3baa0d01f1c37Winson public final static String RECENTS_PACKAGE = "com.android.systemui"; 94190fe3bf88388fcb109af64571e3baa0d01f1c37Winson public final static String RECENTS_ACTIVITY = "com.android.systemui.recents.RecentsActivity"; 95e693aafe0511c2a7ffc571b22abeefba44046225Winson 96190fe3bf88388fcb109af64571e3baa0d01f1c37Winson /** 97938a50b424eb73ee96d34c96b5e2cbd11f733d7aJaewan Kim * An implementation of TaskStackListener, that allows us to listen for changes to the system 98190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * task stacks and update recents accordingly. 99190fe3bf88388fcb109af64571e3baa0d01f1c37Winson */ 100938a50b424eb73ee96d34c96b5e2cbd11f733d7aJaewan Kim class TaskStackListenerImpl extends TaskStackListener { 101190fe3bf88388fcb109af64571e3baa0d01f1c37Winson @Override 102190fe3bf88388fcb109af64571e3baa0d01f1c37Winson public void onTaskStackChanged() { 103938a50b424eb73ee96d34c96b5e2cbd11f733d7aJaewan Kim // Preloads the next task 104a0fdeec66caa4d70786c7f6f31f79a24eef9da10Jorim Jaggi RecentsConfiguration config = Recents.getConfiguration(); 105190fe3bf88388fcb109af64571e3baa0d01f1c37Winson if (config.svelteLevel == RecentsConfiguration.SVELTE_NONE) { 106e7f138c7f0a190c86cec10fb32fa106aacae4093Winson RecentsTaskLoader loader = Recents.getTaskLoader(); 107e7f138c7f0a190c86cec10fb32fa106aacae4093Winson SystemServicesProxy ssp = Recents.getSystemServices(); 108190fe3bf88388fcb109af64571e3baa0d01f1c37Winson ActivityManager.RunningTaskInfo runningTaskInfo = ssp.getTopMostTask(); 109190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 110190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // Load the next task only if we aren't svelte 111190fe3bf88388fcb109af64571e3baa0d01f1c37Winson RecentsTaskLoadPlan plan = loader.createLoadPlan(mContext); 11265c851e6e9e08656744b6f66d3da188e3283b17dWinson loader.preloadTasks(plan, -1, true /* isTopTaskHome */); 113190fe3bf88388fcb109af64571e3baa0d01f1c37Winson RecentsTaskLoadPlan.Options launchOpts = new RecentsTaskLoadPlan.Options(); 114190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // This callback is made when a new activity is launched and the old one is paused 115190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // so ignore the current activity and try and preload the thumbnail for the 116190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // previous one. 117190fe3bf88388fcb109af64571e3baa0d01f1c37Winson if (runningTaskInfo != null) { 118190fe3bf88388fcb109af64571e3baa0d01f1c37Winson launchOpts.runningTaskId = runningTaskInfo.id; 119190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 120190fe3bf88388fcb109af64571e3baa0d01f1c37Winson launchOpts.numVisibleTasks = 2; 121190fe3bf88388fcb109af64571e3baa0d01f1c37Winson launchOpts.numVisibleTaskThumbnails = 2; 122190fe3bf88388fcb109af64571e3baa0d01f1c37Winson launchOpts.onlyLoadForCache = true; 123190fe3bf88388fcb109af64571e3baa0d01f1c37Winson launchOpts.onlyLoadPausedActivities = true; 124190fe3bf88388fcb109af64571e3baa0d01f1c37Winson loader.loadTasks(mContext, plan, launchOpts); 125190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 126190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 127190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 128190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 1294bdb6879bd5f1b7e93e7e9ac236a073921862075Sid Soundararajan protected static RecentsTaskLoadPlan sInstanceLoadPlan; 130190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 1314bdb6879bd5f1b7e93e7e9ac236a073921862075Sid Soundararajan protected Context mContext; 1324bdb6879bd5f1b7e93e7e9ac236a073921862075Sid Soundararajan protected Handler mHandler; 133190fe3bf88388fcb109af64571e3baa0d01f1c37Winson TaskStackListenerImpl mTaskStackListener; 134dd98d41e3a65b3bcb37007ea5b29371cf013f563Jorim Jaggi boolean mDraggingInRecents; 135e161f08e98fdbe6fe83f70ffa1ea11142a027ebeJorim Jaggi boolean mLaunchedWhileDocking; 136190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 137190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // Task launching 138190fe3bf88388fcb109af64571e3baa0d01f1c37Winson Rect mTaskStackBounds = new Rect(); 139190fe3bf88388fcb109af64571e3baa0d01f1c37Winson TaskViewTransform mTmpTransform = new TaskViewTransform(); 140190fe3bf88388fcb109af64571e3baa0d01f1c37Winson int mStatusBarHeight; 141190fe3bf88388fcb109af64571e3baa0d01f1c37Winson int mNavBarHeight; 142190fe3bf88388fcb109af64571e3baa0d01f1c37Winson int mNavBarWidth; 143190fe3bf88388fcb109af64571e3baa0d01f1c37Winson int mTaskBarHeight; 144190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 145190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // Header (for transition) 146190fe3bf88388fcb109af64571e3baa0d01f1c37Winson TaskViewHeader mHeaderBar; 147190fe3bf88388fcb109af64571e3baa0d01f1c37Winson final Object mHeaderBarLock = new Object(); 1484bdb6879bd5f1b7e93e7e9ac236a073921862075Sid Soundararajan protected TaskStackView mDummyStackView; 149190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 150190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // Variables to keep track of if we need to start recents after binding 1514bdb6879bd5f1b7e93e7e9ac236a073921862075Sid Soundararajan protected boolean mTriggeredFromAltTab; 1524bdb6879bd5f1b7e93e7e9ac236a073921862075Sid Soundararajan protected long mLastToggleTime; 1536b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson DozeTrigger mFastAltTabTrigger = new DozeTrigger(FAST_ALT_TAB_DELAY_MS, new Runnable() { 1546b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson @Override 1556b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson public void run() { 1566b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson // When this fires, then the user has not released alt-tab for at least 1576b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson // FAST_ALT_TAB_DELAY_MS milliseconds 158435b2e43cb131d0b38ba19f335aec78bb83944b2Jorim Jaggi showRecents(mTriggeredFromAltTab, false /* draggingInRecents */, true /* animate */, 159435b2e43cb131d0b38ba19f335aec78bb83944b2Jorim Jaggi false /* reloadTasks */); 1606b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson } 1616b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson }); 162190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 163aeb298c4db913b376fb6053ec30c132a93e04635Winson protected Bitmap mThumbTransitionBitmapCache; 164190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 165190fe3bf88388fcb109af64571e3baa0d01f1c37Winson public RecentsImpl(Context context) { 166190fe3bf88388fcb109af64571e3baa0d01f1c37Winson mContext = context; 167190fe3bf88388fcb109af64571e3baa0d01f1c37Winson mHandler = new Handler(); 168190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 169ab84fc56114c0963c6f701de9725f5413ab76da9Winson // Initialize the static foreground thread 170ab84fc56114c0963c6f701de9725f5413ab76da9Winson ForegroundThread.get(); 171ab84fc56114c0963c6f701de9725f5413ab76da9Winson 172190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // Register the task stack listener 173938a50b424eb73ee96d34c96b5e2cbd11f733d7aJaewan Kim mTaskStackListener = new TaskStackListenerImpl(); 174e7f138c7f0a190c86cec10fb32fa106aacae4093Winson SystemServicesProxy ssp = Recents.getSystemServices(); 175e7f138c7f0a190c86cec10fb32fa106aacae4093Winson ssp.registerTaskStackListener(mTaskStackListener); 176190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 177190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // Initialize the static configuration resources 178670ea71f1b4ae59a0cd6608ae44b0fb78a1144c4Winson LayoutInflater inflater = LayoutInflater.from(mContext); 179670ea71f1b4ae59a0cd6608ae44b0fb78a1144c4Winson mDummyStackView = new TaskStackView(mContext); 180670ea71f1b4ae59a0cd6608ae44b0fb78a1144c4Winson mHeaderBar = (TaskViewHeader) inflater.inflate(R.layout.recents_task_view_header, 181670ea71f1b4ae59a0cd6608ae44b0fb78a1144c4Winson null, false); 182670ea71f1b4ae59a0cd6608ae44b0fb78a1144c4Winson reloadResources(); 183190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 184190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // When we start, preload the data associated with the previous recent tasks. 185190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // We can use a new plan since the caches will be the same. 186e7f138c7f0a190c86cec10fb32fa106aacae4093Winson RecentsTaskLoader loader = Recents.getTaskLoader(); 187190fe3bf88388fcb109af64571e3baa0d01f1c37Winson RecentsTaskLoadPlan plan = loader.createLoadPlan(mContext); 18865c851e6e9e08656744b6f66d3da188e3283b17dWinson loader.preloadTasks(plan, -1, true /* isTopTaskHome */); 189190fe3bf88388fcb109af64571e3baa0d01f1c37Winson RecentsTaskLoadPlan.Options launchOpts = new RecentsTaskLoadPlan.Options(); 190296278a0679375b8c43962a9e3c9bb4e8ab201e7Winson Chung launchOpts.numVisibleTasks = loader.getIconCacheSize(); 191190fe3bf88388fcb109af64571e3baa0d01f1c37Winson launchOpts.numVisibleTaskThumbnails = loader.getThumbnailCacheSize(); 192190fe3bf88388fcb109af64571e3baa0d01f1c37Winson launchOpts.onlyLoadForCache = true; 193190fe3bf88388fcb109af64571e3baa0d01f1c37Winson loader.loadTasks(mContext, plan, launchOpts); 194190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 195190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 196190fe3bf88388fcb109af64571e3baa0d01f1c37Winson public void onBootCompleted() { 197aeb298c4db913b376fb6053ec30c132a93e04635Winson // Do nothing 198190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 199190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 200190fe3bf88388fcb109af64571e3baa0d01f1c37Winson public void onConfigurationChanged() { 201670ea71f1b4ae59a0cd6608ae44b0fb78a1144c4Winson reloadResources(); 202670ea71f1b4ae59a0cd6608ae44b0fb78a1144c4Winson mDummyStackView.reloadOnConfigurationChange(); 203670ea71f1b4ae59a0cd6608ae44b0fb78a1144c4Winson mHeaderBar.onConfigurationChanged(); 204190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 205190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 206190fe3bf88388fcb109af64571e3baa0d01f1c37Winson /** 207190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * This is only called from the system user's Recents. Secondary users will instead proxy their 208190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * visibility change events through to the system user via 209190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * {@link Recents#onBusEvent(RecentsVisibilityChangedEvent)}. 210190fe3bf88388fcb109af64571e3baa0d01f1c37Winson */ 211190fe3bf88388fcb109af64571e3baa0d01f1c37Winson public void onVisibilityChanged(Context context, boolean visible) { 212190fe3bf88388fcb109af64571e3baa0d01f1c37Winson SystemUIApplication app = (SystemUIApplication) context; 213190fe3bf88388fcb109af64571e3baa0d01f1c37Winson PhoneStatusBar statusBar = app.getComponent(PhoneStatusBar.class); 214190fe3bf88388fcb109af64571e3baa0d01f1c37Winson if (statusBar != null) { 215190fe3bf88388fcb109af64571e3baa0d01f1c37Winson statusBar.updateRecentsVisibility(visible); 216190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 217190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 218190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 219190fe3bf88388fcb109af64571e3baa0d01f1c37Winson /** 220190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * This is only called from the system user's Recents. Secondary users will instead proxy their 221190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * visibility change events through to the system user via 222190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * {@link Recents#onBusEvent(ScreenPinningRequestEvent)}. 223190fe3bf88388fcb109af64571e3baa0d01f1c37Winson */ 224190fe3bf88388fcb109af64571e3baa0d01f1c37Winson public void onStartScreenPinning(Context context) { 225190fe3bf88388fcb109af64571e3baa0d01f1c37Winson SystemUIApplication app = (SystemUIApplication) context; 226190fe3bf88388fcb109af64571e3baa0d01f1c37Winson PhoneStatusBar statusBar = app.getComponent(PhoneStatusBar.class); 227190fe3bf88388fcb109af64571e3baa0d01f1c37Winson if (statusBar != null) { 228190fe3bf88388fcb109af64571e3baa0d01f1c37Winson statusBar.showScreenPinningRequest(false); 229190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 230190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 231190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 232bb42a46631b4cecdd03bd628feeb8270d412ebd3Jorim Jaggi public void showRecents(boolean triggeredFromAltTab, boolean draggingInRecents, 233e161f08e98fdbe6fe83f70ffa1ea11142a027ebeJorim Jaggi boolean animate, boolean launchedWhileDockingTask) { 234190fe3bf88388fcb109af64571e3baa0d01f1c37Winson mTriggeredFromAltTab = triggeredFromAltTab; 235dd98d41e3a65b3bcb37007ea5b29371cf013f563Jorim Jaggi mDraggingInRecents = draggingInRecents; 236e161f08e98fdbe6fe83f70ffa1ea11142a027ebeJorim Jaggi mLaunchedWhileDocking = launchedWhileDockingTask; 237e693aafe0511c2a7ffc571b22abeefba44046225Winson if (mFastAltTabTrigger.isAsleep()) { 238e693aafe0511c2a7ffc571b22abeefba44046225Winson // Fast alt-tab duration has elapsed, fall through to showing Recents and reset 239e693aafe0511c2a7ffc571b22abeefba44046225Winson mFastAltTabTrigger.stopDozing(); 2406b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson } else if (mFastAltTabTrigger.isDozing()) { 241e693aafe0511c2a7ffc571b22abeefba44046225Winson // Fast alt-tab duration has not elapsed. If this is triggered by a different 242e693aafe0511c2a7ffc571b22abeefba44046225Winson // showRecents() call, then ignore that call for now. 243e693aafe0511c2a7ffc571b22abeefba44046225Winson // TODO: We can not handle quick tabs that happen between the initial showRecents() call 244e693aafe0511c2a7ffc571b22abeefba44046225Winson // that started the activity and the activity starting up. The severity of this 245e693aafe0511c2a7ffc571b22abeefba44046225Winson // is inversely proportional to the FAST_ALT_TAB_DELAY_MS duration though. 2466b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson if (!triggeredFromAltTab) { 2476b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson return; 2486b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson } 2496b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson mFastAltTabTrigger.stopDozing(); 250e693aafe0511c2a7ffc571b22abeefba44046225Winson } else if (triggeredFromAltTab) { 251e693aafe0511c2a7ffc571b22abeefba44046225Winson // The fast alt-tab detector is not yet running, so start the trigger and wait for the 252e693aafe0511c2a7ffc571b22abeefba44046225Winson // hideRecents() call, or for the fast alt-tab duration to elapse 253e693aafe0511c2a7ffc571b22abeefba44046225Winson mFastAltTabTrigger.startDozing(); 254e693aafe0511c2a7ffc571b22abeefba44046225Winson return; 2556b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson } 256190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 257190fe3bf88388fcb109af64571e3baa0d01f1c37Winson try { 258190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // Check if the top task is in the home stack, and start the recents activity 259e7f138c7f0a190c86cec10fb32fa106aacae4093Winson SystemServicesProxy ssp = Recents.getSystemServices(); 260e7f138c7f0a190c86cec10fb32fa106aacae4093Winson ActivityManager.RunningTaskInfo topTask = ssp.getTopMostTask(); 261190fe3bf88388fcb109af64571e3baa0d01f1c37Winson MutableBoolean isTopTaskHome = new MutableBoolean(true); 262e7f138c7f0a190c86cec10fb32fa106aacae4093Winson if (topTask == null || !ssp.isRecentsTopMost(topTask, isTopTaskHome)) { 263bb42a46631b4cecdd03bd628feeb8270d412ebd3Jorim Jaggi startRecentsActivity(topTask, isTopTaskHome.value, animate); 264190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 265190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } catch (ActivityNotFoundException e) { 2661b58561f66a9453754b1b419296899fdc08b4c93Winson Log.e(TAG, "Failed to launch RecentsActivity", e); 267190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 268190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 269190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 270190fe3bf88388fcb109af64571e3baa0d01f1c37Winson public void hideRecents(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) { 2712799eca21715390faf10596884b65165528f89c4Winson if (triggeredFromAltTab && mFastAltTabTrigger.isDozing()) { 2722799eca21715390faf10596884b65165528f89c4Winson // The user has released alt-tab before the trigger has run, so just show the next 2732799eca21715390faf10596884b65165528f89c4Winson // task immediately 2742799eca21715390faf10596884b65165528f89c4Winson showNextTask(); 2756b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson 2762799eca21715390faf10596884b65165528f89c4Winson // Cancel the fast alt-tab trigger 2772799eca21715390faf10596884b65165528f89c4Winson mFastAltTabTrigger.stopDozing(); 2782799eca21715390faf10596884b65165528f89c4Winson return; 279190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 2802799eca21715390faf10596884b65165528f89c4Winson 2812799eca21715390faf10596884b65165528f89c4Winson // Defer to the activity to handle hiding recents, if it handles it, then it must still 2822799eca21715390faf10596884b65165528f89c4Winson // be visible 2832799eca21715390faf10596884b65165528f89c4Winson EventBus.getDefault().post(new HideRecentsEvent(triggeredFromAltTab, 2842799eca21715390faf10596884b65165528f89c4Winson triggeredFromHomeKey)); 285190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 286190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 287190fe3bf88388fcb109af64571e3baa0d01f1c37Winson public void toggleRecents() { 2886b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson // Skip this toggle if we are already waiting to trigger recents via alt-tab 2896b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson if (mFastAltTabTrigger.isDozing()) { 2906b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson return; 2916b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson } 2926b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson 293dd98d41e3a65b3bcb37007ea5b29371cf013f563Jorim Jaggi mDraggingInRecents = false; 294e161f08e98fdbe6fe83f70ffa1ea11142a027ebeJorim Jaggi mLaunchedWhileDocking = false; 295190fe3bf88388fcb109af64571e3baa0d01f1c37Winson mTriggeredFromAltTab = false; 296190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 297190fe3bf88388fcb109af64571e3baa0d01f1c37Winson try { 298e7f138c7f0a190c86cec10fb32fa106aacae4093Winson SystemServicesProxy ssp = Recents.getSystemServices(); 299e7f138c7f0a190c86cec10fb32fa106aacae4093Winson ActivityManager.RunningTaskInfo topTask = ssp.getTopMostTask(); 300190fe3bf88388fcb109af64571e3baa0d01f1c37Winson MutableBoolean isTopTaskHome = new MutableBoolean(true); 301b61e654b9a46e79827355104760a3ac5228380bcWinson long elapsedTime = SystemClock.elapsedRealtime() - mLastToggleTime; 302b61e654b9a46e79827355104760a3ac5228380bcWinson 303e7f138c7f0a190c86cec10fb32fa106aacae4093Winson if (topTask != null && ssp.isRecentsTopMost(topTask, isTopTaskHome)) { 304e693aafe0511c2a7ffc571b22abeefba44046225Winson RecentsDebugFlags debugFlags = Recents.getDebugFlags(); 3055da4347b41b105dc6c6c01bf2810af3ce3013229Winson RecentsConfiguration config = Recents.getConfiguration(); 3065da4347b41b105dc6c6c01bf2810af3ce3013229Winson RecentsActivityLaunchState launchState = config.getLaunchState(); 307ead5c0fc20e5c60a68cd017af0b8eacaf1167a1cWinson Chung if (!launchState.launchedWithAltTab) { 308b61e654b9a46e79827355104760a3ac5228380bcWinson // If the user taps quickly 309e693aafe0511c2a7ffc571b22abeefba44046225Winson if (!debugFlags.isPagingEnabled() || 310e693aafe0511c2a7ffc571b22abeefba44046225Winson (ViewConfiguration.getDoubleTapMinTime() < elapsedTime && 311e693aafe0511c2a7ffc571b22abeefba44046225Winson elapsedTime < ViewConfiguration.getDoubleTapTimeout())) { 312b61e654b9a46e79827355104760a3ac5228380bcWinson // Launch the next focused task 313b61e654b9a46e79827355104760a3ac5228380bcWinson EventBus.getDefault().post(new LaunchNextTaskRequestEvent()); 314b61e654b9a46e79827355104760a3ac5228380bcWinson } else { 315b61e654b9a46e79827355104760a3ac5228380bcWinson // Notify recents to move onto the next task 316b61e654b9a46e79827355104760a3ac5228380bcWinson EventBus.getDefault().post(new IterateRecentsEvent()); 317b61e654b9a46e79827355104760a3ac5228380bcWinson } 3180d14d4da91c3d8b1221269712d5abf43a7cf9f31Winson } else { 3190d14d4da91c3d8b1221269712d5abf43a7cf9f31Winson // If the user has toggled it too quickly, then just eat up the event here (it's 3200d14d4da91c3d8b1221269712d5abf43a7cf9f31Winson // better than showing a janky screenshot). 3210d14d4da91c3d8b1221269712d5abf43a7cf9f31Winson // NOTE: Ideally, the screenshot mechanism would take the window transform into 3220d14d4da91c3d8b1221269712d5abf43a7cf9f31Winson // account 323b61e654b9a46e79827355104760a3ac5228380bcWinson if (elapsedTime < MIN_TOGGLE_DELAY_MS) { 3240d14d4da91c3d8b1221269712d5abf43a7cf9f31Winson return; 3250d14d4da91c3d8b1221269712d5abf43a7cf9f31Winson } 3260d14d4da91c3d8b1221269712d5abf43a7cf9f31Winson 3270d14d4da91c3d8b1221269712d5abf43a7cf9f31Winson EventBus.getDefault().post(new ToggleRecentsEvent()); 3280d14d4da91c3d8b1221269712d5abf43a7cf9f31Winson mLastToggleTime = SystemClock.elapsedRealtime(); 3290d14d4da91c3d8b1221269712d5abf43a7cf9f31Winson } 330190fe3bf88388fcb109af64571e3baa0d01f1c37Winson return; 331190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } else { 3320d14d4da91c3d8b1221269712d5abf43a7cf9f31Winson // If the user has toggled it too quickly, then just eat up the event here (it's 3330d14d4da91c3d8b1221269712d5abf43a7cf9f31Winson // better than showing a janky screenshot). 3340d14d4da91c3d8b1221269712d5abf43a7cf9f31Winson // NOTE: Ideally, the screenshot mechanism would take the window transform into 3350d14d4da91c3d8b1221269712d5abf43a7cf9f31Winson // account 336b61e654b9a46e79827355104760a3ac5228380bcWinson if (elapsedTime < MIN_TOGGLE_DELAY_MS) { 3370d14d4da91c3d8b1221269712d5abf43a7cf9f31Winson return; 3380d14d4da91c3d8b1221269712d5abf43a7cf9f31Winson } 3390d14d4da91c3d8b1221269712d5abf43a7cf9f31Winson 340190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // Otherwise, start the recents activity 341bb42a46631b4cecdd03bd628feeb8270d412ebd3Jorim Jaggi startRecentsActivity(topTask, isTopTaskHome.value, true /* animate */); 342d8b1d63f96580fe961e1751e7b4f56c90c1e0a76Winson 343d8b1d63f96580fe961e1751e7b4f56c90c1e0a76Winson // Only close the other system windows if we are actually showing recents 344d8b1d63f96580fe961e1751e7b4f56c90c1e0a76Winson ssp.sendCloseSystemWindows(BaseStatusBar.SYSTEM_DIALOG_REASON_RECENT_APPS); 3450d14d4da91c3d8b1221269712d5abf43a7cf9f31Winson mLastToggleTime = SystemClock.elapsedRealtime(); 346190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 347190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } catch (ActivityNotFoundException e) { 3481b58561f66a9453754b1b419296899fdc08b4c93Winson Log.e(TAG, "Failed to launch RecentsActivity", e); 349190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 350190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 351190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 352190fe3bf88388fcb109af64571e3baa0d01f1c37Winson public void preloadRecents() { 353190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // Preload only the raw task list into a new load plan (which will be consumed by the 354190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // RecentsActivity) only if there is a task to animate to. 355e7f138c7f0a190c86cec10fb32fa106aacae4093Winson SystemServicesProxy ssp = Recents.getSystemServices(); 356e7f138c7f0a190c86cec10fb32fa106aacae4093Winson ActivityManager.RunningTaskInfo topTask = ssp.getTopMostTask(); 357190fe3bf88388fcb109af64571e3baa0d01f1c37Winson MutableBoolean topTaskHome = new MutableBoolean(true); 358e7f138c7f0a190c86cec10fb32fa106aacae4093Winson if (topTask != null && !ssp.isRecentsTopMost(topTask, topTaskHome)) { 3595b4e0d2b11b2b3579bac36fde5ac3805346618ccWinson RecentsTaskLoader loader = Recents.getTaskLoader(); 3605b4e0d2b11b2b3579bac36fde5ac3805346618ccWinson sInstanceLoadPlan = loader.createLoadPlan(mContext); 361190fe3bf88388fcb109af64571e3baa0d01f1c37Winson sInstanceLoadPlan.preloadRawTasks(topTaskHome.value); 36265c851e6e9e08656744b6f66d3da188e3283b17dWinson loader.preloadTasks(sInstanceLoadPlan, topTask.id, topTaskHome.value); 363190fe3bf88388fcb109af64571e3baa0d01f1c37Winson TaskStack stack = sInstanceLoadPlan.getTaskStack(); 3644b057c6787624b75613769a857ccdf51114bb7f2Winson if (stack.getTaskCount() > 0) { 365aeb298c4db913b376fb6053ec30c132a93e04635Winson // Only preload the icon (but not the thumbnail since it may not have been taken for 366aeb298c4db913b376fb6053ec30c132a93e04635Winson // the pausing activity) 367aeb298c4db913b376fb6053ec30c132a93e04635Winson preloadIcon(topTask); 368aeb298c4db913b376fb6053ec30c132a93e04635Winson 369aeb298c4db913b376fb6053ec30c132a93e04635Winson // At this point, we don't know anything about the stack state. So only calculate 370aeb298c4db913b376fb6053ec30c132a93e04635Winson // the dimensions of the thumbnail that we need for the transition into Recents, but 371aeb298c4db913b376fb6053ec30c132a93e04635Winson // do not draw it until we construct the activity options when we start Recents 372aeb298c4db913b376fb6053ec30c132a93e04635Winson updateHeaderBarLayout(stack); 373190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 374190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 375190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 376190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 377190fe3bf88388fcb109af64571e3baa0d01f1c37Winson public void cancelPreloadingRecents() { 378190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // Do nothing 379190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 380190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 381dd98d41e3a65b3bcb37007ea5b29371cf013f563Jorim Jaggi public void onDraggingInRecents(float distanceFromTop) { 382dd98d41e3a65b3bcb37007ea5b29371cf013f563Jorim Jaggi EventBus.getDefault().sendOntoMainThread(new DraggingInRecentsEvent(distanceFromTop)); 383dd98d41e3a65b3bcb37007ea5b29371cf013f563Jorim Jaggi } 384dd98d41e3a65b3bcb37007ea5b29371cf013f563Jorim Jaggi 385dd98d41e3a65b3bcb37007ea5b29371cf013f563Jorim Jaggi public void onDraggingInRecentsEnded(float velocity) { 386dd98d41e3a65b3bcb37007ea5b29371cf013f563Jorim Jaggi EventBus.getDefault().sendOntoMainThread(new DraggingInRecentsEndedEvent(velocity)); 387dd98d41e3a65b3bcb37007ea5b29371cf013f563Jorim Jaggi } 388dd98d41e3a65b3bcb37007ea5b29371cf013f563Jorim Jaggi 3896b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson /** 3906b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson * Transitions to the next recent task in the stack. 3916b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson */ 3926b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson public void showNextTask() { 3936b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson SystemServicesProxy ssp = Recents.getSystemServices(); 3946b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson RecentsTaskLoader loader = Recents.getTaskLoader(); 3956b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson RecentsTaskLoadPlan plan = loader.createLoadPlan(mContext); 39665c851e6e9e08656744b6f66d3da188e3283b17dWinson loader.preloadTasks(plan, -1, true /* isTopTaskHome */); 3976b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson TaskStack focusedStack = plan.getTaskStack(); 3986b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson 3996b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson // Return early if there are no tasks in the focused stack 4004b057c6787624b75613769a857ccdf51114bb7f2Winson if (focusedStack == null || focusedStack.getTaskCount() == 0) return; 4016b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson 4026b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson ActivityManager.RunningTaskInfo runningTask = ssp.getTopMostTask(); 4036b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson // Return early if there is no running task 4046b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson if (runningTask == null) return; 4056b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson 4066b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson // Find the task in the recents list 407e86deb8adb022ba7721a1af1112d3a45e757095cWinson boolean isTopTaskHome = SystemServicesProxy.isHomeStack(runningTask.stackId); 408250608a5cd08862f4752a924d51710805850db8aWinson ArrayList<Task> tasks = focusedStack.getStackTasks(); 4096b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson Task toTask = null; 4106b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson ActivityOptions launchOpts = null; 4116b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson int taskCount = tasks.size(); 4126b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson for (int i = taskCount - 1; i >= 1; i--) { 4136b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson Task task = tasks.get(i); 414e86deb8adb022ba7721a1af1112d3a45e757095cWinson if (isTopTaskHome) { 415e86deb8adb022ba7721a1af1112d3a45e757095cWinson toTask = tasks.get(i - 1); 416e86deb8adb022ba7721a1af1112d3a45e757095cWinson launchOpts = ActivityOptions.makeCustomAnimation(mContext, 417e86deb8adb022ba7721a1af1112d3a45e757095cWinson R.anim.recents_launch_next_affiliated_task_target, 418e86deb8adb022ba7721a1af1112d3a45e757095cWinson R.anim.recents_fast_toggle_app_home_exit); 419e86deb8adb022ba7721a1af1112d3a45e757095cWinson break; 420e86deb8adb022ba7721a1af1112d3a45e757095cWinson } else if (task.key.id == runningTask.id) { 4216b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson toTask = tasks.get(i - 1); 4226b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson launchOpts = ActivityOptions.makeCustomAnimation(mContext, 4236b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson R.anim.recents_launch_prev_affiliated_task_target, 4246b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson R.anim.recents_launch_prev_affiliated_task_source); 4256b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson break; 4266b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson } 4276b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson } 4286b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson 4296b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson // Return early if there is no next task 4306b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson if (toTask == null) { 4316b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson ssp.startInPlaceAnimationOnFrontMostApplication( 4326b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson ActivityOptions.makeCustomInPlaceAnimation(mContext, 4336b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson R.anim.recents_launch_prev_affiliated_task_bounce)); 4346b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson return; 4356b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson } 4366b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson 4376b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson // Launch the task 43864ae08aa16fdf7ee33073979400afa40692342f1Wale Ogunwale ssp.startActivityFromRecents(mContext, toTask.key, toTask.title, launchOpts); 4396b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson } 4406b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson 4416b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson /** 4426b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson * Transitions to the next affiliated task. 4436b92c6e524dbb7598fbeb4aefd98b69e6c13c03aWinson */ 444190fe3bf88388fcb109af64571e3baa0d01f1c37Winson public void showRelativeAffiliatedTask(boolean showNextTask) { 445e7f138c7f0a190c86cec10fb32fa106aacae4093Winson SystemServicesProxy ssp = Recents.getSystemServices(); 446e7f138c7f0a190c86cec10fb32fa106aacae4093Winson RecentsTaskLoader loader = Recents.getTaskLoader(); 447190fe3bf88388fcb109af64571e3baa0d01f1c37Winson RecentsTaskLoadPlan plan = loader.createLoadPlan(mContext); 44865c851e6e9e08656744b6f66d3da188e3283b17dWinson loader.preloadTasks(plan, -1, true /* isTopTaskHome */); 449190fe3bf88388fcb109af64571e3baa0d01f1c37Winson TaskStack focusedStack = plan.getTaskStack(); 450190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 451190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // Return early if there are no tasks in the focused stack 4524b057c6787624b75613769a857ccdf51114bb7f2Winson if (focusedStack == null || focusedStack.getTaskCount() == 0) return; 453190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 454e7f138c7f0a190c86cec10fb32fa106aacae4093Winson ActivityManager.RunningTaskInfo runningTask = ssp.getTopMostTask(); 455190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // Return early if there is no running task (can't determine affiliated tasks in this case) 456190fe3bf88388fcb109af64571e3baa0d01f1c37Winson if (runningTask == null) return; 457190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // Return early if the running task is in the home stack (optimization) 4585510f6c1b9c20483e1507147eed7b24ac8bb6363Winson if (SystemServicesProxy.isHomeStack(runningTask.stackId)) return; 459190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 460190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // Find the task in the recents list 461250608a5cd08862f4752a924d51710805850db8aWinson ArrayList<Task> tasks = focusedStack.getStackTasks(); 462190fe3bf88388fcb109af64571e3baa0d01f1c37Winson Task toTask = null; 463190fe3bf88388fcb109af64571e3baa0d01f1c37Winson ActivityOptions launchOpts = null; 464190fe3bf88388fcb109af64571e3baa0d01f1c37Winson int taskCount = tasks.size(); 465190fe3bf88388fcb109af64571e3baa0d01f1c37Winson int numAffiliatedTasks = 0; 466190fe3bf88388fcb109af64571e3baa0d01f1c37Winson for (int i = 0; i < taskCount; i++) { 467190fe3bf88388fcb109af64571e3baa0d01f1c37Winson Task task = tasks.get(i); 468190fe3bf88388fcb109af64571e3baa0d01f1c37Winson if (task.key.id == runningTask.id) { 469190fe3bf88388fcb109af64571e3baa0d01f1c37Winson TaskGrouping group = task.group; 470190fe3bf88388fcb109af64571e3baa0d01f1c37Winson Task.TaskKey toTaskKey; 471190fe3bf88388fcb109af64571e3baa0d01f1c37Winson if (showNextTask) { 472190fe3bf88388fcb109af64571e3baa0d01f1c37Winson toTaskKey = group.getNextTaskInGroup(task); 473190fe3bf88388fcb109af64571e3baa0d01f1c37Winson launchOpts = ActivityOptions.makeCustomAnimation(mContext, 474190fe3bf88388fcb109af64571e3baa0d01f1c37Winson R.anim.recents_launch_next_affiliated_task_target, 475190fe3bf88388fcb109af64571e3baa0d01f1c37Winson R.anim.recents_launch_next_affiliated_task_source); 476190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } else { 477190fe3bf88388fcb109af64571e3baa0d01f1c37Winson toTaskKey = group.getPrevTaskInGroup(task); 478190fe3bf88388fcb109af64571e3baa0d01f1c37Winson launchOpts = ActivityOptions.makeCustomAnimation(mContext, 479190fe3bf88388fcb109af64571e3baa0d01f1c37Winson R.anim.recents_launch_prev_affiliated_task_target, 480190fe3bf88388fcb109af64571e3baa0d01f1c37Winson R.anim.recents_launch_prev_affiliated_task_source); 481190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 482190fe3bf88388fcb109af64571e3baa0d01f1c37Winson if (toTaskKey != null) { 483190fe3bf88388fcb109af64571e3baa0d01f1c37Winson toTask = focusedStack.findTaskWithId(toTaskKey.id); 484190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 485190fe3bf88388fcb109af64571e3baa0d01f1c37Winson numAffiliatedTasks = group.getTaskCount(); 486190fe3bf88388fcb109af64571e3baa0d01f1c37Winson break; 487190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 488190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 489190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 490190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // Return early if there is no next task 491190fe3bf88388fcb109af64571e3baa0d01f1c37Winson if (toTask == null) { 492190fe3bf88388fcb109af64571e3baa0d01f1c37Winson if (numAffiliatedTasks > 1) { 493190fe3bf88388fcb109af64571e3baa0d01f1c37Winson if (showNextTask) { 494e7f138c7f0a190c86cec10fb32fa106aacae4093Winson ssp.startInPlaceAnimationOnFrontMostApplication( 495190fe3bf88388fcb109af64571e3baa0d01f1c37Winson ActivityOptions.makeCustomInPlaceAnimation(mContext, 496190fe3bf88388fcb109af64571e3baa0d01f1c37Winson R.anim.recents_launch_next_affiliated_task_bounce)); 497190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } else { 498e7f138c7f0a190c86cec10fb32fa106aacae4093Winson ssp.startInPlaceAnimationOnFrontMostApplication( 499190fe3bf88388fcb109af64571e3baa0d01f1c37Winson ActivityOptions.makeCustomInPlaceAnimation(mContext, 500190fe3bf88388fcb109af64571e3baa0d01f1c37Winson R.anim.recents_launch_prev_affiliated_task_bounce)); 501190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 502190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 503190fe3bf88388fcb109af64571e3baa0d01f1c37Winson return; 504190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 505190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 506190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // Keep track of actually launched affiliated tasks 507190fe3bf88388fcb109af64571e3baa0d01f1c37Winson MetricsLogger.count(mContext, "overview_affiliated_task_launch", 1); 508190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 509190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // Launch the task 51064ae08aa16fdf7ee33073979400afa40692342f1Wale Ogunwale ssp.startActivityFromRecents(mContext, toTask.key, toTask.title, launchOpts); 511190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 512190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 513190fe3bf88388fcb109af64571e3baa0d01f1c37Winson public void showNextAffiliatedTask() { 514190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // Keep track of when the affiliated task is triggered 515190fe3bf88388fcb109af64571e3baa0d01f1c37Winson MetricsLogger.count(mContext, "overview_affiliated_task_next", 1); 516190fe3bf88388fcb109af64571e3baa0d01f1c37Winson showRelativeAffiliatedTask(true); 517190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 518190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 519190fe3bf88388fcb109af64571e3baa0d01f1c37Winson public void showPrevAffiliatedTask() { 520190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // Keep track of when the affiliated task is triggered 521190fe3bf88388fcb109af64571e3baa0d01f1c37Winson MetricsLogger.count(mContext, "overview_affiliated_task_prev", 1); 522190fe3bf88388fcb109af64571e3baa0d01f1c37Winson showRelativeAffiliatedTask(false); 523190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 524190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 525cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi public void dockTopTask(int topTaskId, int dragMode, 526cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi int stackCreateMode, Rect initialBounds) { 52775b2597e5826662c1740d6f3b81966a9e6a9e7b4Jorim Jaggi SystemServicesProxy ssp = Recents.getSystemServices(); 5289511b0f1e9ac629a4a747a0c9373d33ab33cfc32Jorim Jaggi 5299511b0f1e9ac629a4a747a0c9373d33ab33cfc32Jorim Jaggi // Make sure we inform DividerView before we actually start the activity so we can change 5309511b0f1e9ac629a4a747a0c9373d33ab33cfc32Jorim Jaggi // the resize mode already. 531e4fbd328f83ea0ee086731f852cd6c56a3deb733Chong Zhang if (ssp.moveTaskToDockedStack(topTaskId, stackCreateMode, initialBounds)) { 532899327f5cbbfb0eae5562b262ccea860c98f6bc4Jorim Jaggi EventBus.getDefault().send(new DockedTopTaskEvent(dragMode, initialBounds)); 533e4fbd328f83ea0ee086731f852cd6c56a3deb733Chong Zhang showRecents( 534e4fbd328f83ea0ee086731f852cd6c56a3deb733Chong Zhang false /* triggeredFromAltTab */, 535e4fbd328f83ea0ee086731f852cd6c56a3deb733Chong Zhang dragMode == NavigationBarGestureHelper.DRAG_MODE_RECENTS, 536e4fbd328f83ea0ee086731f852cd6c56a3deb733Chong Zhang false /* animate */, 537e693aafe0511c2a7ffc571b22abeefba44046225Winson true /* launchedWhileDockingTask*/); 538e4fbd328f83ea0ee086731f852cd6c56a3deb733Chong Zhang } 53975b2597e5826662c1740d6f3b81966a9e6a9e7b4Jorim Jaggi } 54075b2597e5826662c1740d6f3b81966a9e6a9e7b4Jorim Jaggi 541190fe3bf88388fcb109af64571e3baa0d01f1c37Winson /** 542190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * Returns the preloaded load plan and invalidates it. 543190fe3bf88388fcb109af64571e3baa0d01f1c37Winson */ 544190fe3bf88388fcb109af64571e3baa0d01f1c37Winson public static RecentsTaskLoadPlan consumeInstanceLoadPlan() { 545190fe3bf88388fcb109af64571e3baa0d01f1c37Winson RecentsTaskLoadPlan plan = sInstanceLoadPlan; 546190fe3bf88388fcb109af64571e3baa0d01f1c37Winson sInstanceLoadPlan = null; 547190fe3bf88388fcb109af64571e3baa0d01f1c37Winson return plan; 548190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 549190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 550190fe3bf88388fcb109af64571e3baa0d01f1c37Winson /** 551670ea71f1b4ae59a0cd6608ae44b0fb78a1144c4Winson * Reloads all the resources for the current configuration. 552b94443d876d3c9575e88078d0e537bb385f79ca4Winson */ 553670ea71f1b4ae59a0cd6608ae44b0fb78a1144c4Winson private void reloadResources() { 554b94443d876d3c9575e88078d0e537bb385f79ca4Winson Resources res = mContext.getResources(); 555b94443d876d3c9575e88078d0e537bb385f79ca4Winson 556b94443d876d3c9575e88078d0e537bb385f79ca4Winson mStatusBarHeight = res.getDimensionPixelSize( 557b94443d876d3c9575e88078d0e537bb385f79ca4Winson com.android.internal.R.dimen.status_bar_height); 558b94443d876d3c9575e88078d0e537bb385f79ca4Winson mNavBarHeight = res.getDimensionPixelSize( 559b94443d876d3c9575e88078d0e537bb385f79ca4Winson com.android.internal.R.dimen.navigation_bar_height); 560b94443d876d3c9575e88078d0e537bb385f79ca4Winson mNavBarWidth = res.getDimensionPixelSize( 561b94443d876d3c9575e88078d0e537bb385f79ca4Winson com.android.internal.R.dimen.navigation_bar_width); 562217009356efa2b854ab3981dff8d315a0d679c73Winson mTaskBarHeight = TaskStackLayoutAlgorithm.getDimensionForDevice(res, 563217009356efa2b854ab3981dff8d315a0d679c73Winson R.dimen.recents_task_view_header_height, 564217009356efa2b854ab3981dff8d315a0d679c73Winson R.dimen.recents_task_view_header_height, 565217009356efa2b854ab3981dff8d315a0d679c73Winson R.dimen.recents_task_view_header_height, 566217009356efa2b854ab3981dff8d315a0d679c73Winson R.dimen.recents_task_view_header_height_tablet_land, 567217009356efa2b854ab3981dff8d315a0d679c73Winson R.dimen.recents_task_view_header_height, 568217009356efa2b854ab3981dff8d315a0d679c73Winson R.dimen.recents_task_view_header_height_tablet_land); 569b94443d876d3c9575e88078d0e537bb385f79ca4Winson } 570b94443d876d3c9575e88078d0e537bb385f79ca4Winson 571b94443d876d3c9575e88078d0e537bb385f79ca4Winson /** 572190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * Prepares the header bar layout for the next transition, if the task view bounds has changed 573190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * since the last call, it will attempt to re-measure and layout the header bar to the new size. 574190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * 575f0d1c44a59a10707baa0cca8dd377302260710c1Winson * @param stack the stack to initialize the stack layout with 576190fe3bf88388fcb109af64571e3baa0d01f1c37Winson */ 577008ee15fe82c8216e8e4f67e3032de468cc6c92aWinson private void updateHeaderBarLayout(TaskStack stack) { 578e7f138c7f0a190c86cec10fb32fa106aacae4093Winson SystemServicesProxy ssp = Recents.getSystemServices(); 579c6c89a82144f59475242c75d67529fed943ae30bJorim Jaggi Rect systemInsets = new Rect(); 580c6c89a82144f59475242c75d67529fed943ae30bJorim Jaggi ssp.getStableInsets(systemInsets); 581e7f138c7f0a190c86cec10fb32fa106aacae4093Winson Rect windowRect = ssp.getWindowRect(); 582cf9b8326cecfca3917779c3701aa08eaaad56505Winson // When docked, the nav bar insets are consumed and the activity is measured without insets. 583cf9b8326cecfca3917779c3701aa08eaaad56505Winson // However, the window bounds include the insets, so we need to subtract them here to make 584cf9b8326cecfca3917779c3701aa08eaaad56505Winson // them identical. 585cf9b8326cecfca3917779c3701aa08eaaad56505Winson if (ssp.hasDockedTask()) { 586cf9b8326cecfca3917779c3701aa08eaaad56505Winson windowRect.bottom -= systemInsets.bottom; 587cf9b8326cecfca3917779c3701aa08eaaad56505Winson systemInsets.bottom = 0; 588cf9b8326cecfca3917779c3701aa08eaaad56505Winson } 589c6c89a82144f59475242c75d67529fed943ae30bJorim Jaggi calculateWindowStableInsets(systemInsets, windowRect); 590c6c89a82144f59475242c75d67529fed943ae30bJorim Jaggi windowRect.offsetTo(0, 0); 591190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 59259924fe0d9136cf349759bea1e06b661603f95feWinson TaskStackLayoutAlgorithm stackLayout = mDummyStackView.getStackAlgorithm(); 593190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 594190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // Rebind the header bar and draw it for the transition 5958873754f66527d2cc9feab295dd4eef23298212aWinson stackLayout.setSystemInsets(systemInsets); 596f0d1c44a59a10707baa0cca8dd377302260710c1Winson if (stack != null) { 597cf9b8326cecfca3917779c3701aa08eaaad56505Winson stackLayout.getTaskStackBounds(windowRect, systemInsets.top, systemInsets.right, 598cf9b8326cecfca3917779c3701aa08eaaad56505Winson mTaskStackBounds); 599aeb298c4db913b376fb6053ec30c132a93e04635Winson stackLayout.reset(); 600cf9b8326cecfca3917779c3701aa08eaaad56505Winson stackLayout.initialize(windowRect, mTaskStackBounds, 601f0d1c44a59a10707baa0cca8dd377302260710c1Winson TaskStackLayoutAlgorithm.StackState.getStackStateForStack(stack)); 602a1ededd056d51532ab18354f17f8065ec1134535Winson mDummyStackView.setTasks(stack, false /* allowNotifyStackChanges */); 603190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 604aeb298c4db913b376fb6053ec30c132a93e04635Winson Rect taskViewBounds = stackLayout.getUntransformedTaskViewBounds(); 60594bc4f2238d8eefb77c63a560aa0de1335ee57abWinson if (!taskViewBounds.isEmpty()) { 60694bc4f2238d8eefb77c63a560aa0de1335ee57abWinson int taskViewWidth = taskViewBounds.width(); 60794bc4f2238d8eefb77c63a560aa0de1335ee57abWinson synchronized (mHeaderBarLock) { 60894bc4f2238d8eefb77c63a560aa0de1335ee57abWinson if (mHeaderBar.getMeasuredWidth() != taskViewWidth || 60994bc4f2238d8eefb77c63a560aa0de1335ee57abWinson mHeaderBar.getMeasuredHeight() != mTaskBarHeight) { 61094bc4f2238d8eefb77c63a560aa0de1335ee57abWinson mHeaderBar.measure( 61194bc4f2238d8eefb77c63a560aa0de1335ee57abWinson MeasureSpec.makeMeasureSpec(taskViewWidth, MeasureSpec.EXACTLY), 61294bc4f2238d8eefb77c63a560aa0de1335ee57abWinson MeasureSpec.makeMeasureSpec(mTaskBarHeight, MeasureSpec.EXACTLY)); 61394bc4f2238d8eefb77c63a560aa0de1335ee57abWinson } 61494bc4f2238d8eefb77c63a560aa0de1335ee57abWinson mHeaderBar.layout(0, 0, taskViewWidth, mTaskBarHeight); 615aeb298c4db913b376fb6053ec30c132a93e04635Winson } 616aeb298c4db913b376fb6053ec30c132a93e04635Winson 61794bc4f2238d8eefb77c63a560aa0de1335ee57abWinson // Update the transition bitmap to match the new header bar height 61894bc4f2238d8eefb77c63a560aa0de1335ee57abWinson if (mThumbTransitionBitmapCache == null || 61994bc4f2238d8eefb77c63a560aa0de1335ee57abWinson (mThumbTransitionBitmapCache.getWidth() != taskViewWidth) || 62094bc4f2238d8eefb77c63a560aa0de1335ee57abWinson (mThumbTransitionBitmapCache.getHeight() != mTaskBarHeight)) { 62194bc4f2238d8eefb77c63a560aa0de1335ee57abWinson mThumbTransitionBitmapCache = Bitmap.createBitmap(taskViewWidth, 62294bc4f2238d8eefb77c63a560aa0de1335ee57abWinson mTaskBarHeight, Bitmap.Config.ARGB_8888); 62394bc4f2238d8eefb77c63a560aa0de1335ee57abWinson } 624aeb298c4db913b376fb6053ec30c132a93e04635Winson } 625190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 626190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 627190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 628190fe3bf88388fcb109af64571e3baa0d01f1c37Winson /** 629c6c89a82144f59475242c75d67529fed943ae30bJorim Jaggi * Given the stable insets and the rect for our window, calculates the insets that affect our 630c6c89a82144f59475242c75d67529fed943ae30bJorim Jaggi * window. 631c6c89a82144f59475242c75d67529fed943ae30bJorim Jaggi */ 632c6c89a82144f59475242c75d67529fed943ae30bJorim Jaggi private void calculateWindowStableInsets(Rect inOutInsets, Rect windowRect) { 633c6c89a82144f59475242c75d67529fed943ae30bJorim Jaggi Rect displayRect = Recents.getSystemServices().getDisplayRect(); 634c6c89a82144f59475242c75d67529fed943ae30bJorim Jaggi 635c6c89a82144f59475242c75d67529fed943ae30bJorim Jaggi // Display rect without insets - available app space 636c6c89a82144f59475242c75d67529fed943ae30bJorim Jaggi Rect appRect = new Rect(displayRect); 637c6c89a82144f59475242c75d67529fed943ae30bJorim Jaggi appRect.inset(inOutInsets); 638c6c89a82144f59475242c75d67529fed943ae30bJorim Jaggi 639c6c89a82144f59475242c75d67529fed943ae30bJorim Jaggi // Our window intersected with available app space 640c6c89a82144f59475242c75d67529fed943ae30bJorim Jaggi Rect windowRectWithInsets = new Rect(windowRect); 641c6c89a82144f59475242c75d67529fed943ae30bJorim Jaggi windowRectWithInsets.intersect(appRect); 642c6c89a82144f59475242c75d67529fed943ae30bJorim Jaggi inOutInsets.left = windowRectWithInsets.left - windowRect.left; 643c6c89a82144f59475242c75d67529fed943ae30bJorim Jaggi inOutInsets.top = windowRectWithInsets.top - windowRect.top; 644c6c89a82144f59475242c75d67529fed943ae30bJorim Jaggi inOutInsets.right = windowRect.right - windowRectWithInsets.right; 645c6c89a82144f59475242c75d67529fed943ae30bJorim Jaggi inOutInsets.bottom = windowRect.bottom - windowRectWithInsets.bottom; 646c6c89a82144f59475242c75d67529fed943ae30bJorim Jaggi } 647c6c89a82144f59475242c75d67529fed943ae30bJorim Jaggi 648c6c89a82144f59475242c75d67529fed943ae30bJorim Jaggi /** 649190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * Preloads the icon of a task. 650190fe3bf88388fcb109af64571e3baa0d01f1c37Winson */ 651190fe3bf88388fcb109af64571e3baa0d01f1c37Winson private void preloadIcon(ActivityManager.RunningTaskInfo task) { 652190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // Ensure that we load the running task's icon 653190fe3bf88388fcb109af64571e3baa0d01f1c37Winson RecentsTaskLoadPlan.Options launchOpts = new RecentsTaskLoadPlan.Options(); 654190fe3bf88388fcb109af64571e3baa0d01f1c37Winson launchOpts.runningTaskId = task.id; 655190fe3bf88388fcb109af64571e3baa0d01f1c37Winson launchOpts.loadThumbnails = false; 656190fe3bf88388fcb109af64571e3baa0d01f1c37Winson launchOpts.onlyLoadForCache = true; 657e7f138c7f0a190c86cec10fb32fa106aacae4093Winson Recents.getTaskLoader().loadTasks(mContext, sInstanceLoadPlan, launchOpts); 658190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 659190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 660190fe3bf88388fcb109af64571e3baa0d01f1c37Winson /** 661190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * Creates the activity options for a unknown state->recents transition. 662190fe3bf88388fcb109af64571e3baa0d01f1c37Winson */ 6634bdb6879bd5f1b7e93e7e9ac236a073921862075Sid Soundararajan protected ActivityOptions getUnknownTransitionActivityOptions() { 664190fe3bf88388fcb109af64571e3baa0d01f1c37Winson return ActivityOptions.makeCustomAnimation(mContext, 665190fe3bf88388fcb109af64571e3baa0d01f1c37Winson R.anim.recents_from_unknown_enter, 666190fe3bf88388fcb109af64571e3baa0d01f1c37Winson R.anim.recents_from_unknown_exit, 6673fb67562c548662910160d5672b1b9558bd6571cWinson mHandler, null); 668190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 669190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 670190fe3bf88388fcb109af64571e3baa0d01f1c37Winson /** 671190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * Creates the activity options for a home->recents transition. 672190fe3bf88388fcb109af64571e3baa0d01f1c37Winson */ 673008ee15fe82c8216e8e4f67e3032de468cc6c92aWinson protected ActivityOptions getHomeTransitionActivityOptions() { 674190fe3bf88388fcb109af64571e3baa0d01f1c37Winson return ActivityOptions.makeCustomAnimation(mContext, 675190fe3bf88388fcb109af64571e3baa0d01f1c37Winson R.anim.recents_from_launcher_enter, 676190fe3bf88388fcb109af64571e3baa0d01f1c37Winson R.anim.recents_from_launcher_exit, 6773fb67562c548662910160d5672b1b9558bd6571cWinson mHandler, null); 678190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 679190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 680190fe3bf88388fcb109af64571e3baa0d01f1c37Winson /** 681190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * Creates the activity options for an app->recents transition. 682190fe3bf88388fcb109af64571e3baa0d01f1c37Winson */ 683190fe3bf88388fcb109af64571e3baa0d01f1c37Winson private ActivityOptions getThumbnailTransitionActivityOptions( 684e693aafe0511c2a7ffc571b22abeefba44046225Winson ActivityManager.RunningTaskInfo topTask, TaskStackView stackView) { 685d64ef3ef33c50a03b4be3b2baaa93aab7319fca8Filip Gruszczynski if (topTask.stackId == FREEFORM_WORKSPACE_STACK_ID) { 686d64ef3ef33c50a03b4be3b2baaa93aab7319fca8Filip Gruszczynski ArrayList<AppTransitionAnimationSpec> specs = new ArrayList<>(); 687e693aafe0511c2a7ffc571b22abeefba44046225Winson ArrayList<Task> tasks = stackView.getStack().getStackTasks(); 688e693aafe0511c2a7ffc571b22abeefba44046225Winson TaskStackLayoutAlgorithm stackLayout = stackView.getStackAlgorithm(); 689e693aafe0511c2a7ffc571b22abeefba44046225Winson TaskStackViewScroller stackScroller = stackView.getScroller(); 690e693aafe0511c2a7ffc571b22abeefba44046225Winson 691003eda6c230a1b1c4e3709466c46660e7602d740Winson stackView.updateLayoutAlgorithm(true /* boundScroll */); 692619e40cd56266a362ab7da80cb9e4eba6c33b204Winson stackView.updateToInitialState(true /* scrollToInitialState */); 693e693aafe0511c2a7ffc571b22abeefba44046225Winson 694d64ef3ef33c50a03b4be3b2baaa93aab7319fca8Filip Gruszczynski for (int i = tasks.size() - 1; i >= 0; i--) { 695d64ef3ef33c50a03b4be3b2baaa93aab7319fca8Filip Gruszczynski Task task = tasks.get(i); 696387aac6ad7bde21f2c2510cb8a2f3af3959721e0Winson if (task.isFreeformTask()) { 697e693aafe0511c2a7ffc571b22abeefba44046225Winson mTmpTransform = stackLayout.getStackTransformScreenCoordinates(task, 698e693aafe0511c2a7ffc571b22abeefba44046225Winson stackScroller.getStackScroll(), mTmpTransform, null); 699aeb298c4db913b376fb6053ec30c132a93e04635Winson Bitmap thumbnail = drawThumbnailTransitionBitmap(task, mTmpTransform, 700aeb298c4db913b376fb6053ec30c132a93e04635Winson mThumbTransitionBitmapCache); 701d64ef3ef33c50a03b4be3b2baaa93aab7319fca8Filip Gruszczynski Rect toTaskRect = new Rect(); 702d64ef3ef33c50a03b4be3b2baaa93aab7319fca8Filip Gruszczynski mTmpTransform.rect.round(toTaskRect); 703d64ef3ef33c50a03b4be3b2baaa93aab7319fca8Filip Gruszczynski specs.add(new AppTransitionAnimationSpec(task.key.id, thumbnail, toTaskRect)); 704d64ef3ef33c50a03b4be3b2baaa93aab7319fca8Filip Gruszczynski } 705d64ef3ef33c50a03b4be3b2baaa93aab7319fca8Filip Gruszczynski } 706d64ef3ef33c50a03b4be3b2baaa93aab7319fca8Filip Gruszczynski AppTransitionAnimationSpec[] specsArray = new AppTransitionAnimationSpec[specs.size()]; 707d64ef3ef33c50a03b4be3b2baaa93aab7319fca8Filip Gruszczynski specs.toArray(specsArray); 708d64ef3ef33c50a03b4be3b2baaa93aab7319fca8Filip Gruszczynski return ActivityOptions.makeThumbnailAspectScaleDownAnimation(mDummyStackView, 7093fb67562c548662910160d5672b1b9558bd6571cWinson specsArray, mHandler, null, this); 710d64ef3ef33c50a03b4be3b2baaa93aab7319fca8Filip Gruszczynski } else { 711d64ef3ef33c50a03b4be3b2baaa93aab7319fca8Filip Gruszczynski // Update the destination rect 712d64ef3ef33c50a03b4be3b2baaa93aab7319fca8Filip Gruszczynski Task toTask = new Task(); 713e693aafe0511c2a7ffc571b22abeefba44046225Winson TaskViewTransform toTransform = getThumbnailTransitionTransform(stackView, toTask); 714aeb298c4db913b376fb6053ec30c132a93e04635Winson Bitmap thumbnail = drawThumbnailTransitionBitmap(toTask, toTransform, 715aeb298c4db913b376fb6053ec30c132a93e04635Winson mThumbTransitionBitmapCache); 716d64ef3ef33c50a03b4be3b2baaa93aab7319fca8Filip Gruszczynski if (thumbnail != null) { 717aeb298c4db913b376fb6053ec30c132a93e04635Winson RectF toTaskRect = toTransform.rect; 718d64ef3ef33c50a03b4be3b2baaa93aab7319fca8Filip Gruszczynski return ActivityOptions.makeThumbnailAspectScaleDownAnimation(mDummyStackView, 719d64ef3ef33c50a03b4be3b2baaa93aab7319fca8Filip Gruszczynski thumbnail, (int) toTaskRect.left, (int) toTaskRect.top, 7203fb67562c548662910160d5672b1b9558bd6571cWinson (int) toTaskRect.width(), (int) toTaskRect.height(), mHandler, null); 721d64ef3ef33c50a03b4be3b2baaa93aab7319fca8Filip Gruszczynski } 722d64ef3ef33c50a03b4be3b2baaa93aab7319fca8Filip Gruszczynski // If both the screenshot and thumbnail fails, then just fall back to the default transition 723d64ef3ef33c50a03b4be3b2baaa93aab7319fca8Filip Gruszczynski return getUnknownTransitionActivityOptions(); 724d64ef3ef33c50a03b4be3b2baaa93aab7319fca8Filip Gruszczynski } 725d64ef3ef33c50a03b4be3b2baaa93aab7319fca8Filip Gruszczynski } 726190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 727190fe3bf88388fcb109af64571e3baa0d01f1c37Winson /** 728190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * Returns the transition rect for the given task id. 729190fe3bf88388fcb109af64571e3baa0d01f1c37Winson */ 730e693aafe0511c2a7ffc571b22abeefba44046225Winson private TaskViewTransform getThumbnailTransitionTransform(TaskStackView stackView, 731e693aafe0511c2a7ffc571b22abeefba44046225Winson Task runningTaskOut) { 732190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // Find the running task in the TaskStack 733e693aafe0511c2a7ffc571b22abeefba44046225Winson TaskStack stack = stackView.getStack(); 73465c851e6e9e08656744b6f66d3da188e3283b17dWinson Task launchTask = stack.getLaunchTarget(); 73565c851e6e9e08656744b6f66d3da188e3283b17dWinson if (launchTask != null) { 73665c851e6e9e08656744b6f66d3da188e3283b17dWinson runningTaskOut.copyFrom(launchTask); 73765c851e6e9e08656744b6f66d3da188e3283b17dWinson } else { 738190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // If no task is specified or we can not find the task just use the front most one 73935a8b04140598a5b5c4865254b942adb6a830991Winson launchTask = stack.getStackFrontMostTask(true /* includeFreeform */); 74065c851e6e9e08656744b6f66d3da188e3283b17dWinson runningTaskOut.copyFrom(launchTask); 741190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 742190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 743190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // Get the transform for the running task 744003eda6c230a1b1c4e3709466c46660e7602d740Winson stackView.updateLayoutAlgorithm(true /* boundScroll */); 745619e40cd56266a362ab7da80cb9e4eba6c33b204Winson stackView.updateToInitialState(true /* scrollToInitialState */); 7467845e8c4946f6b5dadfcd9c1d64e826bacc50edbWinson stackView.getStackAlgorithm().getStackTransformScreenCoordinates(launchTask, 747190fe3bf88388fcb109af64571e3baa0d01f1c37Winson stackView.getScroller().getStackScroll(), mTmpTransform, null); 748190fe3bf88388fcb109af64571e3baa0d01f1c37Winson return mTmpTransform; 749190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 750190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 751190fe3bf88388fcb109af64571e3baa0d01f1c37Winson /** 752190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * Draws the header of a task used for the window animation into a bitmap. 753190fe3bf88388fcb109af64571e3baa0d01f1c37Winson */ 754aeb298c4db913b376fb6053ec30c132a93e04635Winson private Bitmap drawThumbnailTransitionBitmap(Task toTask, TaskViewTransform toTransform, 755aeb298c4db913b376fb6053ec30c132a93e04635Winson Bitmap thumbnail) { 7568be1634a543022bd6ee0c1e974d3201d452981e8Winson SystemServicesProxy ssp = Recents.getSystemServices(); 757190fe3bf88388fcb109af64571e3baa0d01f1c37Winson if (toTransform != null && toTask.key != null) { 758190fe3bf88388fcb109af64571e3baa0d01f1c37Winson synchronized (mHeaderBarLock) { 7598be1634a543022bd6ee0c1e974d3201d452981e8Winson boolean disabledInSafeMode = !toTask.isSystemApp && ssp.isInSafeMode(); 760509d0d0c9e2ee165d04e898fea59f8941ac7138dWinson Chung mHeaderBar.onTaskViewSizeChanged((int) toTransform.rect.width(), 761509d0d0c9e2ee165d04e898fea59f8941ac7138dWinson Chung (int) toTransform.rect.height()); 762c742f973b1e506732911c156c5869fd377afc5bfWinson if (RecentsDebugFlags.Static.EnableTransitionThumbnailDebugMode) { 763190fe3bf88388fcb109af64571e3baa0d01f1c37Winson thumbnail.eraseColor(0xFFff0000); 764190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } else { 765aeb298c4db913b376fb6053ec30c132a93e04635Winson thumbnail.eraseColor(0); 766190fe3bf88388fcb109af64571e3baa0d01f1c37Winson Canvas c = new Canvas(thumbnail); 76722574afa00b7e32b7c4c5a1b98deebd67751b364Winson // Workaround for b/27815919, reset the callback so that we do not trigger an 76822574afa00b7e32b7c4c5a1b98deebd67751b364Winson // invalidate on the header bar as a result of updating the icon 76922574afa00b7e32b7c4c5a1b98deebd67751b364Winson Drawable icon = mHeaderBar.getIconView().getDrawable(); 77022574afa00b7e32b7c4c5a1b98deebd67751b364Winson if (icon != null) { 77122574afa00b7e32b7c4c5a1b98deebd67751b364Winson icon.setCallback(null); 77222574afa00b7e32b7c4c5a1b98deebd67751b364Winson } 7738be1634a543022bd6ee0c1e974d3201d452981e8Winson mHeaderBar.rebindToTask(toTask, false /* touchExplorationEnabled */, 7748be1634a543022bd6ee0c1e974d3201d452981e8Winson disabledInSafeMode); 775e693aafe0511c2a7ffc571b22abeefba44046225Winson mHeaderBar.setDimAlpha(toTransform.dimAlpha); 776190fe3bf88388fcb109af64571e3baa0d01f1c37Winson mHeaderBar.draw(c); 777190fe3bf88388fcb109af64571e3baa0d01f1c37Winson c.setBitmap(null); 778190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 779190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 780190fe3bf88388fcb109af64571e3baa0d01f1c37Winson return thumbnail.createAshmemBitmap(); 781190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 782190fe3bf88388fcb109af64571e3baa0d01f1c37Winson return null; 783190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 784190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 785190fe3bf88388fcb109af64571e3baa0d01f1c37Winson /** 786190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * Shows the recents activity 787190fe3bf88388fcb109af64571e3baa0d01f1c37Winson */ 7884bdb6879bd5f1b7e93e7e9ac236a073921862075Sid Soundararajan protected void startRecentsActivity(ActivityManager.RunningTaskInfo topTask, 789bb42a46631b4cecdd03bd628feeb8270d412ebd3Jorim Jaggi boolean isTopTaskHome, boolean animate) { 790e7f138c7f0a190c86cec10fb32fa106aacae4093Winson RecentsTaskLoader loader = Recents.getTaskLoader(); 791c5b12dd37e964b220c0a108e86ad8a2d12805747Winson RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState(); 792190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 793e5f1faa9f8009a723ab21aed6fe5ab325c61442bWinson // In the case where alt-tab is triggered, we never get a preloadRecents() call, so we 794435b2e43cb131d0b38ba19f335aec78bb83944b2Jorim Jaggi // should always preload the tasks now. If we are dragging in recents, reload them as 795435b2e43cb131d0b38ba19f335aec78bb83944b2Jorim Jaggi // the stacks might have changed. 796e161f08e98fdbe6fe83f70ffa1ea11142a027ebeJorim Jaggi if (mLaunchedWhileDocking || mTriggeredFromAltTab ||sInstanceLoadPlan == null) { 797e5f1faa9f8009a723ab21aed6fe5ab325c61442bWinson // Create a new load plan if preloadRecents() was never triggered 798190fe3bf88388fcb109af64571e3baa0d01f1c37Winson sInstanceLoadPlan = loader.createLoadPlan(mContext); 799190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 800e161f08e98fdbe6fe83f70ffa1ea11142a027ebeJorim Jaggi if (mLaunchedWhileDocking || mTriggeredFromAltTab || !sInstanceLoadPlan.hasTasks()) { 80165c851e6e9e08656744b6f66d3da188e3283b17dWinson loader.preloadTasks(sInstanceLoadPlan, topTask.id, isTopTaskHome); 802190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 803c5b12dd37e964b220c0a108e86ad8a2d12805747Winson 804190fe3bf88388fcb109af64571e3baa0d01f1c37Winson TaskStack stack = sInstanceLoadPlan.getTaskStack(); 805c5b12dd37e964b220c0a108e86ad8a2d12805747Winson boolean hasRecentTasks = stack.getTaskCount() > 0; 806c5b12dd37e964b220c0a108e86ad8a2d12805747Winson boolean useThumbnailTransition = (topTask != null) && !isTopTaskHome && hasRecentTasks; 807190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 808aeb298c4db913b376fb6053ec30c132a93e04635Winson // Update the launch state that we need in updateHeaderBarLayout() 809aeb298c4db913b376fb6053ec30c132a93e04635Winson launchState.launchedFromHome = !useThumbnailTransition; 810aeb298c4db913b376fb6053ec30c132a93e04635Winson launchState.launchedFromApp = useThumbnailTransition || mLaunchedWhileDocking; 811aeb298c4db913b376fb6053ec30c132a93e04635Winson launchState.launchedViaDockGesture = mLaunchedWhileDocking; 812aeb298c4db913b376fb6053ec30c132a93e04635Winson launchState.launchedViaDragGesture = mDraggingInRecents; 813aeb298c4db913b376fb6053ec30c132a93e04635Winson launchState.launchedToTaskId = (topTask != null) ? topTask.id : -1; 814aeb298c4db913b376fb6053ec30c132a93e04635Winson launchState.launchedWithAltTab = mTriggeredFromAltTab; 815aeb298c4db913b376fb6053ec30c132a93e04635Winson 816aeb298c4db913b376fb6053ec30c132a93e04635Winson // Preload the icon (this will be a null-op if we have preloaded the icon already in 817aeb298c4db913b376fb6053ec30c132a93e04635Winson // preloadRecents()) 818aeb298c4db913b376fb6053ec30c132a93e04635Winson preloadIcon(topTask); 819aeb298c4db913b376fb6053ec30c132a93e04635Winson 820f0d1c44a59a10707baa0cca8dd377302260710c1Winson // Update the header bar if necessary 821008ee15fe82c8216e8e4f67e3032de468cc6c92aWinson updateHeaderBarLayout(stack); 822f0d1c44a59a10707baa0cca8dd377302260710c1Winson 823190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // Prepare the dummy stack for the transition 82436a5a2c7003ef8157f276b411c3fda47ad2f75e3Winson TaskStackLayoutAlgorithm.VisibilityReport stackVr = 825190fe3bf88388fcb109af64571e3baa0d01f1c37Winson mDummyStackView.computeStackVisibilityReport(); 826bb42a46631b4cecdd03bd628feeb8270d412ebd3Jorim Jaggi 827aeb298c4db913b376fb6053ec30c132a93e04635Winson // Update the remaining launch state 828c5b12dd37e964b220c0a108e86ad8a2d12805747Winson launchState.launchedNumVisibleTasks = stackVr.numVisibleTasks; 829c5b12dd37e964b220c0a108e86ad8a2d12805747Winson launchState.launchedNumVisibleThumbnails = stackVr.numVisibleThumbnails; 830c5b12dd37e964b220c0a108e86ad8a2d12805747Winson 831bb42a46631b4cecdd03bd628feeb8270d412ebd3Jorim Jaggi if (!animate) { 832c5b12dd37e964b220c0a108e86ad8a2d12805747Winson startRecentsActivity(ActivityOptions.makeCustomAnimation(mContext, -1, -1)); 833bb42a46631b4cecdd03bd628feeb8270d412ebd3Jorim Jaggi return; 834bb42a46631b4cecdd03bd628feeb8270d412ebd3Jorim Jaggi } 835bb42a46631b4cecdd03bd628feeb8270d412ebd3Jorim Jaggi 836aeb298c4db913b376fb6053ec30c132a93e04635Winson ActivityOptions opts; 837190fe3bf88388fcb109af64571e3baa0d01f1c37Winson if (useThumbnailTransition) { 838190fe3bf88388fcb109af64571e3baa0d01f1c37Winson // Try starting with a thumbnail transition 839aeb298c4db913b376fb6053ec30c132a93e04635Winson opts = getThumbnailTransitionActivityOptions(topTask, mDummyStackView); 840aeb298c4db913b376fb6053ec30c132a93e04635Winson } else { 841fa61ce343e91e11bb06545eae00e0659a2942a7dSid Soundararajan // If there is no thumbnail transition, but is launching from home into recents, then 842008ee15fe82c8216e8e4f67e3032de468cc6c92aWinson // use a quick home transition 843aeb298c4db913b376fb6053ec30c132a93e04635Winson opts = hasRecentTasks 844aeb298c4db913b376fb6053ec30c132a93e04635Winson ? getHomeTransitionActivityOptions() 845aeb298c4db913b376fb6053ec30c132a93e04635Winson : getUnknownTransitionActivityOptions(); 846fa61ce343e91e11bb06545eae00e0659a2942a7dSid Soundararajan } 847aeb298c4db913b376fb6053ec30c132a93e04635Winson startRecentsActivity(opts); 848fa61ce343e91e11bb06545eae00e0659a2942a7dSid Soundararajan mLastToggleTime = SystemClock.elapsedRealtime(); 849fa61ce343e91e11bb06545eae00e0659a2942a7dSid Soundararajan } 850fa61ce343e91e11bb06545eae00e0659a2942a7dSid Soundararajan 851fa61ce343e91e11bb06545eae00e0659a2942a7dSid Soundararajan /** 852190fe3bf88388fcb109af64571e3baa0d01f1c37Winson * Starts the recents activity. 853190fe3bf88388fcb109af64571e3baa0d01f1c37Winson */ 854c5b12dd37e964b220c0a108e86ad8a2d12805747Winson private void startRecentsActivity(ActivityOptions opts) { 855190fe3bf88388fcb109af64571e3baa0d01f1c37Winson Intent intent = new Intent(); 8564bdb6879bd5f1b7e93e7e9ac236a073921862075Sid Soundararajan intent.setClassName(RECENTS_PACKAGE, RECENTS_ACTIVITY); 857190fe3bf88388fcb109af64571e3baa0d01f1c37Winson intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 858190fe3bf88388fcb109af64571e3baa0d01f1c37Winson | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS 859190fe3bf88388fcb109af64571e3baa0d01f1c37Winson | Intent.FLAG_ACTIVITY_TASK_ON_HOME); 860b58c46acec2e270f24ca587a64298f06cefb09cbSid Soundararajan 861190fe3bf88388fcb109af64571e3baa0d01f1c37Winson if (opts != null) { 862190fe3bf88388fcb109af64571e3baa0d01f1c37Winson mContext.startActivityAsUser(intent, opts.toBundle(), UserHandle.CURRENT); 863190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } else { 864190fe3bf88388fcb109af64571e3baa0d01f1c37Winson mContext.startActivityAsUser(intent, UserHandle.CURRENT); 865190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 866cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi EventBus.getDefault().send(new RecentsActivityStartingEvent()); 867190fe3bf88388fcb109af64571e3baa0d01f1c37Winson } 868190fe3bf88388fcb109af64571e3baa0d01f1c37Winson 8693fb67562c548662910160d5672b1b9558bd6571cWinson /**** OnAnimationFinishedListener Implementation ****/ 8701a5203dfd5264104db018b8a09d50075b1af9b2dFilip Gruszczynski 8711a5203dfd5264104db018b8a09d50075b1af9b2dFilip Gruszczynski @Override 8721a5203dfd5264104db018b8a09d50075b1af9b2dFilip Gruszczynski public void onAnimationFinished() { 8731a5203dfd5264104db018b8a09d50075b1af9b2dFilip Gruszczynski EventBus.getDefault().post(new EnterRecentsWindowLastAnimationFrameEvent()); 8741a5203dfd5264104db018b8a09d50075b1af9b2dFilip Gruszczynski } 875190fe3bf88388fcb109af64571e3baa0d01f1c37Winson} 876