blob: 6cb11b12bf29fb2675b6f4b0ad7b4921712d44bf [file] [log] [blame]
Winson Chung303e1ff2014-03-07 15:06:19 -08001/*
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
17package com.android.systemui.recents.views;
18
19import android.app.ActivityOptions;
Winson Chung9f9679d2014-04-11 16:49:09 -070020import android.app.TaskStackBuilder;
Winson Chung303e1ff2014-03-07 15:06:19 -080021import android.content.Context;
22import android.content.Intent;
23import android.graphics.Bitmap;
24import android.graphics.Canvas;
25import android.graphics.Rect;
Winson Chung9f9679d2014-04-11 16:49:09 -070026import android.net.Uri;
Jorim Jaggi6e18e002015-06-02 17:07:39 -070027import android.os.Bundle;
28import android.os.IRemoteCallback;
29import android.os.RemoteException;
Kenny Guy94a07ac2014-08-07 15:34:38 +010030import android.os.UserHandle;
Winson Chung9f9679d2014-04-11 16:49:09 -070031import android.provider.Settings;
Winson Chung8e548f72014-06-24 14:40:53 -070032import android.util.AttributeSet;
Jorim Jaggi6e18e002015-06-02 17:07:39 -070033import android.util.Log;
Winson Chungecd9b302014-04-16 17:07:18 -070034import android.view.LayoutInflater;
Winson Chung303e1ff2014-03-07 15:06:19 -080035import android.view.View;
Winson Chung653f70c22014-05-19 14:49:42 -070036import android.view.WindowInsets;
Jorim Jaggi6e18e002015-06-02 17:07:39 -070037import android.view.WindowManagerGlobal;
Winson Chung303e1ff2014-03-07 15:06:19 -080038import android.widget.FrameLayout;
Jorim Jaggi88f3db92015-06-02 16:29:40 -070039
Winson Chungd16c5652015-01-26 16:11:07 -080040import com.android.systemui.R;
Winson Chung303e1ff2014-03-07 15:06:19 -080041import com.android.systemui.recents.Constants;
Winson Chungaee097c2015-04-02 18:16:02 -070042import com.android.systemui.recents.RecentsAppWidgetHostView;
Winson Chung303e1ff2014-03-07 15:06:19 -080043import com.android.systemui.recents.RecentsConfiguration;
Winson Chung1f24c7e2014-07-11 17:06:48 -070044import com.android.systemui.recents.misc.SystemServicesProxy;
Winson Chungf1fbd772014-06-24 18:06:58 -070045import com.android.systemui.recents.model.RecentsPackageMonitor;
46import com.android.systemui.recents.model.RecentsTaskLoader;
Winson Chung303e1ff2014-03-07 15:06:19 -080047import com.android.systemui.recents.model.Task;
48import com.android.systemui.recents.model.TaskStack;
49
50import java.util.ArrayList;
Winson Chung6ac8bd62015-01-07 16:38:35 -080051import java.util.List;
Winson Chung303e1ff2014-03-07 15:06:19 -080052
Winson Chung303e1ff2014-03-07 15:06:19 -080053/**
54 * This view is the the top level layout that contains TaskStacks (which are laid out according
55 * to their SpaceNode bounds.
56 */
Winson Chung9f49df92014-05-07 18:08:34 -070057public class RecentsView extends FrameLayout implements TaskStackView.TaskStackViewCallbacks,
58 RecentsPackageMonitor.PackageCallbacks {
Winson Chung47c4c692014-03-17 10:17:11 -070059
Jorim Jaggi6e18e002015-06-02 17:07:39 -070060 private static final String TAG = "RecentsView";
61
Winson Chung47c4c692014-03-17 10:17:11 -070062 /** The RecentsView callbacks */
63 public interface RecentsViewCallbacks {
Winson Chung7aceb9a2014-07-03 13:38:01 -070064 public void onTaskViewClicked();
Winson Chung4e96eb72014-09-17 15:16:09 +020065 public void onTaskLaunchFailed();
Winson Chung7aceb9a2014-07-03 13:38:01 -070066 public void onAllTaskViewsDismissed();
Winson Chungcdbbb7e2014-06-24 12:11:49 -070067 public void onExitToHomeAnimationTriggered();
Jason Monk18f99d92014-09-11 13:36:42 -040068 public void onScreenPinningRequest();
Skuhneece738b2015-03-17 15:02:18 -070069 public void onTaskResize(Task t);
Jorim Jaggi6e18e002015-06-02 17:07:39 -070070 public void runAfterPause(Runnable r);
Winson Chung47c4c692014-03-17 10:17:11 -070071 }
72
Winson Chungd42a6cf2014-06-03 16:24:04 -070073 RecentsConfiguration mConfig;
74 LayoutInflater mInflater;
Winson Chungdcfa7972014-07-22 12:27:13 -070075 DebugOverlayView mDebugOverlay;
Winson Chungd16c5652015-01-26 16:11:07 -080076 RecentsViewLayoutAlgorithm mLayoutAlgorithm;
Winson Chungd42a6cf2014-06-03 16:24:04 -070077
Winson Chungdcfa7972014-07-22 12:27:13 -070078 ArrayList<TaskStack> mStacks;
Winson Chung93847da2015-02-03 10:26:22 -080079 List<TaskStackView> mTaskStackViews = new ArrayList<>();
Winson Chungaee097c2015-04-02 18:16:02 -070080 RecentsAppWidgetHostView mSearchBar;
Winson Chung47c4c692014-03-17 10:17:11 -070081 RecentsViewCallbacks mCb;
Winson Chung303e1ff2014-03-07 15:06:19 -080082
83 public RecentsView(Context context) {
84 super(context);
Winson Chung8e548f72014-06-24 14:40:53 -070085 }
86
87 public RecentsView(Context context, AttributeSet attrs) {
88 this(context, attrs, 0);
89 }
90
91 public RecentsView(Context context, AttributeSet attrs, int defStyleAttr) {
92 this(context, attrs, defStyleAttr, 0);
93 }
94
95 public RecentsView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
96 super(context, attrs, defStyleAttr, defStyleRes);
Winson Chungd42a6cf2014-06-03 16:24:04 -070097 mConfig = RecentsConfiguration.getInstance();
Winson Chungecd9b302014-04-16 17:07:18 -070098 mInflater = LayoutInflater.from(context);
Winson Chungd16c5652015-01-26 16:11:07 -080099 mLayoutAlgorithm = new RecentsViewLayoutAlgorithm(mConfig);
100 }
101
Winson Chung47c4c692014-03-17 10:17:11 -0700102 /** Sets the callbacks */
103 public void setCallbacks(RecentsViewCallbacks cb) {
104 mCb = cb;
105 }
106
Winson Chungdcfa7972014-07-22 12:27:13 -0700107 /** Sets the debug overlay */
108 public void setDebugOverlay(DebugOverlayView overlay) {
109 mDebugOverlay = overlay;
110 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800111
Winson Chungdcfa7972014-07-22 12:27:13 -0700112 /** Set/get the bsp root node */
113 public void setTaskStacks(ArrayList<TaskStack> stacks) {
Winson Chungb0a28ea2014-10-28 15:21:35 -0700114 int numStacks = stacks.size();
115
Winson Chungb0a28ea2014-10-28 15:21:35 -0700116 // Remove all/extra stack views
117 int numTaskStacksToKeep = 0; // Keep no tasks if we are recreating the layout
118 if (mConfig.launchedReuseTaskStackViews) {
Winson Chung93847da2015-02-03 10:26:22 -0800119 numTaskStacksToKeep = Math.min(mTaskStackViews.size(), numStacks);
Winson Chungb0a28ea2014-10-28 15:21:35 -0700120 }
Winson Chung93847da2015-02-03 10:26:22 -0800121 for (int i = mTaskStackViews.size() - 1; i >= numTaskStacksToKeep; i--) {
122 removeView(mTaskStackViews.remove(i));
Winson Chungb0a28ea2014-10-28 15:21:35 -0700123 }
124
125 // Update the stack views that we are keeping
126 for (int i = 0; i < numTaskStacksToKeep; i++) {
Winson Chung93847da2015-02-03 10:26:22 -0800127 TaskStackView tsv = mTaskStackViews.get(i);
Winson Chungbc571a92014-11-19 17:09:03 -0800128 // If onRecentsHidden is not triggered, we need to the stack view again here
129 tsv.reset();
130 tsv.setStack(stacks.get(i));
Winson Chungb0a28ea2014-10-28 15:21:35 -0700131 }
132
133 // Add remaining/recreate stack views
Winson Chungdcfa7972014-07-22 12:27:13 -0700134 mStacks = stacks;
Winson Chung93847da2015-02-03 10:26:22 -0800135 for (int i = mTaskStackViews.size(); i < numStacks; i++) {
Winson Chungb0a28ea2014-10-28 15:21:35 -0700136 TaskStack stack = stacks.get(i);
Winson Chung303e1ff2014-03-07 15:06:19 -0800137 TaskStackView stackView = new TaskStackView(getContext(), stack);
138 stackView.setCallbacks(this);
139 addView(stackView);
Winson Chung93847da2015-02-03 10:26:22 -0800140 mTaskStackViews.add(stackView);
Winson Chung303e1ff2014-03-07 15:06:19 -0800141 }
Winson Chung02d49272014-08-29 13:57:29 -0700142
Winson Chungb0a28ea2014-10-28 15:21:35 -0700143 // Enable debug mode drawing on all the stacks if necessary
144 if (mConfig.debugModeEnabled) {
Winson Chung93847da2015-02-03 10:26:22 -0800145 for (int i = mTaskStackViews.size() - 1; i >= 0; i--) {
146 TaskStackView stackView = mTaskStackViews.get(i);
Winson Chungd16c5652015-01-26 16:11:07 -0800147 stackView.setDebugOverlay(mDebugOverlay);
Winson Chungb0a28ea2014-10-28 15:21:35 -0700148 }
149 }
150
Winson Chungb0a28ea2014-10-28 15:21:35 -0700151 // Trigger a new layout
152 requestLayout();
Winson Chung19fc1172014-07-31 18:40:03 -0700153 }
154
Winson Chungd16c5652015-01-26 16:11:07 -0800155 /** Gets the list of task views */
156 List<TaskStackView> getTaskStackViews() {
Winson Chung93847da2015-02-03 10:26:22 -0800157 return mTaskStackViews;
Winson Chungd16c5652015-01-26 16:11:07 -0800158 }
159
Skuhne8aa7d162015-03-20 13:40:53 -0700160 /** Gets the next task in the stack - or if the last - the top task */
161 public Task getNextTaskOrTopTask(Task taskToSearch) {
162 Task returnTask = null;
163 boolean found = false;
164 List<TaskStackView> stackViews = getTaskStackViews();
165 int stackCount = stackViews.size();
166 for (int i = stackCount - 1; i >= 0; --i) {
167 TaskStack stack = stackViews.get(i).getStack();
168 ArrayList<Task> taskList = stack.getTasks();
169 // Iterate the stack views and try and find the focused task
170 for (int j = taskList.size() - 1; j >= 0; --j) {
171 Task task = taskList.get(j);
172 // Return the next task in the line.
173 if (found)
174 return task;
175 // Remember the first possible task as the top task.
176 if (returnTask == null)
177 returnTask = task;
178 if (task == taskToSearch)
179 found = true;
180 }
181 }
182 return returnTask;
183 }
184
Winson Chung1e8d71b2014-05-16 17:05:22 -0700185 /** Launches the focused task from the first stack if possible */
186 public boolean launchFocusedTask() {
187 // Get the first stack view
Winson Chungd16c5652015-01-26 16:11:07 -0800188 List<TaskStackView> stackViews = getTaskStackViews();
189 int stackCount = stackViews.size();
190 for (int i = 0; i < stackCount; i++) {
191 TaskStackView stackView = stackViews.get(i);
192 TaskStack stack = stackView.getStack();
193 // Iterate the stack views and try and find the focused task
194 List<TaskView> taskViews = stackView.getTaskViews();
195 int taskViewCount = taskViews.size();
196 for (int j = 0; j < taskViewCount; j++) {
197 TaskView tv = taskViews.get(j);
198 Task task = tv.getTask();
199 if (tv.isFocusedTask()) {
200 onTaskViewClicked(stackView, tv, stack, task, false);
201 return true;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700202 }
203 }
204 }
Winson Chung1e8d71b2014-05-16 17:05:22 -0700205 return false;
206 }
207
Skuhne8aa7d162015-03-20 13:40:53 -0700208 /** Launches a given task. */
209 public boolean launchTask(Task task) {
210 // Get the first stack view
211 List<TaskStackView> stackViews = getTaskStackViews();
212 int stackCount = stackViews.size();
213 for (int i = 0; i < stackCount; i++) {
214 TaskStackView stackView = stackViews.get(i);
215 TaskStack stack = stackView.getStack();
216 // Iterate the stack views and try and find the given task.
217 List<TaskView> taskViews = stackView.getTaskViews();
218 int taskViewCount = taskViews.size();
219 for (int j = 0; j < taskViewCount; j++) {
220 TaskView tv = taskViews.get(j);
221 if (tv.getTask() == task) {
222 onTaskViewClicked(stackView, tv, stack, task, false);
223 return true;
224 }
225 }
226 }
227 return false;
228 }
229
Winson Chungdcfa7972014-07-22 12:27:13 -0700230 /** Launches the task that Recents was launched from, if possible */
231 public boolean launchPreviousTask() {
Winson Chung47c4c692014-03-17 10:17:11 -0700232 // Get the first stack view
Winson Chungd16c5652015-01-26 16:11:07 -0800233 List<TaskStackView> stackViews = getTaskStackViews();
234 int stackCount = stackViews.size();
235 for (int i = 0; i < stackCount; i++) {
236 TaskStackView stackView = stackViews.get(i);
237 TaskStack stack = stackView.getStack();
238 ArrayList<Task> tasks = stack.getTasks();
Winson Chung47c4c692014-03-17 10:17:11 -0700239
Winson Chungd16c5652015-01-26 16:11:07 -0800240 // Find the launch task in the stack
241 if (!tasks.isEmpty()) {
242 int taskCount = tasks.size();
243 for (int j = 0; j < taskCount; j++) {
244 if (tasks.get(j).isLaunchTarget) {
245 Task task = tasks.get(j);
246 TaskView tv = stackView.getChildViewForTask(task);
247 onTaskViewClicked(stackView, tv, stack, task, false);
248 return true;
Winson Chung303e1ff2014-03-07 15:06:19 -0800249 }
250 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800251 }
252 }
253 return false;
254 }
255
Winson Chung24cf1522014-05-29 12:03:33 -0700256 /** Requests all task stacks to start their enter-recents animation */
Winson Chung969f5862014-06-16 17:08:24 -0700257 public void startEnterRecentsAnimation(ViewAnimation.TaskViewEnterContext ctx) {
Winson Chung740c3ac2014-11-12 16:14:38 -0800258 // We have to increment/decrement the post animation trigger in case there are no children
259 // to ensure that it runs
260 ctx.postAnimationTrigger.increment();
261
Winson Chungd16c5652015-01-26 16:11:07 -0800262 List<TaskStackView> stackViews = getTaskStackViews();
263 int stackCount = stackViews.size();
264 for (int i = 0; i < stackCount; i++) {
265 TaskStackView stackView = stackViews.get(i);
266 stackView.startEnterRecentsAnimation(ctx);
Winson Chung24cf1522014-05-29 12:03:33 -0700267 }
Winson Chung740c3ac2014-11-12 16:14:38 -0800268 ctx.postAnimationTrigger.decrement();
Winson Chung24cf1522014-05-29 12:03:33 -0700269 }
270
Winson Chungd42a6cf2014-06-03 16:24:04 -0700271 /** Requests all task stacks to start their exit-recents animation */
Winson Chung969f5862014-06-16 17:08:24 -0700272 public void startExitToHomeAnimation(ViewAnimation.TaskViewExitContext ctx) {
Winson Chunga91c2932014-11-07 15:02:38 -0800273 // We have to increment/decrement the post animation trigger in case there are no children
274 // to ensure that it runs
275 ctx.postAnimationTrigger.increment();
Winson Chungd16c5652015-01-26 16:11:07 -0800276 List<TaskStackView> stackViews = getTaskStackViews();
277 int stackCount = stackViews.size();
278 for (int i = 0; i < stackCount; i++) {
279 TaskStackView stackView = stackViews.get(i);
280 stackView.startExitToHomeAnimation(ctx);
Winson Chungd42a6cf2014-06-03 16:24:04 -0700281 }
Winson Chunga91c2932014-11-07 15:02:38 -0800282 ctx.postAnimationTrigger.decrement();
Winson Chungd42a6cf2014-06-03 16:24:04 -0700283
Winson Chung969f5862014-06-16 17:08:24 -0700284 // Notify of the exit animation
Winson Chungcdbbb7e2014-06-24 12:11:49 -0700285 mCb.onExitToHomeAnimationTriggered();
Winson Chungd42a6cf2014-06-03 16:24:04 -0700286 }
287
Winson Chungf7bca432014-04-30 17:11:13 -0700288 /** Adds the search bar */
Winson Chungaee097c2015-04-02 18:16:02 -0700289 public void setSearchBar(RecentsAppWidgetHostView searchBar) {
Winson Chungaf3bb692015-06-03 17:31:39 -0700290 // Remove the previous search bar if one exists
291 if (mSearchBar != null && indexOfChild(mSearchBar) > -1) {
292 removeView(mSearchBar);
293 }
294 // Add the new search bar
295 if (searchBar != null) {
296 mSearchBar = searchBar;
297 addView(mSearchBar);
Winson Chungf7bca432014-04-30 17:11:13 -0700298 }
Winson Chungecd9b302014-04-16 17:07:18 -0700299 }
300
Winson Chung772b6b12014-07-03 15:54:02 -0700301 /** Returns whether there is currently a search bar */
Winson Chungaee097c2015-04-02 18:16:02 -0700302 public boolean hasValidSearchBar() {
303 return mSearchBar != null && !mSearchBar.isReinflateRequired();
Winson Chung772b6b12014-07-03 15:54:02 -0700304 }
305
306 /** Sets the visibility of the search bar */
307 public void setSearchBarVisibility(int visibility) {
308 if (mSearchBar != null) {
309 mSearchBar.setVisibility(visibility);
Winson Chung012ef362014-07-31 18:36:25 -0700310 // Always bring the search bar to the top
311 mSearchBar.bringToFront();
Winson Chung772b6b12014-07-03 15:54:02 -0700312 }
313 }
314
Winson Chungf7bca432014-04-30 17:11:13 -0700315 /**
316 * This is called with the full size of the window since we are handling our own insets.
317 */
Winson Chung303e1ff2014-03-07 15:06:19 -0800318 @Override
319 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
320 int width = MeasureSpec.getSize(widthMeasureSpec);
321 int height = MeasureSpec.getSize(heightMeasureSpec);
Winson Chungbd912972014-03-18 14:36:35 -0700322
Winson Chungf7bca432014-04-30 17:11:13 -0700323 // Get the search bar bounds and measure the search bar layout
Winson Chungaf3bb692015-06-03 17:31:39 -0700324 Rect searchBarSpaceBounds = new Rect();
Winson Chungecd9b302014-04-16 17:07:18 -0700325 if (mSearchBar != null) {
Winson Chungdcfa7972014-07-22 12:27:13 -0700326 mConfig.getSearchBarBounds(width, height, mConfig.systemInsets.top, searchBarSpaceBounds);
Winson Chungf7bca432014-04-30 17:11:13 -0700327 mSearchBar.measure(
328 MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.width(), MeasureSpec.EXACTLY),
329 MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.height(), MeasureSpec.EXACTLY));
Winson Chungecd9b302014-04-16 17:07:18 -0700330 }
331
Winson Chungf7bca432014-04-30 17:11:13 -0700332 Rect taskStackBounds = new Rect();
Winson Chungd16c5652015-01-26 16:11:07 -0800333 mConfig.getAvailableTaskStackBounds(width, height, mConfig.systemInsets.top,
Winson Chungaf3bb692015-06-03 17:31:39 -0700334 mConfig.systemInsets.right, searchBarSpaceBounds, taskStackBounds);
Winson Chung303e1ff2014-03-07 15:06:19 -0800335
Winson Chungd16c5652015-01-26 16:11:07 -0800336 // Measure each TaskStackView with the full width and height of the window since the
Winson Chungdcfa7972014-07-22 12:27:13 -0700337 // transition view is a child of that stack view
Winson Chungd16c5652015-01-26 16:11:07 -0800338 List<TaskStackView> stackViews = getTaskStackViews();
339 List<Rect> stackViewsBounds = mLayoutAlgorithm.computeStackRects(stackViews,
340 taskStackBounds);
341 int stackCount = stackViews.size();
342 for (int i = 0; i < stackCount; i++) {
343 TaskStackView stackView = stackViews.get(i);
344 if (stackView.getVisibility() != GONE) {
345 // We are going to measure the TaskStackView with the whole RecentsView dimensions,
346 // but the actual stack is going to be inset to the bounds calculated by the layout
347 // algorithm
348 stackView.setStackInsetRect(stackViewsBounds.get(i));
349 stackView.measure(widthMeasureSpec, heightMeasureSpec);
Winson Chung303e1ff2014-03-07 15:06:19 -0800350 }
351 }
352
353 setMeasuredDimension(width, height);
354 }
355
Winson Chungf7bca432014-04-30 17:11:13 -0700356 /**
357 * This is called with the full size of the window since we are handling our own insets.
358 */
Winson Chung303e1ff2014-03-07 15:06:19 -0800359 @Override
360 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
Winson Chungf7bca432014-04-30 17:11:13 -0700361 // Get the search bar bounds so that we lay it out
Winson Chungecd9b302014-04-16 17:07:18 -0700362 if (mSearchBar != null) {
Winson Chungf7bca432014-04-30 17:11:13 -0700363 Rect searchBarSpaceBounds = new Rect();
Winson Chungdcfa7972014-07-22 12:27:13 -0700364 mConfig.getSearchBarBounds(getMeasuredWidth(), getMeasuredHeight(),
365 mConfig.systemInsets.top, searchBarSpaceBounds);
366 mSearchBar.layout(searchBarSpaceBounds.left, searchBarSpaceBounds.top,
367 searchBarSpaceBounds.right, searchBarSpaceBounds.bottom);
Winson Chungecd9b302014-04-16 17:07:18 -0700368 }
369
Winson Chungdcfa7972014-07-22 12:27:13 -0700370 // Layout each TaskStackView with the full width and height of the window since the
371 // transition view is a child of that stack view
Winson Chungd16c5652015-01-26 16:11:07 -0800372 List<TaskStackView> stackViews = getTaskStackViews();
373 int stackCount = stackViews.size();
374 for (int i = 0; i < stackCount; i++) {
375 TaskStackView stackView = stackViews.get(i);
376 if (stackView.getVisibility() != GONE) {
377 stackView.layout(left, top, left + stackView.getMeasuredWidth(),
378 top + stackView.getMeasuredHeight());
Winson Chung303e1ff2014-03-07 15:06:19 -0800379 }
380 }
381 }
382
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700383 @Override
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700384 public WindowInsets onApplyWindowInsets(WindowInsets insets) {
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700385 // Update the configuration with the latest system insets and trigger a relayout
386 mConfig.updateSystemInsets(insets.getSystemWindowInsets());
387 requestLayout();
Winson Chungdcfa7972014-07-22 12:27:13 -0700388 return insets.consumeSystemWindowInsets();
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700389 }
390
Winson Chunga26fb782014-06-12 17:52:39 -0700391 /** Notifies each task view of the user interaction. */
392 public void onUserInteraction() {
393 // Get the first stack view
Winson Chungd16c5652015-01-26 16:11:07 -0800394 List<TaskStackView> stackViews = getTaskStackViews();
395 int stackCount = stackViews.size();
396 for (int i = 0; i < stackCount; i++) {
397 TaskStackView stackView = stackViews.get(i);
398 stackView.onUserInteraction();
Winson Chunga26fb782014-06-12 17:52:39 -0700399 }
400 }
401
Winson Chung1e8d71b2014-05-16 17:05:22 -0700402 /** Focuses the next task in the first stack view */
403 public void focusNextTask(boolean forward) {
404 // Get the first stack view
Winson Chungd16c5652015-01-26 16:11:07 -0800405 List<TaskStackView> stackViews = getTaskStackViews();
406 if (!stackViews.isEmpty()) {
407 stackViews.get(0).focusNextTask(forward, true);
Winson Chung1e8d71b2014-05-16 17:05:22 -0700408 }
Winson Chunga0e88b52014-08-11 19:25:42 -0700409 }
Winson Chung1e8d71b2014-05-16 17:05:22 -0700410
Winson Chunga0e88b52014-08-11 19:25:42 -0700411 /** Dismisses the focused task. */
412 public void dismissFocusedTask() {
413 // Get the first stack view
Winson Chungd16c5652015-01-26 16:11:07 -0800414 List<TaskStackView> stackViews = getTaskStackViews();
415 if (!stackViews.isEmpty()) {
416 stackViews.get(0).dismissFocusedTask();
Winson Chung1e8d71b2014-05-16 17:05:22 -0700417 }
418 }
419
Winson Chung303e1ff2014-03-07 15:06:19 -0800420 /** Unfilters any filtered stacks */
421 public boolean unfilterFilteredStacks() {
Winson Chungdcfa7972014-07-22 12:27:13 -0700422 if (mStacks != null) {
Winson Chung303e1ff2014-03-07 15:06:19 -0800423 // Check if there are any filtered stacks and unfilter them before we back out of Recents
424 boolean stacksUnfiltered = false;
Winson Chungdcfa7972014-07-22 12:27:13 -0700425 int numStacks = mStacks.size();
426 for (int i = 0; i < numStacks; i++) {
427 TaskStack stack = mStacks.get(i);
Winson Chung303e1ff2014-03-07 15:06:19 -0800428 if (stack.hasFilteredTasks()) {
429 stack.unfilterTasks();
430 stacksUnfiltered = true;
431 }
432 }
433 return stacksUnfiltered;
434 }
435 return false;
436 }
437
Jorim Jaggi900fb482015-06-02 15:07:33 -0700438 public void disableLayersForOneFrame() {
439 List<TaskStackView> stackViews = getTaskStackViews();
440 for (int i = 0; i < stackViews.size(); i++) {
441 stackViews.get(i).disableLayersForOneFrame();
442 }
443 }
444
Jorim Jaggi6e18e002015-06-02 17:07:39 -0700445 private void postDrawHeaderThumbnailTransitionRunnable(final TaskView tv, final int offsetX,
446 final int offsetY, final TaskViewTransform transform,
447 final ActivityOptions.OnAnimationStartedListener animStartedListener) {
448 Runnable r = new Runnable() {
449 @Override
450 public void run() {
451 // Disable any focused state before we draw the header
452 if (tv.isFocusedTask()) {
453 tv.unsetFocusedTask();
454 }
455
456 float scale = tv.getScaleX();
457 int fromHeaderWidth = (int) (tv.mHeaderView.getMeasuredWidth() * scale);
458 int fromHeaderHeight = (int) (tv.mHeaderView.getMeasuredHeight() * scale);
459
460 Bitmap b = Bitmap.createBitmap(fromHeaderWidth, fromHeaderHeight,
461 Bitmap.Config.ARGB_8888);
462 if (Constants.DebugFlags.App.EnableTransitionThumbnailDebugMode) {
463 b.eraseColor(0xFFff0000);
464 } else {
465 Canvas c = new Canvas(b);
466 c.scale(tv.getScaleX(), tv.getScaleY());
467 tv.mHeaderView.draw(c);
468 c.setBitmap(null);
469 }
470 b = b.createAshmemBitmap();
471 int[] pts = new int[2];
472 tv.getLocationOnScreen(pts);
473 try {
474 WindowManagerGlobal.getWindowManagerService()
475 .overridePendingAppTransitionAspectScaledThumb(b,
476 pts[0] + offsetX,
477 pts[1] + offsetY,
478 transform.rect.width(),
479 transform.rect.height(),
480 new IRemoteCallback.Stub() {
481 @Override
482 public void sendResult(Bundle data)
483 throws RemoteException {
484 post(new Runnable() {
485 @Override
486 public void run() {
487 if (animStartedListener != null) {
488 animStartedListener.onAnimationStarted();
489 }
490 }
491 });
492 }
493 }, true);
494 } catch (RemoteException e) {
495 Log.w(TAG, "Error overriding app transition", e);
496 }
497 }
498 };
499 mCb.runAfterPause(r);
500 }
Winson Chung47c4c692014-03-17 10:17:11 -0700501 /**** TaskStackView.TaskStackCallbacks Implementation ****/
Winson Chung303e1ff2014-03-07 15:06:19 -0800502
503 @Override
Winson Chung7aceb9a2014-07-03 13:38:01 -0700504 public void onTaskViewClicked(final TaskStackView stackView, final TaskView tv,
Winson Chung1f24c7e2014-07-11 17:06:48 -0700505 final TaskStack stack, final Task task, final boolean lockToTask) {
Jorim Jaggi88f3db92015-06-02 16:29:40 -0700506
Winson Chung47c4c692014-03-17 10:17:11 -0700507 // Notify any callbacks of the launching of a new task
508 if (mCb != null) {
Winson Chung7aceb9a2014-07-03 13:38:01 -0700509 mCb.onTaskViewClicked();
Winson Chung47c4c692014-03-17 10:17:11 -0700510 }
511
Winson Chunge0e45bc2014-06-17 17:56:17 -0700512 // Upfront the processing of the thumbnail
Winson Chungffa2ec62014-07-03 15:54:42 -0700513 TaskViewTransform transform = new TaskViewTransform();
Jorim Jaggicb557032014-09-16 23:09:24 +0200514 View sourceView;
Winson Chunge0e45bc2014-06-17 17:56:17 -0700515 int offsetX = 0;
516 int offsetY = 0;
Winson Chung012ef362014-07-31 18:36:25 -0700517 float stackScroll = stackView.getScroller().getStackScroll();
Winson Chunge0e45bc2014-06-17 17:56:17 -0700518 if (tv == null) {
519 // If there is no actual task view, then use the stack view as the source view
520 // and then offset to the expected transform rect, but bound this to just
521 // outside the display rect (to ensure we don't animate from too far away)
522 sourceView = stackView;
Winson Chung012ef362014-07-31 18:36:25 -0700523 transform = stackView.getStackAlgorithm().getStackTransform(task, stackScroll, transform, null);
Winson Chunge0e45bc2014-06-17 17:56:17 -0700524 offsetX = transform.rect.left;
Winson Chunge41ab842014-08-07 15:55:37 -0700525 offsetY = mConfig.displayRect.height();
Winson Chunge0e45bc2014-06-17 17:56:17 -0700526 } else {
Jorim Jaggicb557032014-09-16 23:09:24 +0200527 sourceView = tv.mThumbnailView;
Winson Chung012ef362014-07-31 18:36:25 -0700528 transform = stackView.getStackAlgorithm().getStackTransform(task, stackScroll, transform, null);
Winson Chunge0e45bc2014-06-17 17:56:17 -0700529 }
530
531 // Compute the thumbnail to scale up from
Winson Chung1f24c7e2014-07-11 17:06:48 -0700532 final SystemServicesProxy ssp =
533 RecentsTaskLoader.getInstance().getSystemServicesProxy();
Winson Chunge0e45bc2014-06-17 17:56:17 -0700534 ActivityOptions opts = null;
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200535 if (task.thumbnail != null && task.thumbnail.getWidth() > 0 &&
536 task.thumbnail.getHeight() > 0) {
Winson Chung1f24c7e2014-07-11 17:06:48 -0700537 ActivityOptions.OnAnimationStartedListener animStartedListener = null;
538 if (lockToTask) {
539 animStartedListener = new ActivityOptions.OnAnimationStartedListener() {
540 boolean mTriggered = false;
541 @Override
542 public void onAnimationStarted() {
543 if (!mTriggered) {
544 postDelayed(new Runnable() {
545 @Override
546 public void run() {
Jason Monk18f99d92014-09-11 13:36:42 -0400547 mCb.onScreenPinningRequest();
Winson Chung1f24c7e2014-07-11 17:06:48 -0700548 }
549 }, 350);
550 mTriggered = true;
551 }
552 }
553 };
554 }
Jorim Jaggi6e18e002015-06-02 17:07:39 -0700555 if (tv != null) {
556 postDrawHeaderThumbnailTransitionRunnable(tv, offsetX, offsetY, transform,
557 animStartedListener);
558 }
Winson Chungd16c5652015-01-26 16:11:07 -0800559 if (mConfig.multiStackEnabled) {
560 opts = ActivityOptions.makeCustomAnimation(sourceView.getContext(),
561 R.anim.recents_from_unknown_enter,
562 R.anim.recents_from_unknown_exit,
563 sourceView.getHandler(), animStartedListener);
564 } else {
565 opts = ActivityOptions.makeThumbnailAspectScaleUpAnimation(sourceView,
Jorim Jaggi6e18e002015-06-02 17:07:39 -0700566 Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8).createAshmemBitmap(),
567 offsetX, offsetY, transform.rect.width(), transform.rect.height(),
Winson Chungd16c5652015-01-26 16:11:07 -0800568 sourceView.getHandler(), animStartedListener);
569 }
Winson Chunge0e45bc2014-06-17 17:56:17 -0700570 }
571
572 final ActivityOptions launchOpts = opts;
Winson Chung303e1ff2014-03-07 15:06:19 -0800573 final Runnable launchRunnable = new Runnable() {
574 @Override
575 public void run() {
Winson Chung4be04452014-03-24 17:22:30 -0700576 if (task.isActive) {
577 // Bring an active task to the foreground
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700578 ssp.moveTaskToFront(task.key.id, launchOpts);
Winson Chung4be04452014-03-24 17:22:30 -0700579 } else {
Winson Chung4e96eb72014-09-17 15:16:09 +0200580 if (ssp.startActivityFromRecents(getContext(), task.key.id,
581 task.activityLabel, launchOpts)) {
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700582 if (launchOpts == null && lockToTask) {
Jason Monk18f99d92014-09-11 13:36:42 -0400583 mCb.onScreenPinningRequest();
Winson Chung4be04452014-03-24 17:22:30 -0700584 }
Winson Chung4e96eb72014-09-17 15:16:09 +0200585 } else {
586 // Dismiss the task and return the user to home if we fail to
587 // launch the task
588 onTaskViewDismissed(task);
589 if (mCb != null) {
590 mCb.onTaskLaunchFailed();
591 }
Winson Chung4be04452014-03-24 17:22:30 -0700592 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800593 }
594 }
595 };
596
597 // Launch the app right away if there is no task view, otherwise, animate the icon out first
Winson Chung814086d2014-05-07 15:01:14 -0700598 if (tv == null) {
Winson Chunga91c2932014-11-07 15:02:38 -0800599 launchRunnable.run();
Winson Chung303e1ff2014-03-07 15:06:19 -0800600 } else {
Winson Chunge1e20e12015-06-02 14:11:49 -0700601 if (task.group != null && !task.group.isFrontMostTask(task)) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700602 // For affiliated tasks that are behind other tasks, we must animate the front cards
603 // out of view before starting the task transition
Winson Chungebfc6982014-08-26 12:25:34 -0700604 stackView.startLaunchTaskAnimation(tv, launchRunnable, lockToTask);
Winson Chunga4ccb862014-08-22 15:26:27 -0700605 } else {
606 // Otherwise, we can start the task transition immediately
Winson Chungebfc6982014-08-26 12:25:34 -0700607 stackView.startLaunchTaskAnimation(tv, null, lockToTask);
Winson Chunga91c2932014-11-07 15:02:38 -0800608 launchRunnable.run();
Winson Chunga4ccb862014-08-22 15:26:27 -0700609 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800610 }
611 }
Winson Chung9f9679d2014-04-11 16:49:09 -0700612
613 @Override
Winson Chung7aceb9a2014-07-03 13:38:01 -0700614 public void onTaskViewAppInfoClicked(Task t) {
Winson Chung9f9679d2014-04-11 16:49:09 -0700615 // Create a new task stack with the application info details activity
616 Intent baseIntent = t.key.baseIntent;
617 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
618 Uri.fromParts("package", baseIntent.getComponent().getPackageName(), null));
619 intent.setComponent(intent.resolveActivity(getContext().getPackageManager()));
620 TaskStackBuilder.create(getContext())
Kenny Guy94a07ac2014-08-07 15:34:38 +0100621 .addNextIntentWithParentStack(intent).startActivities(null,
Winson Chunga4ccb862014-08-22 15:26:27 -0700622 new UserHandle(t.key.userId));
Winson Chung9f9679d2014-04-11 16:49:09 -0700623 }
Winson Chung9f49df92014-05-07 18:08:34 -0700624
Winson Chung5393dff2014-05-08 14:25:43 -0700625 @Override
Winson Chung7aceb9a2014-07-03 13:38:01 -0700626 public void onTaskViewDismissed(Task t) {
Winson Chung5393dff2014-05-08 14:25:43 -0700627 // Remove any stored data from the loader. We currently don't bother notifying the views
Winson Chung7aceb9a2014-07-03 13:38:01 -0700628 // that the data has been unloaded because at the point we call onTaskViewDismissed(), the views
Winson Chung5393dff2014-05-08 14:25:43 -0700629 // either don't need to be updated, or have already been removed.
630 RecentsTaskLoader loader = RecentsTaskLoader.getInstance();
631 loader.deleteTaskData(t, false);
632
633 // Remove the old task from activity manager
Winson Chung2cf8b222015-01-20 11:44:05 -0800634 loader.getSystemServicesProxy().removeTask(t.key.id);
Winson Chung5393dff2014-05-08 14:25:43 -0700635 }
636
Winson Chung8e548f72014-06-24 14:40:53 -0700637 @Override
Winson Chung6ac8bd62015-01-07 16:38:35 -0800638 public void onAllTaskViewsDismissed(ArrayList<Task> removedTasks) {
639 if (removedTasks != null) {
640 int taskCount = removedTasks.size();
641 for (int i = 0; i < taskCount; i++) {
642 onTaskViewDismissed(removedTasks.get(i));
643 }
644 }
645
Winson Chung7aceb9a2014-07-03 13:38:01 -0700646 mCb.onAllTaskViewsDismissed();
Winson Chungd7b2cb12014-06-26 15:08:50 -0700647 }
648
Winson Chungb0a28ea2014-10-28 15:21:35 -0700649 /** Final callback after Recents is finally hidden. */
650 public void onRecentsHidden() {
651 // Notify each task stack view
Winson Chungd16c5652015-01-26 16:11:07 -0800652 List<TaskStackView> stackViews = getTaskStackViews();
653 int stackCount = stackViews.size();
654 for (int i = 0; i < stackCount; i++) {
655 TaskStackView stackView = stackViews.get(i);
656 stackView.onRecentsHidden();
Winson Chungb0a28ea2014-10-28 15:21:35 -0700657 }
658 }
659
Winson Chungd7b2cb12014-06-26 15:08:50 -0700660 @Override
Winson Chung8e548f72014-06-24 14:40:53 -0700661 public void onTaskStackFilterTriggered() {
662 // Hide the search bar
663 if (mSearchBar != null) {
664 mSearchBar.animate()
665 .alpha(0f)
666 .setStartDelay(0)
667 .setInterpolator(mConfig.fastOutSlowInInterpolator)
668 .setDuration(mConfig.filteringCurrentViewsAnimDuration)
669 .withLayer()
670 .start();
671 }
672 }
673
674 @Override
675 public void onTaskStackUnfilterTriggered() {
676 // Show the search bar
677 if (mSearchBar != null) {
678 mSearchBar.animate()
679 .alpha(1f)
680 .setStartDelay(0)
681 .setInterpolator(mConfig.fastOutSlowInInterpolator)
682 .setDuration(mConfig.filteringNewViewsAnimDuration)
683 .withLayer()
684 .start();
685 }
686 }
687
Winson Chungd16c5652015-01-26 16:11:07 -0800688 @Override
Skuhneece738b2015-03-17 15:02:18 -0700689 public void onTaskResize(Task t) {
Winson Chungd16c5652015-01-26 16:11:07 -0800690 if (mCb != null) {
Skuhneece738b2015-03-17 15:02:18 -0700691 mCb.onTaskResize(t);
Winson Chungd16c5652015-01-26 16:11:07 -0800692 }
693 }
694
Winson Chung9f49df92014-05-07 18:08:34 -0700695 /**** RecentsPackageMonitor.PackageCallbacks Implementation ****/
696
697 @Override
Winson Chung04400672014-10-17 14:53:30 -0700698 public void onPackagesChanged(RecentsPackageMonitor monitor, String packageName, int userId) {
Winson Chung9f49df92014-05-07 18:08:34 -0700699 // Propagate this event down to each task stack view
Winson Chungd16c5652015-01-26 16:11:07 -0800700 List<TaskStackView> stackViews = getTaskStackViews();
701 int stackCount = stackViews.size();
702 for (int i = 0; i < stackCount; i++) {
703 TaskStackView stackView = stackViews.get(i);
704 stackView.onPackagesChanged(monitor, packageName, userId);
Winson Chung9f49df92014-05-07 18:08:34 -0700705 }
706 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800707}