blob: 32f7e20df94a0c4017cbcaf7ef50518968c1c9f1 [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
Filip Gruszczynski170192a2015-08-16 17:46:34 -070019import android.app.ActivityManager;
Winson Chung303e1ff2014-03-07 15:06:19 -080020import android.app.ActivityOptions;
21import android.content.Context;
Winson Chung303e1ff2014-03-07 15:06:19 -080022import android.graphics.Bitmap;
23import android.graphics.Canvas;
24import android.graphics.Rect;
Winson4165d3362015-10-10 14:40:35 -070025import android.graphics.drawable.Drawable;
Jorim Jaggi6e18e002015-06-02 17:07:39 -070026import android.os.Bundle;
27import android.os.IRemoteCallback;
28import android.os.RemoteException;
Winson882072b2015-10-12 11:26:33 -070029import android.util.ArraySet;
Winson Chung8e548f72014-06-24 14:40:53 -070030import android.util.AttributeSet;
Jorim Jaggi6e18e002015-06-02 17:07:39 -070031import android.util.Log;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070032import android.util.SparseArray;
33import android.view.AppTransitionAnimationSpec;
Winson Chungecd9b302014-04-16 17:07:18 -070034import android.view.LayoutInflater;
Winsonbe7607a2015-10-01 17:24:51 -070035import android.view.MotionEvent;
Winson Chung303e1ff2014-03-07 15:06:19 -080036import android.view.View;
Winson Chung653f70c22014-05-19 14:49:42 -070037import android.view.WindowInsets;
Jorim Jaggi6e18e002015-06-02 17:07:39 -070038import android.view.WindowManagerGlobal;
Winson35f30502015-09-28 11:24:36 -070039import android.view.animation.AnimationUtils;
40import android.view.animation.Interpolator;
Winson Chung303e1ff2014-03-07 15:06:19 -080041import android.widget.FrameLayout;
Winson Chung5c9f4b92015-06-25 16:16:46 -070042import com.android.internal.logging.MetricsLogger;
Winson Chungd16c5652015-01-26 16:11:07 -080043import com.android.systemui.R;
Winson Chung303e1ff2014-03-07 15:06:19 -080044import com.android.systemui.recents.Constants;
Winsone7f138c2015-10-22 16:15:21 -070045import com.android.systemui.recents.Recents;
Winsonbe7607a2015-10-01 17:24:51 -070046import com.android.systemui.recents.RecentsActivity;
Winson Chungaee097c2015-04-02 18:16:02 -070047import com.android.systemui.recents.RecentsAppWidgetHostView;
Winson Chung303e1ff2014-03-07 15:06:19 -080048import com.android.systemui.recents.RecentsConfiguration;
Winson2536c7e2015-10-01 15:49:31 -070049import com.android.systemui.recents.events.EventBus;
Winson412e1802015-10-20 16:57:57 -070050import com.android.systemui.recents.events.activity.DismissRecentsToHomeAnimationStarted;
51import com.android.systemui.recents.events.component.ScreenPinningRequestEvent;
Winson0d14d4d2015-10-26 17:05:04 -070052import com.android.systemui.recents.events.ui.DismissTaskViewEvent;
Winsonbe7607a2015-10-01 17:24:51 -070053import com.android.systemui.recents.events.ui.dragndrop.DragDockStateChangedEvent;
54import com.android.systemui.recents.events.ui.dragndrop.DragEndEvent;
55import com.android.systemui.recents.events.ui.dragndrop.DragStartEvent;
Winson Chung1f24c7e2014-07-11 17:06:48 -070056import com.android.systemui.recents.misc.SystemServicesProxy;
Winson Chung303e1ff2014-03-07 15:06:19 -080057import com.android.systemui.recents.model.Task;
58import com.android.systemui.recents.model.TaskStack;
59
60import java.util.ArrayList;
Winson Chung6ac8bd62015-01-07 16:38:35 -080061import java.util.List;
Winson Chung303e1ff2014-03-07 15:06:19 -080062
Wale Ogunwale3797c222015-10-27 14:21:58 -070063import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
64import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
65import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
Winson412e1802015-10-20 16:57:57 -070066
Winson Chung303e1ff2014-03-07 15:06:19 -080067/**
68 * This view is the the top level layout that contains TaskStacks (which are laid out according
69 * to their SpaceNode bounds.
70 */
Winsone6c90732015-09-24 16:06:29 -070071public class RecentsView extends FrameLayout implements TaskStackView.TaskStackViewCallbacks {
Winson Chung47c4c692014-03-17 10:17:11 -070072
Jorim Jaggi6e18e002015-06-02 17:07:39 -070073 private static final String TAG = "RecentsView";
Winson0d14d4d2015-10-26 17:05:04 -070074 private static final boolean DEBUG = false;
Jorim Jaggi6e18e002015-06-02 17:07:39 -070075
Filip Gruszczynski170192a2015-08-16 17:46:34 -070076 private static final boolean ADD_HEADER_BITMAP = true;
77
Winson Chung47c4c692014-03-17 10:17:11 -070078 /** The RecentsView callbacks */
79 public interface RecentsViewCallbacks {
Winson Chung7aceb9a2014-07-03 13:38:01 -070080 public void onTaskViewClicked();
Winson Chung4e96eb72014-09-17 15:16:09 +020081 public void onTaskLaunchFailed();
Winson Chung7aceb9a2014-07-03 13:38:01 -070082 public void onAllTaskViewsDismissed();
Jorim Jaggi6e18e002015-06-02 17:07:39 -070083 public void runAfterPause(Runnable r);
Winson Chung47c4c692014-03-17 10:17:11 -070084 }
85
Winson Chungd42a6cf2014-06-03 16:24:04 -070086 LayoutInflater mInflater;
87
Winson Chungdcfa7972014-07-22 12:27:13 -070088 ArrayList<TaskStack> mStacks;
Winson147ecaf2015-09-16 16:49:55 -070089 TaskStackView mTaskStackView;
Winson Chungaee097c2015-04-02 18:16:02 -070090 RecentsAppWidgetHostView mSearchBar;
Winson Chung47c4c692014-03-17 10:17:11 -070091 RecentsViewCallbacks mCb;
Winsonbe7607a2015-10-01 17:24:51 -070092
93 RecentsViewTouchHandler mTouchHandler;
94 DragView mDragView;
Winson882072b2015-10-12 11:26:33 -070095 TaskStack.DockState[] mVisibleDockStates = {
96 TaskStack.DockState.LEFT,
97 TaskStack.DockState.TOP,
98 TaskStack.DockState.RIGHT,
99 TaskStack.DockState.BOTTOM,
100 };
Winsonbe7607a2015-10-01 17:24:51 -0700101
Winson35f30502015-09-28 11:24:36 -0700102 Interpolator mFastOutSlowInInterpolator;
103
104 Rect mSystemInsets = new Rect();
Winson Chung303e1ff2014-03-07 15:06:19 -0800105
106 public RecentsView(Context context) {
107 super(context);
Winson Chung8e548f72014-06-24 14:40:53 -0700108 }
109
110 public RecentsView(Context context, AttributeSet attrs) {
111 this(context, attrs, 0);
112 }
113
114 public RecentsView(Context context, AttributeSet attrs, int defStyleAttr) {
115 this(context, attrs, defStyleAttr, 0);
116 }
117
118 public RecentsView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
119 super(context, attrs, defStyleAttr, defStyleRes);
Winsonbe7607a2015-10-01 17:24:51 -0700120 setWillNotDraw(false);
Winson Chungecd9b302014-04-16 17:07:18 -0700121 mInflater = LayoutInflater.from(context);
Winson35f30502015-09-28 11:24:36 -0700122 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
123 com.android.internal.R.interpolator.fast_out_slow_in);
Winsonbe7607a2015-10-01 17:24:51 -0700124 mTouchHandler = new RecentsViewTouchHandler(this);
Winson Chungd16c5652015-01-26 16:11:07 -0800125 }
126
Winson Chung47c4c692014-03-17 10:17:11 -0700127 /** Sets the callbacks */
128 public void setCallbacks(RecentsViewCallbacks cb) {
129 mCb = cb;
130 }
131
Winson Chungdcfa7972014-07-22 12:27:13 -0700132 /** Set/get the bsp root node */
Winson147ecaf2015-09-16 16:49:55 -0700133 public void setTaskStack(TaskStack stack) {
Winson53ec42c2015-10-28 15:55:35 -0700134 RecentsConfiguration config = Recents.getConfiguration();
135 if (config.getLaunchState().launchedReuseTaskStackViews) {
Winson147ecaf2015-09-16 16:49:55 -0700136 if (mTaskStackView != null) {
137 // If onRecentsHidden is not triggered, we need to the stack view again here
138 mTaskStackView.reset();
139 mTaskStackView.setStack(stack);
140 } else {
141 mTaskStackView = new TaskStackView(getContext(), stack);
142 mTaskStackView.setCallbacks(this);
143 addView(mTaskStackView);
144 }
145 } else {
146 if (mTaskStackView != null) {
147 removeView(mTaskStackView);
148 }
149 mTaskStackView = new TaskStackView(getContext(), stack);
150 mTaskStackView.setCallbacks(this);
151 addView(mTaskStackView);
Winson Chung303e1ff2014-03-07 15:06:19 -0800152 }
Winson Chung02d49272014-08-29 13:57:29 -0700153
Winson Chungb0a28ea2014-10-28 15:21:35 -0700154 // Trigger a new layout
155 requestLayout();
Winson Chung19fc1172014-07-31 18:40:03 -0700156 }
157
Skuhne8aa7d162015-03-20 13:40:53 -0700158 /** Gets the next task in the stack - or if the last - the top task */
159 public Task getNextTaskOrTopTask(Task taskToSearch) {
Chong Zhang0fa656b2015-08-31 15:17:21 -0700160 Task returnTask = null;
Skuhne8aa7d162015-03-20 13:40:53 -0700161 boolean found = false;
Winson147ecaf2015-09-16 16:49:55 -0700162 if (mTaskStackView != null) {
163 TaskStack stack = mTaskStackView.getStack();
Skuhne8aa7d162015-03-20 13:40:53 -0700164 ArrayList<Task> taskList = stack.getTasks();
165 // Iterate the stack views and try and find the focused task
166 for (int j = taskList.size() - 1; j >= 0; --j) {
167 Task task = taskList.get(j);
168 // Return the next task in the line.
169 if (found)
170 return task;
171 // Remember the first possible task as the top task.
172 if (returnTask == null)
173 returnTask = task;
174 if (task == taskToSearch)
175 found = true;
176 }
177 }
178 return returnTask;
179 }
180
Winson Chung1e8d71b2014-05-16 17:05:22 -0700181 /** Launches the focused task from the first stack if possible */
182 public boolean launchFocusedTask() {
Winson147ecaf2015-09-16 16:49:55 -0700183 if (mTaskStackView != null) {
184 TaskStack stack = mTaskStackView.getStack();
Winson Chungd16c5652015-01-26 16:11:07 -0800185 // Iterate the stack views and try and find the focused task
Winson147ecaf2015-09-16 16:49:55 -0700186 List<TaskView> taskViews = mTaskStackView.getTaskViews();
Winson Chungd16c5652015-01-26 16:11:07 -0800187 int taskViewCount = taskViews.size();
188 for (int j = 0; j < taskViewCount; j++) {
189 TaskView tv = taskViews.get(j);
190 Task task = tv.getTask();
191 if (tv.isFocusedTask()) {
Filip Gruszczynskif48b5852015-10-13 10:28:22 -0700192 onTaskViewClicked(mTaskStackView, tv, stack, task, false, false, null,
193 INVALID_STACK_ID);
Winson Chungd16c5652015-01-26 16:11:07 -0800194 return true;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700195 }
196 }
197 }
Winson Chung1e8d71b2014-05-16 17:05:22 -0700198 return false;
199 }
200
Skuhne8aa7d162015-03-20 13:40:53 -0700201 /** Launches a given task. */
Filip Gruszczynskif48b5852015-10-13 10:28:22 -0700202 public boolean launchTask(Task task, Rect taskBounds, int destinationStack) {
Winson147ecaf2015-09-16 16:49:55 -0700203 if (mTaskStackView != null) {
204 TaskStack stack = mTaskStackView.getStack();
Skuhne8aa7d162015-03-20 13:40:53 -0700205 // Iterate the stack views and try and find the given task.
Winson147ecaf2015-09-16 16:49:55 -0700206 List<TaskView> taskViews = mTaskStackView.getTaskViews();
Skuhne8aa7d162015-03-20 13:40:53 -0700207 int taskViewCount = taskViews.size();
208 for (int j = 0; j < taskViewCount; j++) {
209 TaskView tv = taskViews.get(j);
210 if (tv.getTask() == task) {
Winsonb1bbaed2015-09-23 15:45:11 -0700211 onTaskViewClicked(mTaskStackView, tv, stack, task, false, taskBounds != null,
Filip Gruszczynskif48b5852015-10-13 10:28:22 -0700212 taskBounds, destinationStack);
Skuhne8aa7d162015-03-20 13:40:53 -0700213 return true;
214 }
215 }
216 }
217 return false;
218 }
219
Winson Chungdcfa7972014-07-22 12:27:13 -0700220 /** Launches the task that Recents was launched from, if possible */
221 public boolean launchPreviousTask() {
Winson147ecaf2015-09-16 16:49:55 -0700222 if (mTaskStackView != null) {
223 TaskStack stack = mTaskStackView.getStack();
Winson Chungd16c5652015-01-26 16:11:07 -0800224 ArrayList<Task> tasks = stack.getTasks();
Winson Chung47c4c692014-03-17 10:17:11 -0700225
Winson Chungd16c5652015-01-26 16:11:07 -0800226 // Find the launch task in the stack
Winsonbe7607a2015-10-01 17:24:51 -0700227 // TODO: replace this with an event from RecentsActivity
Winson Chungd16c5652015-01-26 16:11:07 -0800228 if (!tasks.isEmpty()) {
229 int taskCount = tasks.size();
230 for (int j = 0; j < taskCount; j++) {
231 if (tasks.get(j).isLaunchTarget) {
232 Task task = tasks.get(j);
Winson147ecaf2015-09-16 16:49:55 -0700233 TaskView tv = mTaskStackView.getChildViewForTask(task);
Filip Gruszczynskif48b5852015-10-13 10:28:22 -0700234 onTaskViewClicked(mTaskStackView, tv, stack, task, false, false, null,
235 INVALID_STACK_ID);
Winson Chungd16c5652015-01-26 16:11:07 -0800236 return true;
Winson Chung303e1ff2014-03-07 15:06:19 -0800237 }
238 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800239 }
240 }
241 return false;
242 }
243
Winson Chung24cf1522014-05-29 12:03:33 -0700244 /** Requests all task stacks to start their enter-recents animation */
Winson Chung969f5862014-06-16 17:08:24 -0700245 public void startEnterRecentsAnimation(ViewAnimation.TaskViewEnterContext ctx) {
Winson Chung740c3ac2014-11-12 16:14:38 -0800246 // We have to increment/decrement the post animation trigger in case there are no children
247 // to ensure that it runs
248 ctx.postAnimationTrigger.increment();
Winson147ecaf2015-09-16 16:49:55 -0700249 if (mTaskStackView != null) {
250 mTaskStackView.startEnterRecentsAnimation(ctx);
Winson Chung24cf1522014-05-29 12:03:33 -0700251 }
Winson Chung740c3ac2014-11-12 16:14:38 -0800252 ctx.postAnimationTrigger.decrement();
Winson Chung24cf1522014-05-29 12:03:33 -0700253 }
254
Winson Chungd42a6cf2014-06-03 16:24:04 -0700255 /** Requests all task stacks to start their exit-recents animation */
Winson Chung969f5862014-06-16 17:08:24 -0700256 public void startExitToHomeAnimation(ViewAnimation.TaskViewExitContext ctx) {
Winson Chunga91c2932014-11-07 15:02:38 -0800257 // We have to increment/decrement the post animation trigger in case there are no children
258 // to ensure that it runs
259 ctx.postAnimationTrigger.increment();
Winson147ecaf2015-09-16 16:49:55 -0700260 if (mTaskStackView != null) {
261 mTaskStackView.startExitToHomeAnimation(ctx);
Winson Chungd42a6cf2014-06-03 16:24:04 -0700262 }
Winson Chunga91c2932014-11-07 15:02:38 -0800263 ctx.postAnimationTrigger.decrement();
Winson Chungd42a6cf2014-06-03 16:24:04 -0700264
Winson Chung969f5862014-06-16 17:08:24 -0700265 // Notify of the exit animation
Winson412e1802015-10-20 16:57:57 -0700266 EventBus.getDefault().send(new DismissRecentsToHomeAnimationStarted());
Winson Chungd42a6cf2014-06-03 16:24:04 -0700267 }
268
Winson Chungf7bca432014-04-30 17:11:13 -0700269 /** Adds the search bar */
Winson Chungaee097c2015-04-02 18:16:02 -0700270 public void setSearchBar(RecentsAppWidgetHostView searchBar) {
Winson Chungaf3bb692015-06-03 17:31:39 -0700271 // Remove the previous search bar if one exists
272 if (mSearchBar != null && indexOfChild(mSearchBar) > -1) {
273 removeView(mSearchBar);
274 }
275 // Add the new search bar
276 if (searchBar != null) {
277 mSearchBar = searchBar;
278 addView(mSearchBar);
Winson Chungf7bca432014-04-30 17:11:13 -0700279 }
Winson Chungecd9b302014-04-16 17:07:18 -0700280 }
281
Winson Chung772b6b12014-07-03 15:54:02 -0700282 /** Returns whether there is currently a search bar */
Winson Chungaee097c2015-04-02 18:16:02 -0700283 public boolean hasValidSearchBar() {
284 return mSearchBar != null && !mSearchBar.isReinflateRequired();
Winson Chung772b6b12014-07-03 15:54:02 -0700285 }
286
287 /** Sets the visibility of the search bar */
288 public void setSearchBarVisibility(int visibility) {
289 if (mSearchBar != null) {
290 mSearchBar.setVisibility(visibility);
Winson Chung012ef362014-07-31 18:36:25 -0700291 // Always bring the search bar to the top
292 mSearchBar.bringToFront();
Winson Chung772b6b12014-07-03 15:54:02 -0700293 }
294 }
295
Winsonbe7607a2015-10-01 17:24:51 -0700296 @Override
297 protected void onAttachedToWindow() {
298 EventBus.getDefault().register(this, RecentsActivity.EVENT_BUS_PRIORITY + 1);
299 EventBus.getDefault().register(mTouchHandler, RecentsActivity.EVENT_BUS_PRIORITY + 1);
300 super.onAttachedToWindow();
301 }
302
303 @Override
304 protected void onDetachedFromWindow() {
305 super.onDetachedFromWindow();
306 EventBus.getDefault().unregister(this);
307 EventBus.getDefault().unregister(mTouchHandler);
308 }
309
Winson Chungf7bca432014-04-30 17:11:13 -0700310 /**
311 * This is called with the full size of the window since we are handling our own insets.
312 */
Winson Chung303e1ff2014-03-07 15:06:19 -0800313 @Override
314 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Winson53ec42c2015-10-28 15:55:35 -0700315 RecentsConfiguration config = Recents.getConfiguration();
Winson Chung303e1ff2014-03-07 15:06:19 -0800316 int width = MeasureSpec.getSize(widthMeasureSpec);
317 int height = MeasureSpec.getSize(heightMeasureSpec);
Winson Chungbd912972014-03-18 14:36:35 -0700318
Winson Chungf7bca432014-04-30 17:11:13 -0700319 // Get the search bar bounds and measure the search bar layout
Winson Chungaf3bb692015-06-03 17:31:39 -0700320 Rect searchBarSpaceBounds = new Rect();
Winson Chungecd9b302014-04-16 17:07:18 -0700321 if (mSearchBar != null) {
Winson53ec42c2015-10-28 15:55:35 -0700322 config.getSearchBarBounds(new Rect(0, 0, width, height), mSystemInsets.top,
Winson147ecaf2015-09-16 16:49:55 -0700323 searchBarSpaceBounds);
Winson Chungf7bca432014-04-30 17:11:13 -0700324 mSearchBar.measure(
325 MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.width(), MeasureSpec.EXACTLY),
326 MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.height(), MeasureSpec.EXACTLY));
Winson Chungecd9b302014-04-16 17:07:18 -0700327 }
328
Winson Chungf7bca432014-04-30 17:11:13 -0700329 Rect taskStackBounds = new Rect();
Winson53ec42c2015-10-28 15:55:35 -0700330 config.getTaskStackBounds(new Rect(0, 0, width, height), mSystemInsets.top,
Winson35f30502015-09-28 11:24:36 -0700331 mSystemInsets.right, searchBarSpaceBounds, taskStackBounds);
Winson147ecaf2015-09-16 16:49:55 -0700332 if (mTaskStackView != null && mTaskStackView.getVisibility() != GONE) {
Winson88f00ab2015-10-05 17:24:00 -0700333 mTaskStackView.setTaskStackBounds(taskStackBounds, mSystemInsets);
Winson147ecaf2015-09-16 16:49:55 -0700334 mTaskStackView.measure(widthMeasureSpec, heightMeasureSpec);
Winson Chung303e1ff2014-03-07 15:06:19 -0800335 }
336
Winsonbe7607a2015-10-01 17:24:51 -0700337 if (mDragView != null) {
338 mDragView.measure(
339 MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST),
340 MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST));
341 }
342
Winson Chung303e1ff2014-03-07 15:06:19 -0800343 setMeasuredDimension(width, height);
344 }
345
Winson Chungf7bca432014-04-30 17:11:13 -0700346 /**
347 * This is called with the full size of the window since we are handling our own insets.
348 */
Winson Chung303e1ff2014-03-07 15:06:19 -0800349 @Override
350 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
Winson53ec42c2015-10-28 15:55:35 -0700351 RecentsConfiguration config = Recents.getConfiguration();
352
Winson Chungf7bca432014-04-30 17:11:13 -0700353 // Get the search bar bounds so that we lay it out
Winson147ecaf2015-09-16 16:49:55 -0700354 Rect measuredRect = new Rect(0, 0, getMeasuredWidth(), getMeasuredHeight());
355 Rect searchBarSpaceBounds = new Rect();
Winson Chungecd9b302014-04-16 17:07:18 -0700356 if (mSearchBar != null) {
Winson53ec42c2015-10-28 15:55:35 -0700357 config.getSearchBarBounds(measuredRect,
Winson35f30502015-09-28 11:24:36 -0700358 mSystemInsets.top, searchBarSpaceBounds);
Winson Chungdcfa7972014-07-22 12:27:13 -0700359 mSearchBar.layout(searchBarSpaceBounds.left, searchBarSpaceBounds.top,
360 searchBarSpaceBounds.right, searchBarSpaceBounds.bottom);
Winson Chungecd9b302014-04-16 17:07:18 -0700361 }
362
Winson147ecaf2015-09-16 16:49:55 -0700363 if (mTaskStackView != null && mTaskStackView.getVisibility() != GONE) {
364 mTaskStackView.layout(left, top, left + getMeasuredWidth(), top + getMeasuredHeight());
Winson Chung303e1ff2014-03-07 15:06:19 -0800365 }
Winsonbe7607a2015-10-01 17:24:51 -0700366
367 if (mDragView != null) {
368 mDragView.layout(left, top, left + mDragView.getMeasuredWidth(),
369 top + mDragView.getMeasuredHeight());
370 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800371 }
372
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700373 @Override
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700374 public WindowInsets onApplyWindowInsets(WindowInsets insets) {
Winson35f30502015-09-28 11:24:36 -0700375 mSystemInsets.set(insets.getSystemWindowInsets());
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700376 requestLayout();
Winson Chungdcfa7972014-07-22 12:27:13 -0700377 return insets.consumeSystemWindowInsets();
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700378 }
379
Winsonbe7607a2015-10-01 17:24:51 -0700380 @Override
381 public boolean onInterceptTouchEvent(MotionEvent ev) {
382 return mTouchHandler.onInterceptTouchEvent(ev);
383 }
384
385 @Override
386 public boolean onTouchEvent(MotionEvent ev) {
387 return mTouchHandler.onTouchEvent(ev);
388 }
389
390 @Override
391 protected void dispatchDraw(Canvas canvas) {
392 super.dispatchDraw(canvas);
Winson882072b2015-10-12 11:26:33 -0700393 for (int i = mVisibleDockStates.length - 1; i >= 0; i--) {
394 Drawable d = mVisibleDockStates[i].viewState.dockAreaOverlay;
395 if (d.getAlpha() > 0) {
396 d.draw(canvas);
397 }
Winsonbe7607a2015-10-01 17:24:51 -0700398 }
399 }
400
Winson4165d3362015-10-10 14:40:35 -0700401 @Override
402 protected boolean verifyDrawable(Drawable who) {
Winson882072b2015-10-12 11:26:33 -0700403 for (int i = mVisibleDockStates.length - 1; i >= 0; i--) {
404 Drawable d = mVisibleDockStates[i].viewState.dockAreaOverlay;
405 if (d == who) {
406 return true;
407 }
408 }
409 return super.verifyDrawable(who);
Winson4165d3362015-10-10 14:40:35 -0700410 }
411
Winson Chung303e1ff2014-03-07 15:06:19 -0800412 /** Unfilters any filtered stacks */
413 public boolean unfilterFilteredStacks() {
Winson Chungdcfa7972014-07-22 12:27:13 -0700414 if (mStacks != null) {
Winson Chung303e1ff2014-03-07 15:06:19 -0800415 // Check if there are any filtered stacks and unfilter them before we back out of Recents
416 boolean stacksUnfiltered = false;
Winson Chungdcfa7972014-07-22 12:27:13 -0700417 int numStacks = mStacks.size();
418 for (int i = 0; i < numStacks; i++) {
419 TaskStack stack = mStacks.get(i);
Winson Chung303e1ff2014-03-07 15:06:19 -0800420 if (stack.hasFilteredTasks()) {
421 stack.unfilterTasks();
422 stacksUnfiltered = true;
423 }
424 }
425 return stacksUnfiltered;
426 }
427 return false;
428 }
429
Jorim Jaggi900fb482015-06-02 15:07:33 -0700430 public void disableLayersForOneFrame() {
Winson147ecaf2015-09-16 16:49:55 -0700431 if (mTaskStackView != null) {
432 mTaskStackView.disableLayersForOneFrame();
Jorim Jaggi900fb482015-06-02 15:07:33 -0700433 }
434 }
435
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700436 private void postDrawHeaderThumbnailTransitionRunnable(final TaskStackView view,
437 final TaskView clickedView, final int offsetX, final int offsetY,
438 final float stackScroll,
Filip Gruszczynskif48b5852015-10-13 10:28:22 -0700439 final ActivityOptions.OnAnimationStartedListener animStartedListener,
440 final int destinationStack) {
Jorim Jaggi6e18e002015-06-02 17:07:39 -0700441 Runnable r = new Runnable() {
442 @Override
443 public void run() {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700444 overrideDrawHeaderThumbnailTransition(view, clickedView, offsetX, offsetY,
Filip Gruszczynskif48b5852015-10-13 10:28:22 -0700445 stackScroll, animStartedListener, destinationStack);
Jorim Jaggi6e18e002015-06-02 17:07:39 -0700446
Jorim Jaggi6e18e002015-06-02 17:07:39 -0700447 }
448 };
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700449
Jorim Jaggi6e18e002015-06-02 17:07:39 -0700450 mCb.runAfterPause(r);
451 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700452
453 private void overrideDrawHeaderThumbnailTransition(TaskStackView stackView,
454 TaskView clickedTask, int offsetX, int offsetY, float stackScroll,
Filip Gruszczynskif48b5852015-10-13 10:28:22 -0700455 final ActivityOptions.OnAnimationStartedListener animStartedListener,
456 int destinationStack) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700457 List<AppTransitionAnimationSpec> specs = getAppTransitionAnimationSpecs(stackView,
Filip Gruszczynskif48b5852015-10-13 10:28:22 -0700458 clickedTask, offsetX, offsetY, stackScroll, destinationStack);
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700459 if (specs == null) {
460 return;
461 }
462
463 IRemoteCallback.Stub callback = new IRemoteCallback.Stub() {
464 @Override
465 public void sendResult(Bundle data) throws RemoteException {
466 post(new Runnable() {
467 @Override
468 public void run() {
469 if (animStartedListener != null) {
470 animStartedListener.onAnimationStarted();
471 }
472 }
473 });
474 }
475 };
476
477 AppTransitionAnimationSpec[] specsArray =
478 new AppTransitionAnimationSpec[specs.size()];
479 try {
480 WindowManagerGlobal.getWindowManagerService().overridePendingAppTransitionMultiThumb(
481 specs.toArray(specsArray), callback, true /* scaleUp */);
482
483 } catch (RemoteException e) {
484 Log.w(TAG, "Error overriding app transition", e);
485 }
486 }
487
488 private List<AppTransitionAnimationSpec> getAppTransitionAnimationSpecs(TaskStackView stackView,
Filip Gruszczynskif48b5852015-10-13 10:28:22 -0700489 TaskView clickedTask, int offsetX, int offsetY, float stackScroll,
490 int destinationStack) {
491 final int targetStackId = destinationStack != INVALID_STACK_ID ?
492 destinationStack : clickedTask.getTask().key.stackId;
Wale Ogunwale3797c222015-10-27 14:21:58 -0700493 if (targetStackId != FREEFORM_WORKSPACE_STACK_ID
494 && targetStackId != FULLSCREEN_WORKSPACE_STACK_ID) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700495 return null;
496 }
497 // If this is a full screen stack, the transition will be towards the single, full screen
498 // task. We only need the transition spec for this task.
499 List<AppTransitionAnimationSpec> specs = new ArrayList<>();
Wale Ogunwale3797c222015-10-27 14:21:58 -0700500 if (targetStackId == FULLSCREEN_WORKSPACE_STACK_ID) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700501 specs.add(createThumbnailHeaderAnimationSpec(
502 stackView, offsetX, offsetY, stackScroll, clickedTask,
503 clickedTask.getTask().key.id, ADD_HEADER_BITMAP));
504 return specs;
505 }
506 // This is a free form stack or full screen stack, so there will be multiple windows
507 // animating from thumbnails. We need transition animation specs for all of them.
508
509 // We will use top and bottom task views as a base for tasks, that aren't visible on the
510 // screen. This is necessary for cascade recents list, where some of the tasks might be
511 // hidden.
512 List<TaskView> taskViews = stackView.getTaskViews();
513 int childCount = taskViews.size();
514 TaskView topChild = taskViews.get(0);
515 TaskView bottomChild = taskViews.get(childCount - 1);
516 SparseArray<TaskView> taskViewsByTaskId = new SparseArray<>();
517 for (int i = 0; i < childCount; i++) {
518 TaskView taskView = taskViews.get(i);
519 taskViewsByTaskId.put(taskView.getTask().key.id, taskView);
520 }
521
522 TaskStack stack = stackView.getStack();
523 // We go through all tasks now and for each generate transition animation spec. If there is
524 // a view associated with a task, we use that view as a base for the animation. If there
525 // isn't, we use bottom or top view, depending on which one would be closer to the task
526 // view if it existed.
527 ArrayList<Task> tasks = stack.getTasks();
528 boolean passedClickedTask = false;
529 for (int i = 0, n = tasks.size(); i < n; i++) {
530 Task task = tasks.get(i);
531 TaskView taskView = taskViewsByTaskId.get(task.key.id);
532 if (taskView != null) {
533 specs.add(createThumbnailHeaderAnimationSpec(stackView, offsetX, offsetY,
534 stackScroll, taskView, taskView.getTask().key.id, ADD_HEADER_BITMAP));
535 if (taskView == clickedTask) {
536 passedClickedTask = true;
537 }
538 } else {
539 taskView = passedClickedTask ? bottomChild : topChild;
540 specs.add(createThumbnailHeaderAnimationSpec(stackView, offsetX, offsetY,
541 stackScroll, taskView, task.key.id, !ADD_HEADER_BITMAP));
542 }
543 }
544
545 return specs;
546 }
547
548 private AppTransitionAnimationSpec createThumbnailHeaderAnimationSpec(TaskStackView stackView,
549 int offsetX, int offsetY, float stackScroll, TaskView tv, int taskId,
550 boolean addHeaderBitmap) {
551 // Disable any focused state before we draw the header
552 // Upfront the processing of the thumbnail
553 if (tv.isFocusedTask()) {
Winson0d14d4d2015-10-26 17:05:04 -0700554 tv.setFocusedState(false, false /* animated */, false /* requestViewFocus */);
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700555 }
556 TaskViewTransform transform = new TaskViewTransform();
557 transform = stackView.getStackAlgorithm().getStackTransform(tv.mTask, stackScroll,
558 transform, null);
559
560 float scale = tv.getScaleX();
561 int fromHeaderWidth = (int) (tv.mHeaderView.getMeasuredWidth() * scale);
562 int fromHeaderHeight = (int) (tv.mHeaderView.getMeasuredHeight() * scale);
563
564 Bitmap b = null;
565 if (addHeaderBitmap) {
566 b = Bitmap.createBitmap(fromHeaderWidth, fromHeaderHeight,
567 Bitmap.Config.ARGB_8888);
568
569 if (Constants.DebugFlags.App.EnableTransitionThumbnailDebugMode) {
570 b.eraseColor(0xFFff0000);
571 } else {
572 Canvas c = new Canvas(b);
573 c.scale(tv.getScaleX(), tv.getScaleY());
574 tv.mHeaderView.draw(c);
575 c.setBitmap(null);
576
577 }
578 b = b.createAshmemBitmap();
579 }
580
581 int[] pts = new int[2];
582 tv.getLocationOnScreen(pts);
583
584 final int left = pts[0] + offsetX;
585 final int top = pts[1] + offsetY;
Winson3150e572015-10-23 15:07:24 -0700586 final Rect rect = new Rect(left, top, left + (int) transform.rect.width(),
587 top + (int) transform.rect.height());
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700588
589 return new AppTransitionAnimationSpec(taskId, b, rect);
590 }
591
Winson Chung47c4c692014-03-17 10:17:11 -0700592 /**** TaskStackView.TaskStackCallbacks Implementation ****/
Winson Chung303e1ff2014-03-07 15:06:19 -0800593
594 @Override
Winson Chung7aceb9a2014-07-03 13:38:01 -0700595 public void onTaskViewClicked(final TaskStackView stackView, final TaskView tv,
Filip Gruszczynskif48b5852015-10-13 10:28:22 -0700596 final TaskStack stack, final Task task, final boolean lockToTask,
597 final boolean boundsValid, final Rect bounds, int destinationStack) {
Winson Chung47c4c692014-03-17 10:17:11 -0700598 // Notify any callbacks of the launching of a new task
599 if (mCb != null) {
Winson Chung7aceb9a2014-07-03 13:38:01 -0700600 mCb.onTaskViewClicked();
Winson Chung47c4c692014-03-17 10:17:11 -0700601 }
602
Winson Chunge0e45bc2014-06-17 17:56:17 -0700603 // Upfront the processing of the thumbnail
Winson Chungffa2ec62014-07-03 15:54:42 -0700604 TaskViewTransform transform = new TaskViewTransform();
Jorim Jaggicb557032014-09-16 23:09:24 +0200605 View sourceView;
Winson Chunge0e45bc2014-06-17 17:56:17 -0700606 int offsetX = 0;
607 int offsetY = 0;
Winson Chung012ef362014-07-31 18:36:25 -0700608 float stackScroll = stackView.getScroller().getStackScroll();
Winson Chunge0e45bc2014-06-17 17:56:17 -0700609 if (tv == null) {
610 // If there is no actual task view, then use the stack view as the source view
611 // and then offset to the expected transform rect, but bound this to just
612 // outside the display rect (to ensure we don't animate from too far away)
613 sourceView = stackView;
Winson3150e572015-10-23 15:07:24 -0700614 offsetX = (int) transform.rect.left;
Winson35f30502015-09-28 11:24:36 -0700615 offsetY = getMeasuredHeight();
Winson Chunge0e45bc2014-06-17 17:56:17 -0700616 } else {
Jorim Jaggicb557032014-09-16 23:09:24 +0200617 sourceView = tv.mThumbnailView;
Winson Chunge0e45bc2014-06-17 17:56:17 -0700618 }
619
620 // Compute the thumbnail to scale up from
Winsone7f138c2015-10-22 16:15:21 -0700621 final SystemServicesProxy ssp = Recents.getSystemServices();
Winson Chunge0e45bc2014-06-17 17:56:17 -0700622 ActivityOptions opts = null;
Chong Zhang0fa656b2015-08-31 15:17:21 -0700623 ActivityOptions.OnAnimationStartedListener animStartedListener = null;
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200624 if (task.thumbnail != null && task.thumbnail.getWidth() > 0 &&
625 task.thumbnail.getHeight() > 0) {
Winson Chung1f24c7e2014-07-11 17:06:48 -0700626 if (lockToTask) {
627 animStartedListener = new ActivityOptions.OnAnimationStartedListener() {
628 boolean mTriggered = false;
629 @Override
630 public void onAnimationStarted() {
631 if (!mTriggered) {
632 postDelayed(new Runnable() {
633 @Override
634 public void run() {
Winson412e1802015-10-20 16:57:57 -0700635 EventBus.getDefault().send(new ScreenPinningRequestEvent(
636 getContext(), ssp));
Winson Chung1f24c7e2014-07-11 17:06:48 -0700637 }
638 }, 350);
639 mTriggered = true;
640 }
641 }
642 };
643 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700644 postDrawHeaderThumbnailTransitionRunnable(stackView, tv, offsetX, offsetY, stackScroll,
Filip Gruszczynskif48b5852015-10-13 10:28:22 -0700645 animStartedListener, destinationStack);
Winsonec417e42015-09-29 12:42:29 -0700646 opts = ActivityOptions.makeThumbnailAspectScaleUpAnimation(sourceView,
647 Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8).createAshmemBitmap(),
Winson3150e572015-10-23 15:07:24 -0700648 offsetX, offsetY, (int) transform.rect.width(), (int) transform.rect.height(),
Winsonec417e42015-09-29 12:42:29 -0700649 sourceView.getHandler(), animStartedListener);
Chong Zhang0fa656b2015-08-31 15:17:21 -0700650 } else {
651 opts = ActivityOptions.makeBasic();
Winson Chunge0e45bc2014-06-17 17:56:17 -0700652 }
Chong Zhang0fa656b2015-08-31 15:17:21 -0700653 if (boundsValid) {
Winsonb1bbaed2015-09-23 15:45:11 -0700654 opts.setBounds(bounds.isEmpty() ? null : bounds);
Chong Zhang0fa656b2015-08-31 15:17:21 -0700655 }
Winson Chunge0e45bc2014-06-17 17:56:17 -0700656 final ActivityOptions launchOpts = opts;
Chong Zhang0fa656b2015-08-31 15:17:21 -0700657 final boolean screenPinningRequested = (animStartedListener == null) && lockToTask;
Winson Chung303e1ff2014-03-07 15:06:19 -0800658 final Runnable launchRunnable = new Runnable() {
659 @Override
660 public void run() {
Winson Chung4be04452014-03-24 17:22:30 -0700661 if (task.isActive) {
662 // Bring an active task to the foreground
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700663 ssp.moveTaskToFront(task.key.id, launchOpts);
Winson Chung4be04452014-03-24 17:22:30 -0700664 } else {
Winson Chung4e96eb72014-09-17 15:16:09 +0200665 if (ssp.startActivityFromRecents(getContext(), task.key.id,
666 task.activityLabel, launchOpts)) {
Chong Zhang0fa656b2015-08-31 15:17:21 -0700667 if (screenPinningRequested) {
Winson412e1802015-10-20 16:57:57 -0700668 EventBus.getDefault().send(new ScreenPinningRequestEvent(
669 getContext(), ssp));
Winson Chung4be04452014-03-24 17:22:30 -0700670 }
Winson Chung4e96eb72014-09-17 15:16:09 +0200671 } else {
672 // Dismiss the task and return the user to home if we fail to
673 // launch the task
Winson0d14d4d2015-10-26 17:05:04 -0700674 EventBus.getDefault().send(new DismissTaskViewEvent(task, tv));
Winson Chung4e96eb72014-09-17 15:16:09 +0200675 if (mCb != null) {
676 mCb.onTaskLaunchFailed();
677 }
Winson Chung5c9f4b92015-06-25 16:16:46 -0700678
679 // Keep track of failed launches
680 MetricsLogger.count(getContext(), "overview_task_launch_failed", 1);
Winson Chung4be04452014-03-24 17:22:30 -0700681 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800682 }
683 }
684 };
685
Winson Chung5c9f4b92015-06-25 16:16:46 -0700686 // Keep track of the index of the task launch
687 int taskIndexFromFront = 0;
688 int taskIndex = stack.indexOfTask(task);
689 if (taskIndex > -1) {
690 taskIndexFromFront = stack.getTaskCount() - taskIndex - 1;
691 }
692 MetricsLogger.histogram(getContext(), "overview_task_launch_index", taskIndexFromFront);
693
Winson Chung303e1ff2014-03-07 15:06:19 -0800694 // Launch the app right away if there is no task view, otherwise, animate the icon out first
Winson Chung814086d2014-05-07 15:01:14 -0700695 if (tv == null) {
Winson Chunga91c2932014-11-07 15:02:38 -0800696 launchRunnable.run();
Winson Chung303e1ff2014-03-07 15:06:19 -0800697 } else {
Winson Chunge1e20e12015-06-02 14:11:49 -0700698 if (task.group != null && !task.group.isFrontMostTask(task)) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700699 // For affiliated tasks that are behind other tasks, we must animate the front cards
700 // out of view before starting the task transition
Winson Chungebfc6982014-08-26 12:25:34 -0700701 stackView.startLaunchTaskAnimation(tv, launchRunnable, lockToTask);
Winson Chunga4ccb862014-08-22 15:26:27 -0700702 } else {
703 // Otherwise, we can start the task transition immediately
Winson Chungebfc6982014-08-26 12:25:34 -0700704 stackView.startLaunchTaskAnimation(tv, null, lockToTask);
Winson Chunga91c2932014-11-07 15:02:38 -0800705 launchRunnable.run();
Winson Chunga4ccb862014-08-22 15:26:27 -0700706 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800707 }
708 }
Winson Chung9f9679d2014-04-11 16:49:09 -0700709
710 @Override
Winson Chung6ac8bd62015-01-07 16:38:35 -0800711 public void onAllTaskViewsDismissed(ArrayList<Task> removedTasks) {
Winson2536c7e2015-10-01 15:49:31 -0700712 /* TODO: Not currently enabled
Winson Chung6ac8bd62015-01-07 16:38:35 -0800713 if (removedTasks != null) {
714 int taskCount = removedTasks.size();
715 for (int i = 0; i < taskCount; i++) {
716 onTaskViewDismissed(removedTasks.get(i));
717 }
718 }
Winson2536c7e2015-10-01 15:49:31 -0700719 */
Winson Chung6ac8bd62015-01-07 16:38:35 -0800720
Winson Chung7aceb9a2014-07-03 13:38:01 -0700721 mCb.onAllTaskViewsDismissed();
Winson Chung5c9f4b92015-06-25 16:16:46 -0700722
723 // Keep track of all-deletions
724 MetricsLogger.count(getContext(), "overview_task_all_dismissed", 1);
Winson Chungd7b2cb12014-06-26 15:08:50 -0700725 }
726
727 @Override
Winson Chung8e548f72014-06-24 14:40:53 -0700728 public void onTaskStackFilterTriggered() {
729 // Hide the search bar
730 if (mSearchBar != null) {
Winson35f30502015-09-28 11:24:36 -0700731 int filterDuration = getResources().getInteger(
732 R.integer.recents_filter_animate_current_views_duration);
Winson Chung8e548f72014-06-24 14:40:53 -0700733 mSearchBar.animate()
734 .alpha(0f)
735 .setStartDelay(0)
Winson35f30502015-09-28 11:24:36 -0700736 .setInterpolator(mFastOutSlowInInterpolator)
737 .setDuration(filterDuration)
Winson Chung8e548f72014-06-24 14:40:53 -0700738 .withLayer()
739 .start();
740 }
741 }
742
743 @Override
744 public void onTaskStackUnfilterTriggered() {
745 // Show the search bar
746 if (mSearchBar != null) {
Winson35f30502015-09-28 11:24:36 -0700747 int filterDuration = getResources().getInteger(
748 R.integer.recents_filter_animate_new_views_duration);
Winson Chung8e548f72014-06-24 14:40:53 -0700749 mSearchBar.animate()
750 .alpha(1f)
751 .setStartDelay(0)
Winson35f30502015-09-28 11:24:36 -0700752 .setInterpolator(mFastOutSlowInInterpolator)
753 .setDuration(filterDuration)
Winson Chung8e548f72014-06-24 14:40:53 -0700754 .withLayer()
755 .start();
756 }
757 }
Winsonbe7607a2015-10-01 17:24:51 -0700758
759 /**** EventBus Events ****/
760
761 public final void onBusEvent(DragStartEvent event) {
762 // Add the drag view
763 mDragView = event.dragView;
764 addView(mDragView);
Winson4165d3362015-10-10 14:40:35 -0700765
Winson882072b2015-10-12 11:26:33 -0700766 updateVisibleDockRegions(mTouchHandler.getDockStatesForCurrentOrientation(),
767 TaskStack.DockState.NONE.viewState.dockAreaAlpha);
Winsonbe7607a2015-10-01 17:24:51 -0700768 }
769
770 public final void onBusEvent(DragDockStateChangedEvent event) {
Winson882072b2015-10-12 11:26:33 -0700771 if (event.dockState == TaskStack.DockState.NONE) {
772 updateVisibleDockRegions(mTouchHandler.getDockStatesForCurrentOrientation(),
773 TaskStack.DockState.NONE.viewState.dockAreaAlpha);
774 } else {
775 updateVisibleDockRegions(new TaskStack.DockState[] {event.dockState}, -1);
776 }
Winsonbe7607a2015-10-01 17:24:51 -0700777 }
778
779 public final void onBusEvent(final DragEndEvent event) {
780 event.postAnimationTrigger.increment();
781 event.postAnimationTrigger.addLastDecrementRunnable(new Runnable() {
782 @Override
783 public void run() {
784 // Remove the drag view
785 removeView(mDragView);
786 mDragView = null;
Winson882072b2015-10-12 11:26:33 -0700787 updateVisibleDockRegions(null, -1);
Winsonbe7607a2015-10-01 17:24:51 -0700788
789 // Dock the new task if we are hovering over a valid dock state
Winson4165d3362015-10-10 14:40:35 -0700790 if (event.dockState != TaskStack.DockState.NONE) {
Winsone7f138c2015-10-22 16:15:21 -0700791 SystemServicesProxy ssp = Recents.getSystemServices();
Jorim Jaggi75b25972015-10-21 14:51:10 +0200792 ssp.startTaskInDockedMode(event.task.key.id, event.dockState.createMode);
Filip Gruszczynskif48b5852015-10-13 10:28:22 -0700793 launchTask(event.task, null, INVALID_STACK_ID);
Winsonbe7607a2015-10-01 17:24:51 -0700794 }
795 }
796 });
Winson4165d3362015-10-10 14:40:35 -0700797 if (event.dockState == TaskStack.DockState.NONE) {
Winsonbe7607a2015-10-01 17:24:51 -0700798 // Animate the alpha back to what it was before
799 Rect taskBounds = mTaskStackView.getStackAlgorithm().getUntransformedTaskViewBounds();
800 int left = taskBounds.left + (int) ((1f - event.taskView.getScaleX()) * taskBounds.width()) / 2;
801 int top = taskBounds.top + (int) ((1f - event.taskView.getScaleY()) * taskBounds.height()) / 2;
802 event.dragView.animate()
Winson4165d3362015-10-10 14:40:35 -0700803 .scaleX(1f)
804 .scaleY(1f)
Winsonbe7607a2015-10-01 17:24:51 -0700805 .translationX(left + event.taskView.getTranslationX())
806 .translationY(top + event.taskView.getTranslationY())
807 .setDuration(175)
Winson4165d3362015-10-10 14:40:35 -0700808 .setInterpolator(mFastOutSlowInInterpolator)
Winsonbe7607a2015-10-01 17:24:51 -0700809 .withEndAction(event.postAnimationTrigger.decrementAsRunnable())
Winsonbe7607a2015-10-01 17:24:51 -0700810 .start();
Winson4165d3362015-10-10 14:40:35 -0700811
812 // Animate the overlay alpha back to 0
Winson882072b2015-10-12 11:26:33 -0700813 updateVisibleDockRegions(null, -1);
Winsonbe7607a2015-10-01 17:24:51 -0700814 } else {
815 event.postAnimationTrigger.decrement();
816 }
817 }
Winson4165d3362015-10-10 14:40:35 -0700818
819 /**
820 * Updates the dock region to match the specified dock state.
821 */
Winson882072b2015-10-12 11:26:33 -0700822 private void updateVisibleDockRegions(TaskStack.DockState[] newDockStates, int overrideAlpha) {
823 ArraySet<TaskStack.DockState> newDockStatesSet = new ArraySet<>();
824 if (newDockStates != null) {
825 for (TaskStack.DockState dockState : newDockStates) {
826 newDockStatesSet.add(dockState);
827 }
Winson4165d3362015-10-10 14:40:35 -0700828 }
Winson882072b2015-10-12 11:26:33 -0700829 for (TaskStack.DockState dockState : mVisibleDockStates) {
830 TaskStack.DockState.ViewState viewState = dockState.viewState;
831 if (newDockStates == null || !newDockStatesSet.contains(dockState)) {
832 // This is no longer visible, so hide it
833 viewState.startAlphaAnimation(0, 150);
834 } else {
835 // This state is now visible, update the bounds and show it
836 int alpha = (overrideAlpha != -1 ? overrideAlpha : viewState.dockAreaAlpha);
837 viewState.dockAreaOverlay.setBounds(
838 dockState.getDockedBounds(getMeasuredWidth(), getMeasuredHeight()));
839 viewState.dockAreaOverlay.setCallback(this);
840 viewState.startAlphaAnimation(alpha, 150);
841 }
Winson4165d3362015-10-10 14:40:35 -0700842 }
Winson4165d3362015-10-10 14:40:35 -0700843 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800844}