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