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