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