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 Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 19 | import android.content.Context; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 20 | import android.graphics.Canvas; |
| 21 | import android.graphics.Rect; |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 22 | import android.graphics.drawable.Drawable; |
Winson | 83c1b07 | 2015-11-09 10:48:04 -0800 | [diff] [blame] | 23 | import android.os.Handler; |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 24 | import android.util.ArraySet; |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 25 | import android.util.AttributeSet; |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 26 | import android.view.AppTransitionAnimationSpec; |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 27 | import android.view.LayoutInflater; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 28 | import android.view.MotionEvent; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 29 | import android.view.View; |
Winson Chung | 653f70c2 | 2014-05-19 14:49:42 -0700 | [diff] [blame] | 30 | import android.view.WindowInsets; |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 31 | import android.view.animation.AnimationUtils; |
| 32 | import android.view.animation.Interpolator; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 33 | import android.widget.FrameLayout; |
Jorim Jaggi | 2f7d292 | 2015-10-29 13:08:29 +0100 | [diff] [blame] | 34 | import com.android.internal.annotations.GuardedBy; |
Winson Chung | 5c9f4b9 | 2015-06-25 16:16:46 -0700 | [diff] [blame] | 35 | import com.android.internal.logging.MetricsLogger; |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 36 | import com.android.systemui.R; |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 37 | import com.android.systemui.recents.Recents; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 38 | import com.android.systemui.recents.RecentsActivity; |
Winson Chung | aee097c | 2015-04-02 18:16:02 -0700 | [diff] [blame] | 39 | import com.android.systemui.recents.RecentsAppWidgetHostView; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 40 | import com.android.systemui.recents.RecentsConfiguration; |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 41 | import com.android.systemui.recents.events.EventBus; |
Winson | 13d3066 | 2015-11-06 15:30:29 -0800 | [diff] [blame] | 42 | import com.android.systemui.recents.events.activity.CancelEnterRecentsWindowAnimationEvent; |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 43 | import com.android.systemui.recents.events.activity.DismissRecentsToHomeAnimationStarted; |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame^] | 44 | import com.android.systemui.recents.events.ui.DraggingInRecentsEndedEvent; |
| 45 | import com.android.systemui.recents.events.ui.DraggingInRecentsEvent; |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 46 | import com.android.systemui.recents.events.ui.dragndrop.DragDropTargetChangedEvent; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 47 | import com.android.systemui.recents.events.ui.dragndrop.DragEndEvent; |
| 48 | import com.android.systemui.recents.events.ui.dragndrop.DragStartEvent; |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 49 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 50 | import com.android.systemui.recents.model.Task; |
| 51 | import com.android.systemui.recents.model.TaskStack; |
| 52 | |
| 53 | import java.util.ArrayList; |
Winson Chung | 6ac8bd6 | 2015-01-07 16:38:35 -0800 | [diff] [blame] | 54 | import java.util.List; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 55 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 56 | import static android.app.ActivityManager.StackId.INVALID_STACK_ID; |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 57 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 58 | /** |
| 59 | * This view is the the top level layout that contains TaskStacks (which are laid out according |
| 60 | * to their SpaceNode bounds. |
| 61 | */ |
Winson | e6c9073 | 2015-09-24 16:06:29 -0700 | [diff] [blame] | 62 | public class RecentsView extends FrameLayout implements TaskStackView.TaskStackViewCallbacks { |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 63 | |
Jorim Jaggi | 6e18e00 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 64 | private static final String TAG = "RecentsView"; |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 65 | private static final boolean DEBUG = false; |
Jorim Jaggi | 6e18e00 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 66 | |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 67 | private int mStackViewVisibility = View.VISIBLE; |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 68 | |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 69 | /** The RecentsView callbacks */ |
| 70 | public interface RecentsViewCallbacks { |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 71 | public void onAllTaskViewsDismissed(); |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 74 | LayoutInflater mInflater; |
Winson | 83c1b07 | 2015-11-09 10:48:04 -0800 | [diff] [blame] | 75 | Handler mHandler; |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 76 | |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 77 | ArrayList<TaskStack> mStacks; |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 78 | TaskStackView mTaskStackView; |
Winson Chung | aee097c | 2015-04-02 18:16:02 -0700 | [diff] [blame] | 79 | RecentsAppWidgetHostView mSearchBar; |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 80 | RecentsViewCallbacks mCb; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 81 | |
Winson | 83c1b07 | 2015-11-09 10:48:04 -0800 | [diff] [blame] | 82 | RecentsTransitionHelper mTransitionHelper; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 83 | RecentsViewTouchHandler mTouchHandler; |
| 84 | DragView mDragView; |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 85 | TaskStack.DockState[] mVisibleDockStates = { |
| 86 | TaskStack.DockState.LEFT, |
| 87 | TaskStack.DockState.TOP, |
| 88 | TaskStack.DockState.RIGHT, |
| 89 | TaskStack.DockState.BOTTOM, |
| 90 | }; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 91 | |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 92 | Interpolator mFastOutSlowInInterpolator; |
| 93 | |
| 94 | Rect mSystemInsets = new Rect(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 95 | |
| 96 | public RecentsView(Context context) { |
| 97 | super(context); |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | public RecentsView(Context context, AttributeSet attrs) { |
| 101 | this(context, attrs, 0); |
| 102 | } |
| 103 | |
| 104 | public RecentsView(Context context, AttributeSet attrs, int defStyleAttr) { |
| 105 | this(context, attrs, defStyleAttr, 0); |
| 106 | } |
| 107 | |
| 108 | public RecentsView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
| 109 | super(context, attrs, defStyleAttr, defStyleRes); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 110 | setWillNotDraw(false); |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 111 | mInflater = LayoutInflater.from(context); |
Winson | 83c1b07 | 2015-11-09 10:48:04 -0800 | [diff] [blame] | 112 | mHandler = new Handler(); |
| 113 | mTransitionHelper = new RecentsTransitionHelper(getContext(), mHandler); |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 114 | mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context, |
| 115 | com.android.internal.R.interpolator.fast_out_slow_in); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 116 | mTouchHandler = new RecentsViewTouchHandler(this); |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 117 | } |
| 118 | |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 119 | /** Sets the callbacks */ |
| 120 | public void setCallbacks(RecentsViewCallbacks cb) { |
| 121 | mCb = cb; |
| 122 | } |
| 123 | |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 124 | /** Set/get the bsp root node */ |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 125 | public void setTaskStack(TaskStack stack) { |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 126 | RecentsConfiguration config = Recents.getConfiguration(); |
| 127 | if (config.getLaunchState().launchedReuseTaskStackViews) { |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 128 | if (mTaskStackView != null) { |
| 129 | // If onRecentsHidden is not triggered, we need to the stack view again here |
| 130 | mTaskStackView.reset(); |
| 131 | mTaskStackView.setStack(stack); |
| 132 | } else { |
| 133 | mTaskStackView = new TaskStackView(getContext(), stack); |
| 134 | mTaskStackView.setCallbacks(this); |
| 135 | addView(mTaskStackView); |
| 136 | } |
| 137 | } else { |
| 138 | if (mTaskStackView != null) { |
| 139 | removeView(mTaskStackView); |
| 140 | } |
| 141 | mTaskStackView = new TaskStackView(getContext(), stack); |
| 142 | mTaskStackView.setCallbacks(this); |
| 143 | addView(mTaskStackView); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 144 | } |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 145 | mTaskStackView.setVisibility(mStackViewVisibility); |
Winson Chung | 02d4927 | 2014-08-29 13:57:29 -0700 | [diff] [blame] | 146 | |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 147 | // Trigger a new layout |
| 148 | requestLayout(); |
Winson Chung | 19fc117 | 2014-07-31 18:40:03 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 151 | /** Gets the next task in the stack - or if the last - the top task */ |
| 152 | public Task getNextTaskOrTopTask(Task taskToSearch) { |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 153 | Task returnTask = null; |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 154 | boolean found = false; |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 155 | if (mTaskStackView != null) { |
| 156 | TaskStack stack = mTaskStackView.getStack(); |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 157 | ArrayList<Task> taskList = stack.getTasks(); |
| 158 | // Iterate the stack views and try and find the focused task |
| 159 | for (int j = taskList.size() - 1; j >= 0; --j) { |
| 160 | Task task = taskList.get(j); |
| 161 | // Return the next task in the line. |
| 162 | if (found) |
| 163 | return task; |
| 164 | // Remember the first possible task as the top task. |
| 165 | if (returnTask == null) |
| 166 | returnTask = task; |
| 167 | if (task == taskToSearch) |
| 168 | found = true; |
| 169 | } |
| 170 | } |
| 171 | return returnTask; |
| 172 | } |
| 173 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 174 | /** Launches the focused task from the first stack if possible */ |
| 175 | public boolean launchFocusedTask() { |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 176 | if (mTaskStackView != null) { |
| 177 | TaskStack stack = mTaskStackView.getStack(); |
Winson | 142af42 | 2015-11-09 10:39:57 -0800 | [diff] [blame] | 178 | Task task = mTaskStackView.getFocusedTask(); |
| 179 | if (task != null) { |
| 180 | TaskView taskView = mTaskStackView.getChildViewForTask(task); |
Winson | 83c1b07 | 2015-11-09 10:48:04 -0800 | [diff] [blame] | 181 | onTaskViewClicked(mTaskStackView, taskView, stack, task, false, null, |
Winson | 142af42 | 2015-11-09 10:39:57 -0800 | [diff] [blame] | 182 | INVALID_STACK_ID); |
| 183 | return true; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 184 | } |
| 185 | } |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 186 | return false; |
| 187 | } |
| 188 | |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 189 | /** Launches a given task. */ |
Filip Gruszczynski | f48b585 | 2015-10-13 10:28:22 -0700 | [diff] [blame] | 190 | public boolean launchTask(Task task, Rect taskBounds, int destinationStack) { |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 191 | if (mTaskStackView != null) { |
| 192 | TaskStack stack = mTaskStackView.getStack(); |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 193 | // Iterate the stack views and try and find the given task. |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 194 | List<TaskView> taskViews = mTaskStackView.getTaskViews(); |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 195 | int taskViewCount = taskViews.size(); |
| 196 | for (int j = 0; j < taskViewCount; j++) { |
| 197 | TaskView tv = taskViews.get(j); |
| 198 | if (tv.getTask() == task) { |
Winson | 83c1b07 | 2015-11-09 10:48:04 -0800 | [diff] [blame] | 199 | onTaskViewClicked(mTaskStackView, tv, stack, task, false, |
Filip Gruszczynski | f48b585 | 2015-10-13 10:28:22 -0700 | [diff] [blame] | 200 | taskBounds, destinationStack); |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 201 | return true; |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | return false; |
| 206 | } |
| 207 | |
Winson Chung | 24cf152 | 2014-05-29 12:03:33 -0700 | [diff] [blame] | 208 | /** Requests all task stacks to start their enter-recents animation */ |
Winson Chung | 969f586 | 2014-06-16 17:08:24 -0700 | [diff] [blame] | 209 | public void startEnterRecentsAnimation(ViewAnimation.TaskViewEnterContext ctx) { |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 210 | // We have to increment/decrement the post animation trigger in case there are no children |
| 211 | // to ensure that it runs |
| 212 | ctx.postAnimationTrigger.increment(); |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 213 | if (mTaskStackView != null) { |
| 214 | mTaskStackView.startEnterRecentsAnimation(ctx); |
Winson Chung | 24cf152 | 2014-05-29 12:03:33 -0700 | [diff] [blame] | 215 | } |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 216 | ctx.postAnimationTrigger.decrement(); |
Winson Chung | 24cf152 | 2014-05-29 12:03:33 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 219 | /** Requests all task stacks to start their exit-recents animation */ |
Winson Chung | 969f586 | 2014-06-16 17:08:24 -0700 | [diff] [blame] | 220 | public void startExitToHomeAnimation(ViewAnimation.TaskViewExitContext ctx) { |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 221 | // We have to increment/decrement the post animation trigger in case there are no children |
| 222 | // to ensure that it runs |
| 223 | ctx.postAnimationTrigger.increment(); |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 224 | if (mTaskStackView != null) { |
| 225 | mTaskStackView.startExitToHomeAnimation(ctx); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 226 | } |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 227 | ctx.postAnimationTrigger.decrement(); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 228 | |
Winson | 13d3066 | 2015-11-06 15:30:29 -0800 | [diff] [blame] | 229 | // If we are going home, cancel the previous task's window transition |
| 230 | EventBus.getDefault().send(new CancelEnterRecentsWindowAnimationEvent(null)); |
| 231 | |
Winson Chung | 969f586 | 2014-06-16 17:08:24 -0700 | [diff] [blame] | 232 | // Notify of the exit animation |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 233 | EventBus.getDefault().send(new DismissRecentsToHomeAnimationStarted()); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 234 | } |
| 235 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 236 | /** Adds the search bar */ |
Winson Chung | aee097c | 2015-04-02 18:16:02 -0700 | [diff] [blame] | 237 | public void setSearchBar(RecentsAppWidgetHostView searchBar) { |
Winson Chung | af3bb69 | 2015-06-03 17:31:39 -0700 | [diff] [blame] | 238 | // Remove the previous search bar if one exists |
| 239 | if (mSearchBar != null && indexOfChild(mSearchBar) > -1) { |
| 240 | removeView(mSearchBar); |
| 241 | } |
| 242 | // Add the new search bar |
| 243 | if (searchBar != null) { |
| 244 | mSearchBar = searchBar; |
| 245 | addView(mSearchBar); |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 246 | } |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Winson Chung | 772b6b1 | 2014-07-03 15:54:02 -0700 | [diff] [blame] | 249 | /** Returns whether there is currently a search bar */ |
Winson Chung | aee097c | 2015-04-02 18:16:02 -0700 | [diff] [blame] | 250 | public boolean hasValidSearchBar() { |
| 251 | return mSearchBar != null && !mSearchBar.isReinflateRequired(); |
Winson Chung | 772b6b1 | 2014-07-03 15:54:02 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | /** Sets the visibility of the search bar */ |
| 255 | public void setSearchBarVisibility(int visibility) { |
| 256 | if (mSearchBar != null) { |
| 257 | mSearchBar.setVisibility(visibility); |
Winson Chung | 012ef36 | 2014-07-31 18:36:25 -0700 | [diff] [blame] | 258 | // Always bring the search bar to the top |
| 259 | mSearchBar.bringToFront(); |
Winson Chung | 772b6b1 | 2014-07-03 15:54:02 -0700 | [diff] [blame] | 260 | } |
| 261 | } |
| 262 | |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 263 | @Override |
| 264 | protected void onAttachedToWindow() { |
| 265 | EventBus.getDefault().register(this, RecentsActivity.EVENT_BUS_PRIORITY + 1); |
| 266 | EventBus.getDefault().register(mTouchHandler, RecentsActivity.EVENT_BUS_PRIORITY + 1); |
| 267 | super.onAttachedToWindow(); |
| 268 | } |
| 269 | |
| 270 | @Override |
| 271 | protected void onDetachedFromWindow() { |
| 272 | super.onDetachedFromWindow(); |
| 273 | EventBus.getDefault().unregister(this); |
| 274 | EventBus.getDefault().unregister(mTouchHandler); |
| 275 | } |
| 276 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 277 | /** |
| 278 | * This is called with the full size of the window since we are handling our own insets. |
| 279 | */ |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 280 | @Override |
| 281 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 282 | RecentsConfiguration config = Recents.getConfiguration(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 283 | int width = MeasureSpec.getSize(widthMeasureSpec); |
| 284 | int height = MeasureSpec.getSize(heightMeasureSpec); |
Winson Chung | bd91297 | 2014-03-18 14:36:35 -0700 | [diff] [blame] | 285 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 286 | // Get the search bar bounds and measure the search bar layout |
Winson Chung | af3bb69 | 2015-06-03 17:31:39 -0700 | [diff] [blame] | 287 | Rect searchBarSpaceBounds = new Rect(); |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 288 | if (mSearchBar != null) { |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 289 | config.getSearchBarBounds(new Rect(0, 0, width, height), mSystemInsets.top, |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 290 | searchBarSpaceBounds); |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 291 | mSearchBar.measure( |
| 292 | MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.width(), MeasureSpec.EXACTLY), |
| 293 | MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.height(), MeasureSpec.EXACTLY)); |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 296 | Rect taskStackBounds = new Rect(); |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 297 | config.getTaskStackBounds(new Rect(0, 0, width, height), mSystemInsets.top, |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 298 | mSystemInsets.right, searchBarSpaceBounds, taskStackBounds); |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 299 | if (mTaskStackView != null && mTaskStackView.getVisibility() != GONE) { |
Winson | 88f00ab | 2015-10-05 17:24:00 -0700 | [diff] [blame] | 300 | mTaskStackView.setTaskStackBounds(taskStackBounds, mSystemInsets); |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 301 | mTaskStackView.measure(widthMeasureSpec, heightMeasureSpec); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 302 | } |
| 303 | |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 304 | if (mDragView != null) { |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 305 | Rect taskRect = mTaskStackView.mLayoutAlgorithm.mTaskRect; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 306 | mDragView.measure( |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 307 | MeasureSpec.makeMeasureSpec(taskRect.width(), MeasureSpec.AT_MOST), |
| 308 | MeasureSpec.makeMeasureSpec(taskRect.height(), MeasureSpec.AT_MOST)); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 311 | setMeasuredDimension(width, height); |
| 312 | } |
| 313 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 314 | /** |
| 315 | * This is called with the full size of the window since we are handling our own insets. |
| 316 | */ |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 317 | @Override |
| 318 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 319 | RecentsConfiguration config = Recents.getConfiguration(); |
| 320 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 321 | // Get the search bar bounds so that we lay it out |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 322 | Rect measuredRect = new Rect(0, 0, getMeasuredWidth(), getMeasuredHeight()); |
| 323 | Rect searchBarSpaceBounds = new Rect(); |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 324 | if (mSearchBar != null) { |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 325 | config.getSearchBarBounds(measuredRect, |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 326 | mSystemInsets.top, searchBarSpaceBounds); |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 327 | mSearchBar.layout(searchBarSpaceBounds.left, searchBarSpaceBounds.top, |
| 328 | searchBarSpaceBounds.right, searchBarSpaceBounds.bottom); |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 331 | if (mTaskStackView != null && mTaskStackView.getVisibility() != GONE) { |
| 332 | mTaskStackView.layout(left, top, left + getMeasuredWidth(), top + getMeasuredHeight()); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 333 | } |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 334 | |
| 335 | if (mDragView != null) { |
| 336 | mDragView.layout(left, top, left + mDragView.getMeasuredWidth(), |
| 337 | top + mDragView.getMeasuredHeight()); |
| 338 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 339 | } |
| 340 | |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 341 | @Override |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 342 | public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 343 | mSystemInsets.set(insets.getSystemWindowInsets()); |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 344 | requestLayout(); |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 345 | return insets.consumeSystemWindowInsets(); |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 348 | @Override |
| 349 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
| 350 | return mTouchHandler.onInterceptTouchEvent(ev); |
| 351 | } |
| 352 | |
| 353 | @Override |
| 354 | public boolean onTouchEvent(MotionEvent ev) { |
| 355 | return mTouchHandler.onTouchEvent(ev); |
| 356 | } |
| 357 | |
| 358 | @Override |
| 359 | protected void dispatchDraw(Canvas canvas) { |
| 360 | super.dispatchDraw(canvas); |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 361 | for (int i = mVisibleDockStates.length - 1; i >= 0; i--) { |
| 362 | Drawable d = mVisibleDockStates[i].viewState.dockAreaOverlay; |
| 363 | if (d.getAlpha() > 0) { |
| 364 | d.draw(canvas); |
| 365 | } |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 366 | } |
| 367 | } |
| 368 | |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 369 | @Override |
| 370 | protected boolean verifyDrawable(Drawable who) { |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 371 | for (int i = mVisibleDockStates.length - 1; i >= 0; i--) { |
| 372 | Drawable d = mVisibleDockStates[i].viewState.dockAreaOverlay; |
| 373 | if (d == who) { |
| 374 | return true; |
| 375 | } |
| 376 | } |
| 377 | return super.verifyDrawable(who); |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 380 | /** Unfilters any filtered stacks */ |
| 381 | public boolean unfilterFilteredStacks() { |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 382 | if (mStacks != null) { |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 383 | // Check if there are any filtered stacks and unfilter them before we back out of Recents |
| 384 | boolean stacksUnfiltered = false; |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 385 | int numStacks = mStacks.size(); |
| 386 | for (int i = 0; i < numStacks; i++) { |
| 387 | TaskStack stack = mStacks.get(i); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 388 | if (stack.hasFilteredTasks()) { |
| 389 | stack.unfilterTasks(); |
| 390 | stacksUnfiltered = true; |
| 391 | } |
| 392 | } |
| 393 | return stacksUnfiltered; |
| 394 | } |
| 395 | return false; |
| 396 | } |
| 397 | |
Jorim Jaggi | 900fb48 | 2015-06-02 15:07:33 -0700 | [diff] [blame] | 398 | public void disableLayersForOneFrame() { |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 399 | if (mTaskStackView != null) { |
| 400 | mTaskStackView.disableLayersForOneFrame(); |
Jorim Jaggi | 900fb48 | 2015-06-02 15:07:33 -0700 | [diff] [blame] | 401 | } |
| 402 | } |
| 403 | |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 404 | /**** TaskStackView.TaskStackCallbacks Implementation ****/ |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 405 | |
| 406 | @Override |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 407 | public void onTaskViewClicked(final TaskStackView stackView, final TaskView tv, |
Filip Gruszczynski | f48b585 | 2015-10-13 10:28:22 -0700 | [diff] [blame] | 408 | final TaskStack stack, final Task task, final boolean lockToTask, |
Winson | 83c1b07 | 2015-11-09 10:48:04 -0800 | [diff] [blame] | 409 | final Rect bounds, int destinationStack) { |
| 410 | mTransitionHelper.launchTaskFromRecents(stack, task, stackView, tv, lockToTask, bounds, |
| 411 | destinationStack); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 412 | } |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 413 | |
| 414 | @Override |
Winson Chung | 6ac8bd6 | 2015-01-07 16:38:35 -0800 | [diff] [blame] | 415 | public void onAllTaskViewsDismissed(ArrayList<Task> removedTasks) { |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 416 | /* TODO: Not currently enabled |
Winson Chung | 6ac8bd6 | 2015-01-07 16:38:35 -0800 | [diff] [blame] | 417 | if (removedTasks != null) { |
| 418 | int taskCount = removedTasks.size(); |
| 419 | for (int i = 0; i < taskCount; i++) { |
| 420 | onTaskViewDismissed(removedTasks.get(i)); |
| 421 | } |
| 422 | } |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 423 | */ |
Winson Chung | 6ac8bd6 | 2015-01-07 16:38:35 -0800 | [diff] [blame] | 424 | |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 425 | mCb.onAllTaskViewsDismissed(); |
Winson Chung | 5c9f4b9 | 2015-06-25 16:16:46 -0700 | [diff] [blame] | 426 | |
| 427 | // Keep track of all-deletions |
| 428 | MetricsLogger.count(getContext(), "overview_task_all_dismissed", 1); |
Winson Chung | d7b2cb1 | 2014-06-26 15:08:50 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | @Override |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 432 | public void onTaskStackFilterTriggered() { |
| 433 | // Hide the search bar |
| 434 | if (mSearchBar != null) { |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 435 | int filterDuration = getResources().getInteger( |
| 436 | R.integer.recents_filter_animate_current_views_duration); |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 437 | mSearchBar.animate() |
| 438 | .alpha(0f) |
| 439 | .setStartDelay(0) |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 440 | .setInterpolator(mFastOutSlowInInterpolator) |
| 441 | .setDuration(filterDuration) |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 442 | .withLayer() |
| 443 | .start(); |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | @Override |
| 448 | public void onTaskStackUnfilterTriggered() { |
| 449 | // Show the search bar |
| 450 | if (mSearchBar != null) { |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 451 | int filterDuration = getResources().getInteger( |
| 452 | R.integer.recents_filter_animate_new_views_duration); |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 453 | mSearchBar.animate() |
| 454 | .alpha(1f) |
| 455 | .setStartDelay(0) |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 456 | .setInterpolator(mFastOutSlowInInterpolator) |
| 457 | .setDuration(filterDuration) |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 458 | .withLayer() |
| 459 | .start(); |
| 460 | } |
| 461 | } |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 462 | |
| 463 | /**** EventBus Events ****/ |
| 464 | |
| 465 | public final void onBusEvent(DragStartEvent event) { |
| 466 | // Add the drag view |
| 467 | mDragView = event.dragView; |
| 468 | addView(mDragView); |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 469 | |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 470 | updateVisibleDockRegions(mTouchHandler.getDockStatesForCurrentOrientation(), |
| 471 | TaskStack.DockState.NONE.viewState.dockAreaAlpha); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 474 | public final void onBusEvent(DragDropTargetChangedEvent event) { |
| 475 | if (event.dropTarget == null || !(event.dropTarget instanceof TaskStack.DockState)) { |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 476 | updateVisibleDockRegions(mTouchHandler.getDockStatesForCurrentOrientation(), |
| 477 | TaskStack.DockState.NONE.viewState.dockAreaAlpha); |
| 478 | } else { |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 479 | final TaskStack.DockState dockState = (TaskStack.DockState) event.dropTarget; |
| 480 | updateVisibleDockRegions(new TaskStack.DockState[] {dockState}, -1); |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 481 | } |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | public final void onBusEvent(final DragEndEvent event) { |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 485 | final Runnable cleanUpRunnable = new Runnable() { |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 486 | @Override |
| 487 | public void run() { |
| 488 | // Remove the drag view |
| 489 | removeView(mDragView); |
| 490 | mDragView = null; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 491 | } |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 492 | }; |
| 493 | |
| 494 | // Animate the overlay alpha back to 0 |
| 495 | updateVisibleDockRegions(null, -1); |
| 496 | |
| 497 | if (event.dropTarget == null) { |
| 498 | // No drop targets for hit, so just animate the task back to its place |
| 499 | event.postAnimationTrigger.increment(); |
| 500 | event.postAnimationTrigger.addLastDecrementRunnable(new Runnable() { |
| 501 | @Override |
| 502 | public void run() { |
| 503 | cleanUpRunnable.run(); |
| 504 | } |
| 505 | }); |
| 506 | // Animate the task back to where it was before then clean up afterwards |
| 507 | TaskViewTransform taskTransform = new TaskViewTransform(); |
| 508 | TaskStackLayoutAlgorithm layoutAlgorithm = mTaskStackView.getStackAlgorithm(); |
| 509 | layoutAlgorithm.getStackTransform(event.task, |
| 510 | mTaskStackView.getScroller().getStackScroll(), taskTransform, null); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 511 | event.dragView.animate() |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 512 | .scaleX(taskTransform.scale) |
| 513 | .scaleY(taskTransform.scale) |
| 514 | .translationX((layoutAlgorithm.mTaskRect.left - event.dragView.getLeft()) |
| 515 | + taskTransform.translationX) |
| 516 | .translationY((layoutAlgorithm.mTaskRect.top - event.dragView.getTop()) |
| 517 | + taskTransform.translationY) |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 518 | .setDuration(175) |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 519 | .setInterpolator(mFastOutSlowInInterpolator) |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 520 | .withEndAction(event.postAnimationTrigger.decrementAsRunnable()) |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 521 | .start(); |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 522 | |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 523 | } else if (event.dropTarget instanceof TaskStack.DockState) { |
| 524 | final TaskStack.DockState dockState = (TaskStack.DockState) event.dropTarget; |
| 525 | |
| 526 | // For now, just remove the drag view and the original task |
| 527 | // TODO: Animate the task to the drop target rect before launching it above |
| 528 | cleanUpRunnable.run(); |
| 529 | |
| 530 | // Dock the task and launch it |
| 531 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 532 | ssp.startTaskInDockedMode(event.task.key.id, dockState.createMode); |
| 533 | launchTask(event.task, null, INVALID_STACK_ID); |
| 534 | |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 535 | } else { |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 536 | // We dropped on another drop target, so just add the cleanup to the post animation |
| 537 | // trigger |
| 538 | event.postAnimationTrigger.addLastDecrementRunnable(new Runnable() { |
| 539 | @Override |
| 540 | public void run() { |
| 541 | cleanUpRunnable.run(); |
| 542 | } |
| 543 | }); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 544 | } |
| 545 | } |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 546 | |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame^] | 547 | public final void onBusEvent(DraggingInRecentsEvent event) { |
| 548 | setStackViewVisibility(View.VISIBLE); |
| 549 | setTranslationY(event.distanceFromTop - mTaskStackView.getTaskViews().get(0).getY()); |
| 550 | } |
| 551 | |
| 552 | public final void onBusEvent(DraggingInRecentsEndedEvent event) { |
| 553 | animate().translationY(0f); |
| 554 | } |
| 555 | |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 556 | /** |
| 557 | * Updates the dock region to match the specified dock state. |
| 558 | */ |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 559 | private void updateVisibleDockRegions(TaskStack.DockState[] newDockStates, int overrideAlpha) { |
| 560 | ArraySet<TaskStack.DockState> newDockStatesSet = new ArraySet<>(); |
| 561 | if (newDockStates != null) { |
| 562 | for (TaskStack.DockState dockState : newDockStates) { |
| 563 | newDockStatesSet.add(dockState); |
| 564 | } |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 565 | } |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 566 | for (TaskStack.DockState dockState : mVisibleDockStates) { |
| 567 | TaskStack.DockState.ViewState viewState = dockState.viewState; |
| 568 | if (newDockStates == null || !newDockStatesSet.contains(dockState)) { |
| 569 | // This is no longer visible, so hide it |
| 570 | viewState.startAlphaAnimation(0, 150); |
| 571 | } else { |
| 572 | // This state is now visible, update the bounds and show it |
| 573 | int alpha = (overrideAlpha != -1 ? overrideAlpha : viewState.dockAreaAlpha); |
| 574 | viewState.dockAreaOverlay.setBounds( |
| 575 | dockState.getDockedBounds(getMeasuredWidth(), getMeasuredHeight())); |
| 576 | viewState.dockAreaOverlay.setCallback(this); |
| 577 | viewState.startAlphaAnimation(alpha, 150); |
| 578 | } |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 579 | } |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 580 | } |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 581 | |
| 582 | public void setStackViewVisibility(int stackViewVisibility) { |
| 583 | mStackViewVisibility = stackViewVisibility; |
| 584 | if (mTaskStackView != null) { |
| 585 | mTaskStackView.setVisibility(stackViewVisibility); |
| 586 | invalidate(); |
| 587 | } |
| 588 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 589 | } |