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