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