blob: 126612074a1be40870ca1a8d99ea38bd656bb0c1 [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;
Winsonbe7607a2015-10-01 17:24:51 -070045import com.android.systemui.recents.RecentsActivity;
Winson Chungaee097c2015-04-02 18:16:02 -070046import com.android.systemui.recents.RecentsAppWidgetHostView;
Winson Chung303e1ff2014-03-07 15:06:19 -080047import com.android.systemui.recents.RecentsConfiguration;
Winson2536c7e2015-10-01 15:49:31 -070048import com.android.systemui.recents.events.EventBus;
49import com.android.systemui.recents.events.ui.DismissTaskEvent;
Winsonbe7607a2015-10-01 17:24:51 -070050import com.android.systemui.recents.events.ui.dragndrop.DragDockStateChangedEvent;
51import com.android.systemui.recents.events.ui.dragndrop.DragEndEvent;
52import com.android.systemui.recents.events.ui.dragndrop.DragStartEvent;
Winson Chung1f24c7e2014-07-11 17:06:48 -070053import com.android.systemui.recents.misc.SystemServicesProxy;
Winson Chungf1fbd772014-06-24 18:06:58 -070054import com.android.systemui.recents.model.RecentsTaskLoader;
Winson Chung303e1ff2014-03-07 15:06:19 -080055import com.android.systemui.recents.model.Task;
56import com.android.systemui.recents.model.TaskStack;
57
58import java.util.ArrayList;
Winson Chung6ac8bd62015-01-07 16:38:35 -080059import java.util.List;
Winson Chung303e1ff2014-03-07 15:06:19 -080060
Winson Chung303e1ff2014-03-07 15:06:19 -080061/**
62 * This view is the the top level layout that contains TaskStacks (which are laid out according
63 * to their SpaceNode bounds.
64 */
Winsone6c90732015-09-24 16:06:29 -070065public class RecentsView extends FrameLayout implements TaskStackView.TaskStackViewCallbacks {
Winson Chung47c4c692014-03-17 10:17:11 -070066
Jorim Jaggi6e18e002015-06-02 17:07:39 -070067 private static final String TAG = "RecentsView";
68
Filip Gruszczynski170192a2015-08-16 17:46:34 -070069 private static final boolean ADD_HEADER_BITMAP = true;
70
Winson Chung47c4c692014-03-17 10:17:11 -070071 /** The RecentsView callbacks */
72 public interface RecentsViewCallbacks {
Winson Chung7aceb9a2014-07-03 13:38:01 -070073 public void onTaskViewClicked();
Winson Chung4e96eb72014-09-17 15:16:09 +020074 public void onTaskLaunchFailed();
Winson Chung7aceb9a2014-07-03 13:38:01 -070075 public void onAllTaskViewsDismissed();
Winson Chungcdbbb7e2014-06-24 12:11:49 -070076 public void onExitToHomeAnimationTriggered();
Jason Monk18f99d92014-09-11 13:36:42 -040077 public void onScreenPinningRequest();
Jorim Jaggi6e18e002015-06-02 17:07:39 -070078 public void runAfterPause(Runnable r);
Winson Chung47c4c692014-03-17 10:17:11 -070079 }
80
Winson Chungd42a6cf2014-06-03 16:24:04 -070081 RecentsConfiguration mConfig;
82 LayoutInflater mInflater;
83
Winson Chungdcfa7972014-07-22 12:27:13 -070084 ArrayList<TaskStack> mStacks;
Winson147ecaf2015-09-16 16:49:55 -070085 TaskStackView mTaskStackView;
Winson Chungaee097c2015-04-02 18:16:02 -070086 RecentsAppWidgetHostView mSearchBar;
Winson Chung47c4c692014-03-17 10:17:11 -070087 RecentsViewCallbacks mCb;
Winsonbe7607a2015-10-01 17:24:51 -070088
89 RecentsViewTouchHandler mTouchHandler;
90 DragView mDragView;
Winson882072b2015-10-12 11:26:33 -070091 TaskStack.DockState[] mVisibleDockStates = {
92 TaskStack.DockState.LEFT,
93 TaskStack.DockState.TOP,
94 TaskStack.DockState.RIGHT,
95 TaskStack.DockState.BOTTOM,
96 };
Winsonbe7607a2015-10-01 17:24:51 -070097
Winson35f30502015-09-28 11:24:36 -070098 Interpolator mFastOutSlowInInterpolator;
99
100 Rect mSystemInsets = new Rect();
Winson Chung303e1ff2014-03-07 15:06:19 -0800101
102 public RecentsView(Context context) {
103 super(context);
Winson Chung8e548f72014-06-24 14:40:53 -0700104 }
105
106 public RecentsView(Context context, AttributeSet attrs) {
107 this(context, attrs, 0);
108 }
109
110 public RecentsView(Context context, AttributeSet attrs, int defStyleAttr) {
111 this(context, attrs, defStyleAttr, 0);
112 }
113
114 public RecentsView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
115 super(context, attrs, defStyleAttr, defStyleRes);
Winsonbe7607a2015-10-01 17:24:51 -0700116 setWillNotDraw(false);
Winson Chungd42a6cf2014-06-03 16:24:04 -0700117 mConfig = RecentsConfiguration.getInstance();
Winson Chungecd9b302014-04-16 17:07:18 -0700118 mInflater = LayoutInflater.from(context);
Winson35f30502015-09-28 11:24:36 -0700119 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
120 com.android.internal.R.interpolator.fast_out_slow_in);
Winsonbe7607a2015-10-01 17:24:51 -0700121 mTouchHandler = new RecentsViewTouchHandler(this);
Winson Chungd16c5652015-01-26 16:11:07 -0800122 }
123
Winson Chung47c4c692014-03-17 10:17:11 -0700124 /** Sets the callbacks */
125 public void setCallbacks(RecentsViewCallbacks cb) {
126 mCb = cb;
127 }
128
Winson Chungdcfa7972014-07-22 12:27:13 -0700129 /** Set/get the bsp root node */
Winson147ecaf2015-09-16 16:49:55 -0700130 public void setTaskStack(TaskStack stack) {
Winson35f30502015-09-28 11:24:36 -0700131 if (mConfig.getLaunchState().launchedReuseTaskStackViews) {
Winson147ecaf2015-09-16 16:49:55 -0700132 if (mTaskStackView != null) {
133 // If onRecentsHidden is not triggered, we need to the stack view again here
134 mTaskStackView.reset();
135 mTaskStackView.setStack(stack);
136 } else {
137 mTaskStackView = new TaskStackView(getContext(), stack);
138 mTaskStackView.setCallbacks(this);
139 addView(mTaskStackView);
140 }
141 } else {
142 if (mTaskStackView != null) {
143 removeView(mTaskStackView);
144 }
145 mTaskStackView = new TaskStackView(getContext(), stack);
146 mTaskStackView.setCallbacks(this);
147 addView(mTaskStackView);
Winson Chung303e1ff2014-03-07 15:06:19 -0800148 }
Winson Chung02d49272014-08-29 13:57:29 -0700149
Winson Chungb0a28ea2014-10-28 15:21:35 -0700150 // Trigger a new layout
151 requestLayout();
Winson Chung19fc1172014-07-31 18:40:03 -0700152 }
153
Skuhne8aa7d162015-03-20 13:40:53 -0700154 /** Gets the next task in the stack - or if the last - the top task */
155 public Task getNextTaskOrTopTask(Task taskToSearch) {
Chong Zhang0fa656b2015-08-31 15:17:21 -0700156 Task returnTask = null;
Skuhne8aa7d162015-03-20 13:40:53 -0700157 boolean found = false;
Winson147ecaf2015-09-16 16:49:55 -0700158 if (mTaskStackView != null) {
159 TaskStack stack = mTaskStackView.getStack();
Skuhne8aa7d162015-03-20 13:40:53 -0700160 ArrayList<Task> taskList = stack.getTasks();
161 // Iterate the stack views and try and find the focused task
162 for (int j = taskList.size() - 1; j >= 0; --j) {
163 Task task = taskList.get(j);
164 // Return the next task in the line.
165 if (found)
166 return task;
167 // Remember the first possible task as the top task.
168 if (returnTask == null)
169 returnTask = task;
170 if (task == taskToSearch)
171 found = true;
172 }
173 }
174 return returnTask;
175 }
176
Winson Chung1e8d71b2014-05-16 17:05:22 -0700177 /** Launches the focused task from the first stack if possible */
178 public boolean launchFocusedTask() {
Winson147ecaf2015-09-16 16:49:55 -0700179 if (mTaskStackView != null) {
180 TaskStack stack = mTaskStackView.getStack();
Winson Chungd16c5652015-01-26 16:11:07 -0800181 // Iterate the stack views and try and find the focused task
Winson147ecaf2015-09-16 16:49:55 -0700182 List<TaskView> taskViews = mTaskStackView.getTaskViews();
Winson Chungd16c5652015-01-26 16:11:07 -0800183 int taskViewCount = taskViews.size();
184 for (int j = 0; j < taskViewCount; j++) {
185 TaskView tv = taskViews.get(j);
186 Task task = tv.getTask();
187 if (tv.isFocusedTask()) {
Winson147ecaf2015-09-16 16:49:55 -0700188 onTaskViewClicked(mTaskStackView, tv, stack, task, false, false, null);
Winson Chungd16c5652015-01-26 16:11:07 -0800189 return true;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700190 }
191 }
192 }
Winson Chung1e8d71b2014-05-16 17:05:22 -0700193 return false;
194 }
195
Skuhne8aa7d162015-03-20 13:40:53 -0700196 /** Launches a given task. */
Chong Zhang0fa656b2015-08-31 15:17:21 -0700197 public boolean launchTask(Task task, Rect taskBounds) {
Winson147ecaf2015-09-16 16:49:55 -0700198 if (mTaskStackView != null) {
199 TaskStack stack = mTaskStackView.getStack();
Skuhne8aa7d162015-03-20 13:40:53 -0700200 // Iterate the stack views and try and find the given task.
Winson147ecaf2015-09-16 16:49:55 -0700201 List<TaskView> taskViews = mTaskStackView.getTaskViews();
Skuhne8aa7d162015-03-20 13:40:53 -0700202 int taskViewCount = taskViews.size();
203 for (int j = 0; j < taskViewCount; j++) {
204 TaskView tv = taskViews.get(j);
205 if (tv.getTask() == task) {
Winsonb1bbaed2015-09-23 15:45:11 -0700206 onTaskViewClicked(mTaskStackView, tv, stack, task, false, taskBounds != null,
207 taskBounds);
Skuhne8aa7d162015-03-20 13:40:53 -0700208 return true;
209 }
210 }
211 }
212 return false;
213 }
214
Winson Chungdcfa7972014-07-22 12:27:13 -0700215 /** Launches the task that Recents was launched from, if possible */
216 public boolean launchPreviousTask() {
Winson147ecaf2015-09-16 16:49:55 -0700217 if (mTaskStackView != null) {
218 TaskStack stack = mTaskStackView.getStack();
Winson Chungd16c5652015-01-26 16:11:07 -0800219 ArrayList<Task> tasks = stack.getTasks();
Winson Chung47c4c692014-03-17 10:17:11 -0700220
Winson Chungd16c5652015-01-26 16:11:07 -0800221 // Find the launch task in the stack
Winsonbe7607a2015-10-01 17:24:51 -0700222 // TODO: replace this with an event from RecentsActivity
Winson Chungd16c5652015-01-26 16:11:07 -0800223 if (!tasks.isEmpty()) {
224 int taskCount = tasks.size();
225 for (int j = 0; j < taskCount; j++) {
226 if (tasks.get(j).isLaunchTarget) {
227 Task task = tasks.get(j);
Winson147ecaf2015-09-16 16:49:55 -0700228 TaskView tv = mTaskStackView.getChildViewForTask(task);
229 onTaskViewClicked(mTaskStackView, tv, stack, task, false, false, null);
Winson Chungd16c5652015-01-26 16:11:07 -0800230 return true;
Winson Chung303e1ff2014-03-07 15:06:19 -0800231 }
232 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800233 }
234 }
235 return false;
236 }
237
Winson Chung24cf1522014-05-29 12:03:33 -0700238 /** Requests all task stacks to start their enter-recents animation */
Winson Chung969f5862014-06-16 17:08:24 -0700239 public void startEnterRecentsAnimation(ViewAnimation.TaskViewEnterContext ctx) {
Winson Chung740c3ac2014-11-12 16:14:38 -0800240 // We have to increment/decrement the post animation trigger in case there are no children
241 // to ensure that it runs
242 ctx.postAnimationTrigger.increment();
Winson147ecaf2015-09-16 16:49:55 -0700243 if (mTaskStackView != null) {
244 mTaskStackView.startEnterRecentsAnimation(ctx);
Winson Chung24cf1522014-05-29 12:03:33 -0700245 }
Winson Chung740c3ac2014-11-12 16:14:38 -0800246 ctx.postAnimationTrigger.decrement();
Winson Chung24cf1522014-05-29 12:03:33 -0700247 }
248
Winson Chungd42a6cf2014-06-03 16:24:04 -0700249 /** Requests all task stacks to start their exit-recents animation */
Winson Chung969f5862014-06-16 17:08:24 -0700250 public void startExitToHomeAnimation(ViewAnimation.TaskViewExitContext ctx) {
Winson Chunga91c2932014-11-07 15:02:38 -0800251 // We have to increment/decrement the post animation trigger in case there are no children
252 // to ensure that it runs
253 ctx.postAnimationTrigger.increment();
Winson147ecaf2015-09-16 16:49:55 -0700254 if (mTaskStackView != null) {
255 mTaskStackView.startExitToHomeAnimation(ctx);
Winson Chungd42a6cf2014-06-03 16:24:04 -0700256 }
Winson Chunga91c2932014-11-07 15:02:38 -0800257 ctx.postAnimationTrigger.decrement();
Winson Chungd42a6cf2014-06-03 16:24:04 -0700258
Winson Chung969f5862014-06-16 17:08:24 -0700259 // Notify of the exit animation
Winson Chungcdbbb7e2014-06-24 12:11:49 -0700260 mCb.onExitToHomeAnimationTriggered();
Winson Chungd42a6cf2014-06-03 16:24:04 -0700261 }
262
Winson Chungf7bca432014-04-30 17:11:13 -0700263 /** Adds the search bar */
Winson Chungaee097c2015-04-02 18:16:02 -0700264 public void setSearchBar(RecentsAppWidgetHostView searchBar) {
Winson Chungaf3bb692015-06-03 17:31:39 -0700265 // Remove the previous search bar if one exists
266 if (mSearchBar != null && indexOfChild(mSearchBar) > -1) {
267 removeView(mSearchBar);
268 }
269 // Add the new search bar
270 if (searchBar != null) {
271 mSearchBar = searchBar;
272 addView(mSearchBar);
Winson Chungf7bca432014-04-30 17:11:13 -0700273 }
Winson Chungecd9b302014-04-16 17:07:18 -0700274 }
275
Winson Chung772b6b12014-07-03 15:54:02 -0700276 /** Returns whether there is currently a search bar */
Winson Chungaee097c2015-04-02 18:16:02 -0700277 public boolean hasValidSearchBar() {
278 return mSearchBar != null && !mSearchBar.isReinflateRequired();
Winson Chung772b6b12014-07-03 15:54:02 -0700279 }
280
281 /** Sets the visibility of the search bar */
282 public void setSearchBarVisibility(int visibility) {
283 if (mSearchBar != null) {
284 mSearchBar.setVisibility(visibility);
Winson Chung012ef362014-07-31 18:36:25 -0700285 // Always bring the search bar to the top
286 mSearchBar.bringToFront();
Winson Chung772b6b12014-07-03 15:54:02 -0700287 }
288 }
289
Winsonbe7607a2015-10-01 17:24:51 -0700290 @Override
291 protected void onAttachedToWindow() {
292 EventBus.getDefault().register(this, RecentsActivity.EVENT_BUS_PRIORITY + 1);
293 EventBus.getDefault().register(mTouchHandler, RecentsActivity.EVENT_BUS_PRIORITY + 1);
294 super.onAttachedToWindow();
295 }
296
297 @Override
298 protected void onDetachedFromWindow() {
299 super.onDetachedFromWindow();
300 EventBus.getDefault().unregister(this);
301 EventBus.getDefault().unregister(mTouchHandler);
302 }
303
Winson Chungf7bca432014-04-30 17:11:13 -0700304 /**
305 * This is called with the full size of the window since we are handling our own insets.
306 */
Winson Chung303e1ff2014-03-07 15:06:19 -0800307 @Override
308 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
309 int width = MeasureSpec.getSize(widthMeasureSpec);
310 int height = MeasureSpec.getSize(heightMeasureSpec);
Winson Chungbd912972014-03-18 14:36:35 -0700311
Winson Chungf7bca432014-04-30 17:11:13 -0700312 // Get the search bar bounds and measure the search bar layout
Winson Chungaf3bb692015-06-03 17:31:39 -0700313 Rect searchBarSpaceBounds = new Rect();
Winson Chungecd9b302014-04-16 17:07:18 -0700314 if (mSearchBar != null) {
Winson35f30502015-09-28 11:24:36 -0700315 mConfig.getSearchBarBounds(new Rect(0, 0, width, height), mSystemInsets.top,
Winson147ecaf2015-09-16 16:49:55 -0700316 searchBarSpaceBounds);
Winson Chungf7bca432014-04-30 17:11:13 -0700317 mSearchBar.measure(
318 MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.width(), MeasureSpec.EXACTLY),
319 MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.height(), MeasureSpec.EXACTLY));
Winson Chungecd9b302014-04-16 17:07:18 -0700320 }
321
Winson Chungf7bca432014-04-30 17:11:13 -0700322 Rect taskStackBounds = new Rect();
Winson88f00ab2015-10-05 17:24:00 -0700323 mConfig.getTaskStackBounds(new Rect(0, 0, width, height), mSystemInsets.top,
Winson35f30502015-09-28 11:24:36 -0700324 mSystemInsets.right, searchBarSpaceBounds, taskStackBounds);
Winson147ecaf2015-09-16 16:49:55 -0700325 if (mTaskStackView != null && mTaskStackView.getVisibility() != GONE) {
Winson88f00ab2015-10-05 17:24:00 -0700326 mTaskStackView.setTaskStackBounds(taskStackBounds, mSystemInsets);
Winson147ecaf2015-09-16 16:49:55 -0700327 mTaskStackView.measure(widthMeasureSpec, heightMeasureSpec);
Winson Chung303e1ff2014-03-07 15:06:19 -0800328 }
329
Winsonbe7607a2015-10-01 17:24:51 -0700330 if (mDragView != null) {
331 mDragView.measure(
332 MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST),
333 MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST));
334 }
335
Winson Chung303e1ff2014-03-07 15:06:19 -0800336 setMeasuredDimension(width, height);
337 }
338
Winson Chungf7bca432014-04-30 17:11:13 -0700339 /**
340 * This is called with the full size of the window since we are handling our own insets.
341 */
Winson Chung303e1ff2014-03-07 15:06:19 -0800342 @Override
343 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
Winson Chungf7bca432014-04-30 17:11:13 -0700344 // Get the search bar bounds so that we lay it out
Winson147ecaf2015-09-16 16:49:55 -0700345 Rect measuredRect = new Rect(0, 0, getMeasuredWidth(), getMeasuredHeight());
346 Rect searchBarSpaceBounds = new Rect();
Winson Chungecd9b302014-04-16 17:07:18 -0700347 if (mSearchBar != null) {
Winson147ecaf2015-09-16 16:49:55 -0700348 mConfig.getSearchBarBounds(measuredRect,
Winson35f30502015-09-28 11:24:36 -0700349 mSystemInsets.top, searchBarSpaceBounds);
Winson Chungdcfa7972014-07-22 12:27:13 -0700350 mSearchBar.layout(searchBarSpaceBounds.left, searchBarSpaceBounds.top,
351 searchBarSpaceBounds.right, searchBarSpaceBounds.bottom);
Winson Chungecd9b302014-04-16 17:07:18 -0700352 }
353
Winson147ecaf2015-09-16 16:49:55 -0700354 if (mTaskStackView != null && mTaskStackView.getVisibility() != GONE) {
355 mTaskStackView.layout(left, top, left + getMeasuredWidth(), top + getMeasuredHeight());
Winson Chung303e1ff2014-03-07 15:06:19 -0800356 }
Winsonbe7607a2015-10-01 17:24:51 -0700357
358 if (mDragView != null) {
359 mDragView.layout(left, top, left + mDragView.getMeasuredWidth(),
360 top + mDragView.getMeasuredHeight());
361 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800362 }
363
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700364 @Override
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700365 public WindowInsets onApplyWindowInsets(WindowInsets insets) {
Winson35f30502015-09-28 11:24:36 -0700366 mSystemInsets.set(insets.getSystemWindowInsets());
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700367 requestLayout();
Winson Chungdcfa7972014-07-22 12:27:13 -0700368 return insets.consumeSystemWindowInsets();
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700369 }
370
Winsonbe7607a2015-10-01 17:24:51 -0700371 @Override
372 public boolean onInterceptTouchEvent(MotionEvent ev) {
373 return mTouchHandler.onInterceptTouchEvent(ev);
374 }
375
376 @Override
377 public boolean onTouchEvent(MotionEvent ev) {
378 return mTouchHandler.onTouchEvent(ev);
379 }
380
381 @Override
382 protected void dispatchDraw(Canvas canvas) {
383 super.dispatchDraw(canvas);
Winson882072b2015-10-12 11:26:33 -0700384 for (int i = mVisibleDockStates.length - 1; i >= 0; i--) {
385 Drawable d = mVisibleDockStates[i].viewState.dockAreaOverlay;
386 if (d.getAlpha() > 0) {
387 d.draw(canvas);
388 }
Winsonbe7607a2015-10-01 17:24:51 -0700389 }
390 }
391
Winson4165d3362015-10-10 14:40:35 -0700392 @Override
393 protected boolean verifyDrawable(Drawable who) {
Winson882072b2015-10-12 11:26:33 -0700394 for (int i = mVisibleDockStates.length - 1; i >= 0; i--) {
395 Drawable d = mVisibleDockStates[i].viewState.dockAreaOverlay;
396 if (d == who) {
397 return true;
398 }
399 }
400 return super.verifyDrawable(who);
Winson4165d3362015-10-10 14:40:35 -0700401 }
402
Winson Chunga26fb782014-06-12 17:52:39 -0700403 /** Notifies each task view of the user interaction. */
404 public void onUserInteraction() {
405 // Get the first stack view
Winson147ecaf2015-09-16 16:49:55 -0700406 if (mTaskStackView != null) {
407 mTaskStackView.onUserInteraction();
Winson Chunga26fb782014-06-12 17:52:39 -0700408 }
409 }
410
Winson Chung1e8d71b2014-05-16 17:05:22 -0700411 /** Focuses the next task in the first stack view */
412 public void focusNextTask(boolean forward) {
413 // Get the first stack view
Winson147ecaf2015-09-16 16:49:55 -0700414 if (mTaskStackView != null) {
415 mTaskStackView.focusNextTask(forward, true);
Winson Chung1e8d71b2014-05-16 17:05:22 -0700416 }
Winson Chunga0e88b52014-08-11 19:25:42 -0700417 }
Winson Chung1e8d71b2014-05-16 17:05:22 -0700418
Winson Chunga0e88b52014-08-11 19:25:42 -0700419 /** Dismisses the focused task. */
420 public void dismissFocusedTask() {
421 // Get the first stack view
Winson147ecaf2015-09-16 16:49:55 -0700422 if (mTaskStackView != null) {
423 mTaskStackView.dismissFocusedTask();
Winson Chung1e8d71b2014-05-16 17:05:22 -0700424 }
425 }
426
Winson Chung303e1ff2014-03-07 15:06:19 -0800427 /** Unfilters any filtered stacks */
428 public boolean unfilterFilteredStacks() {
Winson Chungdcfa7972014-07-22 12:27:13 -0700429 if (mStacks != null) {
Winson Chung303e1ff2014-03-07 15:06:19 -0800430 // Check if there are any filtered stacks and unfilter them before we back out of Recents
431 boolean stacksUnfiltered = false;
Winson Chungdcfa7972014-07-22 12:27:13 -0700432 int numStacks = mStacks.size();
433 for (int i = 0; i < numStacks; i++) {
434 TaskStack stack = mStacks.get(i);
Winson Chung303e1ff2014-03-07 15:06:19 -0800435 if (stack.hasFilteredTasks()) {
436 stack.unfilterTasks();
437 stacksUnfiltered = true;
438 }
439 }
440 return stacksUnfiltered;
441 }
442 return false;
443 }
444
Jorim Jaggi900fb482015-06-02 15:07:33 -0700445 public void disableLayersForOneFrame() {
Winson147ecaf2015-09-16 16:49:55 -0700446 if (mTaskStackView != null) {
447 mTaskStackView.disableLayersForOneFrame();
Jorim Jaggi900fb482015-06-02 15:07:33 -0700448 }
449 }
450
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700451 private void postDrawHeaderThumbnailTransitionRunnable(final TaskStackView view,
452 final TaskView clickedView, final int offsetX, final int offsetY,
453 final float stackScroll,
Jorim Jaggi6e18e002015-06-02 17:07:39 -0700454 final ActivityOptions.OnAnimationStartedListener animStartedListener) {
455 Runnable r = new Runnable() {
456 @Override
457 public void run() {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700458 overrideDrawHeaderThumbnailTransition(view, clickedView, offsetX, offsetY,
459 stackScroll, animStartedListener);
Jorim Jaggi6e18e002015-06-02 17:07:39 -0700460
Jorim Jaggi6e18e002015-06-02 17:07:39 -0700461 }
462 };
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700463
Jorim Jaggi6e18e002015-06-02 17:07:39 -0700464 mCb.runAfterPause(r);
465 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700466
467 private void overrideDrawHeaderThumbnailTransition(TaskStackView stackView,
468 TaskView clickedTask, int offsetX, int offsetY, float stackScroll,
469 final ActivityOptions.OnAnimationStartedListener animStartedListener) {
470 List<AppTransitionAnimationSpec> specs = getAppTransitionAnimationSpecs(stackView,
471 clickedTask, offsetX, offsetY, stackScroll);
472 if (specs == null) {
473 return;
474 }
475
476 IRemoteCallback.Stub callback = new IRemoteCallback.Stub() {
477 @Override
478 public void sendResult(Bundle data) throws RemoteException {
479 post(new Runnable() {
480 @Override
481 public void run() {
482 if (animStartedListener != null) {
483 animStartedListener.onAnimationStarted();
484 }
485 }
486 });
487 }
488 };
489
490 AppTransitionAnimationSpec[] specsArray =
491 new AppTransitionAnimationSpec[specs.size()];
492 try {
493 WindowManagerGlobal.getWindowManagerService().overridePendingAppTransitionMultiThumb(
494 specs.toArray(specsArray), callback, true /* scaleUp */);
495
496 } catch (RemoteException e) {
497 Log.w(TAG, "Error overriding app transition", e);
498 }
499 }
500
501 private List<AppTransitionAnimationSpec> getAppTransitionAnimationSpecs(TaskStackView stackView,
502 TaskView clickedTask, int offsetX, int offsetY, float stackScroll) {
503 final int targetStackId = clickedTask.getTask().key.stackId;
504 if (targetStackId != ActivityManager.FREEFORM_WORKSPACE_STACK_ID
505 && targetStackId != ActivityManager.FULLSCREEN_WORKSPACE_STACK_ID) {
506 return null;
507 }
508 // If this is a full screen stack, the transition will be towards the single, full screen
509 // task. We only need the transition spec for this task.
510 List<AppTransitionAnimationSpec> specs = new ArrayList<>();
511 if (targetStackId == ActivityManager.FULLSCREEN_WORKSPACE_STACK_ID) {
512 specs.add(createThumbnailHeaderAnimationSpec(
513 stackView, offsetX, offsetY, stackScroll, clickedTask,
514 clickedTask.getTask().key.id, ADD_HEADER_BITMAP));
515 return specs;
516 }
517 // This is a free form stack or full screen stack, so there will be multiple windows
518 // animating from thumbnails. We need transition animation specs for all of them.
519
520 // We will use top and bottom task views as a base for tasks, that aren't visible on the
521 // screen. This is necessary for cascade recents list, where some of the tasks might be
522 // hidden.
523 List<TaskView> taskViews = stackView.getTaskViews();
524 int childCount = taskViews.size();
525 TaskView topChild = taskViews.get(0);
526 TaskView bottomChild = taskViews.get(childCount - 1);
527 SparseArray<TaskView> taskViewsByTaskId = new SparseArray<>();
528 for (int i = 0; i < childCount; i++) {
529 TaskView taskView = taskViews.get(i);
530 taskViewsByTaskId.put(taskView.getTask().key.id, taskView);
531 }
532
533 TaskStack stack = stackView.getStack();
534 // We go through all tasks now and for each generate transition animation spec. If there is
535 // a view associated with a task, we use that view as a base for the animation. If there
536 // isn't, we use bottom or top view, depending on which one would be closer to the task
537 // view if it existed.
538 ArrayList<Task> tasks = stack.getTasks();
539 boolean passedClickedTask = false;
540 for (int i = 0, n = tasks.size(); i < n; i++) {
541 Task task = tasks.get(i);
542 TaskView taskView = taskViewsByTaskId.get(task.key.id);
543 if (taskView != null) {
544 specs.add(createThumbnailHeaderAnimationSpec(stackView, offsetX, offsetY,
545 stackScroll, taskView, taskView.getTask().key.id, ADD_HEADER_BITMAP));
546 if (taskView == clickedTask) {
547 passedClickedTask = true;
548 }
549 } else {
550 taskView = passedClickedTask ? bottomChild : topChild;
551 specs.add(createThumbnailHeaderAnimationSpec(stackView, offsetX, offsetY,
552 stackScroll, taskView, task.key.id, !ADD_HEADER_BITMAP));
553 }
554 }
555
556 return specs;
557 }
558
559 private AppTransitionAnimationSpec createThumbnailHeaderAnimationSpec(TaskStackView stackView,
560 int offsetX, int offsetY, float stackScroll, TaskView tv, int taskId,
561 boolean addHeaderBitmap) {
562 // Disable any focused state before we draw the header
563 // Upfront the processing of the thumbnail
564 if (tv.isFocusedTask()) {
565 tv.unsetFocusedTask();
566 }
567 TaskViewTransform transform = new TaskViewTransform();
568 transform = stackView.getStackAlgorithm().getStackTransform(tv.mTask, stackScroll,
569 transform, null);
570
571 float scale = tv.getScaleX();
572 int fromHeaderWidth = (int) (tv.mHeaderView.getMeasuredWidth() * scale);
573 int fromHeaderHeight = (int) (tv.mHeaderView.getMeasuredHeight() * scale);
574
575 Bitmap b = null;
576 if (addHeaderBitmap) {
577 b = Bitmap.createBitmap(fromHeaderWidth, fromHeaderHeight,
578 Bitmap.Config.ARGB_8888);
579
580 if (Constants.DebugFlags.App.EnableTransitionThumbnailDebugMode) {
581 b.eraseColor(0xFFff0000);
582 } else {
583 Canvas c = new Canvas(b);
584 c.scale(tv.getScaleX(), tv.getScaleY());
585 tv.mHeaderView.draw(c);
586 c.setBitmap(null);
587
588 }
589 b = b.createAshmemBitmap();
590 }
591
592 int[] pts = new int[2];
593 tv.getLocationOnScreen(pts);
594
595 final int left = pts[0] + offsetX;
596 final int top = pts[1] + offsetY;
597 final Rect rect = new Rect(left, top, left + transform.rect.width(),
598 top + transform.rect.height());
599
600 return new AppTransitionAnimationSpec(taskId, b, rect);
601 }
602
Winson Chung47c4c692014-03-17 10:17:11 -0700603 /**** TaskStackView.TaskStackCallbacks Implementation ****/
Winson Chung303e1ff2014-03-07 15:06:19 -0800604
605 @Override
Winson Chung7aceb9a2014-07-03 13:38:01 -0700606 public void onTaskViewClicked(final TaskStackView stackView, final TaskView tv,
Chong Zhang0fa656b2015-08-31 15:17:21 -0700607 final TaskStack stack, final Task task, final boolean lockToTask,
608 final boolean boundsValid, final Rect bounds) {
Jorim Jaggi88f3db92015-06-02 16:29:40 -0700609
Winson Chung47c4c692014-03-17 10:17:11 -0700610 // Notify any callbacks of the launching of a new task
611 if (mCb != null) {
Winson Chung7aceb9a2014-07-03 13:38:01 -0700612 mCb.onTaskViewClicked();
Winson Chung47c4c692014-03-17 10:17:11 -0700613 }
614
Winson Chunge0e45bc2014-06-17 17:56:17 -0700615 // Upfront the processing of the thumbnail
Winson Chungffa2ec62014-07-03 15:54:42 -0700616 TaskViewTransform transform = new TaskViewTransform();
Jorim Jaggicb557032014-09-16 23:09:24 +0200617 View sourceView;
Winson Chunge0e45bc2014-06-17 17:56:17 -0700618 int offsetX = 0;
619 int offsetY = 0;
Winson Chung012ef362014-07-31 18:36:25 -0700620 float stackScroll = stackView.getScroller().getStackScroll();
Winson Chunge0e45bc2014-06-17 17:56:17 -0700621 if (tv == null) {
622 // If there is no actual task view, then use the stack view as the source view
623 // and then offset to the expected transform rect, but bound this to just
624 // outside the display rect (to ensure we don't animate from too far away)
625 sourceView = stackView;
Winson Chunge0e45bc2014-06-17 17:56:17 -0700626 offsetX = transform.rect.left;
Winson35f30502015-09-28 11:24:36 -0700627 offsetY = getMeasuredHeight();
Winson Chunge0e45bc2014-06-17 17:56:17 -0700628 } else {
Jorim Jaggicb557032014-09-16 23:09:24 +0200629 sourceView = tv.mThumbnailView;
Winson Chunge0e45bc2014-06-17 17:56:17 -0700630 }
631
632 // Compute the thumbnail to scale up from
Winson Chung1f24c7e2014-07-11 17:06:48 -0700633 final SystemServicesProxy ssp =
634 RecentsTaskLoader.getInstance().getSystemServicesProxy();
Winson Chunge0e45bc2014-06-17 17:56:17 -0700635 ActivityOptions opts = null;
Chong Zhang0fa656b2015-08-31 15:17:21 -0700636 ActivityOptions.OnAnimationStartedListener animStartedListener = null;
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200637 if (task.thumbnail != null && task.thumbnail.getWidth() > 0 &&
638 task.thumbnail.getHeight() > 0) {
Winson Chung1f24c7e2014-07-11 17:06:48 -0700639 if (lockToTask) {
640 animStartedListener = new ActivityOptions.OnAnimationStartedListener() {
641 boolean mTriggered = false;
642 @Override
643 public void onAnimationStarted() {
644 if (!mTriggered) {
645 postDelayed(new Runnable() {
646 @Override
647 public void run() {
Jason Monk18f99d92014-09-11 13:36:42 -0400648 mCb.onScreenPinningRequest();
Winson Chung1f24c7e2014-07-11 17:06:48 -0700649 }
650 }, 350);
651 mTriggered = true;
652 }
653 }
654 };
655 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700656 postDrawHeaderThumbnailTransitionRunnable(stackView, tv, offsetX, offsetY, stackScroll,
657 animStartedListener);
Winsonec417e42015-09-29 12:42:29 -0700658 opts = ActivityOptions.makeThumbnailAspectScaleUpAnimation(sourceView,
659 Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8).createAshmemBitmap(),
660 offsetX, offsetY, transform.rect.width(), transform.rect.height(),
661 sourceView.getHandler(), animStartedListener);
Chong Zhang0fa656b2015-08-31 15:17:21 -0700662 } else {
663 opts = ActivityOptions.makeBasic();
Winson Chunge0e45bc2014-06-17 17:56:17 -0700664 }
Chong Zhang0fa656b2015-08-31 15:17:21 -0700665 if (boundsValid) {
Winsonb1bbaed2015-09-23 15:45:11 -0700666 opts.setBounds(bounds.isEmpty() ? null : bounds);
Chong Zhang0fa656b2015-08-31 15:17:21 -0700667 }
Winson Chunge0e45bc2014-06-17 17:56:17 -0700668 final ActivityOptions launchOpts = opts;
Chong Zhang0fa656b2015-08-31 15:17:21 -0700669 final boolean screenPinningRequested = (animStartedListener == null) && lockToTask;
Winson Chung303e1ff2014-03-07 15:06:19 -0800670 final Runnable launchRunnable = new Runnable() {
671 @Override
672 public void run() {
Winson Chung4be04452014-03-24 17:22:30 -0700673 if (task.isActive) {
674 // Bring an active task to the foreground
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700675 ssp.moveTaskToFront(task.key.id, launchOpts);
Winson Chung4be04452014-03-24 17:22:30 -0700676 } else {
Winson Chung4e96eb72014-09-17 15:16:09 +0200677 if (ssp.startActivityFromRecents(getContext(), task.key.id,
678 task.activityLabel, launchOpts)) {
Chong Zhang0fa656b2015-08-31 15:17:21 -0700679 if (screenPinningRequested) {
Jason Monk18f99d92014-09-11 13:36:42 -0400680 mCb.onScreenPinningRequest();
Winson Chung4be04452014-03-24 17:22:30 -0700681 }
Winson Chung4e96eb72014-09-17 15:16:09 +0200682 } else {
683 // Dismiss the task and return the user to home if we fail to
684 // launch the task
Winson2536c7e2015-10-01 15:49:31 -0700685 EventBus.getDefault().send(new DismissTaskEvent(task, tv));
Winson Chung4e96eb72014-09-17 15:16:09 +0200686 if (mCb != null) {
687 mCb.onTaskLaunchFailed();
688 }
Winson Chung5c9f4b92015-06-25 16:16:46 -0700689
690 // Keep track of failed launches
691 MetricsLogger.count(getContext(), "overview_task_launch_failed", 1);
Winson Chung4be04452014-03-24 17:22:30 -0700692 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800693 }
694 }
695 };
696
Winson Chung5c9f4b92015-06-25 16:16:46 -0700697 // Keep track of the index of the task launch
698 int taskIndexFromFront = 0;
699 int taskIndex = stack.indexOfTask(task);
700 if (taskIndex > -1) {
701 taskIndexFromFront = stack.getTaskCount() - taskIndex - 1;
702 }
703 MetricsLogger.histogram(getContext(), "overview_task_launch_index", taskIndexFromFront);
704
Winson Chung303e1ff2014-03-07 15:06:19 -0800705 // Launch the app right away if there is no task view, otherwise, animate the icon out first
Winson Chung814086d2014-05-07 15:01:14 -0700706 if (tv == null) {
Winson Chunga91c2932014-11-07 15:02:38 -0800707 launchRunnable.run();
Winson Chung303e1ff2014-03-07 15:06:19 -0800708 } else {
Winson Chunge1e20e12015-06-02 14:11:49 -0700709 if (task.group != null && !task.group.isFrontMostTask(task)) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700710 // For affiliated tasks that are behind other tasks, we must animate the front cards
711 // out of view before starting the task transition
Winson Chungebfc6982014-08-26 12:25:34 -0700712 stackView.startLaunchTaskAnimation(tv, launchRunnable, lockToTask);
Winson Chunga4ccb862014-08-22 15:26:27 -0700713 } else {
714 // Otherwise, we can start the task transition immediately
Winson Chungebfc6982014-08-26 12:25:34 -0700715 stackView.startLaunchTaskAnimation(tv, null, lockToTask);
Winson Chunga91c2932014-11-07 15:02:38 -0800716 launchRunnable.run();
Winson Chunga4ccb862014-08-22 15:26:27 -0700717 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800718 }
719 }
Winson Chung9f9679d2014-04-11 16:49:09 -0700720
721 @Override
Winson Chung6ac8bd62015-01-07 16:38:35 -0800722 public void onAllTaskViewsDismissed(ArrayList<Task> removedTasks) {
Winson2536c7e2015-10-01 15:49:31 -0700723 /* TODO: Not currently enabled
Winson Chung6ac8bd62015-01-07 16:38:35 -0800724 if (removedTasks != null) {
725 int taskCount = removedTasks.size();
726 for (int i = 0; i < taskCount; i++) {
727 onTaskViewDismissed(removedTasks.get(i));
728 }
729 }
Winson2536c7e2015-10-01 15:49:31 -0700730 */
Winson Chung6ac8bd62015-01-07 16:38:35 -0800731
Winson Chung7aceb9a2014-07-03 13:38:01 -0700732 mCb.onAllTaskViewsDismissed();
Winson Chung5c9f4b92015-06-25 16:16:46 -0700733
734 // Keep track of all-deletions
735 MetricsLogger.count(getContext(), "overview_task_all_dismissed", 1);
Winson Chungd7b2cb12014-06-26 15:08:50 -0700736 }
737
Winson Chungb0a28ea2014-10-28 15:21:35 -0700738 /** Final callback after Recents is finally hidden. */
739 public void onRecentsHidden() {
740 // Notify each task stack view
Winson147ecaf2015-09-16 16:49:55 -0700741 if (mTaskStackView != null) {
742 mTaskStackView.onRecentsHidden();
Winson Chungb0a28ea2014-10-28 15:21:35 -0700743 }
744 }
745
Winson Chungd7b2cb12014-06-26 15:08:50 -0700746 @Override
Winson Chung8e548f72014-06-24 14:40:53 -0700747 public void onTaskStackFilterTriggered() {
748 // Hide the search bar
749 if (mSearchBar != null) {
Winson35f30502015-09-28 11:24:36 -0700750 int filterDuration = getResources().getInteger(
751 R.integer.recents_filter_animate_current_views_duration);
Winson Chung8e548f72014-06-24 14:40:53 -0700752 mSearchBar.animate()
753 .alpha(0f)
754 .setStartDelay(0)
Winson35f30502015-09-28 11:24:36 -0700755 .setInterpolator(mFastOutSlowInInterpolator)
756 .setDuration(filterDuration)
Winson Chung8e548f72014-06-24 14:40:53 -0700757 .withLayer()
758 .start();
759 }
760 }
761
762 @Override
763 public void onTaskStackUnfilterTriggered() {
764 // Show the search bar
765 if (mSearchBar != null) {
Winson35f30502015-09-28 11:24:36 -0700766 int filterDuration = getResources().getInteger(
767 R.integer.recents_filter_animate_new_views_duration);
Winson Chung8e548f72014-06-24 14:40:53 -0700768 mSearchBar.animate()
769 .alpha(1f)
770 .setStartDelay(0)
Winson35f30502015-09-28 11:24:36 -0700771 .setInterpolator(mFastOutSlowInInterpolator)
772 .setDuration(filterDuration)
Winson Chung8e548f72014-06-24 14:40:53 -0700773 .withLayer()
774 .start();
775 }
776 }
Winsonbe7607a2015-10-01 17:24:51 -0700777
778 /**** EventBus Events ****/
779
780 public final void onBusEvent(DragStartEvent event) {
781 // Add the drag view
782 mDragView = event.dragView;
783 addView(mDragView);
Winson4165d3362015-10-10 14:40:35 -0700784
Winson882072b2015-10-12 11:26:33 -0700785 updateVisibleDockRegions(mTouchHandler.getDockStatesForCurrentOrientation(),
786 TaskStack.DockState.NONE.viewState.dockAreaAlpha);
Winsonbe7607a2015-10-01 17:24:51 -0700787 }
788
789 public final void onBusEvent(DragDockStateChangedEvent event) {
Winson882072b2015-10-12 11:26:33 -0700790 if (event.dockState == TaskStack.DockState.NONE) {
791 updateVisibleDockRegions(mTouchHandler.getDockStatesForCurrentOrientation(),
792 TaskStack.DockState.NONE.viewState.dockAreaAlpha);
793 } else {
794 updateVisibleDockRegions(new TaskStack.DockState[] {event.dockState}, -1);
795 }
Winsonbe7607a2015-10-01 17:24:51 -0700796 }
797
798 public final void onBusEvent(final DragEndEvent event) {
799 event.postAnimationTrigger.increment();
800 event.postAnimationTrigger.addLastDecrementRunnable(new Runnable() {
801 @Override
802 public void run() {
803 // Remove the drag view
804 removeView(mDragView);
805 mDragView = null;
Winson882072b2015-10-12 11:26:33 -0700806 updateVisibleDockRegions(null, -1);
Winsonbe7607a2015-10-01 17:24:51 -0700807
808 // Dock the new task if we are hovering over a valid dock state
Winson4165d3362015-10-10 14:40:35 -0700809 if (event.dockState != TaskStack.DockState.NONE) {
Winsonbe7607a2015-10-01 17:24:51 -0700810 SystemServicesProxy ssp = RecentsTaskLoader.getInstance().getSystemServicesProxy();
811 ssp.setTaskResizeable(event.task.key.id);
812 ssp.dockTask(event.task.key.id, event.dockState.createMode);
813 launchTask(event.task, null);
814 }
815 }
816 });
Winson4165d3362015-10-10 14:40:35 -0700817 if (event.dockState == TaskStack.DockState.NONE) {
Winsonbe7607a2015-10-01 17:24:51 -0700818 // Animate the alpha back to what it was before
819 Rect taskBounds = mTaskStackView.getStackAlgorithm().getUntransformedTaskViewBounds();
820 int left = taskBounds.left + (int) ((1f - event.taskView.getScaleX()) * taskBounds.width()) / 2;
821 int top = taskBounds.top + (int) ((1f - event.taskView.getScaleY()) * taskBounds.height()) / 2;
822 event.dragView.animate()
Winson4165d3362015-10-10 14:40:35 -0700823 .scaleX(1f)
824 .scaleY(1f)
Winsonbe7607a2015-10-01 17:24:51 -0700825 .translationX(left + event.taskView.getTranslationX())
826 .translationY(top + event.taskView.getTranslationY())
827 .setDuration(175)
Winson4165d3362015-10-10 14:40:35 -0700828 .setInterpolator(mFastOutSlowInInterpolator)
Winsonbe7607a2015-10-01 17:24:51 -0700829 .withEndAction(event.postAnimationTrigger.decrementAsRunnable())
Winsonbe7607a2015-10-01 17:24:51 -0700830 .start();
Winson4165d3362015-10-10 14:40:35 -0700831
832 // Animate the overlay alpha back to 0
Winson882072b2015-10-12 11:26:33 -0700833 updateVisibleDockRegions(null, -1);
Winsonbe7607a2015-10-01 17:24:51 -0700834 } else {
835 event.postAnimationTrigger.decrement();
836 }
837 }
Winson4165d3362015-10-10 14:40:35 -0700838
839 /**
840 * Updates the dock region to match the specified dock state.
841 */
Winson882072b2015-10-12 11:26:33 -0700842 private void updateVisibleDockRegions(TaskStack.DockState[] newDockStates, int overrideAlpha) {
843 ArraySet<TaskStack.DockState> newDockStatesSet = new ArraySet<>();
844 if (newDockStates != null) {
845 for (TaskStack.DockState dockState : newDockStates) {
846 newDockStatesSet.add(dockState);
847 }
Winson4165d3362015-10-10 14:40:35 -0700848 }
Winson882072b2015-10-12 11:26:33 -0700849 for (TaskStack.DockState dockState : mVisibleDockStates) {
850 TaskStack.DockState.ViewState viewState = dockState.viewState;
851 if (newDockStates == null || !newDockStatesSet.contains(dockState)) {
852 // This is no longer visible, so hide it
853 viewState.startAlphaAnimation(0, 150);
854 } else {
855 // This state is now visible, update the bounds and show it
856 int alpha = (overrideAlpha != -1 ? overrideAlpha : viewState.dockAreaAlpha);
857 viewState.dockAreaOverlay.setBounds(
858 dockState.getDockedBounds(getMeasuredWidth(), getMeasuredHeight()));
859 viewState.dockAreaOverlay.setCallback(this);
860 viewState.startAlphaAnimation(alpha, 150);
861 }
Winson4165d3362015-10-10 14:40:35 -0700862 }
Winson4165d3362015-10-10 14:40:35 -0700863 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800864}