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