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