blob: e0d048660b96632eaf7a6ec8e51c832be1b8aa60 [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;
Winson49df4202016-01-25 17:33:34 -080022import android.animation.ObjectAnimator;
Jorim Jaggi192086e2016-03-11 17:17:03 +010023import android.app.ActivityOptions.OnAnimationStartedListener;
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;
Winson882072b2015-10-12 11:26:33 -070031import android.util.ArraySet;
Winson Chung8e548f72014-06-24 14:40:53 -070032import android.util.AttributeSet;
Jorim Jaggic69bd222016-03-15 14:38:37 +010033import android.view.AppTransitionAnimationSpec;
34import android.view.IAppTransitionAnimationSpecsFuture;
Winson Chungecd9b302014-04-16 17:07:18 -070035import android.view.LayoutInflater;
Winsonbe7607a2015-10-01 17:24:51 -070036import android.view.MotionEvent;
Winsonc29ff002015-11-20 16:00:45 -080037import android.view.View;
Winson231bc9c2016-02-09 12:31:00 -080038import android.view.ViewDebug;
Winson49df4202016-01-25 17:33:34 -080039import android.view.ViewOutlineProvider;
Jorim Jaggi870ab5a2015-12-02 18:37:54 -080040import android.view.ViewPropertyAnimator;
Winson Chung653f70c22014-05-19 14:49:42 -070041import android.view.WindowInsets;
Winson Chung303e1ff2014-03-07 15:06:19 -080042import android.widget.FrameLayout;
Winson Chungde750de2015-12-11 10:26:06 -050043import android.widget.TextView;
Chris Wrenf6e9228b2016-01-26 18:04:35 -050044
Winsondc8de842016-01-06 15:21:41 -080045import com.android.internal.logging.MetricsLogger;
Chris Wrenf6e9228b2016-01-26 18:04:35 -050046import com.android.internal.logging.MetricsProto.MetricsEvent;
Winsonc0d70582016-01-29 10:24:39 -080047import com.android.systemui.Interpolators;
Winson Chungd16c5652015-01-26 16:11:07 -080048import com.android.systemui.R;
Winsone7f138c2015-10-22 16:15:21 -070049import com.android.systemui.recents.Recents;
Winsonbe7607a2015-10-01 17:24:51 -070050import com.android.systemui.recents.RecentsActivity;
Winsonb1e71d02015-11-23 12:40:23 -080051import com.android.systemui.recents.RecentsActivityLaunchState;
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;
Winson412e1802015-10-20 16:57:57 -070055import com.android.systemui.recents.events.activity.DismissRecentsToHomeAnimationStarted;
Jorim Jaggi192086e2016-03-11 17:17:03 +010056import com.android.systemui.recents.events.activity.DockedFirstAnimationFrameEvent;
Winson49df4202016-01-25 17:33:34 -080057import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationCompletedEvent;
Winson8f6ee482016-03-18 17:51:48 -070058import com.android.systemui.recents.events.activity.HideStackActionButtonEvent;
Winson Chung48f2cda2015-12-11 13:20:12 -050059import com.android.systemui.recents.events.activity.LaunchTaskEvent;
Winson8f6ee482016-03-18 17:51:48 -070060import com.android.systemui.recents.events.activity.ShowStackActionButtonEvent;
Winson3b6ba1a2016-03-22 15:37:54 -070061import com.android.systemui.recents.events.ui.AllTaskViewsDismissedEvent;
Winson3b6ba1a2016-03-22 15:37:54 -070062import com.android.systemui.recents.events.ui.DismissAllTaskViewsEvent;
Jorim Jaggidd98d412015-11-18 15:57:38 -080063import com.android.systemui.recents.events.ui.DraggingInRecentsEndedEvent;
64import com.android.systemui.recents.events.ui.DraggingInRecentsEvent;
Winsoneca4ab62015-11-04 10:50:28 -080065import com.android.systemui.recents.events.ui.dragndrop.DragDropTargetChangedEvent;
Winsonbe7607a2015-10-01 17:24:51 -070066import com.android.systemui.recents.events.ui.dragndrop.DragEndEvent;
67import com.android.systemui.recents.events.ui.dragndrop.DragStartEvent;
Winson Chung9a742902015-12-11 10:25:40 -050068import com.android.systemui.recents.misc.ReferenceCountedTrigger;
Winson Chung1f24c7e2014-07-11 17:06:48 -070069import com.android.systemui.recents.misc.SystemServicesProxy;
Winsonc5fd3502016-01-18 15:18:37 -080070import com.android.systemui.recents.misc.Utilities;
Winson Chung303e1ff2014-03-07 15:06:19 -080071import com.android.systemui.recents.model.Task;
72import com.android.systemui.recents.model.TaskStack;
Jorim Jaggic69bd222016-03-15 14:38:37 +010073import com.android.systemui.recents.views.RecentsTransitionHelper.AnimationSpecComposer;
Jorim Jaggi870ab5a2015-12-02 18:37:54 -080074import com.android.systemui.stackdivider.WindowManagerProxy;
75import com.android.systemui.statusbar.FlingAnimationUtils;
Winson Chung303e1ff2014-03-07 15:06:19 -080076
77import java.util.ArrayList;
Winson Chung6ac8bd62015-01-07 16:38:35 -080078import java.util.List;
Winson Chung303e1ff2014-03-07 15:06:19 -080079
Winson Chung303e1ff2014-03-07 15:06:19 -080080/**
81 * This view is the the top level layout that contains TaskStacks (which are laid out according
82 * to their SpaceNode bounds.
83 */
Winson Chung48f2cda2015-12-11 13:20:12 -050084public class RecentsView extends FrameLayout {
Winson Chung47c4c692014-03-17 10:17:11 -070085
Winson3e874742016-01-07 10:08:17 -080086 private static final int DOCK_AREA_OVERLAY_TRANSITION_DURATION = 135;
Winson49df4202016-01-25 17:33:34 -080087 private static final int DEFAULT_UPDATE_SCRIM_DURATION = 200;
88 private static final float DEFAULT_SCRIM_ALPHA = 0.33f;
Jorim Jaggi6e18e002015-06-02 17:07:39 -070089
Winson3b6ba1a2016-03-22 15:37:54 -070090 private static final int SHOW_STACK_ACTION_BUTTON_DURATION = 150;
91 private static final int HIDE_STACK_ACTION_BUTTON_DURATION = 100;
92
Winson Chung9a742902015-12-11 10:25:40 -050093 private TaskStack mStack;
94 private TaskStackView mTaskStackView;
Winson8f6ee482016-03-18 17:51:48 -070095 private TextView mStackActionButton;
Winson196e8612016-03-15 15:20:17 -070096 private TextView mEmptyView;
Winson49df4202016-01-25 17:33:34 -080097
Winson Chung9a742902015-12-11 10:25:40 -050098 private boolean mAwaitingFirstLayout = true;
99 private boolean mLastTaskLaunchedWasFreeform;
Winson231bc9c2016-02-09 12:31:00 -0800100
101 @ViewDebug.ExportedProperty(category="recents")
Winson Chung9a742902015-12-11 10:25:40 -0500102 private Rect mSystemInsets = new Rect();
Winson3e874742016-01-07 10:08:17 -0800103 private int mDividerSize;
Winsonbe7607a2015-10-01 17:24:51 -0700104
Winsone8a4eff2016-03-28 16:20:35 -0700105 private Drawable mBackgroundScrim = new ColorDrawable(
106 Color.argb((int) (DEFAULT_SCRIM_ALPHA * 255), 0, 0, 0)).mutate();
Winson49df4202016-01-25 17:33:34 -0800107 private Animator mBackgroundScrimAnimator;
108
Winson Chung9a742902015-12-11 10:25:40 -0500109 private RecentsTransitionHelper mTransitionHelper;
Winson231bc9c2016-02-09 12:31:00 -0800110 @ViewDebug.ExportedProperty(deepExport=true, prefix="touch_")
Winson Chung9a742902015-12-11 10:25:40 -0500111 private RecentsViewTouchHandler mTouchHandler;
Winson Chung9a742902015-12-11 10:25:40 -0500112 private final FlingAnimationUtils mFlingAnimationUtils;
Jorim Jaggi870ab5a2015-12-02 18:37:54 -0800113
Winson Chung303e1ff2014-03-07 15:06:19 -0800114 public RecentsView(Context context) {
Jorim Jaggi870ab5a2015-12-02 18:37:54 -0800115 this(context, null);
Winson Chung8e548f72014-06-24 14:40:53 -0700116 }
117
118 public RecentsView(Context context, AttributeSet attrs) {
119 this(context, attrs, 0);
120 }
121
122 public RecentsView(Context context, AttributeSet attrs, int defStyleAttr) {
123 this(context, attrs, defStyleAttr, 0);
124 }
125
126 public RecentsView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
127 super(context, attrs, defStyleAttr, defStyleRes);
Winsonbe7607a2015-10-01 17:24:51 -0700128 setWillNotDraw(false);
Winson3e874742016-01-07 10:08:17 -0800129
130 SystemServicesProxy ssp = Recents.getSystemServices();
Winsona1ededd2016-03-25 12:23:12 -0700131 mTransitionHelper = new RecentsTransitionHelper(getContext());
Winson3e874742016-01-07 10:08:17 -0800132 mDividerSize = ssp.getDockedDividerSize(context);
Winsonbe7607a2015-10-01 17:24:51 -0700133 mTouchHandler = new RecentsViewTouchHandler(this);
Jorim Jaggi870ab5a2015-12-02 18:37:54 -0800134 mFlingAnimationUtils = new FlingAnimationUtils(context, 0.3f);
Winsonc29ff002015-11-20 16:00:45 -0800135
136 LayoutInflater inflater = LayoutInflater.from(context);
Winson8f6ee482016-03-18 17:51:48 -0700137 if (RecentsDebugFlags.Static.EnableStackActionButton) {
Winsona1ededd2016-03-25 12:23:12 -0700138 float cornerRadius = context.getResources().getDimensionPixelSize(
139 R.dimen.recents_task_view_rounded_corners_radius);
140 mStackActionButton = (TextView) inflater.inflate(R.layout.recents_stack_action_button,
141 this, false);
Winson3b6ba1a2016-03-22 15:37:54 -0700142 mStackActionButton.forceHasOverlappingRendering(false);
Winson8f6ee482016-03-18 17:51:48 -0700143 mStackActionButton.setOnClickListener(new View.OnClickListener() {
Winson91b225d2016-02-16 15:18:07 -0800144 @Override
145 public void onClick(View v) {
Winson3b6ba1a2016-03-22 15:37:54 -0700146 EventBus.getDefault().send(new DismissAllTaskViewsEvent());
Winson91b225d2016-02-16 15:18:07 -0800147 }
148 });
Winson8f6ee482016-03-18 17:51:48 -0700149 addView(mStackActionButton);
150 mStackActionButton.setClipToOutline(true);
151 mStackActionButton.setOutlineProvider(new ViewOutlineProvider() {
Winson91b225d2016-02-16 15:18:07 -0800152 @Override
153 public void getOutline(View view, Outline outline) {
154 outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), cornerRadius);
155 }
156 });
157 }
Winson196e8612016-03-15 15:20:17 -0700158 mEmptyView = (TextView) inflater.inflate(R.layout.recents_empty, this, false);
Winson Chung9a742902015-12-11 10:25:40 -0500159 addView(mEmptyView);
Winson Chungd16c5652015-01-26 16:11:07 -0800160 }
161
Winsona1ededd2016-03-25 12:23:12 -0700162 /**
163 * Called from RecentsActivity when it is relaunched.
164 */
165 public void onReload(boolean isResumingFromVisible, boolean isTaskStackEmpty) {
Winson53ec42c2015-10-28 15:55:35 -0700166 RecentsConfiguration config = Recents.getConfiguration();
Winson Chung9a742902015-12-11 10:25:40 -0500167 RecentsActivityLaunchState launchState = config.getLaunchState();
Winson88737542016-02-17 13:27:33 -0800168
Winsona1ededd2016-03-25 12:23:12 -0700169 if (mTaskStackView == null) {
Winson88737542016-02-17 13:27:33 -0800170 isResumingFromVisible = false;
Winson88737542016-02-17 13:27:33 -0800171 mTaskStackView = new TaskStackView(getContext());
Winson59924fe2016-03-17 14:13:18 -0700172 mTaskStackView.setSystemInsets(mSystemInsets);
Winson147ecaf2015-09-16 16:49:55 -0700173 addView(mTaskStackView);
Winson Chung303e1ff2014-03-07 15:06:19 -0800174 }
Winson Chung9a742902015-12-11 10:25:40 -0500175
Winson88737542016-02-17 13:27:33 -0800176 // Reset the state
177 mAwaitingFirstLayout = !isResumingFromVisible;
178 mLastTaskLaunchedWasFreeform = false;
179
180 // Update the stack
Winsona1ededd2016-03-25 12:23:12 -0700181 mTaskStackView.onReload(isResumingFromVisible);
Winson88737542016-02-17 13:27:33 -0800182
183 if (isResumingFromVisible) {
184 // If we are already visible, then restore the background scrim
Winsone8a4eff2016-03-28 16:20:35 -0700185 animateBackgroundScrim(1f, DEFAULT_UPDATE_SCRIM_DURATION);
Winson49df4202016-01-25 17:33:34 -0800186 } else {
Winson88737542016-02-17 13:27:33 -0800187 // If we are already occluded by the app, then set the final background scrim alpha now.
188 // Otherwise, defer until the enter animation completes to animate the scrim alpha with
189 // the tasks for the home animation.
Winsonc69249f2016-03-28 13:38:39 -0700190 if (launchState.launchedViaDockGesture || launchState.launchedFromApp
Winsona1ededd2016-03-25 12:23:12 -0700191 || isTaskStackEmpty) {
Winsone8a4eff2016-03-28 16:20:35 -0700192 mBackgroundScrim.setAlpha(255);
Winson88737542016-02-17 13:27:33 -0800193 } else {
194 mBackgroundScrim.setAlpha(0);
195 }
Winson49df4202016-01-25 17:33:34 -0800196 }
Winsona1ededd2016-03-25 12:23:12 -0700197 }
198
199 /**
200 * Called from RecentsActivity when the task stack is updated.
201 */
202 public void updateStack(TaskStack stack) {
203 mStack = stack;
204 mTaskStackView.setTasks(stack, true /* allowNotifyStackChanges */);
Winson49df4202016-01-25 17:33:34 -0800205
Winson Chung9a742902015-12-11 10:25:40 -0500206 // Update the top level view's visibilities
Winson4b057c62016-01-12 15:01:52 -0800207 if (stack.getTaskCount() > 0) {
Winson Chung9a742902015-12-11 10:25:40 -0500208 hideEmptyView();
Winsonc29ff002015-11-20 16:00:45 -0800209 } else {
Winson196e8612016-03-15 15:20:17 -0700210 showEmptyView(R.string.recents_empty_message);
Winsonc29ff002015-11-20 16:00:45 -0800211 }
Winson Chung19fc1172014-07-31 18:40:03 -0700212 }
213
Winsonb1e71d02015-11-23 12:40:23 -0800214 /**
Winsona1ededd2016-03-25 12:23:12 -0700215 * Returns the current TaskStack.
216 */
217 public TaskStack getStack() {
218 return mStack;
219 }
220
Winsone8a4eff2016-03-28 16:20:35 -0700221 /*
222 * Returns the window background scrim.
223 */
224 public Drawable getBackgroundScrim() {
225 return mBackgroundScrim;
226 }
227
Winsona1ededd2016-03-25 12:23:12 -0700228 /**
Winsonb1e71d02015-11-23 12:40:23 -0800229 * Returns whether the last task launched was in the freeform stack or not.
230 */
231 public boolean isLastTaskLaunchedFreeform() {
232 return mLastTaskLaunchedWasFreeform;
233 }
234
Winson Chung1e8d71b2014-05-16 17:05:22 -0700235 /** Launches the focused task from the first stack if possible */
Winson42329522016-02-05 10:39:46 -0800236 public boolean launchFocusedTask(int logEvent) {
Winson147ecaf2015-09-16 16:49:55 -0700237 if (mTaskStackView != null) {
Winson142af422015-11-09 10:39:57 -0800238 Task task = mTaskStackView.getFocusedTask();
239 if (task != null) {
240 TaskView taskView = mTaskStackView.getChildViewForTask(task);
Winson Chung48f2cda2015-12-11 13:20:12 -0500241 EventBus.getDefault().send(new LaunchTaskEvent(taskView, task, null,
242 INVALID_STACK_ID, false));
Winson42329522016-02-05 10:39:46 -0800243
244 if (logEvent != 0) {
245 MetricsLogger.action(getContext(), logEvent,
246 task.key.getComponent().toString());
247 }
Winson142af422015-11-09 10:39:57 -0800248 return true;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700249 }
250 }
Winson Chung1e8d71b2014-05-16 17:05:22 -0700251 return false;
252 }
253
Winsona0731a12015-12-02 15:10:14 -0800254 /** Launches the task that recents was launched from if possible */
255 public boolean launchPreviousTask() {
256 if (mTaskStackView != null) {
257 TaskStack stack = mTaskStackView.getStack();
258 Task task = stack.getLaunchTarget();
259 if (task != null) {
260 TaskView taskView = mTaskStackView.getChildViewForTask(task);
Winson Chung48f2cda2015-12-11 13:20:12 -0500261 EventBus.getDefault().send(new LaunchTaskEvent(taskView, task, null,
262 INVALID_STACK_ID, false));
Winsona0731a12015-12-02 15:10:14 -0800263 return true;
264 }
265 }
266 return false;
267 }
268
Skuhne8aa7d162015-03-20 13:40:53 -0700269 /** Launches a given task. */
Filip Gruszczynskif48b5852015-10-13 10:28:22 -0700270 public boolean launchTask(Task task, Rect taskBounds, int destinationStack) {
Winson147ecaf2015-09-16 16:49:55 -0700271 if (mTaskStackView != null) {
Skuhne8aa7d162015-03-20 13:40:53 -0700272 // Iterate the stack views and try and find the given task.
Winson147ecaf2015-09-16 16:49:55 -0700273 List<TaskView> taskViews = mTaskStackView.getTaskViews();
Skuhne8aa7d162015-03-20 13:40:53 -0700274 int taskViewCount = taskViews.size();
275 for (int j = 0; j < taskViewCount; j++) {
276 TaskView tv = taskViews.get(j);
277 if (tv.getTask() == task) {
Winson Chung48f2cda2015-12-11 13:20:12 -0500278 EventBus.getDefault().send(new LaunchTaskEvent(tv, task, taskBounds,
279 destinationStack, false));
Skuhne8aa7d162015-03-20 13:40:53 -0700280 return true;
281 }
282 }
283 }
284 return false;
285 }
286
Winson Chung9a742902015-12-11 10:25:40 -0500287 /**
288 * Hides the task stack and shows the empty view.
289 */
Winson196e8612016-03-15 15:20:17 -0700290 public void showEmptyView(int msgResId) {
Winson Chung9a742902015-12-11 10:25:40 -0500291 mTaskStackView.setVisibility(View.INVISIBLE);
Winson196e8612016-03-15 15:20:17 -0700292 mEmptyView.setText(msgResId);
Winson Chung9a742902015-12-11 10:25:40 -0500293 mEmptyView.setVisibility(View.VISIBLE);
294 mEmptyView.bringToFront();
Winson8f6ee482016-03-18 17:51:48 -0700295 if (RecentsDebugFlags.Static.EnableStackActionButton) {
296 mStackActionButton.bringToFront();
Winson91b225d2016-02-16 15:18:07 -0800297 }
Winson Chung9a742902015-12-11 10:25:40 -0500298 }
299
300 /**
301 * Shows the task stack and hides the empty view.
302 */
303 public void hideEmptyView() {
304 mEmptyView.setVisibility(View.INVISIBLE);
305 mTaskStackView.setVisibility(View.VISIBLE);
Winson Chung9a742902015-12-11 10:25:40 -0500306 mTaskStackView.bringToFront();
Winson8f6ee482016-03-18 17:51:48 -0700307 if (RecentsDebugFlags.Static.EnableStackActionButton) {
308 mStackActionButton.bringToFront();
Winson91b225d2016-02-16 15:18:07 -0800309 }
Winson Chung772b6b12014-07-03 15:54:02 -0700310 }
311
Winsonbe7607a2015-10-01 17:24:51 -0700312 @Override
313 protected void onAttachedToWindow() {
314 EventBus.getDefault().register(this, RecentsActivity.EVENT_BUS_PRIORITY + 1);
Winsonc8a4cdc2016-01-19 11:30:51 -0800315 EventBus.getDefault().register(mTouchHandler, RecentsActivity.EVENT_BUS_PRIORITY + 2);
Winsonbe7607a2015-10-01 17:24:51 -0700316 super.onAttachedToWindow();
317 }
318
319 @Override
320 protected void onDetachedFromWindow() {
321 super.onDetachedFromWindow();
322 EventBus.getDefault().unregister(this);
323 EventBus.getDefault().unregister(mTouchHandler);
324 }
325
Winson Chungf7bca432014-04-30 17:11:13 -0700326 /**
327 * This is called with the full size of the window since we are handling our own insets.
328 */
Winson Chung303e1ff2014-03-07 15:06:19 -0800329 @Override
330 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
331 int width = MeasureSpec.getSize(widthMeasureSpec);
332 int height = MeasureSpec.getSize(heightMeasureSpec);
Winson Chungbd912972014-03-18 14:36:35 -0700333
Winson59924fe2016-03-17 14:13:18 -0700334 if (mTaskStackView.getVisibility() != GONE) {
Winson147ecaf2015-09-16 16:49:55 -0700335 mTaskStackView.measure(widthMeasureSpec, heightMeasureSpec);
Winson Chung303e1ff2014-03-07 15:06:19 -0800336 }
337
Winson49df4202016-01-25 17:33:34 -0800338 // Measure the empty view to the full size of the screen
339 if (mEmptyView.getVisibility() != GONE) {
Winson196e8612016-03-15 15:20:17 -0700340 measureChild(mEmptyView, MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST),
341 MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST));
Winson49df4202016-01-25 17:33:34 -0800342 }
Winson Chung9a742902015-12-11 10:25:40 -0500343
Winson8f6ee482016-03-18 17:51:48 -0700344 if (RecentsDebugFlags.Static.EnableStackActionButton) {
345 // Measure the stack action button within the constraints of the space above the stack
Winson47c78f92016-03-31 16:02:30 -0700346 Rect buttonBounds = mTaskStackView.mLayoutAlgorithm.mStackActionButtonRect;
Winson8f6ee482016-03-18 17:51:48 -0700347 measureChild(mStackActionButton,
Winson19852372016-03-30 18:26:49 -0700348 MeasureSpec.makeMeasureSpec(buttonBounds.width(), MeasureSpec.AT_MOST),
349 MeasureSpec.makeMeasureSpec(buttonBounds.height(), MeasureSpec.AT_MOST));
Winson214f0f02016-01-26 13:37:37 -0800350 }
Winson Chung9a742902015-12-11 10:25:40 -0500351
Winson Chung303e1ff2014-03-07 15:06:19 -0800352 setMeasuredDimension(width, height);
353 }
354
Winson Chungf7bca432014-04-30 17:11:13 -0700355 /**
356 * This is called with the full size of the window since we are handling our own insets.
357 */
Winson Chung303e1ff2014-03-07 15:06:19 -0800358 @Override
359 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
Winson59924fe2016-03-17 14:13:18 -0700360 if (mTaskStackView.getVisibility() != GONE) {
Winson147ecaf2015-09-16 16:49:55 -0700361 mTaskStackView.layout(left, top, left + getMeasuredWidth(), top + getMeasuredHeight());
Winson Chung303e1ff2014-03-07 15:06:19 -0800362 }
Winsonbe7607a2015-10-01 17:24:51 -0700363
Winson Chung9a742902015-12-11 10:25:40 -0500364 // Layout the empty view
Winson49df4202016-01-25 17:33:34 -0800365 if (mEmptyView.getVisibility() != GONE) {
Winson196e8612016-03-15 15:20:17 -0700366 int leftRightInsets = mSystemInsets.left + mSystemInsets.right;
367 int topBottomInsets = mSystemInsets.top + mSystemInsets.bottom;
368 int childWidth = mEmptyView.getMeasuredWidth();
369 int childHeight = mEmptyView.getMeasuredHeight();
370 int childLeft = left + Math.max(0, (right - left - leftRightInsets - childWidth)) / 2;
371 int childTop = top + Math.max(0, (bottom - top - topBottomInsets - childHeight)) / 2;
372 mEmptyView.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
Winson49df4202016-01-25 17:33:34 -0800373 }
Winson Chung9a742902015-12-11 10:25:40 -0500374
Winson8f6ee482016-03-18 17:51:48 -0700375 if (RecentsDebugFlags.Static.EnableStackActionButton) {
376 // Layout the stack action button such that its drawable is start-aligned with the
377 // stack, vertically centered in the available space above the stack
Winson19852372016-03-30 18:26:49 -0700378 Rect buttonBounds = getStackActionButtonBoundsFromStackLayout();
379 mStackActionButton.layout(buttonBounds.left, buttonBounds.top, buttonBounds.right,
380 buttonBounds.bottom);
Winson214f0f02016-01-26 13:37:37 -0800381 }
382
Winsonb1e71d02015-11-23 12:40:23 -0800383 if (mAwaitingFirstLayout) {
384 mAwaitingFirstLayout = false;
385
386 // If launched via dragging from the nav bar, then we should translate the whole view
387 // down offscreen
388 RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState();
389 if (launchState.launchedViaDragGesture) {
390 setTranslationY(getMeasuredHeight());
Jorim Jaggi0ca88262015-12-07 17:15:16 -0800391 } else {
392 setTranslationY(0f);
Winsonb1e71d02015-11-23 12:40:23 -0800393 }
394 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800395 }
396
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700397 @Override
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700398 public WindowInsets onApplyWindowInsets(WindowInsets insets) {
Winson35f30502015-09-28 11:24:36 -0700399 mSystemInsets.set(insets.getSystemWindowInsets());
Winson59924fe2016-03-17 14:13:18 -0700400 mTaskStackView.setSystemInsets(mSystemInsets);
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700401 requestLayout();
Winsonc29ff002015-11-20 16:00:45 -0800402 return insets;
Winson Chung8eaeb7d2014-06-25 15:10:59 -0700403 }
404
Winsonbe7607a2015-10-01 17:24:51 -0700405 @Override
406 public boolean onInterceptTouchEvent(MotionEvent ev) {
407 return mTouchHandler.onInterceptTouchEvent(ev);
408 }
409
410 @Override
411 public boolean onTouchEvent(MotionEvent ev) {
412 return mTouchHandler.onTouchEvent(ev);
413 }
414
415 @Override
Winsonbe8e6962016-02-01 14:27:52 -0800416 public void onDrawForeground(Canvas canvas) {
417 super.onDrawForeground(canvas);
418
Winson036693c2016-01-14 17:16:06 -0800419 ArrayList<TaskStack.DockState> visDockStates = mTouchHandler.getVisibleDockStates();
420 for (int i = visDockStates.size() - 1; i >= 0; i--) {
421 Drawable d = visDockStates.get(i).viewState.dockAreaOverlay;
Winson882072b2015-10-12 11:26:33 -0700422 if (d.getAlpha() > 0) {
423 d.draw(canvas);
424 }
Winsonbe7607a2015-10-01 17:24:51 -0700425 }
426 }
427
Winson4165d3362015-10-10 14:40:35 -0700428 @Override
429 protected boolean verifyDrawable(Drawable who) {
Winson036693c2016-01-14 17:16:06 -0800430 ArrayList<TaskStack.DockState> visDockStates = mTouchHandler.getVisibleDockStates();
431 for (int i = visDockStates.size() - 1; i >= 0; i--) {
432 Drawable d = visDockStates.get(i).viewState.dockAreaOverlay;
Winson882072b2015-10-12 11:26:33 -0700433 if (d == who) {
434 return true;
435 }
436 }
437 return super.verifyDrawable(who);
Winson4165d3362015-10-10 14:40:35 -0700438 }
439
Winsonbe7607a2015-10-01 17:24:51 -0700440 /**** EventBus Events ****/
441
Winson Chung48f2cda2015-12-11 13:20:12 -0500442 public final void onBusEvent(LaunchTaskEvent event) {
443 mLastTaskLaunchedWasFreeform = event.task.isFreeformTask();
444 mTransitionHelper.launchTaskFromRecents(mStack, event.task, mTaskStackView, event.taskView,
445 event.screenPinningRequested, event.targetTaskBounds, event.targetTaskStack);
446 }
447
Winsonef064132016-01-05 12:11:31 -0800448 public final void onBusEvent(DismissRecentsToHomeAnimationStarted event) {
Winson50448632016-02-01 18:04:59 -0800449 int taskViewExitToHomeDuration = TaskStackAnimationHelper.EXIT_TO_HOME_TRANSLATION_DURATION;
Winson8f6ee482016-03-18 17:51:48 -0700450 if (RecentsDebugFlags.Static.EnableStackActionButton) {
451 // Hide the stack action button
452 hideStackActionButton(taskViewExitToHomeDuration, false /* translate */);
Winson91b225d2016-02-16 15:18:07 -0800453 }
Winson49df4202016-01-25 17:33:34 -0800454 animateBackgroundScrim(0f, taskViewExitToHomeDuration);
Winsonef064132016-01-05 12:11:31 -0800455 }
456
Winsonbe7607a2015-10-01 17:24:51 -0700457 public final void onBusEvent(DragStartEvent event) {
Winson882072b2015-10-12 11:26:33 -0700458 updateVisibleDockRegions(mTouchHandler.getDockStatesForCurrentOrientation(),
Winson3e874742016-01-07 10:08:17 -0800459 true /* isDefaultDockState */, TaskStack.DockState.NONE.viewState.dockAreaAlpha,
460 true /* animateAlpha */, false /* animateBounds */);
Winsonbe7607a2015-10-01 17:24:51 -0700461 }
462
Winsoneca4ab62015-11-04 10:50:28 -0800463 public final void onBusEvent(DragDropTargetChangedEvent event) {
464 if (event.dropTarget == null || !(event.dropTarget instanceof TaskStack.DockState)) {
Winson882072b2015-10-12 11:26:33 -0700465 updateVisibleDockRegions(mTouchHandler.getDockStatesForCurrentOrientation(),
Winson3e874742016-01-07 10:08:17 -0800466 true /* isDefaultDockState */, TaskStack.DockState.NONE.viewState.dockAreaAlpha,
467 true /* animateAlpha */, true /* animateBounds */);
Winson882072b2015-10-12 11:26:33 -0700468 } else {
Winsoneca4ab62015-11-04 10:50:28 -0800469 final TaskStack.DockState dockState = (TaskStack.DockState) event.dropTarget;
Winson3e874742016-01-07 10:08:17 -0800470 updateVisibleDockRegions(new TaskStack.DockState[] {dockState},
471 false /* isDefaultDockState */, -1, true /* animateAlpha */,
472 true /* animateBounds */);
Winson882072b2015-10-12 11:26:33 -0700473 }
Winson19852372016-03-30 18:26:49 -0700474 if (mStackActionButton != null) {
475 event.addPostAnimationCallback(new Runnable() {
476 @Override
477 public void run() {
478 // Move the clear all button to its new position
479 Rect buttonBounds = getStackActionButtonBoundsFromStackLayout();
480 mStackActionButton.setLeftTopRightBottom(buttonBounds.left, buttonBounds.top,
481 buttonBounds.right, buttonBounds.bottom);
482 }
483 });
484 }
Winsonbe7607a2015-10-01 17:24:51 -0700485 }
486
487 public final void onBusEvent(final DragEndEvent event) {
Winson479f7442015-11-25 15:16:27 -0800488 // Handle the case where we drop onto a dock region
489 if (event.dropTarget instanceof TaskStack.DockState) {
Winson3e874742016-01-07 10:08:17 -0800490 final TaskStack.DockState dockState = (TaskStack.DockState) event.dropTarget;
491
492 // Hide the dock region
493 updateVisibleDockRegions(null, false /* isDefaultDockState */, -1,
494 false /* animateAlpha */, false /* animateBounds */);
495
Winsonf24f2162016-01-05 12:11:55 -0800496 TaskStackLayoutAlgorithm stackLayout = mTaskStackView.getStackAlgorithm();
497 TaskStackViewScroller stackScroller = mTaskStackView.getScroller();
498 TaskViewTransform tmpTransform = new TaskViewTransform();
Winsoneca4ab62015-11-04 10:50:28 -0800499
Winson3e874742016-01-07 10:08:17 -0800500 // We translated the view but we need to animate it back from the current layout-space
501 // rect to its final layout-space rect
502 int x = (int) event.taskView.getTranslationX();
503 int y = (int) event.taskView.getTranslationY();
504 Rect taskViewRect = new Rect(event.taskView.getLeft(), event.taskView.getTop(),
505 event.taskView.getRight(), event.taskView.getBottom());
506 taskViewRect.offset(x, y);
507 event.taskView.setTranslationX(0);
508 event.taskView.setTranslationY(0);
509 event.taskView.setLeftTopRightBottom(taskViewRect.left, taskViewRect.top,
510 taskViewRect.right, taskViewRect.bottom);
511
Jorim Jaggi192086e2016-03-11 17:17:03 +0100512 final OnAnimationStartedListener startedListener = new OnAnimationStartedListener() {
513 @Override
514 public void onAnimationStarted() {
515 EventBus.getDefault().send(new DockedFirstAnimationFrameEvent());
516 mTaskStackView.getStack().removeTask(event.task, AnimationProps.IMMEDIATE,
517 true /* fromDockGesture */);
518 }
519 };
Jorim Jaggic69bd222016-03-15 14:38:37 +0100520
521 // Dock the task and launch it
522 SystemServicesProxy ssp = Recents.getSystemServices();
523 ssp.startTaskInDockedMode(event.task.key.id, dockState.createMode);
524 final Rect taskRect = getTaskRect(event.taskView);
525 IAppTransitionAnimationSpecsFuture future = mTransitionHelper.getAppTransitionFuture(
526 new AnimationSpecComposer() {
527 @Override
528 public List<AppTransitionAnimationSpec> composeSpecs() {
529 return mTransitionHelper.composeDockAnimationSpec(
530 event.taskView, taskRect);
531 }
532 });
533 ssp.overridePendingAppTransitionMultiThumbFuture(future,
534 mTransitionHelper.wrapStartedListener(startedListener),
535 true /* scaleUp */);
Winsona0a8ae42015-12-01 10:43:02 -0800536
Chris Wrenf6e9228b2016-01-26 18:04:35 -0500537 MetricsLogger.action(mContext, MetricsEvent.ACTION_WINDOW_DOCK_DRAG_DROP);
Winson3e874742016-01-07 10:08:17 -0800538 } else {
539 // Animate the overlay alpha back to 0
540 updateVisibleDockRegions(null, true /* isDefaultDockState */, -1,
541 true /* animateAlpha */, false /* animateBounds */);
Winsonbe7607a2015-10-01 17:24:51 -0700542 }
543 }
Winson4165d3362015-10-10 14:40:35 -0700544
Jorim Jaggic69bd222016-03-15 14:38:37 +0100545 private Rect getTaskRect(TaskView taskView) {
546 int[] location = taskView.getLocationOnScreen();
547 int viewX = location[0];
548 int viewY = location[1];
549 return new Rect(viewX, viewY,
550 (int) (viewX + taskView.getWidth() * taskView.getScaleX()),
551 (int) (viewY + taskView.getHeight() * taskView.getScaleY()));
552 }
553
Jorim Jaggidd98d412015-11-18 15:57:38 -0800554 public final void onBusEvent(DraggingInRecentsEvent event) {
Jorim Jaggi54b1a6d2015-11-24 17:48:26 -0800555 if (mTaskStackView.getTaskViews().size() > 0) {
556 setTranslationY(event.distanceFromTop - mTaskStackView.getTaskViews().get(0).getY());
557 }
Jorim Jaggidd98d412015-11-18 15:57:38 -0800558 }
559
560 public final void onBusEvent(DraggingInRecentsEndedEvent event) {
Jorim Jaggi870ab5a2015-12-02 18:37:54 -0800561 ViewPropertyAnimator animator = animate();
Jorim Jaggi8fccfe22015-12-03 16:58:08 -0800562 if (event.velocity > mFlingAnimationUtils.getMinVelocityPxPerSecond()) {
Jorim Jaggi870ab5a2015-12-02 18:37:54 -0800563 animator.translationY(getHeight());
564 animator.withEndAction(new Runnable() {
565 @Override
566 public void run() {
567 WindowManagerProxy.getInstance().maximizeDockedStack();
568 }
569 });
570 mFlingAnimationUtils.apply(animator, getTranslationY(), getHeight(), event.velocity);
571 } else {
572 animator.translationY(0f);
573 animator.setListener(null);
574 mFlingAnimationUtils.apply(animator, getTranslationY(), 0, event.velocity);
575 }
576 animator.start();
Jorim Jaggidd98d412015-11-18 15:57:38 -0800577 }
578
Winson49df4202016-01-25 17:33:34 -0800579 public final void onBusEvent(EnterRecentsWindowAnimationCompletedEvent event) {
580 RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState();
Winsonc69249f2016-03-28 13:38:39 -0700581 if (!launchState.launchedViaDockGesture && !launchState.launchedFromApp
Jorim Jaggie161f082016-02-05 14:26:16 -0800582 && mStack.getTaskCount() > 0) {
Winsone8a4eff2016-03-28 16:20:35 -0700583 animateBackgroundScrim(1f,
Winson50448632016-02-01 18:04:59 -0800584 TaskStackAnimationHelper.ENTER_FROM_HOME_TRANSLATION_DURATION);
Winson49df4202016-01-25 17:33:34 -0800585 }
586 }
587
Winson3b6ba1a2016-03-22 15:37:54 -0700588 public final void onBusEvent(AllTaskViewsDismissedEvent event) {
589 hideStackActionButton(HIDE_STACK_ACTION_BUTTON_DURATION, true /* translate */);
590 }
591
592 public final void onBusEvent(DismissAllTaskViewsEvent event) {
593 SystemServicesProxy ssp = Recents.getSystemServices();
594 if (!ssp.hasDockedTask()) {
595 // Animate the background away only if we are dismissing Recents to home
596 animateBackgroundScrim(0f, DEFAULT_UPDATE_SCRIM_DURATION);
597 }
598 }
599
Winson8f6ee482016-03-18 17:51:48 -0700600 public final void onBusEvent(ShowStackActionButtonEvent event) {
601 if (!RecentsDebugFlags.Static.EnableStackActionButton) {
Winson91b225d2016-02-16 15:18:07 -0800602 return;
603 }
604
Winson3b6ba1a2016-03-22 15:37:54 -0700605 showStackActionButton(SHOW_STACK_ACTION_BUTTON_DURATION, event.translate);
Winson49df4202016-01-25 17:33:34 -0800606 }
607
Winson8f6ee482016-03-18 17:51:48 -0700608 public final void onBusEvent(HideStackActionButtonEvent event) {
609 if (!RecentsDebugFlags.Static.EnableStackActionButton) {
Winson91b225d2016-02-16 15:18:07 -0800610 return;
611 }
612
Winson3b6ba1a2016-03-22 15:37:54 -0700613 hideStackActionButton(HIDE_STACK_ACTION_BUTTON_DURATION, true /* translate */);
Winson49df4202016-01-25 17:33:34 -0800614 }
615
Winsonc29ff002015-11-20 16:00:45 -0800616 /**
Winson8f6ee482016-03-18 17:51:48 -0700617 * Shows the stack action button.
Winsonc29ff002015-11-20 16:00:45 -0800618 */
Winson8f6ee482016-03-18 17:51:48 -0700619 private void showStackActionButton(final int duration, final boolean translate) {
620 if (!RecentsDebugFlags.Static.EnableStackActionButton) {
Winson91b225d2016-02-16 15:18:07 -0800621 return;
622 }
623
Winson49df4202016-01-25 17:33:34 -0800624 final ReferenceCountedTrigger postAnimationTrigger = new ReferenceCountedTrigger();
Winson8f6ee482016-03-18 17:51:48 -0700625 if (mStackActionButton.getVisibility() == View.INVISIBLE) {
626 mStackActionButton.setVisibility(View.VISIBLE);
627 mStackActionButton.setAlpha(0f);
Winson49df4202016-01-25 17:33:34 -0800628 if (translate) {
Winson8f6ee482016-03-18 17:51:48 -0700629 mStackActionButton.setTranslationY(-mStackActionButton.getMeasuredHeight() * 0.25f);
Winson214f0f02016-01-26 13:37:37 -0800630 } else {
Winson8f6ee482016-03-18 17:51:48 -0700631 mStackActionButton.setTranslationY(0f);
Winson49df4202016-01-25 17:33:34 -0800632 }
633 postAnimationTrigger.addLastDecrementRunnable(new Runnable() {
Winsonf24f2162016-01-05 12:11:55 -0800634 @Override
635 public void run() {
Winson49df4202016-01-25 17:33:34 -0800636 if (translate) {
Winson8f6ee482016-03-18 17:51:48 -0700637 mStackActionButton.animate()
Winson49df4202016-01-25 17:33:34 -0800638 .translationY(0f);
639 }
Winson8f6ee482016-03-18 17:51:48 -0700640 mStackActionButton.animate()
Winsonf24f2162016-01-05 12:11:55 -0800641 .alpha(1f)
642 .setDuration(duration)
Winsonc0d70582016-01-29 10:24:39 -0800643 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
Winsonf24f2162016-01-05 12:11:55 -0800644 .start();
645 }
646 });
647 }
Winson49df4202016-01-25 17:33:34 -0800648 postAnimationTrigger.flushLastDecrementRunnables();
Winsonc29ff002015-11-20 16:00:45 -0800649 }
650
651 /**
Winson8f6ee482016-03-18 17:51:48 -0700652 * Hides the stack action button.
Winsonc29ff002015-11-20 16:00:45 -0800653 */
Winson8f6ee482016-03-18 17:51:48 -0700654 private void hideStackActionButton(int duration, boolean translate) {
655 if (!RecentsDebugFlags.Static.EnableStackActionButton) {
Winson91b225d2016-02-16 15:18:07 -0800656 return;
657 }
658
Winson49df4202016-01-25 17:33:34 -0800659 final ReferenceCountedTrigger postAnimationTrigger = new ReferenceCountedTrigger();
Winson8f6ee482016-03-18 17:51:48 -0700660 hideStackActionButton(duration, translate, postAnimationTrigger);
Winson Chungaaeaac12015-12-16 16:49:36 -0500661 postAnimationTrigger.flushLastDecrementRunnables();
Winson Chung9a742902015-12-11 10:25:40 -0500662 }
663
Winson49df4202016-01-25 17:33:34 -0800664 /**
Winson8f6ee482016-03-18 17:51:48 -0700665 * Hides the stack action button.
Winson49df4202016-01-25 17:33:34 -0800666 */
Winson8f6ee482016-03-18 17:51:48 -0700667 private void hideStackActionButton(int duration, boolean translate,
668 final ReferenceCountedTrigger postAnimationTrigger) {
669 if (!RecentsDebugFlags.Static.EnableStackActionButton) {
Winson91b225d2016-02-16 15:18:07 -0800670 return;
671 }
672
Winson8f6ee482016-03-18 17:51:48 -0700673 if (mStackActionButton.getVisibility() == View.VISIBLE) {
Winson49df4202016-01-25 17:33:34 -0800674 if (translate) {
Winson8f6ee482016-03-18 17:51:48 -0700675 mStackActionButton.animate()
676 .translationY(-mStackActionButton.getMeasuredHeight() * 0.25f);
Winson49df4202016-01-25 17:33:34 -0800677 }
Winson8f6ee482016-03-18 17:51:48 -0700678 mStackActionButton.animate()
Winsonf24f2162016-01-05 12:11:55 -0800679 .alpha(0f)
680 .setDuration(duration)
Winsonc0d70582016-01-29 10:24:39 -0800681 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
Winsonf24f2162016-01-05 12:11:55 -0800682 .withEndAction(new Runnable() {
683 @Override
684 public void run() {
Winson8f6ee482016-03-18 17:51:48 -0700685 mStackActionButton.setVisibility(View.INVISIBLE);
Winson49df4202016-01-25 17:33:34 -0800686 postAnimationTrigger.decrement();
Winsonf24f2162016-01-05 12:11:55 -0800687 }
688 })
Winsonf24f2162016-01-05 12:11:55 -0800689 .start();
Winson49df4202016-01-25 17:33:34 -0800690 postAnimationTrigger.increment();
Winsonf24f2162016-01-05 12:11:55 -0800691 }
Winsonc29ff002015-11-20 16:00:45 -0800692 }
693
Winson4165d3362015-10-10 14:40:35 -0700694 /**
695 * Updates the dock region to match the specified dock state.
696 */
Winson3e874742016-01-07 10:08:17 -0800697 private void updateVisibleDockRegions(TaskStack.DockState[] newDockStates,
698 boolean isDefaultDockState, int overrideAlpha, boolean animateAlpha,
699 boolean animateBounds) {
Winsonc5fd3502016-01-18 15:18:37 -0800700 ArraySet<TaskStack.DockState> newDockStatesSet = Utilities.arrayToSet(newDockStates,
701 new ArraySet<TaskStack.DockState>());
Winson036693c2016-01-14 17:16:06 -0800702 ArrayList<TaskStack.DockState> visDockStates = mTouchHandler.getVisibleDockStates();
703 for (int i = visDockStates.size() - 1; i >= 0; i--) {
704 TaskStack.DockState dockState = visDockStates.get(i);
Winson882072b2015-10-12 11:26:33 -0700705 TaskStack.DockState.ViewState viewState = dockState.viewState;
706 if (newDockStates == null || !newDockStatesSet.contains(dockState)) {
707 // This is no longer visible, so hide it
Winson3e874742016-01-07 10:08:17 -0800708 viewState.startAnimation(null, 0, DOCK_AREA_OVERLAY_TRANSITION_DURATION,
Winsonc0d70582016-01-29 10:24:39 -0800709 Interpolators.ALPHA_OUT, animateAlpha, animateBounds);
Winson882072b2015-10-12 11:26:33 -0700710 } else {
711 // This state is now visible, update the bounds and show it
712 int alpha = (overrideAlpha != -1 ? overrideAlpha : viewState.dockAreaAlpha);
Winson3e874742016-01-07 10:08:17 -0800713 Rect bounds = isDefaultDockState
714 ? dockState.getPreDockedBounds(getMeasuredWidth(), getMeasuredHeight())
715 : dockState.getDockedBounds(getMeasuredWidth(), getMeasuredHeight(),
716 mDividerSize, mSystemInsets, getResources());
717 if (viewState.dockAreaOverlay.getCallback() != this) {
718 viewState.dockAreaOverlay.setCallback(this);
719 viewState.dockAreaOverlay.setBounds(bounds);
720 }
721 viewState.startAnimation(bounds, alpha, DOCK_AREA_OVERLAY_TRANSITION_DURATION,
Winsonc0d70582016-01-29 10:24:39 -0800722 Interpolators.ALPHA_IN, animateAlpha, animateBounds);
Winson882072b2015-10-12 11:26:33 -0700723 }
Winson4165d3362015-10-10 14:40:35 -0700724 }
Winson4165d3362015-10-10 14:40:35 -0700725 }
Filip Gruszczynski14b4e572015-11-03 15:53:55 -0800726
Winson49df4202016-01-25 17:33:34 -0800727 /**
728 * Animates the background scrim to the given {@param alpha}.
729 */
730 private void animateBackgroundScrim(float alpha, int duration) {
731 Utilities.cancelAnimationWithoutCallbacks(mBackgroundScrimAnimator);
Winson47c78f92016-03-31 16:02:30 -0700732 // Calculate the absolute alpha to animate from
733 int fromAlpha = (int) ((mBackgroundScrim.getAlpha() / (DEFAULT_SCRIM_ALPHA * 255)) * 255);
734 int toAlpha = (int) (alpha * 255);
Winson49df4202016-01-25 17:33:34 -0800735 mBackgroundScrimAnimator = ObjectAnimator.ofInt(mBackgroundScrim, Utilities.DRAWABLE_ALPHA,
Winson47c78f92016-03-31 16:02:30 -0700736 fromAlpha, toAlpha);
Winson49df4202016-01-25 17:33:34 -0800737 mBackgroundScrimAnimator.setDuration(duration);
Winson47c78f92016-03-31 16:02:30 -0700738 mBackgroundScrimAnimator.setInterpolator(toAlpha > fromAlpha
739 ? Interpolators.ALPHA_IN
740 : Interpolators.ALPHA_OUT);
Winson49df4202016-01-25 17:33:34 -0800741 mBackgroundScrimAnimator.start();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -0800742 }
Winson19852372016-03-30 18:26:49 -0700743
744 /**
745 * @return the bounds of the stack action button.
746 */
747 private Rect getStackActionButtonBoundsFromStackLayout() {
748 Rect actionButtonRect = new Rect(mTaskStackView.mLayoutAlgorithm.mStackActionButtonRect);
749 int left = isLayoutRtl()
750 ? actionButtonRect.left - mStackActionButton.getPaddingLeft()
751 : actionButtonRect.right + mStackActionButton.getPaddingRight()
Winson47c78f92016-03-31 16:02:30 -0700752 - mStackActionButton.getMeasuredWidth();
Winson19852372016-03-30 18:26:49 -0700753 int top = actionButtonRect.top +
754 (actionButtonRect.height() - mStackActionButton.getMeasuredHeight()) / 2;
Winson47c78f92016-03-31 16:02:30 -0700755 actionButtonRect.set(left, top, left + mStackActionButton.getMeasuredWidth(),
756 top + mStackActionButton.getMeasuredHeight());
Winson19852372016-03-30 18:26:49 -0700757 return actionButtonRect;
758 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800759}