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