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 | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 19 | import static android.app.ActivityManager.StackId.INVALID_STACK_ID; |
| 20 | |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 21 | import android.animation.Animator; |
| 22 | import android.animation.AnimatorListenerAdapter; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 23 | import android.animation.ObjectAnimator; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 24 | import android.content.Context; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 25 | import android.graphics.Canvas; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 26 | import android.graphics.Color; |
| 27 | import android.graphics.Outline; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 28 | import android.graphics.Rect; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 29 | import android.graphics.drawable.ColorDrawable; |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 30 | import android.graphics.drawable.Drawable; |
Winson | 83c1b07 | 2015-11-09 10:48:04 -0800 | [diff] [blame] | 31 | import android.os.Handler; |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 32 | import android.util.ArraySet; |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 33 | import android.util.AttributeSet; |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 34 | import android.view.LayoutInflater; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 35 | import android.view.MotionEvent; |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 36 | import android.view.View; |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 37 | import android.view.ViewDebug; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 38 | import android.view.ViewOutlineProvider; |
Jorim Jaggi | 870ab5a | 2015-12-02 18:37:54 -0800 | [diff] [blame] | 39 | import android.view.ViewPropertyAnimator; |
Winson Chung | 653f70c2 | 2014-05-19 14:49:42 -0700 | [diff] [blame] | 40 | import android.view.WindowInsets; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 41 | import android.widget.FrameLayout; |
Winson Chung | de750de | 2015-12-11 10:26:06 -0500 | [diff] [blame] | 42 | import android.widget.TextView; |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 43 | |
Winson | dc8de84 | 2016-01-06 15:21:41 -0800 | [diff] [blame] | 44 | import com.android.internal.logging.MetricsLogger; |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 45 | import com.android.internal.logging.MetricsProto.MetricsEvent; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 46 | import com.android.systemui.Interpolators; |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 47 | import com.android.systemui.R; |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 48 | import com.android.systemui.recents.Recents; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 49 | import com.android.systemui.recents.RecentsActivity; |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 50 | import com.android.systemui.recents.RecentsActivityLaunchState; |
Winson Chung | aee097c | 2015-04-02 18:16:02 -0700 | [diff] [blame] | 51 | import com.android.systemui.recents.RecentsAppWidgetHostView; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 52 | import com.android.systemui.recents.RecentsConfiguration; |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 53 | import com.android.systemui.recents.RecentsDebugFlags; |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 54 | import com.android.systemui.recents.events.EventBus; |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 55 | import com.android.systemui.recents.events.activity.ClearHistoryEvent; |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 56 | import com.android.systemui.recents.events.activity.DismissRecentsToHomeAnimationStarted; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 57 | import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationCompletedEvent; |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 58 | import com.android.systemui.recents.events.activity.HideHistoryButtonEvent; |
| 59 | import com.android.systemui.recents.events.activity.HideHistoryEvent; |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 60 | import com.android.systemui.recents.events.activity.LaunchTaskEvent; |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 61 | import com.android.systemui.recents.events.activity.ShowHistoryButtonEvent; |
| 62 | import com.android.systemui.recents.events.activity.ShowHistoryEvent; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 63 | import com.android.systemui.recents.events.activity.ToggleHistoryEvent; |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 64 | import com.android.systemui.recents.events.ui.DraggingInRecentsEndedEvent; |
| 65 | import com.android.systemui.recents.events.ui.DraggingInRecentsEvent; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 66 | import com.android.systemui.recents.events.ui.ResetBackgroundScrimEvent; |
| 67 | import com.android.systemui.recents.events.ui.UpdateBackgroundScrimEvent; |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 68 | import com.android.systemui.recents.events.ui.dragndrop.DragDropTargetChangedEvent; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 69 | import com.android.systemui.recents.events.ui.dragndrop.DragEndEvent; |
| 70 | import com.android.systemui.recents.events.ui.dragndrop.DragStartEvent; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 71 | import com.android.systemui.recents.history.RecentsHistoryView; |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 72 | import com.android.systemui.recents.misc.ReferenceCountedTrigger; |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 73 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Winson | c5fd350 | 2016-01-18 15:18:37 -0800 | [diff] [blame] | 74 | import com.android.systemui.recents.misc.Utilities; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 75 | import com.android.systemui.recents.model.Task; |
| 76 | import com.android.systemui.recents.model.TaskStack; |
Jorim Jaggi | 870ab5a | 2015-12-02 18:37:54 -0800 | [diff] [blame] | 77 | import com.android.systemui.stackdivider.WindowManagerProxy; |
| 78 | import com.android.systemui.statusbar.FlingAnimationUtils; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 79 | |
| 80 | import java.util.ArrayList; |
Winson Chung | 6ac8bd6 | 2015-01-07 16:38:35 -0800 | [diff] [blame] | 81 | import java.util.List; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 82 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 83 | /** |
| 84 | * This view is the the top level layout that contains TaskStacks (which are laid out according |
| 85 | * to their SpaceNode bounds. |
| 86 | */ |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 87 | public class RecentsView extends FrameLayout { |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 88 | |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 89 | private static final int DOCK_AREA_OVERLAY_TRANSITION_DURATION = 135; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 90 | private static final int DEFAULT_UPDATE_SCRIM_DURATION = 200; |
| 91 | private static final float DEFAULT_SCRIM_ALPHA = 0.33f; |
Jorim Jaggi | 6e18e00 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 92 | |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 93 | private final Handler mHandler; |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 94 | |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 95 | private TaskStack mStack; |
| 96 | private TaskStackView mTaskStackView; |
| 97 | private RecentsAppWidgetHostView mSearchBar; |
Winson Chung | de750de | 2015-12-11 10:26:06 -0500 | [diff] [blame] | 98 | private TextView mHistoryButton; |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 99 | private TextView mHistoryClearAllButton; |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 100 | private View mEmptyView; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 101 | private RecentsHistoryView mHistoryView; |
| 102 | |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 103 | private boolean mAwaitingFirstLayout = true; |
| 104 | private boolean mLastTaskLaunchedWasFreeform; |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 105 | |
| 106 | @ViewDebug.ExportedProperty(category="recents") |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 107 | private Rect mSystemInsets = new Rect(); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 108 | private int mDividerSize; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 109 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 110 | private ColorDrawable mBackgroundScrim = new ColorDrawable(Color.BLACK); |
| 111 | private Animator mBackgroundScrimAnimator; |
| 112 | |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 113 | private RecentsTransitionHelper mTransitionHelper; |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 114 | @ViewDebug.ExportedProperty(deepExport=true, prefix="touch_") |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 115 | private RecentsViewTouchHandler mTouchHandler; |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 116 | private final FlingAnimationUtils mFlingAnimationUtils; |
Jorim Jaggi | 870ab5a | 2015-12-02 18:37:54 -0800 | [diff] [blame] | 117 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 118 | public RecentsView(Context context) { |
Jorim Jaggi | 870ab5a | 2015-12-02 18:37:54 -0800 | [diff] [blame] | 119 | this(context, null); |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | public RecentsView(Context context, AttributeSet attrs) { |
| 123 | this(context, attrs, 0); |
| 124 | } |
| 125 | |
| 126 | public RecentsView(Context context, AttributeSet attrs, int defStyleAttr) { |
| 127 | this(context, attrs, defStyleAttr, 0); |
| 128 | } |
| 129 | |
| 130 | public RecentsView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
| 131 | super(context, attrs, defStyleAttr, defStyleRes); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 132 | setWillNotDraw(false); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 133 | |
| 134 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Winson | 83c1b07 | 2015-11-09 10:48:04 -0800 | [diff] [blame] | 135 | mHandler = new Handler(); |
| 136 | mTransitionHelper = new RecentsTransitionHelper(getContext(), mHandler); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 137 | mDividerSize = ssp.getDockedDividerSize(context); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 138 | mTouchHandler = new RecentsViewTouchHandler(this); |
Jorim Jaggi | 870ab5a | 2015-12-02 18:37:54 -0800 | [diff] [blame] | 139 | mFlingAnimationUtils = new FlingAnimationUtils(context, 0.3f); |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 140 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 141 | final float cornerRadius = context.getResources().getDimensionPixelSize( |
| 142 | R.dimen.recents_task_view_rounded_corners_radius); |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 143 | LayoutInflater inflater = LayoutInflater.from(context); |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 144 | if (RecentsDebugFlags.Static.EnableHistory) { |
| 145 | mHistoryButton = (TextView) inflater.inflate(R.layout.recents_history_button, this, |
| 146 | false); |
| 147 | mHistoryButton.setOnClickListener(new View.OnClickListener() { |
| 148 | @Override |
| 149 | public void onClick(View v) { |
| 150 | EventBus.getDefault().send(new ToggleHistoryEvent()); |
| 151 | } |
| 152 | }); |
| 153 | addView(mHistoryButton); |
| 154 | mHistoryButton.setClipToOutline(true); |
| 155 | mHistoryButton.setOutlineProvider(new ViewOutlineProvider() { |
| 156 | @Override |
| 157 | public void getOutline(View view, Outline outline) { |
| 158 | outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), cornerRadius); |
| 159 | } |
| 160 | }); |
| 161 | } |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 162 | mEmptyView = inflater.inflate(R.layout.recents_empty, this, false); |
| 163 | addView(mEmptyView); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 164 | |
| 165 | setBackground(mBackgroundScrim); |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 166 | } |
| 167 | |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 168 | /** Set/get the bsp root node */ |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 169 | public void onResume(boolean isResumingFromVisible, TaskStack stack) { |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 170 | RecentsConfiguration config = Recents.getConfiguration(); |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 171 | RecentsActivityLaunchState launchState = config.getLaunchState(); |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 172 | |
| 173 | if (mTaskStackView == null || !launchState.launchedReuseTaskStackViews) { |
| 174 | isResumingFromVisible = false; |
| 175 | removeView(mTaskStackView); |
| 176 | mTaskStackView = new TaskStackView(getContext()); |
| 177 | mStack = mTaskStackView.getStack(); |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 178 | addView(mTaskStackView); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 179 | } |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 180 | |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 181 | // Reset the state |
| 182 | mAwaitingFirstLayout = !isResumingFromVisible; |
| 183 | mLastTaskLaunchedWasFreeform = false; |
| 184 | |
| 185 | // Update the stack |
| 186 | mTaskStackView.onResume(isResumingFromVisible); |
| 187 | mTaskStackView.setTasks(stack, isResumingFromVisible /* notifyStackChanges */); |
| 188 | |
| 189 | if (isResumingFromVisible) { |
| 190 | // If we are already visible, then restore the background scrim |
| 191 | animateBackgroundScrim(DEFAULT_SCRIM_ALPHA, DEFAULT_UPDATE_SCRIM_DURATION); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 192 | } else { |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 193 | // If we are already occluded by the app, then set the final background scrim alpha now. |
| 194 | // Otherwise, defer until the enter animation completes to animate the scrim alpha with |
| 195 | // the tasks for the home animation. |
| 196 | if (launchState.launchedWhileDocking || launchState.launchedFromApp |
| 197 | || mStack.getTaskCount() == 0) { |
| 198 | mBackgroundScrim.setAlpha((int) (DEFAULT_SCRIM_ALPHA * 255)); |
| 199 | } else { |
| 200 | mBackgroundScrim.setAlpha(0); |
| 201 | } |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 202 | } |
| 203 | |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 204 | // Update the top level view's visibilities |
Winson | 4b057c6 | 2016-01-12 15:01:52 -0800 | [diff] [blame] | 205 | if (stack.getTaskCount() > 0) { |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 206 | hideEmptyView(); |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 207 | } else { |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 208 | showEmptyView(); |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 209 | } |
Winson Chung | 19fc117 | 2014-07-31 18:40:03 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 212 | /** |
| 213 | * Returns whether the last task launched was in the freeform stack or not. |
| 214 | */ |
| 215 | public boolean isLastTaskLaunchedFreeform() { |
| 216 | return mLastTaskLaunchedWasFreeform; |
| 217 | } |
| 218 | |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 219 | /** |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 220 | * Returns whether the history is visible or not. |
| 221 | */ |
| 222 | public boolean isHistoryVisible() { |
| 223 | return mHistoryView != null && mHistoryView.isVisible(); |
| 224 | } |
| 225 | |
| 226 | /** |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 227 | * Returns the currently set task stack. |
| 228 | */ |
| 229 | public TaskStack getTaskStack() { |
| 230 | return mStack; |
| 231 | } |
| 232 | |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 233 | /** Gets the next task in the stack - or if the last - the top task */ |
| 234 | public Task getNextTaskOrTopTask(Task taskToSearch) { |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 235 | Task returnTask = null; |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 236 | boolean found = false; |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 237 | if (mTaskStackView != null) { |
| 238 | TaskStack stack = mTaskStackView.getStack(); |
Winson | 250608a | 2015-11-24 15:00:31 -0800 | [diff] [blame] | 239 | ArrayList<Task> taskList = stack.getStackTasks(); |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 240 | // Iterate the stack views and try and find the focused task |
| 241 | for (int j = taskList.size() - 1; j >= 0; --j) { |
| 242 | Task task = taskList.get(j); |
| 243 | // Return the next task in the line. |
| 244 | if (found) |
| 245 | return task; |
| 246 | // Remember the first possible task as the top task. |
| 247 | if (returnTask == null) |
| 248 | returnTask = task; |
| 249 | if (task == taskToSearch) |
| 250 | found = true; |
| 251 | } |
| 252 | } |
| 253 | return returnTask; |
| 254 | } |
| 255 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 256 | /** Launches the focused task from the first stack if possible */ |
Winson | 4232952 | 2016-02-05 10:39:46 -0800 | [diff] [blame] | 257 | public boolean launchFocusedTask(int logEvent) { |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 258 | if (mTaskStackView != null) { |
Winson | 142af42 | 2015-11-09 10:39:57 -0800 | [diff] [blame] | 259 | Task task = mTaskStackView.getFocusedTask(); |
| 260 | if (task != null) { |
| 261 | TaskView taskView = mTaskStackView.getChildViewForTask(task); |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 262 | EventBus.getDefault().send(new LaunchTaskEvent(taskView, task, null, |
| 263 | INVALID_STACK_ID, false)); |
Winson | 4232952 | 2016-02-05 10:39:46 -0800 | [diff] [blame] | 264 | |
| 265 | if (logEvent != 0) { |
| 266 | MetricsLogger.action(getContext(), logEvent, |
| 267 | task.key.getComponent().toString()); |
| 268 | } |
Winson | 142af42 | 2015-11-09 10:39:57 -0800 | [diff] [blame] | 269 | return true; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 270 | } |
| 271 | } |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 272 | return false; |
| 273 | } |
| 274 | |
Winson | a0731a1 | 2015-12-02 15:10:14 -0800 | [diff] [blame] | 275 | /** Launches the task that recents was launched from if possible */ |
| 276 | public boolean launchPreviousTask() { |
| 277 | if (mTaskStackView != null) { |
| 278 | TaskStack stack = mTaskStackView.getStack(); |
| 279 | Task task = stack.getLaunchTarget(); |
| 280 | if (task != null) { |
| 281 | TaskView taskView = mTaskStackView.getChildViewForTask(task); |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 282 | EventBus.getDefault().send(new LaunchTaskEvent(taskView, task, null, |
| 283 | INVALID_STACK_ID, false)); |
Winson | a0731a1 | 2015-12-02 15:10:14 -0800 | [diff] [blame] | 284 | return true; |
| 285 | } |
| 286 | } |
| 287 | return false; |
| 288 | } |
| 289 | |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 290 | /** Launches a given task. */ |
Filip Gruszczynski | f48b585 | 2015-10-13 10:28:22 -0700 | [diff] [blame] | 291 | public boolean launchTask(Task task, Rect taskBounds, int destinationStack) { |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 292 | if (mTaskStackView != null) { |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 293 | // Iterate the stack views and try and find the given task. |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 294 | List<TaskView> taskViews = mTaskStackView.getTaskViews(); |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 295 | int taskViewCount = taskViews.size(); |
| 296 | for (int j = 0; j < taskViewCount; j++) { |
| 297 | TaskView tv = taskViews.get(j); |
| 298 | if (tv.getTask() == task) { |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 299 | EventBus.getDefault().send(new LaunchTaskEvent(tv, task, taskBounds, |
| 300 | destinationStack, false)); |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 301 | return true; |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | return false; |
| 306 | } |
| 307 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 308 | /** Adds the search bar */ |
Winson Chung | aee097c | 2015-04-02 18:16:02 -0700 | [diff] [blame] | 309 | public void setSearchBar(RecentsAppWidgetHostView searchBar) { |
Winson Chung | af3bb69 | 2015-06-03 17:31:39 -0700 | [diff] [blame] | 310 | // Remove the previous search bar if one exists |
| 311 | if (mSearchBar != null && indexOfChild(mSearchBar) > -1) { |
| 312 | removeView(mSearchBar); |
| 313 | } |
| 314 | // Add the new search bar |
| 315 | if (searchBar != null) { |
| 316 | mSearchBar = searchBar; |
| 317 | addView(mSearchBar); |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 318 | } |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Winson Chung | 772b6b1 | 2014-07-03 15:54:02 -0700 | [diff] [blame] | 321 | /** Returns whether there is currently a search bar */ |
Winson Chung | aee097c | 2015-04-02 18:16:02 -0700 | [diff] [blame] | 322 | public boolean hasValidSearchBar() { |
| 323 | return mSearchBar != null && !mSearchBar.isReinflateRequired(); |
Winson Chung | 772b6b1 | 2014-07-03 15:54:02 -0700 | [diff] [blame] | 324 | } |
| 325 | |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 326 | /** |
| 327 | * Hides the task stack and shows the empty view. |
| 328 | */ |
| 329 | public void showEmptyView() { |
Winson | d8b1d63 | 2016-01-04 17:51:18 -0800 | [diff] [blame] | 330 | if (RecentsDebugFlags.Static.EnableSearchBar && (mSearchBar != null)) { |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 331 | mSearchBar.setVisibility(View.INVISIBLE); |
| 332 | } |
| 333 | mTaskStackView.setVisibility(View.INVISIBLE); |
| 334 | mEmptyView.setVisibility(View.VISIBLE); |
| 335 | mEmptyView.bringToFront(); |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 336 | if (RecentsDebugFlags.Static.EnableHistory) { |
| 337 | mHistoryButton.bringToFront(); |
| 338 | } |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | /** |
| 342 | * Shows the task stack and hides the empty view. |
| 343 | */ |
| 344 | public void hideEmptyView() { |
| 345 | mEmptyView.setVisibility(View.INVISIBLE); |
| 346 | mTaskStackView.setVisibility(View.VISIBLE); |
Winson | d8b1d63 | 2016-01-04 17:51:18 -0800 | [diff] [blame] | 347 | if (RecentsDebugFlags.Static.EnableSearchBar && (mSearchBar != null)) { |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 348 | mSearchBar.setVisibility(View.VISIBLE); |
| 349 | } |
| 350 | mTaskStackView.bringToFront(); |
Winson Chung | 772b6b1 | 2014-07-03 15:54:02 -0700 | [diff] [blame] | 351 | if (mSearchBar != null) { |
Winson Chung | 012ef36 | 2014-07-31 18:36:25 -0700 | [diff] [blame] | 352 | mSearchBar.bringToFront(); |
Winson Chung | 772b6b1 | 2014-07-03 15:54:02 -0700 | [diff] [blame] | 353 | } |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 354 | if (RecentsDebugFlags.Static.EnableHistory) { |
| 355 | mHistoryButton.bringToFront(); |
| 356 | } |
Winson Chung | 772b6b1 | 2014-07-03 15:54:02 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 359 | @Override |
| 360 | protected void onAttachedToWindow() { |
| 361 | EventBus.getDefault().register(this, RecentsActivity.EVENT_BUS_PRIORITY + 1); |
Winson | c8a4cdc | 2016-01-19 11:30:51 -0800 | [diff] [blame] | 362 | EventBus.getDefault().register(mTouchHandler, RecentsActivity.EVENT_BUS_PRIORITY + 2); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 363 | super.onAttachedToWindow(); |
| 364 | } |
| 365 | |
| 366 | @Override |
| 367 | protected void onDetachedFromWindow() { |
| 368 | super.onDetachedFromWindow(); |
| 369 | EventBus.getDefault().unregister(this); |
| 370 | EventBus.getDefault().unregister(mTouchHandler); |
| 371 | } |
| 372 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 373 | /** |
| 374 | * This is called with the full size of the window since we are handling our own insets. |
| 375 | */ |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 376 | @Override |
| 377 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 378 | RecentsConfiguration config = Recents.getConfiguration(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 379 | int width = MeasureSpec.getSize(widthMeasureSpec); |
| 380 | int height = MeasureSpec.getSize(heightMeasureSpec); |
Winson Chung | bd91297 | 2014-03-18 14:36:35 -0700 | [diff] [blame] | 381 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 382 | // Get the search bar bounds and measure the search bar layout |
Winson Chung | af3bb69 | 2015-06-03 17:31:39 -0700 | [diff] [blame] | 383 | Rect searchBarSpaceBounds = new Rect(); |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 384 | if (mSearchBar != null) { |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 385 | config.getSearchBarBounds(new Rect(0, 0, width, height), mSystemInsets.top, |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 386 | searchBarSpaceBounds); |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 387 | mSearchBar.measure( |
| 388 | MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.width(), MeasureSpec.EXACTLY), |
| 389 | MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.height(), MeasureSpec.EXACTLY)); |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 392 | Rect taskStackBounds = new Rect(); |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 393 | config.getTaskStackBounds(new Rect(0, 0, width, height), mSystemInsets.top, |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 394 | mSystemInsets.right, searchBarSpaceBounds, taskStackBounds); |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 395 | if (mTaskStackView != null && mTaskStackView.getVisibility() != GONE) { |
Winson | 88f00ab | 2015-10-05 17:24:00 -0700 | [diff] [blame] | 396 | mTaskStackView.setTaskStackBounds(taskStackBounds, mSystemInsets); |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 397 | mTaskStackView.measure(widthMeasureSpec, heightMeasureSpec); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 398 | } |
| 399 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 400 | // Measure the empty view to the full size of the screen |
| 401 | if (mEmptyView.getVisibility() != GONE) { |
| 402 | measureChild(mEmptyView, MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), |
| 403 | MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)); |
| 404 | } |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 405 | |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 406 | if (RecentsDebugFlags.Static.EnableHistory) { |
| 407 | // Measure the history view |
| 408 | if (mHistoryView != null && mHistoryView.getVisibility() != GONE) { |
| 409 | measureChild(mHistoryView, MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), |
| 410 | MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)); |
| 411 | } |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 412 | |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 413 | // Measure the history button within the constraints of the space above the stack |
| 414 | Rect historyButtonRect = mTaskStackView.mLayoutAlgorithm.mHistoryButtonRect; |
| 415 | measureChild(mHistoryButton, |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 416 | MeasureSpec.makeMeasureSpec(historyButtonRect.width(), MeasureSpec.AT_MOST), |
| 417 | MeasureSpec.makeMeasureSpec(historyButtonRect.height(), MeasureSpec.AT_MOST)); |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 418 | if (mHistoryClearAllButton != null && mHistoryClearAllButton.getVisibility() != GONE) { |
| 419 | measureChild(mHistoryClearAllButton, |
| 420 | MeasureSpec.makeMeasureSpec(historyButtonRect.width(), MeasureSpec.AT_MOST), |
| 421 | MeasureSpec.makeMeasureSpec(historyButtonRect.height(), MeasureSpec.AT_MOST)); |
| 422 | } |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 423 | } |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 424 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 425 | setMeasuredDimension(width, height); |
| 426 | } |
| 427 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 428 | /** |
| 429 | * This is called with the full size of the window since we are handling our own insets. |
| 430 | */ |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 431 | @Override |
| 432 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 433 | RecentsConfiguration config = Recents.getConfiguration(); |
| 434 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 435 | // Get the search bar bounds so that we lay it out |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 436 | Rect measuredRect = new Rect(0, 0, getMeasuredWidth(), getMeasuredHeight()); |
| 437 | Rect searchBarSpaceBounds = new Rect(); |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 438 | if (mSearchBar != null) { |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 439 | config.getSearchBarBounds(measuredRect, |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 440 | mSystemInsets.top, searchBarSpaceBounds); |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 441 | mSearchBar.layout(searchBarSpaceBounds.left, searchBarSpaceBounds.top, |
| 442 | searchBarSpaceBounds.right, searchBarSpaceBounds.bottom); |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 443 | } |
| 444 | |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 445 | if (mTaskStackView != null && mTaskStackView.getVisibility() != GONE) { |
| 446 | mTaskStackView.layout(left, top, left + getMeasuredWidth(), top + getMeasuredHeight()); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 447 | } |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 448 | |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 449 | // Layout the empty view |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 450 | if (mEmptyView.getVisibility() != GONE) { |
| 451 | mEmptyView.layout(left, top, right, bottom); |
| 452 | } |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 453 | |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 454 | if (RecentsDebugFlags.Static.EnableHistory) { |
| 455 | // Layout the history view |
| 456 | if (mHistoryView != null && mHistoryView.getVisibility() != GONE) { |
| 457 | mHistoryView.layout(left, top, right, bottom); |
| 458 | } |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 459 | |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 460 | // Layout the history button such that its drawable is start-aligned with the stack, |
| 461 | // vertically centered in the available space above the stack |
| 462 | Rect historyButtonRect = mTaskStackView.mLayoutAlgorithm.mHistoryButtonRect; |
| 463 | int historyLeft = isLayoutRtl() |
| 464 | ? historyButtonRect.right + mHistoryButton.getPaddingStart() |
| 465 | - mHistoryButton.getMeasuredWidth() |
| 466 | : historyButtonRect.left - mHistoryButton.getPaddingStart(); |
| 467 | int historyTop = historyButtonRect.top + |
| 468 | (historyButtonRect.height() - mHistoryButton.getMeasuredHeight()) / 2; |
| 469 | mHistoryButton.layout(historyLeft, historyTop, |
| 470 | historyLeft + mHistoryButton.getMeasuredWidth(), |
| 471 | historyTop + mHistoryButton.getMeasuredHeight()); |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 472 | |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 473 | // Layout the history clear all button such that it is end-aligned with the stack, |
| 474 | // vertically centered in the available space above the stack |
| 475 | if (mHistoryClearAllButton != null && mHistoryClearAllButton.getVisibility() != GONE) { |
| 476 | int clearAllLeft = isLayoutRtl() |
| 477 | ? historyButtonRect.left - mHistoryClearAllButton.getPaddingStart() |
| 478 | : historyButtonRect.right + mHistoryClearAllButton.getPaddingStart() |
| 479 | - mHistoryClearAllButton.getMeasuredWidth(); |
| 480 | int clearAllTop = historyButtonRect.top + |
| 481 | (historyButtonRect.height() - mHistoryClearAllButton.getMeasuredHeight()) / |
| 482 | 2; |
| 483 | mHistoryClearAllButton.layout(clearAllLeft, clearAllTop, |
| 484 | clearAllLeft + mHistoryClearAllButton.getMeasuredWidth(), |
| 485 | clearAllTop + mHistoryClearAllButton.getMeasuredHeight()); |
| 486 | } |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 487 | } |
| 488 | |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 489 | if (mAwaitingFirstLayout) { |
| 490 | mAwaitingFirstLayout = false; |
| 491 | |
| 492 | // If launched via dragging from the nav bar, then we should translate the whole view |
| 493 | // down offscreen |
| 494 | RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState(); |
| 495 | if (launchState.launchedViaDragGesture) { |
| 496 | setTranslationY(getMeasuredHeight()); |
Jorim Jaggi | 0ca8826 | 2015-12-07 17:15:16 -0800 | [diff] [blame] | 497 | } else { |
| 498 | setTranslationY(0f); |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 499 | } |
| 500 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 501 | } |
| 502 | |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 503 | @Override |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 504 | public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 505 | mSystemInsets.set(insets.getSystemWindowInsets()); |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 506 | requestLayout(); |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 507 | return insets; |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 508 | } |
| 509 | |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 510 | @Override |
| 511 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
| 512 | return mTouchHandler.onInterceptTouchEvent(ev); |
| 513 | } |
| 514 | |
| 515 | @Override |
| 516 | public boolean onTouchEvent(MotionEvent ev) { |
| 517 | return mTouchHandler.onTouchEvent(ev); |
| 518 | } |
| 519 | |
| 520 | @Override |
Winson | be8e696 | 2016-02-01 14:27:52 -0800 | [diff] [blame] | 521 | public void onDrawForeground(Canvas canvas) { |
| 522 | super.onDrawForeground(canvas); |
| 523 | |
Winson | 036693c | 2016-01-14 17:16:06 -0800 | [diff] [blame] | 524 | ArrayList<TaskStack.DockState> visDockStates = mTouchHandler.getVisibleDockStates(); |
| 525 | for (int i = visDockStates.size() - 1; i >= 0; i--) { |
| 526 | Drawable d = visDockStates.get(i).viewState.dockAreaOverlay; |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 527 | if (d.getAlpha() > 0) { |
| 528 | d.draw(canvas); |
| 529 | } |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 530 | } |
| 531 | } |
| 532 | |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 533 | @Override |
| 534 | protected boolean verifyDrawable(Drawable who) { |
Winson | 036693c | 2016-01-14 17:16:06 -0800 | [diff] [blame] | 535 | ArrayList<TaskStack.DockState> visDockStates = mTouchHandler.getVisibleDockStates(); |
| 536 | for (int i = visDockStates.size() - 1; i >= 0; i--) { |
| 537 | Drawable d = visDockStates.get(i).viewState.dockAreaOverlay; |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 538 | if (d == who) { |
| 539 | return true; |
| 540 | } |
| 541 | } |
| 542 | return super.verifyDrawable(who); |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 543 | } |
| 544 | |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 545 | /**** EventBus Events ****/ |
| 546 | |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 547 | public final void onBusEvent(LaunchTaskEvent event) { |
| 548 | mLastTaskLaunchedWasFreeform = event.task.isFreeformTask(); |
| 549 | mTransitionHelper.launchTaskFromRecents(mStack, event.task, mTaskStackView, event.taskView, |
| 550 | event.screenPinningRequested, event.targetTaskBounds, event.targetTaskStack); |
| 551 | } |
| 552 | |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 553 | public final void onBusEvent(DismissRecentsToHomeAnimationStarted event) { |
Winson | 5044863 | 2016-02-01 18:04:59 -0800 | [diff] [blame] | 554 | int taskViewExitToHomeDuration = TaskStackAnimationHelper.EXIT_TO_HOME_TRANSLATION_DURATION; |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 555 | if (RecentsDebugFlags.Static.EnableHistory) { |
| 556 | // Hide the history button |
| 557 | hideHistoryButton(taskViewExitToHomeDuration, false /* translate */); |
| 558 | } |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 559 | animateBackgroundScrim(0f, taskViewExitToHomeDuration); |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 560 | } |
| 561 | |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 562 | public final void onBusEvent(DragStartEvent event) { |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 563 | updateVisibleDockRegions(mTouchHandler.getDockStatesForCurrentOrientation(), |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 564 | true /* isDefaultDockState */, TaskStack.DockState.NONE.viewState.dockAreaAlpha, |
| 565 | true /* animateAlpha */, false /* animateBounds */); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 566 | } |
| 567 | |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 568 | public final void onBusEvent(DragDropTargetChangedEvent event) { |
| 569 | if (event.dropTarget == null || !(event.dropTarget instanceof TaskStack.DockState)) { |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 570 | updateVisibleDockRegions(mTouchHandler.getDockStatesForCurrentOrientation(), |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 571 | true /* isDefaultDockState */, TaskStack.DockState.NONE.viewState.dockAreaAlpha, |
| 572 | true /* animateAlpha */, true /* animateBounds */); |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 573 | } else { |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 574 | final TaskStack.DockState dockState = (TaskStack.DockState) event.dropTarget; |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 575 | updateVisibleDockRegions(new TaskStack.DockState[] {dockState}, |
| 576 | false /* isDefaultDockState */, -1, true /* animateAlpha */, |
| 577 | true /* animateBounds */); |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 578 | } |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | public final void onBusEvent(final DragEndEvent event) { |
Winson | 479f744 | 2015-11-25 15:16:27 -0800 | [diff] [blame] | 582 | // Handle the case where we drop onto a dock region |
| 583 | if (event.dropTarget instanceof TaskStack.DockState) { |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 584 | final TaskStack.DockState dockState = (TaskStack.DockState) event.dropTarget; |
| 585 | |
| 586 | // Hide the dock region |
| 587 | updateVisibleDockRegions(null, false /* isDefaultDockState */, -1, |
| 588 | false /* animateAlpha */, false /* animateBounds */); |
| 589 | |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 590 | TaskStackLayoutAlgorithm stackLayout = mTaskStackView.getStackAlgorithm(); |
| 591 | TaskStackViewScroller stackScroller = mTaskStackView.getScroller(); |
| 592 | TaskViewTransform tmpTransform = new TaskViewTransform(); |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 593 | |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 594 | // We translated the view but we need to animate it back from the current layout-space |
| 595 | // rect to its final layout-space rect |
| 596 | int x = (int) event.taskView.getTranslationX(); |
| 597 | int y = (int) event.taskView.getTranslationY(); |
| 598 | Rect taskViewRect = new Rect(event.taskView.getLeft(), event.taskView.getTop(), |
| 599 | event.taskView.getRight(), event.taskView.getBottom()); |
| 600 | taskViewRect.offset(x, y); |
| 601 | event.taskView.setTranslationX(0); |
| 602 | event.taskView.setTranslationY(0); |
| 603 | event.taskView.setLeftTopRightBottom(taskViewRect.left, taskViewRect.top, |
| 604 | taskViewRect.right, taskViewRect.bottom); |
| 605 | |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 606 | // Remove the task view after it is docked |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 607 | mTaskStackView.updateLayoutAlgorithm(false /* boundScroll */); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 608 | stackLayout.getStackTransform(event.task, stackScroller.getStackScroll(), tmpTransform, |
| 609 | null); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 610 | tmpTransform.alpha = 0; |
| 611 | tmpTransform.scale = 1f; |
| 612 | tmpTransform.rect.set(taskViewRect); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 613 | mTaskStackView.updateTaskViewToTransform(event.taskView, tmpTransform, |
Winson | be8e696 | 2016-02-01 14:27:52 -0800 | [diff] [blame] | 614 | new AnimationProps(125, Interpolators.ALPHA_OUT, |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 615 | new AnimatorListenerAdapter() { |
| 616 | @Override |
| 617 | public void onAnimationEnd(Animator animation) { |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 618 | // Dock the task and launch it |
| 619 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Filip Gruszczynski | f298e90 | 2016-01-18 08:59:45 -0800 | [diff] [blame] | 620 | ssp.startTaskInDockedMode(getContext(), event.taskView, |
| 621 | event.task.key.id, dockState.createMode); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 622 | |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 623 | // Animate the stack accordingly |
Winson | be8e696 | 2016-02-01 14:27:52 -0800 | [diff] [blame] | 624 | AnimationProps stackAnim = new AnimationProps( |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 625 | TaskStackView.DEFAULT_SYNC_STACK_DURATION, |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 626 | Interpolators.FAST_OUT_SLOW_IN); |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 627 | mTaskStackView.getStack().removeTask(event.task, stackAnim); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 628 | } |
| 629 | })); |
Winson | a0a8ae4 | 2015-12-01 10:43:02 -0800 | [diff] [blame] | 630 | |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 631 | MetricsLogger.action(mContext, MetricsEvent.ACTION_WINDOW_DOCK_DRAG_DROP); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 632 | } else { |
| 633 | // Animate the overlay alpha back to 0 |
| 634 | updateVisibleDockRegions(null, true /* isDefaultDockState */, -1, |
| 635 | true /* animateAlpha */, false /* animateBounds */); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 636 | } |
| 637 | } |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 638 | |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 639 | public final void onBusEvent(DraggingInRecentsEvent event) { |
Jorim Jaggi | 54b1a6d | 2015-11-24 17:48:26 -0800 | [diff] [blame] | 640 | if (mTaskStackView.getTaskViews().size() > 0) { |
| 641 | setTranslationY(event.distanceFromTop - mTaskStackView.getTaskViews().get(0).getY()); |
| 642 | } |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | public final void onBusEvent(DraggingInRecentsEndedEvent event) { |
Jorim Jaggi | 870ab5a | 2015-12-02 18:37:54 -0800 | [diff] [blame] | 646 | ViewPropertyAnimator animator = animate(); |
Jorim Jaggi | 8fccfe2 | 2015-12-03 16:58:08 -0800 | [diff] [blame] | 647 | if (event.velocity > mFlingAnimationUtils.getMinVelocityPxPerSecond()) { |
Jorim Jaggi | 870ab5a | 2015-12-02 18:37:54 -0800 | [diff] [blame] | 648 | animator.translationY(getHeight()); |
| 649 | animator.withEndAction(new Runnable() { |
| 650 | @Override |
| 651 | public void run() { |
| 652 | WindowManagerProxy.getInstance().maximizeDockedStack(); |
| 653 | } |
| 654 | }); |
| 655 | mFlingAnimationUtils.apply(animator, getTranslationY(), getHeight(), event.velocity); |
| 656 | } else { |
| 657 | animator.translationY(0f); |
| 658 | animator.setListener(null); |
| 659 | mFlingAnimationUtils.apply(animator, getTranslationY(), 0, event.velocity); |
| 660 | } |
| 661 | animator.start(); |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 662 | } |
| 663 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 664 | public final void onBusEvent(EnterRecentsWindowAnimationCompletedEvent event) { |
| 665 | RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState(); |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 666 | if (!launchState.launchedWhileDocking && !launchState.launchedFromApp |
Jorim Jaggi | e161f08 | 2016-02-05 14:26:16 -0800 | [diff] [blame] | 667 | && mStack.getTaskCount() > 0) { |
Winson | 5044863 | 2016-02-01 18:04:59 -0800 | [diff] [blame] | 668 | animateBackgroundScrim(DEFAULT_SCRIM_ALPHA, |
| 669 | TaskStackAnimationHelper.ENTER_FROM_HOME_TRANSLATION_DURATION); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 670 | } |
| 671 | } |
| 672 | |
| 673 | public final void onBusEvent(UpdateBackgroundScrimEvent event) { |
| 674 | animateBackgroundScrim(event.alpha, DEFAULT_UPDATE_SCRIM_DURATION); |
| 675 | } |
| 676 | |
| 677 | public final void onBusEvent(ResetBackgroundScrimEvent event) { |
| 678 | animateBackgroundScrim(DEFAULT_SCRIM_ALPHA, DEFAULT_UPDATE_SCRIM_DURATION); |
| 679 | } |
| 680 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 681 | public final void onBusEvent(ToggleHistoryEvent event) { |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 682 | if (!RecentsDebugFlags.Static.EnableHistory) { |
| 683 | return; |
| 684 | } |
| 685 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 686 | if (mHistoryView != null && mHistoryView.isVisible()) { |
| 687 | EventBus.getDefault().send(new HideHistoryEvent(true /* animate */)); |
| 688 | } else { |
| 689 | EventBus.getDefault().send(new ShowHistoryEvent()); |
| 690 | } |
| 691 | } |
| 692 | |
| 693 | public final void onBusEvent(ShowHistoryEvent event) { |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 694 | if (!RecentsDebugFlags.Static.EnableHistory) { |
| 695 | return; |
| 696 | } |
| 697 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 698 | if (mHistoryView == null) { |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 699 | LayoutInflater inflater = LayoutInflater.from(getContext()); |
| 700 | mHistoryView = (RecentsHistoryView) inflater.inflate(R.layout.recents_history, this, |
| 701 | false); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 702 | addView(mHistoryView); |
| 703 | |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 704 | final float cornerRadius = getResources().getDimensionPixelSize( |
| 705 | R.dimen.recents_task_view_rounded_corners_radius); |
| 706 | mHistoryClearAllButton = (TextView) inflater.inflate( |
| 707 | R.layout.recents_history_clear_all_button, this, false); |
| 708 | mHistoryClearAllButton.setOnClickListener(new View.OnClickListener() { |
| 709 | @Override |
| 710 | public void onClick(View v) { |
| 711 | EventBus.getDefault().send(new ClearHistoryEvent()); |
| 712 | } |
| 713 | }); |
| 714 | mHistoryClearAllButton.setClipToOutline(true); |
| 715 | mHistoryClearAllButton.setOutlineProvider(new ViewOutlineProvider() { |
| 716 | @Override |
| 717 | public void getOutline(View view, Outline outline) { |
| 718 | outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), cornerRadius); |
| 719 | } |
| 720 | }); |
| 721 | addView(mHistoryClearAllButton); |
| 722 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 723 | // Since this history view is inflated by a view stub after the insets have already |
| 724 | // been applied, we have to set them ourselves initial from the insets that were last |
| 725 | // provided. |
| 726 | mHistoryView.setSystemInsets(mSystemInsets); |
| 727 | mHistoryView.setHeaderHeight(mHistoryButton.getMeasuredHeight()); |
| 728 | mHistoryButton.bringToFront(); |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 729 | mHistoryClearAllButton.bringToFront(); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | // Animate the empty view in parallel with the history view (the task view animations are |
| 733 | // handled in TaskStackView) |
| 734 | Rect stackRect = mTaskStackView.mLayoutAlgorithm.mStackRect; |
| 735 | if (mEmptyView.getVisibility() == View.VISIBLE) { |
| 736 | int historyTransitionDuration = getResources().getInteger( |
| 737 | R.integer.recents_history_transition_duration); |
| 738 | mEmptyView.animate() |
| 739 | .alpha(0f) |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 740 | .translationY(stackRect.height() / 2) |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 741 | .setDuration(historyTransitionDuration) |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 742 | .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 743 | .withEndAction(new Runnable() { |
| 744 | @Override |
| 745 | public void run() { |
| 746 | mEmptyView.setVisibility(View.INVISIBLE); |
| 747 | } |
| 748 | }) |
| 749 | .start(); |
| 750 | } |
| 751 | |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 752 | mHistoryView.show(mStack, stackRect.height(), mHistoryClearAllButton); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | public final void onBusEvent(HideHistoryEvent event) { |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 756 | if (!RecentsDebugFlags.Static.EnableHistory) { |
| 757 | return; |
| 758 | } |
| 759 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 760 | // Animate the empty view in parallel with the history view (the task view animations are |
| 761 | // handled in TaskStackView) |
| 762 | Rect stackRect = mTaskStackView.mLayoutAlgorithm.mStackRect; |
| 763 | if (mStack.getTaskCount() == 0) { |
| 764 | int historyTransitionDuration = getResources().getInteger( |
| 765 | R.integer.recents_history_transition_duration); |
| 766 | mEmptyView.setVisibility(View.VISIBLE); |
| 767 | mEmptyView.animate() |
| 768 | .alpha(1f) |
| 769 | .translationY(0) |
| 770 | .setDuration(historyTransitionDuration) |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 771 | .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 772 | .start(); |
| 773 | } |
| 774 | |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 775 | mHistoryView.hide(event.animate, stackRect.height(), mHistoryClearAllButton); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | public final void onBusEvent(ShowHistoryButtonEvent event) { |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 779 | if (!RecentsDebugFlags.Static.EnableHistory) { |
| 780 | return; |
| 781 | } |
| 782 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 783 | showHistoryButton(150, event.translate); |
| 784 | } |
| 785 | |
| 786 | public final void onBusEvent(HideHistoryButtonEvent event) { |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 787 | if (!RecentsDebugFlags.Static.EnableHistory) { |
| 788 | return; |
| 789 | } |
| 790 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 791 | hideHistoryButton(100, true /* translate */); |
| 792 | } |
| 793 | |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 794 | /** |
| 795 | * Shows the history button. |
| 796 | */ |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 797 | private void showHistoryButton(final int duration, final boolean translate) { |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 798 | if (!RecentsDebugFlags.Static.EnableHistory) { |
| 799 | return; |
| 800 | } |
| 801 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 802 | final ReferenceCountedTrigger postAnimationTrigger = new ReferenceCountedTrigger(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 803 | if (mHistoryButton.getVisibility() == View.INVISIBLE) { |
| 804 | mHistoryButton.setVisibility(View.VISIBLE); |
| 805 | mHistoryButton.setAlpha(0f); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 806 | if (translate) { |
| 807 | mHistoryButton.setTranslationY(-mHistoryButton.getMeasuredHeight() * 0.25f); |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 808 | } else { |
| 809 | mHistoryButton.setTranslationY(0f); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 810 | } |
| 811 | postAnimationTrigger.addLastDecrementRunnable(new Runnable() { |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 812 | @Override |
| 813 | public void run() { |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 814 | if (translate) { |
| 815 | mHistoryButton.animate() |
| 816 | .translationY(0f); |
| 817 | } |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 818 | mHistoryButton.animate() |
| 819 | .alpha(1f) |
| 820 | .setDuration(duration) |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 821 | .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 822 | .withLayer() |
| 823 | .start(); |
| 824 | } |
| 825 | }); |
| 826 | } |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 827 | postAnimationTrigger.flushLastDecrementRunnables(); |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | /** |
| 831 | * Hides the history button. |
| 832 | */ |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 833 | private void hideHistoryButton(int duration, boolean translate) { |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 834 | if (!RecentsDebugFlags.Static.EnableHistory) { |
| 835 | return; |
| 836 | } |
| 837 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 838 | final ReferenceCountedTrigger postAnimationTrigger = new ReferenceCountedTrigger(); |
| 839 | hideHistoryButton(duration, translate, postAnimationTrigger); |
Winson Chung | aaeaac1 | 2015-12-16 16:49:36 -0500 | [diff] [blame] | 840 | postAnimationTrigger.flushLastDecrementRunnables(); |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 841 | } |
| 842 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 843 | /** |
| 844 | * Hides the history button. |
| 845 | */ |
| 846 | private void hideHistoryButton(int duration, boolean translate, |
| 847 | final ReferenceCountedTrigger postAnimationTrigger) { |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 848 | if (!RecentsDebugFlags.Static.EnableHistory) { |
| 849 | return; |
| 850 | } |
| 851 | |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 852 | if (mHistoryButton.getVisibility() == View.VISIBLE) { |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 853 | if (translate) { |
| 854 | mHistoryButton.animate() |
| 855 | .translationY(-mHistoryButton.getMeasuredHeight() * 0.25f); |
| 856 | } |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 857 | mHistoryButton.animate() |
| 858 | .alpha(0f) |
| 859 | .setDuration(duration) |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 860 | .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 861 | .withEndAction(new Runnable() { |
| 862 | @Override |
| 863 | public void run() { |
| 864 | mHistoryButton.setVisibility(View.INVISIBLE); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 865 | postAnimationTrigger.decrement(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 866 | } |
| 867 | }) |
| 868 | .withLayer() |
| 869 | .start(); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 870 | postAnimationTrigger.increment(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 871 | } |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 872 | } |
| 873 | |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 874 | /** |
| 875 | * Updates the dock region to match the specified dock state. |
| 876 | */ |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 877 | private void updateVisibleDockRegions(TaskStack.DockState[] newDockStates, |
| 878 | boolean isDefaultDockState, int overrideAlpha, boolean animateAlpha, |
| 879 | boolean animateBounds) { |
Winson | c5fd350 | 2016-01-18 15:18:37 -0800 | [diff] [blame] | 880 | ArraySet<TaskStack.DockState> newDockStatesSet = Utilities.arrayToSet(newDockStates, |
| 881 | new ArraySet<TaskStack.DockState>()); |
Winson | 036693c | 2016-01-14 17:16:06 -0800 | [diff] [blame] | 882 | ArrayList<TaskStack.DockState> visDockStates = mTouchHandler.getVisibleDockStates(); |
| 883 | for (int i = visDockStates.size() - 1; i >= 0; i--) { |
| 884 | TaskStack.DockState dockState = visDockStates.get(i); |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 885 | TaskStack.DockState.ViewState viewState = dockState.viewState; |
| 886 | if (newDockStates == null || !newDockStatesSet.contains(dockState)) { |
| 887 | // This is no longer visible, so hide it |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 888 | viewState.startAnimation(null, 0, DOCK_AREA_OVERLAY_TRANSITION_DURATION, |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 889 | Interpolators.ALPHA_OUT, animateAlpha, animateBounds); |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 890 | } else { |
| 891 | // This state is now visible, update the bounds and show it |
| 892 | int alpha = (overrideAlpha != -1 ? overrideAlpha : viewState.dockAreaAlpha); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 893 | Rect bounds = isDefaultDockState |
| 894 | ? dockState.getPreDockedBounds(getMeasuredWidth(), getMeasuredHeight()) |
| 895 | : dockState.getDockedBounds(getMeasuredWidth(), getMeasuredHeight(), |
| 896 | mDividerSize, mSystemInsets, getResources()); |
| 897 | if (viewState.dockAreaOverlay.getCallback() != this) { |
| 898 | viewState.dockAreaOverlay.setCallback(this); |
| 899 | viewState.dockAreaOverlay.setBounds(bounds); |
| 900 | } |
| 901 | viewState.startAnimation(bounds, alpha, DOCK_AREA_OVERLAY_TRANSITION_DURATION, |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 902 | Interpolators.ALPHA_IN, animateAlpha, animateBounds); |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 903 | } |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 904 | } |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 905 | } |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 906 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 907 | /** |
| 908 | * Animates the background scrim to the given {@param alpha}. |
| 909 | */ |
| 910 | private void animateBackgroundScrim(float alpha, int duration) { |
| 911 | Utilities.cancelAnimationWithoutCallbacks(mBackgroundScrimAnimator); |
| 912 | int alphaInt = (int) (alpha * 255); |
| 913 | mBackgroundScrimAnimator = ObjectAnimator.ofInt(mBackgroundScrim, Utilities.DRAWABLE_ALPHA, |
| 914 | mBackgroundScrim.getAlpha(), alphaInt); |
| 915 | mBackgroundScrimAnimator.setDuration(duration); |
| 916 | mBackgroundScrimAnimator.setInterpolator(alphaInt > mBackgroundScrim.getAlpha() |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 917 | ? Interpolators.ALPHA_OUT |
| 918 | : Interpolators.ALPHA_IN); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 919 | mBackgroundScrimAnimator.start(); |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 920 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 921 | } |