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