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 | c620baf | 2014-03-19 17:15:29 -0700 | [diff] [blame] | 21 | import android.content.ActivityNotFoundException; |
Winson Chung | 9f49df9 | 2014-05-07 18:08:34 -0700 | [diff] [blame] | 22 | import android.content.ComponentName; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 23 | import android.content.Context; |
| 24 | import android.content.Intent; |
| 25 | import android.graphics.Bitmap; |
| 26 | import android.graphics.Canvas; |
| 27 | import android.graphics.Rect; |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 28 | import android.net.Uri; |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 29 | import android.provider.Settings; |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 30 | import android.util.AttributeSet; |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 31 | import android.view.LayoutInflater; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 32 | import android.view.View; |
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 | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 35 | import com.android.systemui.recents.Constants; |
| 36 | import com.android.systemui.recents.RecentsConfiguration; |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 37 | import com.android.systemui.recents.misc.Console; |
| 38 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Winson Chung | ff88d7b | 2014-07-17 12:30:07 -0700 | [diff] [blame] | 39 | import com.android.systemui.recents.misc.Utilities; |
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 | 82c8c5e | 2014-07-14 17:31:41 -0700 | [diff] [blame] | 46 | import java.util.HashSet; |
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(); |
| 58 | public void onAllTaskViewsDismissed(); |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 59 | public void onExitToHomeAnimationTriggered(); |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 62 | RecentsConfiguration mConfig; |
| 63 | LayoutInflater mInflater; |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 64 | DebugOverlayView mDebugOverlay; |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 65 | |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 66 | ArrayList<TaskStack> mStacks; |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 67 | View mSearchBar; |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 68 | RecentsViewCallbacks mCb; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 69 | |
| 70 | public RecentsView(Context context) { |
| 71 | super(context); |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | public RecentsView(Context context, AttributeSet attrs) { |
| 75 | this(context, attrs, 0); |
| 76 | } |
| 77 | |
| 78 | public RecentsView(Context context, AttributeSet attrs, int defStyleAttr) { |
| 79 | this(context, attrs, defStyleAttr, 0); |
| 80 | } |
| 81 | |
| 82 | public RecentsView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
| 83 | super(context, attrs, defStyleAttr, defStyleRes); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 84 | mConfig = RecentsConfiguration.getInstance(); |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 85 | mInflater = LayoutInflater.from(context); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 86 | } |
| 87 | |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 88 | /** Sets the callbacks */ |
| 89 | public void setCallbacks(RecentsViewCallbacks cb) { |
| 90 | mCb = cb; |
| 91 | } |
| 92 | |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 93 | /** Sets the debug overlay */ |
| 94 | public void setDebugOverlay(DebugOverlayView overlay) { |
| 95 | mDebugOverlay = overlay; |
| 96 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 97 | |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 98 | /** Set/get the bsp root node */ |
| 99 | public void setTaskStacks(ArrayList<TaskStack> stacks) { |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 100 | // Remove all TaskStackViews (but leave the search bar) |
| 101 | int childCount = getChildCount(); |
| 102 | for (int i = childCount - 1; i >= 0; i--) { |
| 103 | View v = getChildAt(i); |
| 104 | if (v != mSearchBar) { |
| 105 | removeViewAt(i); |
| 106 | } |
| 107 | } |
| 108 | |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 109 | // Create and add all the stacks for this partition of space. |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 110 | mStacks = stacks; |
| 111 | int numStacks = mStacks.size(); |
| 112 | for (int i = 0; i < numStacks; i++) { |
| 113 | TaskStack stack = mStacks.get(i); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 114 | TaskStackView stackView = new TaskStackView(getContext(), stack); |
| 115 | stackView.setCallbacks(this); |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 116 | // Enable debug mode drawing |
| 117 | if (mConfig.debugModeEnabled) { |
| 118 | stackView.setDebugOverlay(mDebugOverlay); |
| 119 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 120 | addView(stackView); |
| 121 | } |
| 122 | } |
| 123 | |
Winson Chung | 19fc117 | 2014-07-31 18:40:03 -0700 | [diff] [blame^] | 124 | /** Removes all the task stack views from this recents view. */ |
| 125 | public void removeAllTaskStacks() { |
| 126 | int childCount = getChildCount(); |
| 127 | for (int i = childCount - 1; i >= 0; i--) { |
| 128 | View child = getChildAt(i); |
| 129 | if (child != mSearchBar) { |
| 130 | removeViewAt(i); |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 135 | /** Launches the focused task from the first stack if possible */ |
| 136 | public boolean launchFocusedTask() { |
| 137 | // Get the first stack view |
| 138 | int childCount = getChildCount(); |
| 139 | for (int i = 0; i < childCount; i++) { |
| 140 | View child = getChildAt(i); |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 141 | if (child != mSearchBar) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 142 | TaskStackView stackView = (TaskStackView) child; |
| 143 | TaskStack stack = stackView.mStack; |
| 144 | // Iterate the stack views and try and find the focused task |
| 145 | int taskCount = stackView.getChildCount(); |
| 146 | for (int j = 0; j < taskCount; j++) { |
| 147 | TaskView tv = (TaskView) stackView.getChildAt(j); |
| 148 | Task task = tv.getTask(); |
| 149 | if (tv.isFocusedTask()) { |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 150 | onTaskViewClicked(stackView, tv, stack, task, false); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 151 | return true; |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | } |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 156 | return false; |
| 157 | } |
| 158 | |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 159 | /** Launches the task that Recents was launched from, if possible */ |
| 160 | public boolean launchPreviousTask() { |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 161 | // Get the first stack view |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 162 | int childCount = getChildCount(); |
| 163 | for (int i = 0; i < childCount; i++) { |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 164 | View child = getChildAt(i); |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 165 | if (child != mSearchBar) { |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 166 | TaskStackView stackView = (TaskStackView) child; |
| 167 | TaskStack stack = stackView.mStack; |
| 168 | ArrayList<Task> tasks = stack.getTasks(); |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 169 | |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 170 | // Find the launch task in the stack |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 171 | if (!tasks.isEmpty()) { |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 172 | int taskCount = tasks.size(); |
| 173 | for (int j = 0; j < taskCount; j++) { |
| 174 | if (tasks.get(j).isLaunchTarget) { |
| 175 | Task task = tasks.get(j); |
| 176 | TaskView tv = stackView.getChildViewForTask(task); |
| 177 | onTaskViewClicked(stackView, tv, stack, task, false); |
| 178 | return true; |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 179 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 180 | } |
| 181 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | return false; |
| 185 | } |
| 186 | |
Winson Chung | 24cf152 | 2014-05-29 12:03:33 -0700 | [diff] [blame] | 187 | /** Requests all task stacks to start their enter-recents animation */ |
Winson Chung | 969f586 | 2014-06-16 17:08:24 -0700 | [diff] [blame] | 188 | public void startEnterRecentsAnimation(ViewAnimation.TaskViewEnterContext ctx) { |
Winson Chung | 24cf152 | 2014-05-29 12:03:33 -0700 | [diff] [blame] | 189 | int childCount = getChildCount(); |
| 190 | for (int i = 0; i < childCount; i++) { |
| 191 | View child = getChildAt(i); |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 192 | if (child != mSearchBar) { |
Winson Chung | 24cf152 | 2014-05-29 12:03:33 -0700 | [diff] [blame] | 193 | TaskStackView stackView = (TaskStackView) child; |
Winson Chung | 969f586 | 2014-06-16 17:08:24 -0700 | [diff] [blame] | 194 | stackView.startEnterRecentsAnimation(ctx); |
Winson Chung | 24cf152 | 2014-05-29 12:03:33 -0700 | [diff] [blame] | 195 | } |
| 196 | } |
| 197 | } |
| 198 | |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 199 | /** Requests all task stacks to start their exit-recents animation */ |
Winson Chung | 969f586 | 2014-06-16 17:08:24 -0700 | [diff] [blame] | 200 | public void startExitToHomeAnimation(ViewAnimation.TaskViewExitContext ctx) { |
Winson Chung | d7b2cb1 | 2014-06-26 15:08:50 -0700 | [diff] [blame] | 201 | int childCount = getChildCount(); |
| 202 | for (int i = 0; i < childCount; i++) { |
| 203 | View child = getChildAt(i); |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 204 | if (child != mSearchBar) { |
Winson Chung | d7b2cb1 | 2014-06-26 15:08:50 -0700 | [diff] [blame] | 205 | TaskStackView stackView = (TaskStackView) child; |
| 206 | stackView.startExitToHomeAnimation(ctx); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 207 | } |
| 208 | } |
| 209 | |
Winson Chung | 969f586 | 2014-06-16 17:08:24 -0700 | [diff] [blame] | 210 | // Notify of the exit animation |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 211 | mCb.onExitToHomeAnimationTriggered(); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 214 | /** Adds the search bar */ |
| 215 | public void setSearchBar(View searchBar) { |
| 216 | // 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] | 217 | if (Constants.DebugFlags.App.EnableSearchLayout) { |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 218 | // Remove the previous search bar if one exists |
| 219 | if (mSearchBar != null && indexOfChild(mSearchBar) > -1) { |
| 220 | removeView(mSearchBar); |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 221 | } |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 222 | // Add the new search bar |
| 223 | if (searchBar != null) { |
| 224 | mSearchBar = searchBar; |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 225 | addView(mSearchBar); |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 226 | } |
| 227 | } |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Winson Chung | 772b6b1 | 2014-07-03 15:54:02 -0700 | [diff] [blame] | 230 | /** Returns whether there is currently a search bar */ |
| 231 | public boolean hasSearchBar() { |
| 232 | return mSearchBar != null; |
| 233 | } |
| 234 | |
| 235 | /** Sets the visibility of the search bar */ |
| 236 | public void setSearchBarVisibility(int visibility) { |
| 237 | if (mSearchBar != null) { |
| 238 | mSearchBar.setVisibility(visibility); |
Winson Chung | 012ef36 | 2014-07-31 18:36:25 -0700 | [diff] [blame] | 239 | // Always bring the search bar to the top |
| 240 | mSearchBar.bringToFront(); |
Winson Chung | 772b6b1 | 2014-07-03 15:54:02 -0700 | [diff] [blame] | 241 | } |
| 242 | } |
| 243 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 244 | /** |
| 245 | * This is called with the full size of the window since we are handling our own insets. |
| 246 | */ |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 247 | @Override |
| 248 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 249 | int width = MeasureSpec.getSize(widthMeasureSpec); |
| 250 | int height = MeasureSpec.getSize(heightMeasureSpec); |
Winson Chung | bd91297 | 2014-03-18 14:36:35 -0700 | [diff] [blame] | 251 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 252 | // Get the search bar bounds and measure the search bar layout |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 253 | if (mSearchBar != null) { |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 254 | Rect searchBarSpaceBounds = new Rect(); |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 255 | mConfig.getSearchBarBounds(width, height, mConfig.systemInsets.top, searchBarSpaceBounds); |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 256 | mSearchBar.measure( |
| 257 | MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.width(), MeasureSpec.EXACTLY), |
| 258 | MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.height(), MeasureSpec.EXACTLY)); |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 261 | Rect taskStackBounds = new Rect(); |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 262 | mConfig.getTaskStackBounds(width, height, mConfig.systemInsets.top, |
| 263 | mConfig.systemInsets.right, taskStackBounds); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 264 | |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 265 | // Measure each TaskStackView with the full width and height of the window since the |
| 266 | // transition view is a child of that stack view |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 267 | int childCount = getChildCount(); |
| 268 | for (int i = 0; i < childCount; i++) { |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 269 | View child = getChildAt(i); |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 270 | if (child != mSearchBar && child.getVisibility() != GONE) { |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 271 | TaskStackView tsv = (TaskStackView) child; |
| 272 | // Set the insets to be the top/left inset + search bounds |
| 273 | tsv.setStackInsetRect(taskStackBounds); |
| 274 | tsv.measure(widthMeasureSpec, heightMeasureSpec); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 275 | } |
| 276 | } |
| 277 | |
| 278 | setMeasuredDimension(width, height); |
| 279 | } |
| 280 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 281 | /** |
| 282 | * This is called with the full size of the window since we are handling our own insets. |
| 283 | */ |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 284 | @Override |
| 285 | 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] | 286 | // Get the search bar bounds so that we lay it out |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 287 | if (mSearchBar != null) { |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 288 | Rect searchBarSpaceBounds = new Rect(); |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 289 | mConfig.getSearchBarBounds(getMeasuredWidth(), getMeasuredHeight(), |
| 290 | mConfig.systemInsets.top, searchBarSpaceBounds); |
| 291 | mSearchBar.layout(searchBarSpaceBounds.left, searchBarSpaceBounds.top, |
| 292 | searchBarSpaceBounds.right, searchBarSpaceBounds.bottom); |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 293 | } |
| 294 | |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 295 | // Layout each TaskStackView with the full width and height of the window since the |
| 296 | // transition view is a child of that stack view |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 297 | int childCount = getChildCount(); |
| 298 | for (int i = 0; i < childCount; i++) { |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 299 | View child = getChildAt(i); |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 300 | if (child != mSearchBar && child.getVisibility() != GONE) { |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 301 | child.layout(left, top, left + child.getMeasuredWidth(), |
| 302 | top + child.getMeasuredHeight()); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | } |
| 306 | |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 307 | @Override |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 308 | public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 309 | // Update the configuration with the latest system insets and trigger a relayout |
| 310 | mConfig.updateSystemInsets(insets.getSystemWindowInsets()); |
| 311 | requestLayout(); |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 312 | return insets.consumeSystemWindowInsets(); |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 313 | } |
| 314 | |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 315 | /** Notifies each task view of the user interaction. */ |
| 316 | public void onUserInteraction() { |
| 317 | // Get the first stack view |
| 318 | TaskStackView stackView = null; |
| 319 | int childCount = getChildCount(); |
| 320 | for (int i = 0; i < childCount; i++) { |
| 321 | View child = getChildAt(i); |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 322 | if (child != mSearchBar) { |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 323 | stackView = (TaskStackView) child; |
| 324 | stackView.onUserInteraction(); |
| 325 | } |
| 326 | } |
| 327 | } |
| 328 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 329 | /** Focuses the next task in the first stack view */ |
| 330 | public void focusNextTask(boolean forward) { |
| 331 | // Get the first stack view |
| 332 | TaskStackView stackView = null; |
| 333 | int childCount = getChildCount(); |
| 334 | for (int i = 0; i < childCount; i++) { |
| 335 | View child = getChildAt(i); |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 336 | if (child != mSearchBar) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 337 | stackView = (TaskStackView) child; |
| 338 | break; |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | if (stackView != null) { |
| 343 | stackView.focusNextTask(forward); |
| 344 | } |
| 345 | } |
| 346 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 347 | /** Unfilters any filtered stacks */ |
| 348 | public boolean unfilterFilteredStacks() { |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 349 | if (mStacks != null) { |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 350 | // Check if there are any filtered stacks and unfilter them before we back out of Recents |
| 351 | boolean stacksUnfiltered = false; |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 352 | int numStacks = mStacks.size(); |
| 353 | for (int i = 0; i < numStacks; i++) { |
| 354 | TaskStack stack = mStacks.get(i); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 355 | if (stack.hasFilteredTasks()) { |
| 356 | stack.unfilterTasks(); |
| 357 | stacksUnfiltered = true; |
| 358 | } |
| 359 | } |
| 360 | return stacksUnfiltered; |
| 361 | } |
| 362 | return false; |
| 363 | } |
| 364 | |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 365 | /**** TaskStackView.TaskStackCallbacks Implementation ****/ |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 366 | |
| 367 | @Override |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 368 | public void onTaskViewClicked(final TaskStackView stackView, final TaskView tv, |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 369 | final TaskStack stack, final Task task, final boolean lockToTask) { |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 370 | // Notify any callbacks of the launching of a new task |
| 371 | if (mCb != null) { |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 372 | mCb.onTaskViewClicked(); |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 373 | } |
| 374 | |
Winson Chung | e0e45bc | 2014-06-17 17:56:17 -0700 | [diff] [blame] | 375 | // Upfront the processing of the thumbnail |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 376 | TaskViewTransform transform = new TaskViewTransform(); |
Winson Chung | e0e45bc | 2014-06-17 17:56:17 -0700 | [diff] [blame] | 377 | View sourceView = tv; |
| 378 | int offsetX = 0; |
| 379 | int offsetY = 0; |
Winson Chung | 012ef36 | 2014-07-31 18:36:25 -0700 | [diff] [blame] | 380 | float stackScroll = stackView.getScroller().getStackScroll(); |
Winson Chung | e0e45bc | 2014-06-17 17:56:17 -0700 | [diff] [blame] | 381 | if (tv == null) { |
| 382 | // If there is no actual task view, then use the stack view as the source view |
| 383 | // and then offset to the expected transform rect, but bound this to just |
| 384 | // outside the display rect (to ensure we don't animate from too far away) |
| 385 | sourceView = stackView; |
Winson Chung | 012ef36 | 2014-07-31 18:36:25 -0700 | [diff] [blame] | 386 | transform = stackView.getStackAlgorithm().getStackTransform(task, stackScroll, transform, null); |
Winson Chung | e0e45bc | 2014-06-17 17:56:17 -0700 | [diff] [blame] | 387 | offsetX = transform.rect.left; |
| 388 | offsetY = Math.min(transform.rect.top, mConfig.displayRect.height()); |
| 389 | } else { |
Winson Chung | 012ef36 | 2014-07-31 18:36:25 -0700 | [diff] [blame] | 390 | transform = stackView.getStackAlgorithm().getStackTransform(task, stackScroll, transform, null); |
Winson Chung | e0e45bc | 2014-06-17 17:56:17 -0700 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | // Compute the thumbnail to scale up from |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 394 | final SystemServicesProxy ssp = |
| 395 | RecentsTaskLoader.getInstance().getSystemServicesProxy(); |
Winson Chung | e0e45bc | 2014-06-17 17:56:17 -0700 | [diff] [blame] | 396 | ActivityOptions opts = null; |
| 397 | int thumbnailWidth = transform.rect.width(); |
| 398 | int thumbnailHeight = transform.rect.height(); |
| 399 | if (task.thumbnail != null && thumbnailWidth > 0 && thumbnailHeight > 0 && |
| 400 | task.thumbnail.getWidth() > 0 && task.thumbnail.getHeight() > 0) { |
| 401 | // Resize the thumbnail to the size of the view that we are animating from |
| 402 | Bitmap b = Bitmap.createBitmap(thumbnailWidth, thumbnailHeight, |
| 403 | Bitmap.Config.ARGB_8888); |
| 404 | Canvas c = new Canvas(b); |
| 405 | c.drawBitmap(task.thumbnail, |
| 406 | new Rect(0, 0, task.thumbnail.getWidth(), task.thumbnail.getHeight()), |
| 407 | new Rect(0, 0, thumbnailWidth, thumbnailHeight), null); |
| 408 | c.setBitmap(null); |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 409 | ActivityOptions.OnAnimationStartedListener animStartedListener = null; |
| 410 | if (lockToTask) { |
| 411 | animStartedListener = new ActivityOptions.OnAnimationStartedListener() { |
| 412 | boolean mTriggered = false; |
| 413 | @Override |
| 414 | public void onAnimationStarted() { |
| 415 | if (!mTriggered) { |
| 416 | postDelayed(new Runnable() { |
| 417 | @Override |
| 418 | public void run() { |
| 419 | ssp.lockCurrentTask(); |
| 420 | } |
| 421 | }, 350); |
| 422 | mTriggered = true; |
| 423 | } |
| 424 | } |
| 425 | }; |
| 426 | } |
Winson Chung | e0e45bc | 2014-06-17 17:56:17 -0700 | [diff] [blame] | 427 | opts = ActivityOptions.makeThumbnailScaleUpAnimation(sourceView, |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 428 | b, offsetX, offsetY, animStartedListener); |
Winson Chung | e0e45bc | 2014-06-17 17:56:17 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | final ActivityOptions launchOpts = opts; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 432 | final Runnable launchRunnable = new Runnable() { |
| 433 | @Override |
| 434 | public void run() { |
Winson Chung | 4be0445 | 2014-03-24 17:22:30 -0700 | [diff] [blame] | 435 | if (task.isActive) { |
| 436 | // Bring an active task to the foreground |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 437 | ssp.moveTaskToFront(task.key.id, launchOpts); |
Winson Chung | 4be0445 | 2014-03-24 17:22:30 -0700 | [diff] [blame] | 438 | } else { |
Winson Chung | 5393dff | 2014-05-08 14:25:43 -0700 | [diff] [blame] | 439 | // Launch the activity anew with the desired animation |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 440 | Intent i = new Intent(task.key.baseIntent); |
Winson Chung | dc9b7e7 | 2014-07-16 11:25:22 -0700 | [diff] [blame] | 441 | i.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY |
| 442 | | Intent.FLAG_ACTIVITY_TASK_ON_HOME); |
Winson Chung | ff88d7b | 2014-07-17 12:30:07 -0700 | [diff] [blame] | 443 | if (!Utilities.isDocument(i)) { |
Winson Chung | dc9b7e7 | 2014-07-16 11:25:22 -0700 | [diff] [blame] | 444 | i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 445 | } |
Winson Chung | 4be0445 | 2014-03-24 17:22:30 -0700 | [diff] [blame] | 446 | try { |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 447 | ssp.startActivityFromRecents(task.key.id, launchOpts); |
| 448 | if (launchOpts == null && lockToTask) { |
| 449 | ssp.lockCurrentTask(); |
Winson Chung | 4be0445 | 2014-03-24 17:22:30 -0700 | [diff] [blame] | 450 | } |
| 451 | } catch (ActivityNotFoundException anfe) { |
| 452 | Console.logError(getContext(), "Could not start Activity"); |
| 453 | } |
Winson Chung | 5393dff | 2014-05-08 14:25:43 -0700 | [diff] [blame] | 454 | |
| 455 | // And clean up the old task |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 456 | onTaskViewDismissed(task); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | }; |
| 460 | |
| 461 | // 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] | 462 | if (tv == null) { |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 463 | post(launchRunnable); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 464 | } else { |
Winson Chung | 1907cd4 | 2014-07-23 18:20:13 -0700 | [diff] [blame] | 465 | stackView.startLaunchTaskAnimation(tv, launchRunnable); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 466 | } |
| 467 | } |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 468 | |
| 469 | @Override |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 470 | public void onTaskViewAppInfoClicked(Task t) { |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 471 | // Create a new task stack with the application info details activity |
| 472 | Intent baseIntent = t.key.baseIntent; |
| 473 | Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, |
| 474 | Uri.fromParts("package", baseIntent.getComponent().getPackageName(), null)); |
| 475 | intent.setComponent(intent.resolveActivity(getContext().getPackageManager())); |
| 476 | TaskStackBuilder.create(getContext()) |
| 477 | .addNextIntentWithParentStack(intent).startActivities(); |
| 478 | } |
Winson Chung | 9f49df9 | 2014-05-07 18:08:34 -0700 | [diff] [blame] | 479 | |
Winson Chung | 5393dff | 2014-05-08 14:25:43 -0700 | [diff] [blame] | 480 | @Override |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 481 | public void onTaskViewDismissed(Task t) { |
Winson Chung | 5393dff | 2014-05-08 14:25:43 -0700 | [diff] [blame] | 482 | // 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] | 483 | // 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] | 484 | // either don't need to be updated, or have already been removed. |
| 485 | RecentsTaskLoader loader = RecentsTaskLoader.getInstance(); |
| 486 | loader.deleteTaskData(t, false); |
| 487 | |
| 488 | // Remove the old task from activity manager |
Winson Chung | 5393dff | 2014-05-08 14:25:43 -0700 | [diff] [blame] | 489 | RecentsTaskLoader.getInstance().getSystemServicesProxy().removeTask(t.key.id, |
Winson Chung | ff88d7b | 2014-07-17 12:30:07 -0700 | [diff] [blame] | 490 | Utilities.isDocument(t.key.baseIntent)); |
Winson Chung | 5393dff | 2014-05-08 14:25:43 -0700 | [diff] [blame] | 491 | } |
| 492 | |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 493 | @Override |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 494 | public void onAllTaskViewsDismissed() { |
| 495 | mCb.onAllTaskViewsDismissed(); |
Winson Chung | d7b2cb1 | 2014-06-26 15:08:50 -0700 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | @Override |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 499 | public void onTaskStackFilterTriggered() { |
| 500 | // Hide the search bar |
| 501 | if (mSearchBar != null) { |
| 502 | mSearchBar.animate() |
| 503 | .alpha(0f) |
| 504 | .setStartDelay(0) |
| 505 | .setInterpolator(mConfig.fastOutSlowInInterpolator) |
| 506 | .setDuration(mConfig.filteringCurrentViewsAnimDuration) |
| 507 | .withLayer() |
| 508 | .start(); |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | @Override |
| 513 | public void onTaskStackUnfilterTriggered() { |
| 514 | // Show the search bar |
| 515 | if (mSearchBar != null) { |
| 516 | mSearchBar.animate() |
| 517 | .alpha(1f) |
| 518 | .setStartDelay(0) |
| 519 | .setInterpolator(mConfig.fastOutSlowInInterpolator) |
| 520 | .setDuration(mConfig.filteringNewViewsAnimDuration) |
| 521 | .withLayer() |
| 522 | .start(); |
| 523 | } |
| 524 | } |
| 525 | |
Winson Chung | 9f49df9 | 2014-05-07 18:08:34 -0700 | [diff] [blame] | 526 | /**** RecentsPackageMonitor.PackageCallbacks Implementation ****/ |
| 527 | |
| 528 | @Override |
Winson Chung | 82c8c5e | 2014-07-14 17:31:41 -0700 | [diff] [blame] | 529 | public void onComponentRemoved(HashSet<ComponentName> cns) { |
Winson Chung | 9f49df9 | 2014-05-07 18:08:34 -0700 | [diff] [blame] | 530 | // Propagate this event down to each task stack view |
| 531 | int childCount = getChildCount(); |
| 532 | for (int i = 0; i < childCount; i++) { |
| 533 | View child = getChildAt(i); |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 534 | if (child != mSearchBar) { |
Winson Chung | 9f49df9 | 2014-05-07 18:08:34 -0700 | [diff] [blame] | 535 | TaskStackView stackView = (TaskStackView) child; |
| 536 | stackView.onComponentRemoved(cns); |
| 537 | } |
| 538 | } |
| 539 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 540 | } |