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