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; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 22 | import android.animation.ObjectAnimator; |
Winson Chung | d45aac4 | 2017-08-17 17:15:31 -0700 | [diff] [blame] | 23 | import android.animation.ValueAnimator; |
| 24 | import android.animation.ValueAnimator.AnimatorUpdateListener; |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 25 | import android.app.ActivityOptions.OnAnimationStartedListener; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 26 | import android.content.Context; |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 27 | import android.content.res.ColorStateList; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 28 | import android.graphics.Canvas; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 29 | import android.graphics.Color; |
Winson Chung | d45aac4 | 2017-08-17 17:15:31 -0700 | [diff] [blame] | 30 | import android.graphics.Point; |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 31 | import android.graphics.PointF; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 32 | import android.graphics.Rect; |
Winson Chung | d45aac4 | 2017-08-17 17:15:31 -0700 | [diff] [blame] | 33 | import android.graphics.drawable.ColorDrawable; |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 34 | import android.graphics.drawable.Drawable; |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 35 | import android.util.ArraySet; |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 36 | import android.util.AttributeSet; |
Lucas Dupin | ae90ba8 | 2017-06-16 16:45:59 -0700 | [diff] [blame] | 37 | import android.util.MathUtils; |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 38 | import android.view.AppTransitionAnimationSpec; |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 39 | import android.view.LayoutInflater; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 40 | import android.view.MotionEvent; |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 41 | import android.view.View; |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 42 | import android.view.ViewDebug; |
Jorim Jaggi | 870ab5a | 2015-12-02 18:37:54 -0800 | [diff] [blame] | 43 | import android.view.ViewPropertyAnimator; |
Winson Chung | d45aac4 | 2017-08-17 17:15:31 -0700 | [diff] [blame] | 44 | import android.view.Window; |
Winson Chung | 653f70c2 | 2014-05-19 14:49:42 -0700 | [diff] [blame] | 45 | import android.view.WindowInsets; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 46 | import android.widget.FrameLayout; |
Winson Chung | de750de | 2015-12-11 10:26:06 -0500 | [diff] [blame] | 47 | import android.widget.TextView; |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 48 | |
Lucas Dupin | 7224c1e | 2017-07-06 14:35:30 -0700 | [diff] [blame] | 49 | import com.android.internal.colorextraction.ColorExtractor; |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 50 | import com.android.internal.colorextraction.drawable.GradientDrawable; |
Winson | dc8de84 | 2016-01-06 15:21:41 -0800 | [diff] [blame] | 51 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 52 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 53 | import com.android.settingslib.Utils; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 54 | import com.android.systemui.Interpolators; |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 55 | import com.android.systemui.R; |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 56 | import com.android.systemui.recents.Recents; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 57 | import com.android.systemui.recents.RecentsActivity; |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 58 | import com.android.systemui.recents.RecentsActivityLaunchState; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 59 | import com.android.systemui.recents.RecentsConfiguration; |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 60 | import com.android.systemui.recents.RecentsDebugFlags; |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 61 | import com.android.systemui.recents.events.EventBus; |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 62 | import com.android.systemui.recents.events.activity.DismissRecentsToHomeAnimationStarted; |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 63 | import com.android.systemui.recents.events.activity.DockedFirstAnimationFrameEvent; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 64 | import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationCompletedEvent; |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 65 | import com.android.systemui.recents.events.activity.HideStackActionButtonEvent; |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 66 | import com.android.systemui.recents.events.activity.LaunchTaskEvent; |
Winson | d2a0306 | 2016-04-15 11:19:07 -0700 | [diff] [blame] | 67 | import com.android.systemui.recents.events.activity.MultiWindowStateChangedEvent; |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 68 | import com.android.systemui.recents.events.activity.ShowEmptyViewEvent; |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 69 | import com.android.systemui.recents.events.activity.ShowStackActionButtonEvent; |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 70 | import com.android.systemui.recents.events.component.ExpandPipEvent; |
Winson | 3b6ba1a | 2016-03-22 15:37:54 -0700 | [diff] [blame] | 71 | import com.android.systemui.recents.events.ui.AllTaskViewsDismissedEvent; |
Winson | 3b6ba1a | 2016-03-22 15:37:54 -0700 | [diff] [blame] | 72 | import com.android.systemui.recents.events.ui.DismissAllTaskViewsEvent; |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 73 | import com.android.systemui.recents.events.ui.DraggingInRecentsEndedEvent; |
| 74 | import com.android.systemui.recents.events.ui.DraggingInRecentsEvent; |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 75 | import com.android.systemui.recents.events.ui.dragndrop.DragDropTargetChangedEvent; |
Winson | 27c28f8 | 2016-05-05 16:16:50 -0700 | [diff] [blame] | 76 | import com.android.systemui.recents.events.ui.dragndrop.DragEndCancelledEvent; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 77 | import com.android.systemui.recents.events.ui.dragndrop.DragEndEvent; |
| 78 | import com.android.systemui.recents.events.ui.dragndrop.DragStartEvent; |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 79 | import com.android.systemui.recents.misc.ReferenceCountedTrigger; |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 80 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Winson | c5fd350 | 2016-01-18 15:18:37 -0800 | [diff] [blame] | 81 | import com.android.systemui.recents.misc.Utilities; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 82 | import com.android.systemui.recents.model.Task; |
| 83 | import com.android.systemui.recents.model.TaskStack; |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 84 | import com.android.systemui.recents.views.RecentsTransitionHelper.AnimationSpecComposer; |
Jorim Jaggi | cf4411d | 2017-05-12 17:27:46 +0200 | [diff] [blame] | 85 | import com.android.systemui.recents.views.RecentsTransitionHelper.AppTransitionAnimationSpecsFuture; |
Jorim Jaggi | 870ab5a | 2015-12-02 18:37:54 -0800 | [diff] [blame] | 86 | import com.android.systemui.stackdivider.WindowManagerProxy; |
| 87 | import com.android.systemui.statusbar.FlingAnimationUtils; |
Lucas Dupin | ae90ba8 | 2017-06-16 16:45:59 -0700 | [diff] [blame] | 88 | import com.android.systemui.statusbar.phone.ScrimController; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 89 | |
Winson | d72c315 | 2016-04-05 15:33:35 -0700 | [diff] [blame] | 90 | import java.io.PrintWriter; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 91 | import java.util.ArrayList; |
Winson Chung | 6ac8bd6 | 2015-01-07 16:38:35 -0800 | [diff] [blame] | 92 | import java.util.List; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 93 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 94 | /** |
| 95 | * This view is the the top level layout that contains TaskStacks (which are laid out according |
| 96 | * to their SpaceNode bounds. |
| 97 | */ |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 98 | public class RecentsView extends FrameLayout { |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 99 | |
Winson | d72c315 | 2016-04-05 15:33:35 -0700 | [diff] [blame] | 100 | private static final String TAG = "RecentsView"; |
| 101 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 102 | private static final int DEFAULT_UPDATE_SCRIM_DURATION = 200; |
Jorim Jaggi | 6e18e00 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 103 | |
Winson | b677bcb | 2016-04-18 16:58:33 -0700 | [diff] [blame] | 104 | private static final int SHOW_STACK_ACTION_BUTTON_DURATION = 134; |
Winson | 3b6ba1a | 2016-03-22 15:37:54 -0700 | [diff] [blame] | 105 | private static final int HIDE_STACK_ACTION_BUTTON_DURATION = 100; |
| 106 | |
Lucas Dupin | ae90ba8 | 2017-06-16 16:45:59 -0700 | [diff] [blame] | 107 | private static final int BUSY_RECENTS_TASK_COUNT = 3; |
| 108 | |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 109 | private TaskStackView mTaskStackView; |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 110 | private TextView mStackActionButton; |
Winson | 196e861 | 2016-03-15 15:20:17 -0700 | [diff] [blame] | 111 | private TextView mEmptyView; |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 112 | private final float mStackButtonShadowRadius; |
| 113 | private final PointF mStackButtonShadowDistance; |
| 114 | private final int mStackButtonShadowColor; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 115 | |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 116 | private boolean mAwaitingFirstLayout = true; |
| 117 | private boolean mLastTaskLaunchedWasFreeform; |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 118 | |
| 119 | @ViewDebug.ExportedProperty(category="recents") |
Winson | 08deff0 | 2016-08-05 13:58:31 -0700 | [diff] [blame] | 120 | Rect mSystemInsets = new Rect(); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 121 | private int mDividerSize; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 122 | |
Lucas Dupin | ae90ba8 | 2017-06-16 16:45:59 -0700 | [diff] [blame] | 123 | private float mBusynessFactor; |
Lucas Dupin | 7aaa353 | 2017-05-28 08:51:07 -0700 | [diff] [blame] | 124 | private GradientDrawable mBackgroundScrim; |
Winson Chung | d45aac4 | 2017-08-17 17:15:31 -0700 | [diff] [blame] | 125 | private ColorDrawable mMultiWindowBackgroundScrim; |
| 126 | private ValueAnimator mBackgroundScrimAnimator; |
| 127 | private Point mTmpDisplaySize = new Point(); |
| 128 | |
| 129 | private final AnimatorUpdateListener mUpdateBackgroundScrimAlpha = (animation) -> { |
| 130 | int alpha = (Integer) animation.getAnimatedValue(); |
| 131 | mBackgroundScrim.setAlpha(alpha); |
| 132 | mMultiWindowBackgroundScrim.setAlpha(alpha); |
| 133 | }; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 134 | |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 135 | private RecentsTransitionHelper mTransitionHelper; |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 136 | @ViewDebug.ExportedProperty(deepExport=true, prefix="touch_") |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 137 | private RecentsViewTouchHandler mTouchHandler; |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 138 | private final FlingAnimationUtils mFlingAnimationUtils; |
Jorim Jaggi | 870ab5a | 2015-12-02 18:37:54 -0800 | [diff] [blame] | 139 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 140 | public RecentsView(Context context) { |
Jorim Jaggi | 870ab5a | 2015-12-02 18:37:54 -0800 | [diff] [blame] | 141 | this(context, null); |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | public RecentsView(Context context, AttributeSet attrs) { |
| 145 | this(context, attrs, 0); |
| 146 | } |
| 147 | |
| 148 | public RecentsView(Context context, AttributeSet attrs, int defStyleAttr) { |
| 149 | this(context, attrs, defStyleAttr, 0); |
| 150 | } |
| 151 | |
| 152 | public RecentsView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
| 153 | super(context, attrs, defStyleAttr, defStyleRes); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 154 | setWillNotDraw(false); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 155 | |
| 156 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 157 | mTransitionHelper = new RecentsTransitionHelper(getContext()); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 158 | mDividerSize = ssp.getDockedDividerSize(context); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 159 | mTouchHandler = new RecentsViewTouchHandler(this); |
Jorim Jaggi | 870ab5a | 2015-12-02 18:37:54 -0800 | [diff] [blame] | 160 | mFlingAnimationUtils = new FlingAnimationUtils(context, 0.3f); |
Lucas Dupin | 6672fb4 | 2017-05-01 15:59:41 -0700 | [diff] [blame] | 161 | mBackgroundScrim = new GradientDrawable(context); |
Winson Chung | d45aac4 | 2017-08-17 17:15:31 -0700 | [diff] [blame] | 162 | mMultiWindowBackgroundScrim = new ColorDrawable(); |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 163 | |
| 164 | LayoutInflater inflater = LayoutInflater.from(context); |
Lucas Dupin | 3ceaa0a | 2017-06-27 18:17:40 -0700 | [diff] [blame] | 165 | mEmptyView = (TextView) inflater.inflate(R.layout.recents_empty, this, false); |
| 166 | addView(mEmptyView); |
| 167 | |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 168 | if (RecentsDebugFlags.Static.EnableStackActionButton) { |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 169 | if (mStackActionButton != null) { |
| 170 | removeView(mStackActionButton); |
| 171 | } |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 172 | mStackActionButton = (TextView) inflater.inflate(Recents.getConfiguration() |
| 173 | .isLowRamDevice |
| 174 | ? R.layout.recents_low_ram_stack_action_button |
| 175 | : R.layout.recents_stack_action_button, |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 176 | this, false); |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 177 | mStackActionButton.setOnClickListener( |
| 178 | v -> EventBus.getDefault().send(new DismissAllTaskViewsEvent())); |
| 179 | |
| 180 | mStackButtonShadowRadius = mStackActionButton.getShadowRadius(); |
| 181 | mStackButtonShadowDistance = new PointF(mStackActionButton.getShadowDx(), |
| 182 | mStackActionButton.getShadowDy()); |
| 183 | mStackButtonShadowColor = mStackActionButton.getShadowColor(); |
| 184 | addView(mStackActionButton); |
| 185 | } |
| 186 | |
| 187 | reevaluateStyles(); |
| 188 | } |
| 189 | |
| 190 | public void reevaluateStyles() { |
| 191 | int textColor = Utils.getColorAttr(mContext, R.attr.wallpaperTextColor); |
| 192 | boolean usingDarkText = Color.luminance(textColor) < 0.5f; |
| 193 | |
| 194 | mEmptyView.setTextColor(textColor); |
| 195 | mEmptyView.setCompoundDrawableTintList(new ColorStateList(new int[][]{ |
| 196 | {android.R.attr.state_enabled}}, new int[]{textColor})); |
| 197 | |
| 198 | if (mStackActionButton != null) { |
| 199 | mStackActionButton.setTextColor(textColor); |
| 200 | // Enable/disable shadow if text color is already dark. |
Lucas Dupin | 3ceaa0a | 2017-06-27 18:17:40 -0700 | [diff] [blame] | 201 | if (usingDarkText) { |
| 202 | mStackActionButton.setShadowLayer(0, 0, 0, 0); |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 203 | } else { |
| 204 | mStackActionButton.setShadowLayer(mStackButtonShadowRadius, |
| 205 | mStackButtonShadowDistance.x, mStackButtonShadowDistance.y, |
| 206 | mStackButtonShadowColor); |
Lucas Dupin | 3ceaa0a | 2017-06-27 18:17:40 -0700 | [diff] [blame] | 207 | } |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 208 | } |
Lucas Dupin | 3ceaa0a | 2017-06-27 18:17:40 -0700 | [diff] [blame] | 209 | |
| 210 | // Let's also require dark status and nav bars if the text is dark |
| 211 | int systemBarsStyle = usingDarkText ? View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR | |
| 212 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR : 0; |
| 213 | |
| 214 | setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | |
| 215 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | |
| 216 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | |
| 217 | systemBarsStyle); |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 218 | } |
| 219 | |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 220 | /** |
| 221 | * Called from RecentsActivity when it is relaunched. |
| 222 | */ |
Lucas Dupin | ae90ba8 | 2017-06-16 16:45:59 -0700 | [diff] [blame] | 223 | public void onReload(TaskStack stack, boolean isResumingFromVisible) { |
| 224 | final RecentsConfiguration config = Recents.getConfiguration(); |
| 225 | final RecentsActivityLaunchState launchState = config.getLaunchState(); |
| 226 | final boolean isTaskStackEmpty = stack.getTaskCount() == 0; |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 227 | |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 228 | if (mTaskStackView == null) { |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 229 | isResumingFromVisible = false; |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 230 | mTaskStackView = new TaskStackView(getContext()); |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 231 | mTaskStackView.setSystemInsets(mSystemInsets); |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 232 | addView(mTaskStackView); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 233 | } |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 234 | |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 235 | // Reset the state |
| 236 | mAwaitingFirstLayout = !isResumingFromVisible; |
| 237 | mLastTaskLaunchedWasFreeform = false; |
| 238 | |
| 239 | // Update the stack |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 240 | mTaskStackView.onReload(isResumingFromVisible); |
Lucas Dupin | ae90ba8 | 2017-06-16 16:45:59 -0700 | [diff] [blame] | 241 | updateStack(stack, true /* setStackViewTasks */); |
| 242 | updateBusyness(); |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 243 | |
| 244 | if (isResumingFromVisible) { |
| 245 | // If we are already visible, then restore the background scrim |
Lucas Dupin | ae90ba8 | 2017-06-16 16:45:59 -0700 | [diff] [blame] | 246 | animateBackgroundScrim(getOpaqueScrimAlpha(), DEFAULT_UPDATE_SCRIM_DURATION); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 247 | } else { |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 248 | // If we are already occluded by the app, then set the final background scrim alpha now. |
| 249 | // Otherwise, defer until the enter animation completes to animate the scrim alpha with |
| 250 | // the tasks for the home animation. |
Winson | c69249f | 2016-03-28 13:38:39 -0700 | [diff] [blame] | 251 | if (launchState.launchedViaDockGesture || launchState.launchedFromApp |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 252 | || isTaskStackEmpty) { |
Lucas Dupin | ae90ba8 | 2017-06-16 16:45:59 -0700 | [diff] [blame] | 253 | mBackgroundScrim.setAlpha((int) (getOpaqueScrimAlpha() * 255)); |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 254 | } else { |
| 255 | mBackgroundScrim.setAlpha(0); |
| 256 | } |
Winson Chung | d45aac4 | 2017-08-17 17:15:31 -0700 | [diff] [blame] | 257 | mMultiWindowBackgroundScrim.setAlpha(mBackgroundScrim.getAlpha()); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 258 | } |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | /** |
| 262 | * Called from RecentsActivity when the task stack is updated. |
| 263 | */ |
Winson | d2a0306 | 2016-04-15 11:19:07 -0700 | [diff] [blame] | 264 | public void updateStack(TaskStack stack, boolean setStackViewTasks) { |
Winson | d2a0306 | 2016-04-15 11:19:07 -0700 | [diff] [blame] | 265 | if (setStackViewTasks) { |
| 266 | mTaskStackView.setTasks(stack, true /* allowNotifyStackChanges */); |
| 267 | } |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 268 | |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 269 | // Update the top level view's visibilities |
Winson | 4b057c6 | 2016-01-12 15:01:52 -0800 | [diff] [blame] | 270 | if (stack.getTaskCount() > 0) { |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 271 | hideEmptyView(); |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 272 | } else { |
Winson | 196e861 | 2016-03-15 15:20:17 -0700 | [diff] [blame] | 273 | showEmptyView(R.string.recents_empty_message); |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 274 | } |
Winson Chung | 19fc117 | 2014-07-31 18:40:03 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 277 | /** |
Lucas Dupin | ae90ba8 | 2017-06-16 16:45:59 -0700 | [diff] [blame] | 278 | * Animates the scrim opacity based on how many tasks are visible. |
| 279 | * Called from {@link RecentsActivity} when tasks are dismissed. |
| 280 | */ |
| 281 | public void updateScrimOpacity() { |
| 282 | if (updateBusyness()) { |
| 283 | animateBackgroundScrim(getOpaqueScrimAlpha(), DEFAULT_UPDATE_SCRIM_DURATION); |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | /** |
| 288 | * Updates the busyness factor. |
| 289 | * |
| 290 | * @return True if it changed. |
| 291 | */ |
| 292 | private boolean updateBusyness() { |
| 293 | final int taskCount = mTaskStackView.getStack().getStackTaskCount(); |
| 294 | final float busyness = Math.min(taskCount, BUSY_RECENTS_TASK_COUNT) |
| 295 | / (float) BUSY_RECENTS_TASK_COUNT; |
| 296 | if (mBusynessFactor == busyness) { |
| 297 | return false; |
| 298 | } else { |
| 299 | mBusynessFactor = busyness; |
| 300 | return true; |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | /** |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 305 | * Returns the current TaskStack. |
| 306 | */ |
| 307 | public TaskStack getStack() { |
Matthew Ng | b7164cd | 2016-10-25 17:06:26 -0700 | [diff] [blame] | 308 | return mTaskStackView.getStack(); |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Lucas Dupin | ae90ba8 | 2017-06-16 16:45:59 -0700 | [diff] [blame] | 311 | /** |
Winson | e8a4eff | 2016-03-28 16:20:35 -0700 | [diff] [blame] | 312 | * Returns the window background scrim. |
| 313 | */ |
Winson Chung | d45aac4 | 2017-08-17 17:15:31 -0700 | [diff] [blame] | 314 | public void updateBackgroundScrim(Window window, boolean isInMultiWindow) { |
| 315 | if (isInMultiWindow) { |
| 316 | mBackgroundScrim.setCallback(null); |
| 317 | window.setBackgroundDrawable(mMultiWindowBackgroundScrim); |
| 318 | } else { |
| 319 | mMultiWindowBackgroundScrim.setCallback(null); |
| 320 | window.setBackgroundDrawable(mBackgroundScrim); |
| 321 | } |
Winson | e8a4eff | 2016-03-28 16:20:35 -0700 | [diff] [blame] | 322 | } |
| 323 | |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 324 | /** |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 325 | * Returns whether the last task launched was in the freeform stack or not. |
| 326 | */ |
| 327 | public boolean isLastTaskLaunchedFreeform() { |
| 328 | return mLastTaskLaunchedWasFreeform; |
| 329 | } |
| 330 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 331 | /** Launches the focused task from the first stack if possible */ |
Winson | 4232952 | 2016-02-05 10:39:46 -0800 | [diff] [blame] | 332 | public boolean launchFocusedTask(int logEvent) { |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 333 | if (mTaskStackView != null) { |
Winson | 142af42 | 2015-11-09 10:39:57 -0800 | [diff] [blame] | 334 | Task task = mTaskStackView.getFocusedTask(); |
| 335 | if (task != null) { |
| 336 | TaskView taskView = mTaskStackView.getChildViewForTask(task); |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 337 | EventBus.getDefault().send(new LaunchTaskEvent(taskView, task, null, |
| 338 | INVALID_STACK_ID, false)); |
Winson | 4232952 | 2016-02-05 10:39:46 -0800 | [diff] [blame] | 339 | |
| 340 | if (logEvent != 0) { |
| 341 | MetricsLogger.action(getContext(), logEvent, |
| 342 | task.key.getComponent().toString()); |
| 343 | } |
Winson | 142af42 | 2015-11-09 10:39:57 -0800 | [diff] [blame] | 344 | return true; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 345 | } |
| 346 | } |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 347 | return false; |
| 348 | } |
| 349 | |
Winson | a0731a1 | 2015-12-02 15:10:14 -0800 | [diff] [blame] | 350 | /** Launches the task that recents was launched from if possible */ |
| 351 | public boolean launchPreviousTask() { |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 352 | if (Recents.getConfiguration().getLaunchState().launchedFromPipApp) { |
| 353 | // If the app auto-entered PiP on the way to Recents, then just re-expand it |
| 354 | EventBus.getDefault().send(new ExpandPipEvent()); |
| 355 | return true; |
| 356 | } |
| 357 | |
Winson | a0731a1 | 2015-12-02 15:10:14 -0800 | [diff] [blame] | 358 | if (mTaskStackView != null) { |
Matthew Ng | b7164cd | 2016-10-25 17:06:26 -0700 | [diff] [blame] | 359 | Task task = getStack().getLaunchTarget(); |
Winson | a0731a1 | 2015-12-02 15:10:14 -0800 | [diff] [blame] | 360 | if (task != null) { |
| 361 | TaskView taskView = mTaskStackView.getChildViewForTask(task); |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 362 | EventBus.getDefault().send(new LaunchTaskEvent(taskView, task, null, |
| 363 | INVALID_STACK_ID, false)); |
Winson | a0731a1 | 2015-12-02 15:10:14 -0800 | [diff] [blame] | 364 | return true; |
| 365 | } |
| 366 | } |
| 367 | return false; |
| 368 | } |
| 369 | |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 370 | /** Launches a given task. */ |
Filip Gruszczynski | f48b585 | 2015-10-13 10:28:22 -0700 | [diff] [blame] | 371 | public boolean launchTask(Task task, Rect taskBounds, int destinationStack) { |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 372 | if (mTaskStackView != null) { |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 373 | // Iterate the stack views and try and find the given task. |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 374 | List<TaskView> taskViews = mTaskStackView.getTaskViews(); |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 375 | int taskViewCount = taskViews.size(); |
| 376 | for (int j = 0; j < taskViewCount; j++) { |
| 377 | TaskView tv = taskViews.get(j); |
| 378 | if (tv.getTask() == task) { |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 379 | EventBus.getDefault().send(new LaunchTaskEvent(tv, task, taskBounds, |
| 380 | destinationStack, false)); |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 381 | return true; |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | return false; |
| 386 | } |
| 387 | |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 388 | /** |
| 389 | * Hides the task stack and shows the empty view. |
| 390 | */ |
Winson | 196e861 | 2016-03-15 15:20:17 -0700 | [diff] [blame] | 391 | public void showEmptyView(int msgResId) { |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 392 | mTaskStackView.setVisibility(View.INVISIBLE); |
Winson | 196e861 | 2016-03-15 15:20:17 -0700 | [diff] [blame] | 393 | mEmptyView.setText(msgResId); |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 394 | mEmptyView.setVisibility(View.VISIBLE); |
| 395 | mEmptyView.bringToFront(); |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 396 | if (RecentsDebugFlags.Static.EnableStackActionButton) { |
| 397 | mStackActionButton.bringToFront(); |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 398 | } |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | /** |
| 402 | * Shows the task stack and hides the empty view. |
| 403 | */ |
| 404 | public void hideEmptyView() { |
| 405 | mEmptyView.setVisibility(View.INVISIBLE); |
| 406 | mTaskStackView.setVisibility(View.VISIBLE); |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 407 | mTaskStackView.bringToFront(); |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 408 | if (RecentsDebugFlags.Static.EnableStackActionButton) { |
| 409 | mStackActionButton.bringToFront(); |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 410 | } |
Winson Chung | 772b6b1 | 2014-07-03 15:54:02 -0700 | [diff] [blame] | 411 | } |
| 412 | |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 413 | /** |
| 414 | * Set the color of the scrim. |
| 415 | * |
| 416 | * @param scrimColors Colors to use. |
| 417 | * @param animated Interpolate colors if true. |
| 418 | */ |
| 419 | public void setScrimColors(ColorExtractor.GradientColors scrimColors, boolean animated) { |
| 420 | mBackgroundScrim.setColors(scrimColors, animated); |
Winson Chung | d45aac4 | 2017-08-17 17:15:31 -0700 | [diff] [blame] | 421 | int alpha = mMultiWindowBackgroundScrim.getAlpha(); |
| 422 | mMultiWindowBackgroundScrim.setColor(scrimColors.getMainColor()); |
| 423 | mMultiWindowBackgroundScrim.setAlpha(alpha); |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 424 | } |
| 425 | |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 426 | @Override |
| 427 | protected void onAttachedToWindow() { |
| 428 | EventBus.getDefault().register(this, RecentsActivity.EVENT_BUS_PRIORITY + 1); |
Winson | c8a4cdc | 2016-01-19 11:30:51 -0800 | [diff] [blame] | 429 | EventBus.getDefault().register(mTouchHandler, RecentsActivity.EVENT_BUS_PRIORITY + 2); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 430 | super.onAttachedToWindow(); |
| 431 | } |
| 432 | |
| 433 | @Override |
| 434 | protected void onDetachedFromWindow() { |
| 435 | super.onDetachedFromWindow(); |
| 436 | EventBus.getDefault().unregister(this); |
| 437 | EventBus.getDefault().unregister(mTouchHandler); |
| 438 | } |
| 439 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 440 | /** |
| 441 | * This is called with the full size of the window since we are handling our own insets. |
| 442 | */ |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 443 | @Override |
| 444 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 445 | int width = MeasureSpec.getSize(widthMeasureSpec); |
| 446 | int height = MeasureSpec.getSize(heightMeasureSpec); |
Winson Chung | bd91297 | 2014-03-18 14:36:35 -0700 | [diff] [blame] | 447 | |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 448 | if (mTaskStackView.getVisibility() != GONE) { |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 449 | mTaskStackView.measure(widthMeasureSpec, heightMeasureSpec); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 450 | } |
| 451 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 452 | // Measure the empty view to the full size of the screen |
| 453 | if (mEmptyView.getVisibility() != GONE) { |
Winson | 196e861 | 2016-03-15 15:20:17 -0700 | [diff] [blame] | 454 | measureChild(mEmptyView, MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST), |
| 455 | MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST)); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 456 | } |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 457 | |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 458 | if (RecentsDebugFlags.Static.EnableStackActionButton) { |
| 459 | // Measure the stack action button within the constraints of the space above the stack |
Jiaquan He | 26f637b | 2016-12-27 14:44:14 -0800 | [diff] [blame] | 460 | Rect buttonBounds = mTaskStackView.mLayoutAlgorithm.getStackActionButtonRect(); |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 461 | measureChild(mStackActionButton, |
Winson | 1985237 | 2016-03-30 18:26:49 -0700 | [diff] [blame] | 462 | MeasureSpec.makeMeasureSpec(buttonBounds.width(), MeasureSpec.AT_MOST), |
| 463 | MeasureSpec.makeMeasureSpec(buttonBounds.height(), MeasureSpec.AT_MOST)); |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 464 | } |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 465 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 466 | setMeasuredDimension(width, height); |
| 467 | } |
| 468 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 469 | /** |
| 470 | * This is called with the full size of the window since we are handling our own insets. |
| 471 | */ |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 472 | @Override |
| 473 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 474 | if (mTaskStackView.getVisibility() != GONE) { |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 475 | mTaskStackView.layout(left, top, left + getMeasuredWidth(), top + getMeasuredHeight()); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 476 | } |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 477 | |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 478 | // Layout the empty view |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 479 | if (mEmptyView.getVisibility() != GONE) { |
Winson | 196e861 | 2016-03-15 15:20:17 -0700 | [diff] [blame] | 480 | int leftRightInsets = mSystemInsets.left + mSystemInsets.right; |
| 481 | int topBottomInsets = mSystemInsets.top + mSystemInsets.bottom; |
| 482 | int childWidth = mEmptyView.getMeasuredWidth(); |
| 483 | int childHeight = mEmptyView.getMeasuredHeight(); |
Winson | 24251b6 | 2016-04-04 18:45:24 -0700 | [diff] [blame] | 484 | int childLeft = left + mSystemInsets.left + |
| 485 | Math.max(0, (right - left - leftRightInsets - childWidth)) / 2; |
| 486 | int childTop = top + mSystemInsets.top + |
| 487 | Math.max(0, (bottom - top - topBottomInsets - childHeight)) / 2; |
Winson | 196e861 | 2016-03-15 15:20:17 -0700 | [diff] [blame] | 488 | mEmptyView.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 489 | } |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 490 | |
Lucas Dupin | 6672fb4 | 2017-05-01 15:59:41 -0700 | [diff] [blame] | 491 | // Needs to know the screen size since the gradient never scales up or down |
| 492 | // even when bounds change. |
Winson Chung | d45aac4 | 2017-08-17 17:15:31 -0700 | [diff] [blame] | 493 | mContext.getDisplay().getRealSize(mTmpDisplaySize); |
| 494 | mBackgroundScrim.setScreenSize(mTmpDisplaySize.x, mTmpDisplaySize.y); |
Lucas Dupin | 6672fb4 | 2017-05-01 15:59:41 -0700 | [diff] [blame] | 495 | mBackgroundScrim.setBounds(left, top, right, bottom); |
Winson Chung | d45aac4 | 2017-08-17 17:15:31 -0700 | [diff] [blame] | 496 | mMultiWindowBackgroundScrim.setBounds(0, 0, mTmpDisplaySize.x, mTmpDisplaySize.y); |
Lucas Dupin | 6672fb4 | 2017-05-01 15:59:41 -0700 | [diff] [blame] | 497 | |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 498 | if (RecentsDebugFlags.Static.EnableStackActionButton) { |
| 499 | // Layout the stack action button such that its drawable is start-aligned with the |
| 500 | // stack, vertically centered in the available space above the stack |
Winson | 1985237 | 2016-03-30 18:26:49 -0700 | [diff] [blame] | 501 | Rect buttonBounds = getStackActionButtonBoundsFromStackLayout(); |
| 502 | mStackActionButton.layout(buttonBounds.left, buttonBounds.top, buttonBounds.right, |
| 503 | buttonBounds.bottom); |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 504 | } |
| 505 | |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 506 | if (mAwaitingFirstLayout) { |
| 507 | mAwaitingFirstLayout = false; |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 508 | // If launched via dragging from the nav bar, then we should translate the whole view |
| 509 | // down offscreen |
| 510 | RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState(); |
| 511 | if (launchState.launchedViaDragGesture) { |
| 512 | setTranslationY(getMeasuredHeight()); |
Jorim Jaggi | 0ca8826 | 2015-12-07 17:15:16 -0800 | [diff] [blame] | 513 | } else { |
| 514 | setTranslationY(0f); |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 515 | } |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 516 | |
| 517 | if (Recents.getConfiguration().isLowRamDevice |
| 518 | && mEmptyView.getVisibility() == View.VISIBLE) { |
| 519 | animateEmptyView(true /* show */, null /* postAnimationTrigger */); |
| 520 | } |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 521 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 522 | } |
| 523 | |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 524 | @Override |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 525 | public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 526 | mSystemInsets.set(insets.getSystemWindowInsets()); |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 527 | mTaskStackView.setSystemInsets(mSystemInsets); |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 528 | requestLayout(); |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 529 | return insets; |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 532 | @Override |
| 533 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
| 534 | return mTouchHandler.onInterceptTouchEvent(ev); |
| 535 | } |
| 536 | |
| 537 | @Override |
| 538 | public boolean onTouchEvent(MotionEvent ev) { |
| 539 | return mTouchHandler.onTouchEvent(ev); |
| 540 | } |
| 541 | |
| 542 | @Override |
Winson | be8e696 | 2016-02-01 14:27:52 -0800 | [diff] [blame] | 543 | public void onDrawForeground(Canvas canvas) { |
| 544 | super.onDrawForeground(canvas); |
| 545 | |
Winson | 036693c | 2016-01-14 17:16:06 -0800 | [diff] [blame] | 546 | ArrayList<TaskStack.DockState> visDockStates = mTouchHandler.getVisibleDockStates(); |
| 547 | for (int i = visDockStates.size() - 1; i >= 0; i--) { |
Winson | 99ef458 | 2016-04-18 16:57:27 -0700 | [diff] [blame] | 548 | visDockStates.get(i).viewState.draw(canvas); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 549 | } |
| 550 | } |
| 551 | |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 552 | @Override |
| 553 | protected boolean verifyDrawable(Drawable who) { |
Winson | 036693c | 2016-01-14 17:16:06 -0800 | [diff] [blame] | 554 | ArrayList<TaskStack.DockState> visDockStates = mTouchHandler.getVisibleDockStates(); |
| 555 | for (int i = visDockStates.size() - 1; i >= 0; i--) { |
| 556 | Drawable d = visDockStates.get(i).viewState.dockAreaOverlay; |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 557 | if (d == who) { |
| 558 | return true; |
| 559 | } |
| 560 | } |
| 561 | return super.verifyDrawable(who); |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 562 | } |
| 563 | |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 564 | /**** EventBus Events ****/ |
| 565 | |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 566 | public final void onBusEvent(LaunchTaskEvent event) { |
| 567 | mLastTaskLaunchedWasFreeform = event.task.isFreeformTask(); |
Matthew Ng | b7164cd | 2016-10-25 17:06:26 -0700 | [diff] [blame] | 568 | mTransitionHelper.launchTaskFromRecents(getStack(), event.task, mTaskStackView, |
Jorim Jaggi | cf4411d | 2017-05-12 17:27:46 +0200 | [diff] [blame] | 569 | event.taskView, event.screenPinningRequested, event.targetTaskStack); |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 570 | if (Recents.getConfiguration().isLowRamDevice) { |
| 571 | hideStackActionButton(HIDE_STACK_ACTION_BUTTON_DURATION, false /* translate */); |
| 572 | } |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 573 | } |
| 574 | |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 575 | public final void onBusEvent(DismissRecentsToHomeAnimationStarted event) { |
Winson | 5044863 | 2016-02-01 18:04:59 -0800 | [diff] [blame] | 576 | int taskViewExitToHomeDuration = TaskStackAnimationHelper.EXIT_TO_HOME_TRANSLATION_DURATION; |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 577 | if (RecentsDebugFlags.Static.EnableStackActionButton) { |
| 578 | // Hide the stack action button |
| 579 | hideStackActionButton(taskViewExitToHomeDuration, false /* translate */); |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 580 | } |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 581 | animateBackgroundScrim(0f, taskViewExitToHomeDuration); |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 582 | |
| 583 | if (Recents.getConfiguration().isLowRamDevice) { |
| 584 | animateEmptyView(false /* show */, event.getAnimationTrigger()); |
| 585 | } |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 586 | } |
| 587 | |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 588 | public final void onBusEvent(DragStartEvent event) { |
Matthew Ng | b7035f3 | 2017-01-19 11:04:50 -0800 | [diff] [blame] | 589 | updateVisibleDockRegions(Recents.getConfiguration().getDockStatesForCurrentOrientation(), |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 590 | true /* isDefaultDockState */, TaskStack.DockState.NONE.viewState.dockAreaAlpha, |
Winson | 99ef458 | 2016-04-18 16:57:27 -0700 | [diff] [blame] | 591 | TaskStack.DockState.NONE.viewState.hintTextAlpha, |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 592 | true /* animateAlpha */, false /* animateBounds */); |
Winson | b677bcb | 2016-04-18 16:58:33 -0700 | [diff] [blame] | 593 | |
| 594 | // Temporarily hide the stack action button without changing visibility |
| 595 | if (mStackActionButton != null) { |
| 596 | mStackActionButton.animate() |
| 597 | .alpha(0f) |
| 598 | .setDuration(HIDE_STACK_ACTION_BUTTON_DURATION) |
| 599 | .setInterpolator(Interpolators.ALPHA_OUT) |
| 600 | .start(); |
| 601 | } |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 602 | } |
| 603 | |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 604 | public final void onBusEvent(DragDropTargetChangedEvent event) { |
| 605 | if (event.dropTarget == null || !(event.dropTarget instanceof TaskStack.DockState)) { |
Matthew Ng | b7035f3 | 2017-01-19 11:04:50 -0800 | [diff] [blame] | 606 | updateVisibleDockRegions( |
| 607 | Recents.getConfiguration().getDockStatesForCurrentOrientation(), |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 608 | true /* isDefaultDockState */, TaskStack.DockState.NONE.viewState.dockAreaAlpha, |
Winson | 99ef458 | 2016-04-18 16:57:27 -0700 | [diff] [blame] | 609 | TaskStack.DockState.NONE.viewState.hintTextAlpha, |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 610 | true /* animateAlpha */, true /* animateBounds */); |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 611 | } else { |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 612 | final TaskStack.DockState dockState = (TaskStack.DockState) event.dropTarget; |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 613 | updateVisibleDockRegions(new TaskStack.DockState[] {dockState}, |
Winson | 99ef458 | 2016-04-18 16:57:27 -0700 | [diff] [blame] | 614 | false /* isDefaultDockState */, -1, -1, true /* animateAlpha */, |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 615 | true /* animateBounds */); |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 616 | } |
Winson | 1985237 | 2016-03-30 18:26:49 -0700 | [diff] [blame] | 617 | if (mStackActionButton != null) { |
| 618 | event.addPostAnimationCallback(new Runnable() { |
| 619 | @Override |
| 620 | public void run() { |
| 621 | // Move the clear all button to its new position |
| 622 | Rect buttonBounds = getStackActionButtonBoundsFromStackLayout(); |
| 623 | mStackActionButton.setLeftTopRightBottom(buttonBounds.left, buttonBounds.top, |
| 624 | buttonBounds.right, buttonBounds.bottom); |
| 625 | } |
| 626 | }); |
| 627 | } |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | public final void onBusEvent(final DragEndEvent event) { |
Winson | 479f744 | 2015-11-25 15:16:27 -0800 | [diff] [blame] | 631 | // Handle the case where we drop onto a dock region |
| 632 | if (event.dropTarget instanceof TaskStack.DockState) { |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 633 | final TaskStack.DockState dockState = (TaskStack.DockState) event.dropTarget; |
| 634 | |
| 635 | // Hide the dock region |
Winson | 99ef458 | 2016-04-18 16:57:27 -0700 | [diff] [blame] | 636 | updateVisibleDockRegions(null, false /* isDefaultDockState */, -1, -1, |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 637 | false /* animateAlpha */, false /* animateBounds */); |
| 638 | |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 639 | // We translated the view but we need to animate it back from the current layout-space |
| 640 | // rect to its final layout-space rect |
Winson | 27c28f8 | 2016-05-05 16:16:50 -0700 | [diff] [blame] | 641 | Utilities.setViewFrameFromTranslation(event.taskView); |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 642 | |
| 643 | // Dock the task and launch it |
| 644 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Winson | 27c28f8 | 2016-05-05 16:16:50 -0700 | [diff] [blame] | 645 | if (ssp.startTaskInDockedMode(event.task.key.id, dockState.createMode)) { |
| 646 | final OnAnimationStartedListener startedListener = |
| 647 | new OnAnimationStartedListener() { |
| 648 | @Override |
| 649 | public void onAnimationStarted() { |
| 650 | EventBus.getDefault().send(new DockedFirstAnimationFrameEvent()); |
| 651 | // Remove the task and don't bother relaying out, as all the tasks will be |
| 652 | // relaid out when the stack changes on the multiwindow change event |
Matthew Ng | b7164cd | 2016-10-25 17:06:26 -0700 | [diff] [blame] | 653 | getStack().removeTask(event.task, null, true /* fromDockGesture */); |
Winson | 27c28f8 | 2016-05-05 16:16:50 -0700 | [diff] [blame] | 654 | } |
| 655 | }; |
Winson | a0a8ae4 | 2015-12-01 10:43:02 -0800 | [diff] [blame] | 656 | |
Winson | 27c28f8 | 2016-05-05 16:16:50 -0700 | [diff] [blame] | 657 | final Rect taskRect = getTaskRect(event.taskView); |
Jorim Jaggi | cf4411d | 2017-05-12 17:27:46 +0200 | [diff] [blame] | 658 | AppTransitionAnimationSpecsFuture future = |
Winson | 27c28f8 | 2016-05-05 16:16:50 -0700 | [diff] [blame] | 659 | mTransitionHelper.getAppTransitionFuture( |
| 660 | new AnimationSpecComposer() { |
| 661 | @Override |
| 662 | public List<AppTransitionAnimationSpec> composeSpecs() { |
| 663 | return mTransitionHelper.composeDockAnimationSpec( |
| 664 | event.taskView, taskRect); |
| 665 | } |
| 666 | }); |
Jorim Jaggi | cf4411d | 2017-05-12 17:27:46 +0200 | [diff] [blame] | 667 | ssp.overridePendingAppTransitionMultiThumbFuture(future.getFuture(), |
Winson | 27c28f8 | 2016-05-05 16:16:50 -0700 | [diff] [blame] | 668 | mTransitionHelper.wrapStartedListener(startedListener), |
| 669 | true /* scaleUp */); |
| 670 | |
| 671 | MetricsLogger.action(mContext, MetricsEvent.ACTION_WINDOW_DOCK_DRAG_DROP, |
| 672 | event.task.getTopComponent().flattenToShortString()); |
| 673 | } else { |
Matthew Ng | b7164cd | 2016-10-25 17:06:26 -0700 | [diff] [blame] | 674 | EventBus.getDefault().send(new DragEndCancelledEvent(getStack(), event.task, |
Winson | 27c28f8 | 2016-05-05 16:16:50 -0700 | [diff] [blame] | 675 | event.taskView)); |
| 676 | } |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 677 | } else { |
| 678 | // Animate the overlay alpha back to 0 |
Winson | 99ef458 | 2016-04-18 16:57:27 -0700 | [diff] [blame] | 679 | updateVisibleDockRegions(null, true /* isDefaultDockState */, -1, -1, |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 680 | true /* animateAlpha */, false /* animateBounds */); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 681 | } |
Winson | b677bcb | 2016-04-18 16:58:33 -0700 | [diff] [blame] | 682 | |
| 683 | // Show the stack action button again without changing visibility |
| 684 | if (mStackActionButton != null) { |
| 685 | mStackActionButton.animate() |
| 686 | .alpha(1f) |
| 687 | .setDuration(SHOW_STACK_ACTION_BUTTON_DURATION) |
| 688 | .setInterpolator(Interpolators.ALPHA_IN) |
| 689 | .start(); |
| 690 | } |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 691 | } |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 692 | |
Winson | 27c28f8 | 2016-05-05 16:16:50 -0700 | [diff] [blame] | 693 | public final void onBusEvent(final DragEndCancelledEvent event) { |
| 694 | // Animate the overlay alpha back to 0 |
| 695 | updateVisibleDockRegions(null, true /* isDefaultDockState */, -1, -1, |
| 696 | true /* animateAlpha */, false /* animateBounds */); |
| 697 | } |
| 698 | |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 699 | private Rect getTaskRect(TaskView taskView) { |
| 700 | int[] location = taskView.getLocationOnScreen(); |
| 701 | int viewX = location[0]; |
| 702 | int viewY = location[1]; |
| 703 | return new Rect(viewX, viewY, |
| 704 | (int) (viewX + taskView.getWidth() * taskView.getScaleX()), |
| 705 | (int) (viewY + taskView.getHeight() * taskView.getScaleY())); |
| 706 | } |
| 707 | |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 708 | public final void onBusEvent(DraggingInRecentsEvent event) { |
Jorim Jaggi | 54b1a6d | 2015-11-24 17:48:26 -0800 | [diff] [blame] | 709 | if (mTaskStackView.getTaskViews().size() > 0) { |
| 710 | setTranslationY(event.distanceFromTop - mTaskStackView.getTaskViews().get(0).getY()); |
| 711 | } |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | public final void onBusEvent(DraggingInRecentsEndedEvent event) { |
Jorim Jaggi | 870ab5a | 2015-12-02 18:37:54 -0800 | [diff] [blame] | 715 | ViewPropertyAnimator animator = animate(); |
Jorim Jaggi | 8fccfe2 | 2015-12-03 16:58:08 -0800 | [diff] [blame] | 716 | if (event.velocity > mFlingAnimationUtils.getMinVelocityPxPerSecond()) { |
Jorim Jaggi | 870ab5a | 2015-12-02 18:37:54 -0800 | [diff] [blame] | 717 | animator.translationY(getHeight()); |
| 718 | animator.withEndAction(new Runnable() { |
| 719 | @Override |
| 720 | public void run() { |
| 721 | WindowManagerProxy.getInstance().maximizeDockedStack(); |
| 722 | } |
| 723 | }); |
| 724 | mFlingAnimationUtils.apply(animator, getTranslationY(), getHeight(), event.velocity); |
| 725 | } else { |
| 726 | animator.translationY(0f); |
| 727 | animator.setListener(null); |
| 728 | mFlingAnimationUtils.apply(animator, getTranslationY(), 0, event.velocity); |
| 729 | } |
| 730 | animator.start(); |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 731 | } |
| 732 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 733 | public final void onBusEvent(EnterRecentsWindowAnimationCompletedEvent event) { |
| 734 | RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState(); |
Winson | c69249f | 2016-03-28 13:38:39 -0700 | [diff] [blame] | 735 | if (!launchState.launchedViaDockGesture && !launchState.launchedFromApp |
Matthew Ng | b7164cd | 2016-10-25 17:06:26 -0700 | [diff] [blame] | 736 | && getStack().getTaskCount() > 0) { |
Lucas Dupin | ae90ba8 | 2017-06-16 16:45:59 -0700 | [diff] [blame] | 737 | animateBackgroundScrim(getOpaqueScrimAlpha(), |
Winson | 5044863 | 2016-02-01 18:04:59 -0800 | [diff] [blame] | 738 | TaskStackAnimationHelper.ENTER_FROM_HOME_TRANSLATION_DURATION); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 739 | } |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 740 | if (Recents.getConfiguration().isLowRamDevice && mEmptyView.getVisibility() != View.VISIBLE) { |
| 741 | showStackActionButton(SHOW_STACK_ACTION_BUTTON_DURATION, false /* translate */); |
| 742 | } |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 743 | } |
| 744 | |
Winson | 3b6ba1a | 2016-03-22 15:37:54 -0700 | [diff] [blame] | 745 | public final void onBusEvent(AllTaskViewsDismissedEvent event) { |
| 746 | hideStackActionButton(HIDE_STACK_ACTION_BUTTON_DURATION, true /* translate */); |
| 747 | } |
| 748 | |
| 749 | public final void onBusEvent(DismissAllTaskViewsEvent event) { |
| 750 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 751 | if (!ssp.hasDockedTask()) { |
| 752 | // Animate the background away only if we are dismissing Recents to home |
| 753 | animateBackgroundScrim(0f, DEFAULT_UPDATE_SCRIM_DURATION); |
| 754 | } |
| 755 | } |
| 756 | |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 757 | public final void onBusEvent(ShowStackActionButtonEvent event) { |
| 758 | if (!RecentsDebugFlags.Static.EnableStackActionButton) { |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 759 | return; |
| 760 | } |
| 761 | |
Winson | 3b6ba1a | 2016-03-22 15:37:54 -0700 | [diff] [blame] | 762 | showStackActionButton(SHOW_STACK_ACTION_BUTTON_DURATION, event.translate); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 763 | } |
| 764 | |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 765 | public final void onBusEvent(HideStackActionButtonEvent event) { |
| 766 | if (!RecentsDebugFlags.Static.EnableStackActionButton) { |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 767 | return; |
| 768 | } |
| 769 | |
Winson | 3b6ba1a | 2016-03-22 15:37:54 -0700 | [diff] [blame] | 770 | hideStackActionButton(HIDE_STACK_ACTION_BUTTON_DURATION, true /* translate */); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 771 | } |
| 772 | |
Winson | d2a0306 | 2016-04-15 11:19:07 -0700 | [diff] [blame] | 773 | public final void onBusEvent(MultiWindowStateChangedEvent event) { |
| 774 | updateStack(event.stack, false /* setStackViewTasks */); |
| 775 | } |
| 776 | |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 777 | public final void onBusEvent(ShowEmptyViewEvent event) { |
| 778 | showEmptyView(R.string.recents_empty_message); |
| 779 | } |
| 780 | |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 781 | /** |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 782 | * Shows the stack action button. |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 783 | */ |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 784 | private void showStackActionButton(final int duration, final boolean translate) { |
| 785 | if (!RecentsDebugFlags.Static.EnableStackActionButton) { |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 786 | return; |
| 787 | } |
| 788 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 789 | final ReferenceCountedTrigger postAnimationTrigger = new ReferenceCountedTrigger(); |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 790 | if (mStackActionButton.getVisibility() == View.INVISIBLE) { |
| 791 | mStackActionButton.setVisibility(View.VISIBLE); |
| 792 | mStackActionButton.setAlpha(0f); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 793 | if (translate) { |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 794 | mStackActionButton.setTranslationY(-mStackActionButton.getMeasuredHeight() * 0.25f); |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 795 | } else { |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 796 | mStackActionButton.setTranslationY(0f); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 797 | } |
| 798 | postAnimationTrigger.addLastDecrementRunnable(new Runnable() { |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 799 | @Override |
| 800 | public void run() { |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 801 | if (translate) { |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 802 | mStackActionButton.animate() |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 803 | .translationY(0f); |
| 804 | } |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 805 | mStackActionButton.animate() |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 806 | .alpha(1f) |
| 807 | .setDuration(duration) |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 808 | .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 809 | .start(); |
| 810 | } |
| 811 | }); |
| 812 | } |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 813 | postAnimationTrigger.flushLastDecrementRunnables(); |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | /** |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 817 | * Hides the stack action button. |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 818 | */ |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 819 | private void hideStackActionButton(int duration, boolean translate) { |
| 820 | if (!RecentsDebugFlags.Static.EnableStackActionButton) { |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 821 | return; |
| 822 | } |
| 823 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 824 | final ReferenceCountedTrigger postAnimationTrigger = new ReferenceCountedTrigger(); |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 825 | hideStackActionButton(duration, translate, postAnimationTrigger); |
Winson Chung | aaeaac1 | 2015-12-16 16:49:36 -0500 | [diff] [blame] | 826 | postAnimationTrigger.flushLastDecrementRunnables(); |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 827 | } |
| 828 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 829 | /** |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 830 | * Hides the stack action button. |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 831 | */ |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 832 | private void hideStackActionButton(int duration, boolean translate, |
| 833 | final ReferenceCountedTrigger postAnimationTrigger) { |
| 834 | if (!RecentsDebugFlags.Static.EnableStackActionButton) { |
Winson | 91b225d | 2016-02-16 15:18:07 -0800 | [diff] [blame] | 835 | return; |
| 836 | } |
| 837 | |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 838 | if (mStackActionButton.getVisibility() == View.VISIBLE) { |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 839 | if (translate) { |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 840 | mStackActionButton.animate() |
| 841 | .translationY(-mStackActionButton.getMeasuredHeight() * 0.25f); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 842 | } |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 843 | mStackActionButton.animate() |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 844 | .alpha(0f) |
| 845 | .setDuration(duration) |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 846 | .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 847 | .withEndAction(new Runnable() { |
| 848 | @Override |
| 849 | public void run() { |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 850 | mStackActionButton.setVisibility(View.INVISIBLE); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 851 | postAnimationTrigger.decrement(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 852 | } |
| 853 | }) |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 854 | .start(); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 855 | postAnimationTrigger.increment(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 856 | } |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 857 | } |
| 858 | |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 859 | /** |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 860 | * Animates a translation in the Y direction and fades in/out for empty view to show or hide it. |
| 861 | * @param show whether to translate up and fade in the empty view to the center of the screen |
| 862 | * @param postAnimationTrigger to keep track of the animation |
| 863 | */ |
| 864 | private void animateEmptyView(boolean show, ReferenceCountedTrigger postAnimationTrigger) { |
| 865 | float start = mTaskStackView.getStackAlgorithm().getTaskRect().height() / 4; |
| 866 | mEmptyView.setTranslationY(show ? start : 0); |
| 867 | mEmptyView.setAlpha(show ? 0f : 1f); |
| 868 | ViewPropertyAnimator animator = mEmptyView.animate() |
| 869 | .setDuration(150) |
| 870 | .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) |
| 871 | .translationY(show ? 0 : start) |
| 872 | .alpha(show ? 1f : 0f); |
| 873 | |
| 874 | if (postAnimationTrigger != null) { |
| 875 | animator.setListener(postAnimationTrigger.decrementOnAnimationEnd()); |
| 876 | postAnimationTrigger.increment(); |
| 877 | } |
| 878 | animator.start(); |
| 879 | } |
| 880 | |
| 881 | /** |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 882 | * Updates the dock region to match the specified dock state. |
| 883 | */ |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 884 | private void updateVisibleDockRegions(TaskStack.DockState[] newDockStates, |
Winson | 99ef458 | 2016-04-18 16:57:27 -0700 | [diff] [blame] | 885 | boolean isDefaultDockState, int overrideAreaAlpha, int overrideHintAlpha, |
| 886 | boolean animateAlpha, boolean animateBounds) { |
Winson | c5fd350 | 2016-01-18 15:18:37 -0800 | [diff] [blame] | 887 | ArraySet<TaskStack.DockState> newDockStatesSet = Utilities.arrayToSet(newDockStates, |
| 888 | new ArraySet<TaskStack.DockState>()); |
Winson | 036693c | 2016-01-14 17:16:06 -0800 | [diff] [blame] | 889 | ArrayList<TaskStack.DockState> visDockStates = mTouchHandler.getVisibleDockStates(); |
| 890 | for (int i = visDockStates.size() - 1; i >= 0; i--) { |
| 891 | TaskStack.DockState dockState = visDockStates.get(i); |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 892 | TaskStack.DockState.ViewState viewState = dockState.viewState; |
| 893 | if (newDockStates == null || !newDockStatesSet.contains(dockState)) { |
| 894 | // This is no longer visible, so hide it |
Winson | 3f32e7e | 2016-04-20 17:18:08 -0700 | [diff] [blame] | 895 | viewState.startAnimation(null, 0, 0, TaskStackView.SLOW_SYNC_STACK_DURATION, |
| 896 | Interpolators.FAST_OUT_SLOW_IN, animateAlpha, animateBounds); |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 897 | } else { |
| 898 | // This state is now visible, update the bounds and show it |
Winson | 99ef458 | 2016-04-18 16:57:27 -0700 | [diff] [blame] | 899 | int areaAlpha = overrideAreaAlpha != -1 |
| 900 | ? overrideAreaAlpha |
| 901 | : viewState.dockAreaAlpha; |
| 902 | int hintAlpha = overrideHintAlpha != -1 |
| 903 | ? overrideHintAlpha |
| 904 | : viewState.hintTextAlpha; |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 905 | Rect bounds = isDefaultDockState |
Winson | 08deff0 | 2016-08-05 13:58:31 -0700 | [diff] [blame] | 906 | ? dockState.getPreDockedBounds(getMeasuredWidth(), getMeasuredHeight(), |
| 907 | mSystemInsets) |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 908 | : dockState.getDockedBounds(getMeasuredWidth(), getMeasuredHeight(), |
Winson | 08deff0 | 2016-08-05 13:58:31 -0700 | [diff] [blame] | 909 | mDividerSize, mSystemInsets, getResources()); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 910 | if (viewState.dockAreaOverlay.getCallback() != this) { |
| 911 | viewState.dockAreaOverlay.setCallback(this); |
| 912 | viewState.dockAreaOverlay.setBounds(bounds); |
| 913 | } |
Winson | b677bcb | 2016-04-18 16:58:33 -0700 | [diff] [blame] | 914 | viewState.startAnimation(bounds, areaAlpha, hintAlpha, |
Winson | 3f32e7e | 2016-04-20 17:18:08 -0700 | [diff] [blame] | 915 | TaskStackView.SLOW_SYNC_STACK_DURATION, Interpolators.FAST_OUT_SLOW_IN, |
Winson | b677bcb | 2016-04-18 16:58:33 -0700 | [diff] [blame] | 916 | animateAlpha, animateBounds); |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 917 | } |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 918 | } |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 919 | } |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 920 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 921 | /** |
Lucas Dupin | ae90ba8 | 2017-06-16 16:45:59 -0700 | [diff] [blame] | 922 | * Scrim alpha based on how busy recents is: |
| 923 | * Scrim will be {@link ScrimController#GRADIENT_SCRIM_ALPHA} when the stack is empty, |
| 924 | * and {@link ScrimController#GRADIENT_SCRIM_ALPHA_BUSY} when it's full. |
| 925 | * |
| 926 | * @return Alpha from 0 to 1. |
| 927 | */ |
| 928 | private float getOpaqueScrimAlpha() { |
| 929 | return MathUtils.map(0, 1, ScrimController.GRADIENT_SCRIM_ALPHA, |
| 930 | ScrimController.GRADIENT_SCRIM_ALPHA_BUSY, mBusynessFactor); |
| 931 | } |
| 932 | |
| 933 | /** |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 934 | * Animates the background scrim to the given {@param alpha}. |
| 935 | */ |
| 936 | private void animateBackgroundScrim(float alpha, int duration) { |
| 937 | Utilities.cancelAnimationWithoutCallbacks(mBackgroundScrimAnimator); |
Winson | 47c78f9 | 2016-03-31 16:02:30 -0700 | [diff] [blame] | 938 | // Calculate the absolute alpha to animate from |
Lucas Dupin | ae90ba8 | 2017-06-16 16:45:59 -0700 | [diff] [blame] | 939 | final int fromAlpha = mBackgroundScrim.getAlpha(); |
| 940 | final int toAlpha = (int) (alpha * 255); |
Winson Chung | d45aac4 | 2017-08-17 17:15:31 -0700 | [diff] [blame] | 941 | mBackgroundScrimAnimator = ValueAnimator.ofInt(fromAlpha, toAlpha); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 942 | mBackgroundScrimAnimator.setDuration(duration); |
Winson | 47c78f9 | 2016-03-31 16:02:30 -0700 | [diff] [blame] | 943 | mBackgroundScrimAnimator.setInterpolator(toAlpha > fromAlpha |
| 944 | ? Interpolators.ALPHA_IN |
| 945 | : Interpolators.ALPHA_OUT); |
Winson Chung | d45aac4 | 2017-08-17 17:15:31 -0700 | [diff] [blame] | 946 | mBackgroundScrimAnimator.addUpdateListener(mUpdateBackgroundScrimAlpha); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 947 | mBackgroundScrimAnimator.start(); |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 948 | } |
Winson | 1985237 | 2016-03-30 18:26:49 -0700 | [diff] [blame] | 949 | |
| 950 | /** |
| 951 | * @return the bounds of the stack action button. |
| 952 | */ |
| 953 | private Rect getStackActionButtonBoundsFromStackLayout() { |
Jiaquan He | 26f637b | 2016-12-27 14:44:14 -0800 | [diff] [blame] | 954 | Rect actionButtonRect = new Rect(mTaskStackView.mLayoutAlgorithm.getStackActionButtonRect()); |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 955 | int left, top; |
| 956 | if (Recents.getConfiguration().isLowRamDevice) { |
| 957 | Rect windowRect = Recents.getSystemServices().getWindowRect(); |
| 958 | left = (windowRect.width() - mSystemInsets.left - mSystemInsets.right |
| 959 | - mStackActionButton.getMeasuredWidth()) / 2; |
| 960 | top = windowRect.height() - (mStackActionButton.getMeasuredHeight() |
| 961 | + mSystemInsets.bottom + mStackActionButton.getPaddingBottom() / 2); |
| 962 | } else { |
| 963 | left = isLayoutRtl() |
Winson | 1985237 | 2016-03-30 18:26:49 -0700 | [diff] [blame] | 964 | ? actionButtonRect.left - mStackActionButton.getPaddingLeft() |
| 965 | : actionButtonRect.right + mStackActionButton.getPaddingRight() |
Winson | 47c78f9 | 2016-03-31 16:02:30 -0700 | [diff] [blame] | 966 | - mStackActionButton.getMeasuredWidth(); |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 967 | top = actionButtonRect.top + |
Winson | 1985237 | 2016-03-30 18:26:49 -0700 | [diff] [blame] | 968 | (actionButtonRect.height() - mStackActionButton.getMeasuredHeight()) / 2; |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 969 | } |
Winson | 47c78f9 | 2016-03-31 16:02:30 -0700 | [diff] [blame] | 970 | actionButtonRect.set(left, top, left + mStackActionButton.getMeasuredWidth(), |
| 971 | top + mStackActionButton.getMeasuredHeight()); |
Winson | 1985237 | 2016-03-30 18:26:49 -0700 | [diff] [blame] | 972 | return actionButtonRect; |
| 973 | } |
Winson | d72c315 | 2016-04-05 15:33:35 -0700 | [diff] [blame] | 974 | |
| 975 | public void dump(String prefix, PrintWriter writer) { |
| 976 | String innerPrefix = prefix + " "; |
| 977 | String id = Integer.toHexString(System.identityHashCode(this)); |
| 978 | |
| 979 | writer.print(prefix); writer.print(TAG); |
| 980 | writer.print(" awaitingFirstLayout="); writer.print(mAwaitingFirstLayout ? "Y" : "N"); |
| 981 | writer.print(" insets="); writer.print(Utilities.dumpRect(mSystemInsets)); |
| 982 | writer.print(" [0x"); writer.print(id); writer.print("]"); |
| 983 | writer.println(); |
| 984 | |
Matthew Ng | b7164cd | 2016-10-25 17:06:26 -0700 | [diff] [blame] | 985 | if (getStack() != null) { |
| 986 | getStack().dump(innerPrefix, writer); |
Winson | d72c315 | 2016-04-05 15:33:35 -0700 | [diff] [blame] | 987 | } |
| 988 | if (mTaskStackView != null) { |
| 989 | mTaskStackView.dump(innerPrefix, writer); |
| 990 | } |
| 991 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 992 | } |