Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.recents.views; |
| 18 | |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 19 | import static android.app.ActivityManager.StackId.INVALID_STACK_ID; |
| 20 | |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 21 | import android.animation.Animator; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 22 | import android.animation.ObjectAnimator; |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 23 | import android.app.ActivityOptions.OnAnimationStartedListener; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 24 | import android.content.Context; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 25 | import android.graphics.Canvas; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 26 | import android.graphics.Color; |
| 27 | import android.graphics.Outline; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 28 | import android.graphics.Rect; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 29 | import android.graphics.drawable.ColorDrawable; |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 30 | import android.graphics.drawable.Drawable; |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 31 | import android.util.ArraySet; |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 32 | import android.util.AttributeSet; |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 33 | import android.view.AppTransitionAnimationSpec; |
| 34 | import android.view.IAppTransitionAnimationSpecsFuture; |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 35 | import android.view.LayoutInflater; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 36 | import android.view.MotionEvent; |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 37 | import android.view.View; |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 38 | import android.view.ViewDebug; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 39 | import android.view.ViewOutlineProvider; |
Jorim Jaggi | 870ab5a | 2015-12-02 18:37:54 -0800 | [diff] [blame] | 40 | import android.view.ViewPropertyAnimator; |
Winson Chung | 653f70c2 | 2014-05-19 14:49:42 -0700 | [diff] [blame] | 41 | import android.view.WindowInsets; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 42 | import android.widget.FrameLayout; |
Winson Chung | de750de | 2015-12-11 10:26:06 -0500 | [diff] [blame] | 43 | import android.widget.TextView; |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 44 | |
Winson | dc8de84 | 2016-01-06 15:21:41 -0800 | [diff] [blame] | 45 | import com.android.internal.logging.MetricsLogger; |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 46 | import com.android.internal.logging.MetricsProto.MetricsEvent; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 47 | import com.android.systemui.Interpolators; |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 48 | import com.android.systemui.R; |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 49 | import com.android.systemui.recents.Recents; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 50 | import com.android.systemui.recents.RecentsActivity; |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 51 | import com.android.systemui.recents.RecentsActivityLaunchState; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 52 | import com.android.systemui.recents.RecentsConfiguration; |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 53 | import com.android.systemui.recents.RecentsDebugFlags; |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 54 | import com.android.systemui.recents.events.EventBus; |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 55 | import com.android.systemui.recents.events.activity.DismissRecentsToHomeAnimationStarted; |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 56 | import com.android.systemui.recents.events.activity.DockedFirstAnimationFrameEvent; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 57 | import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationCompletedEvent; |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 58 | import com.android.systemui.recents.events.activity.HideStackActionButtonEvent; |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 59 | import com.android.systemui.recents.events.activity.LaunchTaskEvent; |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 60 | import com.android.systemui.recents.events.activity.ShowStackActionButtonEvent; |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 61 | import com.android.systemui.recents.events.ui.DraggingInRecentsEndedEvent; |
| 62 | import com.android.systemui.recents.events.ui.DraggingInRecentsEvent; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 63 | import com.android.systemui.recents.events.ui.ResetBackgroundScrimEvent; |
| 64 | import com.android.systemui.recents.events.ui.UpdateBackgroundScrimEvent; |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 65 | import com.android.systemui.recents.events.ui.dragndrop.DragDropTargetChangedEvent; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 66 | import com.android.systemui.recents.events.ui.dragndrop.DragEndEvent; |
| 67 | import com.android.systemui.recents.events.ui.dragndrop.DragStartEvent; |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 68 | import com.android.systemui.recents.misc.ReferenceCountedTrigger; |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 69 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Winson | c5fd350 | 2016-01-18 15:18:37 -0800 | [diff] [blame] | 70 | import com.android.systemui.recents.misc.Utilities; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 71 | import com.android.systemui.recents.model.Task; |
| 72 | import com.android.systemui.recents.model.TaskStack; |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 73 | import com.android.systemui.recents.views.RecentsTransitionHelper.AnimationSpecComposer; |
Jorim Jaggi | 870ab5a | 2015-12-02 18:37:54 -0800 | [diff] [blame] | 74 | import com.android.systemui.stackdivider.WindowManagerProxy; |
| 75 | import com.android.systemui.statusbar.FlingAnimationUtils; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 76 | |
| 77 | import java.util.ArrayList; |
Winson Chung | 6ac8bd6 | 2015-01-07 16:38:35 -0800 | [diff] [blame] | 78 | import java.util.List; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 79 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 80 | /** |
| 81 | * This view is the the top level layout that contains TaskStacks (which are laid out according |
| 82 | * to their SpaceNode bounds. |
| 83 | */ |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 84 | public class RecentsView extends FrameLayout { |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 85 | |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 86 | private static final int DOCK_AREA_OVERLAY_TRANSITION_DURATION = 135; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 87 | private static final int DEFAULT_UPDATE_SCRIM_DURATION = 200; |
| 88 | private static final float DEFAULT_SCRIM_ALPHA = 0.33f; |
Jorim Jaggi | 6e18e00 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 89 | |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 90 | private TaskStack mStack; |
| 91 | private TaskStackView mTaskStackView; |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 92 | private TextView mStackActionButton; |
Winson | 196e861 | 2016-03-15 15:20:17 -0700 | [diff] [blame] | 93 | private TextView mEmptyView; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 94 | |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 95 | private boolean mAwaitingFirstLayout = true; |
| 96 | private boolean mLastTaskLaunchedWasFreeform; |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 97 | |
| 98 | @ViewDebug.ExportedProperty(category="recents") |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 99 | private Rect mSystemInsets = new Rect(); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 100 | private int mDividerSize; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 101 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 102 | private ColorDrawable mBackgroundScrim = new ColorDrawable(Color.BLACK); |
| 103 | private Animator mBackgroundScrimAnimator; |
| 104 | |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 105 | private RecentsTransitionHelper mTransitionHelper; |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 106 | @ViewDebug.ExportedProperty(deepExport=true, prefix="touch_") |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 107 | private RecentsViewTouchHandler mTouchHandler; |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 108 | private final FlingAnimationUtils mFlingAnimationUtils; |
Jorim Jaggi | 870ab5a | 2015-12-02 18:37:54 -0800 | [diff] [blame] | 109 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 110 | public RecentsView(Context context) { |
Jorim Jaggi | 870ab5a | 2015-12-02 18:37:54 -0800 | [diff] [blame] | 111 | this(context, null); |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | public RecentsView(Context context, AttributeSet attrs) { |
| 115 | this(context, attrs, 0); |
| 116 | } |
| 117 | |
| 118 | public RecentsView(Context context, AttributeSet attrs, int defStyleAttr) { |
| 119 | this(context, attrs, defStyleAttr, 0); |
| 120 | } |
| 121 | |
| 122 | public RecentsView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
| 123 | super(context, attrs, defStyleAttr, defStyleRes); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 124 | setWillNotDraw(false); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 125 | |
| 126 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 127 | mTransitionHelper = new RecentsTransitionHelper(getContext()); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 128 | mDividerSize = ssp.getDockedDividerSize(context); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 129 | mTouchHandler = new RecentsViewTouchHandler(this); |
Jorim Jaggi | 870ab5a | 2015-12-02 18:37:54 -0800 | [diff] [blame] | 130 | mFlingAnimationUtils = new FlingAnimationUtils(context, 0.3f); |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 131 | |
| 132 | LayoutInflater inflater = LayoutInflater.from(context); |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 133 | if (RecentsDebugFlags.Static.EnableStackActionButton) { |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 134 | float cornerRadius = context.getResources().getDimensionPixelSize( |
| 135 | R.dimen.recents_task_view_rounded_corners_radius); |
| 136 | mStackActionButton = (TextView) inflater.inflate(R.layout.recents_stack_action_button, |
| 137 | this, false); |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 138 | mStackActionButton.setOnClickListener(new View.OnClickListener() { |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 139 | @Override |
| 140 | public void onClick(View v) { |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 141 | // TODO: To be implemented |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 142 | } |
| 143 | }); |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 144 | addView(mStackActionButton); |
| 145 | mStackActionButton.setClipToOutline(true); |
| 146 | mStackActionButton.setOutlineProvider(new ViewOutlineProvider() { |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 147 | @Override |
| 148 | public void getOutline(View view, Outline outline) { |
| 149 | outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), cornerRadius); |
| 150 | } |
| 151 | }); |
| 152 | } |
Winson | 196e861 | 2016-03-15 15:20:17 -0700 | [diff] [blame] | 153 | mEmptyView = (TextView) inflater.inflate(R.layout.recents_empty, this, false); |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 154 | addView(mEmptyView); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 155 | |
| 156 | setBackground(mBackgroundScrim); |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 157 | } |
| 158 | |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 159 | /** |
| 160 | * Called from RecentsActivity when it is relaunched. |
| 161 | */ |
| 162 | public void onReload(boolean isResumingFromVisible, boolean isTaskStackEmpty) { |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 163 | RecentsConfiguration config = Recents.getConfiguration(); |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 164 | RecentsActivityLaunchState launchState = config.getLaunchState(); |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 165 | |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 166 | if (mTaskStackView == null) { |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 167 | isResumingFromVisible = false; |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 168 | mTaskStackView = new TaskStackView(getContext()); |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 169 | mTaskStackView.setSystemInsets(mSystemInsets); |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 170 | addView(mTaskStackView); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 171 | } |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 172 | |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 173 | // Reset the state |
| 174 | mAwaitingFirstLayout = !isResumingFromVisible; |
| 175 | mLastTaskLaunchedWasFreeform = false; |
| 176 | |
| 177 | // Update the stack |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 178 | mTaskStackView.onReload(isResumingFromVisible); |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 179 | |
| 180 | if (isResumingFromVisible) { |
| 181 | // If we are already visible, then restore the background scrim |
| 182 | animateBackgroundScrim(DEFAULT_SCRIM_ALPHA, DEFAULT_UPDATE_SCRIM_DURATION); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 183 | } else { |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 184 | // If we are already occluded by the app, then set the final background scrim alpha now. |
| 185 | // Otherwise, defer until the enter animation completes to animate the scrim alpha with |
| 186 | // the tasks for the home animation. |
| 187 | if (launchState.launchedWhileDocking || launchState.launchedFromApp |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 188 | || isTaskStackEmpty) { |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 189 | mBackgroundScrim.setAlpha((int) (DEFAULT_SCRIM_ALPHA * 255)); |
| 190 | } else { |
| 191 | mBackgroundScrim.setAlpha(0); |
| 192 | } |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 193 | } |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Called from RecentsActivity when the task stack is updated. |
| 198 | */ |
| 199 | public void updateStack(TaskStack stack) { |
| 200 | mStack = stack; |
| 201 | mTaskStackView.setTasks(stack, true /* allowNotifyStackChanges */); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 202 | |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 203 | // Update the top level view's visibilities |
Winson | 4b057c6 | 2016-01-12 15:01:52 -0800 | [diff] [blame] | 204 | if (stack.getTaskCount() > 0) { |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 205 | hideEmptyView(); |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 206 | } else { |
Winson | 196e861 | 2016-03-15 15:20:17 -0700 | [diff] [blame] | 207 | showEmptyView(R.string.recents_empty_message); |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 208 | } |
Winson Chung | 19fc117 | 2014-07-31 18:40:03 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 211 | /** |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 212 | * Returns the current TaskStack. |
| 213 | */ |
| 214 | public TaskStack getStack() { |
| 215 | return mStack; |
| 216 | } |
| 217 | |
| 218 | /** |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 219 | * Returns whether the last task launched was in the freeform stack or not. |
| 220 | */ |
| 221 | public boolean isLastTaskLaunchedFreeform() { |
| 222 | return mLastTaskLaunchedWasFreeform; |
| 223 | } |
| 224 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 225 | /** Launches the focused task from the first stack if possible */ |
Winson | 4232952 | 2016-02-05 10:39:46 -0800 | [diff] [blame] | 226 | public boolean launchFocusedTask(int logEvent) { |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 227 | if (mTaskStackView != null) { |
Winson | 142af42 | 2015-11-09 10:39:57 -0800 | [diff] [blame] | 228 | Task task = mTaskStackView.getFocusedTask(); |
| 229 | if (task != null) { |
| 230 | TaskView taskView = mTaskStackView.getChildViewForTask(task); |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 231 | EventBus.getDefault().send(new LaunchTaskEvent(taskView, task, null, |
| 232 | INVALID_STACK_ID, false)); |
Winson | 4232952 | 2016-02-05 10:39:46 -0800 | [diff] [blame] | 233 | |
| 234 | if (logEvent != 0) { |
| 235 | MetricsLogger.action(getContext(), logEvent, |
| 236 | task.key.getComponent().toString()); |
| 237 | } |
Winson | 142af42 | 2015-11-09 10:39:57 -0800 | [diff] [blame] | 238 | return true; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 239 | } |
| 240 | } |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 241 | return false; |
| 242 | } |
| 243 | |
Winson | a0731a1 | 2015-12-02 15:10:14 -0800 | [diff] [blame] | 244 | /** Launches the task that recents was launched from if possible */ |
| 245 | public boolean launchPreviousTask() { |
| 246 | if (mTaskStackView != null) { |
| 247 | TaskStack stack = mTaskStackView.getStack(); |
| 248 | Task task = stack.getLaunchTarget(); |
| 249 | if (task != null) { |
| 250 | TaskView taskView = mTaskStackView.getChildViewForTask(task); |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 251 | EventBus.getDefault().send(new LaunchTaskEvent(taskView, task, null, |
| 252 | INVALID_STACK_ID, false)); |
Winson | a0731a1 | 2015-12-02 15:10:14 -0800 | [diff] [blame] | 253 | return true; |
| 254 | } |
| 255 | } |
| 256 | return false; |
| 257 | } |
| 258 | |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 259 | /** Launches a given task. */ |
Filip Gruszczynski | f48b585 | 2015-10-13 10:28:22 -0700 | [diff] [blame] | 260 | public boolean launchTask(Task task, Rect taskBounds, int destinationStack) { |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 261 | if (mTaskStackView != null) { |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 262 | // Iterate the stack views and try and find the given task. |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 263 | List<TaskView> taskViews = mTaskStackView.getTaskViews(); |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 264 | int taskViewCount = taskViews.size(); |
| 265 | for (int j = 0; j < taskViewCount; j++) { |
| 266 | TaskView tv = taskViews.get(j); |
| 267 | if (tv.getTask() == task) { |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 268 | EventBus.getDefault().send(new LaunchTaskEvent(tv, task, taskBounds, |
| 269 | destinationStack, false)); |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 270 | return true; |
| 271 | } |
| 272 | } |
| 273 | } |
| 274 | return false; |
| 275 | } |
| 276 | |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 277 | /** |
| 278 | * Hides the task stack and shows the empty view. |
| 279 | */ |
Winson | 196e861 | 2016-03-15 15:20:17 -0700 | [diff] [blame] | 280 | public void showEmptyView(int msgResId) { |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 281 | mTaskStackView.setVisibility(View.INVISIBLE); |
Winson | 196e861 | 2016-03-15 15:20:17 -0700 | [diff] [blame] | 282 | mEmptyView.setText(msgResId); |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 283 | mEmptyView.setVisibility(View.VISIBLE); |
| 284 | mEmptyView.bringToFront(); |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 285 | if (RecentsDebugFlags.Static.EnableStackActionButton) { |
| 286 | mStackActionButton.bringToFront(); |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 287 | } |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | /** |
| 291 | * Shows the task stack and hides the empty view. |
| 292 | */ |
| 293 | public void hideEmptyView() { |
| 294 | mEmptyView.setVisibility(View.INVISIBLE); |
| 295 | mTaskStackView.setVisibility(View.VISIBLE); |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 296 | mTaskStackView.bringToFront(); |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 297 | if (RecentsDebugFlags.Static.EnableStackActionButton) { |
| 298 | mStackActionButton.bringToFront(); |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 299 | } |
Winson Chung | 772b6b1 | 2014-07-03 15:54:02 -0700 | [diff] [blame] | 300 | } |
| 301 | |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 302 | @Override |
| 303 | protected void onAttachedToWindow() { |
| 304 | EventBus.getDefault().register(this, RecentsActivity.EVENT_BUS_PRIORITY + 1); |
Winson | c8a4cdc | 2016-01-19 11:30:51 -0800 | [diff] [blame] | 305 | EventBus.getDefault().register(mTouchHandler, RecentsActivity.EVENT_BUS_PRIORITY + 2); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 306 | super.onAttachedToWindow(); |
| 307 | } |
| 308 | |
| 309 | @Override |
| 310 | protected void onDetachedFromWindow() { |
| 311 | super.onDetachedFromWindow(); |
| 312 | EventBus.getDefault().unregister(this); |
| 313 | EventBus.getDefault().unregister(mTouchHandler); |
| 314 | } |
| 315 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 316 | /** |
| 317 | * This is called with the full size of the window since we are handling our own insets. |
| 318 | */ |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 319 | @Override |
| 320 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 321 | int width = MeasureSpec.getSize(widthMeasureSpec); |
| 322 | int height = MeasureSpec.getSize(heightMeasureSpec); |
Winson Chung | bd91297 | 2014-03-18 14:36:35 -0700 | [diff] [blame] | 323 | |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 324 | if (mTaskStackView.getVisibility() != GONE) { |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 325 | mTaskStackView.measure(widthMeasureSpec, heightMeasureSpec); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 326 | } |
| 327 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 328 | // Measure the empty view to the full size of the screen |
| 329 | if (mEmptyView.getVisibility() != GONE) { |
Winson | 196e861 | 2016-03-15 15:20:17 -0700 | [diff] [blame] | 330 | measureChild(mEmptyView, MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST), |
| 331 | MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST)); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 332 | } |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 333 | |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 334 | if (RecentsDebugFlags.Static.EnableStackActionButton) { |
| 335 | // Measure the stack action button within the constraints of the space above the stack |
| 336 | Rect actionButtonRect = mTaskStackView.mLayoutAlgorithm.mStackActionButtonRect; |
| 337 | measureChild(mStackActionButton, |
| 338 | MeasureSpec.makeMeasureSpec(actionButtonRect.width(), MeasureSpec.AT_MOST), |
| 339 | MeasureSpec.makeMeasureSpec(actionButtonRect.height(), MeasureSpec.AT_MOST)); |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 340 | } |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 341 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 342 | setMeasuredDimension(width, height); |
| 343 | } |
| 344 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 345 | /** |
| 346 | * This is called with the full size of the window since we are handling our own insets. |
| 347 | */ |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 348 | @Override |
| 349 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 350 | if (mTaskStackView.getVisibility() != GONE) { |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 351 | mTaskStackView.layout(left, top, left + getMeasuredWidth(), top + getMeasuredHeight()); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 352 | } |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 353 | |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 354 | // Layout the empty view |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 355 | if (mEmptyView.getVisibility() != GONE) { |
Winson | 196e861 | 2016-03-15 15:20:17 -0700 | [diff] [blame] | 356 | int leftRightInsets = mSystemInsets.left + mSystemInsets.right; |
| 357 | int topBottomInsets = mSystemInsets.top + mSystemInsets.bottom; |
| 358 | int childWidth = mEmptyView.getMeasuredWidth(); |
| 359 | int childHeight = mEmptyView.getMeasuredHeight(); |
| 360 | int childLeft = left + Math.max(0, (right - left - leftRightInsets - childWidth)) / 2; |
| 361 | int childTop = top + Math.max(0, (bottom - top - topBottomInsets - childHeight)) / 2; |
| 362 | mEmptyView.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 363 | } |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 364 | |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 365 | if (RecentsDebugFlags.Static.EnableStackActionButton) { |
| 366 | // Layout the stack action button such that its drawable is start-aligned with the |
| 367 | // stack, vertically centered in the available space above the stack |
| 368 | Rect actionButtonRect = mTaskStackView.mLayoutAlgorithm.mStackActionButtonRect; |
| 369 | int buttonLeft = isLayoutRtl() |
| 370 | ? actionButtonRect.right + mStackActionButton.getPaddingStart() |
| 371 | - mStackActionButton.getMeasuredWidth() |
| 372 | : actionButtonRect.left - mStackActionButton.getPaddingStart(); |
| 373 | int buttonTop = actionButtonRect.top + |
| 374 | (actionButtonRect.height() - mStackActionButton.getMeasuredHeight()) / 2; |
| 375 | mStackActionButton.layout(buttonLeft, buttonTop, |
| 376 | buttonLeft + mStackActionButton.getMeasuredWidth(), |
| 377 | buttonTop + mStackActionButton.getMeasuredHeight()); |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 378 | } |
| 379 | |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 380 | if (mAwaitingFirstLayout) { |
| 381 | mAwaitingFirstLayout = false; |
| 382 | |
| 383 | // If launched via dragging from the nav bar, then we should translate the whole view |
| 384 | // down offscreen |
| 385 | RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState(); |
| 386 | if (launchState.launchedViaDragGesture) { |
| 387 | setTranslationY(getMeasuredHeight()); |
Jorim Jaggi | 0ca8826 | 2015-12-07 17:15:16 -0800 | [diff] [blame] | 388 | } else { |
| 389 | setTranslationY(0f); |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 390 | } |
| 391 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 392 | } |
| 393 | |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 394 | @Override |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 395 | public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 396 | mSystemInsets.set(insets.getSystemWindowInsets()); |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 397 | mTaskStackView.setSystemInsets(mSystemInsets); |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 398 | requestLayout(); |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 399 | return insets; |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 402 | @Override |
| 403 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
| 404 | return mTouchHandler.onInterceptTouchEvent(ev); |
| 405 | } |
| 406 | |
| 407 | @Override |
| 408 | public boolean onTouchEvent(MotionEvent ev) { |
| 409 | return mTouchHandler.onTouchEvent(ev); |
| 410 | } |
| 411 | |
| 412 | @Override |
Winson | be8e696 | 2016-02-01 14:27:52 -0800 | [diff] [blame] | 413 | public void onDrawForeground(Canvas canvas) { |
| 414 | super.onDrawForeground(canvas); |
| 415 | |
Winson | 036693c | 2016-01-14 17:16:06 -0800 | [diff] [blame] | 416 | ArrayList<TaskStack.DockState> visDockStates = mTouchHandler.getVisibleDockStates(); |
| 417 | for (int i = visDockStates.size() - 1; i >= 0; i--) { |
| 418 | Drawable d = visDockStates.get(i).viewState.dockAreaOverlay; |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 419 | if (d.getAlpha() > 0) { |
| 420 | d.draw(canvas); |
| 421 | } |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 425 | @Override |
| 426 | protected boolean verifyDrawable(Drawable who) { |
Winson | 036693c | 2016-01-14 17:16:06 -0800 | [diff] [blame] | 427 | ArrayList<TaskStack.DockState> visDockStates = mTouchHandler.getVisibleDockStates(); |
| 428 | for (int i = visDockStates.size() - 1; i >= 0; i--) { |
| 429 | Drawable d = visDockStates.get(i).viewState.dockAreaOverlay; |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 430 | if (d == who) { |
| 431 | return true; |
| 432 | } |
| 433 | } |
| 434 | return super.verifyDrawable(who); |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 435 | } |
| 436 | |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 437 | /**** EventBus Events ****/ |
| 438 | |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 439 | public final void onBusEvent(LaunchTaskEvent event) { |
| 440 | mLastTaskLaunchedWasFreeform = event.task.isFreeformTask(); |
| 441 | mTransitionHelper.launchTaskFromRecents(mStack, event.task, mTaskStackView, event.taskView, |
| 442 | event.screenPinningRequested, event.targetTaskBounds, event.targetTaskStack); |
| 443 | } |
| 444 | |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 445 | public final void onBusEvent(DismissRecentsToHomeAnimationStarted event) { |
Winson | 5044863 | 2016-02-01 18:04:59 -0800 | [diff] [blame] | 446 | int taskViewExitToHomeDuration = TaskStackAnimationHelper.EXIT_TO_HOME_TRANSLATION_DURATION; |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 447 | if (RecentsDebugFlags.Static.EnableStackActionButton) { |
| 448 | // Hide the stack action button |
| 449 | hideStackActionButton(taskViewExitToHomeDuration, false /* translate */); |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 450 | } |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 451 | animateBackgroundScrim(0f, taskViewExitToHomeDuration); |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 452 | } |
| 453 | |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 454 | public final void onBusEvent(DragStartEvent event) { |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 455 | updateVisibleDockRegions(mTouchHandler.getDockStatesForCurrentOrientation(), |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 456 | true /* isDefaultDockState */, TaskStack.DockState.NONE.viewState.dockAreaAlpha, |
| 457 | true /* animateAlpha */, false /* animateBounds */); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 458 | } |
| 459 | |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 460 | public final void onBusEvent(DragDropTargetChangedEvent event) { |
| 461 | if (event.dropTarget == null || !(event.dropTarget instanceof TaskStack.DockState)) { |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 462 | updateVisibleDockRegions(mTouchHandler.getDockStatesForCurrentOrientation(), |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 463 | true /* isDefaultDockState */, TaskStack.DockState.NONE.viewState.dockAreaAlpha, |
| 464 | true /* animateAlpha */, true /* animateBounds */); |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 465 | } else { |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 466 | final TaskStack.DockState dockState = (TaskStack.DockState) event.dropTarget; |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 467 | updateVisibleDockRegions(new TaskStack.DockState[] {dockState}, |
| 468 | false /* isDefaultDockState */, -1, true /* animateAlpha */, |
| 469 | true /* animateBounds */); |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 470 | } |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | public final void onBusEvent(final DragEndEvent event) { |
Winson | 479f744 | 2015-11-25 15:16:27 -0800 | [diff] [blame] | 474 | // Handle the case where we drop onto a dock region |
| 475 | if (event.dropTarget instanceof TaskStack.DockState) { |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 476 | final TaskStack.DockState dockState = (TaskStack.DockState) event.dropTarget; |
| 477 | |
| 478 | // Hide the dock region |
| 479 | updateVisibleDockRegions(null, false /* isDefaultDockState */, -1, |
| 480 | false /* animateAlpha */, false /* animateBounds */); |
| 481 | |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 482 | TaskStackLayoutAlgorithm stackLayout = mTaskStackView.getStackAlgorithm(); |
| 483 | TaskStackViewScroller stackScroller = mTaskStackView.getScroller(); |
| 484 | TaskViewTransform tmpTransform = new TaskViewTransform(); |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 485 | |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 486 | // We translated the view but we need to animate it back from the current layout-space |
| 487 | // rect to its final layout-space rect |
| 488 | int x = (int) event.taskView.getTranslationX(); |
| 489 | int y = (int) event.taskView.getTranslationY(); |
| 490 | Rect taskViewRect = new Rect(event.taskView.getLeft(), event.taskView.getTop(), |
| 491 | event.taskView.getRight(), event.taskView.getBottom()); |
| 492 | taskViewRect.offset(x, y); |
| 493 | event.taskView.setTranslationX(0); |
| 494 | event.taskView.setTranslationY(0); |
| 495 | event.taskView.setLeftTopRightBottom(taskViewRect.left, taskViewRect.top, |
| 496 | taskViewRect.right, taskViewRect.bottom); |
| 497 | |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 498 | final OnAnimationStartedListener startedListener = new OnAnimationStartedListener() { |
| 499 | @Override |
| 500 | public void onAnimationStarted() { |
| 501 | EventBus.getDefault().send(new DockedFirstAnimationFrameEvent()); |
| 502 | mTaskStackView.getStack().removeTask(event.task, AnimationProps.IMMEDIATE, |
| 503 | true /* fromDockGesture */); |
| 504 | } |
| 505 | }; |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 506 | |
| 507 | // Dock the task and launch it |
| 508 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 509 | ssp.startTaskInDockedMode(event.task.key.id, dockState.createMode); |
| 510 | final Rect taskRect = getTaskRect(event.taskView); |
| 511 | IAppTransitionAnimationSpecsFuture future = mTransitionHelper.getAppTransitionFuture( |
| 512 | new AnimationSpecComposer() { |
| 513 | @Override |
| 514 | public List<AppTransitionAnimationSpec> composeSpecs() { |
| 515 | return mTransitionHelper.composeDockAnimationSpec( |
| 516 | event.taskView, taskRect); |
| 517 | } |
| 518 | }); |
| 519 | ssp.overridePendingAppTransitionMultiThumbFuture(future, |
| 520 | mTransitionHelper.wrapStartedListener(startedListener), |
| 521 | true /* scaleUp */); |
Winson | a0a8ae4 | 2015-12-01 10:43:02 -0800 | [diff] [blame] | 522 | |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 523 | MetricsLogger.action(mContext, MetricsEvent.ACTION_WINDOW_DOCK_DRAG_DROP); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 524 | } else { |
| 525 | // Animate the overlay alpha back to 0 |
| 526 | updateVisibleDockRegions(null, true /* isDefaultDockState */, -1, |
| 527 | true /* animateAlpha */, false /* animateBounds */); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 528 | } |
| 529 | } |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 530 | |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 531 | private Rect getTaskRect(TaskView taskView) { |
| 532 | int[] location = taskView.getLocationOnScreen(); |
| 533 | int viewX = location[0]; |
| 534 | int viewY = location[1]; |
| 535 | return new Rect(viewX, viewY, |
| 536 | (int) (viewX + taskView.getWidth() * taskView.getScaleX()), |
| 537 | (int) (viewY + taskView.getHeight() * taskView.getScaleY())); |
| 538 | } |
| 539 | |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 540 | public final void onBusEvent(DraggingInRecentsEvent event) { |
Jorim Jaggi | 54b1a6d | 2015-11-24 17:48:26 -0800 | [diff] [blame] | 541 | if (mTaskStackView.getTaskViews().size() > 0) { |
| 542 | setTranslationY(event.distanceFromTop - mTaskStackView.getTaskViews().get(0).getY()); |
| 543 | } |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | public final void onBusEvent(DraggingInRecentsEndedEvent event) { |
Jorim Jaggi | 870ab5a | 2015-12-02 18:37:54 -0800 | [diff] [blame] | 547 | ViewPropertyAnimator animator = animate(); |
Jorim Jaggi | 8fccfe2 | 2015-12-03 16:58:08 -0800 | [diff] [blame] | 548 | if (event.velocity > mFlingAnimationUtils.getMinVelocityPxPerSecond()) { |
Jorim Jaggi | 870ab5a | 2015-12-02 18:37:54 -0800 | [diff] [blame] | 549 | animator.translationY(getHeight()); |
| 550 | animator.withEndAction(new Runnable() { |
| 551 | @Override |
| 552 | public void run() { |
| 553 | WindowManagerProxy.getInstance().maximizeDockedStack(); |
| 554 | } |
| 555 | }); |
| 556 | mFlingAnimationUtils.apply(animator, getTranslationY(), getHeight(), event.velocity); |
| 557 | } else { |
| 558 | animator.translationY(0f); |
| 559 | animator.setListener(null); |
| 560 | mFlingAnimationUtils.apply(animator, getTranslationY(), 0, event.velocity); |
| 561 | } |
| 562 | animator.start(); |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 563 | } |
| 564 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 565 | public final void onBusEvent(EnterRecentsWindowAnimationCompletedEvent event) { |
| 566 | RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState(); |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 567 | if (!launchState.launchedWhileDocking && !launchState.launchedFromApp |
Jorim Jaggi | e161f08 | 2016-02-05 14:26:16 -0800 | [diff] [blame] | 568 | && mStack.getTaskCount() > 0) { |
Winson | 5044863 | 2016-02-01 18:04:59 -0800 | [diff] [blame] | 569 | animateBackgroundScrim(DEFAULT_SCRIM_ALPHA, |
| 570 | TaskStackAnimationHelper.ENTER_FROM_HOME_TRANSLATION_DURATION); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 571 | } |
| 572 | } |
| 573 | |
| 574 | public final void onBusEvent(UpdateBackgroundScrimEvent event) { |
| 575 | animateBackgroundScrim(event.alpha, DEFAULT_UPDATE_SCRIM_DURATION); |
| 576 | } |
| 577 | |
| 578 | public final void onBusEvent(ResetBackgroundScrimEvent event) { |
| 579 | animateBackgroundScrim(DEFAULT_SCRIM_ALPHA, DEFAULT_UPDATE_SCRIM_DURATION); |
| 580 | } |
| 581 | |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 582 | public final void onBusEvent(ShowStackActionButtonEvent event) { |
| 583 | if (!RecentsDebugFlags.Static.EnableStackActionButton) { |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 584 | return; |
| 585 | } |
| 586 | |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 587 | showStackActionButton(150, event.translate); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 588 | } |
| 589 | |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 590 | public final void onBusEvent(HideStackActionButtonEvent event) { |
| 591 | if (!RecentsDebugFlags.Static.EnableStackActionButton) { |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 592 | return; |
| 593 | } |
| 594 | |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 595 | hideStackActionButton(100, true /* translate */); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 596 | } |
| 597 | |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 598 | /** |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 599 | * Shows the stack action button. |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 600 | */ |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 601 | private void showStackActionButton(final int duration, final boolean translate) { |
| 602 | if (!RecentsDebugFlags.Static.EnableStackActionButton) { |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 603 | return; |
| 604 | } |
| 605 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 606 | final ReferenceCountedTrigger postAnimationTrigger = new ReferenceCountedTrigger(); |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 607 | if (mStackActionButton.getVisibility() == View.INVISIBLE) { |
| 608 | mStackActionButton.setVisibility(View.VISIBLE); |
| 609 | mStackActionButton.setAlpha(0f); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 610 | if (translate) { |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 611 | mStackActionButton.setTranslationY(-mStackActionButton.getMeasuredHeight() * 0.25f); |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 612 | } else { |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 613 | mStackActionButton.setTranslationY(0f); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 614 | } |
| 615 | postAnimationTrigger.addLastDecrementRunnable(new Runnable() { |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 616 | @Override |
| 617 | public void run() { |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 618 | if (translate) { |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 619 | mStackActionButton.animate() |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 620 | .translationY(0f); |
| 621 | } |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 622 | mStackActionButton.animate() |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 623 | .alpha(1f) |
| 624 | .setDuration(duration) |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 625 | .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 626 | .withLayer() |
| 627 | .start(); |
| 628 | } |
| 629 | }); |
| 630 | } |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 631 | postAnimationTrigger.flushLastDecrementRunnables(); |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | /** |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 635 | * Hides the stack action button. |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 636 | */ |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 637 | private void hideStackActionButton(int duration, boolean translate) { |
| 638 | if (!RecentsDebugFlags.Static.EnableStackActionButton) { |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 639 | return; |
| 640 | } |
| 641 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 642 | final ReferenceCountedTrigger postAnimationTrigger = new ReferenceCountedTrigger(); |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 643 | hideStackActionButton(duration, translate, postAnimationTrigger); |
Winson Chung | aaeaac1 | 2015-12-16 16:49:36 -0500 | [diff] [blame] | 644 | postAnimationTrigger.flushLastDecrementRunnables(); |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 645 | } |
| 646 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 647 | /** |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 648 | * Hides the stack action button. |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 649 | */ |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 650 | private void hideStackActionButton(int duration, boolean translate, |
| 651 | final ReferenceCountedTrigger postAnimationTrigger) { |
| 652 | if (!RecentsDebugFlags.Static.EnableStackActionButton) { |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 653 | return; |
| 654 | } |
| 655 | |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 656 | if (mStackActionButton.getVisibility() == View.VISIBLE) { |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 657 | if (translate) { |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 658 | mStackActionButton.animate() |
| 659 | .translationY(-mStackActionButton.getMeasuredHeight() * 0.25f); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 660 | } |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 661 | mStackActionButton.animate() |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 662 | .alpha(0f) |
| 663 | .setDuration(duration) |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 664 | .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 665 | .withEndAction(new Runnable() { |
| 666 | @Override |
| 667 | public void run() { |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 668 | mStackActionButton.setVisibility(View.INVISIBLE); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 669 | postAnimationTrigger.decrement(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 670 | } |
| 671 | }) |
| 672 | .withLayer() |
| 673 | .start(); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 674 | postAnimationTrigger.increment(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 675 | } |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 676 | } |
| 677 | |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 678 | /** |
| 679 | * Updates the dock region to match the specified dock state. |
| 680 | */ |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 681 | private void updateVisibleDockRegions(TaskStack.DockState[] newDockStates, |
| 682 | boolean isDefaultDockState, int overrideAlpha, boolean animateAlpha, |
| 683 | boolean animateBounds) { |
Winson | c5fd350 | 2016-01-18 15:18:37 -0800 | [diff] [blame] | 684 | ArraySet<TaskStack.DockState> newDockStatesSet = Utilities.arrayToSet(newDockStates, |
| 685 | new ArraySet<TaskStack.DockState>()); |
Winson | 036693c | 2016-01-14 17:16:06 -0800 | [diff] [blame] | 686 | ArrayList<TaskStack.DockState> visDockStates = mTouchHandler.getVisibleDockStates(); |
| 687 | for (int i = visDockStates.size() - 1; i >= 0; i--) { |
| 688 | TaskStack.DockState dockState = visDockStates.get(i); |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 689 | TaskStack.DockState.ViewState viewState = dockState.viewState; |
| 690 | if (newDockStates == null || !newDockStatesSet.contains(dockState)) { |
| 691 | // This is no longer visible, so hide it |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 692 | viewState.startAnimation(null, 0, DOCK_AREA_OVERLAY_TRANSITION_DURATION, |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 693 | Interpolators.ALPHA_OUT, animateAlpha, animateBounds); |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 694 | } else { |
| 695 | // This state is now visible, update the bounds and show it |
| 696 | int alpha = (overrideAlpha != -1 ? overrideAlpha : viewState.dockAreaAlpha); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 697 | Rect bounds = isDefaultDockState |
| 698 | ? dockState.getPreDockedBounds(getMeasuredWidth(), getMeasuredHeight()) |
| 699 | : dockState.getDockedBounds(getMeasuredWidth(), getMeasuredHeight(), |
| 700 | mDividerSize, mSystemInsets, getResources()); |
| 701 | if (viewState.dockAreaOverlay.getCallback() != this) { |
| 702 | viewState.dockAreaOverlay.setCallback(this); |
| 703 | viewState.dockAreaOverlay.setBounds(bounds); |
| 704 | } |
| 705 | viewState.startAnimation(bounds, alpha, DOCK_AREA_OVERLAY_TRANSITION_DURATION, |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 706 | Interpolators.ALPHA_IN, animateAlpha, animateBounds); |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 707 | } |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 708 | } |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 709 | } |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 710 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 711 | /** |
| 712 | * Animates the background scrim to the given {@param alpha}. |
| 713 | */ |
| 714 | private void animateBackgroundScrim(float alpha, int duration) { |
| 715 | Utilities.cancelAnimationWithoutCallbacks(mBackgroundScrimAnimator); |
| 716 | int alphaInt = (int) (alpha * 255); |
| 717 | mBackgroundScrimAnimator = ObjectAnimator.ofInt(mBackgroundScrim, Utilities.DRAWABLE_ALPHA, |
| 718 | mBackgroundScrim.getAlpha(), alphaInt); |
| 719 | mBackgroundScrimAnimator.setDuration(duration); |
| 720 | mBackgroundScrimAnimator.setInterpolator(alphaInt > mBackgroundScrim.getAlpha() |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 721 | ? Interpolators.ALPHA_OUT |
| 722 | : Interpolators.ALPHA_IN); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 723 | mBackgroundScrimAnimator.start(); |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 724 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 725 | } |