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