blob: 1af5a55f7a1e9492e134cb9514b9e56d7e19bb44 [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
Winson231bc9c2016-02-09 12:31:00 -080019import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
20
Winsonf24f2162016-01-05 12:11:55 -080021import android.animation.Animator;
22import android.animation.AnimatorListenerAdapter;
Winson49df4202016-01-25 17:33:34 -080023import android.animation.ObjectAnimator;
Winson Chung303e1ff2014-03-07 15:06:19 -080024import android.content.Context;
Winson Chung303e1ff2014-03-07 15:06:19 -080025import android.graphics.Canvas;
Winson49df4202016-01-25 17:33:34 -080026import android.graphics.Color;
27import android.graphics.Outline;
Winson Chung303e1ff2014-03-07 15:06:19 -080028import android.graphics.Rect;
Winson49df4202016-01-25 17:33:34 -080029import android.graphics.drawable.ColorDrawable;
Winson4165d3362015-10-10 14:40:35 -070030import android.graphics.drawable.Drawable;
Winson83c1b072015-11-09 10:48:04 -080031import android.os.Handler;
Winson882072b2015-10-12 11:26:33 -070032import android.util.ArraySet;
Winson Chung8e548f72014-06-24 14:40:53 -070033import android.util.AttributeSet;
Winson Chungecd9b302014-04-16 17:07:18 -070034import android.view.LayoutInflater;
Winsonbe7607a2015-10-01 17:24:51 -070035import android.view.MotionEvent;
Winsonc29ff002015-11-20 16:00:45 -080036import android.view.View;
Winson231bc9c2016-02-09 12:31:00 -080037import android.view.ViewDebug;
Winson49df4202016-01-25 17:33:34 -080038import android.view.ViewOutlineProvider;
Jorim Jaggi870ab5a2015-12-02 18:37:54 -080039import android.view.ViewPropertyAnimator;
Winson Chung653f70c22014-05-19 14:49:42 -070040import android.view.WindowInsets;
Winson Chung303e1ff2014-03-07 15:06:19 -080041import android.widget.FrameLayout;
Winson Chungde750de2015-12-11 10:26:06 -050042import android.widget.TextView;
Chris Wrenf6e9228b2016-01-26 18:04:35 -050043
Winsondc8de842016-01-06 15:21:41 -080044import com.android.internal.logging.MetricsLogger;
Chris Wrenf6e9228b2016-01-26 18:04:35 -050045import com.android.internal.logging.MetricsProto.MetricsEvent;
Winsonc0d70582016-01-29 10:24:39 -080046import com.android.systemui.Interpolators;
Winson Chungd16c5652015-01-26 16:11:07 -080047import com.android.systemui.R;
Winsone7f138c2015-10-22 16:15:21 -070048import com.android.systemui.recents.Recents;
Winsonbe7607a2015-10-01 17:24:51 -070049import com.android.systemui.recents.RecentsActivity;
Winsonb1e71d02015-11-23 12:40:23 -080050import com.android.systemui.recents.RecentsActivityLaunchState;
Winson Chungaee097c2015-04-02 18:16:02 -070051import com.android.systemui.recents.RecentsAppWidgetHostView;
Winson Chung303e1ff2014-03-07 15:06:19 -080052import com.android.systemui.recents.RecentsConfiguration;
Winsonc29ff002015-11-20 16:00:45 -080053import com.android.systemui.recents.RecentsDebugFlags;
Winson2536c7e2015-10-01 15:49:31 -070054import com.android.systemui.recents.events.EventBus;
Winson214f0f02016-01-26 13:37:37 -080055import com.android.systemui.recents.events.activity.ClearHistoryEvent;
Winson412e1802015-10-20 16:57:57 -070056import com.android.systemui.recents.events.activity.DismissRecentsToHomeAnimationStarted;
Winson49df4202016-01-25 17:33:34 -080057import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationCompletedEvent;
Winsonc29ff002015-11-20 16:00:45 -080058import com.android.systemui.recents.events.activity.HideHistoryButtonEvent;
59import com.android.systemui.recents.events.activity.HideHistoryEvent;
Winson Chung48f2cda2015-12-11 13:20:12 -050060import com.android.systemui.recents.events.activity.LaunchTaskEvent;
Winsonc29ff002015-11-20 16:00:45 -080061import com.android.systemui.recents.events.activity.ShowHistoryButtonEvent;
62import com.android.systemui.recents.events.activity.ShowHistoryEvent;
Winson49df4202016-01-25 17:33:34 -080063import com.android.systemui.recents.events.activity.ToggleHistoryEvent;
Jorim Jaggidd98d412015-11-18 15:57:38 -080064import com.android.systemui.recents.events.ui.DraggingInRecentsEndedEvent;
65import com.android.systemui.recents.events.ui.DraggingInRecentsEvent;
Winson49df4202016-01-25 17:33:34 -080066import com.android.systemui.recents.events.ui.ResetBackgroundScrimEvent;
67import com.android.systemui.recents.events.ui.UpdateBackgroundScrimEvent;
Winsoneca4ab62015-11-04 10:50:28 -080068import com.android.systemui.recents.events.ui.dragndrop.DragDropTargetChangedEvent;
Winsonbe7607a2015-10-01 17:24:51 -070069import com.android.systemui.recents.events.ui.dragndrop.DragEndEvent;
70import com.android.systemui.recents.events.ui.dragndrop.DragStartEvent;
Winson49df4202016-01-25 17:33:34 -080071import com.android.systemui.recents.history.RecentsHistoryView;
Winson Chung9a742902015-12-11 10:25:40 -050072import com.android.systemui.recents.misc.ReferenceCountedTrigger;
Winson Chung1f24c7e2014-07-11 17:06:48 -070073import com.android.systemui.recents.misc.SystemServicesProxy;
Winsonc5fd3502016-01-18 15:18:37 -080074import com.android.systemui.recents.misc.Utilities;
Winson Chung303e1ff2014-03-07 15:06:19 -080075import com.android.systemui.recents.model.Task;
76import com.android.systemui.recents.model.TaskStack;
Jorim Jaggi870ab5a2015-12-02 18:37:54 -080077import com.android.systemui.stackdivider.WindowManagerProxy;
78import com.android.systemui.statusbar.FlingAnimationUtils;
Winson Chung303e1ff2014-03-07 15:06:19 -080079
80import java.util.ArrayList;
Winson Chung6ac8bd62015-01-07 16:38:35 -080081import java.util.List;
Winson Chung303e1ff2014-03-07 15:06:19 -080082
Winson Chung303e1ff2014-03-07 15:06:19 -080083/**
84 * This view is the the top level layout that contains TaskStacks (which are laid out according
85 * to their SpaceNode bounds.
86 */
Winson Chung48f2cda2015-12-11 13:20:12 -050087public class RecentsView extends FrameLayout {
Winson Chung47c4c692014-03-17 10:17:11 -070088
Winson3e874742016-01-07 10:08:17 -080089 private static final int DOCK_AREA_OVERLAY_TRANSITION_DURATION = 135;
Winson49df4202016-01-25 17:33:34 -080090 private static final int DEFAULT_UPDATE_SCRIM_DURATION = 200;
91 private static final float DEFAULT_SCRIM_ALPHA = 0.33f;
Jorim Jaggi6e18e002015-06-02 17:07:39 -070092
Winson Chung9a742902015-12-11 10:25:40 -050093 private final Handler mHandler;
Winson Chungd42a6cf2014-06-03 16:24:04 -070094
Winson Chung9a742902015-12-11 10:25:40 -050095 private TaskStack mStack;
96 private TaskStackView mTaskStackView;
97 private RecentsAppWidgetHostView mSearchBar;
Winson Chungde750de2015-12-11 10:26:06 -050098 private TextView mHistoryButton;
Winson214f0f02016-01-26 13:37:37 -080099 private TextView mHistoryClearAllButton;
Winson Chung9a742902015-12-11 10:25:40 -0500100 private View mEmptyView;
Winson49df4202016-01-25 17:33:34 -0800101 private RecentsHistoryView mHistoryView;
102
Winson Chung9a742902015-12-11 10:25:40 -0500103 private boolean mAwaitingFirstLayout = true;
104 private boolean mLastTaskLaunchedWasFreeform;
Winson231bc9c2016-02-09 12:31:00 -0800105
106 @ViewDebug.ExportedProperty(category="recents")
Winson Chung9a742902015-12-11 10:25:40 -0500107 private Rect mSystemInsets = new Rect();
Winson3e874742016-01-07 10:08:17 -0800108 private int mDividerSize;
Winsonbe7607a2015-10-01 17:24:51 -0700109
Winson49df4202016-01-25 17:33:34 -0800110 private ColorDrawable mBackgroundScrim = new ColorDrawable(Color.BLACK);
111 private Animator mBackgroundScrimAnimator;
112
Winson Chung9a742902015-12-11 10:25:40 -0500113 private RecentsTransitionHelper mTransitionHelper;
Winson231bc9c2016-02-09 12:31:00 -0800114 @ViewDebug.ExportedProperty(deepExport=true, prefix="touch_")
Winson Chung9a742902015-12-11 10:25:40 -0500115 private RecentsViewTouchHandler mTouchHandler;
Winson Chung9a742902015-12-11 10:25:40 -0500116 private final FlingAnimationUtils mFlingAnimationUtils;
Jorim Jaggi870ab5a2015-12-02 18:37:54 -0800117
Winson Chung303e1ff2014-03-07 15:06:19 -0800118 public RecentsView(Context context) {
Jorim Jaggi870ab5a2015-12-02 18:37:54 -0800119 this(context, null);
Winson Chung8e548f72014-06-24 14:40:53 -0700120 }
121
122 public RecentsView(Context context, AttributeSet attrs) {
123 this(context, attrs, 0);
124 }
125
126 public RecentsView(Context context, AttributeSet attrs, int defStyleAttr) {
127 this(context, attrs, defStyleAttr, 0);
128 }
129
130 public RecentsView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
131 super(context, attrs, defStyleAttr, defStyleRes);
Winsonbe7607a2015-10-01 17:24:51 -0700132 setWillNotDraw(false);
Winson3e874742016-01-07 10:08:17 -0800133
134 SystemServicesProxy ssp = Recents.getSystemServices();
Winson83c1b072015-11-09 10:48:04 -0800135 mHandler = new Handler();
136 mTransitionHelper = new RecentsTransitionHelper(getContext(), mHandler);
Winson3e874742016-01-07 10:08:17 -0800137 mDividerSize = ssp.getDockedDividerSize(context);
Winsonbe7607a2015-10-01 17:24:51 -0700138 mTouchHandler = new RecentsViewTouchHandler(this);
Jorim Jaggi870ab5a2015-12-02 18:37:54 -0800139 mFlingAnimationUtils = new FlingAnimationUtils(context, 0.3f);
Winsonc29ff002015-11-20 16:00:45 -0800140
Winson49df4202016-01-25 17:33:34 -0800141 final float cornerRadius = context.getResources().getDimensionPixelSize(
142 R.dimen.recents_task_view_rounded_corners_radius);
Winsonc29ff002015-11-20 16:00:45 -0800143 LayoutInflater inflater = LayoutInflater.from(context);
Winson91b225d2016-02-16 15:18:07 -0800144 if (RecentsDebugFlags.Static.EnableHistory) {
145 mHistoryButton = (TextView) inflater.inflate(R.layout.recents_history_button, this,
146 false);
147 mHistoryButton.setOnClickListener(new View.OnClickListener() {
148 @Override
149 public void onClick(View v) {
150 EventBus.getDefault().send(new ToggleHistoryEvent());
151 }
152 });
153 addView(mHistoryButton);
154 mHistoryButton.setClipToOutline(true);
155 mHistoryButton.setOutlineProvider(new ViewOutlineProvider() {
156 @Override
157 public void getOutline(View view, Outline outline) {
158 outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), cornerRadius);
159 }
160 });
161 }
Winson Chung9a742902015-12-11 10:25:40 -0500162 mEmptyView = inflater.inflate(R.layout.recents_empty, this, false);
163 addView(mEmptyView);
Winson49df4202016-01-25 17:33:34 -0800164
165 setBackground(mBackgroundScrim);
Winson Chungd16c5652015-01-26 16:11:07 -0800166 }
167
Winson Chungdcfa7972014-07-22 12:27:13 -0700168 /** Set/get the bsp root node */
Winson88737542016-02-17 13:27:33 -0800169 public void onResume(boolean isResumingFromVisible, TaskStack stack) {
Winson53ec42c2015-10-28 15:55:35 -0700170 RecentsConfiguration config = Recents.getConfiguration();
Winson Chung9a742902015-12-11 10:25:40 -0500171 RecentsActivityLaunchState launchState = config.getLaunchState();
Winson88737542016-02-17 13:27:33 -0800172
173 if (mTaskStackView == null || !launchState.launchedReuseTaskStackViews) {
174 isResumingFromVisible = false;
175 removeView(mTaskStackView);
176 mTaskStackView = new TaskStackView(getContext());
177 mStack = mTaskStackView.getStack();
Winson147ecaf2015-09-16 16:49:55 -0700178 addView(mTaskStackView);
Winson Chung303e1ff2014-03-07 15:06:19 -0800179 }
Winson Chung9a742902015-12-11 10:25:40 -0500180
Winson88737542016-02-17 13:27:33 -0800181 // Reset the state
182 mAwaitingFirstLayout = !isResumingFromVisible;
183 mLastTaskLaunchedWasFreeform = false;
184
185 // Update the stack
186 mTaskStackView.onResume(isResumingFromVisible);
187 mTaskStackView.setTasks(stack, isResumingFromVisible /* notifyStackChanges */);
188
189 if (isResumingFromVisible) {
190 // If we are already visible, then restore the background scrim
191 animateBackgroundScrim(DEFAULT_SCRIM_ALPHA, DEFAULT_UPDATE_SCRIM_DURATION);
Winson49df4202016-01-25 17:33:34 -0800192 } else {
Winson88737542016-02-17 13:27:33 -0800193 // If we are already occluded by the app, then set the final background scrim alpha now.
194 // Otherwise, defer until the enter animation completes to animate the scrim alpha with
195 // the tasks for the home animation.
196 if (launchState.launchedWhileDocking || launchState.launchedFromApp
197 || mStack.getTaskCount() == 0) {
198 mBackgroundScrim.setAlpha((int) (DEFAULT_SCRIM_ALPHA * 255));
199 } else {
200 mBackgroundScrim.setAlpha(0);
201 }
Winson49df4202016-01-25 17:33:34 -0800202 }
203
Winson Chung9a742902015-12-11 10:25:40 -0500204 // Update the top level view's visibilities
Winson4b057c62016-01-12 15:01:52 -0800205 if (stack.getTaskCount() > 0) {
Winson Chung9a742902015-12-11 10:25:40 -0500206 hideEmptyView();
Winsonc29ff002015-11-20 16:00:45 -0800207 } else {
Winson Chung9a742902015-12-11 10:25:40 -0500208 showEmptyView();
Winsonc29ff002015-11-20 16:00:45 -0800209 }
Winson Chung19fc1172014-07-31 18:40:03 -0700210 }
211
Winsonb1e71d02015-11-23 12:40:23 -0800212 /**
213 * Returns whether the last task launched was in the freeform stack or not.
214 */
215 public boolean isLastTaskLaunchedFreeform() {
216 return mLastTaskLaunchedWasFreeform;
217 }
218
Winsonc29ff002015-11-20 16:00:45 -0800219 /**
Winson49df4202016-01-25 17:33:34 -0800220 * Returns whether the history is visible or not.
221 */
222 public boolean isHistoryVisible() {
223 return mHistoryView != null && mHistoryView.isVisible();
224 }
225
226 /**
Winsonc29ff002015-11-20 16:00:45 -0800227 * Returns the currently set task stack.
228 */
229 public TaskStack getTaskStack() {
230 return mStack;
231 }
232
Skuhne8aa7d162015-03-20 13:40:53 -0700233 /** Gets the next task in the stack - or if the last - the top task */
234 public Task getNextTaskOrTopTask(Task taskToSearch) {
Chong Zhang0fa656b2015-08-31 15:17:21 -0700235 Task returnTask = null;
Skuhne8aa7d162015-03-20 13:40:53 -0700236 boolean found = false;
Winson147ecaf2015-09-16 16:49:55 -0700237 if (mTaskStackView != null) {
238 TaskStack stack = mTaskStackView.getStack();
Winson250608a2015-11-24 15:00:31 -0800239 ArrayList<Task> taskList = stack.getStackTasks();
Skuhne8aa7d162015-03-20 13:40:53 -0700240 // Iterate the stack views and try and find the focused task
241 for (int j = taskList.size() - 1; j >= 0; --j) {
242 Task task = taskList.get(j);
243 // Return the next task in the line.
244 if (found)
245 return task;
246 // Remember the first possible task as the top task.
247 if (returnTask == null)
248 returnTask = task;
249 if (task == taskToSearch)
250 found = true;
251 }
252 }
253 return returnTask;
254 }
255
Winson Chung1e8d71b2014-05-16 17:05:22 -0700256 /** Launches the focused task from the first stack if possible */
Winson42329522016-02-05 10:39:46 -0800257 public boolean launchFocusedTask(int logEvent) {
Winson147ecaf2015-09-16 16:49:55 -0700258 if (mTaskStackView != null) {
Winson142af422015-11-09 10:39:57 -0800259 Task task = mTaskStackView.getFocusedTask();
260 if (task != null) {
261 TaskView taskView = mTaskStackView.getChildViewForTask(task);
Winson Chung48f2cda2015-12-11 13:20:12 -0500262 EventBus.getDefault().send(new LaunchTaskEvent(taskView, task, null,
263 INVALID_STACK_ID, false));
Winson42329522016-02-05 10:39:46 -0800264
265 if (logEvent != 0) {
266 MetricsLogger.action(getContext(), logEvent,
267 task.key.getComponent().toString());
268 }
Winson142af422015-11-09 10:39:57 -0800269 return true;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700270 }
271 }
Winson Chung1e8d71b2014-05-16 17:05:22 -0700272 return false;
273 }
274
Winsona0731a12015-12-02 15:10:14 -0800275 /** Launches the task that recents was launched from if possible */
276 public boolean launchPreviousTask() {
277 if (mTaskStackView != null) {
278 TaskStack stack = mTaskStackView.getStack();
279 Task task = stack.getLaunchTarget();
280 if (task != null) {
281 TaskView taskView = mTaskStackView.getChildViewForTask(task);
Winson Chung48f2cda2015-12-11 13:20:12 -0500282 EventBus.getDefault().send(new LaunchTaskEvent(taskView, task, null,
283 INVALID_STACK_ID, false));
Winsona0731a12015-12-02 15:10:14 -0800284 return true;
285 }
286 }
287 return false;
288 }
289
Skuhne8aa7d162015-03-20 13:40:53 -0700290 /** Launches a given task. */
Filip Gruszczynskif48b5852015-10-13 10:28:22 -0700291 public boolean launchTask(Task task, Rect taskBounds, int destinationStack) {
Winson147ecaf2015-09-16 16:49:55 -0700292 if (mTaskStackView != null) {
Skuhne8aa7d162015-03-20 13:40:53 -0700293 // Iterate the stack views and try and find the given task.
Winson147ecaf2015-09-16 16:49:55 -0700294 List<TaskView> taskViews = mTaskStackView.getTaskViews();
Skuhne8aa7d162015-03-20 13:40:53 -0700295 int taskViewCount = taskViews.size();
296 for (int j = 0; j < taskViewCount; j++) {
297 TaskView tv = taskViews.get(j);
298 if (tv.getTask() == task) {
Winson Chung48f2cda2015-12-11 13:20:12 -0500299 EventBus.getDefault().send(new LaunchTaskEvent(tv, task, taskBounds,
300 destinationStack, false));
Skuhne8aa7d162015-03-20 13:40:53 -0700301 return true;
302 }
303 }
304 }
305 return false;
306 }
307
Winson Chungf7bca432014-04-30 17:11:13 -0700308 /** Adds the search bar */
Winson Chungaee097c2015-04-02 18:16:02 -0700309 public void setSearchBar(RecentsAppWidgetHostView searchBar) {
Winson Chungaf3bb692015-06-03 17:31:39 -0700310 // Remove the previous search bar if one exists
311 if (mSearchBar != null && indexOfChild(mSearchBar) > -1) {
312 removeView(mSearchBar);
313 }
314 // Add the new search bar
315 if (searchBar != null) {
316 mSearchBar = searchBar;
317 addView(mSearchBar);
Winson Chungf7bca432014-04-30 17:11:13 -0700318 }
Winson Chungecd9b302014-04-16 17:07:18 -0700319 }
320
Winson Chung772b6b12014-07-03 15:54:02 -0700321 /** Returns whether there is currently a search bar */
Winson Chungaee097c2015-04-02 18:16:02 -0700322 public boolean hasValidSearchBar() {
323 return mSearchBar != null && !mSearchBar.isReinflateRequired();
Winson Chung772b6b12014-07-03 15:54:02 -0700324 }
325
Winson Chung9a742902015-12-11 10:25:40 -0500326 /**
327 * Hides the task stack and shows the empty view.
328 */
329 public void showEmptyView() {
Winsond8b1d632016-01-04 17:51:18 -0800330 if (RecentsDebugFlags.Static.EnableSearchBar && (mSearchBar != null)) {
Winson Chung9a742902015-12-11 10:25:40 -0500331 mSearchBar.setVisibility(View.INVISIBLE);
332 }
333 mTaskStackView.setVisibility(View.INVISIBLE);
334 mEmptyView.setVisibility(View.VISIBLE);
335 mEmptyView.bringToFront();
Winson91b225d2016-02-16 15:18:07 -0800336 if (RecentsDebugFlags.Static.EnableHistory) {
337 mHistoryButton.bringToFront();
338 }
Winson Chung9a742902015-12-11 10:25:40 -0500339 }
340
341 /**
342 * Shows the task stack and hides the empty view.
343 */
344 public void hideEmptyView() {
345 mEmptyView.setVisibility(View.INVISIBLE);
346 mTaskStackView.setVisibility(View.VISIBLE);
Winsond8b1d632016-01-04 17:51:18 -0800347 if (RecentsDebugFlags.Static.EnableSearchBar && (mSearchBar != null)) {
Winson Chung9a742902015-12-11 10:25:40 -0500348 mSearchBar.setVisibility(View.VISIBLE);
349 }
350 mTaskStackView.bringToFront();
Winson Chung772b6b12014-07-03 15:54:02 -0700351 if (mSearchBar != null) {
Winson Chung012ef362014-07-31 18:36:25 -0700352 mSearchBar.bringToFront();
Winson Chung772b6b12014-07-03 15:54:02 -0700353 }
Winson91b225d2016-02-16 15:18:07 -0800354 if (RecentsDebugFlags.Static.EnableHistory) {
355 mHistoryButton.bringToFront();
356 }
Winson Chung772b6b12014-07-03 15:54:02 -0700357 }
358
Winsonbe7607a2015-10-01 17:24:51 -0700359 @Override
360 protected void onAttachedToWindow() {
361 EventBus.getDefault().register(this, RecentsActivity.EVENT_BUS_PRIORITY + 1);
Winsonc8a4cdc2016-01-19 11:30:51 -0800362 EventBus.getDefault().register(mTouchHandler, RecentsActivity.EVENT_BUS_PRIORITY + 2);
Winsonbe7607a2015-10-01 17:24:51 -0700363 super.onAttachedToWindow();
364 }
365
366 @Override
367 protected void onDetachedFromWindow() {
368 super.onDetachedFromWindow();
369 EventBus.getDefault().unregister(this);
370 EventBus.getDefault().unregister(mTouchHandler);
371 }
372
Winson Chungf7bca432014-04-30 17:11:13 -0700373 /**
374 * This is called with the full size of the window since we are handling our own insets.
375 */
Winson Chung303e1ff2014-03-07 15:06:19 -0800376 @Override
377 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Winson53ec42c2015-10-28 15:55:35 -0700378 RecentsConfiguration config = Recents.getConfiguration();
Winson Chung303e1ff2014-03-07 15:06:19 -0800379 int width = MeasureSpec.getSize(widthMeasureSpec);
380 int height = MeasureSpec.getSize(heightMeasureSpec);
Winson Chungbd912972014-03-18 14:36:35 -0700381
Winson Chungf7bca432014-04-30 17:11:13 -0700382 // Get the search bar bounds and measure the search bar layout
Winson Chungaf3bb692015-06-03 17:31:39 -0700383 Rect searchBarSpaceBounds = new Rect();
Winson Chungecd9b302014-04-16 17:07:18 -0700384 if (mSearchBar != null) {
Winson53ec42c2015-10-28 15:55:35 -0700385 config.getSearchBarBounds(new Rect(0, 0, width, height), mSystemInsets.top,
Winson147ecaf2015-09-16 16:49:55 -0700386 searchBarSpaceBounds);
Winson Chungf7bca432014-04-30 17:11:13 -0700387 mSearchBar.measure(
388 MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.width(), MeasureSpec.EXACTLY),
389 MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.height(), MeasureSpec.EXACTLY));
Winson Chungecd9b302014-04-16 17:07:18 -0700390 }
391
Winson Chungf7bca432014-04-30 17:11:13 -0700392 Rect taskStackBounds = new Rect();
Winson53ec42c2015-10-28 15:55:35 -0700393 config.getTaskStackBounds(new Rect(0, 0, width, height), mSystemInsets.top,
Winson35f30502015-09-28 11:24:36 -0700394 mSystemInsets.right, searchBarSpaceBounds, taskStackBounds);
Winson147ecaf2015-09-16 16:49:55 -0700395 if (mTaskStackView != null && mTaskStackView.getVisibility() != GONE) {
Winson88f00ab2015-10-05 17:24:00 -0700396 mTaskStackView.setTaskStackBounds(taskStackBounds, mSystemInsets);
Winson147ecaf2015-09-16 16:49:55 -0700397 mTaskStackView.measure(widthMeasureSpec, heightMeasureSpec);
Winson Chung303e1ff2014-03-07 15:06:19 -0800398 }
399
Winson49df4202016-01-25 17:33:34 -0800400 // Measure the empty view to the full size of the screen
401 if (mEmptyView.getVisibility() != GONE) {
402 measureChild(mEmptyView, MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
403 MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
404 }
Winson Chung9a742902015-12-11 10:25:40 -0500405
Winson91b225d2016-02-16 15:18:07 -0800406 if (RecentsDebugFlags.Static.EnableHistory) {
407 // Measure the history view
408 if (mHistoryView != null && mHistoryView.getVisibility() != GONE) {
409 measureChild(mHistoryView, MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
410 MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
411 }
Winson49df4202016-01-25 17:33:34 -0800412
Winson91b225d2016-02-16 15:18:07 -0800413 // Measure the history button within the constraints of the space above the stack
414 Rect historyButtonRect = mTaskStackView.mLayoutAlgorithm.mHistoryButtonRect;
415 measureChild(mHistoryButton,
Winson214f0f02016-01-26 13:37:37 -0800416 MeasureSpec.makeMeasureSpec(historyButtonRect.width(), MeasureSpec.AT_MOST),
417 MeasureSpec.makeMeasureSpec(historyButtonRect.height(), MeasureSpec.AT_MOST));
Winson91b225d2016-02-16 15:18:07 -0800418 if (mHistoryClearAllButton != null && mHistoryClearAllButton.getVisibility() != GONE) {
419 measureChild(mHistoryClearAllButton,
420 MeasureSpec.makeMeasureSpec(historyButtonRect.width(), MeasureSpec.AT_MOST),
421 MeasureSpec.makeMeasureSpec(historyButtonRect.height(), MeasureSpec.AT_MOST));
422 }
Winson214f0f02016-01-26 13:37:37 -0800423 }
Winson Chung9a742902015-12-11 10:25:40 -0500424
Winson Chung303e1ff2014-03-07 15:06:19 -0800425 setMeasuredDimension(width, height);
426 }
427
Winson Chungf7bca432014-04-30 17:11:13 -0700428 /**
429 * This is called with the full size of the window since we are handling our own insets.
430 */
Winson Chung303e1ff2014-03-07 15:06:19 -0800431 @Override
432 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
Winson53ec42c2015-10-28 15:55:35 -0700433 RecentsConfiguration config = Recents.getConfiguration();
434
Winson Chungf7bca432014-04-30 17:11:13 -0700435 // Get the search bar bounds so that we lay it out
Winson147ecaf2015-09-16 16:49:55 -0700436 Rect measuredRect = new Rect(0, 0, getMeasuredWidth(), getMeasuredHeight());
437 Rect searchBarSpaceBounds = new Rect();
Winson Chungecd9b302014-04-16 17:07:18 -0700438 if (mSearchBar != null) {
Winson53ec42c2015-10-28 15:55:35 -0700439 config.getSearchBarBounds(measuredRect,
Winson35f30502015-09-28 11:24:36 -0700440 mSystemInsets.top, searchBarSpaceBounds);
Winson Chungdcfa7972014-07-22 12:27:13 -0700441 mSearchBar.layout(searchBarSpaceBounds.left, searchBarSpaceBounds.top,
442 searchBarSpaceBounds.right, searchBarSpaceBounds.bottom);
Winson Chungecd9b302014-04-16 17:07:18 -0700443 }
444
Winson147ecaf2015-09-16 16:49:55 -0700445 if (mTaskStackView != null && mTaskStackView.getVisibility() != GONE) {
446 mTaskStackView.layout(left, top, left + getMeasuredWidth(), top + getMeasuredHeight());
Winson Chung303e1ff2014-03-07 15:06:19 -0800447 }
Winsonbe7607a2015-10-01 17:24:51 -0700448
Winson Chung9a742902015-12-11 10:25:40 -0500449 // Layout the empty view
Winson49df4202016-01-25 17:33:34 -0800450 if (mEmptyView.getVisibility() != GONE) {
451 mEmptyView.layout(left, top, right, bottom);
452 }
Winson Chung9a742902015-12-11 10:25:40 -0500453
Winson91b225d2016-02-16 15:18:07 -0800454 if (RecentsDebugFlags.Static.EnableHistory) {
455 // Layout the history view
456 if (mHistoryView != null && mHistoryView.getVisibility() != GONE) {
457 mHistoryView.layout(left, top, right, bottom);
458 }
Winson49df4202016-01-25 17:33:34 -0800459
Winson91b225d2016-02-16 15:18:07 -0800460 // Layout the history button such that its drawable is start-aligned with the stack,
461 // vertically centered in the available space above the stack
462 Rect historyButtonRect = mTaskStackView.mLayoutAlgorithm.mHistoryButtonRect;
463 int historyLeft = isLayoutRtl()
464 ? historyButtonRect.right + mHistoryButton.getPaddingStart()
465 - mHistoryButton.getMeasuredWidth()
466 : historyButtonRect.left - mHistoryButton.getPaddingStart();
467 int historyTop = historyButtonRect.top +
468 (historyButtonRect.height() - mHistoryButton.getMeasuredHeight()) / 2;
469 mHistoryButton.layout(historyLeft, historyTop,
470 historyLeft + mHistoryButton.getMeasuredWidth(),
471 historyTop + mHistoryButton.getMeasuredHeight());
Winsonc29ff002015-11-20 16:00:45 -0800472
Winson91b225d2016-02-16 15:18:07 -0800473 // Layout the history clear all button such that it is end-aligned with the stack,
474 // vertically centered in the available space above the stack
475 if (mHistoryClearAllButton != null && mHistoryClearAllButton.getVisibility() != GONE) {
476 int clearAllLeft = isLayoutRtl()
477 ? historyButtonRect.left - mHistoryClearAllButton.getPaddingStart()
478 : historyButtonRect.right + mHistoryClearAllButton.getPaddingStart()
479 - mHistoryClearAllButton.getMeasuredWidth();
480 int clearAllTop = historyButtonRect.top +
481 (historyButtonRect.height() - mHistoryClearAllButton.getMeasuredHeight()) /
482 2;
483 mHistoryClearAllButton.layout(clearAllLeft, clearAllTop,
484 clearAllLeft + mHistoryClearAllButton.getMeasuredWidth(),
485 clearAllTop + mHistoryClearAllButton.getMeasuredHeight());
486 }
Winson214f0f02016-01-26 13:37:37 -0800487 }
488
Winsonb1e71d02015-11-23 12:40:23 -0800489 if (mAwaitingFirstLayout) {
490 mAwaitingFirstLayout = false;
491
492 // If launched via dragging from the nav bar, then we should translate the whole view
493 // down offscreen
494 RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState();
495 if (launchState.launchedViaDragGesture) {
496 setTranslationY(getMeasuredHeight());
Jorim Jaggi0ca88262015-12-07 17:15:16 -0800497 } else {
498 setTranslationY(0f);
Winsonb1e71d02015-11-23 12:40:23 -0800499 }
500 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800501 }
502
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700503 @Override
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700504 public WindowInsets onApplyWindowInsets(WindowInsets insets) {
Winson35f30502015-09-28 11:24:36 -0700505 mSystemInsets.set(insets.getSystemWindowInsets());
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700506 requestLayout();
Winsonc29ff002015-11-20 16:00:45 -0800507 return insets;
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700508 }
509
Winsonbe7607a2015-10-01 17:24:51 -0700510 @Override
511 public boolean onInterceptTouchEvent(MotionEvent ev) {
512 return mTouchHandler.onInterceptTouchEvent(ev);
513 }
514
515 @Override
516 public boolean onTouchEvent(MotionEvent ev) {
517 return mTouchHandler.onTouchEvent(ev);
518 }
519
520 @Override
Winsonbe8e6962016-02-01 14:27:52 -0800521 public void onDrawForeground(Canvas canvas) {
522 super.onDrawForeground(canvas);
523
Winson036693c2016-01-14 17:16:06 -0800524 ArrayList<TaskStack.DockState> visDockStates = mTouchHandler.getVisibleDockStates();
525 for (int i = visDockStates.size() - 1; i >= 0; i--) {
526 Drawable d = visDockStates.get(i).viewState.dockAreaOverlay;
Winson882072b2015-10-12 11:26:33 -0700527 if (d.getAlpha() > 0) {
528 d.draw(canvas);
529 }
Winsonbe7607a2015-10-01 17:24:51 -0700530 }
531 }
532
Winson4165d3362015-10-10 14:40:35 -0700533 @Override
534 protected boolean verifyDrawable(Drawable who) {
Winson036693c2016-01-14 17:16:06 -0800535 ArrayList<TaskStack.DockState> visDockStates = mTouchHandler.getVisibleDockStates();
536 for (int i = visDockStates.size() - 1; i >= 0; i--) {
537 Drawable d = visDockStates.get(i).viewState.dockAreaOverlay;
Winson882072b2015-10-12 11:26:33 -0700538 if (d == who) {
539 return true;
540 }
541 }
542 return super.verifyDrawable(who);
Winson4165d3362015-10-10 14:40:35 -0700543 }
544
Winsonbe7607a2015-10-01 17:24:51 -0700545 /**** EventBus Events ****/
546
Winson Chung48f2cda2015-12-11 13:20:12 -0500547 public final void onBusEvent(LaunchTaskEvent event) {
548 mLastTaskLaunchedWasFreeform = event.task.isFreeformTask();
549 mTransitionHelper.launchTaskFromRecents(mStack, event.task, mTaskStackView, event.taskView,
550 event.screenPinningRequested, event.targetTaskBounds, event.targetTaskStack);
551 }
552
Winsonef064132016-01-05 12:11:31 -0800553 public final void onBusEvent(DismissRecentsToHomeAnimationStarted event) {
Winson50448632016-02-01 18:04:59 -0800554 int taskViewExitToHomeDuration = TaskStackAnimationHelper.EXIT_TO_HOME_TRANSLATION_DURATION;
Winson91b225d2016-02-16 15:18:07 -0800555 if (RecentsDebugFlags.Static.EnableHistory) {
556 // Hide the history button
557 hideHistoryButton(taskViewExitToHomeDuration, false /* translate */);
558 }
Winson49df4202016-01-25 17:33:34 -0800559 animateBackgroundScrim(0f, taskViewExitToHomeDuration);
Winsonef064132016-01-05 12:11:31 -0800560 }
561
Winsonbe7607a2015-10-01 17:24:51 -0700562 public final void onBusEvent(DragStartEvent event) {
Winson882072b2015-10-12 11:26:33 -0700563 updateVisibleDockRegions(mTouchHandler.getDockStatesForCurrentOrientation(),
Winson3e874742016-01-07 10:08:17 -0800564 true /* isDefaultDockState */, TaskStack.DockState.NONE.viewState.dockAreaAlpha,
565 true /* animateAlpha */, false /* animateBounds */);
Winsonbe7607a2015-10-01 17:24:51 -0700566 }
567
Winsoneca4ab62015-11-04 10:50:28 -0800568 public final void onBusEvent(DragDropTargetChangedEvent event) {
569 if (event.dropTarget == null || !(event.dropTarget instanceof TaskStack.DockState)) {
Winson882072b2015-10-12 11:26:33 -0700570 updateVisibleDockRegions(mTouchHandler.getDockStatesForCurrentOrientation(),
Winson3e874742016-01-07 10:08:17 -0800571 true /* isDefaultDockState */, TaskStack.DockState.NONE.viewState.dockAreaAlpha,
572 true /* animateAlpha */, true /* animateBounds */);
Winson882072b2015-10-12 11:26:33 -0700573 } else {
Winsoneca4ab62015-11-04 10:50:28 -0800574 final TaskStack.DockState dockState = (TaskStack.DockState) event.dropTarget;
Winson3e874742016-01-07 10:08:17 -0800575 updateVisibleDockRegions(new TaskStack.DockState[] {dockState},
576 false /* isDefaultDockState */, -1, true /* animateAlpha */,
577 true /* animateBounds */);
Winson882072b2015-10-12 11:26:33 -0700578 }
Winsonbe7607a2015-10-01 17:24:51 -0700579 }
580
581 public final void onBusEvent(final DragEndEvent event) {
Winson479f7442015-11-25 15:16:27 -0800582 // Handle the case where we drop onto a dock region
583 if (event.dropTarget instanceof TaskStack.DockState) {
Winson3e874742016-01-07 10:08:17 -0800584 final TaskStack.DockState dockState = (TaskStack.DockState) event.dropTarget;
585
586 // Hide the dock region
587 updateVisibleDockRegions(null, false /* isDefaultDockState */, -1,
588 false /* animateAlpha */, false /* animateBounds */);
589
Winsonf24f2162016-01-05 12:11:55 -0800590 TaskStackLayoutAlgorithm stackLayout = mTaskStackView.getStackAlgorithm();
591 TaskStackViewScroller stackScroller = mTaskStackView.getScroller();
592 TaskViewTransform tmpTransform = new TaskViewTransform();
Winsoneca4ab62015-11-04 10:50:28 -0800593
Winson3e874742016-01-07 10:08:17 -0800594 // We translated the view but we need to animate it back from the current layout-space
595 // rect to its final layout-space rect
596 int x = (int) event.taskView.getTranslationX();
597 int y = (int) event.taskView.getTranslationY();
598 Rect taskViewRect = new Rect(event.taskView.getLeft(), event.taskView.getTop(),
599 event.taskView.getRight(), event.taskView.getBottom());
600 taskViewRect.offset(x, y);
601 event.taskView.setTranslationX(0);
602 event.taskView.setTranslationY(0);
603 event.taskView.setLeftTopRightBottom(taskViewRect.left, taskViewRect.top,
604 taskViewRect.right, taskViewRect.bottom);
605
Winsonf24f2162016-01-05 12:11:55 -0800606 // Remove the task view after it is docked
Winson8aa99592016-01-19 15:07:07 -0800607 mTaskStackView.updateLayoutAlgorithm(false /* boundScroll */);
Winsonf24f2162016-01-05 12:11:55 -0800608 stackLayout.getStackTransform(event.task, stackScroller.getStackScroll(), tmpTransform,
609 null);
Winson3e874742016-01-07 10:08:17 -0800610 tmpTransform.alpha = 0;
611 tmpTransform.scale = 1f;
612 tmpTransform.rect.set(taskViewRect);
Winsonf24f2162016-01-05 12:11:55 -0800613 mTaskStackView.updateTaskViewToTransform(event.taskView, tmpTransform,
Winsonbe8e6962016-02-01 14:27:52 -0800614 new AnimationProps(125, Interpolators.ALPHA_OUT,
Winsonf24f2162016-01-05 12:11:55 -0800615 new AnimatorListenerAdapter() {
616 @Override
617 public void onAnimationEnd(Animator animation) {
Winson3e874742016-01-07 10:08:17 -0800618 // Dock the task and launch it
619 SystemServicesProxy ssp = Recents.getSystemServices();
Filip Gruszczynskif298e902016-01-18 08:59:45 -0800620 ssp.startTaskInDockedMode(getContext(), event.taskView,
621 event.task.key.id, dockState.createMode);
Winson3e874742016-01-07 10:08:17 -0800622
Winson8aa99592016-01-19 15:07:07 -0800623 // Animate the stack accordingly
Winsonbe8e6962016-02-01 14:27:52 -0800624 AnimationProps stackAnim = new AnimationProps(
Winson8aa99592016-01-19 15:07:07 -0800625 TaskStackView.DEFAULT_SYNC_STACK_DURATION,
Winsonc0d70582016-01-29 10:24:39 -0800626 Interpolators.FAST_OUT_SLOW_IN);
Winson8aa99592016-01-19 15:07:07 -0800627 mTaskStackView.getStack().removeTask(event.task, stackAnim);
Winsonf24f2162016-01-05 12:11:55 -0800628 }
629 }));
Winsona0a8ae42015-12-01 10:43:02 -0800630
Chris Wrenf6e9228b2016-01-26 18:04:35 -0500631 MetricsLogger.action(mContext, MetricsEvent.ACTION_WINDOW_DOCK_DRAG_DROP);
Winson3e874742016-01-07 10:08:17 -0800632 } else {
633 // Animate the overlay alpha back to 0
634 updateVisibleDockRegions(null, true /* isDefaultDockState */, -1,
635 true /* animateAlpha */, false /* animateBounds */);
Winsonbe7607a2015-10-01 17:24:51 -0700636 }
637 }
Winson4165d3362015-10-10 14:40:35 -0700638
Jorim Jaggidd98d412015-11-18 15:57:38 -0800639 public final void onBusEvent(DraggingInRecentsEvent event) {
Jorim Jaggi54b1a6d2015-11-24 17:48:26 -0800640 if (mTaskStackView.getTaskViews().size() > 0) {
641 setTranslationY(event.distanceFromTop - mTaskStackView.getTaskViews().get(0).getY());
642 }
Jorim Jaggidd98d412015-11-18 15:57:38 -0800643 }
644
645 public final void onBusEvent(DraggingInRecentsEndedEvent event) {
Jorim Jaggi870ab5a2015-12-02 18:37:54 -0800646 ViewPropertyAnimator animator = animate();
Jorim Jaggi8fccfe22015-12-03 16:58:08 -0800647 if (event.velocity > mFlingAnimationUtils.getMinVelocityPxPerSecond()) {
Jorim Jaggi870ab5a2015-12-02 18:37:54 -0800648 animator.translationY(getHeight());
649 animator.withEndAction(new Runnable() {
650 @Override
651 public void run() {
652 WindowManagerProxy.getInstance().maximizeDockedStack();
653 }
654 });
655 mFlingAnimationUtils.apply(animator, getTranslationY(), getHeight(), event.velocity);
656 } else {
657 animator.translationY(0f);
658 animator.setListener(null);
659 mFlingAnimationUtils.apply(animator, getTranslationY(), 0, event.velocity);
660 }
661 animator.start();
Jorim Jaggidd98d412015-11-18 15:57:38 -0800662 }
663
Winson49df4202016-01-25 17:33:34 -0800664 public final void onBusEvent(EnterRecentsWindowAnimationCompletedEvent event) {
665 RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState();
Winsone693aaf2016-03-01 12:05:59 -0800666 if (!launchState.launchedWhileDocking && !launchState.launchedFromApp
Jorim Jaggie161f082016-02-05 14:26:16 -0800667 && mStack.getTaskCount() > 0) {
Winson50448632016-02-01 18:04:59 -0800668 animateBackgroundScrim(DEFAULT_SCRIM_ALPHA,
669 TaskStackAnimationHelper.ENTER_FROM_HOME_TRANSLATION_DURATION);
Winson49df4202016-01-25 17:33:34 -0800670 }
671 }
672
673 public final void onBusEvent(UpdateBackgroundScrimEvent event) {
674 animateBackgroundScrim(event.alpha, DEFAULT_UPDATE_SCRIM_DURATION);
675 }
676
677 public final void onBusEvent(ResetBackgroundScrimEvent event) {
678 animateBackgroundScrim(DEFAULT_SCRIM_ALPHA, DEFAULT_UPDATE_SCRIM_DURATION);
679 }
680
Winson49df4202016-01-25 17:33:34 -0800681 public final void onBusEvent(ToggleHistoryEvent event) {
Winson91b225d2016-02-16 15:18:07 -0800682 if (!RecentsDebugFlags.Static.EnableHistory) {
683 return;
684 }
685
Winson49df4202016-01-25 17:33:34 -0800686 if (mHistoryView != null && mHistoryView.isVisible()) {
687 EventBus.getDefault().send(new HideHistoryEvent(true /* animate */));
688 } else {
689 EventBus.getDefault().send(new ShowHistoryEvent());
690 }
691 }
692
693 public final void onBusEvent(ShowHistoryEvent event) {
Winson91b225d2016-02-16 15:18:07 -0800694 if (!RecentsDebugFlags.Static.EnableHistory) {
695 return;
696 }
697
Winson49df4202016-01-25 17:33:34 -0800698 if (mHistoryView == null) {
Winson214f0f02016-01-26 13:37:37 -0800699 LayoutInflater inflater = LayoutInflater.from(getContext());
700 mHistoryView = (RecentsHistoryView) inflater.inflate(R.layout.recents_history, this,
701 false);
Winson49df4202016-01-25 17:33:34 -0800702 addView(mHistoryView);
703
Winson214f0f02016-01-26 13:37:37 -0800704 final float cornerRadius = getResources().getDimensionPixelSize(
705 R.dimen.recents_task_view_rounded_corners_radius);
706 mHistoryClearAllButton = (TextView) inflater.inflate(
707 R.layout.recents_history_clear_all_button, this, false);
708 mHistoryClearAllButton.setOnClickListener(new View.OnClickListener() {
709 @Override
710 public void onClick(View v) {
711 EventBus.getDefault().send(new ClearHistoryEvent());
712 }
713 });
714 mHistoryClearAllButton.setClipToOutline(true);
715 mHistoryClearAllButton.setOutlineProvider(new ViewOutlineProvider() {
716 @Override
717 public void getOutline(View view, Outline outline) {
718 outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), cornerRadius);
719 }
720 });
721 addView(mHistoryClearAllButton);
722
Winson49df4202016-01-25 17:33:34 -0800723 // Since this history view is inflated by a view stub after the insets have already
724 // been applied, we have to set them ourselves initial from the insets that were last
725 // provided.
726 mHistoryView.setSystemInsets(mSystemInsets);
727 mHistoryView.setHeaderHeight(mHistoryButton.getMeasuredHeight());
728 mHistoryButton.bringToFront();
Winson214f0f02016-01-26 13:37:37 -0800729 mHistoryClearAllButton.bringToFront();
Winson49df4202016-01-25 17:33:34 -0800730 }
731
732 // Animate the empty view in parallel with the history view (the task view animations are
733 // handled in TaskStackView)
734 Rect stackRect = mTaskStackView.mLayoutAlgorithm.mStackRect;
735 if (mEmptyView.getVisibility() == View.VISIBLE) {
736 int historyTransitionDuration = getResources().getInteger(
737 R.integer.recents_history_transition_duration);
738 mEmptyView.animate()
739 .alpha(0f)
Winson214f0f02016-01-26 13:37:37 -0800740 .translationY(stackRect.height() / 2)
Winson49df4202016-01-25 17:33:34 -0800741 .setDuration(historyTransitionDuration)
Winsonc0d70582016-01-29 10:24:39 -0800742 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
Winson49df4202016-01-25 17:33:34 -0800743 .withEndAction(new Runnable() {
744 @Override
745 public void run() {
746 mEmptyView.setVisibility(View.INVISIBLE);
747 }
748 })
749 .start();
750 }
751
Winson214f0f02016-01-26 13:37:37 -0800752 mHistoryView.show(mStack, stackRect.height(), mHistoryClearAllButton);
Winson49df4202016-01-25 17:33:34 -0800753 }
754
755 public final void onBusEvent(HideHistoryEvent event) {
Winson91b225d2016-02-16 15:18:07 -0800756 if (!RecentsDebugFlags.Static.EnableHistory) {
757 return;
758 }
759
Winson49df4202016-01-25 17:33:34 -0800760 // Animate the empty view in parallel with the history view (the task view animations are
761 // handled in TaskStackView)
762 Rect stackRect = mTaskStackView.mLayoutAlgorithm.mStackRect;
763 if (mStack.getTaskCount() == 0) {
764 int historyTransitionDuration = getResources().getInteger(
765 R.integer.recents_history_transition_duration);
766 mEmptyView.setVisibility(View.VISIBLE);
767 mEmptyView.animate()
768 .alpha(1f)
769 .translationY(0)
770 .setDuration(historyTransitionDuration)
Winsonc0d70582016-01-29 10:24:39 -0800771 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
Winson49df4202016-01-25 17:33:34 -0800772 .start();
773 }
774
Winson214f0f02016-01-26 13:37:37 -0800775 mHistoryView.hide(event.animate, stackRect.height(), mHistoryClearAllButton);
Winson49df4202016-01-25 17:33:34 -0800776 }
777
778 public final void onBusEvent(ShowHistoryButtonEvent event) {
Winson91b225d2016-02-16 15:18:07 -0800779 if (!RecentsDebugFlags.Static.EnableHistory) {
780 return;
781 }
782
Winson49df4202016-01-25 17:33:34 -0800783 showHistoryButton(150, event.translate);
784 }
785
786 public final void onBusEvent(HideHistoryButtonEvent event) {
Winson91b225d2016-02-16 15:18:07 -0800787 if (!RecentsDebugFlags.Static.EnableHistory) {
788 return;
789 }
790
Winson49df4202016-01-25 17:33:34 -0800791 hideHistoryButton(100, true /* translate */);
792 }
793
Winsonc29ff002015-11-20 16:00:45 -0800794 /**
795 * Shows the history button.
796 */
Winson49df4202016-01-25 17:33:34 -0800797 private void showHistoryButton(final int duration, final boolean translate) {
Winson91b225d2016-02-16 15:18:07 -0800798 if (!RecentsDebugFlags.Static.EnableHistory) {
799 return;
800 }
801
Winson49df4202016-01-25 17:33:34 -0800802 final ReferenceCountedTrigger postAnimationTrigger = new ReferenceCountedTrigger();
Winsonf24f2162016-01-05 12:11:55 -0800803 if (mHistoryButton.getVisibility() == View.INVISIBLE) {
804 mHistoryButton.setVisibility(View.VISIBLE);
805 mHistoryButton.setAlpha(0f);
Winson49df4202016-01-25 17:33:34 -0800806 if (translate) {
807 mHistoryButton.setTranslationY(-mHistoryButton.getMeasuredHeight() * 0.25f);
Winson214f0f02016-01-26 13:37:37 -0800808 } else {
809 mHistoryButton.setTranslationY(0f);
Winson49df4202016-01-25 17:33:34 -0800810 }
811 postAnimationTrigger.addLastDecrementRunnable(new Runnable() {
Winsonf24f2162016-01-05 12:11:55 -0800812 @Override
813 public void run() {
Winson49df4202016-01-25 17:33:34 -0800814 if (translate) {
815 mHistoryButton.animate()
816 .translationY(0f);
817 }
Winsonf24f2162016-01-05 12:11:55 -0800818 mHistoryButton.animate()
819 .alpha(1f)
820 .setDuration(duration)
Winsonc0d70582016-01-29 10:24:39 -0800821 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
Winsonf24f2162016-01-05 12:11:55 -0800822 .withLayer()
823 .start();
824 }
825 });
826 }
Winson49df4202016-01-25 17:33:34 -0800827 postAnimationTrigger.flushLastDecrementRunnables();
Winsonc29ff002015-11-20 16:00:45 -0800828 }
829
830 /**
831 * Hides the history button.
832 */
Winson49df4202016-01-25 17:33:34 -0800833 private void hideHistoryButton(int duration, boolean translate) {
Winson91b225d2016-02-16 15:18:07 -0800834 if (!RecentsDebugFlags.Static.EnableHistory) {
835 return;
836 }
837
Winson49df4202016-01-25 17:33:34 -0800838 final ReferenceCountedTrigger postAnimationTrigger = new ReferenceCountedTrigger();
839 hideHistoryButton(duration, translate, postAnimationTrigger);
Winson Chungaaeaac12015-12-16 16:49:36 -0500840 postAnimationTrigger.flushLastDecrementRunnables();
Winson Chung9a742902015-12-11 10:25:40 -0500841 }
842
Winson49df4202016-01-25 17:33:34 -0800843 /**
844 * Hides the history button.
845 */
846 private void hideHistoryButton(int duration, boolean translate,
847 final ReferenceCountedTrigger postAnimationTrigger) {
Winson91b225d2016-02-16 15:18:07 -0800848 if (!RecentsDebugFlags.Static.EnableHistory) {
849 return;
850 }
851
Winsonf24f2162016-01-05 12:11:55 -0800852 if (mHistoryButton.getVisibility() == View.VISIBLE) {
Winson49df4202016-01-25 17:33:34 -0800853 if (translate) {
854 mHistoryButton.animate()
855 .translationY(-mHistoryButton.getMeasuredHeight() * 0.25f);
856 }
Winsonf24f2162016-01-05 12:11:55 -0800857 mHistoryButton.animate()
858 .alpha(0f)
859 .setDuration(duration)
Winsonc0d70582016-01-29 10:24:39 -0800860 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
Winsonf24f2162016-01-05 12:11:55 -0800861 .withEndAction(new Runnable() {
862 @Override
863 public void run() {
864 mHistoryButton.setVisibility(View.INVISIBLE);
Winson49df4202016-01-25 17:33:34 -0800865 postAnimationTrigger.decrement();
Winsonf24f2162016-01-05 12:11:55 -0800866 }
867 })
868 .withLayer()
869 .start();
Winson49df4202016-01-25 17:33:34 -0800870 postAnimationTrigger.increment();
Winsonf24f2162016-01-05 12:11:55 -0800871 }
Winsonc29ff002015-11-20 16:00:45 -0800872 }
873
Winson4165d3362015-10-10 14:40:35 -0700874 /**
875 * Updates the dock region to match the specified dock state.
876 */
Winson3e874742016-01-07 10:08:17 -0800877 private void updateVisibleDockRegions(TaskStack.DockState[] newDockStates,
878 boolean isDefaultDockState, int overrideAlpha, boolean animateAlpha,
879 boolean animateBounds) {
Winsonc5fd3502016-01-18 15:18:37 -0800880 ArraySet<TaskStack.DockState> newDockStatesSet = Utilities.arrayToSet(newDockStates,
881 new ArraySet<TaskStack.DockState>());
Winson036693c2016-01-14 17:16:06 -0800882 ArrayList<TaskStack.DockState> visDockStates = mTouchHandler.getVisibleDockStates();
883 for (int i = visDockStates.size() - 1; i >= 0; i--) {
884 TaskStack.DockState dockState = visDockStates.get(i);
Winson882072b2015-10-12 11:26:33 -0700885 TaskStack.DockState.ViewState viewState = dockState.viewState;
886 if (newDockStates == null || !newDockStatesSet.contains(dockState)) {
887 // This is no longer visible, so hide it
Winson3e874742016-01-07 10:08:17 -0800888 viewState.startAnimation(null, 0, DOCK_AREA_OVERLAY_TRANSITION_DURATION,
Winsonc0d70582016-01-29 10:24:39 -0800889 Interpolators.ALPHA_OUT, animateAlpha, animateBounds);
Winson882072b2015-10-12 11:26:33 -0700890 } else {
891 // This state is now visible, update the bounds and show it
892 int alpha = (overrideAlpha != -1 ? overrideAlpha : viewState.dockAreaAlpha);
Winson3e874742016-01-07 10:08:17 -0800893 Rect bounds = isDefaultDockState
894 ? dockState.getPreDockedBounds(getMeasuredWidth(), getMeasuredHeight())
895 : dockState.getDockedBounds(getMeasuredWidth(), getMeasuredHeight(),
896 mDividerSize, mSystemInsets, getResources());
897 if (viewState.dockAreaOverlay.getCallback() != this) {
898 viewState.dockAreaOverlay.setCallback(this);
899 viewState.dockAreaOverlay.setBounds(bounds);
900 }
901 viewState.startAnimation(bounds, alpha, DOCK_AREA_OVERLAY_TRANSITION_DURATION,
Winsonc0d70582016-01-29 10:24:39 -0800902 Interpolators.ALPHA_IN, animateAlpha, animateBounds);
Winson882072b2015-10-12 11:26:33 -0700903 }
Winson4165d3362015-10-10 14:40:35 -0700904 }
Winson4165d3362015-10-10 14:40:35 -0700905 }
Filip Gruszczynski14b4e572015-11-03 15:53:55 -0800906
Winson49df4202016-01-25 17:33:34 -0800907 /**
908 * Animates the background scrim to the given {@param alpha}.
909 */
910 private void animateBackgroundScrim(float alpha, int duration) {
911 Utilities.cancelAnimationWithoutCallbacks(mBackgroundScrimAnimator);
912 int alphaInt = (int) (alpha * 255);
913 mBackgroundScrimAnimator = ObjectAnimator.ofInt(mBackgroundScrim, Utilities.DRAWABLE_ALPHA,
914 mBackgroundScrim.getAlpha(), alphaInt);
915 mBackgroundScrimAnimator.setDuration(duration);
916 mBackgroundScrimAnimator.setInterpolator(alphaInt > mBackgroundScrim.getAlpha()
Winsonc0d70582016-01-29 10:24:39 -0800917 ? Interpolators.ALPHA_OUT
918 : Interpolators.ALPHA_IN);
Winson49df4202016-01-25 17:33:34 -0800919 mBackgroundScrimAnimator.start();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -0800920 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800921}