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