Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | |
Jim Miller | a237a31 | 2014-11-06 18:05:59 -0800 | [diff] [blame] | 19 | import android.app.Activity; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 20 | import android.app.ActivityManager; |
| 21 | import android.app.ActivityOptions; |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 22 | import android.app.ITaskStackListener; |
Winson Chung | d751c01 | 2014-09-15 00:00:38 +0200 | [diff] [blame] | 23 | import android.appwidget.AppWidgetHost; |
Winson Chung | bf8871d | 2014-08-28 20:57:16 -0700 | [diff] [blame] | 24 | import android.appwidget.AppWidgetProviderInfo; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 25 | import android.content.ActivityNotFoundException; |
Jim Miller | a237a31 | 2014-11-06 18:05:59 -0800 | [diff] [blame] | 26 | import android.content.BroadcastReceiver; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 27 | import android.content.Context; |
| 28 | import android.content.Intent; |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 29 | import android.content.IntentFilter; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 30 | import android.content.res.Configuration; |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 31 | import android.content.res.Resources; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 32 | import android.graphics.Bitmap; |
| 33 | import android.graphics.Canvas; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 34 | import android.graphics.Rect; |
Jim Miller | a237a31 | 2014-11-06 18:05:59 -0800 | [diff] [blame] | 35 | import android.os.Handler; |
Winson Chung | 15a2ba8 | 2014-11-18 11:19:24 -0800 | [diff] [blame] | 36 | import android.os.SystemClock; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 37 | import android.os.UserHandle; |
Winson Chung | d751c01 | 2014-09-15 00:00:38 +0200 | [diff] [blame] | 38 | import android.util.Pair; |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 39 | import android.view.Display; |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 40 | import android.view.LayoutInflater; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 41 | import android.view.View; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 42 | import com.android.systemui.R; |
Winson Chung | 9214eff | 2014-06-12 13:59:25 -0700 | [diff] [blame] | 43 | import com.android.systemui.RecentsComponent; |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 44 | import com.android.systemui.SystemUI; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 45 | import com.android.systemui.recents.misc.Console; |
| 46 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 47 | import com.android.systemui.recents.model.RecentsTaskLoadPlan; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 48 | import com.android.systemui.recents.model.RecentsTaskLoader; |
| 49 | import com.android.systemui.recents.model.Task; |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 50 | import com.android.systemui.recents.model.TaskGrouping; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 51 | import com.android.systemui.recents.model.TaskStack; |
| 52 | import com.android.systemui.recents.views.TaskStackView; |
| 53 | import com.android.systemui.recents.views.TaskStackViewLayoutAlgorithm; |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 54 | import com.android.systemui.recents.views.TaskViewHeader; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 55 | import com.android.systemui.recents.views.TaskViewTransform; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 56 | |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 57 | import java.util.ArrayList; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 58 | import java.util.concurrent.atomic.AtomicBoolean; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 59 | |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 60 | /** |
| 61 | * Annotation for a method that is only called from the primary user's SystemUI process and will be |
| 62 | * proxied to the current user. |
| 63 | */ |
| 64 | @interface ProxyFromPrimaryToCurrentUser {} |
| 65 | /** |
| 66 | * Annotation for a method that may be called from any user's SystemUI process and will be proxied |
| 67 | * to the primary user. |
| 68 | */ |
| 69 | @interface ProxyFromAnyToPrimaryUser {} |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 70 | |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 71 | /** A proxy implementation for the recents component */ |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 72 | public class Recents extends SystemUI |
| 73 | implements ActivityOptions.OnAnimationStartedListener, RecentsComponent { |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 74 | |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 75 | final public static String EXTRA_TRIGGERED_FROM_ALT_TAB = "triggeredFromAltTab"; |
| 76 | final public static String EXTRA_TRIGGERED_FROM_HOME_KEY = "triggeredFromHomeKey"; |
| 77 | final public static String EXTRA_RECENTS_VISIBILITY = "recentsVisibility"; |
| 78 | |
| 79 | // Owner proxy events |
| 80 | final public static String ACTION_PROXY_NOTIFY_RECENTS_VISIBLITY_TO_OWNER = |
| 81 | "action_notify_recents_visibility_change"; |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 82 | |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 83 | final public static String ACTION_START_ENTER_ANIMATION = "action_start_enter_animation"; |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 84 | final public static String ACTION_TOGGLE_RECENTS_ACTIVITY = "action_toggle_recents_activity"; |
| 85 | final public static String ACTION_HIDE_RECENTS_ACTIVITY = "action_hide_recents_activity"; |
Winson Chung | b44c24f | 2014-04-09 15:17:43 -0700 | [diff] [blame] | 86 | |
Winson Chung | bf8871d | 2014-08-28 20:57:16 -0700 | [diff] [blame] | 87 | final static int sMinToggleDelay = 350; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 88 | |
Winson Chung | 2cf8b22 | 2015-01-20 11:44:05 -0800 | [diff] [blame] | 89 | public final static String sToggleRecentsAction = "com.android.systemui.recents.SHOW_RECENTS"; |
| 90 | public final static String sRecentsPackage = "com.android.systemui"; |
| 91 | public final static String sRecentsActivity = "com.android.systemui.recents.RecentsActivity"; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 92 | |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 93 | /** |
| 94 | * An implementation of ITaskStackListener, that allows us to listen for changes to the system |
| 95 | * task stacks and update recents accordingly. |
| 96 | */ |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 97 | class TaskStackListenerImpl extends ITaskStackListener.Stub implements Runnable { |
| 98 | Handler mHandler; |
| 99 | |
| 100 | public TaskStackListenerImpl(Handler handler) { |
| 101 | mHandler = handler; |
| 102 | } |
| 103 | |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 104 | @Override |
| 105 | public void onTaskStackChanged() { |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 106 | // Debounce any task stack changes |
| 107 | mHandler.removeCallbacks(this); |
| 108 | mHandler.post(this); |
| 109 | } |
| 110 | |
| 111 | /** Preloads the next task */ |
| 112 | public void run() { |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 113 | // Temporarily skip this if multi stack is enabled |
| 114 | if (mConfig.multiStackEnabled) return; |
| 115 | |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 116 | RecentsConfiguration config = RecentsConfiguration.getInstance(); |
| 117 | if (config.svelteLevel == RecentsConfiguration.SVELTE_NONE) { |
Winson Chung | 2cf8b22 | 2015-01-20 11:44:05 -0800 | [diff] [blame] | 118 | RecentsTaskLoader loader = RecentsTaskLoader.getInstance(); |
| 119 | SystemServicesProxy ssp = loader.getSystemServicesProxy(); |
| 120 | ActivityManager.RunningTaskInfo runningTaskInfo = ssp.getTopMostTask(); |
Winson Chung | 0eae557 | 2014-12-11 11:04:19 -0800 | [diff] [blame] | 121 | |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 122 | // Load the next task only if we aren't svelte |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 123 | RecentsTaskLoadPlan plan = loader.createLoadPlan(mContext); |
| 124 | loader.preloadTasks(plan, true /* isTopTaskHome */); |
| 125 | RecentsTaskLoadPlan.Options launchOpts = new RecentsTaskLoadPlan.Options(); |
Winson Chung | 0eae557 | 2014-12-11 11:04:19 -0800 | [diff] [blame] | 126 | // This callback is made when a new activity is launched and the old one is paused |
| 127 | // so ignore the current activity and try and preload the thumbnail for the |
| 128 | // previous one. |
| 129 | if (runningTaskInfo != null) { |
| 130 | launchOpts.runningTaskId = runningTaskInfo.id; |
| 131 | } |
| 132 | launchOpts.numVisibleTasks = 2; |
| 133 | launchOpts.numVisibleTaskThumbnails = 2; |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 134 | launchOpts.onlyLoadForCache = true; |
Winson Chung | 0eae557 | 2014-12-11 11:04:19 -0800 | [diff] [blame] | 135 | launchOpts.onlyLoadPausedActivities = true; |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 136 | loader.loadTasks(mContext, plan, launchOpts); |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 141 | /** |
| 142 | * A proxy for Recents events which happens strictly for the owner. |
| 143 | */ |
| 144 | class RecentsOwnerEventProxyReceiver extends BroadcastReceiver { |
| 145 | @Override |
| 146 | public void onReceive(Context context, Intent intent) { |
| 147 | switch (intent.getAction()) { |
| 148 | case ACTION_PROXY_NOTIFY_RECENTS_VISIBLITY_TO_OWNER: |
| 149 | visibilityChanged(intent.getBooleanExtra(EXTRA_RECENTS_VISIBILITY, false)); |
| 150 | break; |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | |
Winson Chung | 9214eff | 2014-06-12 13:59:25 -0700 | [diff] [blame] | 155 | static RecentsComponent.Callbacks sRecentsComponentCallbacks; |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 156 | static RecentsTaskLoadPlan sInstanceLoadPlan; |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 157 | static Recents sInstance; |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 158 | |
Winson Chung | 48a10a5 | 2014-08-27 14:36:51 -0700 | [diff] [blame] | 159 | LayoutInflater mInflater; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 160 | SystemServicesProxy mSystemServicesProxy; |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 161 | Handler mHandler; |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 162 | TaskStackListenerImpl mTaskStackListener; |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 163 | RecentsOwnerEventProxyReceiver mProxyBroadcastReceiver; |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 164 | boolean mBootCompleted; |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 165 | boolean mStartAnimationTriggered; |
| 166 | boolean mCanReuseTaskStackViews = true; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 167 | |
| 168 | // Task launching |
| 169 | RecentsConfiguration mConfig; |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 170 | Rect mWindowRect = new Rect(); |
| 171 | Rect mTaskStackBounds = new Rect(); |
| 172 | Rect mSystemInsets = new Rect(); |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 173 | TaskViewTransform mTmpTransform = new TaskViewTransform(); |
| 174 | int mStatusBarHeight; |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 175 | int mNavBarHeight; |
| 176 | int mNavBarWidth; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 177 | |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 178 | // Header (for transition) |
| 179 | TaskViewHeader mHeaderBar; |
| 180 | TaskStackView mDummyStackView; |
| 181 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 182 | // Variables to keep track of if we need to start recents after binding |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 183 | boolean mTriggeredFromAltTab; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 184 | long mLastToggleTime; |
| 185 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 186 | public Recents() { |
| 187 | } |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 188 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 189 | /** |
| 190 | * Gets the singleton instance and starts it if needed. On the primary user on the device, this |
| 191 | * component gets started as a normal {@link SystemUI} component. On a secondary user, this |
| 192 | * lifecycle doesn't exist, so we need to start it manually here if needed. |
| 193 | */ |
| 194 | public static Recents getInstanceAndStartIfNeeded(Context ctx) { |
| 195 | if (sInstance == null) { |
| 196 | sInstance = new Recents(); |
| 197 | sInstance.mContext = ctx; |
| 198 | sInstance.start(); |
| 199 | sInstance.onBootCompleted(); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 200 | } |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 201 | return sInstance; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 204 | /** Creates a new broadcast intent */ |
| 205 | static Intent createLocalBroadcastIntent(Context context, String action) { |
| 206 | Intent intent = new Intent(action); |
| 207 | intent.setPackage(context.getPackageName()); |
| 208 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT | |
| 209 | Intent.FLAG_RECEIVER_FOREGROUND); |
| 210 | return intent; |
| 211 | } |
| 212 | |
| 213 | /** Initializes the Recents. */ |
| 214 | @ProxyFromPrimaryToCurrentUser |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 215 | @Override |
| 216 | public void start() { |
| 217 | if (sInstance == null) { |
| 218 | sInstance = this; |
| 219 | } |
| 220 | RecentsTaskLoader.initialize(mContext); |
| 221 | mInflater = LayoutInflater.from(mContext); |
| 222 | mSystemServicesProxy = new SystemServicesProxy(mContext); |
| 223 | mHandler = new Handler(); |
| 224 | mTaskStackBounds = new Rect(); |
| 225 | |
| 226 | // Register the task stack listener |
| 227 | mTaskStackListener = new TaskStackListenerImpl(mHandler); |
| 228 | mSystemServicesProxy.registerTaskStackListener(mTaskStackListener); |
| 229 | |
| 230 | // Only the owner has the callback to update the SysUI visibility flags, so all non-owner |
| 231 | // instances of AlternateRecentsComponent needs to notify the owner when the visibility |
| 232 | // changes. |
| 233 | if (mSystemServicesProxy.isForegroundUserOwner()) { |
| 234 | mProxyBroadcastReceiver = new RecentsOwnerEventProxyReceiver(); |
| 235 | IntentFilter filter = new IntentFilter(); |
| 236 | filter.addAction(Recents.ACTION_PROXY_NOTIFY_RECENTS_VISIBLITY_TO_OWNER); |
| 237 | mContext.registerReceiverAsUser(mProxyBroadcastReceiver, UserHandle.CURRENT, filter, |
| 238 | null, mHandler); |
| 239 | } |
| 240 | |
Winson Chung | 48a10a5 | 2014-08-27 14:36:51 -0700 | [diff] [blame] | 241 | // Initialize some static datastructures |
| 242 | TaskStackViewLayoutAlgorithm.initializeCurve(); |
| 243 | // Load the header bar layout |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 244 | reloadHeaderBarLayout(true); |
Winson Chung | bac679b | 2014-10-20 14:11:12 -0700 | [diff] [blame] | 245 | |
Winson Chung | 90d5136e | 2014-11-13 14:30:26 -0800 | [diff] [blame] | 246 | // When we start, preload the data associated with the previous recent tasks. |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 247 | // We can use a new plan since the caches will be the same. |
| 248 | RecentsTaskLoader loader = RecentsTaskLoader.getInstance(); |
| 249 | RecentsTaskLoadPlan plan = loader.createLoadPlan(mContext); |
| 250 | loader.preloadTasks(plan, true /* isTopTaskHome */); |
| 251 | RecentsTaskLoadPlan.Options launchOpts = new RecentsTaskLoadPlan.Options(); |
| 252 | launchOpts.numVisibleTasks = loader.getApplicationIconCacheSize(); |
Winson Chung | 90d5136e | 2014-11-13 14:30:26 -0800 | [diff] [blame] | 253 | launchOpts.numVisibleTaskThumbnails = loader.getThumbnailCacheSize(); |
| 254 | launchOpts.onlyLoadForCache = true; |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 255 | loader.loadTasks(mContext, plan, launchOpts); |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 256 | putComponent(Recents.class, this); |
Winson Chung | 5abdceb | 2014-06-05 10:58:05 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 259 | @Override |
Winson Chung | 8bf05af | 2014-09-29 13:42:49 -0700 | [diff] [blame] | 260 | public void onBootCompleted() { |
| 261 | mBootCompleted = true; |
| 262 | } |
| 263 | |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 264 | /** Shows the Recents. */ |
| 265 | @ProxyFromPrimaryToCurrentUser |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 266 | @Override |
| 267 | public void showRecents(boolean triggeredFromAltTab, View statusBarView) { |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 268 | if (mSystemServicesProxy.isForegroundUserOwner()) { |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 269 | showRecentsInternal(triggeredFromAltTab); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 270 | } else { |
| 271 | Intent intent = createLocalBroadcastIntent(mContext, |
| 272 | RecentsUserEventProxyReceiver.ACTION_PROXY_SHOW_RECENTS_TO_USER); |
| 273 | intent.putExtra(EXTRA_TRIGGERED_FROM_ALT_TAB, triggeredFromAltTab); |
| 274 | mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT); |
| 275 | } |
| 276 | } |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 277 | |
| 278 | void showRecentsInternal(boolean triggeredFromAltTab) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 279 | mTriggeredFromAltTab = triggeredFromAltTab; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 280 | |
| 281 | try { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 282 | startRecentsActivity(); |
| 283 | } catch (ActivityNotFoundException e) { |
| 284 | Console.logRawError("Failed to launch RecentAppsIntent", e); |
| 285 | } |
| 286 | } |
| 287 | |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 288 | /** Hides the Recents. */ |
| 289 | @ProxyFromPrimaryToCurrentUser |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 290 | @Override |
| 291 | public void hideRecents(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) { |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 292 | if (mSystemServicesProxy.isForegroundUserOwner()) { |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 293 | hideRecentsInternal(triggeredFromAltTab, triggeredFromHomeKey); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 294 | } else { |
| 295 | Intent intent = createLocalBroadcastIntent(mContext, |
| 296 | RecentsUserEventProxyReceiver.ACTION_PROXY_HIDE_RECENTS_TO_USER); |
| 297 | intent.putExtra(EXTRA_TRIGGERED_FROM_ALT_TAB, triggeredFromAltTab); |
| 298 | intent.putExtra(EXTRA_TRIGGERED_FROM_HOME_KEY, triggeredFromHomeKey); |
| 299 | mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT); |
| 300 | } |
| 301 | } |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 302 | |
| 303 | void hideRecentsInternal(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) { |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 304 | if (mBootCompleted) { |
Winson Chung | 2cf8b22 | 2015-01-20 11:44:05 -0800 | [diff] [blame] | 305 | ActivityManager.RunningTaskInfo topTask = mSystemServicesProxy.getTopMostTask(); |
| 306 | if (topTask != null && mSystemServicesProxy.isRecentsTopMost(topTask, null)) { |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 307 | // Notify recents to hide itself |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 308 | Intent intent = createLocalBroadcastIntent(mContext, ACTION_HIDE_RECENTS_ACTIVITY); |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 309 | intent.putExtra(EXTRA_TRIGGERED_FROM_ALT_TAB, triggeredFromAltTab); |
| 310 | intent.putExtra(EXTRA_TRIGGERED_FROM_HOME_KEY, triggeredFromHomeKey); |
Winson Chung | c37e129 | 2014-07-25 15:46:57 -0700 | [diff] [blame] | 311 | mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | } |
| 315 | |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 316 | /** Toggles the Recents activity. */ |
| 317 | @ProxyFromPrimaryToCurrentUser |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 318 | @Override |
| 319 | public void toggleRecents(Display display, int layoutDirection, View statusBarView) { |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 320 | if (mSystemServicesProxy.isForegroundUserOwner()) { |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 321 | toggleRecentsInternal(); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 322 | } else { |
| 323 | Intent intent = createLocalBroadcastIntent(mContext, |
| 324 | RecentsUserEventProxyReceiver.ACTION_PROXY_TOGGLE_RECENTS_TO_USER); |
| 325 | mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT); |
| 326 | } |
| 327 | } |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 328 | |
| 329 | void toggleRecentsInternal() { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 330 | mTriggeredFromAltTab = false; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 331 | |
| 332 | try { |
| 333 | toggleRecentsActivity(); |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 334 | } catch (ActivityNotFoundException e) { |
| 335 | Console.logRawError("Failed to launch RecentAppsIntent", e); |
| 336 | } |
| 337 | } |
| 338 | |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 339 | /** Preloads info for the Recents activity. */ |
| 340 | @ProxyFromPrimaryToCurrentUser |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 341 | @Override |
| 342 | public void preloadRecents() { |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 343 | if (mSystemServicesProxy.isForegroundUserOwner()) { |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 344 | preloadRecentsInternal(); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 345 | } else { |
| 346 | Intent intent = createLocalBroadcastIntent(mContext, |
| 347 | RecentsUserEventProxyReceiver.ACTION_PROXY_PRELOAD_RECENTS_TO_USER); |
| 348 | mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT); |
| 349 | } |
| 350 | } |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 351 | |
| 352 | void preloadRecentsInternal() { |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 353 | // Preload only the raw task list into a new load plan (which will be consumed by the |
| 354 | // RecentsActivity) |
| 355 | RecentsTaskLoader loader = RecentsTaskLoader.getInstance(); |
| 356 | sInstanceLoadPlan = loader.createLoadPlan(mContext); |
| 357 | sInstanceLoadPlan.preloadRawTasks(true); |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 360 | @Override |
| 361 | public void cancelPreloadingRecents() { |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 362 | // Do nothing |
| 363 | } |
| 364 | |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 365 | void showRelativeAffiliatedTask(boolean showNextTask) { |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 366 | // Return early if there is no focused stack |
| 367 | int focusedStackId = mSystemServicesProxy.getFocusedStack(); |
| 368 | TaskStack focusedStack = null; |
Winson Chung | ebfc698 | 2014-08-26 12:25:34 -0700 | [diff] [blame] | 369 | RecentsTaskLoader loader = RecentsTaskLoader.getInstance(); |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 370 | RecentsTaskLoadPlan plan = loader.createLoadPlan(mContext); |
| 371 | loader.preloadTasks(plan, true /* isTopTaskHome */); |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 372 | if (mConfig.multiStackEnabled) { |
| 373 | if (focusedStackId < 0) return; |
| 374 | focusedStack = plan.getTaskStack(focusedStackId); |
| 375 | } else { |
| 376 | focusedStack = plan.getAllTaskStacks().get(0); |
| 377 | } |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 378 | |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 379 | // Return early if there are no tasks in the focused stack |
| 380 | if (focusedStack.getTaskCount() == 0) return; |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 381 | |
Winson Chung | 2cf8b22 | 2015-01-20 11:44:05 -0800 | [diff] [blame] | 382 | ActivityManager.RunningTaskInfo runningTask = mSystemServicesProxy.getTopMostTask(); |
Winson Chung | bc571a9 | 2014-11-19 17:09:03 -0800 | [diff] [blame] | 383 | // Return early if there is no running task (can't determine affiliated tasks in this case) |
| 384 | if (runningTask == null) return; |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 385 | // Return early if the running task is in the home stack (optimization) |
| 386 | if (mSystemServicesProxy.isInHomeStack(runningTask.id)) return; |
| 387 | |
| 388 | // Find the task in the recents list |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 389 | ArrayList<Task> tasks = focusedStack.getTasks(); |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 390 | Task toTask = null; |
| 391 | ActivityOptions launchOpts = null; |
| 392 | int taskCount = tasks.size(); |
Winson Chung | 044d529 | 2014-11-06 11:05:19 -0800 | [diff] [blame] | 393 | int numAffiliatedTasks = 0; |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 394 | for (int i = 0; i < taskCount; i++) { |
| 395 | Task task = tasks.get(i); |
| 396 | if (task.key.id == runningTask.id) { |
| 397 | TaskGrouping group = task.group; |
| 398 | Task.TaskKey toTaskKey; |
| 399 | if (showNextTask) { |
| 400 | toTaskKey = group.getNextTaskInGroup(task); |
Winson Chung | 3aa9c22 | 2014-09-09 17:54:51 +0200 | [diff] [blame] | 401 | launchOpts = ActivityOptions.makeCustomAnimation(mContext, |
| 402 | R.anim.recents_launch_next_affiliated_task_target, |
| 403 | R.anim.recents_launch_next_affiliated_task_source); |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 404 | } else { |
| 405 | toTaskKey = group.getPrevTaskInGroup(task); |
Winson Chung | 3aa9c22 | 2014-09-09 17:54:51 +0200 | [diff] [blame] | 406 | launchOpts = ActivityOptions.makeCustomAnimation(mContext, |
| 407 | R.anim.recents_launch_prev_affiliated_task_target, |
| 408 | R.anim.recents_launch_prev_affiliated_task_source); |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 409 | } |
| 410 | if (toTaskKey != null) { |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 411 | toTask = focusedStack.findTaskWithId(toTaskKey.id); |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 412 | } |
Winson Chung | 044d529 | 2014-11-06 11:05:19 -0800 | [diff] [blame] | 413 | numAffiliatedTasks = group.getTaskCount(); |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 414 | break; |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | // Return early if there is no next task |
| 419 | if (toTask == null) { |
Winson Chung | 044d529 | 2014-11-06 11:05:19 -0800 | [diff] [blame] | 420 | if (numAffiliatedTasks > 1) { |
| 421 | if (showNextTask) { |
| 422 | mSystemServicesProxy.startInPlaceAnimationOnFrontMostApplication( |
| 423 | ActivityOptions.makeCustomInPlaceAnimation(mContext, |
| 424 | R.anim.recents_launch_next_affiliated_task_bounce)); |
| 425 | } else { |
| 426 | mSystemServicesProxy.startInPlaceAnimationOnFrontMostApplication( |
| 427 | ActivityOptions.makeCustomInPlaceAnimation(mContext, |
| 428 | R.anim.recents_launch_prev_affiliated_task_bounce)); |
| 429 | } |
Winson Chung | 3aa9c22 | 2014-09-09 17:54:51 +0200 | [diff] [blame] | 430 | } |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 431 | return; |
| 432 | } |
| 433 | |
| 434 | // Launch the task |
| 435 | if (toTask.isActive) { |
| 436 | // Bring an active task to the foreground |
| 437 | mSystemServicesProxy.moveTaskToFront(toTask.key.id, launchOpts); |
| 438 | } else { |
Winson Chung | 4e96eb7 | 2014-09-17 15:16:09 +0200 | [diff] [blame] | 439 | mSystemServicesProxy.startActivityFromRecents(mContext, toTask.key.id, |
| 440 | toTask.activityLabel, launchOpts); |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 441 | } |
| 442 | } |
| 443 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 444 | @Override |
| 445 | public void showNextAffiliatedTask() { |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 446 | showRelativeAffiliatedTask(true); |
| 447 | } |
| 448 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 449 | @Override |
| 450 | public void showPrevAffiliatedTask() { |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 451 | showRelativeAffiliatedTask(false); |
| 452 | } |
| 453 | |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 454 | /** Updates on configuration change. */ |
| 455 | @ProxyFromPrimaryToCurrentUser |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 456 | public void onConfigurationChanged(Configuration newConfig) { |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 457 | if (mSystemServicesProxy.isForegroundUserOwner()) { |
| 458 | configurationChanged(); |
| 459 | } else { |
| 460 | Intent intent = createLocalBroadcastIntent(mContext, |
| 461 | RecentsUserEventProxyReceiver.ACTION_PROXY_CONFIG_CHANGE_TO_USER); |
| 462 | mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT); |
| 463 | } |
| 464 | } |
| 465 | void configurationChanged() { |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 466 | // Don't reuse task stack views if the configuration changes |
| 467 | mCanReuseTaskStackViews = false; |
Winson Chung | bf8871d | 2014-08-28 20:57:16 -0700 | [diff] [blame] | 468 | // Reload the header bar layout |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 469 | reloadHeaderBarLayout(false); |
Winson Chung | 48a10a5 | 2014-08-27 14:36:51 -0700 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | /** Prepares the header bar layout. */ |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 473 | void reloadHeaderBarLayout(boolean reloadWidget) { |
Winson Chung | 48a10a5 | 2014-08-27 14:36:51 -0700 | [diff] [blame] | 474 | Resources res = mContext.getResources(); |
| 475 | mWindowRect = mSystemServicesProxy.getWindowRect(); |
| 476 | mStatusBarHeight = res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); |
| 477 | mNavBarHeight = res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height); |
| 478 | mNavBarWidth = res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width); |
Jason Monk | 56e09b4 | 2014-07-18 10:29:14 -0400 | [diff] [blame] | 479 | mConfig = RecentsConfiguration.reinitialize(mContext, mSystemServicesProxy); |
Winson Chung | 6057c91 | 2014-07-08 14:39:08 -0700 | [diff] [blame] | 480 | mConfig.updateOnConfigurationChange(); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 481 | if (reloadWidget) { |
| 482 | // Reload the widget id before we get the task stack bounds |
| 483 | reloadSearchBarAppWidget(mContext, mSystemServicesProxy); |
| 484 | } |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 485 | mConfig.getAvailableTaskStackBounds(mWindowRect.width(), mWindowRect.height(), |
| 486 | mStatusBarHeight, (mConfig.hasTransposedNavBar ? mNavBarWidth : 0), |
| 487 | mTaskStackBounds); |
Winson Chung | 27acf76 | 2014-09-05 17:24:20 +0200 | [diff] [blame] | 488 | if (mConfig.isLandscape && mConfig.hasTransposedNavBar) { |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 489 | mSystemInsets.set(0, mStatusBarHeight, mNavBarWidth, 0); |
| 490 | } else { |
| 491 | mSystemInsets.set(0, mStatusBarHeight, 0, mNavBarHeight); |
| 492 | } |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 493 | |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 494 | // Inflate the header bar layout so that we can rebind and draw it for the transition |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 495 | TaskStack stack = new TaskStack(); |
| 496 | mDummyStackView = new TaskStackView(mContext, stack); |
| 497 | TaskStackViewLayoutAlgorithm algo = mDummyStackView.getStackAlgorithm(); |
| 498 | Rect taskStackBounds = new Rect(mTaskStackBounds); |
| 499 | taskStackBounds.bottom -= mSystemInsets.bottom; |
| 500 | algo.computeRects(mWindowRect.width(), mWindowRect.height(), taskStackBounds); |
| 501 | Rect taskViewSize = algo.getUntransformedTaskViewSize(); |
| 502 | int taskBarHeight = res.getDimensionPixelSize(R.dimen.recents_task_bar_height); |
Winson Chung | 48a10a5 | 2014-08-27 14:36:51 -0700 | [diff] [blame] | 503 | mHeaderBar = (TaskViewHeader) mInflater.inflate(R.layout.recents_task_view_header, null, |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 504 | false); |
| 505 | mHeaderBar.measure( |
| 506 | View.MeasureSpec.makeMeasureSpec(taskViewSize.width(), View.MeasureSpec.EXACTLY), |
| 507 | View.MeasureSpec.makeMeasureSpec(taskBarHeight, View.MeasureSpec.EXACTLY)); |
| 508 | mHeaderBar.layout(0, 0, taskViewSize.width(), taskBarHeight); |
Winson Chung | 96e3bc1 | 2014-05-06 16:44:12 -0700 | [diff] [blame] | 509 | } |
| 510 | |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 511 | /** Prepares the search bar app widget */ |
| 512 | void reloadSearchBarAppWidget(Context context, SystemServicesProxy ssp) { |
| 513 | // Try and pre-emptively bind the search widget on startup to ensure that we |
| 514 | // have the right thumbnail bounds to animate to. |
| 515 | if (Constants.DebugFlags.App.EnableSearchLayout) { |
| 516 | // If there is no id, then bind a new search app widget |
| 517 | if (mConfig.searchBarAppWidgetId < 0) { |
| 518 | AppWidgetHost host = new RecentsAppWidgetHost(context, |
| 519 | Constants.Values.App.AppWidgetHostId); |
| 520 | Pair<Integer, AppWidgetProviderInfo> widgetInfo = ssp.bindSearchAppWidget(host); |
| 521 | if (widgetInfo != null) { |
| 522 | // Save the app widget id into the settings |
| 523 | mConfig.updateSearchBarAppWidgetId(context, widgetInfo.first); |
| 524 | } |
| 525 | } |
| 526 | } |
| 527 | } |
| 528 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 529 | /** Toggles the recents activity */ |
| 530 | void toggleRecentsActivity() { |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 531 | // If the user has toggled it too quickly, then just eat up the event here (it's better than |
| 532 | // showing a janky screenshot). |
| 533 | // NOTE: Ideally, the screenshot mechanism would take the window transform into account |
Winson Chung | 15a2ba8 | 2014-11-18 11:19:24 -0800 | [diff] [blame] | 534 | if ((SystemClock.elapsedRealtime() - mLastToggleTime) < sMinToggleDelay) { |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 535 | return; |
| 536 | } |
| 537 | |
| 538 | // If Recents is the front most activity, then we should just communicate with it directly |
| 539 | // to launch the first task or dismiss itself |
Winson Chung | 2cf8b22 | 2015-01-20 11:44:05 -0800 | [diff] [blame] | 540 | ActivityManager.RunningTaskInfo topTask = mSystemServicesProxy.getTopMostTask(); |
Winson Chung | bc571a9 | 2014-11-19 17:09:03 -0800 | [diff] [blame] | 541 | AtomicBoolean isTopTaskHome = new AtomicBoolean(true); |
Winson Chung | 2cf8b22 | 2015-01-20 11:44:05 -0800 | [diff] [blame] | 542 | if (topTask != null && mSystemServicesProxy.isRecentsTopMost(topTask, isTopTaskHome)) { |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 543 | // Notify recents to toggle itself |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 544 | Intent intent = createLocalBroadcastIntent(mContext, ACTION_TOGGLE_RECENTS_ACTIVITY); |
Winson Chung | c37e129 | 2014-07-25 15:46:57 -0700 | [diff] [blame] | 545 | mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT); |
Winson Chung | 15a2ba8 | 2014-11-18 11:19:24 -0800 | [diff] [blame] | 546 | mLastToggleTime = SystemClock.elapsedRealtime(); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 547 | return; |
| 548 | } else { |
| 549 | // Otherwise, start the recents activity |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 550 | startRecentsActivity(topTask, isTopTaskHome.get()); |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 551 | } |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 552 | } |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 553 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 554 | /** Starts the recents activity if it is not already running */ |
| 555 | void startRecentsActivity() { |
| 556 | // Check if the top task is in the home stack, and start the recents activity |
Winson Chung | 2cf8b22 | 2015-01-20 11:44:05 -0800 | [diff] [blame] | 557 | ActivityManager.RunningTaskInfo topTask = mSystemServicesProxy.getTopMostTask(); |
Winson Chung | bc571a9 | 2014-11-19 17:09:03 -0800 | [diff] [blame] | 558 | AtomicBoolean isTopTaskHome = new AtomicBoolean(true); |
Winson Chung | 2cf8b22 | 2015-01-20 11:44:05 -0800 | [diff] [blame] | 559 | if (topTask == null || !mSystemServicesProxy.isRecentsTopMost(topTask, isTopTaskHome)) { |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 560 | startRecentsActivity(topTask, isTopTaskHome.get()); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 561 | } |
| 562 | } |
| 563 | |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 564 | /** |
| 565 | * Creates the activity options for a unknown state->recents transition. |
| 566 | */ |
| 567 | ActivityOptions getUnknownTransitionActivityOptions() { |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 568 | mStartAnimationTriggered = false; |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 569 | return ActivityOptions.makeCustomAnimation(mContext, |
| 570 | R.anim.recents_from_unknown_enter, |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 571 | R.anim.recents_from_unknown_exit, |
| 572 | mHandler, this); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | /** |
| 576 | * Creates the activity options for a home->recents transition. |
| 577 | */ |
Winson Chung | bf8871d | 2014-08-28 20:57:16 -0700 | [diff] [blame] | 578 | ActivityOptions getHomeTransitionActivityOptions(boolean fromSearchHome) { |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 579 | mStartAnimationTriggered = false; |
Winson Chung | bf8871d | 2014-08-28 20:57:16 -0700 | [diff] [blame] | 580 | if (fromSearchHome) { |
| 581 | return ActivityOptions.makeCustomAnimation(mContext, |
| 582 | R.anim.recents_from_search_launcher_enter, |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 583 | R.anim.recents_from_search_launcher_exit, |
| 584 | mHandler, this); |
Winson Chung | bf8871d | 2014-08-28 20:57:16 -0700 | [diff] [blame] | 585 | } |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 586 | return ActivityOptions.makeCustomAnimation(mContext, |
| 587 | R.anim.recents_from_launcher_enter, |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 588 | R.anim.recents_from_launcher_exit, |
| 589 | mHandler, this); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | /** |
Winson Chung | 353c0b9 | 2014-10-16 17:43:23 -0700 | [diff] [blame] | 593 | * Creates the activity options for an app->recents transition. |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 594 | */ |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 595 | ActivityOptions getThumbnailTransitionActivityOptions(ActivityManager.RunningTaskInfo topTask, |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 596 | TaskStack stack, TaskStackView stackView) { |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 597 | // Update the destination rect |
| 598 | Task toTask = new Task(); |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 599 | TaskViewTransform toTransform = getThumbnailTransitionTransform(stack, stackView, |
| 600 | topTask.id, toTask); |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 601 | if (toTransform != null && toTask.key != null) { |
| 602 | Rect toTaskRect = toTransform.rect; |
Winson Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 603 | int toHeaderWidth = (int) (mHeaderBar.getMeasuredWidth() * toTransform.scale); |
| 604 | int toHeaderHeight = (int) (mHeaderBar.getMeasuredHeight() * toTransform.scale); |
| 605 | Bitmap thumbnail = Bitmap.createBitmap(toHeaderWidth, toHeaderHeight, |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 606 | Bitmap.Config.ARGB_8888); |
| 607 | if (Constants.DebugFlags.App.EnableTransitionThumbnailDebugMode) { |
| 608 | thumbnail.eraseColor(0xFFff0000); |
| 609 | } else { |
| 610 | Canvas c = new Canvas(thumbnail); |
| 611 | c.scale(toTransform.scale, toTransform.scale); |
| 612 | mHeaderBar.rebindToTask(toTask); |
| 613 | mHeaderBar.draw(c); |
| 614 | c.setBitmap(null); |
| 615 | } |
| 616 | |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 617 | mStartAnimationTriggered = false; |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 618 | return ActivityOptions.makeThumbnailAspectScaleDownAnimation(mDummyStackView, |
Winson Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 619 | thumbnail, toTaskRect.left, toTaskRect.top, toTaskRect.width(), |
Winson Chung | e494c38 | 2014-12-17 10:12:54 -0800 | [diff] [blame] | 620 | toTaskRect.height(), mHandler, this); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | // If both the screenshot and thumbnail fails, then just fall back to the default transition |
| 624 | return getUnknownTransitionActivityOptions(); |
| 625 | } |
| 626 | |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 627 | /** Returns the transition rect for the given task id. */ |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 628 | TaskViewTransform getThumbnailTransitionTransform(TaskStack stack, TaskStackView stackView, |
| 629 | int runningTaskId, Task runningTaskOut) { |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 630 | // Find the running task in the TaskStack |
| 631 | Task task = null; |
| 632 | ArrayList<Task> tasks = stack.getTasks(); |
| 633 | if (runningTaskId != -1) { |
| 634 | // Otherwise, try and find the task with the |
| 635 | int taskCount = tasks.size(); |
| 636 | for (int i = taskCount - 1; i >= 0; i--) { |
| 637 | Task t = tasks.get(i); |
| 638 | if (t.key.id == runningTaskId) { |
| 639 | task = t; |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 640 | runningTaskOut.copyFrom(t); |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 641 | break; |
| 642 | } |
| 643 | } |
| 644 | } |
| 645 | if (task == null) { |
| 646 | // If no task is specified or we can not find the task just use the front most one |
| 647 | task = tasks.get(tasks.size() - 1); |
| 648 | } |
| 649 | |
| 650 | // Get the transform for the running task |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 651 | stackView.getScroller().setStackScrollToInitialState(); |
| 652 | mTmpTransform = stackView.getStackAlgorithm().getStackTransform(task, |
| 653 | stackView.getScroller().getStackScroll(), mTmpTransform, null); |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 654 | return mTmpTransform; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 655 | } |
| 656 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 657 | /** Starts the recents activity */ |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 658 | void startRecentsActivity(ActivityManager.RunningTaskInfo topTask, boolean isTopTaskHome) { |
Winson Chung | 2cf8b22 | 2015-01-20 11:44:05 -0800 | [diff] [blame] | 659 | RecentsTaskLoader loader = RecentsTaskLoader.getInstance(); |
| 660 | RecentsConfiguration.reinitialize(mContext, mSystemServicesProxy); |
| 661 | |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 662 | if (sInstanceLoadPlan == null) { |
| 663 | // Create a new load plan if onPreloadRecents() was never triggered |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 664 | sInstanceLoadPlan = loader.createLoadPlan(mContext); |
| 665 | } |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 666 | |
| 667 | // Temporarily skip the transition (use a dummy fade) if multi stack is enabled. |
| 668 | // For multi-stack we need to figure out where each of the tasks are going. |
| 669 | if (mConfig.multiStackEnabled) { |
| 670 | loader.preloadTasks(sInstanceLoadPlan, true); |
| 671 | ArrayList<TaskStack> stacks = sInstanceLoadPlan.getAllTaskStacks(); |
| 672 | TaskStack stack = stacks.get(0); |
| 673 | mDummyStackView.updateMinMaxScrollForStack(stack, mTriggeredFromAltTab, true); |
| 674 | TaskStackViewLayoutAlgorithm.VisibilityReport stackVr = |
| 675 | mDummyStackView.computeStackVisibilityReport(); |
| 676 | ActivityOptions opts = getUnknownTransitionActivityOptions(); |
| 677 | startAlternateRecentsActivity(topTask, opts, true /* fromHome */, |
| 678 | false /* fromSearchHome */, false /* fromThumbnail */, stackVr); |
| 679 | return; |
| 680 | } |
| 681 | |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 682 | loader.preloadTasks(sInstanceLoadPlan, isTopTaskHome); |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 683 | ArrayList<TaskStack> stacks = sInstanceLoadPlan.getAllTaskStacks(); |
| 684 | TaskStack stack = stacks.get(0); |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 685 | |
| 686 | // Prepare the dummy stack for the transition |
| 687 | mDummyStackView.updateMinMaxScrollForStack(stack, mTriggeredFromAltTab, isTopTaskHome); |
| 688 | TaskStackViewLayoutAlgorithm.VisibilityReport stackVr = |
| 689 | mDummyStackView.computeStackVisibilityReport(); |
| 690 | boolean hasRecentTasks = stack.getTaskCount() > 0; |
Winson Chung | bc571a9 | 2014-11-19 17:09:03 -0800 | [diff] [blame] | 691 | boolean useThumbnailTransition = (topTask != null) && !isTopTaskHome && hasRecentTasks; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 692 | |
Winson Chung | 96e3bc1 | 2014-05-06 16:44:12 -0700 | [diff] [blame] | 693 | if (useThumbnailTransition) { |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 694 | // Ensure that we load the running task's icon |
| 695 | RecentsTaskLoadPlan.Options launchOpts = new RecentsTaskLoadPlan.Options(); |
| 696 | launchOpts.runningTaskId = topTask.id; |
| 697 | launchOpts.loadThumbnails = false; |
Winson Chung | 90d5136e | 2014-11-13 14:30:26 -0800 | [diff] [blame] | 698 | launchOpts.onlyLoadForCache = true; |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 699 | loader.loadTasks(mContext, sInstanceLoadPlan, launchOpts); |
| 700 | |
Winson Chung | 96e3bc1 | 2014-05-06 16:44:12 -0700 | [diff] [blame] | 701 | // Try starting with a thumbnail transition |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 702 | ActivityOptions opts = getThumbnailTransitionActivityOptions(topTask, stack, |
| 703 | mDummyStackView); |
Winson Chung | 96e3bc1 | 2014-05-06 16:44:12 -0700 | [diff] [blame] | 704 | if (opts != null) { |
Winson Chung | 860e2d8 | 2014-12-04 11:43:02 -0800 | [diff] [blame] | 705 | startAlternateRecentsActivity(topTask, opts, false /* fromHome */, |
| 706 | false /* fromSearchHome */, true /* fromThumbnail */, stackVr); |
Winson Chung | 96e3bc1 | 2014-05-06 16:44:12 -0700 | [diff] [blame] | 707 | } else { |
| 708 | // Fall through below to the non-thumbnail transition |
| 709 | useThumbnailTransition = false; |
| 710 | } |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | if (!useThumbnailTransition) { |
Winson Chung | 743d5c9 | 2014-06-13 10:14:53 -0700 | [diff] [blame] | 714 | // If there is no thumbnail transition, but is launching from home into recents, then |
| 715 | // use a quick home transition and do the animation from home |
Winson Chung | d7b2cb1 | 2014-06-26 15:08:50 -0700 | [diff] [blame] | 716 | if (hasRecentTasks) { |
Winson Chung | bf8871d | 2014-08-28 20:57:16 -0700 | [diff] [blame] | 717 | // Get the home activity info |
| 718 | String homeActivityPackage = mSystemServicesProxy.getHomeActivityPackageName(); |
| 719 | // Get the search widget info |
| 720 | AppWidgetProviderInfo searchWidget = null; |
| 721 | String searchWidgetPackage = null; |
| 722 | if (mConfig.hasSearchBarAppWidget()) { |
| 723 | searchWidget = mSystemServicesProxy.getAppWidgetInfo( |
| 724 | mConfig.searchBarAppWidgetId); |
| 725 | } else { |
| 726 | searchWidget = mSystemServicesProxy.resolveSearchAppWidget(); |
| 727 | } |
| 728 | if (searchWidget != null && searchWidget.provider != null) { |
| 729 | searchWidgetPackage = searchWidget.provider.getPackageName(); |
| 730 | } |
| 731 | // Determine whether we are coming from a search owned home activity |
| 732 | boolean fromSearchHome = false; |
| 733 | if (homeActivityPackage != null && searchWidgetPackage != null && |
| 734 | homeActivityPackage.equals(searchWidgetPackage)) { |
| 735 | fromSearchHome = true; |
| 736 | } |
| 737 | |
| 738 | ActivityOptions opts = getHomeTransitionActivityOptions(fromSearchHome); |
Winson Chung | 860e2d8 | 2014-12-04 11:43:02 -0800 | [diff] [blame] | 739 | startAlternateRecentsActivity(topTask, opts, true /* fromHome */, fromSearchHome, |
| 740 | false /* fromThumbnail */, stackVr); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 741 | } else { |
Winson Chung | 743d5c9 | 2014-06-13 10:14:53 -0700 | [diff] [blame] | 742 | // Otherwise we do the normal fade from an unknown source |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 743 | ActivityOptions opts = getUnknownTransitionActivityOptions(); |
Winson Chung | 860e2d8 | 2014-12-04 11:43:02 -0800 | [diff] [blame] | 744 | startAlternateRecentsActivity(topTask, opts, true /* fromHome */, |
| 745 | false /* fromSearchHome */, false /* fromThumbnail */, stackVr); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 746 | } |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 747 | } |
Winson Chung | 15a2ba8 | 2014-11-18 11:19:24 -0800 | [diff] [blame] | 748 | mLastToggleTime = SystemClock.elapsedRealtime(); |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | /** Starts the recents activity */ |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 752 | void startAlternateRecentsActivity(ActivityManager.RunningTaskInfo topTask, |
Winson Chung | 860e2d8 | 2014-12-04 11:43:02 -0800 | [diff] [blame] | 753 | ActivityOptions opts, boolean fromHome, boolean fromSearchHome, boolean fromThumbnail, |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 754 | TaskStackViewLayoutAlgorithm.VisibilityReport vr) { |
Winson Chung | 860e2d8 | 2014-12-04 11:43:02 -0800 | [diff] [blame] | 755 | // Update the configuration based on the launch options |
| 756 | mConfig.launchedFromHome = fromSearchHome || fromHome; |
| 757 | mConfig.launchedFromSearchHome = fromSearchHome; |
| 758 | mConfig.launchedFromAppWithThumbnail = fromThumbnail; |
| 759 | mConfig.launchedToTaskId = (topTask != null) ? topTask.id : -1; |
| 760 | mConfig.launchedWithAltTab = mTriggeredFromAltTab; |
| 761 | mConfig.launchedReuseTaskStackViews = mCanReuseTaskStackViews; |
| 762 | mConfig.launchedNumVisibleTasks = vr.numVisibleTasks; |
| 763 | mConfig.launchedNumVisibleThumbnails = vr.numVisibleThumbnails; |
| 764 | mConfig.launchedHasConfigurationChanged = false; |
| 765 | |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 766 | Intent intent = new Intent(sToggleRecentsAction); |
| 767 | intent.setClassName(sRecentsPackage, sRecentsActivity); |
| 768 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 769 | | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS |
| 770 | | Intent.FLAG_ACTIVITY_TASK_ON_HOME); |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 771 | if (opts != null) { |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 772 | mContext.startActivityAsUser(intent, opts.toBundle(), UserHandle.CURRENT); |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 773 | } else { |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 774 | mContext.startActivityAsUser(intent, UserHandle.CURRENT); |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 775 | } |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 776 | mCanReuseTaskStackViews = true; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 777 | } |
Winson Chung | 24cf152 | 2014-05-29 12:03:33 -0700 | [diff] [blame] | 778 | |
Winson Chung | 9214eff | 2014-06-12 13:59:25 -0700 | [diff] [blame] | 779 | /** Sets the RecentsComponent callbacks. */ |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 780 | @Override |
| 781 | public void setCallback(RecentsComponent.Callbacks cb) { |
Winson Chung | 9214eff | 2014-06-12 13:59:25 -0700 | [diff] [blame] | 782 | sRecentsComponentCallbacks = cb; |
| 783 | } |
| 784 | |
| 785 | /** Notifies the callbacks that the visibility of Recents has changed. */ |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 786 | @ProxyFromAnyToPrimaryUser |
| 787 | public static void notifyVisibilityChanged(Context context, SystemServicesProxy ssp, |
| 788 | boolean visible) { |
| 789 | if (ssp.isForegroundUserOwner()) { |
| 790 | visibilityChanged(visible); |
| 791 | } else { |
| 792 | Intent intent = createLocalBroadcastIntent(context, |
| 793 | ACTION_PROXY_NOTIFY_RECENTS_VISIBLITY_TO_OWNER); |
| 794 | intent.putExtra(EXTRA_RECENTS_VISIBILITY, visible); |
| 795 | context.sendBroadcastAsUser(intent, UserHandle.OWNER); |
| 796 | } |
| 797 | } |
| 798 | static void visibilityChanged(boolean visible) { |
Winson Chung | 9214eff | 2014-06-12 13:59:25 -0700 | [diff] [blame] | 799 | if (sRecentsComponentCallbacks != null) { |
| 800 | sRecentsComponentCallbacks.onVisibilityChanged(visible); |
| 801 | } |
| 802 | } |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 803 | |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 804 | /** |
| 805 | * Returns the preloaded load plan and invalidates it. |
| 806 | */ |
| 807 | public static RecentsTaskLoadPlan consumeInstanceLoadPlan() { |
| 808 | RecentsTaskLoadPlan plan = sInstanceLoadPlan; |
| 809 | sInstanceLoadPlan = null; |
| 810 | return plan; |
| 811 | } |
| 812 | |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 813 | /**** OnAnimationStartedListener Implementation ****/ |
| 814 | |
| 815 | @Override |
| 816 | public void onAnimationStarted() { |
| 817 | // Notify recents to start the enter animation |
| 818 | if (!mStartAnimationTriggered) { |
| 819 | // There can be a race condition between the start animation callback and |
| 820 | // the start of the new activity (where we register the receiver that listens |
| 821 | // to this broadcast, so we add our own receiver and if that gets called, then |
| 822 | // we know the activity has not yet started and we can retry sending the broadcast. |
| 823 | BroadcastReceiver fallbackReceiver = new BroadcastReceiver() { |
| 824 | @Override |
| 825 | public void onReceive(Context context, Intent intent) { |
| 826 | if (getResultCode() == Activity.RESULT_OK) { |
| 827 | mStartAnimationTriggered = true; |
| 828 | return; |
| 829 | } |
| 830 | |
| 831 | // Schedule for the broadcast to be sent again after some time |
| 832 | mHandler.postDelayed(new Runnable() { |
| 833 | @Override |
| 834 | public void run() { |
| 835 | onAnimationStarted(); |
| 836 | } |
| 837 | }, 25); |
| 838 | } |
| 839 | }; |
| 840 | |
| 841 | // Send the broadcast to notify Recents that the animation has started |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 842 | Intent intent = createLocalBroadcastIntent(mContext, ACTION_START_ENTER_ANIMATION); |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 843 | mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, null, |
| 844 | fallbackReceiver, null, Activity.RESULT_CANCELED, null, null); |
| 845 | } |
| 846 | } |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 847 | } |