blob: 51521509d113f74aefaac757c865916a86358a1f [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;
Kenny Guy94a07ac2014-08-07 15:34:38 +010027import android.os.UserHandle;
Winson Chung9f9679d2014-04-11 16:49:09 -070028import android.provider.Settings;
Winson Chung8e548f72014-06-24 14:40:53 -070029import android.util.AttributeSet;
Winson Chungecd9b302014-04-16 17:07:18 -070030import android.view.LayoutInflater;
Winson Chung303e1ff2014-03-07 15:06:19 -080031import android.view.View;
Winson Chung653f70c22014-05-19 14:49:42 -070032import android.view.WindowInsets;
Winson Chung303e1ff2014-03-07 15:06:19 -080033import android.widget.FrameLayout;
Winson Chung303e1ff2014-03-07 15:06:19 -080034import com.android.systemui.recents.Constants;
35import com.android.systemui.recents.RecentsConfiguration;
Winson Chung1f24c7e2014-07-11 17:06:48 -070036import com.android.systemui.recents.misc.SystemServicesProxy;
Winson Chungf1fbd772014-06-24 18:06:58 -070037import com.android.systemui.recents.model.RecentsPackageMonitor;
38import com.android.systemui.recents.model.RecentsTaskLoader;
Winson Chung303e1ff2014-03-07 15:06:19 -080039import com.android.systemui.recents.model.Task;
40import com.android.systemui.recents.model.TaskStack;
41
42import java.util.ArrayList;
Winson Chung6ac8bd62015-01-07 16:38:35 -080043import java.util.List;
Winson Chung303e1ff2014-03-07 15:06:19 -080044
Winson Chung303e1ff2014-03-07 15:06:19 -080045/**
46 * This view is the the top level layout that contains TaskStacks (which are laid out according
47 * to their SpaceNode bounds.
48 */
Winson Chung9f49df92014-05-07 18:08:34 -070049public class RecentsView extends FrameLayout implements TaskStackView.TaskStackViewCallbacks,
50 RecentsPackageMonitor.PackageCallbacks {
Winson Chung47c4c692014-03-17 10:17:11 -070051
52 /** The RecentsView callbacks */
53 public interface RecentsViewCallbacks {
Winson Chung7aceb9a2014-07-03 13:38:01 -070054 public void onTaskViewClicked();
Winson Chung4e96eb72014-09-17 15:16:09 +020055 public void onTaskLaunchFailed();
Winson Chung7aceb9a2014-07-03 13:38:01 -070056 public void onAllTaskViewsDismissed();
Winson Chungcdbbb7e2014-06-24 12:11:49 -070057 public void onExitToHomeAnimationTriggered();
Jason Monk18f99d92014-09-11 13:36:42 -040058 public void onScreenPinningRequest();
Winson Chung47c4c692014-03-17 10:17:11 -070059 }
60
Winson Chungd42a6cf2014-06-03 16:24:04 -070061 RecentsConfiguration mConfig;
62 LayoutInflater mInflater;
Winson Chungdcfa7972014-07-22 12:27:13 -070063 DebugOverlayView mDebugOverlay;
Winson Chungd42a6cf2014-06-03 16:24:04 -070064
Winson Chungdcfa7972014-07-22 12:27:13 -070065 ArrayList<TaskStack> mStacks;
Winson Chungecd9b302014-04-16 17:07:18 -070066 View mSearchBar;
Winson Chung47c4c692014-03-17 10:17:11 -070067 RecentsViewCallbacks mCb;
Winson Chung303e1ff2014-03-07 15:06:19 -080068
69 public RecentsView(Context context) {
70 super(context);
Winson Chung8e548f72014-06-24 14:40:53 -070071 }
72
73 public RecentsView(Context context, AttributeSet attrs) {
74 this(context, attrs, 0);
75 }
76
77 public RecentsView(Context context, AttributeSet attrs, int defStyleAttr) {
78 this(context, attrs, defStyleAttr, 0);
79 }
80
81 public RecentsView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
82 super(context, attrs, defStyleAttr, defStyleRes);
Winson Chungd42a6cf2014-06-03 16:24:04 -070083 mConfig = RecentsConfiguration.getInstance();
Winson Chungecd9b302014-04-16 17:07:18 -070084 mInflater = LayoutInflater.from(context);
Winson Chung303e1ff2014-03-07 15:06:19 -080085 }
86
Winson Chung47c4c692014-03-17 10:17:11 -070087 /** Sets the callbacks */
88 public void setCallbacks(RecentsViewCallbacks cb) {
89 mCb = cb;
90 }
91
Winson Chungdcfa7972014-07-22 12:27:13 -070092 /** Sets the debug overlay */
93 public void setDebugOverlay(DebugOverlayView overlay) {
94 mDebugOverlay = overlay;
95 }
Winson Chung303e1ff2014-03-07 15:06:19 -080096
Winson Chungdcfa7972014-07-22 12:27:13 -070097 /** Set/get the bsp root node */
98 public void setTaskStacks(ArrayList<TaskStack> stacks) {
Winson Chungb0a28ea2014-10-28 15:21:35 -070099 int numStacks = stacks.size();
100
101 // Make a list of the stack view children only
102 ArrayList<TaskStackView> stackViews = new ArrayList<TaskStackView>();
Winson Chung7aceb9a2014-07-03 13:38:01 -0700103 int childCount = getChildCount();
Winson Chungb0a28ea2014-10-28 15:21:35 -0700104 for (int i = 0; i < childCount; i++) {
105 View child = getChildAt(i);
106 if (child != mSearchBar) {
107 stackViews.add((TaskStackView) child);
Winson Chung7aceb9a2014-07-03 13:38:01 -0700108 }
109 }
110
Winson Chungb0a28ea2014-10-28 15:21:35 -0700111 // Remove all/extra stack views
112 int numTaskStacksToKeep = 0; // Keep no tasks if we are recreating the layout
113 if (mConfig.launchedReuseTaskStackViews) {
114 numTaskStacksToKeep = Math.min(childCount, numStacks);
115 }
116 for (int i = stackViews.size() - 1; i >= numTaskStacksToKeep; i--) {
117 removeView(stackViews.get(i));
118 stackViews.remove(i);
119 }
120
121 // Update the stack views that we are keeping
122 for (int i = 0; i < numTaskStacksToKeep; i++) {
Winson Chungbc571a92014-11-19 17:09:03 -0800123 TaskStackView tsv = stackViews.get(i);
124 // If onRecentsHidden is not triggered, we need to the stack view again here
125 tsv.reset();
126 tsv.setStack(stacks.get(i));
Winson Chungb0a28ea2014-10-28 15:21:35 -0700127 }
128
129 // Add remaining/recreate stack views
Winson Chungdcfa7972014-07-22 12:27:13 -0700130 mStacks = stacks;
Winson Chungb0a28ea2014-10-28 15:21:35 -0700131 for (int i = stackViews.size(); i < numStacks; i++) {
132 TaskStack stack = stacks.get(i);
Winson Chung303e1ff2014-03-07 15:06:19 -0800133 TaskStackView stackView = new TaskStackView(getContext(), stack);
134 stackView.setCallbacks(this);
135 addView(stackView);
136 }
Winson Chung02d49272014-08-29 13:57:29 -0700137
Winson Chungb0a28ea2014-10-28 15:21:35 -0700138 // Enable debug mode drawing on all the stacks if necessary
139 if (mConfig.debugModeEnabled) {
140 for (int i = childCount - 1; i >= 0; i--) {
141 View v = getChildAt(i);
142 if (v != mSearchBar) {
143 TaskStackView stackView = (TaskStackView) v;
144 stackView.setDebugOverlay(mDebugOverlay);
145 }
146 }
147 }
148
Winson Chungb0a28ea2014-10-28 15:21:35 -0700149 // Trigger a new layout
150 requestLayout();
Winson Chung19fc1172014-07-31 18:40:03 -0700151 }
152
Winson Chung1e8d71b2014-05-16 17:05:22 -0700153 /** Launches the focused task from the first stack if possible */
154 public boolean launchFocusedTask() {
155 // Get the first stack view
156 int childCount = getChildCount();
157 for (int i = 0; i < childCount; i++) {
158 View child = getChildAt(i);
Winson Chung7aceb9a2014-07-03 13:38:01 -0700159 if (child != mSearchBar) {
Winson Chung1e8d71b2014-05-16 17:05:22 -0700160 TaskStackView stackView = (TaskStackView) child;
161 TaskStack stack = stackView.mStack;
162 // Iterate the stack views and try and find the focused task
Winson Chung6ac8bd62015-01-07 16:38:35 -0800163 List<TaskView> taskViews = stackView.getTaskViews();
164 int taskViewCount = taskViews.size();
165 for (int j = 0; j < taskViewCount; j++) {
166 TaskView tv = taskViews.get(j);
Winson Chung1e8d71b2014-05-16 17:05:22 -0700167 Task task = tv.getTask();
168 if (tv.isFocusedTask()) {
Winson Chung1f24c7e2014-07-11 17:06:48 -0700169 onTaskViewClicked(stackView, tv, stack, task, false);
Winson Chung1e8d71b2014-05-16 17:05:22 -0700170 return true;
171 }
172 }
173 }
174 }
Winson Chung1e8d71b2014-05-16 17:05:22 -0700175 return false;
176 }
177
Winson Chungdcfa7972014-07-22 12:27:13 -0700178 /** Launches the task that Recents was launched from, if possible */
179 public boolean launchPreviousTask() {
Winson Chung47c4c692014-03-17 10:17:11 -0700180 // Get the first stack view
Winson Chung303e1ff2014-03-07 15:06:19 -0800181 int childCount = getChildCount();
182 for (int i = 0; i < childCount; i++) {
Winson Chungecd9b302014-04-16 17:07:18 -0700183 View child = getChildAt(i);
Winson Chung7aceb9a2014-07-03 13:38:01 -0700184 if (child != mSearchBar) {
Winson Chungecd9b302014-04-16 17:07:18 -0700185 TaskStackView stackView = (TaskStackView) child;
186 TaskStack stack = stackView.mStack;
187 ArrayList<Task> tasks = stack.getTasks();
Winson Chung47c4c692014-03-17 10:17:11 -0700188
Winson Chungdcfa7972014-07-22 12:27:13 -0700189 // Find the launch task in the stack
Winson Chungecd9b302014-04-16 17:07:18 -0700190 if (!tasks.isEmpty()) {
Winson Chungdcfa7972014-07-22 12:27:13 -0700191 int taskCount = tasks.size();
192 for (int j = 0; j < taskCount; j++) {
193 if (tasks.get(j).isLaunchTarget) {
194 Task task = tasks.get(j);
195 TaskView tv = stackView.getChildViewForTask(task);
196 onTaskViewClicked(stackView, tv, stack, task, false);
197 return true;
Winson Chungecd9b302014-04-16 17:07:18 -0700198 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800199 }
200 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800201 }
202 }
203 return false;
204 }
205
Winson Chung24cf1522014-05-29 12:03:33 -0700206 /** Requests all task stacks to start their enter-recents animation */
Winson Chung969f5862014-06-16 17:08:24 -0700207 public void startEnterRecentsAnimation(ViewAnimation.TaskViewEnterContext ctx) {
Winson Chung740c3ac2014-11-12 16:14:38 -0800208 // We have to increment/decrement the post animation trigger in case there are no children
209 // to ensure that it runs
210 ctx.postAnimationTrigger.increment();
211
Winson Chung24cf1522014-05-29 12:03:33 -0700212 int childCount = getChildCount();
213 for (int i = 0; i < childCount; i++) {
214 View child = getChildAt(i);
Winson Chung7aceb9a2014-07-03 13:38:01 -0700215 if (child != mSearchBar) {
Winson Chung24cf1522014-05-29 12:03:33 -0700216 TaskStackView stackView = (TaskStackView) child;
Winson Chung969f5862014-06-16 17:08:24 -0700217 stackView.startEnterRecentsAnimation(ctx);
Winson Chung24cf1522014-05-29 12:03:33 -0700218 }
219 }
Winson Chung740c3ac2014-11-12 16:14:38 -0800220 ctx.postAnimationTrigger.decrement();
Winson Chung24cf1522014-05-29 12:03:33 -0700221 }
222
Winson Chungd42a6cf2014-06-03 16:24:04 -0700223 /** Requests all task stacks to start their exit-recents animation */
Winson Chung969f5862014-06-16 17:08:24 -0700224 public void startExitToHomeAnimation(ViewAnimation.TaskViewExitContext ctx) {
Winson Chunga91c2932014-11-07 15:02:38 -0800225 // We have to increment/decrement the post animation trigger in case there are no children
226 // to ensure that it runs
227 ctx.postAnimationTrigger.increment();
Winson Chungd7b2cb12014-06-26 15:08:50 -0700228 int childCount = getChildCount();
229 for (int i = 0; i < childCount; i++) {
230 View child = getChildAt(i);
Winson Chung7aceb9a2014-07-03 13:38:01 -0700231 if (child != mSearchBar) {
Winson Chungd7b2cb12014-06-26 15:08:50 -0700232 TaskStackView stackView = (TaskStackView) child;
233 stackView.startExitToHomeAnimation(ctx);
Winson Chungd42a6cf2014-06-03 16:24:04 -0700234 }
235 }
Winson Chunga91c2932014-11-07 15:02:38 -0800236 ctx.postAnimationTrigger.decrement();
Winson Chungd42a6cf2014-06-03 16:24:04 -0700237
Winson Chung969f5862014-06-16 17:08:24 -0700238 // Notify of the exit animation
Winson Chungcdbbb7e2014-06-24 12:11:49 -0700239 mCb.onExitToHomeAnimationTriggered();
Winson Chungd42a6cf2014-06-03 16:24:04 -0700240 }
241
Winson Chungf7bca432014-04-30 17:11:13 -0700242 /** Adds the search bar */
243 public void setSearchBar(View searchBar) {
244 // Create the search bar (and hide it if we have no recent tasks)
Winson Chung814086d2014-05-07 15:01:14 -0700245 if (Constants.DebugFlags.App.EnableSearchLayout) {
Winson Chungf7bca432014-04-30 17:11:13 -0700246 // Remove the previous search bar if one exists
247 if (mSearchBar != null && indexOfChild(mSearchBar) > -1) {
248 removeView(mSearchBar);
Winson Chungecd9b302014-04-16 17:07:18 -0700249 }
Winson Chungf7bca432014-04-30 17:11:13 -0700250 // Add the new search bar
251 if (searchBar != null) {
252 mSearchBar = searchBar;
Winson Chungf7bca432014-04-30 17:11:13 -0700253 addView(mSearchBar);
Winson Chungf7bca432014-04-30 17:11:13 -0700254 }
255 }
Winson Chungecd9b302014-04-16 17:07:18 -0700256 }
257
Winson Chung772b6b12014-07-03 15:54:02 -0700258 /** Returns whether there is currently a search bar */
259 public boolean hasSearchBar() {
260 return mSearchBar != null;
261 }
262
263 /** Sets the visibility of the search bar */
264 public void setSearchBarVisibility(int visibility) {
265 if (mSearchBar != null) {
266 mSearchBar.setVisibility(visibility);
Winson Chung012ef362014-07-31 18:36:25 -0700267 // Always bring the search bar to the top
268 mSearchBar.bringToFront();
Winson Chung772b6b12014-07-03 15:54:02 -0700269 }
270 }
271
Winson Chungf7bca432014-04-30 17:11:13 -0700272 /**
273 * This is called with the full size of the window since we are handling our own insets.
274 */
Winson Chung303e1ff2014-03-07 15:06:19 -0800275 @Override
276 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
277 int width = MeasureSpec.getSize(widthMeasureSpec);
278 int height = MeasureSpec.getSize(heightMeasureSpec);
Winson Chungbd912972014-03-18 14:36:35 -0700279
Winson Chungf7bca432014-04-30 17:11:13 -0700280 // Get the search bar bounds and measure the search bar layout
Winson Chungecd9b302014-04-16 17:07:18 -0700281 if (mSearchBar != null) {
Winson Chungf7bca432014-04-30 17:11:13 -0700282 Rect searchBarSpaceBounds = new Rect();
Winson Chungdcfa7972014-07-22 12:27:13 -0700283 mConfig.getSearchBarBounds(width, height, mConfig.systemInsets.top, searchBarSpaceBounds);
Winson Chungf7bca432014-04-30 17:11:13 -0700284 mSearchBar.measure(
285 MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.width(), MeasureSpec.EXACTLY),
286 MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.height(), MeasureSpec.EXACTLY));
Winson Chungecd9b302014-04-16 17:07:18 -0700287 }
288
Winson Chungf7bca432014-04-30 17:11:13 -0700289 Rect taskStackBounds = new Rect();
Winson Chungdcfa7972014-07-22 12:27:13 -0700290 mConfig.getTaskStackBounds(width, height, mConfig.systemInsets.top,
291 mConfig.systemInsets.right, taskStackBounds);
Winson Chung303e1ff2014-03-07 15:06:19 -0800292
Winson Chungdcfa7972014-07-22 12:27:13 -0700293 // Measure each TaskStackView with the full width and height of the window since the
294 // transition view is a child of that stack view
Winson Chung303e1ff2014-03-07 15:06:19 -0800295 int childCount = getChildCount();
296 for (int i = 0; i < childCount; i++) {
Winson Chungecd9b302014-04-16 17:07:18 -0700297 View child = getChildAt(i);
Winson Chung7aceb9a2014-07-03 13:38:01 -0700298 if (child != mSearchBar && child.getVisibility() != GONE) {
Winson Chungdcfa7972014-07-22 12:27:13 -0700299 TaskStackView tsv = (TaskStackView) child;
300 // Set the insets to be the top/left inset + search bounds
301 tsv.setStackInsetRect(taskStackBounds);
302 tsv.measure(widthMeasureSpec, heightMeasureSpec);
Winson Chung303e1ff2014-03-07 15:06:19 -0800303 }
304 }
305
306 setMeasuredDimension(width, height);
307 }
308
Winson Chungf7bca432014-04-30 17:11:13 -0700309 /**
310 * This is called with the full size of the window since we are handling our own insets.
311 */
Winson Chung303e1ff2014-03-07 15:06:19 -0800312 @Override
313 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
Winson Chungf7bca432014-04-30 17:11:13 -0700314 // Get the search bar bounds so that we lay it out
Winson Chungecd9b302014-04-16 17:07:18 -0700315 if (mSearchBar != null) {
Winson Chungf7bca432014-04-30 17:11:13 -0700316 Rect searchBarSpaceBounds = new Rect();
Winson Chungdcfa7972014-07-22 12:27:13 -0700317 mConfig.getSearchBarBounds(getMeasuredWidth(), getMeasuredHeight(),
318 mConfig.systemInsets.top, searchBarSpaceBounds);
319 mSearchBar.layout(searchBarSpaceBounds.left, searchBarSpaceBounds.top,
320 searchBarSpaceBounds.right, searchBarSpaceBounds.bottom);
Winson Chungecd9b302014-04-16 17:07:18 -0700321 }
322
Winson Chungdcfa7972014-07-22 12:27:13 -0700323 // Layout each TaskStackView with the full width and height of the window since the
324 // transition view is a child of that stack view
Winson Chung303e1ff2014-03-07 15:06:19 -0800325 int childCount = getChildCount();
326 for (int i = 0; i < childCount; i++) {
Winson Chungecd9b302014-04-16 17:07:18 -0700327 View child = getChildAt(i);
Winson Chung7aceb9a2014-07-03 13:38:01 -0700328 if (child != mSearchBar && child.getVisibility() != GONE) {
Winson Chungdcfa7972014-07-22 12:27:13 -0700329 child.layout(left, top, left + child.getMeasuredWidth(),
330 top + child.getMeasuredHeight());
Winson Chung303e1ff2014-03-07 15:06:19 -0800331 }
332 }
333 }
334
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700335 @Override
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700336 public WindowInsets onApplyWindowInsets(WindowInsets insets) {
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700337 // Update the configuration with the latest system insets and trigger a relayout
338 mConfig.updateSystemInsets(insets.getSystemWindowInsets());
339 requestLayout();
Winson Chungdcfa7972014-07-22 12:27:13 -0700340 return insets.consumeSystemWindowInsets();
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700341 }
342
Winson Chunga26fb782014-06-12 17:52:39 -0700343 /** Notifies each task view of the user interaction. */
344 public void onUserInteraction() {
345 // Get the first stack view
Winson Chunga26fb782014-06-12 17:52:39 -0700346 int childCount = getChildCount();
347 for (int i = 0; i < childCount; i++) {
348 View child = getChildAt(i);
Winson Chung7aceb9a2014-07-03 13:38:01 -0700349 if (child != mSearchBar) {
Winson Chunga0e88b52014-08-11 19:25:42 -0700350 TaskStackView stackView = (TaskStackView) child;
Winson Chunga26fb782014-06-12 17:52:39 -0700351 stackView.onUserInteraction();
352 }
353 }
354 }
355
Winson Chung1e8d71b2014-05-16 17:05:22 -0700356 /** Focuses the next task in the first stack view */
357 public void focusNextTask(boolean forward) {
358 // Get the first stack view
Winson Chung1e8d71b2014-05-16 17:05:22 -0700359 int childCount = getChildCount();
360 for (int i = 0; i < childCount; i++) {
361 View child = getChildAt(i);
Winson Chung7aceb9a2014-07-03 13:38:01 -0700362 if (child != mSearchBar) {
Winson Chunga0e88b52014-08-11 19:25:42 -0700363 TaskStackView stackView = (TaskStackView) child;
Winson Chungd213a1e2014-10-02 11:18:30 -0700364 stackView.focusNextTask(forward, true);
Winson Chung1e8d71b2014-05-16 17:05:22 -0700365 break;
366 }
367 }
Winson Chunga0e88b52014-08-11 19:25:42 -0700368 }
Winson Chung1e8d71b2014-05-16 17:05:22 -0700369
Winson Chunga0e88b52014-08-11 19:25:42 -0700370 /** Dismisses the focused task. */
371 public void dismissFocusedTask() {
372 // Get the first stack view
373 int childCount = getChildCount();
374 for (int i = 0; i < childCount; i++) {
375 View child = getChildAt(i);
376 if (child != mSearchBar) {
377 TaskStackView stackView = (TaskStackView) child;
378 stackView.dismissFocusedTask();
379 break;
380 }
Winson Chung1e8d71b2014-05-16 17:05:22 -0700381 }
382 }
383
Winson Chung303e1ff2014-03-07 15:06:19 -0800384 /** Unfilters any filtered stacks */
385 public boolean unfilterFilteredStacks() {
Winson Chungdcfa7972014-07-22 12:27:13 -0700386 if (mStacks != null) {
Winson Chung303e1ff2014-03-07 15:06:19 -0800387 // Check if there are any filtered stacks and unfilter them before we back out of Recents
388 boolean stacksUnfiltered = false;
Winson Chungdcfa7972014-07-22 12:27:13 -0700389 int numStacks = mStacks.size();
390 for (int i = 0; i < numStacks; i++) {
391 TaskStack stack = mStacks.get(i);
Winson Chung303e1ff2014-03-07 15:06:19 -0800392 if (stack.hasFilteredTasks()) {
393 stack.unfilterTasks();
394 stacksUnfiltered = true;
395 }
396 }
397 return stacksUnfiltered;
398 }
399 return false;
400 }
401
Winson Chung47c4c692014-03-17 10:17:11 -0700402 /**** TaskStackView.TaskStackCallbacks Implementation ****/
Winson Chung303e1ff2014-03-07 15:06:19 -0800403
404 @Override
Winson Chung7aceb9a2014-07-03 13:38:01 -0700405 public void onTaskViewClicked(final TaskStackView stackView, final TaskView tv,
Winson Chung1f24c7e2014-07-11 17:06:48 -0700406 final TaskStack stack, final Task task, final boolean lockToTask) {
Winson Chung47c4c692014-03-17 10:17:11 -0700407 // Notify any callbacks of the launching of a new task
408 if (mCb != null) {
Winson Chung7aceb9a2014-07-03 13:38:01 -0700409 mCb.onTaskViewClicked();
Winson Chung47c4c692014-03-17 10:17:11 -0700410 }
411
Winson Chunge0e45bc2014-06-17 17:56:17 -0700412 // Upfront the processing of the thumbnail
Winson Chungffa2ec62014-07-03 15:54:42 -0700413 TaskViewTransform transform = new TaskViewTransform();
Jorim Jaggicb557032014-09-16 23:09:24 +0200414 View sourceView;
Winson Chunge0e45bc2014-06-17 17:56:17 -0700415 int offsetX = 0;
416 int offsetY = 0;
Winson Chung012ef362014-07-31 18:36:25 -0700417 float stackScroll = stackView.getScroller().getStackScroll();
Winson Chunge0e45bc2014-06-17 17:56:17 -0700418 if (tv == null) {
419 // If there is no actual task view, then use the stack view as the source view
420 // and then offset to the expected transform rect, but bound this to just
421 // outside the display rect (to ensure we don't animate from too far away)
422 sourceView = stackView;
Winson Chung012ef362014-07-31 18:36:25 -0700423 transform = stackView.getStackAlgorithm().getStackTransform(task, stackScroll, transform, null);
Winson Chunge0e45bc2014-06-17 17:56:17 -0700424 offsetX = transform.rect.left;
Winson Chunge41ab842014-08-07 15:55:37 -0700425 offsetY = mConfig.displayRect.height();
Winson Chunge0e45bc2014-06-17 17:56:17 -0700426 } else {
Jorim Jaggicb557032014-09-16 23:09:24 +0200427 sourceView = tv.mThumbnailView;
Winson Chung012ef362014-07-31 18:36:25 -0700428 transform = stackView.getStackAlgorithm().getStackTransform(task, stackScroll, transform, null);
Winson Chunge0e45bc2014-06-17 17:56:17 -0700429 }
430
431 // Compute the thumbnail to scale up from
Winson Chung1f24c7e2014-07-11 17:06:48 -0700432 final SystemServicesProxy ssp =
433 RecentsTaskLoader.getInstance().getSystemServicesProxy();
Winson Chunge0e45bc2014-06-17 17:56:17 -0700434 ActivityOptions opts = null;
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200435 if (task.thumbnail != null && task.thumbnail.getWidth() > 0 &&
436 task.thumbnail.getHeight() > 0) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700437 Bitmap b;
438 if (tv != null) {
439 // Disable any focused state before we draw the header
440 if (tv.isFocusedTask()) {
441 tv.unsetFocusedTask();
442 }
443
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200444 float scale = tv.getScaleX();
445 int fromHeaderWidth = (int) (tv.mHeaderView.getMeasuredWidth() * scale);
446 int fromHeaderHeight = (int) (tv.mHeaderView.getMeasuredHeight() * scale);
447 b = Bitmap.createBitmap(fromHeaderWidth, fromHeaderHeight,
448 Bitmap.Config.ARGB_8888);
Winson Chunga4ccb862014-08-22 15:26:27 -0700449 if (Constants.DebugFlags.App.EnableTransitionThumbnailDebugMode) {
450 b.eraseColor(0xFFff0000);
451 } else {
452 Canvas c = new Canvas(b);
453 c.scale(tv.getScaleX(), tv.getScaleY());
454 tv.mHeaderView.draw(c);
455 c.setBitmap(null);
456 }
457 } else {
458 // Notify the system to skip the thumbnail layer by using an ALPHA_8 bitmap
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200459 b = Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8);
Winson Chunga4ccb862014-08-22 15:26:27 -0700460 }
Winson Chung1f24c7e2014-07-11 17:06:48 -0700461 ActivityOptions.OnAnimationStartedListener animStartedListener = null;
462 if (lockToTask) {
463 animStartedListener = new ActivityOptions.OnAnimationStartedListener() {
464 boolean mTriggered = false;
465 @Override
466 public void onAnimationStarted() {
467 if (!mTriggered) {
468 postDelayed(new Runnable() {
469 @Override
470 public void run() {
Jason Monk18f99d92014-09-11 13:36:42 -0400471 mCb.onScreenPinningRequest();
Winson Chung1f24c7e2014-07-11 17:06:48 -0700472 }
473 }, 350);
474 mTriggered = true;
475 }
476 }
477 };
478 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700479 opts = ActivityOptions.makeThumbnailAspectScaleUpAnimation(sourceView,
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200480 b, offsetX, offsetY, transform.rect.width(), transform.rect.height(),
Winson Chunge494c382014-12-17 10:12:54 -0800481 sourceView.getHandler(), animStartedListener);
Winson Chunge0e45bc2014-06-17 17:56:17 -0700482 }
483
484 final ActivityOptions launchOpts = opts;
Winson Chung303e1ff2014-03-07 15:06:19 -0800485 final Runnable launchRunnable = new Runnable() {
486 @Override
487 public void run() {
Winson Chung4be04452014-03-24 17:22:30 -0700488 if (task.isActive) {
489 // Bring an active task to the foreground
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700490 ssp.moveTaskToFront(task.key.id, launchOpts);
Winson Chung4be04452014-03-24 17:22:30 -0700491 } else {
Winson Chung4e96eb72014-09-17 15:16:09 +0200492 if (ssp.startActivityFromRecents(getContext(), task.key.id,
493 task.activityLabel, launchOpts)) {
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700494 if (launchOpts == null && lockToTask) {
Jason Monk18f99d92014-09-11 13:36:42 -0400495 mCb.onScreenPinningRequest();
Winson Chung4be04452014-03-24 17:22:30 -0700496 }
Winson Chung4e96eb72014-09-17 15:16:09 +0200497 } else {
498 // Dismiss the task and return the user to home if we fail to
499 // launch the task
500 onTaskViewDismissed(task);
501 if (mCb != null) {
502 mCb.onTaskLaunchFailed();
503 }
Winson Chung4be04452014-03-24 17:22:30 -0700504 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800505 }
506 }
507 };
508
509 // Launch the app right away if there is no task view, otherwise, animate the icon out first
Winson Chung814086d2014-05-07 15:01:14 -0700510 if (tv == null) {
Winson Chunga91c2932014-11-07 15:02:38 -0800511 launchRunnable.run();
Winson Chung303e1ff2014-03-07 15:06:19 -0800512 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -0700513 if (!task.group.isFrontMostTask(task)) {
514 // For affiliated tasks that are behind other tasks, we must animate the front cards
515 // out of view before starting the task transition
Winson Chungebfc6982014-08-26 12:25:34 -0700516 stackView.startLaunchTaskAnimation(tv, launchRunnable, lockToTask);
Winson Chunga4ccb862014-08-22 15:26:27 -0700517 } else {
518 // Otherwise, we can start the task transition immediately
Winson Chungebfc6982014-08-26 12:25:34 -0700519 stackView.startLaunchTaskAnimation(tv, null, lockToTask);
Winson Chunga91c2932014-11-07 15:02:38 -0800520 launchRunnable.run();
Winson Chunga4ccb862014-08-22 15:26:27 -0700521 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800522 }
523 }
Winson Chung9f9679d2014-04-11 16:49:09 -0700524
525 @Override
Winson Chung7aceb9a2014-07-03 13:38:01 -0700526 public void onTaskViewAppInfoClicked(Task t) {
Winson Chung9f9679d2014-04-11 16:49:09 -0700527 // Create a new task stack with the application info details activity
528 Intent baseIntent = t.key.baseIntent;
529 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
530 Uri.fromParts("package", baseIntent.getComponent().getPackageName(), null));
531 intent.setComponent(intent.resolveActivity(getContext().getPackageManager()));
532 TaskStackBuilder.create(getContext())
Kenny Guy94a07ac2014-08-07 15:34:38 +0100533 .addNextIntentWithParentStack(intent).startActivities(null,
Winson Chunga4ccb862014-08-22 15:26:27 -0700534 new UserHandle(t.key.userId));
Winson Chung9f9679d2014-04-11 16:49:09 -0700535 }
Winson Chung9f49df92014-05-07 18:08:34 -0700536
Winson Chung5393dff2014-05-08 14:25:43 -0700537 @Override
Winson Chung7aceb9a2014-07-03 13:38:01 -0700538 public void onTaskViewDismissed(Task t) {
Winson Chung5393dff2014-05-08 14:25:43 -0700539 // Remove any stored data from the loader. We currently don't bother notifying the views
Winson Chung7aceb9a2014-07-03 13:38:01 -0700540 // that the data has been unloaded because at the point we call onTaskViewDismissed(), the views
Winson Chung5393dff2014-05-08 14:25:43 -0700541 // either don't need to be updated, or have already been removed.
542 RecentsTaskLoader loader = RecentsTaskLoader.getInstance();
543 loader.deleteTaskData(t, false);
544
545 // Remove the old task from activity manager
Winson Chung2cf8b222015-01-20 11:44:05 -0800546 loader.getSystemServicesProxy().removeTask(t.key.id);
Winson Chung5393dff2014-05-08 14:25:43 -0700547 }
548
Winson Chung8e548f72014-06-24 14:40:53 -0700549 @Override
Winson Chung6ac8bd62015-01-07 16:38:35 -0800550 public void onAllTaskViewsDismissed(ArrayList<Task> removedTasks) {
551 if (removedTasks != null) {
552 int taskCount = removedTasks.size();
553 for (int i = 0; i < taskCount; i++) {
554 onTaskViewDismissed(removedTasks.get(i));
555 }
556 }
557
Winson Chung7aceb9a2014-07-03 13:38:01 -0700558 mCb.onAllTaskViewsDismissed();
Winson Chungd7b2cb12014-06-26 15:08:50 -0700559 }
560
Winson Chungb0a28ea2014-10-28 15:21:35 -0700561 /** Final callback after Recents is finally hidden. */
562 public void onRecentsHidden() {
563 // Notify each task stack view
564 int childCount = getChildCount();
565 for (int i = 0; i < childCount; i++) {
566 View child = getChildAt(i);
567 if (child != mSearchBar) {
568 TaskStackView stackView = (TaskStackView) child;
569 stackView.onRecentsHidden();
570 }
571 }
572 }
573
Winson Chungd7b2cb12014-06-26 15:08:50 -0700574 @Override
Winson Chung8e548f72014-06-24 14:40:53 -0700575 public void onTaskStackFilterTriggered() {
576 // Hide the search bar
577 if (mSearchBar != null) {
578 mSearchBar.animate()
579 .alpha(0f)
580 .setStartDelay(0)
581 .setInterpolator(mConfig.fastOutSlowInInterpolator)
582 .setDuration(mConfig.filteringCurrentViewsAnimDuration)
583 .withLayer()
584 .start();
585 }
586 }
587
588 @Override
589 public void onTaskStackUnfilterTriggered() {
590 // Show the search bar
591 if (mSearchBar != null) {
592 mSearchBar.animate()
593 .alpha(1f)
594 .setStartDelay(0)
595 .setInterpolator(mConfig.fastOutSlowInInterpolator)
596 .setDuration(mConfig.filteringNewViewsAnimDuration)
597 .withLayer()
598 .start();
599 }
600 }
601
Winson Chung9f49df92014-05-07 18:08:34 -0700602 /**** RecentsPackageMonitor.PackageCallbacks Implementation ****/
603
604 @Override
Winson Chung04400672014-10-17 14:53:30 -0700605 public void onPackagesChanged(RecentsPackageMonitor monitor, String packageName, int userId) {
Winson Chung9f49df92014-05-07 18:08:34 -0700606 // Propagate this event down to each task stack view
607 int childCount = getChildCount();
608 for (int i = 0; i < childCount; i++) {
609 View child = getChildAt(i);
Winson Chung7aceb9a2014-07-03 13:38:01 -0700610 if (child != mSearchBar) {
Winson Chung9f49df92014-05-07 18:08:34 -0700611 TaskStackView stackView = (TaskStackView) child;
Winson Chung04400672014-10-17 14:53:30 -0700612 stackView.onPackagesChanged(monitor, packageName, userId);
Winson Chung9f49df92014-05-07 18:08:34 -0700613 }
614 }
615 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800616}