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