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