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