blob: 5e113b997bce40eeaf2ce0b02d1db8a5fe75ae3a [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
Winsonf24f2162016-01-05 12:11:55 -080019import android.animation.Animator;
20import android.animation.AnimatorListenerAdapter;
Winson49df4202016-01-25 17:33:34 -080021import android.animation.ObjectAnimator;
Winson Chung303e1ff2014-03-07 15:06:19 -080022import android.content.Context;
Winson Chung303e1ff2014-03-07 15:06:19 -080023import android.graphics.Canvas;
Winson49df4202016-01-25 17:33:34 -080024import android.graphics.Color;
25import android.graphics.Outline;
Winson Chung303e1ff2014-03-07 15:06:19 -080026import android.graphics.Rect;
Winson49df4202016-01-25 17:33:34 -080027import android.graphics.drawable.ColorDrawable;
Winson4165d3362015-10-10 14:40:35 -070028import android.graphics.drawable.Drawable;
Winson83c1b072015-11-09 10:48:04 -080029import android.os.Handler;
Winson882072b2015-10-12 11:26:33 -070030import android.util.ArraySet;
Winson Chung8e548f72014-06-24 14:40:53 -070031import android.util.AttributeSet;
Winson Chungecd9b302014-04-16 17:07:18 -070032import android.view.LayoutInflater;
Winsonbe7607a2015-10-01 17:24:51 -070033import android.view.MotionEvent;
Winsonc29ff002015-11-20 16:00:45 -080034import android.view.View;
Winson49df4202016-01-25 17:33:34 -080035import android.view.ViewOutlineProvider;
Jorim Jaggi870ab5a2015-12-02 18:37:54 -080036import android.view.ViewPropertyAnimator;
Winson Chung653f70c22014-05-19 14:49:42 -070037import android.view.WindowInsets;
Winson Chung303e1ff2014-03-07 15:06:19 -080038import android.widget.FrameLayout;
Winson Chungde750de2015-12-11 10:26:06 -050039import android.widget.TextView;
Chris Wrenf6e9228b2016-01-26 18:04:35 -050040
Winsondc8de842016-01-06 15:21:41 -080041import com.android.internal.logging.MetricsLogger;
Chris Wrenf6e9228b2016-01-26 18:04:35 -050042import com.android.internal.logging.MetricsProto.MetricsEvent;
Winsonc0d70582016-01-29 10:24:39 -080043import com.android.systemui.Interpolators;
Winson Chungd16c5652015-01-26 16:11:07 -080044import com.android.systemui.R;
Winsone7f138c2015-10-22 16:15:21 -070045import com.android.systemui.recents.Recents;
Winsonbe7607a2015-10-01 17:24:51 -070046import com.android.systemui.recents.RecentsActivity;
Winsonb1e71d02015-11-23 12:40:23 -080047import com.android.systemui.recents.RecentsActivityLaunchState;
Winson Chungaee097c2015-04-02 18:16:02 -070048import com.android.systemui.recents.RecentsAppWidgetHostView;
Winson Chung303e1ff2014-03-07 15:06:19 -080049import com.android.systemui.recents.RecentsConfiguration;
Winsonc29ff002015-11-20 16:00:45 -080050import com.android.systemui.recents.RecentsDebugFlags;
Winson2536c7e2015-10-01 15:49:31 -070051import com.android.systemui.recents.events.EventBus;
Winson214f0f02016-01-26 13:37:37 -080052import com.android.systemui.recents.events.activity.ClearHistoryEvent;
Winson412e1802015-10-20 16:57:57 -070053import com.android.systemui.recents.events.activity.DismissRecentsToHomeAnimationStarted;
Winson49df4202016-01-25 17:33:34 -080054import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationCompletedEvent;
Winsonc29ff002015-11-20 16:00:45 -080055import com.android.systemui.recents.events.activity.HideHistoryButtonEvent;
56import com.android.systemui.recents.events.activity.HideHistoryEvent;
Winson Chung48f2cda2015-12-11 13:20:12 -050057import com.android.systemui.recents.events.activity.LaunchTaskEvent;
Winsonc29ff002015-11-20 16:00:45 -080058import com.android.systemui.recents.events.activity.ShowHistoryButtonEvent;
59import com.android.systemui.recents.events.activity.ShowHistoryEvent;
Winson Chung06266772015-12-11 10:24:21 -050060import com.android.systemui.recents.events.activity.TaskStackUpdatedEvent;
Winson49df4202016-01-25 17:33:34 -080061import com.android.systemui.recents.events.activity.ToggleHistoryEvent;
Winsonb1e71d02015-11-23 12:40:23 -080062import com.android.systemui.recents.events.component.RecentsVisibilityChangedEvent;
Jorim Jaggidd98d412015-11-18 15:57:38 -080063import com.android.systemui.recents.events.ui.DraggingInRecentsEndedEvent;
64import com.android.systemui.recents.events.ui.DraggingInRecentsEvent;
Winson49df4202016-01-25 17:33:34 -080065import com.android.systemui.recents.events.ui.ResetBackgroundScrimEvent;
66import com.android.systemui.recents.events.ui.UpdateBackgroundScrimEvent;
Winsoneca4ab62015-11-04 10:50:28 -080067import com.android.systemui.recents.events.ui.dragndrop.DragDropTargetChangedEvent;
Winsonbe7607a2015-10-01 17:24:51 -070068import com.android.systemui.recents.events.ui.dragndrop.DragEndEvent;
69import com.android.systemui.recents.events.ui.dragndrop.DragStartEvent;
Winson49df4202016-01-25 17:33:34 -080070import com.android.systemui.recents.history.RecentsHistoryView;
Winson Chung9a742902015-12-11 10:25:40 -050071import com.android.systemui.recents.misc.ReferenceCountedTrigger;
Winson Chung1f24c7e2014-07-11 17:06:48 -070072import com.android.systemui.recents.misc.SystemServicesProxy;
Winsonc5fd3502016-01-18 15:18:37 -080073import com.android.systemui.recents.misc.Utilities;
Winson Chung303e1ff2014-03-07 15:06:19 -080074import com.android.systemui.recents.model.Task;
75import com.android.systemui.recents.model.TaskStack;
Jorim Jaggi870ab5a2015-12-02 18:37:54 -080076import com.android.systemui.stackdivider.WindowManagerProxy;
77import com.android.systemui.statusbar.FlingAnimationUtils;
Winson Chung303e1ff2014-03-07 15:06:19 -080078
79import java.util.ArrayList;
Winson Chung6ac8bd62015-01-07 16:38:35 -080080import java.util.List;
Winson Chung303e1ff2014-03-07 15:06:19 -080081
Wale Ogunwale3797c222015-10-27 14:21:58 -070082import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
Winson412e1802015-10-20 16:57:57 -070083
Winson Chung303e1ff2014-03-07 15:06:19 -080084/**
85 * This view is the the top level layout that contains TaskStacks (which are laid out according
86 * to their SpaceNode bounds.
87 */
Winson Chung48f2cda2015-12-11 13:20:12 -050088public class RecentsView extends FrameLayout {
Winson Chung47c4c692014-03-17 10:17:11 -070089
Winson3e874742016-01-07 10:08:17 -080090 private static final int DOCK_AREA_OVERLAY_TRANSITION_DURATION = 135;
Winson49df4202016-01-25 17:33:34 -080091 private static final int DEFAULT_UPDATE_SCRIM_DURATION = 200;
92 private static final float DEFAULT_SCRIM_ALPHA = 0.33f;
Jorim Jaggi6e18e002015-06-02 17:07:39 -070093
Winson Chung9a742902015-12-11 10:25:40 -050094 private final Handler mHandler;
Winson Chungd42a6cf2014-06-03 16:24:04 -070095
Winson Chung9a742902015-12-11 10:25:40 -050096 private TaskStack mStack;
97 private TaskStackView mTaskStackView;
98 private RecentsAppWidgetHostView mSearchBar;
Winson Chungde750de2015-12-11 10:26:06 -050099 private TextView mHistoryButton;
Winson214f0f02016-01-26 13:37:37 -0800100 private TextView mHistoryClearAllButton;
Winson Chung9a742902015-12-11 10:25:40 -0500101 private View mEmptyView;
Winson49df4202016-01-25 17:33:34 -0800102 private RecentsHistoryView mHistoryView;
103
Winson Chung9a742902015-12-11 10:25:40 -0500104 private boolean mAwaitingFirstLayout = true;
105 private boolean mLastTaskLaunchedWasFreeform;
106 private Rect mSystemInsets = new Rect();
Winson3e874742016-01-07 10:08:17 -0800107 private int mDividerSize;
Winsonbe7607a2015-10-01 17:24:51 -0700108
Winson49df4202016-01-25 17:33:34 -0800109 private ColorDrawable mBackgroundScrim = new ColorDrawable(Color.BLACK);
110 private Animator mBackgroundScrimAnimator;
111
Winson Chung9a742902015-12-11 10:25:40 -0500112 private RecentsTransitionHelper mTransitionHelper;
113 private RecentsViewTouchHandler mTouchHandler;
Winson Chung9a742902015-12-11 10:25:40 -0500114 private final FlingAnimationUtils mFlingAnimationUtils;
Jorim Jaggi870ab5a2015-12-02 18:37:54 -0800115
Winson Chung303e1ff2014-03-07 15:06:19 -0800116 public RecentsView(Context context) {
Jorim Jaggi870ab5a2015-12-02 18:37:54 -0800117 this(context, null);
Winson Chung8e548f72014-06-24 14:40:53 -0700118 }
119
120 public RecentsView(Context context, AttributeSet attrs) {
121 this(context, attrs, 0);
122 }
123
124 public RecentsView(Context context, AttributeSet attrs, int defStyleAttr) {
125 this(context, attrs, defStyleAttr, 0);
126 }
127
128 public RecentsView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
129 super(context, attrs, defStyleAttr, defStyleRes);
Winsonbe7607a2015-10-01 17:24:51 -0700130 setWillNotDraw(false);
Winson3e874742016-01-07 10:08:17 -0800131
132 SystemServicesProxy ssp = Recents.getSystemServices();
Winson83c1b072015-11-09 10:48:04 -0800133 mHandler = new Handler();
134 mTransitionHelper = new RecentsTransitionHelper(getContext(), mHandler);
Winson3e874742016-01-07 10:08:17 -0800135 mDividerSize = ssp.getDockedDividerSize(context);
Winsonbe7607a2015-10-01 17:24:51 -0700136 mTouchHandler = new RecentsViewTouchHandler(this);
Jorim Jaggi870ab5a2015-12-02 18:37:54 -0800137 mFlingAnimationUtils = new FlingAnimationUtils(context, 0.3f);
Winsonc29ff002015-11-20 16:00:45 -0800138
Winson49df4202016-01-25 17:33:34 -0800139 final float cornerRadius = context.getResources().getDimensionPixelSize(
140 R.dimen.recents_task_view_rounded_corners_radius);
Winsonc29ff002015-11-20 16:00:45 -0800141 LayoutInflater inflater = LayoutInflater.from(context);
Winson Chungde750de2015-12-11 10:26:06 -0500142 mHistoryButton = (TextView) inflater.inflate(R.layout.recents_history_button, this, false);
Winsonc29ff002015-11-20 16:00:45 -0800143 mHistoryButton.setOnClickListener(new View.OnClickListener() {
144 @Override
145 public void onClick(View v) {
Winson49df4202016-01-25 17:33:34 -0800146 EventBus.getDefault().send(new ToggleHistoryEvent());
147 }
148 });
Winson214f0f02016-01-26 13:37:37 -0800149 addView(mHistoryButton);
Winson49df4202016-01-25 17:33:34 -0800150 mHistoryButton.setClipToOutline(true);
151 mHistoryButton.setOutlineProvider(new ViewOutlineProvider() {
152 @Override
153 public void getOutline(View view, Outline outline) {
154 outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), cornerRadius);
Winsonc29ff002015-11-20 16:00:45 -0800155 }
156 });
Winson Chung9a742902015-12-11 10:25:40 -0500157 mEmptyView = inflater.inflate(R.layout.recents_empty, this, false);
158 addView(mEmptyView);
Winson49df4202016-01-25 17:33:34 -0800159
160 setBackground(mBackgroundScrim);
Winson Chungd16c5652015-01-26 16:11:07 -0800161 }
162
Winson Chungdcfa7972014-07-22 12:27:13 -0700163 /** Set/get the bsp root node */
Winson147ecaf2015-09-16 16:49:55 -0700164 public void setTaskStack(TaskStack stack) {
Winson53ec42c2015-10-28 15:55:35 -0700165 RecentsConfiguration config = Recents.getConfiguration();
Winson Chung9a742902015-12-11 10:25:40 -0500166 RecentsActivityLaunchState launchState = config.getLaunchState();
Winsonc29ff002015-11-20 16:00:45 -0800167 mStack = stack;
Winson55e20d52016-01-06 15:21:29 -0800168 if (launchState.launchedReuseTaskStackViews) {
Winson147ecaf2015-09-16 16:49:55 -0700169 if (mTaskStackView != null) {
170 // If onRecentsHidden is not triggered, we need to the stack view again here
171 mTaskStackView.reset();
172 mTaskStackView.setStack(stack);
173 } else {
174 mTaskStackView = new TaskStackView(getContext(), stack);
Winson147ecaf2015-09-16 16:49:55 -0700175 addView(mTaskStackView);
176 }
177 } else {
178 if (mTaskStackView != null) {
179 removeView(mTaskStackView);
180 }
181 mTaskStackView = new TaskStackView(getContext(), stack);
Winson147ecaf2015-09-16 16:49:55 -0700182 addView(mTaskStackView);
Winson Chung303e1ff2014-03-07 15:06:19 -0800183 }
Winson Chung9a742902015-12-11 10:25:40 -0500184
Winson49df4202016-01-25 17:33:34 -0800185 // If we are already occluded by the app, then just set the default background scrim now.
186 // Otherwise, defer until the enter animation completes to animate the scrim with the
187 // tasks for the home animation.
188 if (launchState.launchedFromAppWithThumbnail || mStack.getTaskCount() == 0) {
189 mBackgroundScrim.setAlpha((int) (DEFAULT_SCRIM_ALPHA * 255));
190 } else {
191 mBackgroundScrim.setAlpha(0);
192 }
193
Winson Chung9a742902015-12-11 10:25:40 -0500194 // Update the top level view's visibilities
Winson4b057c62016-01-12 15:01:52 -0800195 if (stack.getTaskCount() > 0) {
Winson Chung9a742902015-12-11 10:25:40 -0500196 hideEmptyView();
Winsonc29ff002015-11-20 16:00:45 -0800197 } else {
Winson Chung9a742902015-12-11 10:25:40 -0500198 showEmptyView();
Winsonc29ff002015-11-20 16:00:45 -0800199 }
Winson Chung02d49272014-08-29 13:57:29 -0700200
Winson Chungb0a28ea2014-10-28 15:21:35 -0700201 // Trigger a new layout
202 requestLayout();
Winson Chung19fc1172014-07-31 18:40:03 -0700203 }
204
Winsonb1e71d02015-11-23 12:40:23 -0800205 /**
206 * Returns whether the last task launched was in the freeform stack or not.
207 */
208 public boolean isLastTaskLaunchedFreeform() {
209 return mLastTaskLaunchedWasFreeform;
210 }
211
Winsonc29ff002015-11-20 16:00:45 -0800212 /**
Winson49df4202016-01-25 17:33:34 -0800213 * Returns whether the history is visible or not.
214 */
215 public boolean isHistoryVisible() {
216 return mHistoryView != null && mHistoryView.isVisible();
217 }
218
219 /**
Winsonc29ff002015-11-20 16:00:45 -0800220 * Returns the currently set task stack.
221 */
222 public TaskStack getTaskStack() {
223 return mStack;
224 }
225
Skuhne8aa7d162015-03-20 13:40:53 -0700226 /** Gets the next task in the stack - or if the last - the top task */
227 public Task getNextTaskOrTopTask(Task taskToSearch) {
Chong Zhang0fa656b2015-08-31 15:17:21 -0700228 Task returnTask = null;
Skuhne8aa7d162015-03-20 13:40:53 -0700229 boolean found = false;
Winson147ecaf2015-09-16 16:49:55 -0700230 if (mTaskStackView != null) {
231 TaskStack stack = mTaskStackView.getStack();
Winson250608a2015-11-24 15:00:31 -0800232 ArrayList<Task> taskList = stack.getStackTasks();
Skuhne8aa7d162015-03-20 13:40:53 -0700233 // Iterate the stack views and try and find the focused task
234 for (int j = taskList.size() - 1; j >= 0; --j) {
235 Task task = taskList.get(j);
236 // Return the next task in the line.
237 if (found)
238 return task;
239 // Remember the first possible task as the top task.
240 if (returnTask == null)
241 returnTask = task;
242 if (task == taskToSearch)
243 found = true;
244 }
245 }
246 return returnTask;
247 }
248
Winson Chung1e8d71b2014-05-16 17:05:22 -0700249 /** Launches the focused task from the first stack if possible */
250 public boolean launchFocusedTask() {
Winson147ecaf2015-09-16 16:49:55 -0700251 if (mTaskStackView != null) {
Winson142af422015-11-09 10:39:57 -0800252 Task task = mTaskStackView.getFocusedTask();
253 if (task != null) {
254 TaskView taskView = mTaskStackView.getChildViewForTask(task);
Winson Chung48f2cda2015-12-11 13:20:12 -0500255 EventBus.getDefault().send(new LaunchTaskEvent(taskView, task, null,
256 INVALID_STACK_ID, false));
Winson142af422015-11-09 10:39:57 -0800257 return true;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700258 }
259 }
Winson Chung1e8d71b2014-05-16 17:05:22 -0700260 return false;
261 }
262
Winsona0731a12015-12-02 15:10:14 -0800263 /** Launches the task that recents was launched from if possible */
264 public boolean launchPreviousTask() {
265 if (mTaskStackView != null) {
266 TaskStack stack = mTaskStackView.getStack();
267 Task task = stack.getLaunchTarget();
268 if (task != null) {
269 TaskView taskView = mTaskStackView.getChildViewForTask(task);
Winson Chung48f2cda2015-12-11 13:20:12 -0500270 EventBus.getDefault().send(new LaunchTaskEvent(taskView, task, null,
271 INVALID_STACK_ID, false));
Winsona0731a12015-12-02 15:10:14 -0800272 return true;
273 }
274 }
275 return false;
276 }
277
Skuhne8aa7d162015-03-20 13:40:53 -0700278 /** Launches a given task. */
Filip Gruszczynskif48b5852015-10-13 10:28:22 -0700279 public boolean launchTask(Task task, Rect taskBounds, int destinationStack) {
Winson147ecaf2015-09-16 16:49:55 -0700280 if (mTaskStackView != null) {
Skuhne8aa7d162015-03-20 13:40:53 -0700281 // Iterate the stack views and try and find the given task.
Winson147ecaf2015-09-16 16:49:55 -0700282 List<TaskView> taskViews = mTaskStackView.getTaskViews();
Skuhne8aa7d162015-03-20 13:40:53 -0700283 int taskViewCount = taskViews.size();
284 for (int j = 0; j < taskViewCount; j++) {
285 TaskView tv = taskViews.get(j);
286 if (tv.getTask() == task) {
Winson Chung48f2cda2015-12-11 13:20:12 -0500287 EventBus.getDefault().send(new LaunchTaskEvent(tv, task, taskBounds,
288 destinationStack, false));
Skuhne8aa7d162015-03-20 13:40:53 -0700289 return true;
290 }
291 }
292 }
293 return false;
294 }
295
Winson Chungf7bca432014-04-30 17:11:13 -0700296 /** Adds the search bar */
Winson Chungaee097c2015-04-02 18:16:02 -0700297 public void setSearchBar(RecentsAppWidgetHostView searchBar) {
Winson Chungaf3bb692015-06-03 17:31:39 -0700298 // Remove the previous search bar if one exists
299 if (mSearchBar != null && indexOfChild(mSearchBar) > -1) {
300 removeView(mSearchBar);
301 }
302 // Add the new search bar
303 if (searchBar != null) {
304 mSearchBar = searchBar;
305 addView(mSearchBar);
Winson Chungf7bca432014-04-30 17:11:13 -0700306 }
Winson Chungecd9b302014-04-16 17:07:18 -0700307 }
308
Winson Chung772b6b12014-07-03 15:54:02 -0700309 /** Returns whether there is currently a search bar */
Winson Chungaee097c2015-04-02 18:16:02 -0700310 public boolean hasValidSearchBar() {
311 return mSearchBar != null && !mSearchBar.isReinflateRequired();
Winson Chung772b6b12014-07-03 15:54:02 -0700312 }
313
Winson Chung9a742902015-12-11 10:25:40 -0500314 /**
315 * Hides the task stack and shows the empty view.
316 */
317 public void showEmptyView() {
Winsond8b1d632016-01-04 17:51:18 -0800318 if (RecentsDebugFlags.Static.EnableSearchBar && (mSearchBar != null)) {
Winson Chung9a742902015-12-11 10:25:40 -0500319 mSearchBar.setVisibility(View.INVISIBLE);
320 }
321 mTaskStackView.setVisibility(View.INVISIBLE);
322 mEmptyView.setVisibility(View.VISIBLE);
323 mEmptyView.bringToFront();
324 mHistoryButton.bringToFront();
325 }
326
327 /**
328 * Shows the task stack and hides the empty view.
329 */
330 public void hideEmptyView() {
331 mEmptyView.setVisibility(View.INVISIBLE);
332 mTaskStackView.setVisibility(View.VISIBLE);
Winsond8b1d632016-01-04 17:51:18 -0800333 if (RecentsDebugFlags.Static.EnableSearchBar && (mSearchBar != null)) {
Winson Chung9a742902015-12-11 10:25:40 -0500334 mSearchBar.setVisibility(View.VISIBLE);
335 }
336 mTaskStackView.bringToFront();
Winson Chung772b6b12014-07-03 15:54:02 -0700337 if (mSearchBar != null) {
Winson Chung012ef362014-07-31 18:36:25 -0700338 mSearchBar.bringToFront();
Winson Chung772b6b12014-07-03 15:54:02 -0700339 }
Winson Chung9a742902015-12-11 10:25:40 -0500340 mHistoryButton.bringToFront();
Winson Chung772b6b12014-07-03 15:54:02 -0700341 }
342
Winsonbe7607a2015-10-01 17:24:51 -0700343 @Override
344 protected void onAttachedToWindow() {
345 EventBus.getDefault().register(this, RecentsActivity.EVENT_BUS_PRIORITY + 1);
Winsonc8a4cdc2016-01-19 11:30:51 -0800346 EventBus.getDefault().register(mTouchHandler, RecentsActivity.EVENT_BUS_PRIORITY + 2);
Winsonbe7607a2015-10-01 17:24:51 -0700347 super.onAttachedToWindow();
348 }
349
350 @Override
351 protected void onDetachedFromWindow() {
352 super.onDetachedFromWindow();
353 EventBus.getDefault().unregister(this);
354 EventBus.getDefault().unregister(mTouchHandler);
355 }
356
Winson Chungf7bca432014-04-30 17:11:13 -0700357 /**
358 * This is called with the full size of the window since we are handling our own insets.
359 */
Winson Chung303e1ff2014-03-07 15:06:19 -0800360 @Override
361 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Winson53ec42c2015-10-28 15:55:35 -0700362 RecentsConfiguration config = Recents.getConfiguration();
Winson Chung303e1ff2014-03-07 15:06:19 -0800363 int width = MeasureSpec.getSize(widthMeasureSpec);
364 int height = MeasureSpec.getSize(heightMeasureSpec);
Winson Chungbd912972014-03-18 14:36:35 -0700365
Winson Chungf7bca432014-04-30 17:11:13 -0700366 // Get the search bar bounds and measure the search bar layout
Winson Chungaf3bb692015-06-03 17:31:39 -0700367 Rect searchBarSpaceBounds = new Rect();
Winson Chungecd9b302014-04-16 17:07:18 -0700368 if (mSearchBar != null) {
Winson53ec42c2015-10-28 15:55:35 -0700369 config.getSearchBarBounds(new Rect(0, 0, width, height), mSystemInsets.top,
Winson147ecaf2015-09-16 16:49:55 -0700370 searchBarSpaceBounds);
Winson Chungf7bca432014-04-30 17:11:13 -0700371 mSearchBar.measure(
372 MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.width(), MeasureSpec.EXACTLY),
373 MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.height(), MeasureSpec.EXACTLY));
Winson Chungecd9b302014-04-16 17:07:18 -0700374 }
375
Winson Chungf7bca432014-04-30 17:11:13 -0700376 Rect taskStackBounds = new Rect();
Winson53ec42c2015-10-28 15:55:35 -0700377 config.getTaskStackBounds(new Rect(0, 0, width, height), mSystemInsets.top,
Winson35f30502015-09-28 11:24:36 -0700378 mSystemInsets.right, searchBarSpaceBounds, taskStackBounds);
Winson147ecaf2015-09-16 16:49:55 -0700379 if (mTaskStackView != null && mTaskStackView.getVisibility() != GONE) {
Winson88f00ab2015-10-05 17:24:00 -0700380 mTaskStackView.setTaskStackBounds(taskStackBounds, mSystemInsets);
Winson147ecaf2015-09-16 16:49:55 -0700381 mTaskStackView.measure(widthMeasureSpec, heightMeasureSpec);
Winson Chung303e1ff2014-03-07 15:06:19 -0800382 }
383
Winson49df4202016-01-25 17:33:34 -0800384 // Measure the empty view to the full size of the screen
385 if (mEmptyView.getVisibility() != GONE) {
386 measureChild(mEmptyView, MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
387 MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
388 }
Winson Chung9a742902015-12-11 10:25:40 -0500389
Winson49df4202016-01-25 17:33:34 -0800390 // Measure the history view
391 if (mHistoryView != null && mHistoryView.getVisibility() != GONE) {
392 measureChild(mHistoryView, MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
393 MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
394 }
395
396 // Measure the history button within the constraints of the space above the stack
Winson387aac62015-11-25 11:18:56 -0800397 Rect historyButtonRect = mTaskStackView.mLayoutAlgorithm.mHistoryButtonRect;
Winsonc29ff002015-11-20 16:00:45 -0800398 measureChild(mHistoryButton,
Winson49df4202016-01-25 17:33:34 -0800399 MeasureSpec.makeMeasureSpec(historyButtonRect.width(), MeasureSpec.AT_MOST),
400 MeasureSpec.makeMeasureSpec(historyButtonRect.height(), MeasureSpec.AT_MOST));
Winson214f0f02016-01-26 13:37:37 -0800401 if (mHistoryClearAllButton != null && mHistoryClearAllButton.getVisibility() != GONE) {
402 measureChild(mHistoryClearAllButton,
403 MeasureSpec.makeMeasureSpec(historyButtonRect.width(), MeasureSpec.AT_MOST),
404 MeasureSpec.makeMeasureSpec(historyButtonRect.height(), MeasureSpec.AT_MOST));
405 }
Winson Chung9a742902015-12-11 10:25:40 -0500406
Winson Chung303e1ff2014-03-07 15:06:19 -0800407 setMeasuredDimension(width, height);
408 }
409
Winson Chungf7bca432014-04-30 17:11:13 -0700410 /**
411 * This is called with the full size of the window since we are handling our own insets.
412 */
Winson Chung303e1ff2014-03-07 15:06:19 -0800413 @Override
414 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
Winson53ec42c2015-10-28 15:55:35 -0700415 RecentsConfiguration config = Recents.getConfiguration();
416
Winson Chungf7bca432014-04-30 17:11:13 -0700417 // Get the search bar bounds so that we lay it out
Winson147ecaf2015-09-16 16:49:55 -0700418 Rect measuredRect = new Rect(0, 0, getMeasuredWidth(), getMeasuredHeight());
419 Rect searchBarSpaceBounds = new Rect();
Winson Chungecd9b302014-04-16 17:07:18 -0700420 if (mSearchBar != null) {
Winson53ec42c2015-10-28 15:55:35 -0700421 config.getSearchBarBounds(measuredRect,
Winson35f30502015-09-28 11:24:36 -0700422 mSystemInsets.top, searchBarSpaceBounds);
Winson Chungdcfa7972014-07-22 12:27:13 -0700423 mSearchBar.layout(searchBarSpaceBounds.left, searchBarSpaceBounds.top,
424 searchBarSpaceBounds.right, searchBarSpaceBounds.bottom);
Winson Chungecd9b302014-04-16 17:07:18 -0700425 }
426
Winson147ecaf2015-09-16 16:49:55 -0700427 if (mTaskStackView != null && mTaskStackView.getVisibility() != GONE) {
428 mTaskStackView.layout(left, top, left + getMeasuredWidth(), top + getMeasuredHeight());
Winson Chung303e1ff2014-03-07 15:06:19 -0800429 }
Winsonbe7607a2015-10-01 17:24:51 -0700430
Winson Chung9a742902015-12-11 10:25:40 -0500431 // Layout the empty view
Winson49df4202016-01-25 17:33:34 -0800432 if (mEmptyView.getVisibility() != GONE) {
433 mEmptyView.layout(left, top, right, bottom);
434 }
Winson Chung9a742902015-12-11 10:25:40 -0500435
Winson49df4202016-01-25 17:33:34 -0800436 // Layout the history view
437 if (mHistoryView != null && mHistoryView.getVisibility() != GONE) {
438 mHistoryView.layout(left, top, right, bottom);
439 }
440
Winson214f0f02016-01-26 13:37:37 -0800441 // Layout the history button such that its drawable is start-aligned with the stack,
Winson49df4202016-01-25 17:33:34 -0800442 // vertically centered in the available space above the stack
Winson387aac62015-11-25 11:18:56 -0800443 Rect historyButtonRect = mTaskStackView.mLayoutAlgorithm.mHistoryButtonRect;
Winson214f0f02016-01-26 13:37:37 -0800444 int historyLeft = isLayoutRtl()
445 ? historyButtonRect.right + mHistoryButton.getPaddingStart()
446 - mHistoryButton.getMeasuredWidth()
447 : historyButtonRect.left - mHistoryButton.getPaddingStart();
Winson49df4202016-01-25 17:33:34 -0800448 int historyTop = historyButtonRect.top +
449 (historyButtonRect.height() - mHistoryButton.getMeasuredHeight()) / 2;
450 mHistoryButton.layout(historyLeft, historyTop,
451 historyLeft + mHistoryButton.getMeasuredWidth(),
452 historyTop + mHistoryButton.getMeasuredHeight());
Winsonc29ff002015-11-20 16:00:45 -0800453
Winson214f0f02016-01-26 13:37:37 -0800454 // Layout the history clear all button such that it is end-aligned with the stack,
455 // vertically centered in the available space above the stack
456 if (mHistoryClearAllButton != null && mHistoryClearAllButton.getVisibility() != GONE) {
457 int clearAllLeft = isLayoutRtl()
458 ? historyButtonRect.left - mHistoryClearAllButton.getPaddingStart()
459 : historyButtonRect.right + mHistoryClearAllButton.getPaddingStart()
460 - mHistoryClearAllButton.getMeasuredWidth();
461 int clearAllTop = historyButtonRect.top +
462 (historyButtonRect.height() - mHistoryClearAllButton.getMeasuredHeight()) / 2;
463 mHistoryClearAllButton.layout(clearAllLeft, clearAllTop,
464 clearAllLeft + mHistoryClearAllButton.getMeasuredWidth(),
465 clearAllTop + mHistoryClearAllButton.getMeasuredHeight());
466 }
467
Winsonb1e71d02015-11-23 12:40:23 -0800468 if (mAwaitingFirstLayout) {
469 mAwaitingFirstLayout = false;
470
471 // If launched via dragging from the nav bar, then we should translate the whole view
472 // down offscreen
473 RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState();
474 if (launchState.launchedViaDragGesture) {
475 setTranslationY(getMeasuredHeight());
Jorim Jaggi0ca88262015-12-07 17:15:16 -0800476 } else {
477 setTranslationY(0f);
Winsonb1e71d02015-11-23 12:40:23 -0800478 }
479 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800480 }
481
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700482 @Override
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700483 public WindowInsets onApplyWindowInsets(WindowInsets insets) {
Winson35f30502015-09-28 11:24:36 -0700484 mSystemInsets.set(insets.getSystemWindowInsets());
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700485 requestLayout();
Winsonc29ff002015-11-20 16:00:45 -0800486 return insets;
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700487 }
488
Winsonbe7607a2015-10-01 17:24:51 -0700489 @Override
490 public boolean onInterceptTouchEvent(MotionEvent ev) {
491 return mTouchHandler.onInterceptTouchEvent(ev);
492 }
493
494 @Override
495 public boolean onTouchEvent(MotionEvent ev) {
496 return mTouchHandler.onTouchEvent(ev);
497 }
498
499 @Override
Winsonbe8e6962016-02-01 14:27:52 -0800500 public void onDrawForeground(Canvas canvas) {
501 super.onDrawForeground(canvas);
502
Winson036693c2016-01-14 17:16:06 -0800503 ArrayList<TaskStack.DockState> visDockStates = mTouchHandler.getVisibleDockStates();
504 for (int i = visDockStates.size() - 1; i >= 0; i--) {
505 Drawable d = visDockStates.get(i).viewState.dockAreaOverlay;
Winson882072b2015-10-12 11:26:33 -0700506 if (d.getAlpha() > 0) {
507 d.draw(canvas);
508 }
Winsonbe7607a2015-10-01 17:24:51 -0700509 }
510 }
511
Winson4165d3362015-10-10 14:40:35 -0700512 @Override
513 protected boolean verifyDrawable(Drawable who) {
Winson036693c2016-01-14 17:16:06 -0800514 ArrayList<TaskStack.DockState> visDockStates = mTouchHandler.getVisibleDockStates();
515 for (int i = visDockStates.size() - 1; i >= 0; i--) {
516 Drawable d = visDockStates.get(i).viewState.dockAreaOverlay;
Winson882072b2015-10-12 11:26:33 -0700517 if (d == who) {
518 return true;
519 }
520 }
521 return super.verifyDrawable(who);
Winson4165d3362015-10-10 14:40:35 -0700522 }
523
Winsonbe7607a2015-10-01 17:24:51 -0700524 /**** EventBus Events ****/
525
Winson Chung48f2cda2015-12-11 13:20:12 -0500526 public final void onBusEvent(LaunchTaskEvent event) {
527 mLastTaskLaunchedWasFreeform = event.task.isFreeformTask();
528 mTransitionHelper.launchTaskFromRecents(mStack, event.task, mTaskStackView, event.taskView,
529 event.screenPinningRequested, event.targetTaskBounds, event.targetTaskStack);
530 }
531
Winsonef064132016-01-05 12:11:31 -0800532 public final void onBusEvent(DismissRecentsToHomeAnimationStarted event) {
533 // Hide the history button
Winson50448632016-02-01 18:04:59 -0800534 int taskViewExitToHomeDuration = TaskStackAnimationHelper.EXIT_TO_HOME_TRANSLATION_DURATION;
Winson49df4202016-01-25 17:33:34 -0800535 hideHistoryButton(taskViewExitToHomeDuration, false /* translate */);
536 animateBackgroundScrim(0f, taskViewExitToHomeDuration);
Winsonef064132016-01-05 12:11:31 -0800537 }
538
Winsonbe7607a2015-10-01 17:24:51 -0700539 public final void onBusEvent(DragStartEvent event) {
Winson882072b2015-10-12 11:26:33 -0700540 updateVisibleDockRegions(mTouchHandler.getDockStatesForCurrentOrientation(),
Winson3e874742016-01-07 10:08:17 -0800541 true /* isDefaultDockState */, TaskStack.DockState.NONE.viewState.dockAreaAlpha,
542 true /* animateAlpha */, false /* animateBounds */);
Winsonbe7607a2015-10-01 17:24:51 -0700543 }
544
Winsoneca4ab62015-11-04 10:50:28 -0800545 public final void onBusEvent(DragDropTargetChangedEvent event) {
546 if (event.dropTarget == null || !(event.dropTarget instanceof TaskStack.DockState)) {
Winson882072b2015-10-12 11:26:33 -0700547 updateVisibleDockRegions(mTouchHandler.getDockStatesForCurrentOrientation(),
Winson3e874742016-01-07 10:08:17 -0800548 true /* isDefaultDockState */, TaskStack.DockState.NONE.viewState.dockAreaAlpha,
549 true /* animateAlpha */, true /* animateBounds */);
Winson882072b2015-10-12 11:26:33 -0700550 } else {
Winsoneca4ab62015-11-04 10:50:28 -0800551 final TaskStack.DockState dockState = (TaskStack.DockState) event.dropTarget;
Winson3e874742016-01-07 10:08:17 -0800552 updateVisibleDockRegions(new TaskStack.DockState[] {dockState},
553 false /* isDefaultDockState */, -1, true /* animateAlpha */,
554 true /* animateBounds */);
Winson882072b2015-10-12 11:26:33 -0700555 }
Winsonbe7607a2015-10-01 17:24:51 -0700556 }
557
558 public final void onBusEvent(final DragEndEvent event) {
Winson479f7442015-11-25 15:16:27 -0800559 // Handle the case where we drop onto a dock region
560 if (event.dropTarget instanceof TaskStack.DockState) {
Winson3e874742016-01-07 10:08:17 -0800561 final TaskStack.DockState dockState = (TaskStack.DockState) event.dropTarget;
562
563 // Hide the dock region
564 updateVisibleDockRegions(null, false /* isDefaultDockState */, -1,
565 false /* animateAlpha */, false /* animateBounds */);
566
Winsonf24f2162016-01-05 12:11:55 -0800567 TaskStackLayoutAlgorithm stackLayout = mTaskStackView.getStackAlgorithm();
568 TaskStackViewScroller stackScroller = mTaskStackView.getScroller();
569 TaskViewTransform tmpTransform = new TaskViewTransform();
Winsoneca4ab62015-11-04 10:50:28 -0800570
Winson3e874742016-01-07 10:08:17 -0800571 // We translated the view but we need to animate it back from the current layout-space
572 // rect to its final layout-space rect
573 int x = (int) event.taskView.getTranslationX();
574 int y = (int) event.taskView.getTranslationY();
575 Rect taskViewRect = new Rect(event.taskView.getLeft(), event.taskView.getTop(),
576 event.taskView.getRight(), event.taskView.getBottom());
577 taskViewRect.offset(x, y);
578 event.taskView.setTranslationX(0);
579 event.taskView.setTranslationY(0);
580 event.taskView.setLeftTopRightBottom(taskViewRect.left, taskViewRect.top,
581 taskViewRect.right, taskViewRect.bottom);
582
Winsonf24f2162016-01-05 12:11:55 -0800583 // Remove the task view after it is docked
Winson8aa99592016-01-19 15:07:07 -0800584 mTaskStackView.updateLayoutAlgorithm(false /* boundScroll */);
Winsonf24f2162016-01-05 12:11:55 -0800585 stackLayout.getStackTransform(event.task, stackScroller.getStackScroll(), tmpTransform,
586 null);
Winson3e874742016-01-07 10:08:17 -0800587 tmpTransform.alpha = 0;
588 tmpTransform.scale = 1f;
589 tmpTransform.rect.set(taskViewRect);
Winsonf24f2162016-01-05 12:11:55 -0800590 mTaskStackView.updateTaskViewToTransform(event.taskView, tmpTransform,
Winsonbe8e6962016-02-01 14:27:52 -0800591 new AnimationProps(125, Interpolators.ALPHA_OUT,
Winsonf24f2162016-01-05 12:11:55 -0800592 new AnimatorListenerAdapter() {
593 @Override
594 public void onAnimationEnd(Animator animation) {
Winson3e874742016-01-07 10:08:17 -0800595 // Dock the task and launch it
596 SystemServicesProxy ssp = Recents.getSystemServices();
Filip Gruszczynskif298e902016-01-18 08:59:45 -0800597 ssp.startTaskInDockedMode(getContext(), event.taskView,
598 event.task.key.id, dockState.createMode);
Winson3e874742016-01-07 10:08:17 -0800599
Winson8aa99592016-01-19 15:07:07 -0800600 // Animate the stack accordingly
Winsonbe8e6962016-02-01 14:27:52 -0800601 AnimationProps stackAnim = new AnimationProps(
Winson8aa99592016-01-19 15:07:07 -0800602 TaskStackView.DEFAULT_SYNC_STACK_DURATION,
Winsonc0d70582016-01-29 10:24:39 -0800603 Interpolators.FAST_OUT_SLOW_IN);
Winson8aa99592016-01-19 15:07:07 -0800604 mTaskStackView.getStack().removeTask(event.task, stackAnim);
Winsonf24f2162016-01-05 12:11:55 -0800605 }
606 }));
Winsona0a8ae42015-12-01 10:43:02 -0800607
Chris Wrenf6e9228b2016-01-26 18:04:35 -0500608 MetricsLogger.action(mContext, MetricsEvent.ACTION_WINDOW_DOCK_DRAG_DROP);
Winson3e874742016-01-07 10:08:17 -0800609 } else {
610 // Animate the overlay alpha back to 0
611 updateVisibleDockRegions(null, true /* isDefaultDockState */, -1,
612 true /* animateAlpha */, false /* animateBounds */);
Winsonbe7607a2015-10-01 17:24:51 -0700613 }
614 }
Winson4165d3362015-10-10 14:40:35 -0700615
Jorim Jaggidd98d412015-11-18 15:57:38 -0800616 public final void onBusEvent(DraggingInRecentsEvent event) {
Jorim Jaggi54b1a6d2015-11-24 17:48:26 -0800617 if (mTaskStackView.getTaskViews().size() > 0) {
618 setTranslationY(event.distanceFromTop - mTaskStackView.getTaskViews().get(0).getY());
619 }
Jorim Jaggidd98d412015-11-18 15:57:38 -0800620 }
621
622 public final void onBusEvent(DraggingInRecentsEndedEvent event) {
Jorim Jaggi870ab5a2015-12-02 18:37:54 -0800623 ViewPropertyAnimator animator = animate();
Jorim Jaggi8fccfe22015-12-03 16:58:08 -0800624 if (event.velocity > mFlingAnimationUtils.getMinVelocityPxPerSecond()) {
Jorim Jaggi870ab5a2015-12-02 18:37:54 -0800625 animator.translationY(getHeight());
626 animator.withEndAction(new Runnable() {
627 @Override
628 public void run() {
629 WindowManagerProxy.getInstance().maximizeDockedStack();
630 }
631 });
632 mFlingAnimationUtils.apply(animator, getTranslationY(), getHeight(), event.velocity);
633 } else {
634 animator.translationY(0f);
635 animator.setListener(null);
636 mFlingAnimationUtils.apply(animator, getTranslationY(), 0, event.velocity);
637 }
638 animator.start();
Jorim Jaggidd98d412015-11-18 15:57:38 -0800639 }
640
Winson Chung06266772015-12-11 10:24:21 -0500641 public final void onBusEvent(TaskStackUpdatedEvent event) {
642 mStack.setTasks(event.stack.computeAllTasksList(), true /* notifyStackChanges */);
Winson Chung97567552015-12-16 17:07:19 -0500643 mStack.createAffiliatedGroupings(getContext());
Winson Chung06266772015-12-11 10:24:21 -0500644 }
645
Winson49df4202016-01-25 17:33:34 -0800646 public final void onBusEvent(EnterRecentsWindowAnimationCompletedEvent event) {
647 RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState();
648 if (!launchState.launchedFromAppWithThumbnail && mStack.getTaskCount() > 0) {
Winson50448632016-02-01 18:04:59 -0800649 animateBackgroundScrim(DEFAULT_SCRIM_ALPHA,
650 TaskStackAnimationHelper.ENTER_FROM_HOME_TRANSLATION_DURATION);
Winson49df4202016-01-25 17:33:34 -0800651 }
652 }
653
654 public final void onBusEvent(UpdateBackgroundScrimEvent event) {
655 animateBackgroundScrim(event.alpha, DEFAULT_UPDATE_SCRIM_DURATION);
656 }
657
658 public final void onBusEvent(ResetBackgroundScrimEvent event) {
659 animateBackgroundScrim(DEFAULT_SCRIM_ALPHA, DEFAULT_UPDATE_SCRIM_DURATION);
660 }
661
662 public final void onBusEvent(RecentsVisibilityChangedEvent event) {
663 if (!event.visible) {
664 // Reset the view state
665 mAwaitingFirstLayout = true;
666 mLastTaskLaunchedWasFreeform = false;
667 hideHistoryButton(0, false /* translate */);
668 }
669 }
670
671 public final void onBusEvent(ToggleHistoryEvent event) {
672 if (mHistoryView != null && mHistoryView.isVisible()) {
673 EventBus.getDefault().send(new HideHistoryEvent(true /* animate */));
674 } else {
675 EventBus.getDefault().send(new ShowHistoryEvent());
676 }
677 }
678
679 public final void onBusEvent(ShowHistoryEvent event) {
680 if (mHistoryView == null) {
Winson214f0f02016-01-26 13:37:37 -0800681 LayoutInflater inflater = LayoutInflater.from(getContext());
682 mHistoryView = (RecentsHistoryView) inflater.inflate(R.layout.recents_history, this,
683 false);
Winson49df4202016-01-25 17:33:34 -0800684 addView(mHistoryView);
685
Winson214f0f02016-01-26 13:37:37 -0800686 final float cornerRadius = getResources().getDimensionPixelSize(
687 R.dimen.recents_task_view_rounded_corners_radius);
688 mHistoryClearAllButton = (TextView) inflater.inflate(
689 R.layout.recents_history_clear_all_button, this, false);
690 mHistoryClearAllButton.setOnClickListener(new View.OnClickListener() {
691 @Override
692 public void onClick(View v) {
693 EventBus.getDefault().send(new ClearHistoryEvent());
694 }
695 });
696 mHistoryClearAllButton.setClipToOutline(true);
697 mHistoryClearAllButton.setOutlineProvider(new ViewOutlineProvider() {
698 @Override
699 public void getOutline(View view, Outline outline) {
700 outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), cornerRadius);
701 }
702 });
703 addView(mHistoryClearAllButton);
704
Winson49df4202016-01-25 17:33:34 -0800705 // Since this history view is inflated by a view stub after the insets have already
706 // been applied, we have to set them ourselves initial from the insets that were last
707 // provided.
708 mHistoryView.setSystemInsets(mSystemInsets);
709 mHistoryView.setHeaderHeight(mHistoryButton.getMeasuredHeight());
710 mHistoryButton.bringToFront();
Winson214f0f02016-01-26 13:37:37 -0800711 mHistoryClearAllButton.bringToFront();
Winson49df4202016-01-25 17:33:34 -0800712 }
713
714 // Animate the empty view in parallel with the history view (the task view animations are
715 // handled in TaskStackView)
716 Rect stackRect = mTaskStackView.mLayoutAlgorithm.mStackRect;
717 if (mEmptyView.getVisibility() == View.VISIBLE) {
718 int historyTransitionDuration = getResources().getInteger(
719 R.integer.recents_history_transition_duration);
720 mEmptyView.animate()
721 .alpha(0f)
Winson214f0f02016-01-26 13:37:37 -0800722 .translationY(stackRect.height() / 2)
Winson49df4202016-01-25 17:33:34 -0800723 .setDuration(historyTransitionDuration)
Winsonc0d70582016-01-29 10:24:39 -0800724 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
Winson49df4202016-01-25 17:33:34 -0800725 .withEndAction(new Runnable() {
726 @Override
727 public void run() {
728 mEmptyView.setVisibility(View.INVISIBLE);
729 }
730 })
731 .start();
732 }
733
Winson214f0f02016-01-26 13:37:37 -0800734 mHistoryView.show(mStack, stackRect.height(), mHistoryClearAllButton);
Winson49df4202016-01-25 17:33:34 -0800735 }
736
737 public final void onBusEvent(HideHistoryEvent event) {
738 // Animate the empty view in parallel with the history view (the task view animations are
739 // handled in TaskStackView)
740 Rect stackRect = mTaskStackView.mLayoutAlgorithm.mStackRect;
741 if (mStack.getTaskCount() == 0) {
742 int historyTransitionDuration = getResources().getInteger(
743 R.integer.recents_history_transition_duration);
744 mEmptyView.setVisibility(View.VISIBLE);
745 mEmptyView.animate()
746 .alpha(1f)
747 .translationY(0)
748 .setDuration(historyTransitionDuration)
Winsonc0d70582016-01-29 10:24:39 -0800749 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
Winson49df4202016-01-25 17:33:34 -0800750 .start();
751 }
752
Winson214f0f02016-01-26 13:37:37 -0800753 mHistoryView.hide(event.animate, stackRect.height(), mHistoryClearAllButton);
Winson49df4202016-01-25 17:33:34 -0800754 }
755
756 public final void onBusEvent(ShowHistoryButtonEvent event) {
757 showHistoryButton(150, event.translate);
758 }
759
760 public final void onBusEvent(HideHistoryButtonEvent event) {
761 hideHistoryButton(100, true /* translate */);
762 }
763
Winsonc29ff002015-11-20 16:00:45 -0800764 /**
765 * Shows the history button.
766 */
Winson49df4202016-01-25 17:33:34 -0800767 private void showHistoryButton(final int duration, final boolean translate) {
768 final ReferenceCountedTrigger postAnimationTrigger = new ReferenceCountedTrigger();
Winsonf24f2162016-01-05 12:11:55 -0800769 if (mHistoryButton.getVisibility() == View.INVISIBLE) {
770 mHistoryButton.setVisibility(View.VISIBLE);
771 mHistoryButton.setAlpha(0f);
Winson49df4202016-01-25 17:33:34 -0800772 if (translate) {
773 mHistoryButton.setTranslationY(-mHistoryButton.getMeasuredHeight() * 0.25f);
Winson214f0f02016-01-26 13:37:37 -0800774 } else {
775 mHistoryButton.setTranslationY(0f);
Winson49df4202016-01-25 17:33:34 -0800776 }
777 postAnimationTrigger.addLastDecrementRunnable(new Runnable() {
Winsonf24f2162016-01-05 12:11:55 -0800778 @Override
779 public void run() {
Winson49df4202016-01-25 17:33:34 -0800780 if (translate) {
781 mHistoryButton.animate()
782 .translationY(0f);
783 }
Winsonf24f2162016-01-05 12:11:55 -0800784 mHistoryButton.animate()
785 .alpha(1f)
786 .setDuration(duration)
Winsonc0d70582016-01-29 10:24:39 -0800787 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
Winsonf24f2162016-01-05 12:11:55 -0800788 .withLayer()
789 .start();
790 }
791 });
792 }
Winson49df4202016-01-25 17:33:34 -0800793 postAnimationTrigger.flushLastDecrementRunnables();
Winsonc29ff002015-11-20 16:00:45 -0800794 }
795
796 /**
797 * Hides the history button.
798 */
Winson49df4202016-01-25 17:33:34 -0800799 private void hideHistoryButton(int duration, boolean translate) {
800 final ReferenceCountedTrigger postAnimationTrigger = new ReferenceCountedTrigger();
801 hideHistoryButton(duration, translate, postAnimationTrigger);
Winson Chungaaeaac12015-12-16 16:49:36 -0500802 postAnimationTrigger.flushLastDecrementRunnables();
Winson Chung9a742902015-12-11 10:25:40 -0500803 }
804
Winson49df4202016-01-25 17:33:34 -0800805 /**
806 * Hides the history button.
807 */
808 private void hideHistoryButton(int duration, boolean translate,
809 final ReferenceCountedTrigger postAnimationTrigger) {
Winsonf24f2162016-01-05 12:11:55 -0800810 if (mHistoryButton.getVisibility() == View.VISIBLE) {
Winson49df4202016-01-25 17:33:34 -0800811 if (translate) {
812 mHistoryButton.animate()
813 .translationY(-mHistoryButton.getMeasuredHeight() * 0.25f);
814 }
Winsonf24f2162016-01-05 12:11:55 -0800815 mHistoryButton.animate()
816 .alpha(0f)
817 .setDuration(duration)
Winsonc0d70582016-01-29 10:24:39 -0800818 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
Winsonf24f2162016-01-05 12:11:55 -0800819 .withEndAction(new Runnable() {
820 @Override
821 public void run() {
822 mHistoryButton.setVisibility(View.INVISIBLE);
Winson49df4202016-01-25 17:33:34 -0800823 postAnimationTrigger.decrement();
Winsonf24f2162016-01-05 12:11:55 -0800824 }
825 })
826 .withLayer()
827 .start();
Winson49df4202016-01-25 17:33:34 -0800828 postAnimationTrigger.increment();
Winsonf24f2162016-01-05 12:11:55 -0800829 }
Winsonc29ff002015-11-20 16:00:45 -0800830 }
831
Winson4165d3362015-10-10 14:40:35 -0700832 /**
833 * Updates the dock region to match the specified dock state.
834 */
Winson3e874742016-01-07 10:08:17 -0800835 private void updateVisibleDockRegions(TaskStack.DockState[] newDockStates,
836 boolean isDefaultDockState, int overrideAlpha, boolean animateAlpha,
837 boolean animateBounds) {
Winsonc5fd3502016-01-18 15:18:37 -0800838 ArraySet<TaskStack.DockState> newDockStatesSet = Utilities.arrayToSet(newDockStates,
839 new ArraySet<TaskStack.DockState>());
Winson036693c2016-01-14 17:16:06 -0800840 ArrayList<TaskStack.DockState> visDockStates = mTouchHandler.getVisibleDockStates();
841 for (int i = visDockStates.size() - 1; i >= 0; i--) {
842 TaskStack.DockState dockState = visDockStates.get(i);
Winson882072b2015-10-12 11:26:33 -0700843 TaskStack.DockState.ViewState viewState = dockState.viewState;
844 if (newDockStates == null || !newDockStatesSet.contains(dockState)) {
845 // This is no longer visible, so hide it
Winson3e874742016-01-07 10:08:17 -0800846 viewState.startAnimation(null, 0, DOCK_AREA_OVERLAY_TRANSITION_DURATION,
Winsonc0d70582016-01-29 10:24:39 -0800847 Interpolators.ALPHA_OUT, animateAlpha, animateBounds);
Winson882072b2015-10-12 11:26:33 -0700848 } else {
849 // This state is now visible, update the bounds and show it
850 int alpha = (overrideAlpha != -1 ? overrideAlpha : viewState.dockAreaAlpha);
Winson3e874742016-01-07 10:08:17 -0800851 Rect bounds = isDefaultDockState
852 ? dockState.getPreDockedBounds(getMeasuredWidth(), getMeasuredHeight())
853 : dockState.getDockedBounds(getMeasuredWidth(), getMeasuredHeight(),
854 mDividerSize, mSystemInsets, getResources());
855 if (viewState.dockAreaOverlay.getCallback() != this) {
856 viewState.dockAreaOverlay.setCallback(this);
857 viewState.dockAreaOverlay.setBounds(bounds);
858 }
859 viewState.startAnimation(bounds, alpha, DOCK_AREA_OVERLAY_TRANSITION_DURATION,
Winsonc0d70582016-01-29 10:24:39 -0800860 Interpolators.ALPHA_IN, animateAlpha, animateBounds);
Winson882072b2015-10-12 11:26:33 -0700861 }
Winson4165d3362015-10-10 14:40:35 -0700862 }
Winson4165d3362015-10-10 14:40:35 -0700863 }
Filip Gruszczynski14b4e572015-11-03 15:53:55 -0800864
Winson49df4202016-01-25 17:33:34 -0800865 /**
866 * Animates the background scrim to the given {@param alpha}.
867 */
868 private void animateBackgroundScrim(float alpha, int duration) {
869 Utilities.cancelAnimationWithoutCallbacks(mBackgroundScrimAnimator);
870 int alphaInt = (int) (alpha * 255);
871 mBackgroundScrimAnimator = ObjectAnimator.ofInt(mBackgroundScrim, Utilities.DRAWABLE_ALPHA,
872 mBackgroundScrim.getAlpha(), alphaInt);
873 mBackgroundScrimAnimator.setDuration(duration);
874 mBackgroundScrimAnimator.setInterpolator(alphaInt > mBackgroundScrim.getAlpha()
Winsonc0d70582016-01-29 10:24:39 -0800875 ? Interpolators.ALPHA_OUT
876 : Interpolators.ALPHA_IN);
Winson49df4202016-01-25 17:33:34 -0800877 mBackgroundScrimAnimator.start();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -0800878 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800879}