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 | |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 19 | import android.app.ActivityManager; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 20 | import android.app.ActivityOptions; |
| 21 | import android.content.Context; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 22 | import android.graphics.Bitmap; |
| 23 | import android.graphics.Canvas; |
| 24 | import android.graphics.Rect; |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 25 | import android.graphics.drawable.Drawable; |
Jorim Jaggi | 6e18e00 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 26 | import android.os.Bundle; |
| 27 | import android.os.IRemoteCallback; |
| 28 | import android.os.RemoteException; |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 29 | import android.util.ArraySet; |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 30 | import android.util.AttributeSet; |
Jorim Jaggi | 6e18e00 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 31 | import android.util.Log; |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 32 | import android.util.SparseArray; |
| 33 | import android.view.AppTransitionAnimationSpec; |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 34 | import android.view.LayoutInflater; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 35 | import android.view.MotionEvent; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 36 | import android.view.View; |
Winson Chung | 653f70c2 | 2014-05-19 14:49:42 -0700 | [diff] [blame] | 37 | import android.view.WindowInsets; |
Jorim Jaggi | 6e18e00 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 38 | import android.view.WindowManagerGlobal; |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 39 | import android.view.animation.AnimationUtils; |
| 40 | import android.view.animation.Interpolator; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 41 | import android.widget.FrameLayout; |
Winson Chung | 5c9f4b9 | 2015-06-25 16:16:46 -0700 | [diff] [blame] | 42 | import com.android.internal.logging.MetricsLogger; |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 43 | import com.android.systemui.R; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 44 | import com.android.systemui.recents.Constants; |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 45 | import com.android.systemui.recents.Recents; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 46 | import com.android.systemui.recents.RecentsActivity; |
Winson Chung | aee097c | 2015-04-02 18:16:02 -0700 | [diff] [blame] | 47 | import com.android.systemui.recents.RecentsAppWidgetHostView; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 48 | import com.android.systemui.recents.RecentsConfiguration; |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 49 | import com.android.systemui.recents.events.EventBus; |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 50 | import com.android.systemui.recents.events.activity.DismissRecentsToHomeAnimationStarted; |
| 51 | import com.android.systemui.recents.events.component.ScreenPinningRequestEvent; |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 52 | import com.android.systemui.recents.events.ui.DismissTaskViewEvent; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 53 | import com.android.systemui.recents.events.ui.dragndrop.DragDockStateChangedEvent; |
| 54 | import com.android.systemui.recents.events.ui.dragndrop.DragEndEvent; |
| 55 | import com.android.systemui.recents.events.ui.dragndrop.DragStartEvent; |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 56 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 57 | import com.android.systemui.recents.model.Task; |
| 58 | import com.android.systemui.recents.model.TaskStack; |
| 59 | |
| 60 | import java.util.ArrayList; |
Winson Chung | 6ac8bd6 | 2015-01-07 16:38:35 -0800 | [diff] [blame] | 61 | import java.util.List; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 62 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame^] | 63 | import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID; |
| 64 | import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; |
| 65 | import static android.app.ActivityManager.StackId.INVALID_STACK_ID; |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 66 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 67 | /** |
| 68 | * This view is the the top level layout that contains TaskStacks (which are laid out according |
| 69 | * to their SpaceNode bounds. |
| 70 | */ |
Winson | e6c9073 | 2015-09-24 16:06:29 -0700 | [diff] [blame] | 71 | public class RecentsView extends FrameLayout implements TaskStackView.TaskStackViewCallbacks { |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 72 | |
Jorim Jaggi | 6e18e00 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 73 | private static final String TAG = "RecentsView"; |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 74 | private static final boolean DEBUG = false; |
Jorim Jaggi | 6e18e00 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 75 | |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 76 | private static final boolean ADD_HEADER_BITMAP = true; |
| 77 | |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 78 | /** The RecentsView callbacks */ |
| 79 | public interface RecentsViewCallbacks { |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 80 | public void onTaskViewClicked(); |
Winson Chung | 4e96eb7 | 2014-09-17 15:16:09 +0200 | [diff] [blame] | 81 | public void onTaskLaunchFailed(); |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 82 | public void onAllTaskViewsDismissed(); |
Jorim Jaggi | 6e18e00 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 83 | public void runAfterPause(Runnable r); |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 86 | LayoutInflater mInflater; |
| 87 | |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 88 | ArrayList<TaskStack> mStacks; |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 89 | TaskStackView mTaskStackView; |
Winson Chung | aee097c | 2015-04-02 18:16:02 -0700 | [diff] [blame] | 90 | RecentsAppWidgetHostView mSearchBar; |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 91 | RecentsViewCallbacks mCb; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 92 | |
| 93 | RecentsViewTouchHandler mTouchHandler; |
| 94 | DragView mDragView; |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 95 | TaskStack.DockState[] mVisibleDockStates = { |
| 96 | TaskStack.DockState.LEFT, |
| 97 | TaskStack.DockState.TOP, |
| 98 | TaskStack.DockState.RIGHT, |
| 99 | TaskStack.DockState.BOTTOM, |
| 100 | }; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 101 | |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 102 | Interpolator mFastOutSlowInInterpolator; |
| 103 | |
| 104 | Rect mSystemInsets = new Rect(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 105 | |
| 106 | public RecentsView(Context context) { |
| 107 | super(context); |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | public RecentsView(Context context, AttributeSet attrs) { |
| 111 | this(context, attrs, 0); |
| 112 | } |
| 113 | |
| 114 | public RecentsView(Context context, AttributeSet attrs, int defStyleAttr) { |
| 115 | this(context, attrs, defStyleAttr, 0); |
| 116 | } |
| 117 | |
| 118 | public RecentsView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
| 119 | super(context, attrs, defStyleAttr, defStyleRes); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 120 | setWillNotDraw(false); |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 121 | mInflater = LayoutInflater.from(context); |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 122 | mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context, |
| 123 | com.android.internal.R.interpolator.fast_out_slow_in); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 124 | mTouchHandler = new RecentsViewTouchHandler(this); |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 125 | } |
| 126 | |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 127 | /** Sets the callbacks */ |
| 128 | public void setCallbacks(RecentsViewCallbacks cb) { |
| 129 | mCb = cb; |
| 130 | } |
| 131 | |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 132 | /** Set/get the bsp root node */ |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 133 | public void setTaskStack(TaskStack stack) { |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 134 | RecentsConfiguration config = Recents.getConfiguration(); |
| 135 | if (config.getLaunchState().launchedReuseTaskStackViews) { |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 136 | if (mTaskStackView != null) { |
| 137 | // If onRecentsHidden is not triggered, we need to the stack view again here |
| 138 | mTaskStackView.reset(); |
| 139 | mTaskStackView.setStack(stack); |
| 140 | } else { |
| 141 | mTaskStackView = new TaskStackView(getContext(), stack); |
| 142 | mTaskStackView.setCallbacks(this); |
| 143 | addView(mTaskStackView); |
| 144 | } |
| 145 | } else { |
| 146 | if (mTaskStackView != null) { |
| 147 | removeView(mTaskStackView); |
| 148 | } |
| 149 | mTaskStackView = new TaskStackView(getContext(), stack); |
| 150 | mTaskStackView.setCallbacks(this); |
| 151 | addView(mTaskStackView); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 152 | } |
Winson Chung | 02d4927 | 2014-08-29 13:57:29 -0700 | [diff] [blame] | 153 | |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 154 | // Trigger a new layout |
| 155 | requestLayout(); |
Winson Chung | 19fc117 | 2014-07-31 18:40:03 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 158 | /** Gets the next task in the stack - or if the last - the top task */ |
| 159 | public Task getNextTaskOrTopTask(Task taskToSearch) { |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 160 | Task returnTask = null; |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 161 | boolean found = false; |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 162 | if (mTaskStackView != null) { |
| 163 | TaskStack stack = mTaskStackView.getStack(); |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 164 | ArrayList<Task> taskList = stack.getTasks(); |
| 165 | // Iterate the stack views and try and find the focused task |
| 166 | for (int j = taskList.size() - 1; j >= 0; --j) { |
| 167 | Task task = taskList.get(j); |
| 168 | // Return the next task in the line. |
| 169 | if (found) |
| 170 | return task; |
| 171 | // Remember the first possible task as the top task. |
| 172 | if (returnTask == null) |
| 173 | returnTask = task; |
| 174 | if (task == taskToSearch) |
| 175 | found = true; |
| 176 | } |
| 177 | } |
| 178 | return returnTask; |
| 179 | } |
| 180 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 181 | /** Launches the focused task from the first stack if possible */ |
| 182 | public boolean launchFocusedTask() { |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 183 | if (mTaskStackView != null) { |
| 184 | TaskStack stack = mTaskStackView.getStack(); |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 185 | // Iterate the stack views and try and find the focused task |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 186 | List<TaskView> taskViews = mTaskStackView.getTaskViews(); |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 187 | int taskViewCount = taskViews.size(); |
| 188 | for (int j = 0; j < taskViewCount; j++) { |
| 189 | TaskView tv = taskViews.get(j); |
| 190 | Task task = tv.getTask(); |
| 191 | if (tv.isFocusedTask()) { |
Filip Gruszczynski | f48b585 | 2015-10-13 10:28:22 -0700 | [diff] [blame] | 192 | onTaskViewClicked(mTaskStackView, tv, stack, task, false, false, null, |
| 193 | INVALID_STACK_ID); |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 194 | return true; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 195 | } |
| 196 | } |
| 197 | } |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 198 | return false; |
| 199 | } |
| 200 | |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 201 | /** Launches a given task. */ |
Filip Gruszczynski | f48b585 | 2015-10-13 10:28:22 -0700 | [diff] [blame] | 202 | public boolean launchTask(Task task, Rect taskBounds, int destinationStack) { |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 203 | if (mTaskStackView != null) { |
| 204 | TaskStack stack = mTaskStackView.getStack(); |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 205 | // Iterate the stack views and try and find the given task. |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 206 | List<TaskView> taskViews = mTaskStackView.getTaskViews(); |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 207 | int taskViewCount = taskViews.size(); |
| 208 | for (int j = 0; j < taskViewCount; j++) { |
| 209 | TaskView tv = taskViews.get(j); |
| 210 | if (tv.getTask() == task) { |
Winson | b1bbaed | 2015-09-23 15:45:11 -0700 | [diff] [blame] | 211 | onTaskViewClicked(mTaskStackView, tv, stack, task, false, taskBounds != null, |
Filip Gruszczynski | f48b585 | 2015-10-13 10:28:22 -0700 | [diff] [blame] | 212 | taskBounds, destinationStack); |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 213 | return true; |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | return false; |
| 218 | } |
| 219 | |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 220 | /** Launches the task that Recents was launched from, if possible */ |
| 221 | public boolean launchPreviousTask() { |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 222 | if (mTaskStackView != null) { |
| 223 | TaskStack stack = mTaskStackView.getStack(); |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 224 | ArrayList<Task> tasks = stack.getTasks(); |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 225 | |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 226 | // Find the launch task in the stack |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 227 | // TODO: replace this with an event from RecentsActivity |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 228 | if (!tasks.isEmpty()) { |
| 229 | int taskCount = tasks.size(); |
| 230 | for (int j = 0; j < taskCount; j++) { |
| 231 | if (tasks.get(j).isLaunchTarget) { |
| 232 | Task task = tasks.get(j); |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 233 | TaskView tv = mTaskStackView.getChildViewForTask(task); |
Filip Gruszczynski | f48b585 | 2015-10-13 10:28:22 -0700 | [diff] [blame] | 234 | onTaskViewClicked(mTaskStackView, tv, stack, task, false, false, null, |
| 235 | INVALID_STACK_ID); |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 236 | return true; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 237 | } |
| 238 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 239 | } |
| 240 | } |
| 241 | return false; |
| 242 | } |
| 243 | |
Winson Chung | 24cf152 | 2014-05-29 12:03:33 -0700 | [diff] [blame] | 244 | /** Requests all task stacks to start their enter-recents animation */ |
Winson Chung | 969f586 | 2014-06-16 17:08:24 -0700 | [diff] [blame] | 245 | public void startEnterRecentsAnimation(ViewAnimation.TaskViewEnterContext ctx) { |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 246 | // We have to increment/decrement the post animation trigger in case there are no children |
| 247 | // to ensure that it runs |
| 248 | ctx.postAnimationTrigger.increment(); |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 249 | if (mTaskStackView != null) { |
| 250 | mTaskStackView.startEnterRecentsAnimation(ctx); |
Winson Chung | 24cf152 | 2014-05-29 12:03:33 -0700 | [diff] [blame] | 251 | } |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 252 | ctx.postAnimationTrigger.decrement(); |
Winson Chung | 24cf152 | 2014-05-29 12:03:33 -0700 | [diff] [blame] | 253 | } |
| 254 | |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 255 | /** Requests all task stacks to start their exit-recents animation */ |
Winson Chung | 969f586 | 2014-06-16 17:08:24 -0700 | [diff] [blame] | 256 | public void startExitToHomeAnimation(ViewAnimation.TaskViewExitContext ctx) { |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 257 | // We have to increment/decrement the post animation trigger in case there are no children |
| 258 | // to ensure that it runs |
| 259 | ctx.postAnimationTrigger.increment(); |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 260 | if (mTaskStackView != null) { |
| 261 | mTaskStackView.startExitToHomeAnimation(ctx); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 262 | } |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 263 | ctx.postAnimationTrigger.decrement(); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 264 | |
Winson Chung | 969f586 | 2014-06-16 17:08:24 -0700 | [diff] [blame] | 265 | // Notify of the exit animation |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 266 | EventBus.getDefault().send(new DismissRecentsToHomeAnimationStarted()); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 269 | /** Adds the search bar */ |
Winson Chung | aee097c | 2015-04-02 18:16:02 -0700 | [diff] [blame] | 270 | public void setSearchBar(RecentsAppWidgetHostView searchBar) { |
Winson Chung | af3bb69 | 2015-06-03 17:31:39 -0700 | [diff] [blame] | 271 | // Remove the previous search bar if one exists |
| 272 | if (mSearchBar != null && indexOfChild(mSearchBar) > -1) { |
| 273 | removeView(mSearchBar); |
| 274 | } |
| 275 | // Add the new search bar |
| 276 | if (searchBar != null) { |
| 277 | mSearchBar = searchBar; |
| 278 | addView(mSearchBar); |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 279 | } |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Winson Chung | 772b6b1 | 2014-07-03 15:54:02 -0700 | [diff] [blame] | 282 | /** Returns whether there is currently a search bar */ |
Winson Chung | aee097c | 2015-04-02 18:16:02 -0700 | [diff] [blame] | 283 | public boolean hasValidSearchBar() { |
| 284 | return mSearchBar != null && !mSearchBar.isReinflateRequired(); |
Winson Chung | 772b6b1 | 2014-07-03 15:54:02 -0700 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | /** Sets the visibility of the search bar */ |
| 288 | public void setSearchBarVisibility(int visibility) { |
| 289 | if (mSearchBar != null) { |
| 290 | mSearchBar.setVisibility(visibility); |
Winson Chung | 012ef36 | 2014-07-31 18:36:25 -0700 | [diff] [blame] | 291 | // Always bring the search bar to the top |
| 292 | mSearchBar.bringToFront(); |
Winson Chung | 772b6b1 | 2014-07-03 15:54:02 -0700 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 296 | @Override |
| 297 | protected void onAttachedToWindow() { |
| 298 | EventBus.getDefault().register(this, RecentsActivity.EVENT_BUS_PRIORITY + 1); |
| 299 | EventBus.getDefault().register(mTouchHandler, RecentsActivity.EVENT_BUS_PRIORITY + 1); |
| 300 | super.onAttachedToWindow(); |
| 301 | } |
| 302 | |
| 303 | @Override |
| 304 | protected void onDetachedFromWindow() { |
| 305 | super.onDetachedFromWindow(); |
| 306 | EventBus.getDefault().unregister(this); |
| 307 | EventBus.getDefault().unregister(mTouchHandler); |
| 308 | } |
| 309 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 310 | /** |
| 311 | * This is called with the full size of the window since we are handling our own insets. |
| 312 | */ |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 313 | @Override |
| 314 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 315 | RecentsConfiguration config = Recents.getConfiguration(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 316 | int width = MeasureSpec.getSize(widthMeasureSpec); |
| 317 | int height = MeasureSpec.getSize(heightMeasureSpec); |
Winson Chung | bd91297 | 2014-03-18 14:36:35 -0700 | [diff] [blame] | 318 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 319 | // Get the search bar bounds and measure the search bar layout |
Winson Chung | af3bb69 | 2015-06-03 17:31:39 -0700 | [diff] [blame] | 320 | Rect searchBarSpaceBounds = new Rect(); |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 321 | if (mSearchBar != null) { |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 322 | config.getSearchBarBounds(new Rect(0, 0, width, height), mSystemInsets.top, |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 323 | searchBarSpaceBounds); |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 324 | mSearchBar.measure( |
| 325 | MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.width(), MeasureSpec.EXACTLY), |
| 326 | MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.height(), MeasureSpec.EXACTLY)); |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 329 | Rect taskStackBounds = new Rect(); |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 330 | config.getTaskStackBounds(new Rect(0, 0, width, height), mSystemInsets.top, |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 331 | mSystemInsets.right, searchBarSpaceBounds, taskStackBounds); |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 332 | if (mTaskStackView != null && mTaskStackView.getVisibility() != GONE) { |
Winson | 88f00ab | 2015-10-05 17:24:00 -0700 | [diff] [blame] | 333 | mTaskStackView.setTaskStackBounds(taskStackBounds, mSystemInsets); |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 334 | mTaskStackView.measure(widthMeasureSpec, heightMeasureSpec); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 335 | } |
| 336 | |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 337 | if (mDragView != null) { |
| 338 | mDragView.measure( |
| 339 | MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST), |
| 340 | MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST)); |
| 341 | } |
| 342 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 343 | setMeasuredDimension(width, height); |
| 344 | } |
| 345 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 346 | /** |
| 347 | * This is called with the full size of the window since we are handling our own insets. |
| 348 | */ |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 349 | @Override |
| 350 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 351 | RecentsConfiguration config = Recents.getConfiguration(); |
| 352 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 353 | // Get the search bar bounds so that we lay it out |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 354 | Rect measuredRect = new Rect(0, 0, getMeasuredWidth(), getMeasuredHeight()); |
| 355 | Rect searchBarSpaceBounds = new Rect(); |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 356 | if (mSearchBar != null) { |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 357 | config.getSearchBarBounds(measuredRect, |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 358 | mSystemInsets.top, searchBarSpaceBounds); |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 359 | mSearchBar.layout(searchBarSpaceBounds.left, searchBarSpaceBounds.top, |
| 360 | searchBarSpaceBounds.right, searchBarSpaceBounds.bottom); |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 363 | if (mTaskStackView != null && mTaskStackView.getVisibility() != GONE) { |
| 364 | mTaskStackView.layout(left, top, left + getMeasuredWidth(), top + getMeasuredHeight()); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 365 | } |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 366 | |
| 367 | if (mDragView != null) { |
| 368 | mDragView.layout(left, top, left + mDragView.getMeasuredWidth(), |
| 369 | top + mDragView.getMeasuredHeight()); |
| 370 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 371 | } |
| 372 | |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 373 | @Override |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 374 | public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 375 | mSystemInsets.set(insets.getSystemWindowInsets()); |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 376 | requestLayout(); |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 377 | return insets.consumeSystemWindowInsets(); |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 380 | @Override |
| 381 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
| 382 | return mTouchHandler.onInterceptTouchEvent(ev); |
| 383 | } |
| 384 | |
| 385 | @Override |
| 386 | public boolean onTouchEvent(MotionEvent ev) { |
| 387 | return mTouchHandler.onTouchEvent(ev); |
| 388 | } |
| 389 | |
| 390 | @Override |
| 391 | protected void dispatchDraw(Canvas canvas) { |
| 392 | super.dispatchDraw(canvas); |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 393 | for (int i = mVisibleDockStates.length - 1; i >= 0; i--) { |
| 394 | Drawable d = mVisibleDockStates[i].viewState.dockAreaOverlay; |
| 395 | if (d.getAlpha() > 0) { |
| 396 | d.draw(canvas); |
| 397 | } |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 398 | } |
| 399 | } |
| 400 | |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 401 | @Override |
| 402 | protected boolean verifyDrawable(Drawable who) { |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 403 | for (int i = mVisibleDockStates.length - 1; i >= 0; i--) { |
| 404 | Drawable d = mVisibleDockStates[i].viewState.dockAreaOverlay; |
| 405 | if (d == who) { |
| 406 | return true; |
| 407 | } |
| 408 | } |
| 409 | return super.verifyDrawable(who); |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 412 | /** Unfilters any filtered stacks */ |
| 413 | public boolean unfilterFilteredStacks() { |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 414 | if (mStacks != null) { |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 415 | // Check if there are any filtered stacks and unfilter them before we back out of Recents |
| 416 | boolean stacksUnfiltered = false; |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 417 | int numStacks = mStacks.size(); |
| 418 | for (int i = 0; i < numStacks; i++) { |
| 419 | TaskStack stack = mStacks.get(i); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 420 | if (stack.hasFilteredTasks()) { |
| 421 | stack.unfilterTasks(); |
| 422 | stacksUnfiltered = true; |
| 423 | } |
| 424 | } |
| 425 | return stacksUnfiltered; |
| 426 | } |
| 427 | return false; |
| 428 | } |
| 429 | |
Jorim Jaggi | 900fb48 | 2015-06-02 15:07:33 -0700 | [diff] [blame] | 430 | public void disableLayersForOneFrame() { |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 431 | if (mTaskStackView != null) { |
| 432 | mTaskStackView.disableLayersForOneFrame(); |
Jorim Jaggi | 900fb48 | 2015-06-02 15:07:33 -0700 | [diff] [blame] | 433 | } |
| 434 | } |
| 435 | |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 436 | private void postDrawHeaderThumbnailTransitionRunnable(final TaskStackView view, |
| 437 | final TaskView clickedView, final int offsetX, final int offsetY, |
| 438 | final float stackScroll, |
Filip Gruszczynski | f48b585 | 2015-10-13 10:28:22 -0700 | [diff] [blame] | 439 | final ActivityOptions.OnAnimationStartedListener animStartedListener, |
| 440 | final int destinationStack) { |
Jorim Jaggi | 6e18e00 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 441 | Runnable r = new Runnable() { |
| 442 | @Override |
| 443 | public void run() { |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 444 | overrideDrawHeaderThumbnailTransition(view, clickedView, offsetX, offsetY, |
Filip Gruszczynski | f48b585 | 2015-10-13 10:28:22 -0700 | [diff] [blame] | 445 | stackScroll, animStartedListener, destinationStack); |
Jorim Jaggi | 6e18e00 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 446 | |
Jorim Jaggi | 6e18e00 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 447 | } |
| 448 | }; |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 449 | |
Jorim Jaggi | 6e18e00 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 450 | mCb.runAfterPause(r); |
| 451 | } |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 452 | |
| 453 | private void overrideDrawHeaderThumbnailTransition(TaskStackView stackView, |
| 454 | TaskView clickedTask, int offsetX, int offsetY, float stackScroll, |
Filip Gruszczynski | f48b585 | 2015-10-13 10:28:22 -0700 | [diff] [blame] | 455 | final ActivityOptions.OnAnimationStartedListener animStartedListener, |
| 456 | int destinationStack) { |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 457 | List<AppTransitionAnimationSpec> specs = getAppTransitionAnimationSpecs(stackView, |
Filip Gruszczynski | f48b585 | 2015-10-13 10:28:22 -0700 | [diff] [blame] | 458 | clickedTask, offsetX, offsetY, stackScroll, destinationStack); |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 459 | if (specs == null) { |
| 460 | return; |
| 461 | } |
| 462 | |
| 463 | IRemoteCallback.Stub callback = new IRemoteCallback.Stub() { |
| 464 | @Override |
| 465 | public void sendResult(Bundle data) throws RemoteException { |
| 466 | post(new Runnable() { |
| 467 | @Override |
| 468 | public void run() { |
| 469 | if (animStartedListener != null) { |
| 470 | animStartedListener.onAnimationStarted(); |
| 471 | } |
| 472 | } |
| 473 | }); |
| 474 | } |
| 475 | }; |
| 476 | |
| 477 | AppTransitionAnimationSpec[] specsArray = |
| 478 | new AppTransitionAnimationSpec[specs.size()]; |
| 479 | try { |
| 480 | WindowManagerGlobal.getWindowManagerService().overridePendingAppTransitionMultiThumb( |
| 481 | specs.toArray(specsArray), callback, true /* scaleUp */); |
| 482 | |
| 483 | } catch (RemoteException e) { |
| 484 | Log.w(TAG, "Error overriding app transition", e); |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | private List<AppTransitionAnimationSpec> getAppTransitionAnimationSpecs(TaskStackView stackView, |
Filip Gruszczynski | f48b585 | 2015-10-13 10:28:22 -0700 | [diff] [blame] | 489 | TaskView clickedTask, int offsetX, int offsetY, float stackScroll, |
| 490 | int destinationStack) { |
| 491 | final int targetStackId = destinationStack != INVALID_STACK_ID ? |
| 492 | destinationStack : clickedTask.getTask().key.stackId; |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame^] | 493 | if (targetStackId != FREEFORM_WORKSPACE_STACK_ID |
| 494 | && targetStackId != FULLSCREEN_WORKSPACE_STACK_ID) { |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 495 | return null; |
| 496 | } |
| 497 | // If this is a full screen stack, the transition will be towards the single, full screen |
| 498 | // task. We only need the transition spec for this task. |
| 499 | List<AppTransitionAnimationSpec> specs = new ArrayList<>(); |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame^] | 500 | if (targetStackId == FULLSCREEN_WORKSPACE_STACK_ID) { |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 501 | specs.add(createThumbnailHeaderAnimationSpec( |
| 502 | stackView, offsetX, offsetY, stackScroll, clickedTask, |
| 503 | clickedTask.getTask().key.id, ADD_HEADER_BITMAP)); |
| 504 | return specs; |
| 505 | } |
| 506 | // This is a free form stack or full screen stack, so there will be multiple windows |
| 507 | // animating from thumbnails. We need transition animation specs for all of them. |
| 508 | |
| 509 | // We will use top and bottom task views as a base for tasks, that aren't visible on the |
| 510 | // screen. This is necessary for cascade recents list, where some of the tasks might be |
| 511 | // hidden. |
| 512 | List<TaskView> taskViews = stackView.getTaskViews(); |
| 513 | int childCount = taskViews.size(); |
| 514 | TaskView topChild = taskViews.get(0); |
| 515 | TaskView bottomChild = taskViews.get(childCount - 1); |
| 516 | SparseArray<TaskView> taskViewsByTaskId = new SparseArray<>(); |
| 517 | for (int i = 0; i < childCount; i++) { |
| 518 | TaskView taskView = taskViews.get(i); |
| 519 | taskViewsByTaskId.put(taskView.getTask().key.id, taskView); |
| 520 | } |
| 521 | |
| 522 | TaskStack stack = stackView.getStack(); |
| 523 | // We go through all tasks now and for each generate transition animation spec. If there is |
| 524 | // a view associated with a task, we use that view as a base for the animation. If there |
| 525 | // isn't, we use bottom or top view, depending on which one would be closer to the task |
| 526 | // view if it existed. |
| 527 | ArrayList<Task> tasks = stack.getTasks(); |
| 528 | boolean passedClickedTask = false; |
| 529 | for (int i = 0, n = tasks.size(); i < n; i++) { |
| 530 | Task task = tasks.get(i); |
| 531 | TaskView taskView = taskViewsByTaskId.get(task.key.id); |
| 532 | if (taskView != null) { |
| 533 | specs.add(createThumbnailHeaderAnimationSpec(stackView, offsetX, offsetY, |
| 534 | stackScroll, taskView, taskView.getTask().key.id, ADD_HEADER_BITMAP)); |
| 535 | if (taskView == clickedTask) { |
| 536 | passedClickedTask = true; |
| 537 | } |
| 538 | } else { |
| 539 | taskView = passedClickedTask ? bottomChild : topChild; |
| 540 | specs.add(createThumbnailHeaderAnimationSpec(stackView, offsetX, offsetY, |
| 541 | stackScroll, taskView, task.key.id, !ADD_HEADER_BITMAP)); |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | return specs; |
| 546 | } |
| 547 | |
| 548 | private AppTransitionAnimationSpec createThumbnailHeaderAnimationSpec(TaskStackView stackView, |
| 549 | int offsetX, int offsetY, float stackScroll, TaskView tv, int taskId, |
| 550 | boolean addHeaderBitmap) { |
| 551 | // Disable any focused state before we draw the header |
| 552 | // Upfront the processing of the thumbnail |
| 553 | if (tv.isFocusedTask()) { |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 554 | tv.setFocusedState(false, false /* animated */, false /* requestViewFocus */); |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 555 | } |
| 556 | TaskViewTransform transform = new TaskViewTransform(); |
| 557 | transform = stackView.getStackAlgorithm().getStackTransform(tv.mTask, stackScroll, |
| 558 | transform, null); |
| 559 | |
| 560 | float scale = tv.getScaleX(); |
| 561 | int fromHeaderWidth = (int) (tv.mHeaderView.getMeasuredWidth() * scale); |
| 562 | int fromHeaderHeight = (int) (tv.mHeaderView.getMeasuredHeight() * scale); |
| 563 | |
| 564 | Bitmap b = null; |
| 565 | if (addHeaderBitmap) { |
| 566 | b = Bitmap.createBitmap(fromHeaderWidth, fromHeaderHeight, |
| 567 | Bitmap.Config.ARGB_8888); |
| 568 | |
| 569 | if (Constants.DebugFlags.App.EnableTransitionThumbnailDebugMode) { |
| 570 | b.eraseColor(0xFFff0000); |
| 571 | } else { |
| 572 | Canvas c = new Canvas(b); |
| 573 | c.scale(tv.getScaleX(), tv.getScaleY()); |
| 574 | tv.mHeaderView.draw(c); |
| 575 | c.setBitmap(null); |
| 576 | |
| 577 | } |
| 578 | b = b.createAshmemBitmap(); |
| 579 | } |
| 580 | |
| 581 | int[] pts = new int[2]; |
| 582 | tv.getLocationOnScreen(pts); |
| 583 | |
| 584 | final int left = pts[0] + offsetX; |
| 585 | final int top = pts[1] + offsetY; |
Winson | 3150e57 | 2015-10-23 15:07:24 -0700 | [diff] [blame] | 586 | final Rect rect = new Rect(left, top, left + (int) transform.rect.width(), |
| 587 | top + (int) transform.rect.height()); |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 588 | |
| 589 | return new AppTransitionAnimationSpec(taskId, b, rect); |
| 590 | } |
| 591 | |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 592 | /**** TaskStackView.TaskStackCallbacks Implementation ****/ |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 593 | |
| 594 | @Override |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 595 | public void onTaskViewClicked(final TaskStackView stackView, final TaskView tv, |
Filip Gruszczynski | f48b585 | 2015-10-13 10:28:22 -0700 | [diff] [blame] | 596 | final TaskStack stack, final Task task, final boolean lockToTask, |
| 597 | final boolean boundsValid, final Rect bounds, int destinationStack) { |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 598 | // Notify any callbacks of the launching of a new task |
| 599 | if (mCb != null) { |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 600 | mCb.onTaskViewClicked(); |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 601 | } |
| 602 | |
Winson Chung | e0e45bc | 2014-06-17 17:56:17 -0700 | [diff] [blame] | 603 | // Upfront the processing of the thumbnail |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 604 | TaskViewTransform transform = new TaskViewTransform(); |
Jorim Jaggi | cb55703 | 2014-09-16 23:09:24 +0200 | [diff] [blame] | 605 | View sourceView; |
Winson Chung | e0e45bc | 2014-06-17 17:56:17 -0700 | [diff] [blame] | 606 | int offsetX = 0; |
| 607 | int offsetY = 0; |
Winson Chung | 012ef36 | 2014-07-31 18:36:25 -0700 | [diff] [blame] | 608 | float stackScroll = stackView.getScroller().getStackScroll(); |
Winson Chung | e0e45bc | 2014-06-17 17:56:17 -0700 | [diff] [blame] | 609 | if (tv == null) { |
| 610 | // If there is no actual task view, then use the stack view as the source view |
| 611 | // and then offset to the expected transform rect, but bound this to just |
| 612 | // outside the display rect (to ensure we don't animate from too far away) |
| 613 | sourceView = stackView; |
Winson | 3150e57 | 2015-10-23 15:07:24 -0700 | [diff] [blame] | 614 | offsetX = (int) transform.rect.left; |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 615 | offsetY = getMeasuredHeight(); |
Winson Chung | e0e45bc | 2014-06-17 17:56:17 -0700 | [diff] [blame] | 616 | } else { |
Jorim Jaggi | cb55703 | 2014-09-16 23:09:24 +0200 | [diff] [blame] | 617 | sourceView = tv.mThumbnailView; |
Winson Chung | e0e45bc | 2014-06-17 17:56:17 -0700 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | // Compute the thumbnail to scale up from |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 621 | final SystemServicesProxy ssp = Recents.getSystemServices(); |
Winson Chung | e0e45bc | 2014-06-17 17:56:17 -0700 | [diff] [blame] | 622 | ActivityOptions opts = null; |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 623 | ActivityOptions.OnAnimationStartedListener animStartedListener = null; |
Winson Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 624 | if (task.thumbnail != null && task.thumbnail.getWidth() > 0 && |
| 625 | task.thumbnail.getHeight() > 0) { |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 626 | if (lockToTask) { |
| 627 | animStartedListener = new ActivityOptions.OnAnimationStartedListener() { |
| 628 | boolean mTriggered = false; |
| 629 | @Override |
| 630 | public void onAnimationStarted() { |
| 631 | if (!mTriggered) { |
| 632 | postDelayed(new Runnable() { |
| 633 | @Override |
| 634 | public void run() { |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 635 | EventBus.getDefault().send(new ScreenPinningRequestEvent( |
| 636 | getContext(), ssp)); |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 637 | } |
| 638 | }, 350); |
| 639 | mTriggered = true; |
| 640 | } |
| 641 | } |
| 642 | }; |
| 643 | } |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 644 | postDrawHeaderThumbnailTransitionRunnable(stackView, tv, offsetX, offsetY, stackScroll, |
Filip Gruszczynski | f48b585 | 2015-10-13 10:28:22 -0700 | [diff] [blame] | 645 | animStartedListener, destinationStack); |
Winson | ec417e4 | 2015-09-29 12:42:29 -0700 | [diff] [blame] | 646 | opts = ActivityOptions.makeThumbnailAspectScaleUpAnimation(sourceView, |
| 647 | Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8).createAshmemBitmap(), |
Winson | 3150e57 | 2015-10-23 15:07:24 -0700 | [diff] [blame] | 648 | offsetX, offsetY, (int) transform.rect.width(), (int) transform.rect.height(), |
Winson | ec417e4 | 2015-09-29 12:42:29 -0700 | [diff] [blame] | 649 | sourceView.getHandler(), animStartedListener); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 650 | } else { |
| 651 | opts = ActivityOptions.makeBasic(); |
Winson Chung | e0e45bc | 2014-06-17 17:56:17 -0700 | [diff] [blame] | 652 | } |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 653 | if (boundsValid) { |
Winson | b1bbaed | 2015-09-23 15:45:11 -0700 | [diff] [blame] | 654 | opts.setBounds(bounds.isEmpty() ? null : bounds); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 655 | } |
Winson Chung | e0e45bc | 2014-06-17 17:56:17 -0700 | [diff] [blame] | 656 | final ActivityOptions launchOpts = opts; |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 657 | final boolean screenPinningRequested = (animStartedListener == null) && lockToTask; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 658 | final Runnable launchRunnable = new Runnable() { |
| 659 | @Override |
| 660 | public void run() { |
Winson Chung | 4be0445 | 2014-03-24 17:22:30 -0700 | [diff] [blame] | 661 | if (task.isActive) { |
| 662 | // Bring an active task to the foreground |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 663 | ssp.moveTaskToFront(task.key.id, launchOpts); |
Winson Chung | 4be0445 | 2014-03-24 17:22:30 -0700 | [diff] [blame] | 664 | } else { |
Winson Chung | 4e96eb7 | 2014-09-17 15:16:09 +0200 | [diff] [blame] | 665 | if (ssp.startActivityFromRecents(getContext(), task.key.id, |
| 666 | task.activityLabel, launchOpts)) { |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 667 | if (screenPinningRequested) { |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 668 | EventBus.getDefault().send(new ScreenPinningRequestEvent( |
| 669 | getContext(), ssp)); |
Winson Chung | 4be0445 | 2014-03-24 17:22:30 -0700 | [diff] [blame] | 670 | } |
Winson Chung | 4e96eb7 | 2014-09-17 15:16:09 +0200 | [diff] [blame] | 671 | } else { |
| 672 | // Dismiss the task and return the user to home if we fail to |
| 673 | // launch the task |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 674 | EventBus.getDefault().send(new DismissTaskViewEvent(task, tv)); |
Winson Chung | 4e96eb7 | 2014-09-17 15:16:09 +0200 | [diff] [blame] | 675 | if (mCb != null) { |
| 676 | mCb.onTaskLaunchFailed(); |
| 677 | } |
Winson Chung | 5c9f4b9 | 2015-06-25 16:16:46 -0700 | [diff] [blame] | 678 | |
| 679 | // Keep track of failed launches |
| 680 | MetricsLogger.count(getContext(), "overview_task_launch_failed", 1); |
Winson Chung | 4be0445 | 2014-03-24 17:22:30 -0700 | [diff] [blame] | 681 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 682 | } |
| 683 | } |
| 684 | }; |
| 685 | |
Winson Chung | 5c9f4b9 | 2015-06-25 16:16:46 -0700 | [diff] [blame] | 686 | // Keep track of the index of the task launch |
| 687 | int taskIndexFromFront = 0; |
| 688 | int taskIndex = stack.indexOfTask(task); |
| 689 | if (taskIndex > -1) { |
| 690 | taskIndexFromFront = stack.getTaskCount() - taskIndex - 1; |
| 691 | } |
| 692 | MetricsLogger.histogram(getContext(), "overview_task_launch_index", taskIndexFromFront); |
| 693 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 694 | // Launch the app right away if there is no task view, otherwise, animate the icon out first |
Winson Chung | 814086d | 2014-05-07 15:01:14 -0700 | [diff] [blame] | 695 | if (tv == null) { |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 696 | launchRunnable.run(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 697 | } else { |
Winson Chung | e1e20e1 | 2015-06-02 14:11:49 -0700 | [diff] [blame] | 698 | if (task.group != null && !task.group.isFrontMostTask(task)) { |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 699 | // For affiliated tasks that are behind other tasks, we must animate the front cards |
| 700 | // out of view before starting the task transition |
Winson Chung | ebfc698 | 2014-08-26 12:25:34 -0700 | [diff] [blame] | 701 | stackView.startLaunchTaskAnimation(tv, launchRunnable, lockToTask); |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 702 | } else { |
| 703 | // Otherwise, we can start the task transition immediately |
Winson Chung | ebfc698 | 2014-08-26 12:25:34 -0700 | [diff] [blame] | 704 | stackView.startLaunchTaskAnimation(tv, null, lockToTask); |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 705 | launchRunnable.run(); |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 706 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 707 | } |
| 708 | } |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 709 | |
| 710 | @Override |
Winson Chung | 6ac8bd6 | 2015-01-07 16:38:35 -0800 | [diff] [blame] | 711 | public void onAllTaskViewsDismissed(ArrayList<Task> removedTasks) { |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 712 | /* TODO: Not currently enabled |
Winson Chung | 6ac8bd6 | 2015-01-07 16:38:35 -0800 | [diff] [blame] | 713 | if (removedTasks != null) { |
| 714 | int taskCount = removedTasks.size(); |
| 715 | for (int i = 0; i < taskCount; i++) { |
| 716 | onTaskViewDismissed(removedTasks.get(i)); |
| 717 | } |
| 718 | } |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 719 | */ |
Winson Chung | 6ac8bd6 | 2015-01-07 16:38:35 -0800 | [diff] [blame] | 720 | |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 721 | mCb.onAllTaskViewsDismissed(); |
Winson Chung | 5c9f4b9 | 2015-06-25 16:16:46 -0700 | [diff] [blame] | 722 | |
| 723 | // Keep track of all-deletions |
| 724 | MetricsLogger.count(getContext(), "overview_task_all_dismissed", 1); |
Winson Chung | d7b2cb1 | 2014-06-26 15:08:50 -0700 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | @Override |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 728 | public void onTaskStackFilterTriggered() { |
| 729 | // Hide the search bar |
| 730 | if (mSearchBar != null) { |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 731 | int filterDuration = getResources().getInteger( |
| 732 | R.integer.recents_filter_animate_current_views_duration); |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 733 | mSearchBar.animate() |
| 734 | .alpha(0f) |
| 735 | .setStartDelay(0) |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 736 | .setInterpolator(mFastOutSlowInInterpolator) |
| 737 | .setDuration(filterDuration) |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 738 | .withLayer() |
| 739 | .start(); |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | @Override |
| 744 | public void onTaskStackUnfilterTriggered() { |
| 745 | // Show the search bar |
| 746 | if (mSearchBar != null) { |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 747 | int filterDuration = getResources().getInteger( |
| 748 | R.integer.recents_filter_animate_new_views_duration); |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 749 | mSearchBar.animate() |
| 750 | .alpha(1f) |
| 751 | .setStartDelay(0) |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 752 | .setInterpolator(mFastOutSlowInInterpolator) |
| 753 | .setDuration(filterDuration) |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 754 | .withLayer() |
| 755 | .start(); |
| 756 | } |
| 757 | } |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 758 | |
| 759 | /**** EventBus Events ****/ |
| 760 | |
| 761 | public final void onBusEvent(DragStartEvent event) { |
| 762 | // Add the drag view |
| 763 | mDragView = event.dragView; |
| 764 | addView(mDragView); |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 765 | |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 766 | updateVisibleDockRegions(mTouchHandler.getDockStatesForCurrentOrientation(), |
| 767 | TaskStack.DockState.NONE.viewState.dockAreaAlpha); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | public final void onBusEvent(DragDockStateChangedEvent event) { |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 771 | if (event.dockState == TaskStack.DockState.NONE) { |
| 772 | updateVisibleDockRegions(mTouchHandler.getDockStatesForCurrentOrientation(), |
| 773 | TaskStack.DockState.NONE.viewState.dockAreaAlpha); |
| 774 | } else { |
| 775 | updateVisibleDockRegions(new TaskStack.DockState[] {event.dockState}, -1); |
| 776 | } |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | public final void onBusEvent(final DragEndEvent event) { |
| 780 | event.postAnimationTrigger.increment(); |
| 781 | event.postAnimationTrigger.addLastDecrementRunnable(new Runnable() { |
| 782 | @Override |
| 783 | public void run() { |
| 784 | // Remove the drag view |
| 785 | removeView(mDragView); |
| 786 | mDragView = null; |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 787 | updateVisibleDockRegions(null, -1); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 788 | |
| 789 | // Dock the new task if we are hovering over a valid dock state |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 790 | if (event.dockState != TaskStack.DockState.NONE) { |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 791 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Jorim Jaggi | 75b2597 | 2015-10-21 14:51:10 +0200 | [diff] [blame] | 792 | ssp.startTaskInDockedMode(event.task.key.id, event.dockState.createMode); |
Filip Gruszczynski | f48b585 | 2015-10-13 10:28:22 -0700 | [diff] [blame] | 793 | launchTask(event.task, null, INVALID_STACK_ID); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 794 | } |
| 795 | } |
| 796 | }); |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 797 | if (event.dockState == TaskStack.DockState.NONE) { |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 798 | // Animate the alpha back to what it was before |
| 799 | Rect taskBounds = mTaskStackView.getStackAlgorithm().getUntransformedTaskViewBounds(); |
| 800 | int left = taskBounds.left + (int) ((1f - event.taskView.getScaleX()) * taskBounds.width()) / 2; |
| 801 | int top = taskBounds.top + (int) ((1f - event.taskView.getScaleY()) * taskBounds.height()) / 2; |
| 802 | event.dragView.animate() |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 803 | .scaleX(1f) |
| 804 | .scaleY(1f) |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 805 | .translationX(left + event.taskView.getTranslationX()) |
| 806 | .translationY(top + event.taskView.getTranslationY()) |
| 807 | .setDuration(175) |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 808 | .setInterpolator(mFastOutSlowInInterpolator) |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 809 | .withEndAction(event.postAnimationTrigger.decrementAsRunnable()) |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 810 | .start(); |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 811 | |
| 812 | // Animate the overlay alpha back to 0 |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 813 | updateVisibleDockRegions(null, -1); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 814 | } else { |
| 815 | event.postAnimationTrigger.decrement(); |
| 816 | } |
| 817 | } |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 818 | |
| 819 | /** |
| 820 | * Updates the dock region to match the specified dock state. |
| 821 | */ |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 822 | private void updateVisibleDockRegions(TaskStack.DockState[] newDockStates, int overrideAlpha) { |
| 823 | ArraySet<TaskStack.DockState> newDockStatesSet = new ArraySet<>(); |
| 824 | if (newDockStates != null) { |
| 825 | for (TaskStack.DockState dockState : newDockStates) { |
| 826 | newDockStatesSet.add(dockState); |
| 827 | } |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 828 | } |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 829 | for (TaskStack.DockState dockState : mVisibleDockStates) { |
| 830 | TaskStack.DockState.ViewState viewState = dockState.viewState; |
| 831 | if (newDockStates == null || !newDockStatesSet.contains(dockState)) { |
| 832 | // This is no longer visible, so hide it |
| 833 | viewState.startAlphaAnimation(0, 150); |
| 834 | } else { |
| 835 | // This state is now visible, update the bounds and show it |
| 836 | int alpha = (overrideAlpha != -1 ? overrideAlpha : viewState.dockAreaAlpha); |
| 837 | viewState.dockAreaOverlay.setBounds( |
| 838 | dockState.getDockedBounds(getMeasuredWidth(), getMeasuredHeight())); |
| 839 | viewState.dockAreaOverlay.setCallback(this); |
| 840 | viewState.startAlphaAnimation(alpha, 150); |
| 841 | } |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 842 | } |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 843 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 844 | } |