Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | |
| 17 | package com.android.systemui.recents.views; |
| 18 | |
| 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorListenerAdapter; |
Winson | 3f32e7e | 2016-04-20 17:18:08 -0700 | [diff] [blame] | 21 | import android.animation.TimeInterpolator; |
Winson | aa0dea7 | 2016-04-28 10:59:30 -0700 | [diff] [blame] | 22 | import android.animation.ValueAnimator; |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 23 | import android.content.Context; |
Jorim Jaggi | 545c5c2 | 2016-04-12 18:59:45 -0700 | [diff] [blame] | 24 | import android.content.res.Configuration; |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 25 | import android.content.res.Resources; |
Winson | 3f3d744 | 2016-03-01 10:07:04 -0800 | [diff] [blame] | 26 | import android.util.Log; |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 27 | import android.view.View; |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 28 | import android.view.animation.Interpolator; |
Winson | 5044863 | 2016-02-01 18:04:59 -0800 | [diff] [blame] | 29 | import android.view.animation.PathInterpolator; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 30 | |
| 31 | import com.android.systemui.Interpolators; |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 32 | import com.android.systemui.R; |
| 33 | import com.android.systemui.recents.Recents; |
| 34 | import com.android.systemui.recents.RecentsActivityLaunchState; |
| 35 | import com.android.systemui.recents.RecentsConfiguration; |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 36 | import com.android.systemui.recents.RecentsDebugFlags; |
Matthew Ng | c57b7f6 | 2017-08-10 15:37:19 -0700 | [diff] [blame] | 37 | import com.android.systemui.recents.events.EventBus; |
| 38 | import com.android.systemui.recents.events.component.SetWaitingForTransitionStartEvent; |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 39 | import com.android.systemui.recents.misc.ReferenceCountedTrigger; |
| 40 | import com.android.systemui.recents.model.Task; |
| 41 | import com.android.systemui.recents.model.TaskStack; |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 42 | import com.android.systemui.recents.views.lowram.TaskStackLowRamLayoutAlgorithm; |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 43 | |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 44 | import java.util.ArrayList; |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 45 | import java.util.List; |
| 46 | |
| 47 | /** |
| 48 | * A helper class to create task view animations for {@link TaskView}s in a {@link TaskStackView}, |
| 49 | * but not the contents of the {@link TaskView}s. |
| 50 | */ |
| 51 | public class TaskStackAnimationHelper { |
| 52 | |
| 53 | /** |
| 54 | * Callbacks from the helper to coordinate view-content animations with view animations. |
| 55 | */ |
| 56 | public interface Callbacks { |
| 57 | /** |
| 58 | * Callback to prepare for the start animation for the launch target {@link TaskView}. |
| 59 | */ |
| 60 | void onPrepareLaunchTargetForEnterAnimation(); |
| 61 | |
| 62 | /** |
| 63 | * Callback to start the animation for the launch target {@link TaskView}. |
| 64 | */ |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 65 | void onStartLaunchTargetEnterAnimation(TaskViewTransform transform, int duration, |
| 66 | boolean screenPinningEnabled, ReferenceCountedTrigger postAnimationTrigger); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 67 | |
| 68 | /** |
| 69 | * Callback to start the animation for the launch target {@link TaskView} when it is |
| 70 | * launched from Recents. |
| 71 | */ |
| 72 | void onStartLaunchTargetLaunchAnimation(int duration, boolean screenPinningRequested, |
| 73 | ReferenceCountedTrigger postAnimationTrigger); |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * Callback to start the animation for the front {@link TaskView} if there is no launch |
| 77 | * target. |
| 78 | */ |
| 79 | void onStartFrontTaskEnterAnimation(boolean screenPinningEnabled); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 80 | } |
| 81 | |
Winson | 3f32e7e | 2016-04-20 17:18:08 -0700 | [diff] [blame] | 82 | private static final int DOUBLE_FRAME_OFFSET_MS = 33; |
Winson | 5044863 | 2016-02-01 18:04:59 -0800 | [diff] [blame] | 83 | private static final int FRAME_OFFSET_MS = 16; |
| 84 | |
Winson | 3f32e7e | 2016-04-20 17:18:08 -0700 | [diff] [blame] | 85 | private static final int ENTER_EXIT_NUM_ANIMATING_TASKS = 5; |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 86 | |
Winson | 3f32e7e | 2016-04-20 17:18:08 -0700 | [diff] [blame] | 87 | private static final int ENTER_FROM_HOME_ALPHA_DURATION = 100; |
| 88 | public static final int ENTER_FROM_HOME_TRANSLATION_DURATION = 300; |
Winson | 3f32e7e | 2016-04-20 17:18:08 -0700 | [diff] [blame] | 89 | private static final Interpolator ENTER_FROM_HOME_ALPHA_INTERPOLATOR = Interpolators.LINEAR; |
Winson | 5044863 | 2016-02-01 18:04:59 -0800 | [diff] [blame] | 90 | |
Winson | 3f32e7e | 2016-04-20 17:18:08 -0700 | [diff] [blame] | 91 | public static final int EXIT_TO_HOME_TRANSLATION_DURATION = 200; |
| 92 | private static final Interpolator EXIT_TO_HOME_TRANSLATION_INTERPOLATOR = |
| 93 | new PathInterpolator(0.4f, 0, 0.6f, 1f); |
| 94 | |
| 95 | private static final int DISMISS_TASK_DURATION = 175; |
| 96 | private static final int DISMISS_ALL_TASKS_DURATION = 200; |
| 97 | private static final Interpolator DISMISS_ALL_TRANSLATION_INTERPOLATOR = |
Winson | 5044863 | 2016-02-01 18:04:59 -0800 | [diff] [blame] | 98 | new PathInterpolator(0.4f, 0, 1f, 1f); |
| 99 | |
Winson | 3f32e7e | 2016-04-20 17:18:08 -0700 | [diff] [blame] | 100 | private static final Interpolator FOCUS_NEXT_TASK_INTERPOLATOR = |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 101 | new PathInterpolator(0.4f, 0, 0, 1f); |
Winson | 3f32e7e | 2016-04-20 17:18:08 -0700 | [diff] [blame] | 102 | private static final Interpolator FOCUS_IN_FRONT_NEXT_TASK_INTERPOLATOR = |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 103 | new PathInterpolator(0, 0, 0, 1f); |
Winson | 3f32e7e | 2016-04-20 17:18:08 -0700 | [diff] [blame] | 104 | private static final Interpolator FOCUS_BEHIND_NEXT_TASK_INTERPOLATOR = |
| 105 | Interpolators.LINEAR_OUT_SLOW_IN; |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 106 | |
Winson | 3f32e7e | 2016-04-20 17:18:08 -0700 | [diff] [blame] | 107 | private static final Interpolator ENTER_WHILE_DOCKING_INTERPOLATOR = |
| 108 | Interpolators.LINEAR_OUT_SLOW_IN; |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 109 | |
Manu Cornet | 45c8048 | 2016-12-20 18:42:16 -0800 | [diff] [blame] | 110 | private final int mEnterAndExitFromHomeTranslationOffset; |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 111 | private TaskStackView mStackView; |
| 112 | |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 113 | private TaskViewTransform mTmpTransform = new TaskViewTransform(); |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 114 | private ArrayList<TaskViewTransform> mTmpCurrentTaskTransforms = new ArrayList<>(); |
| 115 | private ArrayList<TaskViewTransform> mTmpFinalTaskTransforms = new ArrayList<>(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 116 | |
| 117 | public TaskStackAnimationHelper(Context context, TaskStackView stackView) { |
| 118 | mStackView = stackView; |
Manu Cornet | 45c8048 | 2016-12-20 18:42:16 -0800 | [diff] [blame] | 119 | mEnterAndExitFromHomeTranslationOffset = Recents.getConfiguration().isGridEnabled |
| 120 | ? 0 : DOUBLE_FRAME_OFFSET_MS; |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Prepares the stack views and puts them in their initial animation state while visible, before |
| 125 | * the in-app enter animations start (after the window-transition completes). |
| 126 | */ |
| 127 | public void prepareForEnterAnimation() { |
| 128 | RecentsConfiguration config = Recents.getConfiguration(); |
| 129 | RecentsActivityLaunchState launchState = config.getLaunchState(); |
| 130 | Resources res = mStackView.getResources(); |
Jorim Jaggi | e370e15 | 2016-04-15 14:13:33 -0700 | [diff] [blame] | 131 | Resources appResources = mStackView.getContext().getApplicationContext().getResources(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 132 | |
| 133 | TaskStackLayoutAlgorithm stackLayout = mStackView.getStackAlgorithm(); |
| 134 | TaskStackViewScroller stackScroller = mStackView.getScroller(); |
| 135 | TaskStack stack = mStackView.getStack(); |
| 136 | Task launchTargetTask = stack.getLaunchTarget(); |
| 137 | |
| 138 | // Break early if there are no tasks |
Winson | 4b057c6 | 2016-01-12 15:01:52 -0800 | [diff] [blame] | 139 | if (stack.getTaskCount() == 0) { |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 140 | return; |
| 141 | } |
| 142 | |
Winson | 40a2273 | 2016-02-02 18:07:00 -0800 | [diff] [blame] | 143 | int offscreenYOffset = stackLayout.mStackRect.height(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 144 | int taskViewAffiliateGroupEnterOffset = res.getDimensionPixelSize( |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 145 | R.dimen.recents_task_stack_animation_affiliate_enter_offset); |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 146 | int launchedWhileDockingOffset = res.getDimensionPixelSize( |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 147 | R.dimen.recents_task_stack_animation_launched_while_docking_offset); |
Jorim Jaggi | e370e15 | 2016-04-15 14:13:33 -0700 | [diff] [blame] | 148 | boolean isLandscape = appResources.getConfiguration().orientation |
| 149 | == Configuration.ORIENTATION_LANDSCAPE; |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 150 | |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 151 | float top = 0; |
| 152 | final boolean isLowRamDevice = Recents.getConfiguration().isLowRamDevice; |
| 153 | if (isLowRamDevice && launchState.launchedFromApp && !launchState.launchedViaDockGesture) { |
| 154 | stackLayout.getStackTransform(launchTargetTask, stackScroller.getStackScroll(), |
| 155 | mTmpTransform, null /* frontTransform */); |
| 156 | top = mTmpTransform.rect.top; |
| 157 | } |
| 158 | |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 159 | // Prepare each of the task views for their enter animation from front to back |
| 160 | List<TaskView> taskViews = mStackView.getTaskViews(); |
| 161 | for (int i = taskViews.size() - 1; i >= 0; i--) { |
| 162 | TaskView tv = taskViews.get(i); |
| 163 | Task task = tv.getTask(); |
Winson | 8a3ef37 | 2016-05-26 10:46:11 -0700 | [diff] [blame] | 164 | boolean currentTaskOccludesLaunchTarget = launchTargetTask != null && |
| 165 | launchTargetTask.group != null && |
| 166 | launchTargetTask.group.isTaskAboveTask(task, launchTargetTask); |
| 167 | boolean hideTask = launchTargetTask != null && |
| 168 | launchTargetTask.isFreeformTask() && |
| 169 | task.isFreeformTask(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 170 | |
| 171 | // Get the current transform for the task, which will be used to position it offscreen |
| 172 | stackLayout.getStackTransform(task, stackScroller.getStackScroll(), mTmpTransform, |
Jiaquan He | 26f637b | 2016-12-27 14:44:14 -0800 | [diff] [blame] | 173 | null); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 174 | |
| 175 | if (hideTask) { |
| 176 | tv.setVisibility(View.INVISIBLE); |
Winson | c69249f | 2016-03-28 13:38:39 -0700 | [diff] [blame] | 177 | } else if (launchState.launchedFromApp && !launchState.launchedViaDockGesture) { |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 178 | if (task.isLaunchTarget) { |
| 179 | tv.onPrepareLaunchTargetForEnterAnimation(); |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 180 | } else if (isLowRamDevice && i >= taskViews.size() - |
| 181 | (TaskStackLowRamLayoutAlgorithm.MAX_LAYOUT_TASK_COUNT + 1) |
| 182 | && !RecentsDebugFlags.Static.DisableRecentsLowRamEnterExitAnimation) { |
| 183 | // Move the last 2nd and 3rd last tasks in-app animation to match the motion of |
| 184 | // the last task's app transition |
| 185 | stackLayout.getStackTransform(task, stackScroller.getStackScroll(), |
| 186 | mTmpTransform, null); |
| 187 | mTmpTransform.rect.offset(0, -top); |
| 188 | mTmpTransform.alpha = 0f; |
| 189 | mStackView.updateTaskViewToTransform(tv, mTmpTransform, |
| 190 | AnimationProps.IMMEDIATE); |
| 191 | stackLayout.getStackTransform(task, stackScroller.getStackScroll(), |
| 192 | mTmpTransform, null); |
| 193 | mTmpTransform.alpha = 1f; |
| 194 | // Duration see {@link |
| 195 | // com.android.server.wm.AppTransition#DEFAULT_APP_TRANSITION_DURATION} |
| 196 | mStackView.updateTaskViewToTransform(tv, mTmpTransform, |
| 197 | new AnimationProps(336, Interpolators.FAST_OUT_SLOW_IN)); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 198 | } else if (currentTaskOccludesLaunchTarget) { |
| 199 | // Move the task view slightly lower so we can animate it in |
Winson | c69249f | 2016-03-28 13:38:39 -0700 | [diff] [blame] | 200 | mTmpTransform.rect.offset(0, taskViewAffiliateGroupEnterOffset); |
| 201 | mTmpTransform.alpha = 0f; |
| 202 | mStackView.updateTaskViewToTransform(tv, mTmpTransform, |
| 203 | AnimationProps.IMMEDIATE); |
Winson | 65c851e | 2016-01-20 12:43:35 -0800 | [diff] [blame] | 204 | tv.setClipViewInStack(false); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 205 | } |
| 206 | } else if (launchState.launchedFromHome) { |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 207 | if (isLowRamDevice) { |
| 208 | mTmpTransform.rect.offset(0, stackLayout.getTaskRect().height() / 4); |
| 209 | } else { |
| 210 | // Move the task view off screen (below) so we can animate it in |
| 211 | mTmpTransform.rect.offset(0, offscreenYOffset); |
| 212 | } |
Winson | c69249f | 2016-03-28 13:38:39 -0700 | [diff] [blame] | 213 | mTmpTransform.alpha = 0f; |
| 214 | mStackView.updateTaskViewToTransform(tv, mTmpTransform, AnimationProps.IMMEDIATE); |
| 215 | } else if (launchState.launchedViaDockGesture) { |
Jorim Jaggi | 545c5c2 | 2016-04-12 18:59:45 -0700 | [diff] [blame] | 216 | int offset = isLandscape |
| 217 | ? launchedWhileDockingOffset |
| 218 | : (int) (offscreenYOffset * 0.9f); |
| 219 | mTmpTransform.rect.offset(0, offset); |
Winson | c69249f | 2016-03-28 13:38:39 -0700 | [diff] [blame] | 220 | mTmpTransform.alpha = 0f; |
| 221 | mStackView.updateTaskViewToTransform(tv, mTmpTransform, AnimationProps.IMMEDIATE); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 222 | } |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Starts the in-app enter animation, which animates the {@link TaskView}s to their final places |
| 228 | * depending on how Recents was triggered. |
| 229 | */ |
| 230 | public void startEnterAnimation(final ReferenceCountedTrigger postAnimationTrigger) { |
| 231 | RecentsConfiguration config = Recents.getConfiguration(); |
| 232 | RecentsActivityLaunchState launchState = config.getLaunchState(); |
| 233 | Resources res = mStackView.getResources(); |
Jorim Jaggi | e370e15 | 2016-04-15 14:13:33 -0700 | [diff] [blame] | 234 | Resources appRes = mStackView.getContext().getApplicationContext().getResources(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 235 | |
| 236 | TaskStackLayoutAlgorithm stackLayout = mStackView.getStackAlgorithm(); |
| 237 | TaskStackViewScroller stackScroller = mStackView.getScroller(); |
| 238 | TaskStack stack = mStackView.getStack(); |
| 239 | Task launchTargetTask = stack.getLaunchTarget(); |
| 240 | |
| 241 | // Break early if there are no tasks |
Winson | 4b057c6 | 2016-01-12 15:01:52 -0800 | [diff] [blame] | 242 | if (stack.getTaskCount() == 0) { |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 243 | return; |
| 244 | } |
| 245 | |
Matthew Ng | c57b7f6 | 2017-08-10 15:37:19 -0700 | [diff] [blame] | 246 | final boolean isLowRamDevice = Recents.getConfiguration().isLowRamDevice; |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 247 | int taskViewEnterFromAppDuration = res.getInteger( |
| 248 | R.integer.recents_task_enter_from_app_duration); |
Winson | 65c851e | 2016-01-20 12:43:35 -0800 | [diff] [blame] | 249 | int taskViewEnterFromAffiliatedAppDuration = res.getInteger( |
| 250 | R.integer.recents_task_enter_from_affiliated_app_duration); |
Jorim Jaggi | e370e15 | 2016-04-15 14:13:33 -0700 | [diff] [blame] | 251 | int dockGestureAnimDuration = appRes.getInteger( |
| 252 | R.integer.long_press_dock_anim_duration); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 253 | |
Matthew Ng | c57b7f6 | 2017-08-10 15:37:19 -0700 | [diff] [blame] | 254 | // Since low ram devices have an animation when entering app -> recents, do not allow |
| 255 | // toggle until the animation is complete |
| 256 | if (launchState.launchedFromApp && !launchState.launchedViaDockGesture && isLowRamDevice) { |
| 257 | postAnimationTrigger.addLastDecrementRunnable(() -> EventBus.getDefault() |
| 258 | .send(new SetWaitingForTransitionStartEvent(false))); |
| 259 | } |
| 260 | |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 261 | // Create enter animations for each of the views from front to back |
| 262 | List<TaskView> taskViews = mStackView.getTaskViews(); |
| 263 | int taskViewCount = taskViews.size(); |
| 264 | for (int i = taskViewCount - 1; i >= 0; i--) { |
Winson | 5044863 | 2016-02-01 18:04:59 -0800 | [diff] [blame] | 265 | int taskIndexFromFront = taskViewCount - i - 1; |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 266 | int taskIndexFromBack = i; |
Winson | 65c851e | 2016-01-20 12:43:35 -0800 | [diff] [blame] | 267 | final TaskView tv = taskViews.get(i); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 268 | Task task = tv.getTask(); |
Winson | 8a3ef37 | 2016-05-26 10:46:11 -0700 | [diff] [blame] | 269 | boolean currentTaskOccludesLaunchTarget = launchTargetTask != null && |
| 270 | launchTargetTask.group != null && |
| 271 | launchTargetTask.group.isTaskAboveTask(task, launchTargetTask); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 272 | |
| 273 | // Get the current transform for the task, which will be updated to the final transform |
| 274 | // to animate to depending on how recents was invoked |
| 275 | stackLayout.getStackTransform(task, stackScroller.getStackScroll(), mTmpTransform, |
Jiaquan He | 26f637b | 2016-12-27 14:44:14 -0800 | [diff] [blame] | 276 | null); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 277 | |
Winson | c69249f | 2016-03-28 13:38:39 -0700 | [diff] [blame] | 278 | if (launchState.launchedFromApp && !launchState.launchedViaDockGesture) { |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 279 | if (task.isLaunchTarget) { |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 280 | tv.onStartLaunchTargetEnterAnimation(mTmpTransform, |
| 281 | taskViewEnterFromAppDuration, mStackView.mScreenPinningEnabled, |
| 282 | postAnimationTrigger); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 283 | } else { |
| 284 | // Animate the task up if it was occluding the launch target |
| 285 | if (currentTaskOccludesLaunchTarget) { |
Winson | be8e696 | 2016-02-01 14:27:52 -0800 | [diff] [blame] | 286 | AnimationProps taskAnimation = new AnimationProps( |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 287 | taskViewEnterFromAffiliatedAppDuration, Interpolators.ALPHA_IN, |
Winson | 65c851e | 2016-01-20 12:43:35 -0800 | [diff] [blame] | 288 | new AnimatorListenerAdapter() { |
| 289 | @Override |
| 290 | public void onAnimationEnd(Animator animation) { |
| 291 | postAnimationTrigger.decrement(); |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 292 | tv.setClipViewInStack(true); |
Winson | 65c851e | 2016-01-20 12:43:35 -0800 | [diff] [blame] | 293 | } |
| 294 | }); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 295 | postAnimationTrigger.increment(); |
| 296 | mStackView.updateTaskViewToTransform(tv, mTmpTransform, taskAnimation); |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | } else if (launchState.launchedFromHome) { |
Winson | 3f32e7e | 2016-04-20 17:18:08 -0700 | [diff] [blame] | 301 | // Animate the tasks up, but offset the animations to be relative to the front-most |
| 302 | // task animation |
Matthew Ng | ed85be9 | 2017-06-02 12:46:33 -0700 | [diff] [blame] | 303 | final float startOffsetFraction = (float) (Math.min(ENTER_EXIT_NUM_ANIMATING_TASKS, |
| 304 | taskIndexFromFront) * mEnterAndExitFromHomeTranslationOffset) / |
| 305 | ENTER_FROM_HOME_TRANSLATION_DURATION; |
Winson | 5044863 | 2016-02-01 18:04:59 -0800 | [diff] [blame] | 306 | AnimationProps taskAnimation = new AnimationProps() |
Winson | 3f32e7e | 2016-04-20 17:18:08 -0700 | [diff] [blame] | 307 | .setInterpolator(AnimationProps.ALPHA, ENTER_FROM_HOME_ALPHA_INTERPOLATOR) |
Winson | 5044863 | 2016-02-01 18:04:59 -0800 | [diff] [blame] | 308 | .setListener(postAnimationTrigger.decrementOnAnimationEnd()); |
Matthew Ng | c57b7f6 | 2017-08-10 15:37:19 -0700 | [diff] [blame] | 309 | if (isLowRamDevice) { |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 310 | taskAnimation.setInterpolator(AnimationProps.BOUNDS, |
| 311 | Interpolators.FAST_OUT_SLOW_IN) |
| 312 | .setDuration(AnimationProps.BOUNDS, 150) |
| 313 | .setDuration(AnimationProps.ALPHA, 150); |
| 314 | } else { |
| 315 | taskAnimation.setStartDelay(AnimationProps.ALPHA, |
| 316 | Math.min(ENTER_EXIT_NUM_ANIMATING_TASKS, taskIndexFromFront) * |
| 317 | FRAME_OFFSET_MS) |
| 318 | .setInterpolator(AnimationProps.BOUNDS, |
| 319 | new RecentsEntrancePathInterpolator(0f, 0f, 0.2f, 1f, |
| 320 | startOffsetFraction)) |
| 321 | .setDuration(AnimationProps.BOUNDS, ENTER_FROM_HOME_TRANSLATION_DURATION) |
| 322 | .setDuration(AnimationProps.ALPHA, ENTER_FROM_HOME_ALPHA_DURATION); |
| 323 | } |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 324 | postAnimationTrigger.increment(); |
| 325 | mStackView.updateTaskViewToTransform(tv, mTmpTransform, taskAnimation); |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 326 | if (i == taskViewCount - 1) { |
| 327 | tv.onStartFrontTaskEnterAnimation(mStackView.mScreenPinningEnabled); |
| 328 | } |
Winson | c69249f | 2016-03-28 13:38:39 -0700 | [diff] [blame] | 329 | } else if (launchState.launchedViaDockGesture) { |
Jorim Jaggi | c5887ea | 2016-05-13 18:21:48 -0700 | [diff] [blame] | 330 | // Animate the tasks up - add some delay to match the divider animation |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 331 | AnimationProps taskAnimation = new AnimationProps() |
Winson | 3f32e7e | 2016-04-20 17:18:08 -0700 | [diff] [blame] | 332 | .setDuration(AnimationProps.BOUNDS, dockGestureAnimDuration + |
| 333 | (taskIndexFromBack * DOUBLE_FRAME_OFFSET_MS)) |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 334 | .setInterpolator(AnimationProps.BOUNDS, |
| 335 | ENTER_WHILE_DOCKING_INTERPOLATOR) |
Jorim Jaggi | c5887ea | 2016-05-13 18:21:48 -0700 | [diff] [blame] | 336 | .setStartDelay(AnimationProps.BOUNDS, 48) |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 337 | .setListener(postAnimationTrigger.decrementOnAnimationEnd()); |
| 338 | postAnimationTrigger.increment(); |
| 339 | mStackView.updateTaskViewToTransform(tv, mTmpTransform, taskAnimation); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 340 | } |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | /** |
| 345 | * Starts an in-app animation to hide all the task views so that we can transition back home. |
| 346 | */ |
| 347 | public void startExitToHomeAnimation(boolean animated, |
| 348 | ReferenceCountedTrigger postAnimationTrigger) { |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 349 | TaskStackLayoutAlgorithm stackLayout = mStackView.getStackAlgorithm(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 350 | TaskStack stack = mStackView.getStack(); |
| 351 | |
| 352 | // Break early if there are no tasks |
Winson | 4b057c6 | 2016-01-12 15:01:52 -0800 | [diff] [blame] | 353 | if (stack.getTaskCount() == 0) { |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 354 | return; |
| 355 | } |
| 356 | |
Winson | 40a2273 | 2016-02-02 18:07:00 -0800 | [diff] [blame] | 357 | int offscreenYOffset = stackLayout.mStackRect.height(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 358 | |
| 359 | // Create the animations for each of the tasks |
| 360 | List<TaskView> taskViews = mStackView.getTaskViews(); |
| 361 | int taskViewCount = taskViews.size(); |
| 362 | for (int i = 0; i < taskViewCount; i++) { |
Winson | 5044863 | 2016-02-01 18:04:59 -0800 | [diff] [blame] | 363 | int taskIndexFromFront = taskViewCount - i - 1; |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 364 | TaskView tv = taskViews.get(i); |
Winson | 61560f0 | 2016-05-02 16:36:20 -0700 | [diff] [blame] | 365 | Task task = tv.getTask(); |
| 366 | |
| 367 | if (mStackView.isIgnoredTask(task)) { |
| 368 | continue; |
| 369 | } |
Winson | 5044863 | 2016-02-01 18:04:59 -0800 | [diff] [blame] | 370 | |
| 371 | // Animate the tasks down |
| 372 | AnimationProps taskAnimation; |
| 373 | if (animated) { |
Winson | 3f32e7e | 2016-04-20 17:18:08 -0700 | [diff] [blame] | 374 | int delay = Math.min(ENTER_EXIT_NUM_ANIMATING_TASKS , taskIndexFromFront) * |
Manu Cornet | 45c8048 | 2016-12-20 18:42:16 -0800 | [diff] [blame] | 375 | mEnterAndExitFromHomeTranslationOffset; |
Winson | 5044863 | 2016-02-01 18:04:59 -0800 | [diff] [blame] | 376 | taskAnimation = new AnimationProps() |
Winson | 3f32e7e | 2016-04-20 17:18:08 -0700 | [diff] [blame] | 377 | .setDuration(AnimationProps.BOUNDS, EXIT_TO_HOME_TRANSLATION_DURATION) |
Winson | 5044863 | 2016-02-01 18:04:59 -0800 | [diff] [blame] | 378 | .setListener(postAnimationTrigger.decrementOnAnimationEnd()); |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 379 | if (Recents.getConfiguration().isLowRamDevice) { |
| 380 | taskAnimation.setInterpolator(AnimationProps.BOUNDS, |
| 381 | Interpolators.FAST_OUT_SLOW_IN); |
| 382 | } else { |
| 383 | taskAnimation.setStartDelay(AnimationProps.BOUNDS, delay) |
| 384 | .setInterpolator(AnimationProps.BOUNDS, |
| 385 | EXIT_TO_HOME_TRANSLATION_INTERPOLATOR); |
| 386 | } |
Winson | 5044863 | 2016-02-01 18:04:59 -0800 | [diff] [blame] | 387 | postAnimationTrigger.increment(); |
| 388 | } else { |
| 389 | taskAnimation = AnimationProps.IMMEDIATE; |
| 390 | } |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 391 | |
Winson | 3b6ba1a | 2016-03-22 15:37:54 -0700 | [diff] [blame] | 392 | mTmpTransform.fillIn(tv); |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 393 | if (Recents.getConfiguration().isLowRamDevice) { |
| 394 | taskAnimation.setInterpolator(AnimationProps.ALPHA, |
| 395 | EXIT_TO_HOME_TRANSLATION_INTERPOLATOR) |
| 396 | .setDuration(AnimationProps.ALPHA, EXIT_TO_HOME_TRANSLATION_DURATION); |
| 397 | mTmpTransform.rect.offset(0, stackLayout.mTaskStackLowRamLayoutAlgorithm |
| 398 | .getTaskRect().height() / 4); |
| 399 | mTmpTransform.alpha = 0f; |
| 400 | } else { |
| 401 | mTmpTransform.rect.offset(0, offscreenYOffset); |
| 402 | } |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 403 | mStackView.updateTaskViewToTransform(tv, mTmpTransform, taskAnimation); |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | /** |
| 408 | * Starts the animation for the launching task view, hiding any tasks that might occlude the |
| 409 | * window transition for the launching task. |
| 410 | */ |
| 411 | public void startLaunchTaskAnimation(TaskView launchingTaskView, boolean screenPinningRequested, |
| 412 | final ReferenceCountedTrigger postAnimationTrigger) { |
| 413 | Resources res = mStackView.getResources(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 414 | |
| 415 | int taskViewExitToAppDuration = res.getInteger( |
| 416 | R.integer.recents_task_exit_to_app_duration); |
| 417 | int taskViewAffiliateGroupEnterOffset = res.getDimensionPixelSize( |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 418 | R.dimen.recents_task_stack_animation_affiliate_enter_offset); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 419 | |
| 420 | Task launchingTask = launchingTaskView.getTask(); |
| 421 | List<TaskView> taskViews = mStackView.getTaskViews(); |
| 422 | int taskViewCount = taskViews.size(); |
| 423 | for (int i = 0; i < taskViewCount; i++) { |
| 424 | TaskView tv = taskViews.get(i); |
| 425 | Task task = tv.getTask(); |
Winson | 8a3ef37 | 2016-05-26 10:46:11 -0700 | [diff] [blame] | 426 | boolean currentTaskOccludesLaunchTarget = launchingTask != null && |
| 427 | launchingTask.group != null && |
| 428 | launchingTask.group.isTaskAboveTask(task, launchingTask); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 429 | |
| 430 | if (tv == launchingTaskView) { |
| 431 | tv.setClipViewInStack(false); |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 432 | postAnimationTrigger.addLastDecrementRunnable(new Runnable() { |
| 433 | @Override |
| 434 | public void run() { |
| 435 | tv.setClipViewInStack(true); |
| 436 | } |
| 437 | }); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 438 | tv.onStartLaunchTargetLaunchAnimation(taskViewExitToAppDuration, |
| 439 | screenPinningRequested, postAnimationTrigger); |
| 440 | } else if (currentTaskOccludesLaunchTarget) { |
| 441 | // Animate this task out of view |
Winson | be8e696 | 2016-02-01 14:27:52 -0800 | [diff] [blame] | 442 | AnimationProps taskAnimation = new AnimationProps( |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 443 | taskViewExitToAppDuration, Interpolators.ALPHA_OUT, |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 444 | postAnimationTrigger.decrementOnAnimationEnd()); |
| 445 | postAnimationTrigger.increment(); |
| 446 | |
Winson | 3b6ba1a | 2016-03-22 15:37:54 -0700 | [diff] [blame] | 447 | mTmpTransform.fillIn(tv); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 448 | mTmpTransform.alpha = 0f; |
| 449 | mTmpTransform.rect.offset(0, taskViewAffiliateGroupEnterOffset); |
| 450 | mStackView.updateTaskViewToTransform(tv, mTmpTransform, taskAnimation); |
| 451 | } |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | /** |
| 456 | * Starts the delete animation for the specified {@link TaskView}. |
| 457 | */ |
Manu Cornet | 5df7667 | 2017-01-11 15:14:14 -0800 | [diff] [blame] | 458 | public void startDeleteTaskAnimation(final TaskView deleteTaskView, boolean gridLayout, |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 459 | final ReferenceCountedTrigger postAnimationTrigger) { |
Manu Cornet | 5df7667 | 2017-01-11 15:14:14 -0800 | [diff] [blame] | 460 | if (gridLayout) { |
| 461 | startTaskGridDeleteTaskAnimation(deleteTaskView, postAnimationTrigger); |
| 462 | } else { |
| 463 | startTaskStackDeleteTaskAnimation(deleteTaskView, postAnimationTrigger); |
| 464 | } |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | /** |
Winson | 3b6ba1a | 2016-03-22 15:37:54 -0700 | [diff] [blame] | 468 | * Starts the delete animation for all the {@link TaskView}s. |
| 469 | */ |
Manu Cornet | 5df7667 | 2017-01-11 15:14:14 -0800 | [diff] [blame] | 470 | public void startDeleteAllTasksAnimation(final List<TaskView> taskViews, boolean gridLayout, |
| 471 | final ReferenceCountedTrigger postAnimationTrigger) { |
| 472 | if (gridLayout) { |
| 473 | for (int i = 0; i < taskViews.size(); i++) { |
| 474 | startTaskGridDeleteTaskAnimation(taskViews.get(i), postAnimationTrigger); |
| 475 | } |
| 476 | } else { |
| 477 | startTaskStackDeleteAllTasksAnimation(taskViews, postAnimationTrigger); |
Winson | 3b6ba1a | 2016-03-22 15:37:54 -0700 | [diff] [blame] | 478 | } |
| 479 | } |
| 480 | |
| 481 | /** |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 482 | * Starts the animation to focus the next {@link TaskView} when paging through recents. |
| 483 | * |
| 484 | * @return whether or not this will trigger a scroll in the stack |
| 485 | */ |
| 486 | public boolean startScrollToFocusedTaskAnimation(Task newFocusedTask, |
| 487 | boolean requestViewFocus) { |
| 488 | TaskStackLayoutAlgorithm stackLayout = mStackView.getStackAlgorithm(); |
| 489 | TaskStackViewScroller stackScroller = mStackView.getScroller(); |
| 490 | TaskStack stack = mStackView.getStack(); |
| 491 | |
Winson | 3f3d744 | 2016-03-01 10:07:04 -0800 | [diff] [blame] | 492 | final float curScroll = stackScroller.getStackScroll(); |
Winson | aeb298c | 2016-04-05 13:08:11 -0700 | [diff] [blame] | 493 | final float newScroll = stackScroller.getBoundedStackScroll( |
| 494 | stackLayout.getStackScrollForTask(newFocusedTask)); |
Winson | 3f3d744 | 2016-03-01 10:07:04 -0800 | [diff] [blame] | 495 | boolean willScrollToFront = newScroll > curScroll; |
| 496 | boolean willScroll = Float.compare(newScroll, curScroll) != 0; |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 497 | |
| 498 | // Get the current set of task transforms |
Winson | 3f3d744 | 2016-03-01 10:07:04 -0800 | [diff] [blame] | 499 | int taskViewCount = mStackView.getTaskViews().size(); |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 500 | ArrayList<Task> stackTasks = stack.getStackTasks(); |
| 501 | mStackView.getCurrentTaskTransforms(stackTasks, mTmpCurrentTaskTransforms); |
| 502 | |
| 503 | // Pick up the newly visible views after the scroll |
| 504 | mStackView.bindVisibleTaskViews(newScroll); |
| 505 | |
| 506 | // Update the internal state |
| 507 | stackLayout.setFocusState(TaskStackLayoutAlgorithm.STATE_FOCUSED); |
| 508 | stackScroller.setStackScroll(newScroll, null /* animation */); |
| 509 | mStackView.cancelDeferredTaskViewLayoutAnimation(); |
| 510 | |
| 511 | // Get the final set of task transforms |
Winson | 1499150 | 2016-02-15 15:40:08 -0800 | [diff] [blame] | 512 | mStackView.getLayoutTaskTransforms(newScroll, stackLayout.getFocusState(), stackTasks, |
Winson | d2a0306 | 2016-04-15 11:19:07 -0700 | [diff] [blame] | 513 | true /* ignoreTaskOverrides */, mTmpFinalTaskTransforms); |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 514 | |
| 515 | // Focus the task view |
| 516 | TaskView newFocusedTaskView = mStackView.getChildViewForTask(newFocusedTask); |
Winson | 3f3d744 | 2016-03-01 10:07:04 -0800 | [diff] [blame] | 517 | if (newFocusedTaskView == null) { |
| 518 | // Log the error if we have no task view, and skip the animation |
| 519 | Log.e("TaskStackAnimationHelper", "b/27389156 null-task-view prebind:" + taskViewCount + |
| 520 | " postbind:" + mStackView.getTaskViews().size() + " prescroll:" + curScroll + |
| 521 | " postscroll: " + newScroll); |
| 522 | return false; |
| 523 | } |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 524 | newFocusedTaskView.setFocusedState(true, requestViewFocus); |
| 525 | |
| 526 | // Setup the end listener to return all the hidden views to the view pool after the |
| 527 | // focus animation |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 528 | ReferenceCountedTrigger postAnimTrigger = new ReferenceCountedTrigger(); |
| 529 | postAnimTrigger.addLastDecrementRunnable(new Runnable() { |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 530 | @Override |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 531 | public void run() { |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 532 | mStackView.bindVisibleTaskViews(newScroll); |
| 533 | } |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 534 | }); |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 535 | |
| 536 | List<TaskView> taskViews = mStackView.getTaskViews(); |
Winson | 3f3d744 | 2016-03-01 10:07:04 -0800 | [diff] [blame] | 537 | taskViewCount = taskViews.size(); |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 538 | int newFocusTaskViewIndex = taskViews.indexOf(newFocusedTaskView); |
| 539 | for (int i = 0; i < taskViewCount; i++) { |
| 540 | TaskView tv = taskViews.get(i); |
| 541 | Task task = tv.getTask(); |
| 542 | |
| 543 | if (mStackView.isIgnoredTask(task)) { |
| 544 | continue; |
| 545 | } |
| 546 | |
| 547 | int taskIndex = stackTasks.indexOf(task); |
| 548 | TaskViewTransform fromTransform = mTmpCurrentTaskTransforms.get(taskIndex); |
| 549 | TaskViewTransform toTransform = mTmpFinalTaskTransforms.get(taskIndex); |
| 550 | |
| 551 | // Update the task to the initial state (for the newly picked up tasks) |
| 552 | mStackView.updateTaskViewToTransform(tv, fromTransform, AnimationProps.IMMEDIATE); |
| 553 | |
| 554 | int duration; |
| 555 | Interpolator interpolator; |
| 556 | if (willScrollToFront) { |
Winson | d2a0306 | 2016-04-15 11:19:07 -0700 | [diff] [blame] | 557 | duration = calculateStaggeredAnimDuration(i); |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 558 | interpolator = FOCUS_BEHIND_NEXT_TASK_INTERPOLATOR; |
| 559 | } else { |
| 560 | if (i < newFocusTaskViewIndex) { |
| 561 | duration = 150 + ((newFocusTaskViewIndex - i - 1) * 50); |
| 562 | interpolator = FOCUS_BEHIND_NEXT_TASK_INTERPOLATOR; |
| 563 | } else if (i > newFocusTaskViewIndex) { |
| 564 | duration = Math.max(100, 150 - ((i - newFocusTaskViewIndex - 1) * 50)); |
| 565 | interpolator = FOCUS_IN_FRONT_NEXT_TASK_INTERPOLATOR; |
| 566 | } else { |
| 567 | duration = 200; |
| 568 | interpolator = FOCUS_NEXT_TASK_INTERPOLATOR; |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | AnimationProps anim = new AnimationProps() |
| 573 | .setDuration(AnimationProps.BOUNDS, duration) |
| 574 | .setInterpolator(AnimationProps.BOUNDS, interpolator) |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 575 | .setListener(postAnimTrigger.decrementOnAnimationEnd()); |
| 576 | postAnimTrigger.increment(); |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 577 | mStackView.updateTaskViewToTransform(tv, toTransform, anim); |
| 578 | } |
| 579 | return willScroll; |
| 580 | } |
Winson | d2a0306 | 2016-04-15 11:19:07 -0700 | [diff] [blame] | 581 | |
| 582 | /** |
| 583 | * Starts the animation to go to the initial stack layout with a task focused. In addition, the |
| 584 | * previous task will be animated in after the scroll completes. |
| 585 | */ |
| 586 | public void startNewStackScrollAnimation(TaskStack newStack, |
| 587 | ReferenceCountedTrigger animationTrigger) { |
| 588 | TaskStackLayoutAlgorithm stackLayout = mStackView.getStackAlgorithm(); |
| 589 | TaskStackViewScroller stackScroller = mStackView.getScroller(); |
| 590 | |
| 591 | // Get the current set of task transforms |
| 592 | ArrayList<Task> stackTasks = newStack.getStackTasks(); |
| 593 | mStackView.getCurrentTaskTransforms(stackTasks, mTmpCurrentTaskTransforms); |
| 594 | |
| 595 | // Update the stack |
| 596 | mStackView.setTasks(newStack, false /* allowNotifyStackChanges */); |
| 597 | mStackView.updateLayoutAlgorithm(false /* boundScroll */); |
| 598 | |
| 599 | // Pick up the newly visible views after the scroll |
| 600 | final float newScroll = stackLayout.mInitialScrollP; |
| 601 | mStackView.bindVisibleTaskViews(newScroll); |
| 602 | |
| 603 | // Update the internal state |
| 604 | stackLayout.setFocusState(TaskStackLayoutAlgorithm.STATE_UNFOCUSED); |
| 605 | stackLayout.setTaskOverridesForInitialState(newStack, true /* ignoreScrollToFront */); |
| 606 | stackScroller.setStackScroll(newScroll); |
| 607 | mStackView.cancelDeferredTaskViewLayoutAnimation(); |
| 608 | |
| 609 | // Get the final set of task transforms |
| 610 | mStackView.getLayoutTaskTransforms(newScroll, stackLayout.getFocusState(), stackTasks, |
| 611 | false /* ignoreTaskOverrides */, mTmpFinalTaskTransforms); |
| 612 | |
| 613 | // Hide the front most task view until the scroll is complete |
| 614 | Task frontMostTask = newStack.getStackFrontMostTask(false /* includeFreeform */); |
| 615 | final TaskView frontMostTaskView = mStackView.getChildViewForTask(frontMostTask); |
| 616 | final TaskViewTransform frontMostTransform = mTmpFinalTaskTransforms.get( |
| 617 | stackTasks.indexOf(frontMostTask)); |
| 618 | if (frontMostTaskView != null) { |
| 619 | mStackView.updateTaskViewToTransform(frontMostTaskView, |
| 620 | stackLayout.getFrontOfStackTransform(), AnimationProps.IMMEDIATE); |
| 621 | } |
| 622 | |
| 623 | // Setup the end listener to return all the hidden views to the view pool after the |
| 624 | // focus animation |
| 625 | animationTrigger.addLastDecrementRunnable(new Runnable() { |
| 626 | @Override |
| 627 | public void run() { |
| 628 | mStackView.bindVisibleTaskViews(newScroll); |
| 629 | |
| 630 | // Now, animate in the front-most task |
| 631 | if (frontMostTaskView != null) { |
| 632 | mStackView.updateTaskViewToTransform(frontMostTaskView, frontMostTransform, |
Winson | 3f32e7e | 2016-04-20 17:18:08 -0700 | [diff] [blame] | 633 | new AnimationProps(75, 250, FOCUS_BEHIND_NEXT_TASK_INTERPOLATOR)); |
Winson | d2a0306 | 2016-04-15 11:19:07 -0700 | [diff] [blame] | 634 | } |
| 635 | } |
| 636 | }); |
| 637 | |
| 638 | List<TaskView> taskViews = mStackView.getTaskViews(); |
| 639 | int taskViewCount = taskViews.size(); |
| 640 | for (int i = 0; i < taskViewCount; i++) { |
| 641 | TaskView tv = taskViews.get(i); |
| 642 | Task task = tv.getTask(); |
| 643 | |
| 644 | if (mStackView.isIgnoredTask(task)) { |
| 645 | continue; |
| 646 | } |
| 647 | if (task == frontMostTask && frontMostTaskView != null) { |
| 648 | continue; |
| 649 | } |
| 650 | |
| 651 | int taskIndex = stackTasks.indexOf(task); |
| 652 | TaskViewTransform fromTransform = mTmpCurrentTaskTransforms.get(taskIndex); |
| 653 | TaskViewTransform toTransform = mTmpFinalTaskTransforms.get(taskIndex); |
| 654 | |
| 655 | // Update the task to the initial state (for the newly picked up tasks) |
| 656 | mStackView.updateTaskViewToTransform(tv, fromTransform, AnimationProps.IMMEDIATE); |
| 657 | |
| 658 | int duration = calculateStaggeredAnimDuration(i); |
| 659 | Interpolator interpolator = FOCUS_BEHIND_NEXT_TASK_INTERPOLATOR; |
| 660 | |
| 661 | AnimationProps anim = new AnimationProps() |
| 662 | .setDuration(AnimationProps.BOUNDS, duration) |
| 663 | .setInterpolator(AnimationProps.BOUNDS, interpolator) |
| 664 | .setListener(animationTrigger.decrementOnAnimationEnd()); |
| 665 | animationTrigger.increment(); |
| 666 | mStackView.updateTaskViewToTransform(tv, toTransform, anim); |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | /** |
| 671 | * Caclulates a staggered duration for {@link #startScrollToFocusedTaskAnimation} and |
| 672 | * {@link #startNewStackScrollAnimation}. |
| 673 | */ |
| 674 | private int calculateStaggeredAnimDuration(int i) { |
| 675 | return Math.max(100, 100 + ((i - 1) * 50)); |
| 676 | } |
Manu Cornet | 5df7667 | 2017-01-11 15:14:14 -0800 | [diff] [blame] | 677 | |
| 678 | private void startTaskGridDeleteTaskAnimation(final TaskView deleteTaskView, |
| 679 | final ReferenceCountedTrigger postAnimationTrigger) { |
| 680 | postAnimationTrigger.increment(); |
| 681 | postAnimationTrigger.addLastDecrementRunnable(() -> { |
| 682 | mStackView.getTouchHandler().onChildDismissed(deleteTaskView); |
| 683 | }); |
Manu Cornet | 8ea36af | 2017-01-24 18:49:49 +0900 | [diff] [blame] | 684 | deleteTaskView.animate().setDuration(300).scaleX(0.9f).scaleY(0.9f).alpha(0).setListener( |
Manu Cornet | 5df7667 | 2017-01-11 15:14:14 -0800 | [diff] [blame] | 685 | new AnimatorListenerAdapter() { |
| 686 | @Override |
| 687 | public void onAnimationEnd(Animator animation) { |
| 688 | postAnimationTrigger.decrement(); |
| 689 | }}).start(); |
| 690 | } |
| 691 | |
| 692 | private void startTaskStackDeleteTaskAnimation(final TaskView deleteTaskView, |
| 693 | final ReferenceCountedTrigger postAnimationTrigger) { |
| 694 | TaskStackViewTouchHandler touchHandler = mStackView.getTouchHandler(); |
| 695 | touchHandler.onBeginManualDrag(deleteTaskView); |
| 696 | |
| 697 | postAnimationTrigger.increment(); |
| 698 | postAnimationTrigger.addLastDecrementRunnable(() -> { |
| 699 | touchHandler.onChildDismissed(deleteTaskView); |
| 700 | }); |
| 701 | |
| 702 | final float dismissSize = touchHandler.getScaledDismissSize(); |
| 703 | ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f); |
| 704 | animator.setDuration(400); |
| 705 | animator.addUpdateListener((animation) -> { |
| 706 | float progress = (Float) animation.getAnimatedValue(); |
| 707 | deleteTaskView.setTranslationX(progress * dismissSize); |
| 708 | touchHandler.updateSwipeProgress(deleteTaskView, true, progress); |
| 709 | }); |
| 710 | animator.addListener(new AnimatorListenerAdapter() { |
| 711 | @Override |
| 712 | public void onAnimationEnd(Animator animation) { |
| 713 | postAnimationTrigger.decrement(); |
| 714 | } |
| 715 | }); |
| 716 | animator.start(); |
| 717 | } |
| 718 | |
| 719 | private void startTaskStackDeleteAllTasksAnimation(final List<TaskView> taskViews, |
| 720 | final ReferenceCountedTrigger postAnimationTrigger) { |
| 721 | TaskStackLayoutAlgorithm stackLayout = mStackView.getStackAlgorithm(); |
| 722 | |
| 723 | int offscreenXOffset = mStackView.getMeasuredWidth() - stackLayout.getTaskRect().left; |
| 724 | |
| 725 | int taskViewCount = taskViews.size(); |
| 726 | for (int i = taskViewCount - 1; i >= 0; i--) { |
| 727 | TaskView tv = taskViews.get(i); |
| 728 | int taskIndexFromFront = taskViewCount - i - 1; |
| 729 | int startDelay = taskIndexFromFront * DOUBLE_FRAME_OFFSET_MS; |
| 730 | |
| 731 | // Disabling clipping with the stack while the view is animating away |
| 732 | tv.setClipViewInStack(false); |
| 733 | |
| 734 | // Compose the new animation and transform and star the animation |
| 735 | AnimationProps taskAnimation = new AnimationProps(startDelay, |
| 736 | DISMISS_ALL_TASKS_DURATION, DISMISS_ALL_TRANSLATION_INTERPOLATOR, |
| 737 | new AnimatorListenerAdapter() { |
| 738 | @Override |
| 739 | public void onAnimationEnd(Animator animation) { |
| 740 | postAnimationTrigger.decrement(); |
| 741 | |
| 742 | // Re-enable clipping with the stack (we will reuse this view) |
| 743 | tv.setClipViewInStack(true); |
| 744 | } |
| 745 | }); |
| 746 | postAnimationTrigger.increment(); |
| 747 | |
| 748 | mTmpTransform.fillIn(tv); |
| 749 | mTmpTransform.rect.offset(offscreenXOffset, 0); |
| 750 | mStackView.updateTaskViewToTransform(tv, mTmpTransform, taskAnimation); |
| 751 | } |
| 752 | } |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 753 | } |