blob: f12042178f13903d496b47e474ea1014e9be34d1 [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
Winson4165d3362015-10-10 14:40:35 -070019import android.animation.ObjectAnimator;
20import android.animation.ValueAnimator;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070021import android.app.ActivityManager;
Winson Chung303e1ff2014-03-07 15:06:19 -080022import android.app.ActivityOptions;
23import android.content.Context;
Winson Chung303e1ff2014-03-07 15:06:19 -080024import android.graphics.Bitmap;
25import android.graphics.Canvas;
26import android.graphics.Rect;
Winsonbe7607a2015-10-01 17:24:51 -070027import android.graphics.drawable.ColorDrawable;
Winson4165d3362015-10-10 14:40:35 -070028import android.graphics.drawable.Drawable;
Jorim Jaggi6e18e002015-06-02 17:07:39 -070029import android.os.Bundle;
30import android.os.IRemoteCallback;
31import android.os.RemoteException;
Winson Chung8e548f72014-06-24 14:40:53 -070032import android.util.AttributeSet;
Jorim Jaggi6e18e002015-06-02 17:07:39 -070033import android.util.Log;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070034import android.util.SparseArray;
35import android.view.AppTransitionAnimationSpec;
Winson Chungecd9b302014-04-16 17:07:18 -070036import android.view.LayoutInflater;
Winsonbe7607a2015-10-01 17:24:51 -070037import android.view.MotionEvent;
Winson Chung303e1ff2014-03-07 15:06:19 -080038import android.view.View;
Winson Chung653f70c22014-05-19 14:49:42 -070039import android.view.WindowInsets;
Jorim Jaggi6e18e002015-06-02 17:07:39 -070040import android.view.WindowManagerGlobal;
Winsonbe7607a2015-10-01 17:24:51 -070041import android.view.animation.AccelerateInterpolator;
Winson35f30502015-09-28 11:24:36 -070042import android.view.animation.AnimationUtils;
43import android.view.animation.Interpolator;
Winson Chung303e1ff2014-03-07 15:06:19 -080044import android.widget.FrameLayout;
Winson Chung5c9f4b92015-06-25 16:16:46 -070045import com.android.internal.logging.MetricsLogger;
Winson Chungd16c5652015-01-26 16:11:07 -080046import com.android.systemui.R;
Winson Chung303e1ff2014-03-07 15:06:19 -080047import com.android.systemui.recents.Constants;
Winsonbe7607a2015-10-01 17:24:51 -070048import com.android.systemui.recents.RecentsActivity;
Winson Chungaee097c2015-04-02 18:16:02 -070049import com.android.systemui.recents.RecentsAppWidgetHostView;
Winson Chung303e1ff2014-03-07 15:06:19 -080050import com.android.systemui.recents.RecentsConfiguration;
Winson2536c7e2015-10-01 15:49:31 -070051import com.android.systemui.recents.events.EventBus;
52import com.android.systemui.recents.events.ui.DismissTaskEvent;
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 Chungf1fbd772014-06-24 18:06:58 -070057import com.android.systemui.recents.model.RecentsTaskLoader;
Winson Chung303e1ff2014-03-07 15:06:19 -080058import com.android.systemui.recents.model.Task;
59import com.android.systemui.recents.model.TaskStack;
60
61import java.util.ArrayList;
Winson Chung6ac8bd62015-01-07 16:38:35 -080062import java.util.List;
Winson Chung303e1ff2014-03-07 15:06:19 -080063
Winson Chung303e1ff2014-03-07 15:06:19 -080064/**
65 * This view is the the top level layout that contains TaskStacks (which are laid out according
66 * to their SpaceNode bounds.
67 */
Winsone6c90732015-09-24 16:06:29 -070068public class RecentsView extends FrameLayout implements TaskStackView.TaskStackViewCallbacks {
Winson Chung47c4c692014-03-17 10:17:11 -070069
Jorim Jaggi6e18e002015-06-02 17:07:39 -070070 private static final String TAG = "RecentsView";
71
Filip Gruszczynski170192a2015-08-16 17:46:34 -070072 private static final boolean ADD_HEADER_BITMAP = true;
73
Winson Chung47c4c692014-03-17 10:17:11 -070074 /** The RecentsView callbacks */
75 public interface RecentsViewCallbacks {
Winson Chung7aceb9a2014-07-03 13:38:01 -070076 public void onTaskViewClicked();
Winson Chung4e96eb72014-09-17 15:16:09 +020077 public void onTaskLaunchFailed();
Winson Chung7aceb9a2014-07-03 13:38:01 -070078 public void onAllTaskViewsDismissed();
Winson Chungcdbbb7e2014-06-24 12:11:49 -070079 public void onExitToHomeAnimationTriggered();
Jason Monk18f99d92014-09-11 13:36:42 -040080 public void onScreenPinningRequest();
Jorim Jaggi6e18e002015-06-02 17:07:39 -070081 public void runAfterPause(Runnable r);
Winson Chung47c4c692014-03-17 10:17:11 -070082 }
83
Winson Chungd42a6cf2014-06-03 16:24:04 -070084 RecentsConfiguration mConfig;
85 LayoutInflater mInflater;
86
Winson Chungdcfa7972014-07-22 12:27:13 -070087 ArrayList<TaskStack> mStacks;
Winson147ecaf2015-09-16 16:49:55 -070088 TaskStackView mTaskStackView;
Winson Chungaee097c2015-04-02 18:16:02 -070089 RecentsAppWidgetHostView mSearchBar;
Winson Chung47c4c692014-03-17 10:17:11 -070090 RecentsViewCallbacks mCb;
Winsonbe7607a2015-10-01 17:24:51 -070091
92 RecentsViewTouchHandler mTouchHandler;
93 DragView mDragView;
94 ColorDrawable mDockRegionOverlay;
Winson4165d3362015-10-10 14:40:35 -070095 ObjectAnimator mDockRegionOverlayAnimator;
Winsonbe7607a2015-10-01 17:24:51 -070096
Winson35f30502015-09-28 11:24:36 -070097 Interpolator mFastOutSlowInInterpolator;
98
99 Rect mSystemInsets = new Rect();
Winson Chung303e1ff2014-03-07 15:06:19 -0800100
101 public RecentsView(Context context) {
102 super(context);
Winson Chung8e548f72014-06-24 14:40:53 -0700103 }
104
105 public RecentsView(Context context, AttributeSet attrs) {
106 this(context, attrs, 0);
107 }
108
109 public RecentsView(Context context, AttributeSet attrs, int defStyleAttr) {
110 this(context, attrs, defStyleAttr, 0);
111 }
112
113 public RecentsView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
114 super(context, attrs, defStyleAttr, defStyleRes);
Winsonbe7607a2015-10-01 17:24:51 -0700115 setWillNotDraw(false);
Winson Chungd42a6cf2014-06-03 16:24:04 -0700116 mConfig = RecentsConfiguration.getInstance();
Winson Chungecd9b302014-04-16 17:07:18 -0700117 mInflater = LayoutInflater.from(context);
Winson35f30502015-09-28 11:24:36 -0700118 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
119 com.android.internal.R.interpolator.fast_out_slow_in);
Winsonbe7607a2015-10-01 17:24:51 -0700120 mTouchHandler = new RecentsViewTouchHandler(this);
Winson4165d3362015-10-10 14:40:35 -0700121 mDockRegionOverlay = new ColorDrawable(0xFFffffff);
Winsonbe7607a2015-10-01 17:24:51 -0700122 mDockRegionOverlay.setAlpha(0);
Winson4165d3362015-10-10 14:40:35 -0700123 mDockRegionOverlay.setCallback(this);
Winson Chungd16c5652015-01-26 16:11:07 -0800124 }
125
Winson Chung47c4c692014-03-17 10:17:11 -0700126 /** Sets the callbacks */
127 public void setCallbacks(RecentsViewCallbacks cb) {
128 mCb = cb;
129 }
130
Winson Chungdcfa7972014-07-22 12:27:13 -0700131 /** Set/get the bsp root node */
Winson147ecaf2015-09-16 16:49:55 -0700132 public void setTaskStack(TaskStack stack) {
Winson35f30502015-09-28 11:24:36 -0700133 if (mConfig.getLaunchState().launchedReuseTaskStackViews) {
Winson147ecaf2015-09-16 16:49:55 -0700134 if (mTaskStackView != null) {
135 // If onRecentsHidden is not triggered, we need to the stack view again here
136 mTaskStackView.reset();
137 mTaskStackView.setStack(stack);
138 } else {
139 mTaskStackView = new TaskStackView(getContext(), stack);
140 mTaskStackView.setCallbacks(this);
141 addView(mTaskStackView);
142 }
143 } else {
144 if (mTaskStackView != null) {
145 removeView(mTaskStackView);
146 }
147 mTaskStackView = new TaskStackView(getContext(), stack);
148 mTaskStackView.setCallbacks(this);
149 addView(mTaskStackView);
Winson Chung303e1ff2014-03-07 15:06:19 -0800150 }
Winson Chung02d49272014-08-29 13:57:29 -0700151
Winson Chungb0a28ea2014-10-28 15:21:35 -0700152 // Trigger a new layout
153 requestLayout();
Winson Chung19fc1172014-07-31 18:40:03 -0700154 }
155
Skuhne8aa7d162015-03-20 13:40:53 -0700156 /** Gets the next task in the stack - or if the last - the top task */
157 public Task getNextTaskOrTopTask(Task taskToSearch) {
Chong Zhang0fa656b2015-08-31 15:17:21 -0700158 Task returnTask = null;
Skuhne8aa7d162015-03-20 13:40:53 -0700159 boolean found = false;
Winson147ecaf2015-09-16 16:49:55 -0700160 if (mTaskStackView != null) {
161 TaskStack stack = mTaskStackView.getStack();
Skuhne8aa7d162015-03-20 13:40:53 -0700162 ArrayList<Task> taskList = stack.getTasks();
163 // Iterate the stack views and try and find the focused task
164 for (int j = taskList.size() - 1; j >= 0; --j) {
165 Task task = taskList.get(j);
166 // Return the next task in the line.
167 if (found)
168 return task;
169 // Remember the first possible task as the top task.
170 if (returnTask == null)
171 returnTask = task;
172 if (task == taskToSearch)
173 found = true;
174 }
175 }
176 return returnTask;
177 }
178
Winson Chung1e8d71b2014-05-16 17:05:22 -0700179 /** Launches the focused task from the first stack if possible */
180 public boolean launchFocusedTask() {
Winson147ecaf2015-09-16 16:49:55 -0700181 if (mTaskStackView != null) {
182 TaskStack stack = mTaskStackView.getStack();
Winson Chungd16c5652015-01-26 16:11:07 -0800183 // Iterate the stack views and try and find the focused task
Winson147ecaf2015-09-16 16:49:55 -0700184 List<TaskView> taskViews = mTaskStackView.getTaskViews();
Winson Chungd16c5652015-01-26 16:11:07 -0800185 int taskViewCount = taskViews.size();
186 for (int j = 0; j < taskViewCount; j++) {
187 TaskView tv = taskViews.get(j);
188 Task task = tv.getTask();
189 if (tv.isFocusedTask()) {
Winson147ecaf2015-09-16 16:49:55 -0700190 onTaskViewClicked(mTaskStackView, tv, stack, task, false, false, null);
Winson Chungd16c5652015-01-26 16:11:07 -0800191 return true;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700192 }
193 }
194 }
Winson Chung1e8d71b2014-05-16 17:05:22 -0700195 return false;
196 }
197
Skuhne8aa7d162015-03-20 13:40:53 -0700198 /** Launches a given task. */
Chong Zhang0fa656b2015-08-31 15:17:21 -0700199 public boolean launchTask(Task task, Rect taskBounds) {
Winson147ecaf2015-09-16 16:49:55 -0700200 if (mTaskStackView != null) {
201 TaskStack stack = mTaskStackView.getStack();
Skuhne8aa7d162015-03-20 13:40:53 -0700202 // Iterate the stack views and try and find the given task.
Winson147ecaf2015-09-16 16:49:55 -0700203 List<TaskView> taskViews = mTaskStackView.getTaskViews();
Skuhne8aa7d162015-03-20 13:40:53 -0700204 int taskViewCount = taskViews.size();
205 for (int j = 0; j < taskViewCount; j++) {
206 TaskView tv = taskViews.get(j);
207 if (tv.getTask() == task) {
Winsonb1bbaed2015-09-23 15:45:11 -0700208 onTaskViewClicked(mTaskStackView, tv, stack, task, false, taskBounds != null,
209 taskBounds);
Skuhne8aa7d162015-03-20 13:40:53 -0700210 return true;
211 }
212 }
213 }
214 return false;
215 }
216
Winson Chungdcfa7972014-07-22 12:27:13 -0700217 /** Launches the task that Recents was launched from, if possible */
218 public boolean launchPreviousTask() {
Winson147ecaf2015-09-16 16:49:55 -0700219 if (mTaskStackView != null) {
220 TaskStack stack = mTaskStackView.getStack();
Winson Chungd16c5652015-01-26 16:11:07 -0800221 ArrayList<Task> tasks = stack.getTasks();
Winson Chung47c4c692014-03-17 10:17:11 -0700222
Winson Chungd16c5652015-01-26 16:11:07 -0800223 // Find the launch task in the stack
Winsonbe7607a2015-10-01 17:24:51 -0700224 // TODO: replace this with an event from RecentsActivity
Winson Chungd16c5652015-01-26 16:11:07 -0800225 if (!tasks.isEmpty()) {
226 int taskCount = tasks.size();
227 for (int j = 0; j < taskCount; j++) {
228 if (tasks.get(j).isLaunchTarget) {
229 Task task = tasks.get(j);
Winson147ecaf2015-09-16 16:49:55 -0700230 TaskView tv = mTaskStackView.getChildViewForTask(task);
231 onTaskViewClicked(mTaskStackView, tv, stack, task, false, false, null);
Winson Chungd16c5652015-01-26 16:11:07 -0800232 return true;
Winson Chung303e1ff2014-03-07 15:06:19 -0800233 }
234 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800235 }
236 }
237 return false;
238 }
239
Winson Chung24cf1522014-05-29 12:03:33 -0700240 /** Requests all task stacks to start their enter-recents animation */
Winson Chung969f5862014-06-16 17:08:24 -0700241 public void startEnterRecentsAnimation(ViewAnimation.TaskViewEnterContext ctx) {
Winson Chung740c3ac2014-11-12 16:14:38 -0800242 // We have to increment/decrement the post animation trigger in case there are no children
243 // to ensure that it runs
244 ctx.postAnimationTrigger.increment();
Winson147ecaf2015-09-16 16:49:55 -0700245 if (mTaskStackView != null) {
246 mTaskStackView.startEnterRecentsAnimation(ctx);
Winson Chung24cf1522014-05-29 12:03:33 -0700247 }
Winson Chung740c3ac2014-11-12 16:14:38 -0800248 ctx.postAnimationTrigger.decrement();
Winson Chung24cf1522014-05-29 12:03:33 -0700249 }
250
Winson Chungd42a6cf2014-06-03 16:24:04 -0700251 /** Requests all task stacks to start their exit-recents animation */
Winson Chung969f5862014-06-16 17:08:24 -0700252 public void startExitToHomeAnimation(ViewAnimation.TaskViewExitContext ctx) {
Winson Chunga91c2932014-11-07 15:02:38 -0800253 // We have to increment/decrement the post animation trigger in case there are no children
254 // to ensure that it runs
255 ctx.postAnimationTrigger.increment();
Winson147ecaf2015-09-16 16:49:55 -0700256 if (mTaskStackView != null) {
257 mTaskStackView.startExitToHomeAnimation(ctx);
Winson Chungd42a6cf2014-06-03 16:24:04 -0700258 }
Winson Chunga91c2932014-11-07 15:02:38 -0800259 ctx.postAnimationTrigger.decrement();
Winson Chungd42a6cf2014-06-03 16:24:04 -0700260
Winson Chung969f5862014-06-16 17:08:24 -0700261 // Notify of the exit animation
Winson Chungcdbbb7e2014-06-24 12:11:49 -0700262 mCb.onExitToHomeAnimationTriggered();
Winson Chungd42a6cf2014-06-03 16:24:04 -0700263 }
264
Winson Chungf7bca432014-04-30 17:11:13 -0700265 /** Adds the search bar */
Winson Chungaee097c2015-04-02 18:16:02 -0700266 public void setSearchBar(RecentsAppWidgetHostView searchBar) {
Winson Chungaf3bb692015-06-03 17:31:39 -0700267 // Remove the previous search bar if one exists
268 if (mSearchBar != null && indexOfChild(mSearchBar) > -1) {
269 removeView(mSearchBar);
270 }
271 // Add the new search bar
272 if (searchBar != null) {
273 mSearchBar = searchBar;
274 addView(mSearchBar);
Winson Chungf7bca432014-04-30 17:11:13 -0700275 }
Winson Chungecd9b302014-04-16 17:07:18 -0700276 }
277
Winson Chung772b6b12014-07-03 15:54:02 -0700278 /** Returns whether there is currently a search bar */
Winson Chungaee097c2015-04-02 18:16:02 -0700279 public boolean hasValidSearchBar() {
280 return mSearchBar != null && !mSearchBar.isReinflateRequired();
Winson Chung772b6b12014-07-03 15:54:02 -0700281 }
282
283 /** Sets the visibility of the search bar */
284 public void setSearchBarVisibility(int visibility) {
285 if (mSearchBar != null) {
286 mSearchBar.setVisibility(visibility);
Winson Chung012ef362014-07-31 18:36:25 -0700287 // Always bring the search bar to the top
288 mSearchBar.bringToFront();
Winson Chung772b6b12014-07-03 15:54:02 -0700289 }
290 }
291
Winsonbe7607a2015-10-01 17:24:51 -0700292 @Override
293 protected void onAttachedToWindow() {
294 EventBus.getDefault().register(this, RecentsActivity.EVENT_BUS_PRIORITY + 1);
295 EventBus.getDefault().register(mTouchHandler, RecentsActivity.EVENT_BUS_PRIORITY + 1);
296 super.onAttachedToWindow();
297 }
298
299 @Override
300 protected void onDetachedFromWindow() {
301 super.onDetachedFromWindow();
302 EventBus.getDefault().unregister(this);
303 EventBus.getDefault().unregister(mTouchHandler);
304 }
305
Winson Chungf7bca432014-04-30 17:11:13 -0700306 /**
307 * This is called with the full size of the window since we are handling our own insets.
308 */
Winson Chung303e1ff2014-03-07 15:06:19 -0800309 @Override
310 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
311 int width = MeasureSpec.getSize(widthMeasureSpec);
312 int height = MeasureSpec.getSize(heightMeasureSpec);
Winson Chungbd912972014-03-18 14:36:35 -0700313
Winson Chungf7bca432014-04-30 17:11:13 -0700314 // Get the search bar bounds and measure the search bar layout
Winson Chungaf3bb692015-06-03 17:31:39 -0700315 Rect searchBarSpaceBounds = new Rect();
Winson Chungecd9b302014-04-16 17:07:18 -0700316 if (mSearchBar != null) {
Winson35f30502015-09-28 11:24:36 -0700317 mConfig.getSearchBarBounds(new Rect(0, 0, width, height), mSystemInsets.top,
Winson147ecaf2015-09-16 16:49:55 -0700318 searchBarSpaceBounds);
Winson Chungf7bca432014-04-30 17:11:13 -0700319 mSearchBar.measure(
320 MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.width(), MeasureSpec.EXACTLY),
321 MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.height(), MeasureSpec.EXACTLY));
Winson Chungecd9b302014-04-16 17:07:18 -0700322 }
323
Winson Chungf7bca432014-04-30 17:11:13 -0700324 Rect taskStackBounds = new Rect();
Winson88f00ab2015-10-05 17:24:00 -0700325 mConfig.getTaskStackBounds(new Rect(0, 0, width, height), mSystemInsets.top,
Winson35f30502015-09-28 11:24:36 -0700326 mSystemInsets.right, searchBarSpaceBounds, taskStackBounds);
Winson147ecaf2015-09-16 16:49:55 -0700327 if (mTaskStackView != null && mTaskStackView.getVisibility() != GONE) {
Winson88f00ab2015-10-05 17:24:00 -0700328 mTaskStackView.setTaskStackBounds(taskStackBounds, mSystemInsets);
Winson147ecaf2015-09-16 16:49:55 -0700329 mTaskStackView.measure(widthMeasureSpec, heightMeasureSpec);
Winson Chung303e1ff2014-03-07 15:06:19 -0800330 }
331
Winsonbe7607a2015-10-01 17:24:51 -0700332 if (mDragView != null) {
333 mDragView.measure(
334 MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST),
335 MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST));
336 }
337
Winson Chung303e1ff2014-03-07 15:06:19 -0800338 setMeasuredDimension(width, height);
339 }
340
Winson Chungf7bca432014-04-30 17:11:13 -0700341 /**
342 * This is called with the full size of the window since we are handling our own insets.
343 */
Winson Chung303e1ff2014-03-07 15:06:19 -0800344 @Override
345 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
Winson Chungf7bca432014-04-30 17:11:13 -0700346 // Get the search bar bounds so that we lay it out
Winson147ecaf2015-09-16 16:49:55 -0700347 Rect measuredRect = new Rect(0, 0, getMeasuredWidth(), getMeasuredHeight());
348 Rect searchBarSpaceBounds = new Rect();
Winson Chungecd9b302014-04-16 17:07:18 -0700349 if (mSearchBar != null) {
Winson147ecaf2015-09-16 16:49:55 -0700350 mConfig.getSearchBarBounds(measuredRect,
Winson35f30502015-09-28 11:24:36 -0700351 mSystemInsets.top, searchBarSpaceBounds);
Winson Chungdcfa7972014-07-22 12:27:13 -0700352 mSearchBar.layout(searchBarSpaceBounds.left, searchBarSpaceBounds.top,
353 searchBarSpaceBounds.right, searchBarSpaceBounds.bottom);
Winson Chungecd9b302014-04-16 17:07:18 -0700354 }
355
Winson147ecaf2015-09-16 16:49:55 -0700356 if (mTaskStackView != null && mTaskStackView.getVisibility() != GONE) {
357 mTaskStackView.layout(left, top, left + getMeasuredWidth(), top + getMeasuredHeight());
Winson Chung303e1ff2014-03-07 15:06:19 -0800358 }
Winsonbe7607a2015-10-01 17:24:51 -0700359
360 if (mDragView != null) {
361 mDragView.layout(left, top, left + mDragView.getMeasuredWidth(),
362 top + mDragView.getMeasuredHeight());
363 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800364 }
365
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700366 @Override
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700367 public WindowInsets onApplyWindowInsets(WindowInsets insets) {
Winson35f30502015-09-28 11:24:36 -0700368 mSystemInsets.set(insets.getSystemWindowInsets());
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700369 requestLayout();
Winson Chungdcfa7972014-07-22 12:27:13 -0700370 return insets.consumeSystemWindowInsets();
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700371 }
372
Winsonbe7607a2015-10-01 17:24:51 -0700373 @Override
374 public boolean onInterceptTouchEvent(MotionEvent ev) {
375 return mTouchHandler.onInterceptTouchEvent(ev);
376 }
377
378 @Override
379 public boolean onTouchEvent(MotionEvent ev) {
380 return mTouchHandler.onTouchEvent(ev);
381 }
382
383 @Override
384 protected void dispatchDraw(Canvas canvas) {
385 super.dispatchDraw(canvas);
386 if (mDockRegionOverlay.getAlpha() > 0) {
387 mDockRegionOverlay.draw(canvas);
388 }
389 }
390
Winson4165d3362015-10-10 14:40:35 -0700391 @Override
392 protected boolean verifyDrawable(Drawable who) {
393 return super.verifyDrawable(who) || who == mDockRegionOverlay;
394 }
395
Winson Chunga26fb782014-06-12 17:52:39 -0700396 /** Notifies each task view of the user interaction. */
397 public void onUserInteraction() {
398 // Get the first stack view
Winson147ecaf2015-09-16 16:49:55 -0700399 if (mTaskStackView != null) {
400 mTaskStackView.onUserInteraction();
Winson Chunga26fb782014-06-12 17:52:39 -0700401 }
402 }
403
Winson Chung1e8d71b2014-05-16 17:05:22 -0700404 /** Focuses the next task in the first stack view */
405 public void focusNextTask(boolean forward) {
406 // Get the first stack view
Winson147ecaf2015-09-16 16:49:55 -0700407 if (mTaskStackView != null) {
408 mTaskStackView.focusNextTask(forward, true);
Winson Chung1e8d71b2014-05-16 17:05:22 -0700409 }
Winson Chunga0e88b52014-08-11 19:25:42 -0700410 }
Winson Chung1e8d71b2014-05-16 17:05:22 -0700411
Winson Chunga0e88b52014-08-11 19:25:42 -0700412 /** Dismisses the focused task. */
413 public void dismissFocusedTask() {
414 // Get the first stack view
Winson147ecaf2015-09-16 16:49:55 -0700415 if (mTaskStackView != null) {
416 mTaskStackView.dismissFocusedTask();
Winson Chung1e8d71b2014-05-16 17:05:22 -0700417 }
418 }
419
Winson Chung303e1ff2014-03-07 15:06:19 -0800420 /** Unfilters any filtered stacks */
421 public boolean unfilterFilteredStacks() {
Winson Chungdcfa7972014-07-22 12:27:13 -0700422 if (mStacks != null) {
Winson Chung303e1ff2014-03-07 15:06:19 -0800423 // Check if there are any filtered stacks and unfilter them before we back out of Recents
424 boolean stacksUnfiltered = false;
Winson Chungdcfa7972014-07-22 12:27:13 -0700425 int numStacks = mStacks.size();
426 for (int i = 0; i < numStacks; i++) {
427 TaskStack stack = mStacks.get(i);
Winson Chung303e1ff2014-03-07 15:06:19 -0800428 if (stack.hasFilteredTasks()) {
429 stack.unfilterTasks();
430 stacksUnfiltered = true;
431 }
432 }
433 return stacksUnfiltered;
434 }
435 return false;
436 }
437
Jorim Jaggi900fb482015-06-02 15:07:33 -0700438 public void disableLayersForOneFrame() {
Winson147ecaf2015-09-16 16:49:55 -0700439 if (mTaskStackView != null) {
440 mTaskStackView.disableLayersForOneFrame();
Jorim Jaggi900fb482015-06-02 15:07:33 -0700441 }
442 }
443
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700444 private void postDrawHeaderThumbnailTransitionRunnable(final TaskStackView view,
445 final TaskView clickedView, final int offsetX, final int offsetY,
446 final float stackScroll,
Jorim Jaggi6e18e002015-06-02 17:07:39 -0700447 final ActivityOptions.OnAnimationStartedListener animStartedListener) {
448 Runnable r = new Runnable() {
449 @Override
450 public void run() {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700451 overrideDrawHeaderThumbnailTransition(view, clickedView, offsetX, offsetY,
452 stackScroll, animStartedListener);
Jorim Jaggi6e18e002015-06-02 17:07:39 -0700453
Jorim Jaggi6e18e002015-06-02 17:07:39 -0700454 }
455 };
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700456
Jorim Jaggi6e18e002015-06-02 17:07:39 -0700457 mCb.runAfterPause(r);
458 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700459
460 private void overrideDrawHeaderThumbnailTransition(TaskStackView stackView,
461 TaskView clickedTask, int offsetX, int offsetY, float stackScroll,
462 final ActivityOptions.OnAnimationStartedListener animStartedListener) {
463 List<AppTransitionAnimationSpec> specs = getAppTransitionAnimationSpecs(stackView,
464 clickedTask, offsetX, offsetY, stackScroll);
465 if (specs == null) {
466 return;
467 }
468
469 IRemoteCallback.Stub callback = new IRemoteCallback.Stub() {
470 @Override
471 public void sendResult(Bundle data) throws RemoteException {
472 post(new Runnable() {
473 @Override
474 public void run() {
475 if (animStartedListener != null) {
476 animStartedListener.onAnimationStarted();
477 }
478 }
479 });
480 }
481 };
482
483 AppTransitionAnimationSpec[] specsArray =
484 new AppTransitionAnimationSpec[specs.size()];
485 try {
486 WindowManagerGlobal.getWindowManagerService().overridePendingAppTransitionMultiThumb(
487 specs.toArray(specsArray), callback, true /* scaleUp */);
488
489 } catch (RemoteException e) {
490 Log.w(TAG, "Error overriding app transition", e);
491 }
492 }
493
494 private List<AppTransitionAnimationSpec> getAppTransitionAnimationSpecs(TaskStackView stackView,
495 TaskView clickedTask, int offsetX, int offsetY, float stackScroll) {
496 final int targetStackId = clickedTask.getTask().key.stackId;
497 if (targetStackId != ActivityManager.FREEFORM_WORKSPACE_STACK_ID
498 && targetStackId != ActivityManager.FULLSCREEN_WORKSPACE_STACK_ID) {
499 return null;
500 }
501 // If this is a full screen stack, the transition will be towards the single, full screen
502 // task. We only need the transition spec for this task.
503 List<AppTransitionAnimationSpec> specs = new ArrayList<>();
504 if (targetStackId == ActivityManager.FULLSCREEN_WORKSPACE_STACK_ID) {
505 specs.add(createThumbnailHeaderAnimationSpec(
506 stackView, offsetX, offsetY, stackScroll, clickedTask,
507 clickedTask.getTask().key.id, ADD_HEADER_BITMAP));
508 return specs;
509 }
510 // This is a free form stack or full screen stack, so there will be multiple windows
511 // animating from thumbnails. We need transition animation specs for all of them.
512
513 // We will use top and bottom task views as a base for tasks, that aren't visible on the
514 // screen. This is necessary for cascade recents list, where some of the tasks might be
515 // hidden.
516 List<TaskView> taskViews = stackView.getTaskViews();
517 int childCount = taskViews.size();
518 TaskView topChild = taskViews.get(0);
519 TaskView bottomChild = taskViews.get(childCount - 1);
520 SparseArray<TaskView> taskViewsByTaskId = new SparseArray<>();
521 for (int i = 0; i < childCount; i++) {
522 TaskView taskView = taskViews.get(i);
523 taskViewsByTaskId.put(taskView.getTask().key.id, taskView);
524 }
525
526 TaskStack stack = stackView.getStack();
527 // We go through all tasks now and for each generate transition animation spec. If there is
528 // a view associated with a task, we use that view as a base for the animation. If there
529 // isn't, we use bottom or top view, depending on which one would be closer to the task
530 // view if it existed.
531 ArrayList<Task> tasks = stack.getTasks();
532 boolean passedClickedTask = false;
533 for (int i = 0, n = tasks.size(); i < n; i++) {
534 Task task = tasks.get(i);
535 TaskView taskView = taskViewsByTaskId.get(task.key.id);
536 if (taskView != null) {
537 specs.add(createThumbnailHeaderAnimationSpec(stackView, offsetX, offsetY,
538 stackScroll, taskView, taskView.getTask().key.id, ADD_HEADER_BITMAP));
539 if (taskView == clickedTask) {
540 passedClickedTask = true;
541 }
542 } else {
543 taskView = passedClickedTask ? bottomChild : topChild;
544 specs.add(createThumbnailHeaderAnimationSpec(stackView, offsetX, offsetY,
545 stackScroll, taskView, task.key.id, !ADD_HEADER_BITMAP));
546 }
547 }
548
549 return specs;
550 }
551
552 private AppTransitionAnimationSpec createThumbnailHeaderAnimationSpec(TaskStackView stackView,
553 int offsetX, int offsetY, float stackScroll, TaskView tv, int taskId,
554 boolean addHeaderBitmap) {
555 // Disable any focused state before we draw the header
556 // Upfront the processing of the thumbnail
557 if (tv.isFocusedTask()) {
558 tv.unsetFocusedTask();
559 }
560 TaskViewTransform transform = new TaskViewTransform();
561 transform = stackView.getStackAlgorithm().getStackTransform(tv.mTask, stackScroll,
562 transform, null);
563
564 float scale = tv.getScaleX();
565 int fromHeaderWidth = (int) (tv.mHeaderView.getMeasuredWidth() * scale);
566 int fromHeaderHeight = (int) (tv.mHeaderView.getMeasuredHeight() * scale);
567
568 Bitmap b = null;
569 if (addHeaderBitmap) {
570 b = Bitmap.createBitmap(fromHeaderWidth, fromHeaderHeight,
571 Bitmap.Config.ARGB_8888);
572
573 if (Constants.DebugFlags.App.EnableTransitionThumbnailDebugMode) {
574 b.eraseColor(0xFFff0000);
575 } else {
576 Canvas c = new Canvas(b);
577 c.scale(tv.getScaleX(), tv.getScaleY());
578 tv.mHeaderView.draw(c);
579 c.setBitmap(null);
580
581 }
582 b = b.createAshmemBitmap();
583 }
584
585 int[] pts = new int[2];
586 tv.getLocationOnScreen(pts);
587
588 final int left = pts[0] + offsetX;
589 final int top = pts[1] + offsetY;
590 final Rect rect = new Rect(left, top, left + transform.rect.width(),
591 top + transform.rect.height());
592
593 return new AppTransitionAnimationSpec(taskId, b, rect);
594 }
595
Winson Chung47c4c692014-03-17 10:17:11 -0700596 /**** TaskStackView.TaskStackCallbacks Implementation ****/
Winson Chung303e1ff2014-03-07 15:06:19 -0800597
598 @Override
Winson Chung7aceb9a2014-07-03 13:38:01 -0700599 public void onTaskViewClicked(final TaskStackView stackView, final TaskView tv,
Chong Zhang0fa656b2015-08-31 15:17:21 -0700600 final TaskStack stack, final Task task, final boolean lockToTask,
601 final boolean boundsValid, final Rect bounds) {
Jorim Jaggi88f3db92015-06-02 16:29:40 -0700602
Winson Chung47c4c692014-03-17 10:17:11 -0700603 // Notify any callbacks of the launching of a new task
604 if (mCb != null) {
Winson Chung7aceb9a2014-07-03 13:38:01 -0700605 mCb.onTaskViewClicked();
Winson Chung47c4c692014-03-17 10:17:11 -0700606 }
607
Winson Chunge0e45bc2014-06-17 17:56:17 -0700608 // Upfront the processing of the thumbnail
Winson Chungffa2ec62014-07-03 15:54:42 -0700609 TaskViewTransform transform = new TaskViewTransform();
Jorim Jaggicb557032014-09-16 23:09:24 +0200610 View sourceView;
Winson Chunge0e45bc2014-06-17 17:56:17 -0700611 int offsetX = 0;
612 int offsetY = 0;
Winson Chung012ef362014-07-31 18:36:25 -0700613 float stackScroll = stackView.getScroller().getStackScroll();
Winson Chunge0e45bc2014-06-17 17:56:17 -0700614 if (tv == null) {
615 // If there is no actual task view, then use the stack view as the source view
616 // and then offset to the expected transform rect, but bound this to just
617 // outside the display rect (to ensure we don't animate from too far away)
618 sourceView = stackView;
Winson Chunge0e45bc2014-06-17 17:56:17 -0700619 offsetX = transform.rect.left;
Winson35f30502015-09-28 11:24:36 -0700620 offsetY = getMeasuredHeight();
Winson Chunge0e45bc2014-06-17 17:56:17 -0700621 } else {
Jorim Jaggicb557032014-09-16 23:09:24 +0200622 sourceView = tv.mThumbnailView;
Winson Chunge0e45bc2014-06-17 17:56:17 -0700623 }
624
625 // Compute the thumbnail to scale up from
Winson Chung1f24c7e2014-07-11 17:06:48 -0700626 final SystemServicesProxy ssp =
627 RecentsTaskLoader.getInstance().getSystemServicesProxy();
Winson Chunge0e45bc2014-06-17 17:56:17 -0700628 ActivityOptions opts = null;
Chong Zhang0fa656b2015-08-31 15:17:21 -0700629 ActivityOptions.OnAnimationStartedListener animStartedListener = null;
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200630 if (task.thumbnail != null && task.thumbnail.getWidth() > 0 &&
631 task.thumbnail.getHeight() > 0) {
Winson Chung1f24c7e2014-07-11 17:06:48 -0700632 if (lockToTask) {
633 animStartedListener = new ActivityOptions.OnAnimationStartedListener() {
634 boolean mTriggered = false;
635 @Override
636 public void onAnimationStarted() {
637 if (!mTriggered) {
638 postDelayed(new Runnable() {
639 @Override
640 public void run() {
Jason Monk18f99d92014-09-11 13:36:42 -0400641 mCb.onScreenPinningRequest();
Winson Chung1f24c7e2014-07-11 17:06:48 -0700642 }
643 }, 350);
644 mTriggered = true;
645 }
646 }
647 };
648 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700649 postDrawHeaderThumbnailTransitionRunnable(stackView, tv, offsetX, offsetY, stackScroll,
650 animStartedListener);
Winsonec417e42015-09-29 12:42:29 -0700651 opts = ActivityOptions.makeThumbnailAspectScaleUpAnimation(sourceView,
652 Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8).createAshmemBitmap(),
653 offsetX, offsetY, transform.rect.width(), transform.rect.height(),
654 sourceView.getHandler(), animStartedListener);
Chong Zhang0fa656b2015-08-31 15:17:21 -0700655 } else {
656 opts = ActivityOptions.makeBasic();
Winson Chunge0e45bc2014-06-17 17:56:17 -0700657 }
Chong Zhang0fa656b2015-08-31 15:17:21 -0700658 if (boundsValid) {
Winsonb1bbaed2015-09-23 15:45:11 -0700659 opts.setBounds(bounds.isEmpty() ? null : bounds);
Chong Zhang0fa656b2015-08-31 15:17:21 -0700660 }
Winson Chunge0e45bc2014-06-17 17:56:17 -0700661 final ActivityOptions launchOpts = opts;
Chong Zhang0fa656b2015-08-31 15:17:21 -0700662 final boolean screenPinningRequested = (animStartedListener == null) && lockToTask;
Winson Chung303e1ff2014-03-07 15:06:19 -0800663 final Runnable launchRunnable = new Runnable() {
664 @Override
665 public void run() {
Winson Chung4be04452014-03-24 17:22:30 -0700666 if (task.isActive) {
667 // Bring an active task to the foreground
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700668 ssp.moveTaskToFront(task.key.id, launchOpts);
Winson Chung4be04452014-03-24 17:22:30 -0700669 } else {
Winson Chung4e96eb72014-09-17 15:16:09 +0200670 if (ssp.startActivityFromRecents(getContext(), task.key.id,
671 task.activityLabel, launchOpts)) {
Chong Zhang0fa656b2015-08-31 15:17:21 -0700672 if (screenPinningRequested) {
Jason Monk18f99d92014-09-11 13:36:42 -0400673 mCb.onScreenPinningRequest();
Winson Chung4be04452014-03-24 17:22:30 -0700674 }
Winson Chung4e96eb72014-09-17 15:16:09 +0200675 } else {
676 // Dismiss the task and return the user to home if we fail to
677 // launch the task
Winson2536c7e2015-10-01 15:49:31 -0700678 EventBus.getDefault().send(new DismissTaskEvent(task, tv));
Winson Chung4e96eb72014-09-17 15:16:09 +0200679 if (mCb != null) {
680 mCb.onTaskLaunchFailed();
681 }
Winson Chung5c9f4b92015-06-25 16:16:46 -0700682
683 // Keep track of failed launches
684 MetricsLogger.count(getContext(), "overview_task_launch_failed", 1);
Winson Chung4be04452014-03-24 17:22:30 -0700685 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800686 }
687 }
688 };
689
Winson Chung5c9f4b92015-06-25 16:16:46 -0700690 // Keep track of the index of the task launch
691 int taskIndexFromFront = 0;
692 int taskIndex = stack.indexOfTask(task);
693 if (taskIndex > -1) {
694 taskIndexFromFront = stack.getTaskCount() - taskIndex - 1;
695 }
696 MetricsLogger.histogram(getContext(), "overview_task_launch_index", taskIndexFromFront);
697
Winson Chung303e1ff2014-03-07 15:06:19 -0800698 // Launch the app right away if there is no task view, otherwise, animate the icon out first
Winson Chung814086d2014-05-07 15:01:14 -0700699 if (tv == null) {
Winson Chunga91c2932014-11-07 15:02:38 -0800700 launchRunnable.run();
Winson Chung303e1ff2014-03-07 15:06:19 -0800701 } else {
Winson Chunge1e20e12015-06-02 14:11:49 -0700702 if (task.group != null && !task.group.isFrontMostTask(task)) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700703 // For affiliated tasks that are behind other tasks, we must animate the front cards
704 // out of view before starting the task transition
Winson Chungebfc6982014-08-26 12:25:34 -0700705 stackView.startLaunchTaskAnimation(tv, launchRunnable, lockToTask);
Winson Chunga4ccb862014-08-22 15:26:27 -0700706 } else {
707 // Otherwise, we can start the task transition immediately
Winson Chungebfc6982014-08-26 12:25:34 -0700708 stackView.startLaunchTaskAnimation(tv, null, lockToTask);
Winson Chunga91c2932014-11-07 15:02:38 -0800709 launchRunnable.run();
Winson Chunga4ccb862014-08-22 15:26:27 -0700710 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800711 }
712 }
Winson Chung9f9679d2014-04-11 16:49:09 -0700713
714 @Override
Winson Chung6ac8bd62015-01-07 16:38:35 -0800715 public void onAllTaskViewsDismissed(ArrayList<Task> removedTasks) {
Winson2536c7e2015-10-01 15:49:31 -0700716 /* TODO: Not currently enabled
Winson Chung6ac8bd62015-01-07 16:38:35 -0800717 if (removedTasks != null) {
718 int taskCount = removedTasks.size();
719 for (int i = 0; i < taskCount; i++) {
720 onTaskViewDismissed(removedTasks.get(i));
721 }
722 }
Winson2536c7e2015-10-01 15:49:31 -0700723 */
Winson Chung6ac8bd62015-01-07 16:38:35 -0800724
Winson Chung7aceb9a2014-07-03 13:38:01 -0700725 mCb.onAllTaskViewsDismissed();
Winson Chung5c9f4b92015-06-25 16:16:46 -0700726
727 // Keep track of all-deletions
728 MetricsLogger.count(getContext(), "overview_task_all_dismissed", 1);
Winson Chungd7b2cb12014-06-26 15:08:50 -0700729 }
730
Winson Chungb0a28ea2014-10-28 15:21:35 -0700731 /** Final callback after Recents is finally hidden. */
732 public void onRecentsHidden() {
733 // Notify each task stack view
Winson147ecaf2015-09-16 16:49:55 -0700734 if (mTaskStackView != null) {
735 mTaskStackView.onRecentsHidden();
Winson Chungb0a28ea2014-10-28 15:21:35 -0700736 }
737 }
738
Winson Chungd7b2cb12014-06-26 15:08:50 -0700739 @Override
Winson Chung8e548f72014-06-24 14:40:53 -0700740 public void onTaskStackFilterTriggered() {
741 // Hide the search bar
742 if (mSearchBar != null) {
Winson35f30502015-09-28 11:24:36 -0700743 int filterDuration = getResources().getInteger(
744 R.integer.recents_filter_animate_current_views_duration);
Winson Chung8e548f72014-06-24 14:40:53 -0700745 mSearchBar.animate()
746 .alpha(0f)
747 .setStartDelay(0)
Winson35f30502015-09-28 11:24:36 -0700748 .setInterpolator(mFastOutSlowInInterpolator)
749 .setDuration(filterDuration)
Winson Chung8e548f72014-06-24 14:40:53 -0700750 .withLayer()
751 .start();
752 }
753 }
754
755 @Override
756 public void onTaskStackUnfilterTriggered() {
757 // Show the search bar
758 if (mSearchBar != null) {
Winson35f30502015-09-28 11:24:36 -0700759 int filterDuration = getResources().getInteger(
760 R.integer.recents_filter_animate_new_views_duration);
Winson Chung8e548f72014-06-24 14:40:53 -0700761 mSearchBar.animate()
762 .alpha(1f)
763 .setStartDelay(0)
Winson35f30502015-09-28 11:24:36 -0700764 .setInterpolator(mFastOutSlowInInterpolator)
765 .setDuration(filterDuration)
Winson Chung8e548f72014-06-24 14:40:53 -0700766 .withLayer()
767 .start();
768 }
769 }
Winsonbe7607a2015-10-01 17:24:51 -0700770
771 /**** EventBus Events ****/
772
773 public final void onBusEvent(DragStartEvent event) {
774 // Add the drag view
775 mDragView = event.dragView;
776 addView(mDragView);
Winson4165d3362015-10-10 14:40:35 -0700777
778 updateDockRegion(TaskStack.DockState.NONE);
Winsonbe7607a2015-10-01 17:24:51 -0700779 }
780
781 public final void onBusEvent(DragDockStateChangedEvent event) {
Winson4165d3362015-10-10 14:40:35 -0700782 updateDockRegion(event.dockState);
Winsonbe7607a2015-10-01 17:24:51 -0700783 }
784
785 public final void onBusEvent(final DragEndEvent event) {
786 event.postAnimationTrigger.increment();
787 event.postAnimationTrigger.addLastDecrementRunnable(new Runnable() {
788 @Override
789 public void run() {
790 // Remove the drag view
791 removeView(mDragView);
792 mDragView = null;
793 mDockRegionOverlay.setAlpha(0);
794 invalidate();
795
796 // Dock the new task if we are hovering over a valid dock state
Winson4165d3362015-10-10 14:40:35 -0700797 if (event.dockState != TaskStack.DockState.NONE) {
Winsonbe7607a2015-10-01 17:24:51 -0700798 SystemServicesProxy ssp = RecentsTaskLoader.getInstance().getSystemServicesProxy();
799 ssp.setTaskResizeable(event.task.key.id);
800 ssp.dockTask(event.task.key.id, event.dockState.createMode);
801 launchTask(event.task, null);
802 }
803 }
804 });
Winson4165d3362015-10-10 14:40:35 -0700805 if (event.dockState == TaskStack.DockState.NONE) {
Winsonbe7607a2015-10-01 17:24:51 -0700806 // Animate the alpha back to what it was before
807 Rect taskBounds = mTaskStackView.getStackAlgorithm().getUntransformedTaskViewBounds();
808 int left = taskBounds.left + (int) ((1f - event.taskView.getScaleX()) * taskBounds.width()) / 2;
809 int top = taskBounds.top + (int) ((1f - event.taskView.getScaleY()) * taskBounds.height()) / 2;
810 event.dragView.animate()
Winson4165d3362015-10-10 14:40:35 -0700811 .scaleX(1f)
812 .scaleY(1f)
Winsonbe7607a2015-10-01 17:24:51 -0700813 .translationX(left + event.taskView.getTranslationX())
814 .translationY(top + event.taskView.getTranslationY())
815 .setDuration(175)
Winson4165d3362015-10-10 14:40:35 -0700816 .setInterpolator(mFastOutSlowInInterpolator)
Winsonbe7607a2015-10-01 17:24:51 -0700817 .withEndAction(event.postAnimationTrigger.decrementAsRunnable())
Winsonbe7607a2015-10-01 17:24:51 -0700818 .start();
Winson4165d3362015-10-10 14:40:35 -0700819
820 // Animate the overlay alpha back to 0
821 updateDockRegionAlpha(0);
Winsonbe7607a2015-10-01 17:24:51 -0700822 } else {
823 event.postAnimationTrigger.decrement();
824 }
825 }
Winson4165d3362015-10-10 14:40:35 -0700826
827 /**
828 * Updates the dock region to match the specified dock state.
829 */
830 private void updateDockRegion(TaskStack.DockState dockState) {
831 TaskStack.DockState boundsDockState = dockState;
832 if (dockState == TaskStack.DockState.NONE) {
833 // If the dock state is null, then use the bounds of the preferred dock state for this
834 // orientation
835 boundsDockState = mTouchHandler.getPreferredDockStateForCurrentOrientation();
836 }
837 mDockRegionOverlay.setBounds(
838 boundsDockState.getDockedBounds(getMeasuredWidth(), getMeasuredHeight()));
839 updateDockRegionAlpha(dockState.dockAreaAlpha);
840 }
841
842 private void updateDockRegionAlpha(int alpha) {
843 if (mDockRegionOverlayAnimator != null) {
844 mDockRegionOverlayAnimator.cancel();
845 }
846 mDockRegionOverlayAnimator = ObjectAnimator.ofInt(mDockRegionOverlay, "alpha", alpha);
847 mDockRegionOverlayAnimator.setDuration(150);
848 mDockRegionOverlayAnimator.start();
849 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800850}