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