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 | 70f0bf7 | 2016-02-01 14:05:29 -0800 | [diff] [blame] | 19 | import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; |
| 20 | import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID; |
| 21 | import static android.app.ActivityManager.StackId.INVALID_STACK_ID; |
| 22 | |
Manu Cornet | 551e80c | 2017-02-10 12:54:40 -0800 | [diff] [blame] | 23 | import android.animation.Animator; |
| 24 | import android.animation.AnimatorListenerAdapter; |
Winson | a78a8f3 | 2015-12-03 10:55:01 -0800 | [diff] [blame] | 25 | import android.animation.ObjectAnimator; |
Winson Chung | bf5dbf1 | 2014-09-16 00:58:25 +0200 | [diff] [blame] | 26 | import android.animation.ValueAnimator; |
Winson | 619e40c | 2016-03-25 16:12:35 -0700 | [diff] [blame] | 27 | import android.annotation.IntDef; |
Winson Chung | 9f49df9 | 2014-05-07 18:08:34 -0700 | [diff] [blame] | 28 | import android.content.ComponentName; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 29 | import android.content.Context; |
Winson | fc48b07 | 2016-04-21 11:20:11 -0700 | [diff] [blame] | 30 | import android.content.res.Configuration; |
Winson | bb41095 | 2015-12-04 14:34:11 -0800 | [diff] [blame] | 31 | import android.content.res.Resources; |
Jorim Jaggi | 900fb48 | 2015-06-02 15:07:33 -0700 | [diff] [blame] | 32 | import android.graphics.Canvas; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 33 | import android.graphics.Rect; |
Winson | a78a8f3 | 2015-12-03 10:55:01 -0800 | [diff] [blame] | 34 | import android.graphics.drawable.Drawable; |
Winson | de0591a | 2015-12-04 17:24:35 -0800 | [diff] [blame] | 35 | import android.graphics.drawable.GradientDrawable; |
Winson Chung | 83ea6f7 | 2015-06-17 13:00:23 -0700 | [diff] [blame] | 36 | import android.os.Bundle; |
Winson Chung | 931c51f | 2015-12-17 17:08:55 -0500 | [diff] [blame] | 37 | import android.provider.Settings; |
Winson | 5500390 | 2016-01-12 12:00:37 -0800 | [diff] [blame] | 38 | import android.util.ArrayMap; |
| 39 | import android.util.ArraySet; |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 40 | import android.util.MutableBoolean; |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 41 | import android.view.LayoutInflater; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 42 | import android.view.MotionEvent; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 43 | import android.view.View; |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 44 | import android.view.ViewDebug; |
Winson | 70f0bf7 | 2016-02-01 14:05:29 -0800 | [diff] [blame] | 45 | import android.view.ViewGroup; |
Winson Chung | ee44595 | 2014-09-09 16:12:59 +0200 | [diff] [blame] | 46 | import android.view.accessibility.AccessibilityEvent; |
Winson Chung | 83ea6f7 | 2015-06-17 13:00:23 -0700 | [diff] [blame] | 47 | import android.view.accessibility.AccessibilityNodeInfo; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 48 | import android.widget.FrameLayout; |
Winson | f000988 | 2016-06-01 12:22:55 -0700 | [diff] [blame] | 49 | import android.widget.ScrollView; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 50 | |
Winson | 4232952 | 2016-02-05 10:39:46 -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; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 53 | import com.android.systemui.Interpolators; |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 54 | import com.android.systemui.R; |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 55 | import com.android.systemui.recents.Recents; |
Winson | e6c9073 | 2015-09-24 16:06:29 -0700 | [diff] [blame] | 56 | import com.android.systemui.recents.RecentsActivity; |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 57 | import com.android.systemui.recents.RecentsActivityLaunchState; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 58 | import com.android.systemui.recents.RecentsConfiguration; |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 59 | import com.android.systemui.recents.RecentsDebugFlags; |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 60 | import com.android.systemui.recents.RecentsImpl; |
Winson | e6c9073 | 2015-09-24 16:06:29 -0700 | [diff] [blame] | 61 | import com.android.systemui.recents.events.EventBus; |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 62 | import com.android.systemui.recents.events.activity.CancelEnterRecentsWindowAnimationEvent; |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 63 | import com.android.systemui.recents.events.activity.ConfigurationChangedEvent; |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 64 | import com.android.systemui.recents.events.activity.DismissRecentsToHomeAnimationStarted; |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 65 | import com.android.systemui.recents.events.activity.EnterRecentsTaskStackAnimationCompletedEvent; |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 66 | import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationCompletedEvent; |
Winson | bc0f8cd | 2016-03-15 15:44:48 -0700 | [diff] [blame] | 67 | import com.android.systemui.recents.events.activity.HideRecentsEvent; |
Winson | c69249f | 2016-03-28 13:38:39 -0700 | [diff] [blame] | 68 | import com.android.systemui.recents.events.activity.HideStackActionButtonEvent; |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 69 | import com.android.systemui.recents.events.activity.IterateRecentsEvent; |
Manu Cornet | a96a617 | 2017-01-19 12:40:44 -0800 | [diff] [blame] | 70 | import com.android.systemui.recents.events.activity.LaunchMostRecentTaskRequestEvent; |
Winson | b61e654 | 2016-02-04 14:37:18 -0800 | [diff] [blame] | 71 | import com.android.systemui.recents.events.activity.LaunchNextTaskRequestEvent; |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 72 | import com.android.systemui.recents.events.activity.LaunchTaskEvent; |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 73 | import com.android.systemui.recents.events.activity.LaunchTaskStartedEvent; |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 74 | import com.android.systemui.recents.events.activity.MultiWindowStateChangedEvent; |
Winson | e6c9073 | 2015-09-24 16:06:29 -0700 | [diff] [blame] | 75 | import com.android.systemui.recents.events.activity.PackagesChangedEvent; |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 76 | import com.android.systemui.recents.events.activity.ShowEmptyViewEvent; |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 77 | import com.android.systemui.recents.events.activity.ShowStackActionButtonEvent; |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 78 | import com.android.systemui.recents.events.component.ActivityPinnedEvent; |
| 79 | import com.android.systemui.recents.events.component.ExpandPipEvent; |
| 80 | import com.android.systemui.recents.events.component.HidePipMenuEvent; |
Jiaquan He | 21f495f | 2017-01-05 13:00:29 -0800 | [diff] [blame] | 81 | import com.android.systemui.recents.events.component.RecentsVisibilityChangedEvent; |
Winson | 397ae74 | 2015-11-20 11:27:33 -0800 | [diff] [blame] | 82 | import com.android.systemui.recents.events.ui.AllTaskViewsDismissedEvent; |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 83 | import com.android.systemui.recents.events.ui.DeleteTaskDataEvent; |
Winson | 3b6ba1a | 2016-03-22 15:37:54 -0700 | [diff] [blame] | 84 | import com.android.systemui.recents.events.ui.DismissAllTaskViewsEvent; |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 85 | import com.android.systemui.recents.events.ui.DismissTaskViewEvent; |
Jorim Jaggi | db21bbd | 2016-04-18 15:32:07 -0700 | [diff] [blame] | 86 | import com.android.systemui.recents.events.ui.RecentsGrowingEvent; |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 87 | import com.android.systemui.recents.events.ui.TaskViewDismissedEvent; |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 88 | import com.android.systemui.recents.events.ui.UpdateFreeformTaskViewVisibilityEvent; |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 89 | import com.android.systemui.recents.events.ui.UserInteractionEvent; |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 90 | import com.android.systemui.recents.events.ui.dragndrop.DragDropTargetChangedEvent; |
Winson | 27c28f8 | 2016-05-05 16:16:50 -0700 | [diff] [blame] | 91 | import com.android.systemui.recents.events.ui.dragndrop.DragEndCancelledEvent; |
Jorim Jaggi | 6f9dbcb | 2017-03-17 17:22:47 +0100 | [diff] [blame] | 92 | import com.android.systemui.recents.events.ui.dragndrop.DragEndEvent; |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 93 | import com.android.systemui.recents.events.ui.dragndrop.DragStartEvent; |
| 94 | import com.android.systemui.recents.events.ui.dragndrop.DragStartInitializeDropTargetsEvent; |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 95 | import com.android.systemui.recents.events.ui.focus.DismissFocusedTaskViewEvent; |
| 96 | import com.android.systemui.recents.events.ui.focus.FocusNextTaskViewEvent; |
| 97 | import com.android.systemui.recents.events.ui.focus.FocusPreviousTaskViewEvent; |
Jiaquan He | c0e1813 | 2017-01-11 14:47:00 -0800 | [diff] [blame] | 98 | import com.android.systemui.recents.events.ui.focus.NavigateTaskViewEvent; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 99 | import com.android.systemui.recents.misc.DozeTrigger; |
Winson Chung | ee44595 | 2014-09-09 16:12:59 +0200 | [diff] [blame] | 100 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Winson Chung | bf5dbf1 | 2014-09-16 00:58:25 +0200 | [diff] [blame] | 101 | import com.android.systemui.recents.misc.Utilities; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 102 | import com.android.systemui.recents.model.Task; |
| 103 | import com.android.systemui.recents.model.TaskStack; |
Jiaquan He | 5a2eb83 | 2016-12-13 14:36:37 -0800 | [diff] [blame] | 104 | import com.android.systemui.recents.views.grid.GridTaskView; |
Manu Cornet | de3cfb0 | 2017-01-25 18:31:01 +0900 | [diff] [blame] | 105 | import com.android.systemui.recents.views.grid.TaskGridLayoutAlgorithm; |
Jiaquan He | 21f495f | 2017-01-05 13:00:29 -0800 | [diff] [blame] | 106 | import com.android.systemui.recents.views.grid.TaskViewFocusFrame; |
Jorim Jaggi | 6f9dbcb | 2017-03-17 17:22:47 +0100 | [diff] [blame] | 107 | |
Winson | d72c315 | 2016-04-05 15:33:35 -0700 | [diff] [blame] | 108 | import java.io.PrintWriter; |
Winson | 619e40c | 2016-03-25 16:12:35 -0700 | [diff] [blame] | 109 | import java.lang.annotation.Retention; |
| 110 | import java.lang.annotation.RetentionPolicy; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 111 | import java.util.ArrayList; |
Winson Chung | 6ac8bd6 | 2015-01-07 16:38:35 -0800 | [diff] [blame] | 112 | import java.util.List; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 113 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 114 | |
| 115 | /* The visual representation of a task stack view */ |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 116 | public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCallbacks, |
Winson Chung | 012ef36 | 2014-07-31 18:36:25 -0700 | [diff] [blame] | 117 | TaskView.TaskViewCallbacks, TaskStackViewScroller.TaskStackViewScrollerCallbacks, |
Winson | 1c84614 | 2016-01-22 11:34:38 -0800 | [diff] [blame] | 118 | TaskStackLayoutAlgorithm.TaskStackLayoutAlgorithmCallbacks, |
Winson | e6c9073 | 2015-09-24 16:06:29 -0700 | [diff] [blame] | 119 | ViewPool.ViewPoolConsumer<TaskView, Task> { |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 120 | |
Winson | d72c315 | 2016-04-05 15:33:35 -0700 | [diff] [blame] | 121 | private static final String TAG = "TaskStackView"; |
| 122 | |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 123 | // The thresholds at which to show/hide the stack action button. |
| 124 | private static final float SHOW_STACK_ACTION_BUTTON_SCROLL_THRESHOLD = 0.3f; |
| 125 | private static final float HIDE_STACK_ACTION_BUTTON_SCROLL_THRESHOLD = 0.3f; |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 126 | |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 127 | public static final int DEFAULT_SYNC_STACK_DURATION = 200; |
Winson | 3f32e7e | 2016-04-20 17:18:08 -0700 | [diff] [blame] | 128 | public static final int SLOW_SYNC_STACK_DURATION = 250; |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 129 | private static final int DRAG_SCALE_DURATION = 175; |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 130 | static final float DRAG_SCALE_FACTOR = 1.05f; |
Winson Chung | 0626677 | 2015-12-11 10:24:21 -0500 | [diff] [blame] | 131 | |
Winson | f8597b2 | 2016-03-23 18:44:26 -0700 | [diff] [blame] | 132 | private static final int LAUNCH_NEXT_SCROLL_BASE_DURATION = 216; |
Winson | 96e6134 | 2016-03-15 16:47:19 -0700 | [diff] [blame] | 133 | private static final int LAUNCH_NEXT_SCROLL_INCR_DURATION = 32; |
| 134 | |
Winson | 619e40c | 2016-03-25 16:12:35 -0700 | [diff] [blame] | 135 | // The actions to perform when resetting to initial state, |
| 136 | @Retention(RetentionPolicy.SOURCE) |
| 137 | @IntDef({INITIAL_STATE_UPDATE_NONE, INITIAL_STATE_UPDATE_ALL, INITIAL_STATE_UPDATE_LAYOUT_ONLY}) |
| 138 | public @interface InitialStateAction {} |
| 139 | /** Do not update the stack and layout to the initial state. */ |
| 140 | private static final int INITIAL_STATE_UPDATE_NONE = 0; |
| 141 | /** Update both the stack and layout to the initial state. */ |
| 142 | private static final int INITIAL_STATE_UPDATE_ALL = 1; |
| 143 | /** Update only the layout to the initial state. */ |
| 144 | private static final int INITIAL_STATE_UPDATE_LAYOUT_ONLY = 2; |
| 145 | |
Winson | fc48b07 | 2016-04-21 11:20:11 -0700 | [diff] [blame] | 146 | private LayoutInflater mInflater; |
| 147 | private TaskStack mStack = new TaskStack(); |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 148 | @ViewDebug.ExportedProperty(deepExport=true, prefix="layout_") |
Winson | 36a5a2c | 2015-10-29 18:04:39 -0700 | [diff] [blame] | 149 | TaskStackLayoutAlgorithm mLayoutAlgorithm; |
Winson | f9357d9 | 2016-03-25 15:14:37 -0700 | [diff] [blame] | 150 | // The stable layout algorithm is only used to calculate the task rect with the stable bounds |
Winson | fc48b07 | 2016-04-21 11:20:11 -0700 | [diff] [blame] | 151 | private TaskStackLayoutAlgorithm mStableLayoutAlgorithm; |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 152 | @ViewDebug.ExportedProperty(deepExport=true, prefix="scroller_") |
Winson | fc48b07 | 2016-04-21 11:20:11 -0700 | [diff] [blame] | 153 | private TaskStackViewScroller mStackScroller; |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 154 | @ViewDebug.ExportedProperty(deepExport=true, prefix="touch_") |
Winson | fc48b07 | 2016-04-21 11:20:11 -0700 | [diff] [blame] | 155 | private TaskStackViewTouchHandler mTouchHandler; |
| 156 | private TaskStackAnimationHelper mAnimationHelper; |
| 157 | private GradientDrawable mFreeformWorkspaceBackground; |
| 158 | private ObjectAnimator mFreeformWorkspaceBackgroundAnimator; |
| 159 | private ViewPool<TaskView, Task> mViewPool; |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 160 | |
Winson | fc48b07 | 2016-04-21 11:20:11 -0700 | [diff] [blame] | 161 | private ArrayList<TaskView> mTaskViews = new ArrayList<>(); |
| 162 | private ArrayList<TaskViewTransform> mCurrentTaskTransforms = new ArrayList<>(); |
| 163 | private ArraySet<Task.TaskKey> mIgnoreTasks = new ArraySet<>(); |
| 164 | private AnimationProps mDeferredTaskViewLayoutAnimation = null; |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 165 | |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 166 | @ViewDebug.ExportedProperty(deepExport=true, prefix="doze_") |
Winson | fc48b07 | 2016-04-21 11:20:11 -0700 | [diff] [blame] | 167 | private DozeTrigger mUIDozeTrigger; |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 168 | @ViewDebug.ExportedProperty(deepExport=true, prefix="focused_task_") |
Winson | fc48b07 | 2016-04-21 11:20:11 -0700 | [diff] [blame] | 169 | private Task mFocusedTask; |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 170 | |
Winson | fc48b07 | 2016-04-21 11:20:11 -0700 | [diff] [blame] | 171 | private int mTaskCornerRadiusPx; |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 172 | private int mDividerSize; |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 173 | private int mStartTimerIndicatorDuration; |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 174 | |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 175 | @ViewDebug.ExportedProperty(category="recents") |
Winson | fc48b07 | 2016-04-21 11:20:11 -0700 | [diff] [blame] | 176 | private boolean mTaskViewsClipDirty = true; |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 177 | @ViewDebug.ExportedProperty(category="recents") |
Winson | fc48b07 | 2016-04-21 11:20:11 -0700 | [diff] [blame] | 178 | private boolean mAwaitingFirstLayout = true; |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 179 | @ViewDebug.ExportedProperty(category="recents") |
Winson | bd53a31 | 2016-09-21 12:13:32 -0700 | [diff] [blame] | 180 | private boolean mLaunchNextAfterFirstMeasure = false; |
| 181 | @ViewDebug.ExportedProperty(category="recents") |
Winson | 619e40c | 2016-03-25 16:12:35 -0700 | [diff] [blame] | 182 | @InitialStateAction |
Winson | fc48b07 | 2016-04-21 11:20:11 -0700 | [diff] [blame] | 183 | private int mInitialState = INITIAL_STATE_UPDATE_ALL; |
Winson | 619e40c | 2016-03-25 16:12:35 -0700 | [diff] [blame] | 184 | @ViewDebug.ExportedProperty(category="recents") |
Winson | fc48b07 | 2016-04-21 11:20:11 -0700 | [diff] [blame] | 185 | private boolean mInMeasureLayout = false; |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 186 | @ViewDebug.ExportedProperty(category="recents") |
Winson | fc48b07 | 2016-04-21 11:20:11 -0700 | [diff] [blame] | 187 | private boolean mEnterAnimationComplete = false; |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 188 | @ViewDebug.ExportedProperty(category="recents") |
Winson | f000988 | 2016-06-01 12:22:55 -0700 | [diff] [blame] | 189 | boolean mTouchExplorationEnabled; |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 190 | @ViewDebug.ExportedProperty(category="recents") |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 191 | boolean mScreenPinningEnabled; |
Winson | 3150e57 | 2015-10-23 15:07:24 -0700 | [diff] [blame] | 192 | |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 193 | // The stable stack bounds are the full bounds that we were measured with from RecentsView |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 194 | @ViewDebug.ExportedProperty(category="recents") |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 195 | private Rect mStableStackBounds = new Rect(); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 196 | // The current stack bounds are dynamic and may change as the user drags and drops |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 197 | @ViewDebug.ExportedProperty(category="recents") |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 198 | private Rect mStackBounds = new Rect(); |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 199 | // The current window bounds at the point we were measured |
| 200 | @ViewDebug.ExportedProperty(category="recents") |
| 201 | private Rect mStableWindowRect = new Rect(); |
| 202 | // The current window bounds are dynamic and may change as the user drags and drops |
| 203 | @ViewDebug.ExportedProperty(category="recents") |
| 204 | private Rect mWindowRect = new Rect(); |
Winson | fc48b07 | 2016-04-21 11:20:11 -0700 | [diff] [blame] | 205 | // The current display bounds |
| 206 | @ViewDebug.ExportedProperty(category="recents") |
| 207 | private Rect mDisplayRect = new Rect(); |
| 208 | // The current display orientation |
| 209 | @ViewDebug.ExportedProperty(category="recents") |
| 210 | private int mDisplayOrientation = Configuration.ORIENTATION_UNDEFINED; |
Winson | d952961 | 2016-01-28 13:29:49 -0800 | [diff] [blame] | 211 | |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 212 | private Rect mTmpRect = new Rect(); |
| 213 | private ArrayMap<Task.TaskKey, TaskView> mTmpTaskViewMap = new ArrayMap<>(); |
| 214 | private List<TaskView> mTmpTaskViews = new ArrayList<>(); |
| 215 | private TaskViewTransform mTmpTransform = new TaskViewTransform(); |
Winson | c438702 | 2016-02-24 12:05:26 -0800 | [diff] [blame] | 216 | private int[] mTmpIntPair = new int[2]; |
Jorim Jaggi | db21bbd | 2016-04-18 15:32:07 -0700 | [diff] [blame] | 217 | private boolean mResetToInitialStateWhenResized; |
| 218 | private int mLastWidth; |
| 219 | private int mLastHeight; |
Winson Chung | 931c51f | 2015-12-17 17:08:55 -0500 | [diff] [blame] | 220 | |
Jiaquan He | 21f495f | 2017-01-05 13:00:29 -0800 | [diff] [blame] | 221 | // We keep track of the task view focused by user interaction and draw a frame around it in the |
| 222 | // grid layout. |
| 223 | private TaskViewFocusFrame mTaskViewFocusFrame; |
| 224 | |
Jorim Jaggi | 6f9dbcb | 2017-03-17 17:22:47 +0100 | [diff] [blame] | 225 | private Task mPrefetchingTask; |
| 226 | private final float mFastFlingVelocity; |
| 227 | |
Winson Chung | bf5dbf1 | 2014-09-16 00:58:25 +0200 | [diff] [blame] | 228 | // A convenience update listener to request updating clipping of tasks |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 229 | private ValueAnimator.AnimatorUpdateListener mRequestUpdateClippingListener = |
Winson Chung | bf5dbf1 | 2014-09-16 00:58:25 +0200 | [diff] [blame] | 230 | new ValueAnimator.AnimatorUpdateListener() { |
Winson | 5b7dd53 | 2015-12-01 16:02:12 -0800 | [diff] [blame] | 231 | @Override |
| 232 | public void onAnimationUpdate(ValueAnimator animation) { |
Winson | 5500390 | 2016-01-12 12:00:37 -0800 | [diff] [blame] | 233 | if (!mTaskViewsClipDirty) { |
| 234 | mTaskViewsClipDirty = true; |
| 235 | invalidate(); |
| 236 | } |
Winson | 5b7dd53 | 2015-12-01 16:02:12 -0800 | [diff] [blame] | 237 | } |
| 238 | }; |
Winson Chung | bf5dbf1 | 2014-09-16 00:58:25 +0200 | [diff] [blame] | 239 | |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 240 | // The drop targets for a task drag |
| 241 | private DropTarget mFreeformWorkspaceDropTarget = new DropTarget() { |
| 242 | @Override |
Winson | 08deff0 | 2016-08-05 13:58:31 -0700 | [diff] [blame] | 243 | public boolean acceptsDrop(int x, int y, int width, int height, Rect insets, |
| 244 | boolean isCurrentTarget) { |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 245 | // This drop target has a fixed bounds and should be checked last, so just fall through |
| 246 | // if it is the current target |
| 247 | if (!isCurrentTarget) { |
| 248 | return mLayoutAlgorithm.mFreeformRect.contains(x, y); |
| 249 | } |
| 250 | return false; |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 251 | } |
| 252 | }; |
| 253 | |
| 254 | private DropTarget mStackDropTarget = new DropTarget() { |
| 255 | @Override |
Winson | 08deff0 | 2016-08-05 13:58:31 -0700 | [diff] [blame] | 256 | public boolean acceptsDrop(int x, int y, int width, int height, Rect insets, |
| 257 | boolean isCurrentTarget) { |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 258 | // This drop target has a fixed bounds and should be checked last, so just fall through |
| 259 | // if it is the current target |
| 260 | if (!isCurrentTarget) { |
| 261 | return mLayoutAlgorithm.mStackRect.contains(x, y); |
| 262 | } |
| 263 | return false; |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 264 | } |
| 265 | }; |
| 266 | |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 267 | public TaskStackView(Context context) { |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 268 | super(context); |
Winson | de0591a | 2015-12-04 17:24:35 -0800 | [diff] [blame] | 269 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Winson | bb41095 | 2015-12-04 14:34:11 -0800 | [diff] [blame] | 270 | Resources res = context.getResources(); |
| 271 | |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 272 | // Set the stack first |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 273 | mStack.setCallbacks(this); |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 274 | mViewPool = new ViewPool<>(context, this); |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 275 | mInflater = LayoutInflater.from(context); |
Winson | 1c84614 | 2016-01-22 11:34:38 -0800 | [diff] [blame] | 276 | mLayoutAlgorithm = new TaskStackLayoutAlgorithm(context, this); |
Winson | f9357d9 | 2016-03-25 15:14:37 -0700 | [diff] [blame] | 277 | mStableLayoutAlgorithm = new TaskStackLayoutAlgorithm(context, null); |
Winson | 1c84614 | 2016-01-22 11:34:38 -0800 | [diff] [blame] | 278 | mStackScroller = new TaskStackViewScroller(context, this, mLayoutAlgorithm); |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 279 | mTouchHandler = new TaskStackViewTouchHandler(context, this, mStackScroller); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 280 | mAnimationHelper = new TaskStackAnimationHelper(context, this); |
Jiaquan He | 76b2e0a | 2017-01-19 15:57:39 -0800 | [diff] [blame] | 281 | mTaskCornerRadiusPx = Recents.getConfiguration().isGridEnabled ? |
| 282 | res.getDimensionPixelSize(R.dimen.recents_grid_task_view_rounded_corners_radius) : |
| 283 | res.getDimensionPixelSize(R.dimen.recents_task_view_rounded_corners_radius); |
Jorim Jaggi | 6f9dbcb | 2017-03-17 17:22:47 +0100 | [diff] [blame] | 284 | mFastFlingVelocity = res.getDimensionPixelSize(R.dimen.recents_fast_fling_velocity); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 285 | mDividerSize = ssp.getDockedDividerSize(context); |
Winson | fc48b07 | 2016-04-21 11:20:11 -0700 | [diff] [blame] | 286 | mDisplayOrientation = Utilities.getAppConfiguration(mContext).orientation; |
| 287 | mDisplayRect = ssp.getDisplayRect(); |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 288 | |
Jiaquan He | 21f495f | 2017-01-05 13:00:29 -0800 | [diff] [blame] | 289 | // Create a frame to draw around the focused task view |
| 290 | if (Recents.getConfiguration().isGridEnabled) { |
| 291 | mTaskViewFocusFrame = new TaskViewFocusFrame(mContext, this, |
| 292 | mLayoutAlgorithm.mTaskGridLayoutAlgorithm); |
| 293 | addView(mTaskViewFocusFrame); |
| 294 | getViewTreeObserver().addOnGlobalFocusChangeListener(mTaskViewFocusFrame); |
| 295 | } |
| 296 | |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 297 | int taskBarDismissDozeDelaySeconds = getResources().getInteger( |
| 298 | R.integer.recents_task_bar_dismiss_delay_seconds); |
| 299 | mUIDozeTrigger = new DozeTrigger(taskBarDismissDozeDelaySeconds, new Runnable() { |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 300 | @Override |
| 301 | public void run() { |
| 302 | // Show the task bar dismiss buttons |
Winson Chung | 6ac8bd6 | 2015-01-07 16:38:35 -0800 | [diff] [blame] | 303 | List<TaskView> taskViews = getTaskViews(); |
| 304 | int taskViewCount = taskViews.size(); |
| 305 | for (int i = 0; i < taskViewCount; i++) { |
| 306 | TaskView tv = taskViews.get(i); |
Winson Chung | 969f586 | 2014-06-16 17:08:24 -0700 | [diff] [blame] | 307 | tv.startNoUserInteractionAnimation(); |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 308 | } |
| 309 | } |
| 310 | }); |
Winson Chung | 83ea6f7 | 2015-06-17 13:00:23 -0700 | [diff] [blame] | 311 | setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES); |
Winson | edaffc5 | 2016-06-14 14:48:01 -0700 | [diff] [blame] | 312 | if (ssp.hasFreeformWorkspaceSupport()) { |
| 313 | setWillNotDraw(false); |
| 314 | } |
Winson | 36a5a2c | 2015-10-29 18:04:39 -0700 | [diff] [blame] | 315 | |
Winson | de0591a | 2015-12-04 17:24:35 -0800 | [diff] [blame] | 316 | mFreeformWorkspaceBackground = (GradientDrawable) getContext().getDrawable( |
| 317 | R.drawable.recents_freeform_workspace_bg); |
Winson | a78a8f3 | 2015-12-03 10:55:01 -0800 | [diff] [blame] | 318 | mFreeformWorkspaceBackground.setCallback(this); |
Winson | de0591a | 2015-12-04 17:24:35 -0800 | [diff] [blame] | 319 | if (ssp.hasFreeformWorkspaceSupport()) { |
Winson Chung | aa4f800 | 2015-12-17 10:27:55 -0500 | [diff] [blame] | 320 | mFreeformWorkspaceBackground.setColor( |
| 321 | getContext().getColor(R.color.recents_freeform_workspace_bg_color)); |
Winson | de0591a | 2015-12-04 17:24:35 -0800 | [diff] [blame] | 322 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 323 | } |
| 324 | |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 325 | @Override |
| 326 | protected void onAttachedToWindow() { |
| 327 | EventBus.getDefault().register(this, RecentsActivity.EVENT_BUS_PRIORITY + 1); |
| 328 | super.onAttachedToWindow(); |
| 329 | readSystemFlags(); |
| 330 | } |
| 331 | |
| 332 | @Override |
| 333 | protected void onDetachedFromWindow() { |
| 334 | super.onDetachedFromWindow(); |
| 335 | EventBus.getDefault().unregister(this); |
| 336 | } |
| 337 | |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 338 | /** |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 339 | * Called from RecentsActivity when it is relaunched. |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 340 | */ |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 341 | void onReload(boolean isResumingFromVisible) { |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 342 | if (!isResumingFromVisible) { |
| 343 | // Reset the focused task |
| 344 | resetFocusedTask(getFocusedTask()); |
| 345 | } |
| 346 | |
| 347 | // Reset the state of each of the task views |
| 348 | List<TaskView> taskViews = new ArrayList<>(); |
| 349 | taskViews.addAll(getTaskViews()); |
| 350 | taskViews.addAll(mViewPool.getViews()); |
| 351 | for (int i = taskViews.size() - 1; i >= 0; i--) { |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 352 | taskViews.get(i).onReload(isResumingFromVisible); |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | // Reset the stack state |
| 356 | readSystemFlags(); |
| 357 | mTaskViewsClipDirty = true; |
| 358 | mEnterAnimationComplete = false; |
| 359 | mUIDozeTrigger.stopDozing(); |
| 360 | if (isResumingFromVisible) { |
| 361 | // Animate in the freeform workspace |
| 362 | int ffBgAlpha = mLayoutAlgorithm.getStackState().freeformBackgroundAlpha; |
| 363 | animateFreeformWorkspaceBackgroundAlpha(ffBgAlpha, new AnimationProps(150, |
| 364 | Interpolators.FAST_OUT_SLOW_IN)); |
| 365 | } else { |
| 366 | mStackScroller.reset(); |
Winson | f9357d9 | 2016-03-25 15:14:37 -0700 | [diff] [blame] | 367 | mStableLayoutAlgorithm.reset(); |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 368 | mLayoutAlgorithm.reset(); |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 369 | } |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 370 | |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 371 | // Since we always animate to the same place in (the initial state), always reset the stack |
| 372 | // to the initial state when resuming |
| 373 | mAwaitingFirstLayout = true; |
Winson | bd53a31 | 2016-09-21 12:13:32 -0700 | [diff] [blame] | 374 | mLaunchNextAfterFirstMeasure = false; |
Winson | 619e40c | 2016-03-25 16:12:35 -0700 | [diff] [blame] | 375 | mInitialState = INITIAL_STATE_UPDATE_ALL; |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 376 | requestLayout(); |
Winson | e6c9073 | 2015-09-24 16:06:29 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 379 | /** |
| 380 | * Sets the stack tasks of this TaskStackView from the given TaskStack. |
| 381 | */ |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 382 | public void setTasks(TaskStack stack, boolean allowNotifyStackChanges) { |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 383 | boolean isInitialized = mLayoutAlgorithm.isInitialized(); |
Winson | d2a0306 | 2016-04-15 11:19:07 -0700 | [diff] [blame] | 384 | |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 385 | // Only notify if we are already initialized, otherwise, everything will pick up all the |
| 386 | // new and old tasks when we next layout |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 387 | mStack.setTasks(getContext(), stack, allowNotifyStackChanges && isInitialized); |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 388 | } |
| 389 | |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 390 | /** Returns the task stack. */ |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 391 | public TaskStack getStack() { |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 392 | return mStack; |
| 393 | } |
| 394 | |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 395 | /** |
| 396 | * Updates this TaskStackView to the initial state. |
| 397 | */ |
Winson | 67c7957 | 2016-04-13 14:02:18 -0700 | [diff] [blame] | 398 | public void updateToInitialState() { |
| 399 | mStackScroller.setStackScrollToInitialState(); |
Winson | d2a0306 | 2016-04-15 11:19:07 -0700 | [diff] [blame] | 400 | mLayoutAlgorithm.setTaskOverridesForInitialState(mStack, false /* ignoreScrollToFront */); |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 401 | } |
| 402 | |
Winson Chung | 6ac8bd6 | 2015-01-07 16:38:35 -0800 | [diff] [blame] | 403 | /** Updates the list of task views */ |
| 404 | void updateTaskViewsList() { |
| 405 | mTaskViews.clear(); |
| 406 | int childCount = getChildCount(); |
| 407 | for (int i = 0; i < childCount; i++) { |
| 408 | View v = getChildAt(i); |
| 409 | if (v instanceof TaskView) { |
| 410 | mTaskViews.add((TaskView) v); |
| 411 | } |
| 412 | } |
Winson Chung | 6ac8bd6 | 2015-01-07 16:38:35 -0800 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | /** Gets the list of task views */ |
| 416 | List<TaskView> getTaskViews() { |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 417 | return mTaskViews; |
Winson Chung | 6ac8bd6 | 2015-01-07 16:38:35 -0800 | [diff] [blame] | 418 | } |
| 419 | |
Winson | 1b58561 | 2015-11-06 09:16:26 -0800 | [diff] [blame] | 420 | /** |
| 421 | * Returns the front most task view. |
| 422 | * |
| 423 | * @param stackTasksOnly if set, will return the front most task view in the stack (by default |
| 424 | * the front most task view will be freeform since they are placed above |
| 425 | * stack tasks) |
| 426 | */ |
| 427 | private TaskView getFrontMostTaskView(boolean stackTasksOnly) { |
| 428 | List<TaskView> taskViews = getTaskViews(); |
| 429 | int taskViewCount = taskViews.size(); |
| 430 | for (int i = taskViewCount - 1; i >= 0; i--) { |
| 431 | TaskView tv = taskViews.get(i); |
| 432 | Task task = tv.getTask(); |
| 433 | if (stackTasksOnly && task.isFreeformTask()) { |
| 434 | continue; |
| 435 | } |
| 436 | return tv; |
| 437 | } |
| 438 | return null; |
| 439 | } |
| 440 | |
| 441 | /** |
| 442 | * Finds the child view given a specific {@param task}. |
| 443 | */ |
| 444 | public TaskView getChildViewForTask(Task t) { |
| 445 | List<TaskView> taskViews = getTaskViews(); |
| 446 | int taskViewCount = taskViews.size(); |
| 447 | for (int i = 0; i < taskViewCount; i++) { |
| 448 | TaskView tv = taskViews.get(i); |
| 449 | if (tv.getTask() == t) { |
| 450 | return tv; |
| 451 | } |
| 452 | } |
| 453 | return null; |
| 454 | } |
| 455 | |
Winson Chung | d7b2cb1 | 2014-06-26 15:08:50 -0700 | [diff] [blame] | 456 | /** Returns the stack algorithm for this task stack. */ |
Winson | 36a5a2c | 2015-10-29 18:04:39 -0700 | [diff] [blame] | 457 | public TaskStackLayoutAlgorithm getStackAlgorithm() { |
Winson Chung | 012ef36 | 2014-07-31 18:36:25 -0700 | [diff] [blame] | 458 | return mLayoutAlgorithm; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 459 | } |
| 460 | |
Manu Cornet | de3cfb0 | 2017-01-25 18:31:01 +0900 | [diff] [blame] | 461 | /** Returns the grid algorithm for this task stack. */ |
| 462 | public TaskGridLayoutAlgorithm getGridAlgorithm() { |
| 463 | return mLayoutAlgorithm.mTaskGridLayoutAlgorithm; |
| 464 | } |
| 465 | |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 466 | /** |
Winson | aa0dea7 | 2016-04-28 10:59:30 -0700 | [diff] [blame] | 467 | * Returns the touch handler for this task stack. |
| 468 | */ |
| 469 | public TaskStackViewTouchHandler getTouchHandler() { |
| 470 | return mTouchHandler; |
| 471 | } |
| 472 | |
| 473 | /** |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 474 | * Adds a task to the ignored set. |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 475 | */ |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 476 | void addIgnoreTask(Task task) { |
| 477 | mIgnoreTasks.add(task.key); |
| 478 | } |
| 479 | |
| 480 | /** |
| 481 | * Removes a task from the ignored set. |
| 482 | */ |
| 483 | void removeIgnoreTask(Task task) { |
| 484 | mIgnoreTasks.remove(task.key); |
| 485 | } |
| 486 | |
| 487 | /** |
| 488 | * Returns whether the specified {@param task} is ignored. |
| 489 | */ |
| 490 | boolean isIgnoredTask(Task task) { |
| 491 | return mIgnoreTasks.contains(task.key); |
| 492 | } |
| 493 | |
| 494 | /** |
| 495 | * Computes the task transforms at the current stack scroll for all visible tasks. If a valid |
| 496 | * target stack scroll is provided (ie. is different than {@param curStackScroll}), then the |
| 497 | * visible range includes all tasks at the target stack scroll. This is useful for ensure that |
| 498 | * all views necessary for a transition or animation will be visible at the start. |
| 499 | * |
| 500 | * This call ignores freeform tasks. |
| 501 | * |
| 502 | * @param taskTransforms The set of task view transforms to reuse, this list will be sized to |
| 503 | * match the size of {@param tasks} |
| 504 | * @param tasks The set of tasks for which to generate transforms |
| 505 | * @param curStackScroll The current stack scroll |
| 506 | * @param targetStackScroll The stack scroll that we anticipate we are going to be scrolling to. |
| 507 | * The range of the union of the visible views at the current and |
| 508 | * target stack scrolls will be returned. |
| 509 | * @param ignoreTasksSet The set of tasks to skip for purposes of calculaing the visible range. |
| 510 | * Transforms will still be calculated for the ignore tasks. |
Winson | c438702 | 2016-02-24 12:05:26 -0800 | [diff] [blame] | 511 | * @return the front and back most visible task indices (there may be non visible tasks in |
| 512 | * between this range) |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 513 | */ |
Winson | c438702 | 2016-02-24 12:05:26 -0800 | [diff] [blame] | 514 | int[] computeVisibleTaskTransforms(ArrayList<TaskViewTransform> taskTransforms, |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 515 | ArrayList<Task> tasks, float curStackScroll, float targetStackScroll, |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 516 | ArraySet<Task.TaskKey> ignoreTasksSet, boolean ignoreTaskOverrides) { |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 517 | int taskCount = tasks.size(); |
Winson | c438702 | 2016-02-24 12:05:26 -0800 | [diff] [blame] | 518 | int[] visibleTaskRange = mTmpIntPair; |
| 519 | visibleTaskRange[0] = -1; |
| 520 | visibleTaskRange[1] = -1; |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 521 | boolean useTargetStackScroll = Float.compare(curStackScroll, targetStackScroll) != 0; |
Winson Chung | c9567c0 | 2014-06-16 20:25:51 -0700 | [diff] [blame] | 522 | |
| 523 | // We can reuse the task transforms where possible to reduce object allocation |
Winson | c5fd350 | 2016-01-18 15:18:37 -0800 | [diff] [blame] | 524 | Utilities.matchTaskListSize(tasks, taskTransforms); |
Winson Chung | c9567c0 | 2014-06-16 20:25:51 -0700 | [diff] [blame] | 525 | |
| 526 | // Update the stack transforms |
Winson | 4993c2f | 2015-11-19 10:06:06 -0800 | [diff] [blame] | 527 | TaskViewTransform frontTransform = null; |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 528 | TaskViewTransform frontTransformAtTarget = null; |
| 529 | TaskViewTransform transform = null; |
| 530 | TaskViewTransform transformAtTarget = null; |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 531 | for (int i = taskCount - 1; i >= 0; i--) { |
Winson | a5e6b36 | 2015-11-02 17:17:20 -0800 | [diff] [blame] | 532 | Task task = tasks.get(i); |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 533 | |
| 534 | // Calculate the current and (if necessary) the target transform for the task |
| 535 | transform = mLayoutAlgorithm.getStackTransform(task, curStackScroll, |
Jiaquan He | 26f637b | 2016-12-27 14:44:14 -0800 | [diff] [blame] | 536 | taskTransforms.get(i), frontTransform, ignoreTaskOverrides); |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 537 | if (useTargetStackScroll && !transform.visible) { |
| 538 | // If we have a target stack scroll and the task is not currently visible, then we |
| 539 | // just update the transform at the new scroll |
| 540 | // TODO: Optimize this |
Jiaquan He | c0a1acd | 2016-12-13 13:46:46 -0800 | [diff] [blame] | 541 | transformAtTarget = mLayoutAlgorithm.getStackTransform(task, targetStackScroll, |
Jiaquan He | 26f637b | 2016-12-27 14:44:14 -0800 | [diff] [blame] | 542 | new TaskViewTransform(), frontTransformAtTarget); |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 543 | if (transformAtTarget.visible) { |
| 544 | transform.copyFrom(transformAtTarget); |
| 545 | } |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 546 | } |
| 547 | |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 548 | // For ignore tasks, only calculate the stack transform and skip the calculation of the |
| 549 | // visible stack indices |
| 550 | if (ignoreTasksSet.contains(task.key)) { |
| 551 | continue; |
| 552 | } |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 553 | |
| 554 | // For freeform tasks, only calculate the stack transform and skip the calculation of |
| 555 | // the visible stack indices |
Winson | a5e6b36 | 2015-11-02 17:17:20 -0800 | [diff] [blame] | 556 | if (task.isFreeformTask()) { |
| 557 | continue; |
| 558 | } |
| 559 | |
Winson | 4993c2f | 2015-11-19 10:06:06 -0800 | [diff] [blame] | 560 | frontTransform = transform; |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 561 | frontTransformAtTarget = transformAtTarget; |
Winson | c438702 | 2016-02-24 12:05:26 -0800 | [diff] [blame] | 562 | if (transform.visible) { |
| 563 | if (visibleTaskRange[0] < 0) { |
| 564 | visibleTaskRange[0] = i; |
| 565 | } |
| 566 | visibleTaskRange[1] = i; |
| 567 | } |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 568 | } |
Winson | c438702 | 2016-02-24 12:05:26 -0800 | [diff] [blame] | 569 | return visibleTaskRange; |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 570 | } |
| 571 | |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 572 | /** |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 573 | * Binds the visible {@link TaskView}s at the given target scroll. |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 574 | */ |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 575 | void bindVisibleTaskViews(float targetStackScroll) { |
Winson | d2a0306 | 2016-04-15 11:19:07 -0700 | [diff] [blame] | 576 | bindVisibleTaskViews(targetStackScroll, false /* ignoreTaskOverrides */); |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | /** |
| 580 | * Synchronizes the set of children {@link TaskView}s to match the visible set of tasks in the |
| 581 | * current {@link TaskStack}. This call does not continue on to update their position to the |
| 582 | * computed {@link TaskViewTransform}s of the visible range, but only ensures that they will |
| 583 | * be added/removed from the view hierarchy and placed in the correct Z order and initial |
| 584 | * position (if not currently on screen). |
| 585 | * |
| 586 | * @param targetStackScroll If provided, will ensure that the set of visible {@link TaskView}s |
| 587 | * includes those visible at the current stack scroll, and all at the |
| 588 | * target stack scroll. |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 589 | * @param ignoreTaskOverrides If set, the visible task computation will get the transforms for |
| 590 | * tasks at their non-overridden task progress |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 591 | */ |
Winson | d2a0306 | 2016-04-15 11:19:07 -0700 | [diff] [blame] | 592 | void bindVisibleTaskViews(float targetStackScroll, boolean ignoreTaskOverrides) { |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 593 | // Get all the task transforms |
Winson | c438702 | 2016-02-24 12:05:26 -0800 | [diff] [blame] | 594 | ArrayList<Task> tasks = mStack.getStackTasks(); |
| 595 | int[] visibleTaskRange = computeVisibleTaskTransforms(mCurrentTaskTransforms, tasks, |
Winson | d2a0306 | 2016-04-15 11:19:07 -0700 | [diff] [blame] | 596 | mStackScroller.getStackScroll(), targetStackScroll, mIgnoreTasks, |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 597 | ignoreTaskOverrides); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 598 | |
| 599 | // Return all the invisible children to the pool |
Winson | 5500390 | 2016-01-12 12:00:37 -0800 | [diff] [blame] | 600 | mTmpTaskViewMap.clear(); |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 601 | List<TaskView> taskViews = getTaskViews(); |
| 602 | int lastFocusedTaskIndex = -1; |
| 603 | int taskViewCount = taskViews.size(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 604 | for (int i = taskViewCount - 1; i >= 0; i--) { |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 605 | TaskView tv = taskViews.get(i); |
| 606 | Task task = tv.getTask(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 607 | |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 608 | // Skip ignored tasks |
Winson | d2a0306 | 2016-04-15 11:19:07 -0700 | [diff] [blame] | 609 | if (mIgnoreTasks.contains(task.key)) { |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 610 | continue; |
| 611 | } |
| 612 | |
Winson | 1d5ff7e | 2016-03-04 11:21:09 -0800 | [diff] [blame] | 613 | // It is possible for the set of lingering TaskViews to differ from the stack if the |
| 614 | // stack was updated before the relayout. If the task view is no longer in the stack, |
| 615 | // then just return it back to the view pool. |
| 616 | int taskIndex = mStack.indexOfStackTask(task); |
| 617 | TaskViewTransform transform = null; |
| 618 | if (taskIndex != -1) { |
| 619 | transform = mCurrentTaskTransforms.get(taskIndex); |
| 620 | } |
| 621 | |
| 622 | if (task.isFreeformTask() || (transform != null && transform.visible)) { |
Winson | 5500390 | 2016-01-12 12:00:37 -0800 | [diff] [blame] | 623 | mTmpTaskViewMap.put(task.key, tv); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 624 | } else { |
Winson | f000988 | 2016-06-01 12:22:55 -0700 | [diff] [blame] | 625 | if (mTouchExplorationEnabled && Utilities.isDescendentAccessibilityFocused(tv)) { |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 626 | lastFocusedTaskIndex = taskIndex; |
| 627 | resetFocusedTask(task); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 628 | } |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 629 | mViewPool.returnViewToPool(tv); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 630 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 631 | } |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 632 | |
| 633 | // Pick up all the newly visible children |
Winson | c438702 | 2016-02-24 12:05:26 -0800 | [diff] [blame] | 634 | for (int i = tasks.size() - 1; i >= 0; i--) { |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 635 | Task task = tasks.get(i); |
| 636 | TaskViewTransform transform = mCurrentTaskTransforms.get(i); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 637 | |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 638 | // Skip ignored tasks |
Winson | d2a0306 | 2016-04-15 11:19:07 -0700 | [diff] [blame] | 639 | if (mIgnoreTasks.contains(task.key)) { |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 640 | continue; |
| 641 | } |
| 642 | |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 643 | // Skip the invisible non-freeform stack tasks |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 644 | if (!task.isFreeformTask() && !transform.visible) { |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 645 | continue; |
| 646 | } |
| 647 | |
Winson | 5500390 | 2016-01-12 12:00:37 -0800 | [diff] [blame] | 648 | TaskView tv = mTmpTaskViewMap.get(task.key); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 649 | if (tv == null) { |
| 650 | tv = mViewPool.pickUpViewFromPool(task, task); |
| 651 | if (task.isFreeformTask()) { |
Winson | c69249f | 2016-03-28 13:38:39 -0700 | [diff] [blame] | 652 | updateTaskViewToTransform(tv, transform, AnimationProps.IMMEDIATE); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 653 | } else { |
Winson | 6808881 | 2016-02-12 16:06:04 -0800 | [diff] [blame] | 654 | if (transform.rect.top <= mLayoutAlgorithm.mStackRect.top) { |
Winson | c69249f | 2016-03-28 13:38:39 -0700 | [diff] [blame] | 655 | updateTaskViewToTransform(tv, mLayoutAlgorithm.getBackOfStackTransform(), |
| 656 | AnimationProps.IMMEDIATE); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 657 | } else { |
Winson | c69249f | 2016-03-28 13:38:39 -0700 | [diff] [blame] | 658 | updateTaskViewToTransform(tv, mLayoutAlgorithm.getFrontOfStackTransform(), |
| 659 | AnimationProps.IMMEDIATE); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 660 | } |
| 661 | } |
| 662 | } else { |
| 663 | // Reattach it in the right z order |
| 664 | final int taskIndex = mStack.indexOfStackTask(task); |
| 665 | final int insertIndex = findTaskViewInsertIndex(task, taskIndex); |
| 666 | if (insertIndex != getTaskViews().indexOf(tv)){ |
| 667 | detachViewFromParent(tv); |
| 668 | attachViewToParent(tv, insertIndex, tv.getLayoutParams()); |
| 669 | updateTaskViewsList(); |
| 670 | } |
| 671 | } |
| 672 | } |
| 673 | |
Jorim Jaggi | 6f9dbcb | 2017-03-17 17:22:47 +0100 | [diff] [blame] | 674 | updatePrefetchingTask(tasks, visibleTaskRange[0], visibleTaskRange[1]); |
| 675 | |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 676 | // Update the focus if the previous focused task was returned to the view pool |
| 677 | if (lastFocusedTaskIndex != -1) { |
Winson | f000988 | 2016-06-01 12:22:55 -0700 | [diff] [blame] | 678 | int newFocusedTaskIndex = (lastFocusedTaskIndex < visibleTaskRange[1]) |
| 679 | ? visibleTaskRange[1] |
| 680 | : visibleTaskRange[0]; |
| 681 | setFocusedTask(newFocusedTaskIndex, false /* scrollToTask */, |
| 682 | true /* requestViewFocus */); |
| 683 | TaskView focusedTaskView = getChildViewForTask(mFocusedTask); |
| 684 | if (focusedTaskView != null) { |
| 685 | focusedTaskView.requestAccessibilityFocus(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 686 | } |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | /** |
Winson | 27c28f8 | 2016-05-05 16:16:50 -0700 | [diff] [blame] | 691 | * @see #relayoutTaskViews(AnimationProps, ArrayMap<Task, AnimationProps>, boolean) |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 692 | */ |
Winson | 67c7957 | 2016-04-13 14:02:18 -0700 | [diff] [blame] | 693 | public void relayoutTaskViews(AnimationProps animation) { |
Winson | 27c28f8 | 2016-05-05 16:16:50 -0700 | [diff] [blame] | 694 | relayoutTaskViews(animation, null /* animationOverrides */, |
| 695 | false /* ignoreTaskOverrides */); |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | /** |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 699 | * Relayout the the visible {@link TaskView}s to their current transforms as specified by the |
| 700 | * {@link TaskStackLayoutAlgorithm} with the given {@param animation}. This call cancels any |
| 701 | * animations that are current running on those task views, and will ensure that the children |
Winson | 27c28f8 | 2016-05-05 16:16:50 -0700 | [diff] [blame] | 702 | * {@link TaskView}s will match the set of visible tasks in the stack. If a {@link Task} has |
| 703 | * an animation provided in {@param animationOverrides}, that will be used instead. |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 704 | */ |
Winson | 27c28f8 | 2016-05-05 16:16:50 -0700 | [diff] [blame] | 705 | private void relayoutTaskViews(AnimationProps animation, |
| 706 | ArrayMap<Task, AnimationProps> animationOverrides, |
| 707 | boolean ignoreTaskOverrides) { |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 708 | // If we had a deferred animation, cancel that |
Winson | eca47ef | 2016-04-21 16:48:50 -0700 | [diff] [blame] | 709 | cancelDeferredTaskViewLayoutAnimation(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 710 | |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 711 | // Synchronize the current set of TaskViews |
Winson | d2a0306 | 2016-04-15 11:19:07 -0700 | [diff] [blame] | 712 | bindVisibleTaskViews(mStackScroller.getStackScroll(), |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 713 | ignoreTaskOverrides /* ignoreTaskOverrides */); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 714 | |
| 715 | // Animate them to their final transforms with the given animation |
| 716 | List<TaskView> taskViews = getTaskViews(); |
| 717 | int taskViewCount = taskViews.size(); |
| 718 | for (int i = 0; i < taskViewCount; i++) { |
Winson | 4333694 | 2016-03-07 14:52:59 -0800 | [diff] [blame] | 719 | TaskView tv = taskViews.get(i); |
Winson | 27c28f8 | 2016-05-05 16:16:50 -0700 | [diff] [blame] | 720 | Task task = tv.getTask(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 721 | |
Winson | 27c28f8 | 2016-05-05 16:16:50 -0700 | [diff] [blame] | 722 | if (mIgnoreTasks.contains(task.key)) { |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 723 | continue; |
| 724 | } |
| 725 | |
Winson | 448c0ad | 2016-10-19 09:53:59 -0700 | [diff] [blame] | 726 | int taskIndex = mStack.indexOfStackTask(task); |
| 727 | TaskViewTransform transform = mCurrentTaskTransforms.get(taskIndex); |
Winson | 27c28f8 | 2016-05-05 16:16:50 -0700 | [diff] [blame] | 728 | if (animationOverrides != null && animationOverrides.containsKey(task)) { |
| 729 | animation = animationOverrides.get(task); |
| 730 | } |
| 731 | |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 732 | updateTaskViewToTransform(tv, transform, animation); |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | /** |
| 737 | * Posts an update to synchronize the {@link TaskView}s with the stack on the next frame. |
| 738 | */ |
Winson | be8e696 | 2016-02-01 14:27:52 -0800 | [diff] [blame] | 739 | void relayoutTaskViewsOnNextFrame(AnimationProps animation) { |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 740 | mDeferredTaskViewLayoutAnimation = animation; |
Winson | 1c84614 | 2016-01-22 11:34:38 -0800 | [diff] [blame] | 741 | invalidate(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | /** |
| 745 | * Called to update a specific {@link TaskView} to a given {@link TaskViewTransform} with a |
Winson | be8e696 | 2016-02-01 14:27:52 -0800 | [diff] [blame] | 746 | * given set of {@link AnimationProps} properties. |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 747 | */ |
| 748 | public void updateTaskViewToTransform(TaskView taskView, TaskViewTransform transform, |
Winson | be8e696 | 2016-02-01 14:27:52 -0800 | [diff] [blame] | 749 | AnimationProps animation) { |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 750 | if (taskView.isAnimatingTo(transform)) { |
| 751 | return; |
| 752 | } |
| 753 | taskView.cancelTransformAnimation(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 754 | taskView.updateViewPropertiesToTaskTransform(transform, animation, |
| 755 | mRequestUpdateClippingListener); |
| 756 | } |
| 757 | |
| 758 | /** |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 759 | * Returns the current task transforms of all tasks, falling back to the stack layout if there |
| 760 | * is no {@link TaskView} for the task. |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 761 | */ |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 762 | public void getCurrentTaskTransforms(ArrayList<Task> tasks, |
| 763 | ArrayList<TaskViewTransform> transformsOut) { |
| 764 | Utilities.matchTaskListSize(tasks, transformsOut); |
Winson | 6647413 | 2016-02-23 18:45:47 -0800 | [diff] [blame] | 765 | int focusState = mLayoutAlgorithm.getFocusState(); |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 766 | for (int i = tasks.size() - 1; i >= 0; i--) { |
| 767 | Task task = tasks.get(i); |
| 768 | TaskViewTransform transform = transformsOut.get(i); |
| 769 | TaskView tv = getChildViewForTask(task); |
| 770 | if (tv != null) { |
| 771 | transform.fillIn(tv); |
| 772 | } else { |
| 773 | mLayoutAlgorithm.getStackTransform(task, mStackScroller.getStackScroll(), |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 774 | focusState, transform, null, true /* forceUpdate */, |
Jiaquan He | 26f637b | 2016-12-27 14:44:14 -0800 | [diff] [blame] | 775 | false /* ignoreTaskOverrides */); |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 776 | } |
| 777 | transform.visible = true; |
| 778 | } |
| 779 | } |
| 780 | |
| 781 | /** |
| 782 | * Returns the task transforms for all the tasks in the stack if the stack was at the given |
Winson | 1499150 | 2016-02-15 15:40:08 -0800 | [diff] [blame] | 783 | * {@param stackScroll} and {@param focusState}. |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 784 | */ |
Winson | 6647413 | 2016-02-23 18:45:47 -0800 | [diff] [blame] | 785 | public void getLayoutTaskTransforms(float stackScroll, int focusState, ArrayList<Task> tasks, |
Winson | d2a0306 | 2016-04-15 11:19:07 -0700 | [diff] [blame] | 786 | boolean ignoreTaskOverrides, ArrayList<TaskViewTransform> transformsOut) { |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 787 | Utilities.matchTaskListSize(tasks, transformsOut); |
| 788 | for (int i = tasks.size() - 1; i >= 0; i--) { |
| 789 | Task task = tasks.get(i); |
| 790 | TaskViewTransform transform = transformsOut.get(i); |
Winson | 1499150 | 2016-02-15 15:40:08 -0800 | [diff] [blame] | 791 | mLayoutAlgorithm.getStackTransform(task, stackScroll, focusState, transform, null, |
Jiaquan He | 26f637b | 2016-12-27 14:44:14 -0800 | [diff] [blame] | 792 | true /* forceUpdate */, ignoreTaskOverrides); |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 793 | transform.visible = true; |
| 794 | } |
| 795 | } |
| 796 | |
| 797 | /** |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 798 | * Cancels the next deferred task view layout. |
| 799 | */ |
| 800 | void cancelDeferredTaskViewLayoutAnimation() { |
| 801 | mDeferredTaskViewLayoutAnimation = null; |
| 802 | } |
| 803 | |
| 804 | /** |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 805 | * Cancels all {@link TaskView} animations. |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 806 | */ |
| 807 | void cancelAllTaskViewAnimations() { |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 808 | List<TaskView> taskViews = getTaskViews(); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 809 | for (int i = taskViews.size() - 1; i >= 0; i--) { |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 810 | final TaskView tv = taskViews.get(i); |
Winson | eca47ef | 2016-04-21 16:48:50 -0700 | [diff] [blame] | 811 | if (!mIgnoreTasks.contains(tv.getTask().key)) { |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 812 | tv.cancelTransformAnimation(); |
| 813 | } |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 814 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 815 | } |
| 816 | |
Winson | 3150e57 | 2015-10-23 15:07:24 -0700 | [diff] [blame] | 817 | /** |
| 818 | * Updates the clip for each of the task views from back to front. |
| 819 | */ |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 820 | private void clipTaskViews() { |
Jiaquan He | 5a2eb83 | 2016-12-13 14:36:37 -0800 | [diff] [blame] | 821 | // We never clip task views in grid layout |
| 822 | if (Recents.getConfiguration().isGridEnabled) { |
| 823 | return; |
| 824 | } |
| 825 | |
Winson Chung | 93748a1 | 2014-07-13 17:43:31 -0700 | [diff] [blame] | 826 | // Update the clip on each task child |
Winson Chung | 6ac8bd6 | 2015-01-07 16:38:35 -0800 | [diff] [blame] | 827 | List<TaskView> taskViews = getTaskViews(); |
Winson | 3150e57 | 2015-10-23 15:07:24 -0700 | [diff] [blame] | 828 | TaskView tmpTv = null; |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 829 | TaskView prevVisibleTv = null; |
Winson Chung | 6ac8bd6 | 2015-01-07 16:38:35 -0800 | [diff] [blame] | 830 | int taskViewCount = taskViews.size(); |
Winson | 3150e57 | 2015-10-23 15:07:24 -0700 | [diff] [blame] | 831 | for (int i = 0; i < taskViewCount; i++) { |
Winson Chung | 6ac8bd6 | 2015-01-07 16:38:35 -0800 | [diff] [blame] | 832 | TaskView tv = taskViews.get(i); |
Winson | 3150e57 | 2015-10-23 15:07:24 -0700 | [diff] [blame] | 833 | TaskView frontTv = null; |
Winson Chung | 6ac8bd6 | 2015-01-07 16:38:35 -0800 | [diff] [blame] | 834 | int clipBottom = 0; |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 835 | |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 836 | if (isIgnoredTask(tv.getTask())) { |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 837 | // For each of the ignore tasks, update the translationZ of its TaskView to be |
| 838 | // between the translationZ of the tasks immediately underneath it |
| 839 | if (prevVisibleTv != null) { |
| 840 | tv.setTranslationZ(Math.max(tv.getTranslationZ(), |
| 841 | prevVisibleTv.getTranslationZ() + 0.1f)); |
| 842 | } |
| 843 | } |
| 844 | |
Winson | 3150e57 | 2015-10-23 15:07:24 -0700 | [diff] [blame] | 845 | if (i < (taskViewCount - 1) && tv.shouldClipViewInStack()) { |
Winson Chung | 6ac8bd6 | 2015-01-07 16:38:35 -0800 | [diff] [blame] | 846 | // Find the next view to clip against |
Winson | 3150e57 | 2015-10-23 15:07:24 -0700 | [diff] [blame] | 847 | for (int j = i + 1; j < taskViewCount; j++) { |
| 848 | tmpTv = taskViews.get(j); |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 849 | |
Winson | 3150e57 | 2015-10-23 15:07:24 -0700 | [diff] [blame] | 850 | if (tmpTv.shouldClipViewInStack()) { |
| 851 | frontTv = tmpTv; |
Winson Chung | 6ac8bd6 | 2015-01-07 16:38:35 -0800 | [diff] [blame] | 852 | break; |
Winson Chung | 93748a1 | 2014-07-13 17:43:31 -0700 | [diff] [blame] | 853 | } |
| 854 | } |
Winson Chung | 6ac8bd6 | 2015-01-07 16:38:35 -0800 | [diff] [blame] | 855 | |
| 856 | // Clip against the next view, this is just an approximation since we are |
| 857 | // stacked and we can make assumptions about the visibility of the this |
| 858 | // task relative to the ones in front of it. |
Winson | 3150e57 | 2015-10-23 15:07:24 -0700 | [diff] [blame] | 859 | if (frontTv != null) { |
Winson | bb41095 | 2015-12-04 14:34:11 -0800 | [diff] [blame] | 860 | float taskBottom = tv.getBottom(); |
| 861 | float frontTaskTop = frontTv.getTop(); |
Winson | 3150e57 | 2015-10-23 15:07:24 -0700 | [diff] [blame] | 862 | if (frontTaskTop < taskBottom) { |
| 863 | // Map the stack view space coordinate (the rects) to view space |
Winson | bb41095 | 2015-12-04 14:34:11 -0800 | [diff] [blame] | 864 | clipBottom = (int) (taskBottom - frontTaskTop) - mTaskCornerRadiusPx; |
Winson | 3150e57 | 2015-10-23 15:07:24 -0700 | [diff] [blame] | 865 | } |
Winson Chung | 6ac8bd6 | 2015-01-07 16:38:35 -0800 | [diff] [blame] | 866 | } |
Winson Chung | 93748a1 | 2014-07-13 17:43:31 -0700 | [diff] [blame] | 867 | } |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 868 | tv.getViewBounds().setClipBottom(clipBottom); |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 869 | tv.mThumbnailView.updateThumbnailVisibility(clipBottom - tv.getPaddingBottom()); |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 870 | prevVisibleTv = tv; |
Winson Chung | 6ac8bd6 | 2015-01-07 16:38:35 -0800 | [diff] [blame] | 871 | } |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 872 | mTaskViewsClipDirty = false; |
Winson Chung | 93748a1 | 2014-07-13 17:43:31 -0700 | [diff] [blame] | 873 | } |
| 874 | |
Jorim Jaggi | cdef591 | 2017-04-03 17:24:19 +0200 | [diff] [blame] | 875 | public void updateLayoutAlgorithm(boolean boundScrollToNewMinMax) { |
| 876 | updateLayoutAlgorithm(boundScrollToNewMinMax, Recents.getConfiguration().getLaunchState()); |
| 877 | } |
| 878 | |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 879 | /** |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 880 | * Updates the layout algorithm min and max virtual scroll bounds. |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 881 | */ |
Jorim Jaggi | cdef591 | 2017-04-03 17:24:19 +0200 | [diff] [blame] | 882 | public void updateLayoutAlgorithm(boolean boundScrollToNewMinMax, |
| 883 | RecentsActivityLaunchState launchState) { |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 884 | // Compute the min and max scroll values |
Jorim Jaggi | cdef591 | 2017-04-03 17:24:19 +0200 | [diff] [blame] | 885 | mLayoutAlgorithm.update(mStack, mIgnoreTasks, launchState); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 886 | |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 887 | // Update the freeform workspace background |
Winson | a5e6b36 | 2015-11-02 17:17:20 -0800 | [diff] [blame] | 888 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 889 | if (ssp.hasFreeformWorkspaceSupport()) { |
| 890 | mTmpRect.set(mLayoutAlgorithm.mFreeformRect); |
Winson | a5e6b36 | 2015-11-02 17:17:20 -0800 | [diff] [blame] | 891 | mFreeformWorkspaceBackground.setBounds(mTmpRect); |
| 892 | } |
| 893 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 894 | if (boundScrollToNewMinMax) { |
Winson Chung | 012ef36 | 2014-07-31 18:36:25 -0700 | [diff] [blame] | 895 | mStackScroller.boundScroll(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 896 | } |
| 897 | } |
| 898 | |
Winson | 27c28f8 | 2016-05-05 16:16:50 -0700 | [diff] [blame] | 899 | /** |
| 900 | * Updates the stack layout to its stable places. |
| 901 | */ |
| 902 | private void updateLayoutToStableBounds() { |
| 903 | mWindowRect.set(mStableWindowRect); |
| 904 | mStackBounds.set(mStableStackBounds); |
| 905 | mLayoutAlgorithm.setSystemInsets(mStableLayoutAlgorithm.mSystemInsets); |
| 906 | mLayoutAlgorithm.initialize(mDisplayRect, mWindowRect, mStackBounds, |
| 907 | TaskStackLayoutAlgorithm.StackState.getStackStateForStack(mStack)); |
| 908 | updateLayoutAlgorithm(true /* boundScroll */); |
| 909 | } |
| 910 | |
Winson Chung | 012ef36 | 2014-07-31 18:36:25 -0700 | [diff] [blame] | 911 | /** Returns the scroller. */ |
| 912 | public TaskStackViewScroller getScroller() { |
| 913 | return mStackScroller; |
| 914 | } |
| 915 | |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 916 | /** |
| 917 | * Sets the focused task to the provided (bounded taskIndex). |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 918 | * |
| 919 | * @return whether or not the stack will scroll as a part of this focus change |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 920 | */ |
Jiaquan He | 21f495f | 2017-01-05 13:00:29 -0800 | [diff] [blame] | 921 | public boolean setFocusedTask(int taskIndex, boolean scrollToTask, |
Winson | aaf33bc | 2015-12-03 12:02:38 -0800 | [diff] [blame] | 922 | final boolean requestViewFocus) { |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 923 | return setFocusedTask(taskIndex, scrollToTask, requestViewFocus, 0); |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | /** |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 927 | * Sets the focused task to the provided (bounded focusTaskIndex). |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 928 | * |
| 929 | * @return whether or not the stack will scroll as a part of this focus change |
| 930 | */ |
Jiaquan He | 21f495f | 2017-01-05 13:00:29 -0800 | [diff] [blame] | 931 | public boolean setFocusedTask(int focusTaskIndex, boolean scrollToTask, |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 932 | boolean requestViewFocus, int timerIndicatorDuration) { |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 933 | // Find the next task to focus |
Winson | 4b057c6 | 2016-01-12 15:01:52 -0800 | [diff] [blame] | 934 | int newFocusedTaskIndex = mStack.getTaskCount() > 0 ? |
Winson | 6808881 | 2016-02-12 16:06:04 -0800 | [diff] [blame] | 935 | Utilities.clamp(focusTaskIndex, 0, mStack.getTaskCount() - 1) : -1; |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 936 | final Task newFocusedTask = (newFocusedTaskIndex != -1) ? |
Winson | 250608a | 2015-11-24 15:00:31 -0800 | [diff] [blame] | 937 | mStack.getStackTasks().get(newFocusedTaskIndex) : null; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 938 | |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 939 | // Reset the last focused task state if changed |
Winson | aaf33bc | 2015-12-03 12:02:38 -0800 | [diff] [blame] | 940 | if (mFocusedTask != null) { |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 941 | // Cancel the timer indicator, if applicable |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 942 | if (timerIndicatorDuration > 0) { |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 943 | final TaskView tv = getChildViewForTask(mFocusedTask); |
| 944 | if (tv != null) { |
| 945 | tv.getHeaderView().cancelFocusTimerIndicator(); |
| 946 | } |
| 947 | } |
Winson | b433c5b | 2016-01-20 17:11:29 -0800 | [diff] [blame] | 948 | |
| 949 | resetFocusedTask(mFocusedTask); |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 950 | } |
| 951 | |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 952 | boolean willScroll = false; |
Winson | aaf33bc | 2015-12-03 12:02:38 -0800 | [diff] [blame] | 953 | mFocusedTask = newFocusedTask; |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 954 | |
Winson | aaf33bc | 2015-12-03 12:02:38 -0800 | [diff] [blame] | 955 | if (newFocusedTask != null) { |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 956 | // Start the timer indicator, if applicable |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 957 | if (timerIndicatorDuration > 0) { |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 958 | final TaskView tv = getChildViewForTask(mFocusedTask); |
| 959 | if (tv != null) { |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 960 | tv.getHeaderView().startFocusTimerIndicator(timerIndicatorDuration); |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 961 | } else { |
| 962 | // The view is null; set a flag for later |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 963 | mStartTimerIndicatorDuration = timerIndicatorDuration; |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 964 | } |
| 965 | } |
| 966 | |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 967 | if (scrollToTask) { |
Winson | 1c84614 | 2016-01-22 11:34:38 -0800 | [diff] [blame] | 968 | // Cancel any running enter animations at this point when we scroll or change focus |
| 969 | if (!mEnterAnimationComplete) { |
| 970 | cancelAllTaskViewAnimations(); |
| 971 | } |
| 972 | |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 973 | mLayoutAlgorithm.clearUnfocusedTaskOverrides(); |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 974 | willScroll = mAnimationHelper.startScrollToFocusedTaskAnimation(newFocusedTask, |
| 975 | requestViewFocus); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 976 | } else { |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 977 | // Focus the task view |
| 978 | TaskView newFocusedTaskView = getChildViewForTask(newFocusedTask); |
| 979 | if (newFocusedTaskView != null) { |
| 980 | newFocusedTaskView.setFocusedState(true, requestViewFocus); |
| 981 | } |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 982 | } |
Jiaquan He | 21f495f | 2017-01-05 13:00:29 -0800 | [diff] [blame] | 983 | // Any time a task view gets the focus, we move the focus frame around it. |
| 984 | if (mTaskViewFocusFrame != null) { |
| 985 | mTaskViewFocusFrame.moveGridTaskViewFocus(getChildViewForTask(newFocusedTask)); |
| 986 | } |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 987 | } |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 988 | return willScroll; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 989 | } |
| 990 | |
Winson Chung | d213a1e | 2014-10-02 11:18:30 -0700 | [diff] [blame] | 991 | /** |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 992 | * Sets the focused task relative to the currently focused task. |
| 993 | * |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 994 | * @param forward whether to go to the next task in the stack (along the curve) or the previous |
Winson | 1b58561 | 2015-11-06 09:16:26 -0800 | [diff] [blame] | 995 | * @param stackTasksOnly if set, will ensure that the traversal only goes along stack tasks, and |
| 996 | * if the currently focused task is not a stack task, will set the focus |
| 997 | * to the first visible stack task |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 998 | * @param animated determines whether to actually draw the highlight along with the change in |
| 999 | * focus. |
Winson Chung | d213a1e | 2014-10-02 11:18:30 -0700 | [diff] [blame] | 1000 | */ |
Winson | 1b58561 | 2015-11-06 09:16:26 -0800 | [diff] [blame] | 1001 | public void setRelativeFocusedTask(boolean forward, boolean stackTasksOnly, boolean animated) { |
Winson | f000988 | 2016-06-01 12:22:55 -0700 | [diff] [blame] | 1002 | setRelativeFocusedTask(forward, stackTasksOnly, animated, false, 0); |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | /** |
| 1006 | * Sets the focused task relative to the currently focused task. |
| 1007 | * |
| 1008 | * @param forward whether to go to the next task in the stack (along the curve) or the previous |
| 1009 | * @param stackTasksOnly if set, will ensure that the traversal only goes along stack tasks, and |
| 1010 | * if the currently focused task is not a stack task, will set the focus |
| 1011 | * to the first visible stack task |
| 1012 | * @param animated determines whether to actually draw the highlight along with the change in |
| 1013 | * focus. |
| 1014 | * @param cancelWindowAnimations if set, will attempt to cancel window animations if a scroll |
| 1015 | * happens. |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 1016 | * @param timerIndicatorDuration the duration to initialize the auto-advance timer indicator |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 1017 | */ |
| 1018 | public void setRelativeFocusedTask(boolean forward, boolean stackTasksOnly, boolean animated, |
Winson | f000988 | 2016-06-01 12:22:55 -0700 | [diff] [blame] | 1019 | boolean cancelWindowAnimations, int timerIndicatorDuration) { |
| 1020 | Task focusedTask = getFocusedTask(); |
| 1021 | int newIndex = mStack.indexOfStackTask(focusedTask); |
| 1022 | if (focusedTask != null) { |
Winson | 1b58561 | 2015-11-06 09:16:26 -0800 | [diff] [blame] | 1023 | if (stackTasksOnly) { |
Winson | 250608a | 2015-11-24 15:00:31 -0800 | [diff] [blame] | 1024 | List<Task> tasks = mStack.getStackTasks(); |
Winson | f000988 | 2016-06-01 12:22:55 -0700 | [diff] [blame] | 1025 | if (focusedTask.isFreeformTask()) { |
Winson | 1b58561 | 2015-11-06 09:16:26 -0800 | [diff] [blame] | 1026 | // Try and focus the front most stack task |
| 1027 | TaskView tv = getFrontMostTaskView(stackTasksOnly); |
| 1028 | if (tv != null) { |
Winson | 250608a | 2015-11-24 15:00:31 -0800 | [diff] [blame] | 1029 | newIndex = mStack.indexOfStackTask(tv.getTask()); |
Winson | 1b58561 | 2015-11-06 09:16:26 -0800 | [diff] [blame] | 1030 | } |
| 1031 | } else { |
| 1032 | // Try the next task if it is a stack task |
Winson | aaf33bc | 2015-12-03 12:02:38 -0800 | [diff] [blame] | 1033 | int tmpNewIndex = newIndex + (forward ? -1 : 1); |
Winson | 1b58561 | 2015-11-06 09:16:26 -0800 | [diff] [blame] | 1034 | if (0 <= tmpNewIndex && tmpNewIndex < tasks.size()) { |
| 1035 | Task t = tasks.get(tmpNewIndex); |
| 1036 | if (!t.isFreeformTask()) { |
| 1037 | newIndex = tmpNewIndex; |
| 1038 | } |
| 1039 | } |
| 1040 | } |
| 1041 | } else { |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 1042 | // No restrictions, lets just move to the new task (looping forward/backwards if |
| 1043 | // necessary) |
Winson | 4b057c6 | 2016-01-12 15:01:52 -0800 | [diff] [blame] | 1044 | int taskCount = mStack.getTaskCount(); |
Winson | aaf33bc | 2015-12-03 12:02:38 -0800 | [diff] [blame] | 1045 | newIndex = (newIndex + (forward ? -1 : 1) + taskCount) % taskCount; |
Winson | 1b58561 | 2015-11-06 09:16:26 -0800 | [diff] [blame] | 1046 | } |
| 1047 | } else { |
Winson | 23b0d3f | 2016-02-15 17:43:01 -0800 | [diff] [blame] | 1048 | // We don't have a focused task |
| 1049 | float stackScroll = mStackScroller.getStackScroll(); |
| 1050 | ArrayList<Task> tasks = mStack.getStackTasks(); |
| 1051 | int taskCount = tasks.size(); |
Jiaquan He | 21f495f | 2017-01-05 13:00:29 -0800 | [diff] [blame] | 1052 | if (useGridLayout()) { |
| 1053 | // For the grid layout, we directly set focus to the most recently used task |
| 1054 | // no matter we're moving forwards or backwards. |
| 1055 | newIndex = taskCount - 1; |
Winson | 23b0d3f | 2016-02-15 17:43:01 -0800 | [diff] [blame] | 1056 | } else { |
Jiaquan He | 21f495f | 2017-01-05 13:00:29 -0800 | [diff] [blame] | 1057 | // For the grid layout we pick a proper task to focus, according to the current |
| 1058 | // stack scroll. |
| 1059 | if (forward) { |
| 1060 | // Walk backwards and focus the next task smaller than the current stack scroll |
| 1061 | for (newIndex = taskCount - 1; newIndex >= 0; newIndex--) { |
| 1062 | float taskP = mLayoutAlgorithm.getStackScrollForTask(tasks.get(newIndex)); |
| 1063 | if (Float.compare(taskP, stackScroll) <= 0) { |
| 1064 | break; |
| 1065 | } |
| 1066 | } |
| 1067 | } else { |
| 1068 | // Walk forwards and focus the next task larger than the current stack scroll |
| 1069 | for (newIndex = 0; newIndex < taskCount; newIndex++) { |
| 1070 | float taskP = mLayoutAlgorithm.getStackScrollForTask(tasks.get(newIndex)); |
| 1071 | if (Float.compare(taskP, stackScroll) >= 0) { |
| 1072 | break; |
| 1073 | } |
Winson | 23b0d3f | 2016-02-15 17:43:01 -0800 | [diff] [blame] | 1074 | } |
| 1075 | } |
Winson | 1b58561 | 2015-11-06 09:16:26 -0800 | [diff] [blame] | 1076 | } |
| 1077 | } |
| 1078 | if (newIndex != -1) { |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 1079 | boolean willScroll = setFocusedTask(newIndex, true /* scrollToTask */, |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 1080 | true /* requestViewFocus */, timerIndicatorDuration); |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 1081 | if (willScroll && cancelWindowAnimations) { |
| 1082 | // As we iterate to the next/previous task, cancel any current/lagging window |
| 1083 | // transition animations |
| 1084 | EventBus.getDefault().send(new CancelEnterRecentsWindowAnimationEvent(null)); |
| 1085 | } |
Winson | 1b58561 | 2015-11-06 09:16:26 -0800 | [diff] [blame] | 1086 | } |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 1087 | } |
| 1088 | |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 1089 | /** |
| 1090 | * Resets the focused task. |
| 1091 | */ |
Jiaquan He | 21f495f | 2017-01-05 13:00:29 -0800 | [diff] [blame] | 1092 | public void resetFocusedTask(Task task) { |
Winson | a0731a1 | 2015-12-02 15:10:14 -0800 | [diff] [blame] | 1093 | if (task != null) { |
| 1094 | TaskView tv = getChildViewForTask(task); |
Winson Chung | fc33cdf | 2014-12-03 13:16:48 -0800 | [diff] [blame] | 1095 | if (tv != null) { |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 1096 | tv.setFocusedState(false, false /* requestViewFocus */); |
Winson Chung | fc33cdf | 2014-12-03 13:16:48 -0800 | [diff] [blame] | 1097 | } |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 1098 | } |
Jiaquan He | 21f495f | 2017-01-05 13:00:29 -0800 | [diff] [blame] | 1099 | if (mTaskViewFocusFrame != null) { |
| 1100 | mTaskViewFocusFrame.moveGridTaskViewFocus(null); |
| 1101 | } |
Winson | aaf33bc | 2015-12-03 12:02:38 -0800 | [diff] [blame] | 1102 | mFocusedTask = null; |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 1103 | } |
| 1104 | |
Winson | 142af42 | 2015-11-09 10:39:57 -0800 | [diff] [blame] | 1105 | /** |
| 1106 | * Returns the focused task. |
| 1107 | */ |
Jiaquan He | 21f495f | 2017-01-05 13:00:29 -0800 | [diff] [blame] | 1108 | public Task getFocusedTask() { |
Winson | aaf33bc | 2015-12-03 12:02:38 -0800 | [diff] [blame] | 1109 | return mFocusedTask; |
Winson | 142af42 | 2015-11-09 10:39:57 -0800 | [diff] [blame] | 1110 | } |
| 1111 | |
Winson | f000988 | 2016-06-01 12:22:55 -0700 | [diff] [blame] | 1112 | /** |
| 1113 | * Returns the accessibility focused task. |
| 1114 | */ |
| 1115 | Task getAccessibilityFocusedTask() { |
| 1116 | List<TaskView> taskViews = getTaskViews(); |
| 1117 | int taskViewCount = taskViews.size(); |
| 1118 | for (int i = 0; i < taskViewCount; i++) { |
| 1119 | TaskView tv = taskViews.get(i); |
| 1120 | if (Utilities.isDescendentAccessibilityFocused(tv)) { |
| 1121 | return tv.getTask(); |
| 1122 | } |
| 1123 | } |
| 1124 | TaskView frontTv = getFrontMostTaskView(true /* stackTasksOnly */); |
| 1125 | if (frontTv != null) { |
| 1126 | return frontTv.getTask(); |
| 1127 | } |
| 1128 | return null; |
| 1129 | } |
| 1130 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1131 | @Override |
Winson Chung | ee44595 | 2014-09-09 16:12:59 +0200 | [diff] [blame] | 1132 | public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
| 1133 | super.onInitializeAccessibilityEvent(event); |
Winson Chung | 6ac8bd6 | 2015-01-07 16:38:35 -0800 | [diff] [blame] | 1134 | List<TaskView> taskViews = getTaskViews(); |
| 1135 | int taskViewCount = taskViews.size(); |
| 1136 | if (taskViewCount > 0) { |
| 1137 | TaskView backMostTask = taskViews.get(0); |
| 1138 | TaskView frontMostTask = taskViews.get(taskViewCount - 1); |
Winson | 250608a | 2015-11-24 15:00:31 -0800 | [diff] [blame] | 1139 | event.setFromIndex(mStack.indexOfStackTask(backMostTask.getTask())); |
| 1140 | event.setToIndex(mStack.indexOfStackTask(frontMostTask.getTask())); |
Winson Chung | 296278a | 2015-12-17 12:09:02 -0500 | [diff] [blame] | 1141 | event.setContentDescription(frontMostTask.getTask().title); |
Winson Chung | ee44595 | 2014-09-09 16:12:59 +0200 | [diff] [blame] | 1142 | } |
Winson | 4b057c6 | 2016-01-12 15:01:52 -0800 | [diff] [blame] | 1143 | event.setItemCount(mStack.getTaskCount()); |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 1144 | |
| 1145 | int stackHeight = mLayoutAlgorithm.mStackRect.height(); |
| 1146 | event.setScrollY((int) (mStackScroller.getStackScroll() * stackHeight)); |
| 1147 | event.setMaxScrollY((int) (mLayoutAlgorithm.mMaxScrollP * stackHeight)); |
Winson Chung | ee44595 | 2014-09-09 16:12:59 +0200 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | @Override |
Winson Chung | 83ea6f7 | 2015-06-17 13:00:23 -0700 | [diff] [blame] | 1151 | public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { |
| 1152 | super.onInitializeAccessibilityNodeInfo(info); |
| 1153 | List<TaskView> taskViews = getTaskViews(); |
| 1154 | int taskViewCount = taskViews.size(); |
Winson | f000988 | 2016-06-01 12:22:55 -0700 | [diff] [blame] | 1155 | if (taskViewCount > 1) { |
| 1156 | // Find the accessibility focused task |
| 1157 | Task focusedTask = getAccessibilityFocusedTask(); |
Winson Chung | 83ea6f7 | 2015-06-17 13:00:23 -0700 | [diff] [blame] | 1158 | info.setScrollable(true); |
Winson | f000988 | 2016-06-01 12:22:55 -0700 | [diff] [blame] | 1159 | int focusedTaskIndex = mStack.indexOfStackTask(focusedTask); |
Winson | aaf33bc | 2015-12-03 12:02:38 -0800 | [diff] [blame] | 1160 | if (focusedTaskIndex > 0) { |
Winson Chung | 83ea6f7 | 2015-06-17 13:00:23 -0700 | [diff] [blame] | 1161 | info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD); |
| 1162 | } |
Winson | f000988 | 2016-06-01 12:22:55 -0700 | [diff] [blame] | 1163 | if (0 <= focusedTaskIndex && focusedTaskIndex < mStack.getTaskCount() - 1) { |
| 1164 | info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD); |
| 1165 | } |
Winson Chung | 83ea6f7 | 2015-06-17 13:00:23 -0700 | [diff] [blame] | 1166 | } |
| 1167 | } |
| 1168 | |
| 1169 | @Override |
| 1170 | public CharSequence getAccessibilityClassName() { |
Winson | f000988 | 2016-06-01 12:22:55 -0700 | [diff] [blame] | 1171 | return ScrollView.class.getName(); |
Winson Chung | 83ea6f7 | 2015-06-17 13:00:23 -0700 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | @Override |
| 1175 | public boolean performAccessibilityAction(int action, Bundle arguments) { |
| 1176 | if (super.performAccessibilityAction(action, arguments)) { |
| 1177 | return true; |
| 1178 | } |
Winson | f000988 | 2016-06-01 12:22:55 -0700 | [diff] [blame] | 1179 | Task focusedTask = getAccessibilityFocusedTask(); |
| 1180 | int taskIndex = mStack.indexOfStackTask(focusedTask); |
| 1181 | if (0 <= taskIndex && taskIndex < mStack.getTaskCount()) { |
| 1182 | switch (action) { |
| 1183 | case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD: { |
| 1184 | setFocusedTask(taskIndex + 1, true /* scrollToTask */, true /* requestViewFocus */, |
| 1185 | 0); |
| 1186 | return true; |
| 1187 | } |
| 1188 | case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD: { |
| 1189 | setFocusedTask(taskIndex - 1, true /* scrollToTask */, true /* requestViewFocus */, |
| 1190 | 0); |
| 1191 | return true; |
| 1192 | } |
Winson Chung | 83ea6f7 | 2015-06-17 13:00:23 -0700 | [diff] [blame] | 1193 | } |
| 1194 | } |
| 1195 | return false; |
| 1196 | } |
| 1197 | |
| 1198 | @Override |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1199 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
| 1200 | return mTouchHandler.onInterceptTouchEvent(ev); |
| 1201 | } |
| 1202 | |
| 1203 | @Override |
| 1204 | public boolean onTouchEvent(MotionEvent ev) { |
| 1205 | return mTouchHandler.onTouchEvent(ev); |
| 1206 | } |
| 1207 | |
| 1208 | @Override |
Winson Chung | d213a1e | 2014-10-02 11:18:30 -0700 | [diff] [blame] | 1209 | public boolean onGenericMotionEvent(MotionEvent ev) { |
| 1210 | return mTouchHandler.onGenericMotionEvent(ev); |
| 1211 | } |
| 1212 | |
| 1213 | @Override |
Winson Chung | d7b2cb1 | 2014-06-26 15:08:50 -0700 | [diff] [blame] | 1214 | public void computeScroll() { |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 1215 | if (mStackScroller.computeScroll()) { |
| 1216 | // Notify accessibility |
| 1217 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SCROLLED); |
Jorim Jaggi | 6f9dbcb | 2017-03-17 17:22:47 +0100 | [diff] [blame] | 1218 | Recents.getTaskLoader().getHighResThumbnailLoader().setFlingingFast( |
| 1219 | mStackScroller.getScrollVelocity() > mFastFlingVelocity); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 1220 | } |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 1221 | if (mDeferredTaskViewLayoutAnimation != null) { |
| 1222 | relayoutTaskViews(mDeferredTaskViewLayoutAnimation); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 1223 | mTaskViewsClipDirty = true; |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 1224 | mDeferredTaskViewLayoutAnimation = null; |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 1225 | } |
| 1226 | if (mTaskViewsClipDirty) { |
| 1227 | clipTaskViews(); |
| 1228 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1229 | } |
| 1230 | |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 1231 | /** |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 1232 | * Computes the maximum number of visible tasks and thumbnails. Requires that |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 1233 | * updateLayoutForStack() is called first. |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 1234 | */ |
Winson | 36a5a2c | 2015-10-29 18:04:39 -0700 | [diff] [blame] | 1235 | public TaskStackLayoutAlgorithm.VisibilityReport computeStackVisibilityReport() { |
Winson | 250608a | 2015-11-24 15:00:31 -0800 | [diff] [blame] | 1236 | return mLayoutAlgorithm.computeStackVisibilityReport(mStack.getStackTasks()); |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 1237 | } |
| 1238 | |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 1239 | /** |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 1240 | * Updates the system insets. |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 1241 | */ |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 1242 | public void setSystemInsets(Rect systemInsets) { |
Winson | 67c7957 | 2016-04-13 14:02:18 -0700 | [diff] [blame] | 1243 | boolean changed = false; |
| 1244 | changed |= mStableLayoutAlgorithm.setSystemInsets(systemInsets); |
| 1245 | changed |= mLayoutAlgorithm.setSystemInsets(systemInsets); |
| 1246 | if (changed) { |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 1247 | requestLayout(); |
| 1248 | } |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 1249 | } |
| 1250 | |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 1251 | /** |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1252 | * This is called with the full window width and height to allow stack view children to |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 1253 | * perform the full screen transition down. |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 1254 | */ |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1255 | @Override |
| 1256 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
Winson | 70f0bf7 | 2016-02-01 14:05:29 -0800 | [diff] [blame] | 1257 | mInMeasureLayout = true; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1258 | int width = MeasureSpec.getSize(widthMeasureSpec); |
| 1259 | int height = MeasureSpec.getSize(heightMeasureSpec); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1260 | |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 1261 | // Update the stable stack bounds, but only update the current stack bounds if the stable |
| 1262 | // bounds have changed. This is because we may get spurious measures while dragging where |
| 1263 | // our current stack bounds reflect the target drop region. |
Winson | fc48b07 | 2016-04-21 11:20:11 -0700 | [diff] [blame] | 1264 | mLayoutAlgorithm.getTaskStackBounds(mDisplayRect, new Rect(0, 0, width, height), |
Winson | cbb625b | 2016-07-06 15:24:15 -0700 | [diff] [blame] | 1265 | mLayoutAlgorithm.mSystemInsets.top, mLayoutAlgorithm.mSystemInsets.left, |
| 1266 | mLayoutAlgorithm.mSystemInsets.right, mTmpRect); |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 1267 | if (!mTmpRect.equals(mStableStackBounds)) { |
| 1268 | mStableStackBounds.set(mTmpRect); |
| 1269 | mStackBounds.set(mTmpRect); |
| 1270 | mStableWindowRect.set(0, 0, width, height); |
| 1271 | mWindowRect.set(0, 0, width, height); |
| 1272 | } |
| 1273 | |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 1274 | // Compute the rects in the stack algorithm |
Winson | fc48b07 | 2016-04-21 11:20:11 -0700 | [diff] [blame] | 1275 | mStableLayoutAlgorithm.initialize(mDisplayRect, mStableWindowRect, mStableStackBounds, |
Winson | f9357d9 | 2016-03-25 15:14:37 -0700 | [diff] [blame] | 1276 | TaskStackLayoutAlgorithm.StackState.getStackStateForStack(mStack)); |
Winson | fc48b07 | 2016-04-21 11:20:11 -0700 | [diff] [blame] | 1277 | mLayoutAlgorithm.initialize(mDisplayRect, mWindowRect, mStackBounds, |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 1278 | TaskStackLayoutAlgorithm.StackState.getStackStateForStack(mStack)); |
Winson | 67c7957 | 2016-04-13 14:02:18 -0700 | [diff] [blame] | 1279 | updateLayoutAlgorithm(false /* boundScroll */); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1280 | |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 1281 | // If this is the first layout, then scroll to the front of the stack, then update the |
| 1282 | // TaskViews with the stack so that we can lay them out |
Jorim Jaggi | db21bbd | 2016-04-18 15:32:07 -0700 | [diff] [blame] | 1283 | boolean resetToInitialState = (width != mLastWidth || height != mLastHeight) |
| 1284 | && mResetToInitialStateWhenResized; |
| 1285 | if (mAwaitingFirstLayout || mInitialState != INITIAL_STATE_UPDATE_NONE |
| 1286 | || resetToInitialState) { |
| 1287 | if (mInitialState != INITIAL_STATE_UPDATE_LAYOUT_ONLY || resetToInitialState) { |
Winson | 67c7957 | 2016-04-13 14:02:18 -0700 | [diff] [blame] | 1288 | updateToInitialState(); |
Jorim Jaggi | db21bbd | 2016-04-18 15:32:07 -0700 | [diff] [blame] | 1289 | mResetToInitialStateWhenResized = false; |
Winson | 67c7957 | 2016-04-13 14:02:18 -0700 | [diff] [blame] | 1290 | } |
Winson | 670ea71 | 2016-04-12 17:02:26 -0700 | [diff] [blame] | 1291 | if (!mAwaitingFirstLayout) { |
| 1292 | mInitialState = INITIAL_STATE_UPDATE_NONE; |
| 1293 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1294 | } |
Winson | bd53a31 | 2016-09-21 12:13:32 -0700 | [diff] [blame] | 1295 | // If we got the launch-next event before the first layout pass, then re-send it after the |
| 1296 | // initial state has been updated |
| 1297 | if (mLaunchNextAfterFirstMeasure) { |
| 1298 | mLaunchNextAfterFirstMeasure = false; |
| 1299 | EventBus.getDefault().post(new LaunchNextTaskRequestEvent()); |
| 1300 | } |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 1301 | |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 1302 | // Rebind all the views, including the ignore ones |
Winson | d2a0306 | 2016-04-15 11:19:07 -0700 | [diff] [blame] | 1303 | bindVisibleTaskViews(mStackScroller.getStackScroll(), false /* ignoreTaskOverrides */); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1304 | |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 1305 | // Measure each of the TaskViews |
Winson | a2236f1 | 2015-11-13 16:10:01 -0800 | [diff] [blame] | 1306 | mTmpTaskViews.clear(); |
| 1307 | mTmpTaskViews.addAll(getTaskViews()); |
| 1308 | mTmpTaskViews.addAll(mViewPool.getViews()); |
| 1309 | int taskViewCount = mTmpTaskViews.size(); |
Winson Chung | 6ac8bd6 | 2015-01-07 16:38:35 -0800 | [diff] [blame] | 1310 | for (int i = 0; i < taskViewCount; i++) { |
Winson | 70f0bf7 | 2016-02-01 14:05:29 -0800 | [diff] [blame] | 1311 | measureTaskView(mTmpTaskViews.get(i)); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1312 | } |
Jiaquan He | 21f495f | 2017-01-05 13:00:29 -0800 | [diff] [blame] | 1313 | if (mTaskViewFocusFrame != null) { |
| 1314 | mTaskViewFocusFrame.measure(); |
| 1315 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1316 | |
| 1317 | setMeasuredDimension(width, height); |
Jorim Jaggi | db21bbd | 2016-04-18 15:32:07 -0700 | [diff] [blame] | 1318 | mLastWidth = width; |
| 1319 | mLastHeight = height; |
Winson | 70f0bf7 | 2016-02-01 14:05:29 -0800 | [diff] [blame] | 1320 | mInMeasureLayout = false; |
| 1321 | } |
| 1322 | |
| 1323 | /** |
| 1324 | * Measures a TaskView. |
| 1325 | */ |
| 1326 | private void measureTaskView(TaskView tv) { |
Winson | 67c7957 | 2016-04-13 14:02:18 -0700 | [diff] [blame] | 1327 | Rect padding = new Rect(); |
Winson | 70f0bf7 | 2016-02-01 14:05:29 -0800 | [diff] [blame] | 1328 | if (tv.getBackground() != null) { |
Winson | 67c7957 | 2016-04-13 14:02:18 -0700 | [diff] [blame] | 1329 | tv.getBackground().getPadding(padding); |
Winson | 70f0bf7 | 2016-02-01 14:05:29 -0800 | [diff] [blame] | 1330 | } |
Jiaquan He | 8f34df4 | 2016-12-27 15:38:44 -0800 | [diff] [blame] | 1331 | mTmpRect.set(mStableLayoutAlgorithm.getTaskRect()); |
| 1332 | mTmpRect.union(mLayoutAlgorithm.getTaskRect()); |
Winson | 70f0bf7 | 2016-02-01 14:05:29 -0800 | [diff] [blame] | 1333 | tv.measure( |
Winson | 67c7957 | 2016-04-13 14:02:18 -0700 | [diff] [blame] | 1334 | MeasureSpec.makeMeasureSpec(mTmpRect.width() + padding.left + padding.right, |
Winson | 70f0bf7 | 2016-02-01 14:05:29 -0800 | [diff] [blame] | 1335 | MeasureSpec.EXACTLY), |
Winson | 67c7957 | 2016-04-13 14:02:18 -0700 | [diff] [blame] | 1336 | MeasureSpec.makeMeasureSpec(mTmpRect.height() + padding.top + padding.bottom, |
Winson | 70f0bf7 | 2016-02-01 14:05:29 -0800 | [diff] [blame] | 1337 | MeasureSpec.EXACTLY)); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | @Override |
| 1341 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
Winson | 36a5a2c | 2015-10-29 18:04:39 -0700 | [diff] [blame] | 1342 | // Layout each of the TaskViews |
Winson | a2236f1 | 2015-11-13 16:10:01 -0800 | [diff] [blame] | 1343 | mTmpTaskViews.clear(); |
| 1344 | mTmpTaskViews.addAll(getTaskViews()); |
| 1345 | mTmpTaskViews.addAll(mViewPool.getViews()); |
| 1346 | int taskViewCount = mTmpTaskViews.size(); |
Winson Chung | 6ac8bd6 | 2015-01-07 16:38:35 -0800 | [diff] [blame] | 1347 | for (int i = 0; i < taskViewCount; i++) { |
Winson | c69249f | 2016-03-28 13:38:39 -0700 | [diff] [blame] | 1348 | layoutTaskView(changed, mTmpTaskViews.get(i)); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1349 | } |
Jiaquan He | 21f495f | 2017-01-05 13:00:29 -0800 | [diff] [blame] | 1350 | if (mTaskViewFocusFrame != null) { |
| 1351 | mTaskViewFocusFrame.layout(); |
| 1352 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1353 | |
Jorim Jaggi | 7af8ea8 | 2015-11-09 15:28:34 +0100 | [diff] [blame] | 1354 | if (changed) { |
Winson | a2236f1 | 2015-11-13 16:10:01 -0800 | [diff] [blame] | 1355 | if (mStackScroller.isScrollOutOfBounds()) { |
| 1356 | mStackScroller.boundScroll(); |
| 1357 | } |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 1358 | } |
Winson | c69249f | 2016-03-28 13:38:39 -0700 | [diff] [blame] | 1359 | |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 1360 | // Relayout all of the task views including the ignored ones |
Winson | 67c7957 | 2016-04-13 14:02:18 -0700 | [diff] [blame] | 1361 | relayoutTaskViews(AnimationProps.IMMEDIATE); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 1362 | clipTaskViews(); |
| 1363 | |
| 1364 | if (mAwaitingFirstLayout || !mEnterAnimationComplete) { |
| 1365 | mAwaitingFirstLayout = false; |
Winson | 670ea71 | 2016-04-12 17:02:26 -0700 | [diff] [blame] | 1366 | mInitialState = INITIAL_STATE_UPDATE_NONE; |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 1367 | onFirstLayout(); |
Jorim Jaggi | 7af8ea8 | 2015-11-09 15:28:34 +0100 | [diff] [blame] | 1368 | } |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 1369 | } |
Winson Chung | 24cf152 | 2014-05-29 12:03:33 -0700 | [diff] [blame] | 1370 | |
Winson | 70f0bf7 | 2016-02-01 14:05:29 -0800 | [diff] [blame] | 1371 | /** |
| 1372 | * Lays out a TaskView. |
| 1373 | */ |
Winson | c69249f | 2016-03-28 13:38:39 -0700 | [diff] [blame] | 1374 | private void layoutTaskView(boolean changed, TaskView tv) { |
| 1375 | if (changed) { |
Winson | 67c7957 | 2016-04-13 14:02:18 -0700 | [diff] [blame] | 1376 | Rect padding = new Rect(); |
Winson | c69249f | 2016-03-28 13:38:39 -0700 | [diff] [blame] | 1377 | if (tv.getBackground() != null) { |
Winson | 67c7957 | 2016-04-13 14:02:18 -0700 | [diff] [blame] | 1378 | tv.getBackground().getPadding(padding); |
Winson | c69249f | 2016-03-28 13:38:39 -0700 | [diff] [blame] | 1379 | } |
Jiaquan He | 8f34df4 | 2016-12-27 15:38:44 -0800 | [diff] [blame] | 1380 | mTmpRect.set(mStableLayoutAlgorithm.getTaskRect()); |
| 1381 | mTmpRect.union(mLayoutAlgorithm.getTaskRect()); |
Winson | c69249f | 2016-03-28 13:38:39 -0700 | [diff] [blame] | 1382 | tv.cancelTransformAnimation(); |
Winson | 67c7957 | 2016-04-13 14:02:18 -0700 | [diff] [blame] | 1383 | tv.layout(mTmpRect.left - padding.left, mTmpRect.top - padding.top, |
| 1384 | mTmpRect.right + padding.right, mTmpRect.bottom + padding.bottom); |
Winson | 70f0bf7 | 2016-02-01 14:05:29 -0800 | [diff] [blame] | 1385 | } else { |
Winson | c69249f | 2016-03-28 13:38:39 -0700 | [diff] [blame] | 1386 | // If the layout has not changed, then just lay it out again in-place |
| 1387 | tv.layout(tv.getLeft(), tv.getTop(), tv.getRight(), tv.getBottom()); |
Winson | 70f0bf7 | 2016-02-01 14:05:29 -0800 | [diff] [blame] | 1388 | } |
Winson | 70f0bf7 | 2016-02-01 14:05:29 -0800 | [diff] [blame] | 1389 | } |
| 1390 | |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 1391 | /** Handler for the first layout. */ |
| 1392 | void onFirstLayout() { |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 1393 | // Setup the view for the enter animation |
| 1394 | mAnimationHelper.prepareForEnterAnimation(); |
Winson Chung | 083baf9 | 2014-07-11 10:32:42 -0700 | [diff] [blame] | 1395 | |
Winson | a78a8f3 | 2015-12-03 10:55:01 -0800 | [diff] [blame] | 1396 | // Animate in the freeform workspace |
Winson | be8e696 | 2016-02-01 14:27:52 -0800 | [diff] [blame] | 1397 | int ffBgAlpha = mLayoutAlgorithm.getStackState().freeformBackgroundAlpha; |
| 1398 | animateFreeformWorkspaceBackgroundAlpha(ffBgAlpha, new AnimationProps(150, |
| 1399 | Interpolators.FAST_OUT_SLOW_IN)); |
Winson | a78a8f3 | 2015-12-03 10:55:01 -0800 | [diff] [blame] | 1400 | |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 1401 | // Set the task focused state without requesting view focus, and leave the focus animations |
| 1402 | // until after the enter-animation |
Winson | 5da4347 | 2015-11-04 17:39:55 -0800 | [diff] [blame] | 1403 | RecentsConfiguration config = Recents.getConfiguration(); |
| 1404 | RecentsActivityLaunchState launchState = config.getLaunchState(); |
Jiaquan He | 21f495f | 2017-01-05 13:00:29 -0800 | [diff] [blame] | 1405 | |
| 1406 | // We set the initial focused task view iff the following conditions are satisfied: |
| 1407 | // 1. Recents is showing task views in stack layout. |
| 1408 | // 2. Recents is launched with ALT + TAB. |
| 1409 | boolean setFocusOnFirstLayout = !useGridLayout() || |
| 1410 | Recents.getConfiguration().getLaunchState().launchedWithAltTab; |
| 1411 | if (setFocusOnFirstLayout) { |
| 1412 | int focusedTaskIndex = launchState.getInitialFocusTaskIndex(mStack.getTaskCount(), |
| 1413 | useGridLayout()); |
| 1414 | if (focusedTaskIndex != -1) { |
| 1415 | setFocusedTask(focusedTaskIndex, false /* scrollToTask */, |
| 1416 | false /* requestViewFocus */); |
| 1417 | } |
Winson | 0983e02 | 2015-10-13 17:21:42 -0700 | [diff] [blame] | 1418 | } |
Manu Cornet | 5db30f0 | 2016-12-19 17:02:59 -0800 | [diff] [blame] | 1419 | updateStackActionButtonVisibility(); |
Winson Chung | 24cf152 | 2014-05-29 12:03:33 -0700 | [diff] [blame] | 1420 | } |
| 1421 | |
Winson | 671e8f9 | 2016-01-12 13:16:56 -0800 | [diff] [blame] | 1422 | public boolean isTouchPointInView(float x, float y, TaskView tv) { |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 1423 | mTmpRect.set(tv.getLeft(), tv.getTop(), tv.getRight(), tv.getBottom()); |
| 1424 | mTmpRect.offset((int) tv.getTranslationX(), (int) tv.getTranslationY()); |
| 1425 | return mTmpRect.contains((int) x, (int) y); |
| 1426 | } |
| 1427 | |
| 1428 | /** |
| 1429 | * Returns a non-ignored task in the {@param tasks} list that can be used as an achor when |
| 1430 | * calculating the scroll position before and after a layout change. |
| 1431 | */ |
| 1432 | public Task findAnchorTask(List<Task> tasks, MutableBoolean isFrontMostTask) { |
| 1433 | for (int i = tasks.size() - 1; i >= 0; i--) { |
| 1434 | Task task = tasks.get(i); |
| 1435 | |
| 1436 | // Ignore deleting tasks |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 1437 | if (isIgnoredTask(task)) { |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 1438 | if (i == tasks.size() - 1) { |
| 1439 | isFrontMostTask.value = true; |
| 1440 | } |
| 1441 | continue; |
| 1442 | } |
| 1443 | return task; |
| 1444 | } |
| 1445 | return null; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1446 | } |
| 1447 | |
Jorim Jaggi | 900fb48 | 2015-06-02 15:07:33 -0700 | [diff] [blame] | 1448 | @Override |
Winson | be8e696 | 2016-02-01 14:27:52 -0800 | [diff] [blame] | 1449 | protected void onDraw(Canvas canvas) { |
| 1450 | super.onDraw(canvas); |
| 1451 | |
Winson | 36a5a2c | 2015-10-29 18:04:39 -0700 | [diff] [blame] | 1452 | // Draw the freeform workspace background |
Winson | 805578d | 2015-11-23 14:47:37 -0800 | [diff] [blame] | 1453 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 1454 | if (ssp.hasFreeformWorkspaceSupport()) { |
| 1455 | if (mFreeformWorkspaceBackground.getAlpha() > 0) { |
| 1456 | mFreeformWorkspaceBackground.draw(canvas); |
| 1457 | } |
Winson | 36a5a2c | 2015-10-29 18:04:39 -0700 | [diff] [blame] | 1458 | } |
Jorim Jaggi | 900fb48 | 2015-06-02 15:07:33 -0700 | [diff] [blame] | 1459 | } |
| 1460 | |
Winson | a78a8f3 | 2015-12-03 10:55:01 -0800 | [diff] [blame] | 1461 | @Override |
| 1462 | protected boolean verifyDrawable(Drawable who) { |
| 1463 | if (who == mFreeformWorkspaceBackground) { |
| 1464 | return true; |
| 1465 | } |
| 1466 | return super.verifyDrawable(who); |
| 1467 | } |
| 1468 | |
Winson | a5e6b36 | 2015-11-02 17:17:20 -0800 | [diff] [blame] | 1469 | /** |
| 1470 | * Launches the freeform tasks. |
| 1471 | */ |
| 1472 | public boolean launchFreeformTasks() { |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 1473 | ArrayList<Task> tasks = mStack.getFreeformTasks(); |
| 1474 | if (!tasks.isEmpty()) { |
| 1475 | Task frontTask = tasks.get(tasks.size() - 1); |
| 1476 | if (frontTask != null && frontTask.isFreeformTask()) { |
| 1477 | EventBus.getDefault().send(new LaunchTaskEvent(getChildViewForTask(frontTask), |
| 1478 | frontTask, null, INVALID_STACK_ID, false)); |
| 1479 | return true; |
| 1480 | } |
Winson | a5e6b36 | 2015-11-02 17:17:20 -0800 | [diff] [blame] | 1481 | } |
| 1482 | return false; |
| 1483 | } |
| 1484 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1485 | /**** TaskStackCallbacks Implementation ****/ |
| 1486 | |
| 1487 | @Override |
Winson Chung | 0626677 | 2015-12-11 10:24:21 -0500 | [diff] [blame] | 1488 | public void onStackTaskAdded(TaskStack stack, Task newTask) { |
| 1489 | // Update the min/max scroll and animate other task views into their new positions |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 1490 | updateLayoutAlgorithm(true /* boundScroll */); |
Winson Chung | 0626677 | 2015-12-11 10:24:21 -0500 | [diff] [blame] | 1491 | |
| 1492 | // Animate all the tasks into place |
Winson | 409d99a | 2016-05-10 15:03:46 -0700 | [diff] [blame] | 1493 | relayoutTaskViews(mAwaitingFirstLayout |
| 1494 | ? AnimationProps.IMMEDIATE |
| 1495 | : new AnimationProps(DEFAULT_SYNC_STACK_DURATION, Interpolators.FAST_OUT_SLOW_IN)); |
Winson Chung | 0626677 | 2015-12-11 10:24:21 -0500 | [diff] [blame] | 1496 | } |
| 1497 | |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 1498 | /** |
| 1499 | * We expect that the {@link TaskView} associated with the removed task is already hidden. |
| 1500 | */ |
Winson Chung | 0626677 | 2015-12-11 10:24:21 -0500 | [diff] [blame] | 1501 | @Override |
Winson | 6c8217a | 2016-05-25 10:53:53 -0700 | [diff] [blame] | 1502 | public void onStackTaskRemoved(TaskStack stack, Task removedTask, Task newFrontMostTask, |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 1503 | AnimationProps animation, boolean fromDockGesture, boolean dismissRecentsIfAllRemoved) { |
Winson | aaf33bc | 2015-12-03 12:02:38 -0800 | [diff] [blame] | 1504 | if (mFocusedTask == removedTask) { |
Winson | a0731a1 | 2015-12-02 15:10:14 -0800 | [diff] [blame] | 1505 | resetFocusedTask(removedTask); |
| 1506 | } |
| 1507 | |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 1508 | // Remove the view associated with this task, we can't rely on updateTransforms |
| 1509 | // to work here because the task is no longer in the list |
| 1510 | TaskView tv = getChildViewForTask(removedTask); |
| 1511 | if (tv != null) { |
| 1512 | mViewPool.returnViewToPool(tv); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1513 | } |
| 1514 | |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 1515 | // Remove the task from the ignored set |
| 1516 | removeIgnoreTask(removedTask); |
| 1517 | |
| 1518 | // If requested, relayout with the given animation |
| 1519 | if (animation != null) { |
| 1520 | updateLayoutAlgorithm(true /* boundScroll */); |
| 1521 | relayoutTaskViews(animation); |
| 1522 | } |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 1523 | |
Winson Chung | 931c51f | 2015-12-17 17:08:55 -0500 | [diff] [blame] | 1524 | // Update the new front most task's action button |
| 1525 | if (mScreenPinningEnabled && newFrontMostTask != null) { |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 1526 | TaskView frontTv = getChildViewForTask(newFrontMostTask); |
| 1527 | if (frontTv != null) { |
Winson Chung | 931c51f | 2015-12-17 17:08:55 -0500 | [diff] [blame] | 1528 | frontTv.showActionButton(true /* fadeIn */, DEFAULT_SYNC_STACK_DURATION); |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 1529 | } |
| 1530 | } |
| 1531 | |
Winson | 397ae74 | 2015-11-20 11:27:33 -0800 | [diff] [blame] | 1532 | // If there are no remaining tasks, then just close recents |
Winson | 4b057c6 | 2016-01-12 15:01:52 -0800 | [diff] [blame] | 1533 | if (mStack.getTaskCount() == 0) { |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 1534 | if (dismissRecentsIfAllRemoved) { |
| 1535 | EventBus.getDefault().send(new AllTaskViewsDismissedEvent(fromDockGesture |
| 1536 | ? R.string.recents_empty_message |
| 1537 | : R.string.recents_empty_message_dismissed_all)); |
| 1538 | } else { |
| 1539 | EventBus.getDefault().send(new ShowEmptyViewEvent()); |
| 1540 | } |
Winson Chung | 9f49df9 | 2014-05-07 18:08:34 -0700 | [diff] [blame] | 1541 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1542 | } |
| 1543 | |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 1544 | @Override |
Winson | 3b6ba1a | 2016-03-22 15:37:54 -0700 | [diff] [blame] | 1545 | public void onStackTasksRemoved(TaskStack stack) { |
| 1546 | // Reset the focused task |
| 1547 | resetFocusedTask(getFocusedTask()); |
| 1548 | |
| 1549 | // Return all the views to the pool |
| 1550 | List<TaskView> taskViews = new ArrayList<>(); |
| 1551 | taskViews.addAll(getTaskViews()); |
| 1552 | for (int i = taskViews.size() - 1; i >= 0; i--) { |
| 1553 | mViewPool.returnViewToPool(taskViews.get(i)); |
| 1554 | } |
| 1555 | |
| 1556 | // Remove all the ignore tasks |
| 1557 | mIgnoreTasks.clear(); |
| 1558 | |
| 1559 | // If there are no remaining tasks, then just close recents |
| 1560 | EventBus.getDefault().send(new AllTaskViewsDismissedEvent( |
| 1561 | R.string.recents_empty_message_dismissed_all)); |
| 1562 | } |
| 1563 | |
| 1564 | @Override |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 1565 | public void onStackTasksUpdated(TaskStack stack) { |
Jorim Jaggi | cdef591 | 2017-04-03 17:24:19 +0200 | [diff] [blame] | 1566 | if (mAwaitingFirstLayout) { |
| 1567 | return; |
| 1568 | } |
| 1569 | |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 1570 | // Update the layout and immediately layout |
| 1571 | updateLayoutAlgorithm(false /* boundScroll */); |
| 1572 | relayoutTaskViews(AnimationProps.IMMEDIATE); |
| 1573 | |
| 1574 | // Rebind all the task views. This will not trigger new resources to be loaded |
| 1575 | // unless they have actually changed |
| 1576 | List<TaskView> taskViews = getTaskViews(); |
| 1577 | int taskViewCount = taskViews.size(); |
| 1578 | for (int i = 0; i < taskViewCount; i++) { |
| 1579 | TaskView tv = taskViews.get(i); |
| 1580 | bindTaskView(tv, tv.getTask()); |
| 1581 | } |
| 1582 | } |
| 1583 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1584 | /**** ViewPoolConsumer Implementation ****/ |
| 1585 | |
| 1586 | @Override |
| 1587 | public TaskView createView(Context context) { |
Jiaquan He | 5a2eb83 | 2016-12-13 14:36:37 -0800 | [diff] [blame] | 1588 | if (Recents.getConfiguration().isGridEnabled) { |
| 1589 | return (GridTaskView) mInflater.inflate(R.layout.recents_grid_task_view, this, false); |
| 1590 | } else { |
| 1591 | return (TaskView) mInflater.inflate(R.layout.recents_task_view, this, false); |
| 1592 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1593 | } |
| 1594 | |
| 1595 | @Override |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 1596 | public void onReturnViewToPool(TaskView tv) { |
Winson Chung | 931c51f | 2015-12-17 17:08:55 -0500 | [diff] [blame] | 1597 | final Task task = tv.getTask(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1598 | |
Winson | 4333694 | 2016-03-07 14:52:59 -0800 | [diff] [blame] | 1599 | // Unbind the task from the task view |
| 1600 | unbindTaskView(tv, task); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1601 | |
Winson Chung | 931c51f | 2015-12-17 17:08:55 -0500 | [diff] [blame] | 1602 | // Reset the view properties and view state |
Winson | f000988 | 2016-06-01 12:22:55 -0700 | [diff] [blame] | 1603 | tv.clearAccessibilityFocus(); |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 1604 | tv.resetViewProperties(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 1605 | tv.setFocusedState(false, false /* requestViewFocus */); |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 1606 | tv.setClipViewInStack(false); |
Winson Chung | 931c51f | 2015-12-17 17:08:55 -0500 | [diff] [blame] | 1607 | if (mScreenPinningEnabled) { |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 1608 | tv.hideActionButton(false /* fadeOut */, 0 /* duration */, false /* scaleDown */, null); |
Winson Chung | 931c51f | 2015-12-17 17:08:55 -0500 | [diff] [blame] | 1609 | } |
Winson | 3c10716 | 2016-01-22 15:53:00 -0800 | [diff] [blame] | 1610 | |
| 1611 | // Detach the view from the hierarchy |
| 1612 | detachViewFromParent(tv); |
| 1613 | // Update the task views list after removing the task view |
| 1614 | updateTaskViewsList(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1615 | } |
| 1616 | |
| 1617 | @Override |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 1618 | public void onPickUpViewFromPool(TaskView tv, Task task, boolean isNewView) { |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 1619 | // Find the index where this task should be placed in the stack |
Winson | 250608a | 2015-11-24 15:00:31 -0800 | [diff] [blame] | 1620 | int taskIndex = mStack.indexOfStackTask(task); |
Winson | a78a8f3 | 2015-12-03 10:55:01 -0800 | [diff] [blame] | 1621 | int insertIndex = findTaskViewInsertIndex(task, taskIndex); |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 1622 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1623 | // Add/attach the view to the hierarchy |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1624 | if (isNewView) { |
Winson | 70f0bf7 | 2016-02-01 14:05:29 -0800 | [diff] [blame] | 1625 | if (mInMeasureLayout) { |
| 1626 | // If we are measuring the layout, then just add the view normally as it will be |
| 1627 | // laid out during the layout pass |
| 1628 | addView(tv, insertIndex); |
| 1629 | } else { |
| 1630 | // Otherwise, this is from a bindVisibleTaskViews() call outside the measure/layout |
| 1631 | // pass, and we should layout the new child ourselves |
| 1632 | ViewGroup.LayoutParams params = tv.getLayoutParams(); |
| 1633 | if (params == null) { |
| 1634 | params = generateDefaultLayoutParams(); |
| 1635 | } |
| 1636 | addViewInLayout(tv, insertIndex, params, true /* preventRequestLayout */); |
| 1637 | measureTaskView(tv); |
Winson | c69249f | 2016-03-28 13:38:39 -0700 | [diff] [blame] | 1638 | layoutTaskView(true /* changed */, tv); |
Winson | 70f0bf7 | 2016-02-01 14:05:29 -0800 | [diff] [blame] | 1639 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1640 | } else { |
| 1641 | attachViewToParent(tv, insertIndex, tv.getLayoutParams()); |
| 1642 | } |
Winson Chung | 6ac8bd6 | 2015-01-07 16:38:35 -0800 | [diff] [blame] | 1643 | // Update the task views list after adding the new task view |
| 1644 | updateTaskViewsList(); |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 1645 | |
Winson | 4333694 | 2016-03-07 14:52:59 -0800 | [diff] [blame] | 1646 | // Bind the task view to the new task |
| 1647 | bindTaskView(tv, task); |
Winson | 3c10716 | 2016-01-22 15:53:00 -0800 | [diff] [blame] | 1648 | |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 1649 | // Set the new state for this view, including the callbacks and view clipping |
| 1650 | tv.setCallbacks(this); |
| 1651 | tv.setTouchEnabled(true); |
| 1652 | tv.setClipViewInStack(true); |
Winson | aaf33bc | 2015-12-03 12:02:38 -0800 | [diff] [blame] | 1653 | if (mFocusedTask == task) { |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 1654 | tv.setFocusedState(true, false /* requestViewFocus */); |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 1655 | if (mStartTimerIndicatorDuration > 0) { |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 1656 | // The timer indicator couldn't be started before, so start it now |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 1657 | tv.getHeaderView().startFocusTimerIndicator(mStartTimerIndicatorDuration); |
| 1658 | mStartTimerIndicatorDuration = 0; |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 1659 | } |
Winson | a0731a1 | 2015-12-02 15:10:14 -0800 | [diff] [blame] | 1660 | } |
Winson Chung | 931c51f | 2015-12-17 17:08:55 -0500 | [diff] [blame] | 1661 | |
| 1662 | // Restore the action button visibility if it is the front most task view |
Winson | 35a8b04 | 2016-01-22 09:41:09 -0800 | [diff] [blame] | 1663 | if (mScreenPinningEnabled && tv.getTask() == |
| 1664 | mStack.getStackFrontMostTask(false /* includeFreeform */)) { |
Winson Chung | 931c51f | 2015-12-17 17:08:55 -0500 | [diff] [blame] | 1665 | tv.showActionButton(false /* fadeIn */, 0 /* fadeInDuration */); |
| 1666 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1667 | } |
| 1668 | |
| 1669 | @Override |
| 1670 | public boolean hasPreferredData(TaskView tv, Task preferredData) { |
| 1671 | return (tv.getTask() == preferredData); |
| 1672 | } |
| 1673 | |
Winson | 4333694 | 2016-03-07 14:52:59 -0800 | [diff] [blame] | 1674 | private void bindTaskView(TaskView tv, Task task) { |
| 1675 | // Rebind the task and request that this task's data be filled into the TaskView |
Winson | fc48b07 | 2016-04-21 11:20:11 -0700 | [diff] [blame] | 1676 | tv.onTaskBound(task, mTouchExplorationEnabled, mDisplayOrientation, mDisplayRect); |
Winson | 4333694 | 2016-03-07 14:52:59 -0800 | [diff] [blame] | 1677 | |
Winson | 9377110 | 2016-07-11 19:49:26 -0700 | [diff] [blame] | 1678 | // If the doze trigger has already fired, then update the state for this task view |
| 1679 | if (mUIDozeTrigger.isAsleep() || |
Manu Cornet | 8ff7854 | 2016-12-20 17:17:51 -0800 | [diff] [blame] | 1680 | Recents.getSystemServices().hasFreeformWorkspaceSupport() || |
| 1681 | useGridLayout()) { |
Winson | 9377110 | 2016-07-11 19:49:26 -0700 | [diff] [blame] | 1682 | tv.setNoUserInteractionState(); |
| 1683 | } |
| 1684 | |
Jorim Jaggi | 6f9dbcb | 2017-03-17 17:22:47 +0100 | [diff] [blame] | 1685 | if (task == mPrefetchingTask) { |
| 1686 | task.notifyTaskDataLoaded(task.thumbnail, task.icon); |
| 1687 | } else { |
| 1688 | // Load the task data |
| 1689 | Recents.getTaskLoader().loadTaskData(task); |
| 1690 | } |
| 1691 | Recents.getTaskLoader().getHighResThumbnailLoader().onTaskVisible(task); |
Winson | 4333694 | 2016-03-07 14:52:59 -0800 | [diff] [blame] | 1692 | } |
| 1693 | |
| 1694 | private void unbindTaskView(TaskView tv, Task task) { |
Jorim Jaggi | 6f9dbcb | 2017-03-17 17:22:47 +0100 | [diff] [blame] | 1695 | if (task != mPrefetchingTask) { |
| 1696 | // Report that this task's data is no longer being used |
| 1697 | Recents.getTaskLoader().unloadTaskData(task); |
| 1698 | } |
| 1699 | Recents.getTaskLoader().getHighResThumbnailLoader().onTaskInvisible(task); |
| 1700 | } |
| 1701 | |
| 1702 | private void updatePrefetchingTask(ArrayList<Task> tasks, int frontIndex, int backIndex) { |
| 1703 | Task t = null; |
| 1704 | boolean somethingVisible = frontIndex != -1 && backIndex != -1; |
| 1705 | if (somethingVisible && frontIndex < tasks.size() - 1) { |
| 1706 | t = tasks.get(frontIndex + 1); |
| 1707 | } |
| 1708 | if (mPrefetchingTask != t) { |
| 1709 | if (mPrefetchingTask != null) { |
| 1710 | int index = tasks.indexOf(mPrefetchingTask); |
| 1711 | if (index < backIndex || index > frontIndex) { |
| 1712 | Recents.getTaskLoader().unloadTaskData(mPrefetchingTask); |
| 1713 | } |
| 1714 | } |
| 1715 | mPrefetchingTask = t; |
| 1716 | if (t != null) { |
| 1717 | Recents.getTaskLoader().loadTaskData(t); |
| 1718 | } |
| 1719 | } |
Winson | 4333694 | 2016-03-07 14:52:59 -0800 | [diff] [blame] | 1720 | } |
| 1721 | |
Jorim Jaggi | 2149be1 | 2017-04-25 15:08:29 +0200 | [diff] [blame] | 1722 | private void clearPrefetchingTask() { |
| 1723 | if (mPrefetchingTask != null) { |
| 1724 | Recents.getTaskLoader().unloadTaskData(mPrefetchingTask); |
| 1725 | } |
| 1726 | mPrefetchingTask = null; |
| 1727 | } |
| 1728 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1729 | /**** TaskViewCallbacks Implementation ****/ |
| 1730 | |
| 1731 | @Override |
Winson Chung | 93748a1 | 2014-07-13 17:43:31 -0700 | [diff] [blame] | 1732 | public void onTaskViewClipStateChanged(TaskView tv) { |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 1733 | if (!mTaskViewsClipDirty) { |
| 1734 | mTaskViewsClipDirty = true; |
| 1735 | invalidate(); |
| 1736 | } |
Winson Chung | 93748a1 | 2014-07-13 17:43:31 -0700 | [diff] [blame] | 1737 | } |
| 1738 | |
Winson | 1c84614 | 2016-01-22 11:34:38 -0800 | [diff] [blame] | 1739 | /**** TaskStackLayoutAlgorithm.TaskStackLayoutAlgorithmCallbacks ****/ |
| 1740 | |
| 1741 | @Override |
Winson | 6647413 | 2016-02-23 18:45:47 -0800 | [diff] [blame] | 1742 | public void onFocusStateChanged(int prevFocusState, int curFocusState) { |
Winson | 1c84614 | 2016-01-22 11:34:38 -0800 | [diff] [blame] | 1743 | if (mDeferredTaskViewLayoutAnimation == null) { |
| 1744 | mUIDozeTrigger.poke(); |
Winson | be8e696 | 2016-02-01 14:27:52 -0800 | [diff] [blame] | 1745 | relayoutTaskViewsOnNextFrame(AnimationProps.IMMEDIATE); |
Winson | 1c84614 | 2016-01-22 11:34:38 -0800 | [diff] [blame] | 1746 | } |
| 1747 | } |
| 1748 | |
Winson Chung | 012ef36 | 2014-07-31 18:36:25 -0700 | [diff] [blame] | 1749 | /**** TaskStackViewScroller.TaskStackViewScrollerCallbacks ****/ |
| 1750 | |
| 1751 | @Override |
Winson | 1499150 | 2016-02-15 15:40:08 -0800 | [diff] [blame] | 1752 | public void onStackScrollChanged(float prevScroll, float curScroll, AnimationProps animation) { |
Winson Chung | 012ef36 | 2014-07-31 18:36:25 -0700 | [diff] [blame] | 1753 | mUIDozeTrigger.poke(); |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 1754 | if (animation != null) { |
| 1755 | relayoutTaskViewsOnNextFrame(animation); |
| 1756 | } |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 1757 | |
Manu Cornet | 5db30f0 | 2016-12-19 17:02:59 -0800 | [diff] [blame] | 1758 | // In grid layout, the stack action button always remains visible. |
| 1759 | if (mEnterAnimationComplete && !useGridLayout()) { |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 1760 | if (prevScroll > SHOW_STACK_ACTION_BUTTON_SCROLL_THRESHOLD && |
Winson | 3b6ba1a | 2016-03-22 15:37:54 -0700 | [diff] [blame] | 1761 | curScroll <= SHOW_STACK_ACTION_BUTTON_SCROLL_THRESHOLD && |
| 1762 | mStack.getTaskCount() > 0) { |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 1763 | EventBus.getDefault().send(new ShowStackActionButtonEvent(true /* translate */)); |
| 1764 | } else if (prevScroll < HIDE_STACK_ACTION_BUTTON_SCROLL_THRESHOLD && |
| 1765 | curScroll >= HIDE_STACK_ACTION_BUTTON_SCROLL_THRESHOLD) { |
| 1766 | EventBus.getDefault().send(new HideStackActionButtonEvent()); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 1767 | } |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 1768 | } |
Winson Chung | 012ef36 | 2014-07-31 18:36:25 -0700 | [diff] [blame] | 1769 | } |
| 1770 | |
Winson | e6c9073 | 2015-09-24 16:06:29 -0700 | [diff] [blame] | 1771 | /**** EventBus Events ****/ |
Winson Chung | 9f49df9 | 2014-05-07 18:08:34 -0700 | [diff] [blame] | 1772 | |
Winson | e6c9073 | 2015-09-24 16:06:29 -0700 | [diff] [blame] | 1773 | public final void onBusEvent(PackagesChangedEvent event) { |
Winson Chung | 0440067 | 2014-10-17 14:53:30 -0700 | [diff] [blame] | 1774 | // Compute which components need to be removed |
Winson | 5500390 | 2016-01-12 12:00:37 -0800 | [diff] [blame] | 1775 | ArraySet<ComponentName> removedComponents = mStack.computeComponentsRemoved( |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 1776 | event.packageName, event.userId); |
Winson Chung | 0440067 | 2014-10-17 14:53:30 -0700 | [diff] [blame] | 1777 | |
Winson Chung | 9f49df9 | 2014-05-07 18:08:34 -0700 | [diff] [blame] | 1778 | // For other tasks, just remove them directly if they no longer exist |
Winson | 250608a | 2015-11-24 15:00:31 -0800 | [diff] [blame] | 1779 | ArrayList<Task> tasks = mStack.getStackTasks(); |
Winson Chung | 9f49df9 | 2014-05-07 18:08:34 -0700 | [diff] [blame] | 1780 | for (int i = tasks.size() - 1; i >= 0; i--) { |
| 1781 | final Task t = tasks.get(i); |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 1782 | if (removedComponents.contains(t.key.getComponent())) { |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 1783 | final TaskView tv = getChildViewForTask(t); |
Winson Chung | 9f49df9 | 2014-05-07 18:08:34 -0700 | [diff] [blame] | 1784 | if (tv != null) { |
| 1785 | // For visible children, defer removing the task until after the animation |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 1786 | tv.dismissTask(); |
Winson Chung | 9f49df9 | 2014-05-07 18:08:34 -0700 | [diff] [blame] | 1787 | } else { |
| 1788 | // Otherwise, remove the task from the stack immediately |
Winson | 2068408 | 2016-03-16 17:13:34 -0700 | [diff] [blame] | 1789 | mStack.removeTask(t, AnimationProps.IMMEDIATE, false /* fromDockGesture */); |
Winson Chung | 9f49df9 | 2014-05-07 18:08:34 -0700 | [diff] [blame] | 1790 | } |
| 1791 | } |
| 1792 | } |
| 1793 | } |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 1794 | |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 1795 | public final void onBusEvent(LaunchTaskEvent event) { |
| 1796 | // Cancel any doze triggers once a task is launched |
| 1797 | mUIDozeTrigger.stopDozing(); |
| 1798 | } |
| 1799 | |
Manu Cornet | a96a617 | 2017-01-19 12:40:44 -0800 | [diff] [blame] | 1800 | public final void onBusEvent(LaunchMostRecentTaskRequestEvent event) { |
| 1801 | if (mStack.getTaskCount() > 0) { |
| 1802 | Task mostRecentTask = mStack.getStackFrontMostTask(true /* includeFreefromTasks */); |
| 1803 | launchTask(mostRecentTask); |
| 1804 | } |
| 1805 | } |
| 1806 | |
Winson | b61e654 | 2016-02-04 14:37:18 -0800 | [diff] [blame] | 1807 | public final void onBusEvent(LaunchNextTaskRequestEvent event) { |
Winson | bd53a31 | 2016-09-21 12:13:32 -0700 | [diff] [blame] | 1808 | if (mAwaitingFirstLayout) { |
| 1809 | mLaunchNextAfterFirstMeasure = true; |
| 1810 | return; |
| 1811 | } |
| 1812 | |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 1813 | if (mStack.getTaskCount() == 0) { |
| 1814 | if (RecentsImpl.getLastPipTime() != -1) { |
| 1815 | EventBus.getDefault().send(new ExpandPipEvent()); |
| 1816 | MetricsLogger.action(getContext(), MetricsEvent.OVERVIEW_LAUNCH_PREVIOUS_TASK, |
| 1817 | "pip"); |
| 1818 | } else { |
| 1819 | // If there are no tasks, then just hide recents back to home. |
| 1820 | EventBus.getDefault().send(new HideRecentsEvent(false, true)); |
| 1821 | } |
| 1822 | return; |
| 1823 | } |
| 1824 | |
| 1825 | if (!Recents.getConfiguration().getLaunchState().launchedFromPipApp |
| 1826 | && mStack.isNextLaunchTargetPip(RecentsImpl.getLastPipTime())) { |
| 1827 | // If the launch task is in the pinned stack, then expand the PiP now |
| 1828 | EventBus.getDefault().send(new ExpandPipEvent()); |
| 1829 | MetricsLogger.action(getContext(), MetricsEvent.OVERVIEW_LAUNCH_PREVIOUS_TASK, "pip"); |
| 1830 | } else { |
| 1831 | final Task launchTask = mStack.getNextLaunchTarget(); |
| 1832 | if (launchTask != null) { |
| 1833 | // Defer launching the task until the PiP menu has been dismissed (if it is |
| 1834 | // showing at all) |
| 1835 | HidePipMenuEvent hideMenuEvent = new HidePipMenuEvent(); |
| 1836 | hideMenuEvent.addPostAnimationCallback(() -> { |
| 1837 | launchTask(launchTask); |
| 1838 | }); |
| 1839 | EventBus.getDefault().send(hideMenuEvent); |
| 1840 | MetricsLogger.action(getContext(), MetricsEvent.OVERVIEW_LAUNCH_PREVIOUS_TASK, |
| 1841 | launchTask.key.getComponent().toString()); |
| 1842 | } |
Winson | b61e654 | 2016-02-04 14:37:18 -0800 | [diff] [blame] | 1843 | } |
| 1844 | } |
| 1845 | |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 1846 | public final void onBusEvent(LaunchTaskStartedEvent event) { |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 1847 | mAnimationHelper.startLaunchTaskAnimation(event.taskView, event.screenPinningRequested, |
| 1848 | event.getAnimationTrigger()); |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 1849 | } |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 1850 | |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 1851 | public final void onBusEvent(DismissRecentsToHomeAnimationStarted event) { |
| 1852 | // Stop any scrolling |
Winson | 61560f0 | 2016-05-02 16:36:20 -0700 | [diff] [blame] | 1853 | mTouchHandler.cancelNonDismissTaskAnimations(); |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 1854 | mStackScroller.stopScroller(); |
| 1855 | mStackScroller.stopBoundScrollAnimation(); |
Winson | 60df246 | 2016-04-23 16:06:50 -0700 | [diff] [blame] | 1856 | cancelDeferredTaskViewLayoutAnimation(); |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 1857 | |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 1858 | // Start the task animations |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 1859 | mAnimationHelper.startExitToHomeAnimation(event.animated, event.getAnimationTrigger()); |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 1860 | |
| 1861 | // Dismiss the freeform workspace background |
Winson | 5044863 | 2016-02-01 18:04:59 -0800 | [diff] [blame] | 1862 | int taskViewExitToHomeDuration = TaskStackAnimationHelper.EXIT_TO_HOME_TRANSLATION_DURATION; |
Winson | be8e696 | 2016-02-01 14:27:52 -0800 | [diff] [blame] | 1863 | animateFreeformWorkspaceBackgroundAlpha(0, new AnimationProps(taskViewExitToHomeDuration, |
| 1864 | Interpolators.FAST_OUT_SLOW_IN)); |
Jiaquan He | 21f495f | 2017-01-05 13:00:29 -0800 | [diff] [blame] | 1865 | |
| 1866 | // Dismiss the grid task view focus frame |
| 1867 | if (mTaskViewFocusFrame != null) { |
| 1868 | mTaskViewFocusFrame.moveGridTaskViewFocus(null); |
| 1869 | } |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 1870 | } |
Winson | 42be431 | 2015-10-10 11:51:08 -0700 | [diff] [blame] | 1871 | |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 1872 | public final void onBusEvent(DismissFocusedTaskViewEvent event) { |
Winson | aaf33bc | 2015-12-03 12:02:38 -0800 | [diff] [blame] | 1873 | if (mFocusedTask != null) { |
Jiaquan He | 21f495f | 2017-01-05 13:00:29 -0800 | [diff] [blame] | 1874 | if (mTaskViewFocusFrame != null) { |
| 1875 | mTaskViewFocusFrame.moveGridTaskViewFocus(null); |
| 1876 | } |
Winson | aaf33bc | 2015-12-03 12:02:38 -0800 | [diff] [blame] | 1877 | TaskView tv = getChildViewForTask(mFocusedTask); |
| 1878 | if (tv != null) { |
| 1879 | tv.dismissTask(); |
| 1880 | } |
| 1881 | resetFocusedTask(mFocusedTask); |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 1882 | } |
| 1883 | } |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 1884 | |
Winson | 3b6ba1a | 2016-03-22 15:37:54 -0700 | [diff] [blame] | 1885 | public final void onBusEvent(DismissTaskViewEvent event) { |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 1886 | // For visible children, defer removing the task until after the animation |
Manu Cornet | 5df7667 | 2017-01-11 15:14:14 -0800 | [diff] [blame] | 1887 | mAnimationHelper.startDeleteTaskAnimation( |
| 1888 | event.taskView, useGridLayout(), event.getAnimationTrigger()); |
Winson | 3b6ba1a | 2016-03-22 15:37:54 -0700 | [diff] [blame] | 1889 | } |
| 1890 | |
| 1891 | public final void onBusEvent(final DismissAllTaskViewsEvent event) { |
| 1892 | // Keep track of the tasks which will have their data removed |
| 1893 | ArrayList<Task> tasks = new ArrayList<>(mStack.getStackTasks()); |
Manu Cornet | 5df7667 | 2017-01-11 15:14:14 -0800 | [diff] [blame] | 1894 | mAnimationHelper.startDeleteAllTasksAnimation( |
| 1895 | getTaskViews(), useGridLayout(), event.getAnimationTrigger()); |
Winson | 3b6ba1a | 2016-03-22 15:37:54 -0700 | [diff] [blame] | 1896 | event.addPostAnimationCallback(new Runnable() { |
| 1897 | @Override |
| 1898 | public void run() { |
| 1899 | // Announce for accessibility |
| 1900 | announceForAccessibility(getContext().getString( |
| 1901 | R.string.accessibility_recents_all_items_dismissed)); |
| 1902 | |
| 1903 | // Remove all tasks and delete the task data for all tasks |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 1904 | mStack.removeAllTasks(true /* notifyStackChanges */); |
Winson | 3b6ba1a | 2016-03-22 15:37:54 -0700 | [diff] [blame] | 1905 | for (int i = tasks.size() - 1; i >= 0; i--) { |
| 1906 | EventBus.getDefault().send(new DeleteTaskDataEvent(tasks.get(i))); |
| 1907 | } |
| 1908 | |
| 1909 | MetricsLogger.action(getContext(), MetricsEvent.OVERVIEW_DISMISS_ALL); |
| 1910 | } |
| 1911 | }); |
| 1912 | |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 1913 | } |
| 1914 | |
| 1915 | public final void onBusEvent(TaskViewDismissedEvent event) { |
Winson | 3b6ba1a | 2016-03-22 15:37:54 -0700 | [diff] [blame] | 1916 | // Announce for accessibility |
| 1917 | announceForAccessibility(getContext().getString( |
| 1918 | R.string.accessibility_recents_item_dismissed, event.task.title)); |
| 1919 | |
Manu Cornet | 551e80c | 2017-02-10 12:54:40 -0800 | [diff] [blame] | 1920 | if (useGridLayout() && event.animation != null) { |
| 1921 | event.animation.setListener(new AnimatorListenerAdapter() { |
| 1922 | public void onAnimationEnd(Animator animator) { |
| 1923 | if (mTaskViewFocusFrame != null) { |
| 1924 | // Resize the grid layout task view focus frame |
| 1925 | mTaskViewFocusFrame.resize(); |
| 1926 | } |
| 1927 | } |
| 1928 | }); |
| 1929 | } |
| 1930 | |
Winson | 3b6ba1a | 2016-03-22 15:37:54 -0700 | [diff] [blame] | 1931 | // Remove the task from the stack |
Winson | 61560f0 | 2016-05-02 16:36:20 -0700 | [diff] [blame] | 1932 | mStack.removeTask(event.task, event.animation, false /* fromDockGesture */); |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 1933 | EventBus.getDefault().send(new DeleteTaskDataEvent(event.task)); |
Winson | 4232952 | 2016-02-05 10:39:46 -0800 | [diff] [blame] | 1934 | |
| 1935 | MetricsLogger.action(getContext(), MetricsEvent.OVERVIEW_DISMISS, |
| 1936 | event.task.key.getComponent().toString()); |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 1937 | } |
| 1938 | |
| 1939 | public final void onBusEvent(FocusNextTaskViewEvent event) { |
Winson | 6647413 | 2016-02-23 18:45:47 -0800 | [diff] [blame] | 1940 | // Stop any scrolling |
| 1941 | mStackScroller.stopScroller(); |
| 1942 | mStackScroller.stopBoundScrollAnimation(); |
| 1943 | |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 1944 | setRelativeFocusedTask(true, false /* stackTasksOnly */, true /* animated */, false, |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 1945 | event.timerIndicatorDuration); |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | public final void onBusEvent(FocusPreviousTaskViewEvent event) { |
Winson | 6647413 | 2016-02-23 18:45:47 -0800 | [diff] [blame] | 1949 | // Stop any scrolling |
| 1950 | mStackScroller.stopScroller(); |
| 1951 | mStackScroller.stopBoundScrollAnimation(); |
| 1952 | |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 1953 | setRelativeFocusedTask(false, false /* stackTasksOnly */, true /* animated */); |
| 1954 | } |
| 1955 | |
Jiaquan He | c0e1813 | 2017-01-11 14:47:00 -0800 | [diff] [blame] | 1956 | public final void onBusEvent(NavigateTaskViewEvent event) { |
| 1957 | if (useGridLayout()) { |
| 1958 | final int taskCount = mStack.getTaskCount(); |
| 1959 | final int currentIndex = mStack.indexOfStackTask(getFocusedTask()); |
| 1960 | final int nextIndex = mLayoutAlgorithm.mTaskGridLayoutAlgorithm.navigateFocus(taskCount, |
| 1961 | currentIndex, event.direction); |
| 1962 | setFocusedTask(nextIndex, false, true); |
| 1963 | } else { |
| 1964 | switch (event.direction) { |
| 1965 | case UP: |
| 1966 | EventBus.getDefault().send(new FocusPreviousTaskViewEvent()); |
| 1967 | break; |
| 1968 | case DOWN: |
| 1969 | EventBus.getDefault().send( |
| 1970 | new FocusNextTaskViewEvent(0 /* timerIndicatorDuration */)); |
| 1971 | break; |
| 1972 | } |
| 1973 | } |
| 1974 | } |
| 1975 | |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 1976 | public final void onBusEvent(UserInteractionEvent event) { |
| 1977 | // Poke the doze trigger on user interaction |
| 1978 | mUIDozeTrigger.poke(); |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 1979 | |
| 1980 | RecentsDebugFlags debugFlags = Recents.getDebugFlags(); |
| 1981 | if (debugFlags.isFastToggleRecentsEnabled() && mFocusedTask != null) { |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 1982 | TaskView tv = getChildViewForTask(mFocusedTask); |
| 1983 | if (tv != null) { |
| 1984 | tv.getHeaderView().cancelFocusTimerIndicator(); |
| 1985 | } |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 1986 | } |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 1987 | } |
| 1988 | |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 1989 | public final void onBusEvent(DragStartEvent event) { |
Winson | 70f0bf7 | 2016-02-01 14:05:29 -0800 | [diff] [blame] | 1990 | // Ensure that the drag task is not animated |
| 1991 | addIgnoreTask(event.task); |
| 1992 | |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 1993 | if (event.task.isFreeformTask()) { |
| 1994 | // Animate to the front of the stack |
Winson | d952961 | 2016-01-28 13:29:49 -0800 | [diff] [blame] | 1995 | mStackScroller.animateScroll(mLayoutAlgorithm.mInitialScrollP, null); |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 1996 | } |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 1997 | |
| 1998 | // Enlarge the dragged view slightly |
| 1999 | float finalScale = event.taskView.getScaleX() * DRAG_SCALE_FACTOR; |
| 2000 | mLayoutAlgorithm.getStackTransform(event.task, getScroller().getStackScroll(), |
Jiaquan He | 26f637b | 2016-12-27 14:44:14 -0800 | [diff] [blame] | 2001 | mTmpTransform, null); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 2002 | mTmpTransform.scale = finalScale; |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 2003 | mTmpTransform.translationZ = mLayoutAlgorithm.mMaxTranslationZ + 1; |
Winson | 0a461f0 | 2016-04-19 10:51:12 -0700 | [diff] [blame] | 2004 | mTmpTransform.dimAlpha = 0f; |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 2005 | updateTaskViewToTransform(event.taskView, mTmpTransform, |
Winson | be8e696 | 2016-02-01 14:27:52 -0800 | [diff] [blame] | 2006 | new AnimationProps(DRAG_SCALE_DURATION, Interpolators.FAST_OUT_SLOW_IN)); |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | public final void onBusEvent(DragStartInitializeDropTargetsEvent event) { |
| 2010 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 2011 | if (ssp.hasFreeformWorkspaceSupport()) { |
| 2012 | event.handler.registerDropTargetForCurrentDrag(mStackDropTarget); |
| 2013 | event.handler.registerDropTargetForCurrentDrag(mFreeformWorkspaceDropTarget); |
| 2014 | } |
| 2015 | } |
| 2016 | |
| 2017 | public final void onBusEvent(DragDropTargetChangedEvent event) { |
Winson | 3f32e7e | 2016-04-20 17:18:08 -0700 | [diff] [blame] | 2018 | AnimationProps animation = new AnimationProps(SLOW_SYNC_STACK_DURATION, |
| 2019 | Interpolators.FAST_OUT_SLOW_IN); |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 2020 | boolean ignoreTaskOverrides = false; |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 2021 | if (event.dropTarget instanceof TaskStack.DockState) { |
| 2022 | // Calculate the new task stack bounds that matches the window size that Recents will |
| 2023 | // have after the drop |
| 2024 | final TaskStack.DockState dockState = (TaskStack.DockState) event.dropTarget; |
Winson | 670ea71 | 2016-04-12 17:02:26 -0700 | [diff] [blame] | 2025 | Rect systemInsets = new Rect(mStableLayoutAlgorithm.mSystemInsets); |
| 2026 | // When docked, the nav bar insets are consumed and the activity is measured without |
| 2027 | // insets. However, the window bounds include the insets, so we need to subtract them |
| 2028 | // here to make them identical. |
| 2029 | int height = getMeasuredHeight(); |
| 2030 | height -= systemInsets.bottom; |
| 2031 | systemInsets.bottom = 0; |
Winson | fc48b07 | 2016-04-21 11:20:11 -0700 | [diff] [blame] | 2032 | mStackBounds.set(dockState.getDockedTaskStackBounds(mDisplayRect, getMeasuredWidth(), |
Winson | 67c7957 | 2016-04-13 14:02:18 -0700 | [diff] [blame] | 2033 | height, mDividerSize, systemInsets, |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 2034 | mLayoutAlgorithm, getResources(), mWindowRect)); |
Winson | 670ea71 | 2016-04-12 17:02:26 -0700 | [diff] [blame] | 2035 | mLayoutAlgorithm.setSystemInsets(systemInsets); |
Winson | fc48b07 | 2016-04-21 11:20:11 -0700 | [diff] [blame] | 2036 | mLayoutAlgorithm.initialize(mDisplayRect, mWindowRect, mStackBounds, |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 2037 | TaskStackLayoutAlgorithm.StackState.getStackStateForStack(mStack)); |
| 2038 | updateLayoutAlgorithm(true /* boundScroll */); |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 2039 | ignoreTaskOverrides = true; |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 2040 | } else { |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 2041 | // Restore the pre-drag task stack bounds, but ensure that we don't layout the dragging |
| 2042 | // task view, so add it back to the ignore set after updating the layout |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 2043 | removeIgnoreTask(event.task); |
Winson | 27c28f8 | 2016-05-05 16:16:50 -0700 | [diff] [blame] | 2044 | updateLayoutToStableBounds(); |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 2045 | addIgnoreTask(event.task); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 2046 | } |
Winson | 27c28f8 | 2016-05-05 16:16:50 -0700 | [diff] [blame] | 2047 | relayoutTaskViews(animation, null /* animationOverrides */, ignoreTaskOverrides); |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 2048 | } |
| 2049 | |
| 2050 | public final void onBusEvent(final DragEndEvent event) { |
Winson | 479f744 | 2015-11-25 15:16:27 -0800 | [diff] [blame] | 2051 | // We don't handle drops on the dock regions |
| 2052 | if (event.dropTarget instanceof TaskStack.DockState) { |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 2053 | // However, we do need to reset the overrides, since the last state of this task stack |
| 2054 | // view layout was ignoring task overrides (see DragDropTargetChangedEvent handler) |
| 2055 | mLayoutAlgorithm.clearUnfocusedTaskOverrides(); |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 2056 | return; |
| 2057 | } |
| 2058 | |
Winson | 479f744 | 2015-11-25 15:16:27 -0800 | [diff] [blame] | 2059 | boolean isFreeformTask = event.task.isFreeformTask(); |
| 2060 | boolean hasChangedStacks = |
| 2061 | (!isFreeformTask && event.dropTarget == mFreeformWorkspaceDropTarget) || |
| 2062 | (isFreeformTask && event.dropTarget == mStackDropTarget); |
Winson | 479f744 | 2015-11-25 15:16:27 -0800 | [diff] [blame] | 2063 | |
Winson | 5b7dd53 | 2015-12-01 16:02:12 -0800 | [diff] [blame] | 2064 | if (hasChangedStacks) { |
Winson | 479f744 | 2015-11-25 15:16:27 -0800 | [diff] [blame] | 2065 | // Move the task to the right position in the stack (ie. the front of the stack if |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 2066 | // freeform or the front of the stack if fullscreen). Note, we MUST move the tasks |
Winson | 479f744 | 2015-11-25 15:16:27 -0800 | [diff] [blame] | 2067 | // before we update their stack ids, otherwise, the keys will have changed. |
| 2068 | if (event.dropTarget == mFreeformWorkspaceDropTarget) { |
| 2069 | mStack.moveTaskToStack(event.task, FREEFORM_WORKSPACE_STACK_ID); |
Winson | 479f744 | 2015-11-25 15:16:27 -0800 | [diff] [blame] | 2070 | } else if (event.dropTarget == mStackDropTarget) { |
| 2071 | mStack.moveTaskToStack(event.task, FULLSCREEN_WORKSPACE_STACK_ID); |
Winson | 479f744 | 2015-11-25 15:16:27 -0800 | [diff] [blame] | 2072 | } |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 2073 | updateLayoutAlgorithm(true /* boundScroll */); |
Winson | 479f744 | 2015-11-25 15:16:27 -0800 | [diff] [blame] | 2074 | |
| 2075 | // Move the task to the new stack in the system after the animation completes |
Winson Chung | aaeaac1 | 2015-12-16 16:49:36 -0500 | [diff] [blame] | 2076 | event.addPostAnimationCallback(new Runnable() { |
Winson | 479f744 | 2015-11-25 15:16:27 -0800 | [diff] [blame] | 2077 | @Override |
| 2078 | public void run() { |
| 2079 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 2080 | ssp.moveTaskToStack(event.task.key.id, event.task.key.stackId); |
| 2081 | } |
| 2082 | }); |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 2083 | } |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 2084 | |
Winson | 27c28f8 | 2016-05-05 16:16:50 -0700 | [diff] [blame] | 2085 | // Restore the task, so that relayout will apply to it below |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 2086 | removeIgnoreTask(event.task); |
Winson | 27c28f8 | 2016-05-05 16:16:50 -0700 | [diff] [blame] | 2087 | |
| 2088 | // Convert the dragging task view back to its final layout-space rect |
| 2089 | Utilities.setViewFrameFromTranslation(event.taskView); |
| 2090 | |
| 2091 | // Animate all the tasks into place |
| 2092 | ArrayMap<Task, AnimationProps> animationOverrides = new ArrayMap<>(); |
| 2093 | animationOverrides.put(event.task, new AnimationProps(SLOW_SYNC_STACK_DURATION, |
| 2094 | Interpolators.FAST_OUT_SLOW_IN, |
| 2095 | event.getAnimationTrigger().decrementOnAnimationEnd())); |
| 2096 | relayoutTaskViews(new AnimationProps(SLOW_SYNC_STACK_DURATION, |
| 2097 | Interpolators.FAST_OUT_SLOW_IN)); |
| 2098 | event.getAnimationTrigger().increment(); |
| 2099 | } |
| 2100 | |
| 2101 | public final void onBusEvent(final DragEndCancelledEvent event) { |
| 2102 | // Restore the pre-drag task stack bounds, including the dragging task view |
| 2103 | removeIgnoreTask(event.task); |
| 2104 | updateLayoutToStableBounds(); |
| 2105 | |
| 2106 | // Convert the dragging task view back to its final layout-space rect |
| 2107 | Utilities.setViewFrameFromTranslation(event.taskView); |
| 2108 | |
| 2109 | // Animate all the tasks into place |
| 2110 | ArrayMap<Task, AnimationProps> animationOverrides = new ArrayMap<>(); |
| 2111 | animationOverrides.put(event.task, new AnimationProps(SLOW_SYNC_STACK_DURATION, |
| 2112 | Interpolators.FAST_OUT_SLOW_IN, |
| 2113 | event.getAnimationTrigger().decrementOnAnimationEnd())); |
| 2114 | relayoutTaskViews(new AnimationProps(SLOW_SYNC_STACK_DURATION, |
| 2115 | Interpolators.FAST_OUT_SLOW_IN)); |
| 2116 | event.getAnimationTrigger().increment(); |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 2117 | } |
| 2118 | |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 2119 | public final void onBusEvent(IterateRecentsEvent event) { |
Winson Chung | d6b78a3 | 2015-12-15 10:22:45 -0500 | [diff] [blame] | 2120 | if (!mEnterAnimationComplete) { |
| 2121 | // Cancel the previous task's window transition before animating the focused state |
| 2122 | EventBus.getDefault().send(new CancelEnterRecentsWindowAnimationEvent(null)); |
| 2123 | } |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 2124 | } |
| 2125 | |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 2126 | public final void onBusEvent(EnterRecentsWindowAnimationCompletedEvent event) { |
| 2127 | mEnterAnimationComplete = true; |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 2128 | |
Winson | 4b057c6 | 2016-01-12 15:01:52 -0800 | [diff] [blame] | 2129 | if (mStack.getTaskCount() > 0) { |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 2130 | // Start the task enter animations |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 2131 | mAnimationHelper.startEnterAnimation(event.getAnimationTrigger()); |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 2132 | |
| 2133 | // Add a runnable to the post animation ref counter to clear all the views |
| 2134 | event.addPostAnimationCallback(new Runnable() { |
| 2135 | @Override |
| 2136 | public void run() { |
| 2137 | // Start the dozer to trigger to trigger any UI that shows after a timeout |
Winson | 2ed7c47 | 2016-06-14 17:35:53 -0700 | [diff] [blame] | 2138 | if (!Recents.getSystemServices().hasFreeformWorkspaceSupport()) { |
| 2139 | mUIDozeTrigger.startDozing(); |
| 2140 | } |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 2141 | |
| 2142 | // Update the focused state here -- since we only set the focused task without |
| 2143 | // requesting view focus in onFirstLayout(), actually request view focus and |
| 2144 | // animate the focused state if we are alt-tabbing now, after the window enter |
| 2145 | // animation is completed |
| 2146 | if (mFocusedTask != null) { |
| 2147 | RecentsConfiguration config = Recents.getConfiguration(); |
| 2148 | RecentsActivityLaunchState launchState = config.getLaunchState(); |
| 2149 | setFocusedTask(mStack.indexOfStackTask(mFocusedTask), |
| 2150 | false /* scrollToTask */, launchState.launchedWithAltTab); |
Winson | f000988 | 2016-06-01 12:22:55 -0700 | [diff] [blame] | 2151 | TaskView focusedTaskView = getChildViewForTask(mFocusedTask); |
| 2152 | if (mTouchExplorationEnabled && focusedTaskView != null) { |
| 2153 | focusedTaskView.requestAccessibilityFocus(); |
| 2154 | } |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 2155 | } |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 2156 | |
| 2157 | EventBus.getDefault().send(new EnterRecentsTaskStackAnimationCompletedEvent()); |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 2158 | } |
| 2159 | }); |
| 2160 | } |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 2161 | } |
| 2162 | |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 2163 | public final void onBusEvent(UpdateFreeformTaskViewVisibilityEvent event) { |
| 2164 | List<TaskView> taskViews = getTaskViews(); |
| 2165 | int taskViewCount = taskViews.size(); |
| 2166 | for (int i = 0; i < taskViewCount; i++) { |
| 2167 | TaskView tv = taskViews.get(i); |
| 2168 | Task task = tv.getTask(); |
Winson Chung | 296278a | 2015-12-17 12:09:02 -0500 | [diff] [blame] | 2169 | if (task.isFreeformTask()) { |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 2170 | tv.setVisibility(event.visible ? View.VISIBLE : View.INVISIBLE); |
| 2171 | } |
| 2172 | } |
| 2173 | } |
| 2174 | |
Winson | d2a0306 | 2016-04-15 11:19:07 -0700 | [diff] [blame] | 2175 | public final void onBusEvent(final MultiWindowStateChangedEvent event) { |
Winson | 95ee873 | 2016-04-26 14:46:58 -0700 | [diff] [blame] | 2176 | if (event.inMultiWindow || !event.showDeferredAnimation) { |
Winson | d2a0306 | 2016-04-15 11:19:07 -0700 | [diff] [blame] | 2177 | setTasks(event.stack, true /* allowNotifyStackChanges */); |
| 2178 | } else { |
| 2179 | // Reset the launch state before handling the multiwindow change |
| 2180 | RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState(); |
| 2181 | launchState.reset(); |
| 2182 | |
Winson | 67c7957 | 2016-04-13 14:02:18 -0700 | [diff] [blame] | 2183 | // Defer until the next frame to ensure that we have received all the system insets, and |
| 2184 | // initial layout updates |
Winson | d2a0306 | 2016-04-15 11:19:07 -0700 | [diff] [blame] | 2185 | event.getAnimationTrigger().increment(); |
Winson | 67c7957 | 2016-04-13 14:02:18 -0700 | [diff] [blame] | 2186 | post(new Runnable() { |
Winson | 931845f | 2016-02-24 19:38:41 -0800 | [diff] [blame] | 2187 | @Override |
| 2188 | public void run() { |
Winson | 67c7957 | 2016-04-13 14:02:18 -0700 | [diff] [blame] | 2189 | // Scroll the stack to the front to see the undocked task |
Winson | d2a0306 | 2016-04-15 11:19:07 -0700 | [diff] [blame] | 2190 | mAnimationHelper.startNewStackScrollAnimation(event.stack, |
| 2191 | event.getAnimationTrigger()); |
| 2192 | event.getAnimationTrigger().decrement(); |
Winson | 931845f | 2016-02-24 19:38:41 -0800 | [diff] [blame] | 2193 | } |
| 2194 | }); |
| 2195 | } |
Winson | d952961 | 2016-01-28 13:29:49 -0800 | [diff] [blame] | 2196 | } |
| 2197 | |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 2198 | public final void onBusEvent(ConfigurationChangedEvent event) { |
Winson | fc48b07 | 2016-04-21 11:20:11 -0700 | [diff] [blame] | 2199 | if (event.fromDeviceOrientationChange) { |
| 2200 | mDisplayOrientation = Utilities.getAppConfiguration(mContext).orientation; |
| 2201 | mDisplayRect = Recents.getSystemServices().getDisplayRect(); |
Winson | 399d21e | 2016-05-18 13:26:29 -0700 | [diff] [blame] | 2202 | |
| 2203 | // Always stop the scroller, otherwise, we may continue setting the stack scroll to the |
| 2204 | // wrong bounds in the new layout |
| 2205 | mStackScroller.stopScroller(); |
Winson | fc48b07 | 2016-04-21 11:20:11 -0700 | [diff] [blame] | 2206 | } |
Winson | 670ea71 | 2016-04-12 17:02:26 -0700 | [diff] [blame] | 2207 | reloadOnConfigurationChange(); |
Winson | 619e40c | 2016-03-25 16:12:35 -0700 | [diff] [blame] | 2208 | |
| 2209 | // Notify the task views of the configuration change so they can reload their resources |
| 2210 | if (!event.fromMultiWindow) { |
| 2211 | mTmpTaskViews.clear(); |
| 2212 | mTmpTaskViews.addAll(getTaskViews()); |
| 2213 | mTmpTaskViews.addAll(mViewPool.getViews()); |
| 2214 | int taskViewCount = mTmpTaskViews.size(); |
| 2215 | for (int i = 0; i < taskViewCount; i++) { |
| 2216 | mTmpTaskViews.get(i).onConfigurationChanged(); |
| 2217 | } |
| 2218 | } |
| 2219 | |
Manu Cornet | 5db30f0 | 2016-12-19 17:02:59 -0800 | [diff] [blame] | 2220 | // Update the Clear All button in case we're switching in or out of grid layout. |
| 2221 | updateStackActionButtonVisibility(); |
| 2222 | |
Winson | 44849b8 | 2016-03-29 10:45:45 -0700 | [diff] [blame] | 2223 | // Trigger a new layout and update to the initial state if necessary |
Winson | 67c7957 | 2016-04-13 14:02:18 -0700 | [diff] [blame] | 2224 | if (event.fromMultiWindow) { |
Winson | 44849b8 | 2016-03-29 10:45:45 -0700 | [diff] [blame] | 2225 | mInitialState = INITIAL_STATE_UPDATE_LAYOUT_ONLY; |
Winson | 670ea71 | 2016-04-12 17:02:26 -0700 | [diff] [blame] | 2226 | requestLayout(); |
Winson | 67c7957 | 2016-04-13 14:02:18 -0700 | [diff] [blame] | 2227 | } else if (event.fromDeviceOrientationChange) { |
| 2228 | mInitialState = INITIAL_STATE_UPDATE_ALL; |
| 2229 | requestLayout(); |
Winson | 44849b8 | 2016-03-29 10:45:45 -0700 | [diff] [blame] | 2230 | } |
Winson | 670ea71 | 2016-04-12 17:02:26 -0700 | [diff] [blame] | 2231 | } |
| 2232 | |
Jorim Jaggi | db21bbd | 2016-04-18 15:32:07 -0700 | [diff] [blame] | 2233 | public final void onBusEvent(RecentsGrowingEvent event) { |
| 2234 | mResetToInitialStateWhenResized = true; |
| 2235 | } |
| 2236 | |
Jiaquan He | 21f495f | 2017-01-05 13:00:29 -0800 | [diff] [blame] | 2237 | public final void onBusEvent(RecentsVisibilityChangedEvent event) { |
| 2238 | if (!event.visible && mTaskViewFocusFrame != null) { |
| 2239 | mTaskViewFocusFrame.moveGridTaskViewFocus(null); |
| 2240 | } |
Jorim Jaggi | 2149be1 | 2017-04-25 15:08:29 +0200 | [diff] [blame] | 2241 | if (!event.visible) { |
| 2242 | List<TaskView> taskViews = new ArrayList<>(getTaskViews()); |
| 2243 | for (int i = 0; i < taskViews.size(); i++) { |
| 2244 | mViewPool.returnViewToPool(taskViews.get(i)); |
| 2245 | } |
| 2246 | clearPrefetchingTask(); |
| 2247 | } |
Jiaquan He | 21f495f | 2017-01-05 13:00:29 -0800 | [diff] [blame] | 2248 | } |
| 2249 | |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 2250 | public final void onBusEvent(ActivityPinnedEvent event) { |
| 2251 | // If an activity enters PiP while Recents is open, remove the stack task associated with |
| 2252 | // the new PiP task |
| 2253 | Task removeTask = mStack.findTaskWithId(event.taskId); |
| 2254 | if (removeTask != null) { |
| 2255 | // In this case, we remove the task, but if the last task is removed, don't dismiss |
| 2256 | // Recents to home |
| 2257 | mStack.removeTask(removeTask, AnimationProps.IMMEDIATE, false /* fromDockGesture */, |
| 2258 | false /* dismissRecentsIfAllRemoved */); |
| 2259 | } |
| 2260 | updateLayoutAlgorithm(false /* boundScroll */); |
| 2261 | updateToInitialState(); |
| 2262 | } |
| 2263 | |
Winson | 670ea71 | 2016-04-12 17:02:26 -0700 | [diff] [blame] | 2264 | public void reloadOnConfigurationChange() { |
| 2265 | mStableLayoutAlgorithm.reloadOnConfigurationChange(getContext()); |
| 2266 | mLayoutAlgorithm.reloadOnConfigurationChange(getContext()); |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 2267 | } |
| 2268 | |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 2269 | /** |
Winson | a78a8f3 | 2015-12-03 10:55:01 -0800 | [diff] [blame] | 2270 | * Starts an alpha animation on the freeform workspace background. |
| 2271 | */ |
Winson | be8e696 | 2016-02-01 14:27:52 -0800 | [diff] [blame] | 2272 | private void animateFreeformWorkspaceBackgroundAlpha(int targetAlpha, |
| 2273 | AnimationProps animation) { |
Winson | a78a8f3 | 2015-12-03 10:55:01 -0800 | [diff] [blame] | 2274 | if (mFreeformWorkspaceBackground.getAlpha() == targetAlpha) { |
| 2275 | return; |
| 2276 | } |
| 2277 | |
| 2278 | Utilities.cancelAnimationWithoutCallbacks(mFreeformWorkspaceBackgroundAnimator); |
| 2279 | mFreeformWorkspaceBackgroundAnimator = ObjectAnimator.ofInt(mFreeformWorkspaceBackground, |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 2280 | Utilities.DRAWABLE_ALPHA, mFreeformWorkspaceBackground.getAlpha(), targetAlpha); |
Winson | be8e696 | 2016-02-01 14:27:52 -0800 | [diff] [blame] | 2281 | mFreeformWorkspaceBackgroundAnimator.setStartDelay( |
| 2282 | animation.getDuration(AnimationProps.ALPHA)); |
| 2283 | mFreeformWorkspaceBackgroundAnimator.setDuration( |
| 2284 | animation.getDuration(AnimationProps.ALPHA)); |
| 2285 | mFreeformWorkspaceBackgroundAnimator.setInterpolator( |
| 2286 | animation.getInterpolator(AnimationProps.ALPHA)); |
Winson | a78a8f3 | 2015-12-03 10:55:01 -0800 | [diff] [blame] | 2287 | mFreeformWorkspaceBackgroundAnimator.start(); |
| 2288 | } |
| 2289 | |
| 2290 | /** |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 2291 | * Returns the insert index for the task in the current set of task views. If the given task |
Winson | a78a8f3 | 2015-12-03 10:55:01 -0800 | [diff] [blame] | 2292 | * is already in the task view list, then this method returns the insert index assuming it |
| 2293 | * is first removed at the previous index. |
| 2294 | * |
| 2295 | * @param task the task we are finding the index for |
| 2296 | * @param taskIndex the index of the task in the stack |
| 2297 | */ |
| 2298 | private int findTaskViewInsertIndex(Task task, int taskIndex) { |
| 2299 | if (taskIndex != -1) { |
| 2300 | List<TaskView> taskViews = getTaskViews(); |
| 2301 | boolean foundTaskView = false; |
| 2302 | int taskViewCount = taskViews.size(); |
| 2303 | for (int i = 0; i < taskViewCount; i++) { |
| 2304 | Task tvTask = taskViews.get(i).getTask(); |
| 2305 | if (tvTask == task) { |
| 2306 | foundTaskView = true; |
| 2307 | } else if (taskIndex < mStack.indexOfStackTask(tvTask)) { |
| 2308 | if (foundTaskView) { |
| 2309 | return i - 1; |
| 2310 | } else { |
| 2311 | return i; |
| 2312 | } |
| 2313 | } |
| 2314 | } |
| 2315 | } |
| 2316 | return -1; |
| 2317 | } |
Winson Chung | de750de | 2015-12-11 10:26:06 -0500 | [diff] [blame] | 2318 | |
Manu Cornet | a96a617 | 2017-01-19 12:40:44 -0800 | [diff] [blame] | 2319 | private void launchTask(Task task) { |
| 2320 | // Stop all animations |
| 2321 | cancelAllTaskViewAnimations(); |
| 2322 | |
| 2323 | float curScroll = mStackScroller.getStackScroll(); |
| 2324 | float targetScroll = mLayoutAlgorithm.getStackScrollForTaskAtInitialOffset(task); |
| 2325 | float absScrollDiff = Math.abs(targetScroll - curScroll); |
| 2326 | if (getChildViewForTask(task) == null || absScrollDiff > 0.35f) { |
| 2327 | int duration = (int) (LAUNCH_NEXT_SCROLL_BASE_DURATION + |
| 2328 | absScrollDiff * LAUNCH_NEXT_SCROLL_INCR_DURATION); |
| 2329 | mStackScroller.animateScroll(targetScroll, |
| 2330 | duration, new Runnable() { |
| 2331 | @Override |
| 2332 | public void run() { |
| 2333 | EventBus.getDefault().send(new LaunchTaskEvent( |
| 2334 | getChildViewForTask(task), task, null, |
| 2335 | INVALID_STACK_ID, false /* screenPinningRequested */)); |
| 2336 | } |
| 2337 | }); |
| 2338 | } else { |
| 2339 | EventBus.getDefault().send(new LaunchTaskEvent(getChildViewForTask(task), |
| 2340 | task, null, INVALID_STACK_ID, false /* screenPinningRequested */)); |
| 2341 | } |
| 2342 | } |
| 2343 | |
Winson Chung | de750de | 2015-12-11 10:26:06 -0500 | [diff] [blame] | 2344 | /** |
Jiaquan He | c0a1acd | 2016-12-13 13:46:46 -0800 | [diff] [blame] | 2345 | * Check whether we should use the grid layout. |
Jiaquan He | c0a1acd | 2016-12-13 13:46:46 -0800 | [diff] [blame] | 2346 | */ |
| 2347 | public boolean useGridLayout() { |
Manu Cornet | c0432c6 | 2017-01-13 09:21:26 -0800 | [diff] [blame] | 2348 | return mLayoutAlgorithm.useGridLayout(); |
Jiaquan He | c0a1acd | 2016-12-13 13:46:46 -0800 | [diff] [blame] | 2349 | } |
| 2350 | |
| 2351 | /** |
Winson | 6ea2588 | 2016-01-13 10:59:04 -0800 | [diff] [blame] | 2352 | * Reads current system flags related to accessibility and screen pinning. |
| 2353 | */ |
| 2354 | private void readSystemFlags() { |
| 2355 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 2356 | mTouchExplorationEnabled = ssp.isTouchExplorationEnabled(); |
| 2357 | mScreenPinningEnabled = ssp.getSystemSetting(getContext(), |
| 2358 | Settings.System.LOCK_TO_APP_ENABLED) != 0; |
| 2359 | } |
Winson | d72c315 | 2016-04-05 15:33:35 -0700 | [diff] [blame] | 2360 | |
Manu Cornet | 5db30f0 | 2016-12-19 17:02:59 -0800 | [diff] [blame] | 2361 | private void updateStackActionButtonVisibility() { |
| 2362 | // Always show the button in grid layout. |
| 2363 | if (useGridLayout() || |
| 2364 | (mStackScroller.getStackScroll() < SHOW_STACK_ACTION_BUTTON_SCROLL_THRESHOLD && |
| 2365 | mStack.getTaskCount() > 0)) { |
| 2366 | EventBus.getDefault().send(new ShowStackActionButtonEvent(false /* translate */)); |
| 2367 | } else { |
| 2368 | EventBus.getDefault().send(new HideStackActionButtonEvent()); |
| 2369 | } |
| 2370 | } |
| 2371 | |
Winson | d72c315 | 2016-04-05 15:33:35 -0700 | [diff] [blame] | 2372 | public void dump(String prefix, PrintWriter writer) { |
| 2373 | String innerPrefix = prefix + " "; |
| 2374 | String id = Integer.toHexString(System.identityHashCode(this)); |
| 2375 | |
| 2376 | writer.print(prefix); writer.print(TAG); |
| 2377 | writer.print(" hasDefRelayout="); |
| 2378 | writer.print(mDeferredTaskViewLayoutAnimation != null ? "Y" : "N"); |
| 2379 | writer.print(" clipDirty="); writer.print(mTaskViewsClipDirty ? "Y" : "N"); |
| 2380 | writer.print(" awaitingFirstLayout="); writer.print(mAwaitingFirstLayout ? "Y" : "N"); |
| 2381 | writer.print(" initialState="); writer.print(mInitialState); |
| 2382 | writer.print(" inMeasureLayout="); writer.print(mInMeasureLayout ? "Y" : "N"); |
| 2383 | writer.print(" enterAnimCompleted="); writer.print(mEnterAnimationComplete ? "Y" : "N"); |
| 2384 | writer.print(" touchExplorationOn="); writer.print(mTouchExplorationEnabled ? "Y" : "N"); |
| 2385 | writer.print(" screenPinningOn="); writer.print(mScreenPinningEnabled ? "Y" : "N"); |
| 2386 | writer.print(" numIgnoreTasks="); writer.print(mIgnoreTasks.size()); |
| 2387 | writer.print(" numViewPool="); writer.print(mViewPool.getViews().size()); |
| 2388 | writer.print(" stableStackBounds="); writer.print(Utilities.dumpRect(mStableStackBounds)); |
| 2389 | writer.print(" stackBounds="); writer.print(Utilities.dumpRect(mStackBounds)); |
| 2390 | writer.print(" stableWindow="); writer.print(Utilities.dumpRect(mStableWindowRect)); |
| 2391 | writer.print(" window="); writer.print(Utilities.dumpRect(mWindowRect)); |
Winson | fc48b07 | 2016-04-21 11:20:11 -0700 | [diff] [blame] | 2392 | writer.print(" display="); writer.print(Utilities.dumpRect(mDisplayRect)); |
| 2393 | writer.print(" orientation="); writer.print(mDisplayOrientation); |
Winson | d72c315 | 2016-04-05 15:33:35 -0700 | [diff] [blame] | 2394 | writer.print(" [0x"); writer.print(id); writer.print("]"); |
| 2395 | writer.println(); |
| 2396 | |
| 2397 | if (mFocusedTask != null) { |
| 2398 | writer.print(innerPrefix); |
| 2399 | writer.print("Focused task: "); |
Winson | 67c7957 | 2016-04-13 14:02:18 -0700 | [diff] [blame] | 2400 | mFocusedTask.dump("", writer); |
Winson | d72c315 | 2016-04-05 15:33:35 -0700 | [diff] [blame] | 2401 | } |
| 2402 | |
Winson Chung | eb2206c | 2017-01-03 12:37:08 -0800 | [diff] [blame] | 2403 | int numTaskViews = mTaskViews.size(); |
| 2404 | for (int i = 0; i < numTaskViews; i++) { |
| 2405 | mTaskViews.get(i).dump(innerPrefix, writer); |
| 2406 | } |
| 2407 | |
Winson | d72c315 | 2016-04-05 15:33:35 -0700 | [diff] [blame] | 2408 | mLayoutAlgorithm.dump(innerPrefix, writer); |
| 2409 | mStackScroller.dump(innerPrefix, writer); |
| 2410 | } |
Winson Chung | a4cc966 | 2014-07-25 12:10:38 -0700 | [diff] [blame] | 2411 | } |