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