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