Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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.server.wm; |
| 18 | |
Jorim Jaggi | 2917dc4 | 2016-04-11 11:39:13 -0700 | [diff] [blame] | 19 | import static android.app.ActivityManager.DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT; |
Chong Zhang | 73d4b44 | 2016-05-25 14:30:36 -0700 | [diff] [blame] | 20 | import static android.app.ActivityManager.DOCKED_STACK_CREATE_MODE_BOTTOM_OR_RIGHT; |
Jorim Jaggi | 2917dc4 | 2016-04-11 11:39:13 -0700 | [diff] [blame] | 21 | import static android.app.ActivityManager.StackId.DOCKED_STACK_ID; |
| 22 | import static android.app.ActivityManager.StackId.PINNED_STACK_ID; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 23 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT; |
| 24 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; |
| 25 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS; |
| 26 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 27 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET; |
Jorim Jaggi | 2917dc4 | 2016-04-11 11:39:13 -0700 | [diff] [blame] | 28 | import static android.content.res.Configuration.DENSITY_DPI_UNDEFINED; |
| 29 | import static android.content.res.Configuration.ORIENTATION_PORTRAIT; |
Winson Chung | 303c6b7 | 2016-10-24 17:12:49 -0700 | [diff] [blame] | 30 | import static android.view.Display.DEFAULT_DISPLAY; |
Jorim Jaggi | 2917dc4 | 2016-04-11 11:39:13 -0700 | [diff] [blame] | 31 | import static android.view.WindowManager.DOCKED_BOTTOM; |
| 32 | import static android.view.WindowManager.DOCKED_INVALID; |
| 33 | import static android.view.WindowManager.DOCKED_LEFT; |
| 34 | import static android.view.WindowManager.DOCKED_RIGHT; |
| 35 | import static android.view.WindowManager.DOCKED_TOP; |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 36 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 37 | import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER; |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 38 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM; |
Jorim Jaggi | 2917dc4 | 2016-04-11 11:39:13 -0700 | [diff] [blame] | 39 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_MOVEMENT; |
| 40 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 41 | import static com.android.server.wm.WindowManagerService.LAYER_OFFSET_DIM; |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 42 | import static com.android.server.wm.proto.StackProto.ANIMATION_BACKGROUND_SURFACE_IS_DIMMING; |
| 43 | import static com.android.server.wm.proto.StackProto.BOUNDS; |
| 44 | import static com.android.server.wm.proto.StackProto.FILLS_PARENT; |
| 45 | import static com.android.server.wm.proto.StackProto.ID; |
| 46 | import static com.android.server.wm.proto.StackProto.TASKS; |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 47 | import static com.android.server.wm.proto.StackProto.WINDOW_CONTAINER; |
Jorim Jaggi | 2917dc4 | 2016-04-11 11:39:13 -0700 | [diff] [blame] | 48 | |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 49 | import android.annotation.CallSuper; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 50 | import android.content.res.Configuration; |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 51 | import android.graphics.Rect; |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 52 | import android.graphics.Region; |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 53 | import android.os.RemoteException; |
Craig Mautner | 2c2549c | 2013-11-12 08:31:15 -0800 | [diff] [blame] | 54 | import android.util.EventLog; |
Craig Mautner | f0ac5c8 | 2013-06-24 11:21:57 -0700 | [diff] [blame] | 55 | import android.util.Slog; |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 56 | import android.util.SparseArray; |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 57 | import android.util.proto.ProtoOutputStream; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 58 | import android.view.DisplayInfo; |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 59 | import android.view.Surface; |
Filip Gruszczynski | 54977fe | 2015-10-19 17:26:45 -0700 | [diff] [blame] | 60 | |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 61 | import com.android.internal.policy.DividerSnapAlgorithm; |
| 62 | import com.android.internal.policy.DividerSnapAlgorithm.SnapTarget; |
| 63 | import com.android.internal.policy.DockedDividerUtils; |
Craig Mautner | 2c2549c | 2013-11-12 08:31:15 -0800 | [diff] [blame] | 64 | import com.android.server.EventLogTags; |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 65 | |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 66 | import java.io.PrintWriter; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 67 | |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 68 | public class TaskStack extends WindowContainer<Task> implements DimLayer.DimLayerUser, |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 69 | BoundsAnimationTarget { |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 70 | /** Minimum size of an adjusted stack bounds relative to original stack bounds. Used to |
| 71 | * restrict IME adjustment so that a min portion of top stack remains visible.*/ |
| 72 | private static final float ADJUSTED_STACK_FRACTION_MIN = 0.3f; |
| 73 | |
| 74 | /** Dimming amount for non-focused stack when stacks are IME-adjusted. */ |
| 75 | private static final float IME_ADJUST_DIM_AMOUNT = 0.25f; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 76 | |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 77 | /** Unique identifier */ |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 78 | final int mStackId; |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 79 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 80 | /** The service */ |
| 81 | private final WindowManagerService mService; |
| 82 | |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 83 | /** The display this stack sits under. */ |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 84 | // TODO: Track parent marks like this in WindowContainer. |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 85 | private DisplayContent mDisplayContent; |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 86 | |
Craig Mautner | b660b9d | 2014-02-13 10:59:16 -0800 | [diff] [blame] | 87 | /** For comparison with DisplayContent bounds. */ |
| 88 | private Rect mTmpRect = new Rect(); |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 89 | private Rect mTmpRect2 = new Rect(); |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 90 | private Rect mTmpRect3 = new Rect(); |
Craig Mautner | b660b9d | 2014-02-13 10:59:16 -0800 | [diff] [blame] | 91 | |
| 92 | /** Content limits relative to the DisplayContent this sits in. */ |
| 93 | private Rect mBounds = new Rect(); |
| 94 | |
Chong Zhang | b816b86 | 2016-01-25 12:01:12 -0800 | [diff] [blame] | 95 | /** Stack bounds adjusted to screen content area (taking into account IM windows, etc.) */ |
| 96 | private final Rect mAdjustedBounds = new Rect(); |
| 97 | |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 98 | /** |
| 99 | * Fully adjusted IME bounds. These are different from {@link #mAdjustedBounds} because they |
| 100 | * represent the state when the animation has ended. |
| 101 | */ |
| 102 | private final Rect mFullyAdjustedImeBounds = new Rect(); |
| 103 | |
Craig Mautner | b660b9d | 2014-02-13 10:59:16 -0800 | [diff] [blame] | 104 | /** Whether mBounds is fullscreen */ |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 105 | private boolean mFillsParent = true; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 106 | |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 107 | // Device rotation as of the last time {@link #mBounds} was set. |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 108 | private int mRotation; |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 109 | |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 110 | /** Density as of last time {@link #mBounds} was set. */ |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 111 | private int mDensity; |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 112 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 113 | /** Support for non-zero {@link android.view.animation.Animation#getBackgroundColor()} */ |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 114 | private DimLayer mAnimationBackgroundSurface; |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 115 | |
| 116 | /** The particular window with an Animation with non-zero background color. */ |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 117 | private WindowStateAnimator mAnimationBackgroundAnimator; |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 118 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 119 | /** Application tokens that are exiting, but still on screen for animations. */ |
| 120 | final AppTokenList mExitingAppTokens = new AppTokenList(); |
Wale Ogunwale | 48458e1 | 2017-06-06 10:07:58 -0700 | [diff] [blame] | 121 | final AppTokenList mTmpAppTokens = new AppTokenList(); |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 122 | |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 123 | /** Detach this stack from its display when animation completes. */ |
Wale Ogunwale | f619286 | 2016-09-10 13:42:30 -0700 | [diff] [blame] | 124 | // TODO: maybe tie this to WindowContainer#removeChild some how... |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 125 | boolean mDeferRemoval; |
Wale Ogunwale | ecbcadd | 2016-02-21 14:18:51 -0800 | [diff] [blame] | 126 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 127 | private final Rect mTmpAdjustedBounds = new Rect(); |
| 128 | private boolean mAdjustedForIme; |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 129 | private boolean mImeGoingAway; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 130 | private WindowState mImeWin; |
| 131 | private float mMinimizeAmount; |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 132 | private float mAdjustImeAmount; |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 133 | private float mAdjustDividerAmount; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 134 | private final int mDockedStackMinimizeThickness; |
| 135 | |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 136 | // If this is true, we are in the bounds animating mode. The task will be down or upscaled to |
| 137 | // perfectly fit the region it would have been cropped to. We may also avoid certain logic we |
| 138 | // would otherwise apply while resizing, while resizing in the bounds animating mode. |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 139 | private boolean mBoundsAnimating = false; |
Winson Chung | 40a5f93 | 2017-04-13 16:39:36 -0700 | [diff] [blame] | 140 | // Set when an animation has been requested but has not yet started from the UI thread. This is |
| 141 | // cleared when the animation actually starts. |
| 142 | private boolean mBoundsAnimatingRequested = false; |
Robert Carr | 7e4c90e | 2017-02-15 19:52:38 -0800 | [diff] [blame] | 143 | private boolean mBoundsAnimatingToFullscreen = false; |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 144 | private boolean mCancelCurrentBoundsAnimation = false; |
Winson Chung | 84a3834 | 2016-11-08 16:15:10 -0800 | [diff] [blame] | 145 | private Rect mBoundsAnimationTarget = new Rect(); |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 146 | private Rect mBoundsAnimationSourceHintBounds = new Rect(); |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 147 | |
Chong Zhang | 167bbfac | 2016-03-31 09:44:34 -0700 | [diff] [blame] | 148 | // Temporary storage for the new bounds that should be used after the configuration change. |
| 149 | // Will be cleared once the client retrieves the new bounds via getBoundsForNewConfiguration(). |
| 150 | private final Rect mBoundsAfterRotation = new Rect(); |
| 151 | |
Robert Carr | 18f622f | 2017-05-08 11:20:43 -0700 | [diff] [blame] | 152 | Rect mPreAnimationBounds = new Rect(); |
| 153 | |
Wale Ogunwale | 704a3c0 | 2017-09-18 15:30:52 -0700 | [diff] [blame] | 154 | TaskStack(WindowManagerService service, int stackId, StackWindowController controller) { |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 155 | mService = service; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 156 | mStackId = stackId; |
Wale Ogunwale | 704a3c0 | 2017-09-18 15:30:52 -0700 | [diff] [blame] | 157 | setController(controller); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 158 | mDockedStackMinimizeThickness = service.mContext.getResources().getDimensionPixelSize( |
| 159 | com.android.internal.R.dimen.docked_stack_minimize_thickness); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 160 | EventLog.writeEvent(EventLogTags.WM_STACK_CREATED, stackId); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | DisplayContent getDisplayContent() { |
| 164 | return mDisplayContent; |
| 165 | } |
| 166 | |
Jorim Jaggi | d3ec507 | 2016-04-28 15:57:47 -0700 | [diff] [blame] | 167 | Task findHomeTask() { |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 168 | if (!isActivityTypeHome() || mChildren.isEmpty()) { |
Jorim Jaggi | d3ec507 | 2016-04-28 15:57:47 -0700 | [diff] [blame] | 169 | return null; |
| 170 | } |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 171 | return mChildren.get(mChildren.size() - 1); |
Wale Ogunwale | 15ead90 | 2016-09-02 14:30:11 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 174 | /** |
| 175 | * Set the bounds of the stack and its containing tasks. |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 176 | * @param stackBounds New stack bounds. Passing in null sets the bounds to fullscreen. |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 177 | * @param configs Configuration for individual tasks, keyed by task id. |
| 178 | * @param taskBounds Bounds for individual tasks, keyed by task id. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 179 | * @return True if the stack bounds was changed. |
| 180 | * */ |
Wale Ogunwale | a6e902e | 2015-09-21 18:37:15 -0700 | [diff] [blame] | 181 | boolean setBounds( |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 182 | Rect stackBounds, SparseArray<Configuration> configs, SparseArray<Rect> taskBounds, |
| 183 | SparseArray<Rect> taskTempInsetBounds) { |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 184 | setBounds(stackBounds); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 185 | |
| 186 | // Update bounds of containing tasks. |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 187 | for (int taskNdx = mChildren.size() - 1; taskNdx >= 0; --taskNdx) { |
| 188 | final Task task = mChildren.get(taskNdx); |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 189 | Configuration config = configs.get(task.mTaskId); |
| 190 | if (config != null) { |
| 191 | Rect bounds = taskBounds.get(task.mTaskId); |
Chong Zhang | 2e2c81a | 2016-07-15 11:28:17 -0700 | [diff] [blame] | 192 | task.resizeLocked(bounds, config, false /* forced */); |
| 193 | task.setTempInsetBounds(taskTempInsetBounds != null ? |
| 194 | taskTempInsetBounds.get(task.mTaskId) : null); |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 195 | } else { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 196 | Slog.wtf(TAG_WM, "No config for task: " + task + ", is there a mismatch with AM?"); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 197 | } |
| 198 | } |
| 199 | return true; |
| 200 | } |
| 201 | |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 202 | void prepareFreezingTaskBounds() { |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 203 | for (int taskNdx = mChildren.size() - 1; taskNdx >= 0; --taskNdx) { |
| 204 | final Task task = mChildren.get(taskNdx); |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 205 | task.prepareFreezingBounds(); |
| 206 | } |
| 207 | } |
| 208 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 209 | /** |
| 210 | * Overrides the adjusted bounds, i.e. sets temporary layout bounds which are different from |
| 211 | * the normal task bounds. |
| 212 | * |
| 213 | * @param bounds The adjusted bounds. |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 214 | */ |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 215 | private void setAdjustedBounds(Rect bounds) { |
| 216 | if (mAdjustedBounds.equals(bounds) && !isAnimatingForIme()) { |
| 217 | return; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | mAdjustedBounds.set(bounds); |
| 221 | final boolean adjusted = !mAdjustedBounds.isEmpty(); |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 222 | Rect insetBounds = null; |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 223 | if (adjusted && isAdjustedForMinimizedDockedStack()) { |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 224 | insetBounds = mBounds; |
Chong Zhang | 5117e27 | 2016-05-03 12:47:34 -0700 | [diff] [blame] | 225 | } else if (adjusted && mAdjustedForIme) { |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 226 | if (mImeGoingAway) { |
| 227 | insetBounds = mBounds; |
| 228 | } else { |
| 229 | insetBounds = mFullyAdjustedImeBounds; |
| 230 | } |
| 231 | } |
Chong Zhang | 741c0ba | 2016-05-27 12:52:11 -0700 | [diff] [blame] | 232 | alignTasksToAdjustedBounds(adjusted ? mAdjustedBounds : mBounds, insetBounds); |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 233 | mDisplayContent.setLayoutNeeded(); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | private void alignTasksToAdjustedBounds(Rect adjustedBounds, Rect tempInsetBounds) { |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 237 | if (mFillsParent) { |
Chong Zhang | b816b86 | 2016-01-25 12:01:12 -0800 | [diff] [blame] | 238 | return; |
| 239 | } |
Chong Zhang | 2e2c81a | 2016-07-15 11:28:17 -0700 | [diff] [blame] | 240 | |
| 241 | final boolean alignBottom = mAdjustedForIme && getDockSide() == DOCKED_TOP; |
| 242 | |
Chong Zhang | b816b86 | 2016-01-25 12:01:12 -0800 | [diff] [blame] | 243 | // Update bounds of containing tasks. |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 244 | for (int taskNdx = mChildren.size() - 1; taskNdx >= 0; --taskNdx) { |
| 245 | final Task task = mChildren.get(taskNdx); |
Chong Zhang | 2e2c81a | 2016-07-15 11:28:17 -0700 | [diff] [blame] | 246 | task.alignToAdjustedBounds(adjustedBounds, tempInsetBounds, alignBottom); |
Chong Zhang | b816b86 | 2016-01-25 12:01:12 -0800 | [diff] [blame] | 247 | } |
| 248 | } |
| 249 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 250 | private boolean setBounds(Rect bounds) { |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 251 | boolean oldFullscreen = mFillsParent; |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 252 | int rotation = Surface.ROTATION_0; |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 253 | int density = DENSITY_DPI_UNDEFINED; |
Craig Mautner | b660b9d | 2014-02-13 10:59:16 -0800 | [diff] [blame] | 254 | if (mDisplayContent != null) { |
| 255 | mDisplayContent.getLogicalDisplayRect(mTmpRect); |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 256 | rotation = mDisplayContent.getDisplayInfo().rotation; |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 257 | density = mDisplayContent.getDisplayInfo().logicalDensityDpi; |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 258 | mFillsParent = bounds == null; |
| 259 | if (mFillsParent) { |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 260 | bounds = mTmpRect; |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 261 | } |
Craig Mautner | b660b9d | 2014-02-13 10:59:16 -0800 | [diff] [blame] | 262 | } |
| 263 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 264 | if (bounds == null) { |
Wale Ogunwale | 4a02d81 | 2015-02-12 23:01:38 -0800 | [diff] [blame] | 265 | // Can't set to fullscreen if we don't have a display to get bounds from... |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 266 | return false; |
| 267 | } |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 268 | if (mBounds.equals(bounds) && oldFullscreen == mFillsParent && mRotation == rotation) { |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 269 | return false; |
| 270 | } |
| 271 | |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 272 | if (mDisplayContent != null) { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 273 | mDisplayContent.mDimLayerController.updateDimLayer(this); |
Filip Gruszczynski | 57b6cce | 2015-10-06 09:50:51 -0700 | [diff] [blame] | 274 | mAnimationBackgroundSurface.setBounds(bounds); |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 277 | mBounds.set(bounds); |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 278 | mRotation = rotation; |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 279 | mDensity = density; |
Chong Zhang | b816b86 | 2016-01-25 12:01:12 -0800 | [diff] [blame] | 280 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 281 | updateAdjustedBounds(); |
Chong Zhang | b816b86 | 2016-01-25 12:01:12 -0800 | [diff] [blame] | 282 | |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 283 | return true; |
| 284 | } |
| 285 | |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 286 | /** Bounds of the stack without adjusting for other factors in the system like visibility |
| 287 | * of docked stack. |
| 288 | * Most callers should be using {@link #getBounds} as it take into consideration other system |
| 289 | * factors. */ |
| 290 | void getRawBounds(Rect out) { |
Craig Mautner | b660b9d | 2014-02-13 10:59:16 -0800 | [diff] [blame] | 291 | out.set(mBounds); |
| 292 | } |
| 293 | |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 294 | /** Return true if the current bound can get outputted to the rest of the system as-is. */ |
| 295 | private boolean useCurrentBounds() { |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 296 | if (mFillsParent |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 297 | || !inSplitScreenSecondaryWindowingMode() |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 298 | || mDisplayContent == null |
| 299 | || mDisplayContent.getDockedStackLocked() != null) { |
| 300 | return true; |
| 301 | } |
| 302 | return false; |
| 303 | } |
| 304 | |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 305 | public void getBounds(Rect out) { |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 306 | if (useCurrentBounds()) { |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 307 | // If we're currently adjusting for IME or minimized docked stack, we use the adjusted |
| 308 | // bounds; otherwise, no need to adjust the output bounds if fullscreen or the docked |
| 309 | // stack is visible since it is already what we want to represent to the rest of the |
| 310 | // system. |
| 311 | if (!mAdjustedBounds.isEmpty()) { |
Chong Zhang | b816b86 | 2016-01-25 12:01:12 -0800 | [diff] [blame] | 312 | out.set(mAdjustedBounds); |
| 313 | } else { |
| 314 | out.set(mBounds); |
| 315 | } |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 316 | return; |
| 317 | } |
| 318 | |
| 319 | // The bounds has been adjusted to accommodate for a docked stack, but the docked stack |
| 320 | // is not currently visible. Go ahead a represent it as fullscreen to the rest of the |
| 321 | // system. |
| 322 | mDisplayContent.getLogicalDisplayRect(out); |
| 323 | } |
| 324 | |
Winson Chung | 84a3834 | 2016-11-08 16:15:10 -0800 | [diff] [blame] | 325 | /** |
Winson Chung | 40a5f93 | 2017-04-13 16:39:36 -0700 | [diff] [blame] | 326 | * Sets the bounds animation target bounds ahead of an animation. This can't currently be done |
| 327 | * in onAnimationStart() since that is started on the UiThread. |
Winson Chung | 84a3834 | 2016-11-08 16:15:10 -0800 | [diff] [blame] | 328 | */ |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 329 | void setAnimationFinalBounds(Rect sourceHintBounds, Rect destBounds, boolean toFullscreen) { |
Winson Chung | 40a5f93 | 2017-04-13 16:39:36 -0700 | [diff] [blame] | 330 | mBoundsAnimatingRequested = true; |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 331 | mBoundsAnimatingToFullscreen = toFullscreen; |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 332 | if (destBounds != null) { |
| 333 | mBoundsAnimationTarget.set(destBounds); |
Winson Chung | 84a3834 | 2016-11-08 16:15:10 -0800 | [diff] [blame] | 334 | } else { |
| 335 | mBoundsAnimationTarget.setEmpty(); |
| 336 | } |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 337 | if (sourceHintBounds != null) { |
| 338 | mBoundsAnimationSourceHintBounds.set(sourceHintBounds); |
| 339 | } else { |
| 340 | mBoundsAnimationSourceHintBounds.setEmpty(); |
| 341 | } |
Robert Carr | 18f622f | 2017-05-08 11:20:43 -0700 | [diff] [blame] | 342 | |
| 343 | mPreAnimationBounds.set(mBounds); |
Winson Chung | 84a3834 | 2016-11-08 16:15:10 -0800 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | /** |
Winson Chung | 40a5f93 | 2017-04-13 16:39:36 -0700 | [diff] [blame] | 347 | * @return the final bounds for the bounds animation. |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 348 | */ |
Winson Chung | 40a5f93 | 2017-04-13 16:39:36 -0700 | [diff] [blame] | 349 | void getFinalAnimationBounds(Rect outBounds) { |
| 350 | outBounds.set(mBoundsAnimationTarget); |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | /** |
Winson Chung | 40a5f93 | 2017-04-13 16:39:36 -0700 | [diff] [blame] | 354 | * @return the final source bounds for the bounds animation. |
Winson Chung | 84a3834 | 2016-11-08 16:15:10 -0800 | [diff] [blame] | 355 | */ |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 356 | void getFinalAnimationSourceHintBounds(Rect outBounds) { |
| 357 | outBounds.set(mBoundsAnimationSourceHintBounds); |
Winson Chung | 40a5f93 | 2017-04-13 16:39:36 -0700 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | /** |
| 361 | * @return the final animation bounds if the task stack is currently being animated, or the |
| 362 | * current stack bounds otherwise. |
| 363 | */ |
| 364 | void getAnimationOrCurrentBounds(Rect outBounds) { |
| 365 | if ((mBoundsAnimatingRequested || mBoundsAnimating) && !mBoundsAnimationTarget.isEmpty()) { |
| 366 | getFinalAnimationBounds(outBounds); |
Winson Chung | 84a3834 | 2016-11-08 16:15:10 -0800 | [diff] [blame] | 367 | return; |
| 368 | } |
| 369 | getBounds(outBounds); |
| 370 | } |
| 371 | |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 372 | /** Bounds of the stack with other system factors taken into consideration. */ |
| 373 | @Override |
| 374 | public void getDimBounds(Rect out) { |
| 375 | getBounds(out); |
| 376 | } |
| 377 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 378 | void updateDisplayInfo(Rect bounds) { |
Wale Ogunwale | ecbcadd | 2016-02-21 14:18:51 -0800 | [diff] [blame] | 379 | if (mDisplayContent == null) { |
| 380 | return; |
| 381 | } |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 382 | |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 383 | for (int taskNdx = mChildren.size() - 1; taskNdx >= 0; --taskNdx) { |
| 384 | mChildren.get(taskNdx).updateDisplayInfo(mDisplayContent); |
Wale Ogunwale | ecbcadd | 2016-02-21 14:18:51 -0800 | [diff] [blame] | 385 | } |
| 386 | if (bounds != null) { |
| 387 | setBounds(bounds); |
| 388 | return; |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 389 | } else if (mFillsParent) { |
Wale Ogunwale | ecbcadd | 2016-02-21 14:18:51 -0800 | [diff] [blame] | 390 | setBounds(null); |
| 391 | return; |
| 392 | } |
| 393 | |
| 394 | mTmpRect2.set(mBounds); |
| 395 | final int newRotation = mDisplayContent.getDisplayInfo().rotation; |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 396 | final int newDensity = mDisplayContent.getDisplayInfo().logicalDensityDpi; |
| 397 | if (mRotation == newRotation && mDensity == newDensity) { |
Wale Ogunwale | ecbcadd | 2016-02-21 14:18:51 -0800 | [diff] [blame] | 398 | setBounds(mTmpRect2); |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 399 | } |
Jorim Jaggi | eb1cb92 | 2016-04-27 20:37:45 -0700 | [diff] [blame] | 400 | |
| 401 | // If the rotation or density didn't match, we'll update it in onConfigurationChanged. |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 402 | } |
| 403 | |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 404 | /** @return true if bounds were updated to some non-empty value. */ |
| 405 | boolean updateBoundsAfterConfigChange() { |
Andrii Kulian | 0be2cfe | 2016-05-25 14:27:39 -0700 | [diff] [blame] | 406 | if (mDisplayContent == null) { |
| 407 | // If the stack is already detached we're not updating anything, |
| 408 | // as it's going away soon anyway. |
| 409 | return false; |
| 410 | } |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 411 | |
| 412 | if (mStackId == PINNED_STACK_ID) { |
Winson Chung | 40a5f93 | 2017-04-13 16:39:36 -0700 | [diff] [blame] | 413 | getAnimationOrCurrentBounds(mTmpRect2); |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 414 | boolean updated = mDisplayContent.mPinnedStackControllerLocked.onTaskStackBoundsChanged( |
| 415 | mTmpRect2, mTmpRect3); |
| 416 | if (updated) { |
| 417 | mBoundsAfterRotation.set(mTmpRect3); |
| 418 | |
| 419 | // Once we've set the bounds based on the rotation of the old bounds in the new |
| 420 | // orientation, clear the animation target bounds since they are obsolete, and |
| 421 | // cancel any currently running animations |
| 422 | mBoundsAnimationTarget.setEmpty(); |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 423 | mBoundsAnimationSourceHintBounds.setEmpty(); |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 424 | mCancelCurrentBoundsAnimation = true; |
| 425 | return true; |
| 426 | } |
| 427 | } |
| 428 | |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 429 | final int newRotation = getDisplayInfo().rotation; |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 430 | final int newDensity = getDisplayInfo().logicalDensityDpi; |
Wale Ogunwale | ecbcadd | 2016-02-21 14:18:51 -0800 | [diff] [blame] | 431 | |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 432 | if (mRotation == newRotation && mDensity == newDensity) { |
Jorim Jaggi | eb1cb92 | 2016-04-27 20:37:45 -0700 | [diff] [blame] | 433 | // Nothing to do here as we already update the state in updateDisplayInfo. |
Chong Zhang | 167bbfac | 2016-03-31 09:44:34 -0700 | [diff] [blame] | 434 | return false; |
Wale Ogunwale | ecbcadd | 2016-02-21 14:18:51 -0800 | [diff] [blame] | 435 | } |
| 436 | |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 437 | if (mFillsParent) { |
Chong Zhang | ccc335c | 2016-05-13 11:04:38 -0700 | [diff] [blame] | 438 | // Update stack bounds again since rotation changed since updateDisplayInfo(). |
| 439 | setBounds(null); |
| 440 | // Return false since we don't need the client to resize. |
| 441 | return false; |
| 442 | } |
| 443 | |
Wale Ogunwale | 5952f9a | 2016-04-25 13:40:30 -0700 | [diff] [blame] | 444 | mTmpRect2.set(mBounds); |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 445 | mDisplayContent.rotateBounds(mRotation, newRotation, mTmpRect2); |
Winson Chung | cd1ff64 | 2016-10-26 09:44:43 -0700 | [diff] [blame] | 446 | switch (mStackId) { |
Winson Chung | cd1ff64 | 2016-10-26 09:44:43 -0700 | [diff] [blame] | 447 | case DOCKED_STACK_ID: |
| 448 | repositionDockedStackAfterRotation(mTmpRect2); |
| 449 | snapDockedStackAfterRotation(mTmpRect2); |
| 450 | final int newDockSide = getDockSide(mTmpRect2); |
| 451 | |
| 452 | // Update the dock create mode and clear the dock create bounds, these |
| 453 | // might change after a rotation and the original values will be invalid. |
| 454 | mService.setDockedStackCreateStateLocked( |
| 455 | (newDockSide == DOCKED_LEFT || newDockSide == DOCKED_TOP) |
| 456 | ? DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT |
| 457 | : DOCKED_STACK_CREATE_MODE_BOTTOM_OR_RIGHT, |
| 458 | null); |
| 459 | mDisplayContent.getDockedDividerController().notifyDockSideChanged(newDockSide); |
| 460 | break; |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 461 | } |
| 462 | |
Jorim Jaggi | eb1cb92 | 2016-04-27 20:37:45 -0700 | [diff] [blame] | 463 | mBoundsAfterRotation.set(mTmpRect2); |
Chong Zhang | 167bbfac | 2016-03-31 09:44:34 -0700 | [diff] [blame] | 464 | return true; |
| 465 | } |
| 466 | |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 467 | void getBoundsForNewConfiguration(Rect outBounds) { |
Chong Zhang | 167bbfac | 2016-03-31 09:44:34 -0700 | [diff] [blame] | 468 | outBounds.set(mBoundsAfterRotation); |
| 469 | mBoundsAfterRotation.setEmpty(); |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | /** |
Jorim Jaggi | 5060bd8 | 2016-02-19 17:12:19 -0800 | [diff] [blame] | 473 | * Some dock sides are not allowed by the policy. This method queries the policy and moves |
| 474 | * the docked stack around if needed. |
| 475 | * |
| 476 | * @param inOutBounds the bounds of the docked stack to adjust |
| 477 | */ |
| 478 | private void repositionDockedStackAfterRotation(Rect inOutBounds) { |
| 479 | int dockSide = getDockSide(inOutBounds); |
| 480 | if (mService.mPolicy.isDockSideAllowed(dockSide)) { |
| 481 | return; |
| 482 | } |
| 483 | mDisplayContent.getLogicalDisplayRect(mTmpRect); |
| 484 | dockSide = DockedDividerUtils.invertDockSide(dockSide); |
| 485 | switch (dockSide) { |
| 486 | case DOCKED_LEFT: |
| 487 | int movement = inOutBounds.left; |
| 488 | inOutBounds.left -= movement; |
| 489 | inOutBounds.right -= movement; |
| 490 | break; |
| 491 | case DOCKED_RIGHT: |
| 492 | movement = mTmpRect.right - inOutBounds.right; |
| 493 | inOutBounds.left += movement; |
| 494 | inOutBounds.right += movement; |
| 495 | break; |
| 496 | case DOCKED_TOP: |
| 497 | movement = inOutBounds.top; |
| 498 | inOutBounds.top -= movement; |
| 499 | inOutBounds.bottom -= movement; |
| 500 | break; |
| 501 | case DOCKED_BOTTOM: |
| 502 | movement = mTmpRect.bottom - inOutBounds.bottom; |
| 503 | inOutBounds.top += movement; |
| 504 | inOutBounds.bottom += movement; |
| 505 | break; |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | /** |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 510 | * Snaps the bounds after rotation to the closest snap target for the docked stack. |
| 511 | */ |
| 512 | private void snapDockedStackAfterRotation(Rect outBounds) { |
| 513 | |
| 514 | // Calculate the current position. |
| 515 | final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo(); |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 516 | final int dividerSize = mDisplayContent.getDockedDividerController().getContentWidth(); |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 517 | final int dockSide = getDockSide(outBounds); |
| 518 | final int dividerPosition = DockedDividerUtils.calculatePositionForBounds(outBounds, |
| 519 | dockSide, dividerSize); |
| 520 | final int displayWidth = mDisplayContent.getDisplayInfo().logicalWidth; |
| 521 | final int displayHeight = mDisplayContent.getDisplayInfo().logicalHeight; |
| 522 | |
| 523 | // Snap the position to a target. |
| 524 | final int rotation = displayInfo.rotation; |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 525 | final int orientation = mDisplayContent.getConfiguration().orientation; |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 526 | mService.mPolicy.getStableInsetsLw(rotation, displayWidth, displayHeight, outBounds); |
| 527 | final DividerSnapAlgorithm algorithm = new DividerSnapAlgorithm( |
Jorim Jaggi | df012d5 | 2016-01-15 22:40:13 -0800 | [diff] [blame] | 528 | mService.mContext.getResources(), displayWidth, displayHeight, |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 529 | dividerSize, orientation == Configuration.ORIENTATION_PORTRAIT, outBounds, |
| 530 | isMinimizedDockAndHomeStackResizable()); |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 531 | final SnapTarget target = algorithm.calculateNonDismissingSnapTarget(dividerPosition); |
| 532 | |
| 533 | // Recalculate the bounds based on the position of the target. |
| 534 | DockedDividerUtils.calculateBoundsForPosition(target.position, dockSide, |
| 535 | outBounds, displayInfo.logicalWidth, displayInfo.logicalHeight, |
| 536 | dividerSize); |
| 537 | } |
| 538 | |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 539 | // TODO: Checkout the call points of this method and the ones below to see how they can fit in WC. |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 540 | void addTask(Task task, int position) { |
| 541 | addTask(task, position, task.showForAllUsers(), true /* moveParents */); |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 544 | /** |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 545 | * Put a Task in this stack. Used for adding only. |
| 546 | * When task is added to top of the stack, the entire branch of the hierarchy (including stack |
| 547 | * and display) will be brought to top. |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 548 | * @param task The task to add. |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 549 | * @param position Target position to add the task to. |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 550 | * @param showForAllUsers Whether to show the task regardless of the current user. |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 551 | */ |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 552 | void addTask(Task task, int position, boolean showForAllUsers, boolean moveParents) { |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 553 | final TaskStack currentStack = task.mStack; |
| 554 | // TODO: We pass stack to task's constructor, but we still need to call this method. |
| 555 | // This doesn't make sense, mStack will already be set equal to "this" at this point. |
| 556 | if (currentStack != null && currentStack.mStackId != mStackId) { |
| 557 | throw new IllegalStateException("Trying to add taskId=" + task.mTaskId |
| 558 | + " to stackId=" + mStackId |
| 559 | + ", but it is already attached to stackId=" + task.mStack.mStackId); |
| 560 | } |
| 561 | |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 562 | // Add child task. |
| 563 | task.mStack = this; |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 564 | addChild(task, null); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 565 | |
| 566 | // Move child to a proper position, as some restriction for position might apply. |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 567 | positionChildAt(position, task, moveParents /* includingParents */, showForAllUsers); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | @Override |
| 571 | void positionChildAt(int position, Task child, boolean includingParents) { |
| 572 | positionChildAt(position, child, includingParents, child.showForAllUsers()); |
| 573 | } |
| 574 | |
| 575 | /** |
| 576 | * Overridden version of {@link TaskStack#positionChildAt(int, Task, boolean)}. Used in |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 577 | * {@link TaskStack#addTask(Task, int, boolean showForAllUsers, boolean)}, as it can receive |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 578 | * showForAllUsers param from {@link AppWindowToken} instead of {@link Task#showForAllUsers()}. |
| 579 | */ |
| 580 | private void positionChildAt(int position, Task child, boolean includingParents, |
| 581 | boolean showForAllUsers) { |
| 582 | final int targetPosition = findPositionForTask(child, position, showForAllUsers, |
| 583 | false /* addingNew */); |
| 584 | super.positionChildAt(targetPosition, child, includingParents); |
| 585 | |
| 586 | // Log positioning. |
| 587 | if (DEBUG_TASK_MOVEMENT) |
| 588 | Slog.d(TAG_WM, "positionTask: task=" + this + " position=" + position); |
| 589 | |
| 590 | final int toTop = targetPosition == mChildren.size() - 1 ? 1 : 0; |
| 591 | EventLog.writeEvent(EventLogTags.WM_TASK_MOVED, child.mTaskId, toTop, targetPosition); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 592 | } |
| 593 | |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 594 | // TODO: We should really have users as a window container in the hierarchy so that we don't |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 595 | // have to do complicated things like we are doing in this method. |
| 596 | private int findPositionForTask(Task task, int targetPosition, boolean showForAllUsers, |
| 597 | boolean addingNew) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 598 | final boolean canShowTask = |
| 599 | showForAllUsers || mService.isCurrentProfileLocked(task.mUserId); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 600 | |
| 601 | final int stackSize = mChildren.size(); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 602 | int minPosition = 0; |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 603 | int maxPosition = addingNew ? stackSize : stackSize - 1; |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 604 | |
| 605 | if (canShowTask) { |
| 606 | minPosition = computeMinPosition(minPosition, stackSize); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 607 | } else { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 608 | maxPosition = computeMaxPosition(maxPosition); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 609 | } |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 610 | // Reset position based on minimum/maximum possible positions. |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 611 | return Math.min(Math.max(targetPosition, minPosition), maxPosition); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | /** Calculate the minimum possible position for a task that can be shown to the user. |
| 615 | * The minimum position will be above all other tasks that can't be shown. |
| 616 | * @param minPosition The minimum position the caller is suggesting. |
| 617 | * We will start adjusting up from here. |
| 618 | * @param size The size of the current task list. |
| 619 | */ |
| 620 | private int computeMinPosition(int minPosition, int size) { |
| 621 | while (minPosition < size) { |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 622 | final Task tmpTask = mChildren.get(minPosition); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 623 | final boolean canShowTmpTask = |
| 624 | tmpTask.showForAllUsers() |
| 625 | || mService.isCurrentProfileLocked(tmpTask.mUserId); |
| 626 | if (canShowTmpTask) { |
| 627 | break; |
| 628 | } |
| 629 | minPosition++; |
| 630 | } |
| 631 | return minPosition; |
| 632 | } |
| 633 | |
| 634 | /** Calculate the maximum possible position for a task that can't be shown to the user. |
| 635 | * The maximum position will be below all other tasks that can be shown. |
| 636 | * @param maxPosition The maximum position the caller is suggesting. |
| 637 | * We will start adjusting down from here. |
| 638 | */ |
| 639 | private int computeMaxPosition(int maxPosition) { |
| 640 | while (maxPosition > 0) { |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 641 | final Task tmpTask = mChildren.get(maxPosition); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 642 | final boolean canShowTmpTask = |
| 643 | tmpTask.showForAllUsers() |
| 644 | || mService.isCurrentProfileLocked(tmpTask.mUserId); |
| 645 | if (!canShowTmpTask) { |
| 646 | break; |
| 647 | } |
| 648 | maxPosition--; |
| 649 | } |
| 650 | return maxPosition; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 651 | } |
| 652 | |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 653 | /** |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 654 | * Delete a Task from this stack. If it is the last Task in the stack, move this stack to the |
| 655 | * back. |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 656 | * @param task The Task to delete. |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 657 | */ |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 658 | @Override |
| 659 | void removeChild(Task task) { |
| 660 | if (DEBUG_TASK_MOVEMENT) Slog.d(TAG_WM, "removeChild: task=" + task); |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 661 | |
| 662 | super.removeChild(task); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 663 | task.mStack = null; |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 664 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 665 | if (mDisplayContent != null) { |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 666 | if (mChildren.isEmpty()) { |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 667 | getParent().positionChildAt(POSITION_BOTTOM, this, false /* includingParents */); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 668 | } |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 669 | mDisplayContent.setLayoutNeeded(); |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 670 | } |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 671 | for (int appNdx = mExitingAppTokens.size() - 1; appNdx >= 0; --appNdx) { |
| 672 | final AppWindowToken wtoken = mExitingAppTokens.get(appNdx); |
Bryce Lee | 6d41026 | 2017-02-28 15:30:17 -0800 | [diff] [blame] | 673 | if (wtoken.getTask() == task) { |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 674 | wtoken.mIsExiting = false; |
| 675 | mExitingAppTokens.remove(appNdx); |
| 676 | } |
| 677 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 678 | } |
| 679 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 680 | void onDisplayChanged(DisplayContent dc) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 681 | if (mDisplayContent != null) { |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 682 | throw new IllegalStateException("onDisplayChanged: Already attached"); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 683 | } |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 684 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 685 | mDisplayContent = dc; |
Jorim Jaggi | bc5425c | 2016-03-01 13:51:16 +0100 | [diff] [blame] | 686 | mAnimationBackgroundSurface = new DimLayer(mService, this, mDisplayContent.getDisplayId(), |
| 687 | "animation background stackId=" + mStackId); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 688 | |
| 689 | Rect bounds = null; |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 690 | final TaskStack dockedStack = dc.getDockedStackIgnoringVisibility(); |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 691 | if (mStackId == DOCKED_STACK_ID |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 692 | || (dockedStack != null && inSplitScreenSecondaryWindowingMode() |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 693 | && !dockedStack.fillsParent())) { |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 694 | // The existence of a docked stack affects the size of other static stack created since |
Jorim Jaggi | 65002e1 | 2016-04-21 18:25:49 -0700 | [diff] [blame] | 695 | // the docked stack occupies a dedicated region on screen, but only if the dock stack is |
| 696 | // not fullscreen. If it's fullscreen, it means that we are in the transition of |
| 697 | // dismissing it, so we must not resize this stack. |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 698 | bounds = new Rect(); |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 699 | dc.getLogicalDisplayRect(mTmpRect); |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 700 | mTmpRect2.setEmpty(); |
| 701 | if (dockedStack != null) { |
| 702 | dockedStack.getRawBounds(mTmpRect2); |
| 703 | } |
Jorim Jaggi | 9ea2f7b | 2015-11-23 18:08:28 -0800 | [diff] [blame] | 704 | final boolean dockedOnTopOrLeft = mService.mDockedStackCreateMode |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 705 | == DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT; |
| 706 | getStackDockedModeBounds(mTmpRect, bounds, mStackId, mTmpRect2, |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 707 | mDisplayContent.mDividerControllerLocked.getContentWidth(), |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 708 | dockedOnTopOrLeft); |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 709 | } else if (mStackId == PINNED_STACK_ID) { |
| 710 | // Update the bounds based on any changes to the display info |
Winson Chung | 40a5f93 | 2017-04-13 16:39:36 -0700 | [diff] [blame] | 711 | getAnimationOrCurrentBounds(mTmpRect2); |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 712 | boolean updated = mDisplayContent.mPinnedStackControllerLocked.onTaskStackBoundsChanged( |
| 713 | mTmpRect2, mTmpRect3); |
| 714 | if (updated) { |
| 715 | bounds = new Rect(mTmpRect3); |
| 716 | } |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | updateDisplayInfo(bounds); |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 720 | super.onDisplayChanged(dc); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 721 | } |
| 722 | |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 723 | /** |
| 724 | * Determines the stack and task bounds of the other stack when in docked mode. The current task |
| 725 | * bounds is passed in but depending on the stack, the task and stack must match. Only in |
| 726 | * minimized mode with resizable launcher, the other stack ignores calculating the stack bounds |
| 727 | * and uses the task bounds passed in as the stack and task bounds, otherwise the stack bounds |
| 728 | * is calculated and is also used for its task bounds. |
| 729 | * If any of the out bounds are empty, it represents default bounds |
| 730 | * |
| 731 | * @param currentTempTaskBounds the current task bounds of the other stack |
| 732 | * @param outStackBounds the calculated stack bounds of the other stack |
| 733 | * @param outTempTaskBounds the calculated task bounds of the other stack |
| 734 | * @param ignoreVisibility ignore visibility in getting the stack bounds |
| 735 | */ |
| 736 | void getStackDockedModeBoundsLocked(Rect currentTempTaskBounds, Rect outStackBounds, |
| 737 | Rect outTempTaskBounds, boolean ignoreVisibility) { |
| 738 | outTempTaskBounds.setEmpty(); |
| 739 | |
| 740 | // When the home stack is resizable, should always have the same stack and task bounds |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 741 | if (isActivityTypeHome()) { |
Winson Chung | f7fb5e3 | 2017-05-23 17:47:05 -0700 | [diff] [blame] | 742 | final Task homeTask = findHomeTask(); |
| 743 | if (homeTask != null && homeTask.isResizeable()) { |
Wale Ogunwale | 649c160 | 2017-04-24 10:15:31 -0700 | [diff] [blame] | 744 | // Calculate the home stack bounds when in docked mode and the home stack is |
| 745 | // resizeable. |
| 746 | getDisplayContent().mDividerControllerLocked |
| 747 | .getHomeStackBoundsInDockedMode(outStackBounds); |
| 748 | } else { |
| 749 | // Home stack isn't resizeable, so don't specify stack bounds. |
| 750 | outStackBounds.setEmpty(); |
| 751 | } |
| 752 | |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 753 | outTempTaskBounds.set(outStackBounds); |
| 754 | return; |
| 755 | } |
| 756 | |
| 757 | // When minimized state, the stack bounds for all non-home and docked stack bounds should |
| 758 | // match the passed task bounds |
| 759 | if (isMinimizedDockAndHomeStackResizable() && currentTempTaskBounds != null) { |
| 760 | outStackBounds.set(currentTempTaskBounds); |
| 761 | return; |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 762 | } |
| 763 | |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 764 | if (!inSplitScreenWindowingMode() || mDisplayContent == null) { |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 765 | outStackBounds.set(mBounds); |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 766 | return; |
| 767 | } |
| 768 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 769 | final TaskStack dockedStack = mDisplayContent.getDockedStackIgnoringVisibility(); |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 770 | if (dockedStack == null) { |
| 771 | // Not sure why you are calling this method when there is no docked stack... |
| 772 | throw new IllegalStateException( |
| 773 | "Calling getStackDockedModeBoundsLocked() when there is no docked stack."); |
| 774 | } |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 775 | if (!ignoreVisibility && !dockedStack.isVisible()) { |
Filip Gruszczynski | 54977fe | 2015-10-19 17:26:45 -0700 | [diff] [blame] | 776 | // The docked stack is being dismissed, but we caught before it finished being |
| 777 | // dismissed. In that case we want to treat it as if it is not occupying any space and |
| 778 | // let others occupy the whole display. |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 779 | mDisplayContent.getLogicalDisplayRect(outStackBounds); |
Filip Gruszczynski | 54977fe | 2015-10-19 17:26:45 -0700 | [diff] [blame] | 780 | return; |
| 781 | } |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 782 | |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 783 | final int dockedSide = dockedStack.getDockSide(); |
| 784 | if (dockedSide == DOCKED_INVALID) { |
| 785 | // Not sure how you got here...Only thing we can do is return current bounds. |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 786 | Slog.e(TAG_WM, "Failed to get valid docked side for docked stack=" + dockedStack); |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 787 | outStackBounds.set(mBounds); |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 788 | return; |
| 789 | } |
| 790 | |
| 791 | mDisplayContent.getLogicalDisplayRect(mTmpRect); |
| 792 | dockedStack.getRawBounds(mTmpRect2); |
Wale Ogunwale | a9f9b37 | 2016-02-04 18:04:39 -0800 | [diff] [blame] | 793 | final boolean dockedOnTopOrLeft = dockedSide == DOCKED_TOP || dockedSide == DOCKED_LEFT; |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 794 | getStackDockedModeBounds(mTmpRect, outStackBounds, mStackId, mTmpRect2, |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 795 | mDisplayContent.mDividerControllerLocked.getContentWidth(), dockedOnTopOrLeft); |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 796 | |
| 797 | } |
| 798 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 799 | /** |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 800 | * Outputs the bounds a stack should be given the presence of a docked stack on the display. |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 801 | * @param displayRect The bounds of the display the docked stack is on. |
| 802 | * @param outBounds Output bounds that should be used for the stack. |
| 803 | * @param stackId Id of stack we are calculating the bounds for. |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 804 | * @param dockedBounds Bounds of the docked stack. |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 805 | * @param dockDividerWidth We need to know the width of the divider make to the output bounds |
| 806 | * close to the side of the dock. |
| 807 | * @param dockOnTopOrLeft If the docked stack is on the top or left side of the screen. |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 808 | */ |
Jorim Jaggi | 9ea2f7b | 2015-11-23 18:08:28 -0800 | [diff] [blame] | 809 | private void getStackDockedModeBounds( |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 810 | Rect displayRect, Rect outBounds, int stackId, Rect dockedBounds, int dockDividerWidth, |
| 811 | boolean dockOnTopOrLeft) { |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 812 | final boolean dockedStack = stackId == DOCKED_STACK_ID; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 813 | final boolean splitHorizontally = displayRect.width() > displayRect.height(); |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 814 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 815 | outBounds.set(displayRect); |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 816 | if (dockedStack) { |
Jorim Jaggi | 9ea2f7b | 2015-11-23 18:08:28 -0800 | [diff] [blame] | 817 | if (mService.mDockedStackCreateBounds != null) { |
| 818 | outBounds.set(mService.mDockedStackCreateBounds); |
| 819 | return; |
| 820 | } |
Jorim Jaggi | d434dcb | 2016-01-06 17:18:44 +0100 | [diff] [blame] | 821 | |
| 822 | // The initial bounds of the docked stack when it is created about half the screen space |
| 823 | // and its bounds can be adjusted after that. The bounds of all other stacks are |
| 824 | // adjusted to occupy whatever screen space the docked stack isn't occupying. |
| 825 | final DisplayInfo di = mDisplayContent.getDisplayInfo(); |
| 826 | mService.mPolicy.getStableInsetsLw(di.rotation, di.logicalWidth, di.logicalHeight, |
| 827 | mTmpRect2); |
| 828 | final int position = new DividerSnapAlgorithm(mService.mContext.getResources(), |
Jorim Jaggi | d434dcb | 2016-01-06 17:18:44 +0100 | [diff] [blame] | 829 | di.logicalWidth, |
| 830 | di.logicalHeight, |
| 831 | dockDividerWidth, |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 832 | mDisplayContent.getConfiguration().orientation == ORIENTATION_PORTRAIT, |
Jorim Jaggi | d434dcb | 2016-01-06 17:18:44 +0100 | [diff] [blame] | 833 | mTmpRect2).getMiddleTarget().position; |
| 834 | |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 835 | if (dockOnTopOrLeft) { |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 836 | if (splitHorizontally) { |
Jorim Jaggi | d434dcb | 2016-01-06 17:18:44 +0100 | [diff] [blame] | 837 | outBounds.right = position; |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 838 | } else { |
Jorim Jaggi | d434dcb | 2016-01-06 17:18:44 +0100 | [diff] [blame] | 839 | outBounds.bottom = position; |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 840 | } |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 841 | } else { |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 842 | if (splitHorizontally) { |
Andrii Kulian | ef3b272 | 2016-04-08 12:45:27 -0700 | [diff] [blame] | 843 | outBounds.left = position + dockDividerWidth; |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 844 | } else { |
Andrii Kulian | ef3b272 | 2016-04-08 12:45:27 -0700 | [diff] [blame] | 845 | outBounds.top = position + dockDividerWidth; |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 846 | } |
| 847 | } |
| 848 | return; |
| 849 | } |
| 850 | |
| 851 | // Other stacks occupy whatever space is left by the docked stack. |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 852 | if (!dockOnTopOrLeft) { |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 853 | if (splitHorizontally) { |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 854 | outBounds.right = dockedBounds.left - dockDividerWidth; |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 855 | } else { |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 856 | outBounds.bottom = dockedBounds.top - dockDividerWidth; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 857 | } |
| 858 | } else { |
| 859 | if (splitHorizontally) { |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 860 | outBounds.left = dockedBounds.right + dockDividerWidth; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 861 | } else { |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 862 | outBounds.top = dockedBounds.bottom + dockDividerWidth; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 863 | } |
| 864 | } |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 865 | DockedDividerUtils.sanitizeStackBounds(outBounds, !dockOnTopOrLeft); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 866 | } |
| 867 | |
Wale Ogunwale | a9f9b37 | 2016-02-04 18:04:39 -0800 | [diff] [blame] | 868 | void resetDockedStackToMiddle() { |
| 869 | if (mStackId != DOCKED_STACK_ID) { |
| 870 | throw new IllegalStateException("Not a docked stack=" + this); |
| 871 | } |
| 872 | |
| 873 | mService.mDockedStackCreateBounds = null; |
| 874 | |
| 875 | final Rect bounds = new Rect(); |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 876 | final Rect tempBounds = new Rect(); |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 877 | getStackDockedModeBoundsLocked(null /* currentTempTaskBounds */, bounds, tempBounds, |
| 878 | true /*ignoreVisibility*/); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 879 | getController().requestResize(bounds); |
| 880 | } |
| 881 | |
| 882 | @Override |
| 883 | StackWindowController getController() { |
| 884 | return (StackWindowController) super.getController(); |
Wale Ogunwale | a9f9b37 | 2016-02-04 18:04:39 -0800 | [diff] [blame] | 885 | } |
| 886 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 887 | @Override |
| 888 | void removeIfPossible() { |
| 889 | if (isAnimating()) { |
| 890 | mDeferRemoval = true; |
| 891 | return; |
| 892 | } |
| 893 | removeImmediately(); |
| 894 | } |
| 895 | |
| 896 | @Override |
| 897 | void removeImmediately() { |
| 898 | super.removeImmediately(); |
| 899 | |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 900 | onRemovedFromDisplay(); |
| 901 | } |
| 902 | |
| 903 | /** |
| 904 | * Removes the stack it from its current parent, so it can be either destroyed completely or |
| 905 | * re-parented. |
| 906 | */ |
| 907 | void onRemovedFromDisplay() { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 908 | mDisplayContent.mDimLayerController.removeDimLayerUser(this); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 909 | EventLog.writeEvent(EventLogTags.WM_STACK_REMOVED, mStackId); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 910 | |
| 911 | if (mAnimationBackgroundSurface != null) { |
| 912 | mAnimationBackgroundSurface.destroySurface(); |
| 913 | mAnimationBackgroundSurface = null; |
| 914 | } |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 915 | |
| 916 | if (mStackId == DOCKED_STACK_ID) { |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 917 | mDisplayContent.mDividerControllerLocked.notifyDockedStackExistsChanged(false); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 918 | } |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 919 | |
| 920 | mDisplayContent = null; |
| 921 | mService.mWindowPlacerLocked.requestTraversal(); |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 922 | } |
| 923 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 924 | void resetAnimationBackgroundAnimator() { |
| 925 | mAnimationBackgroundAnimator = null; |
Erik Wolsheimer | 0e7f7b3 | 2017-09-29 12:12:47 -0700 | [diff] [blame^] | 926 | if (mAnimationBackgroundSurface != null) { |
| 927 | mAnimationBackgroundSurface.hide(); |
| 928 | } |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 929 | } |
| 930 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 931 | void setAnimationBackground(WindowStateAnimator winAnimator, int color) { |
| 932 | int animLayer = winAnimator.mAnimLayer; |
| 933 | if (mAnimationBackgroundAnimator == null |
| 934 | || animLayer < mAnimationBackgroundAnimator.mAnimLayer) { |
| 935 | mAnimationBackgroundAnimator = winAnimator; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 936 | animLayer = mDisplayContent.getLayerForAnimationBackground(winAnimator); |
| 937 | mAnimationBackgroundSurface.show(animLayer - LAYER_OFFSET_DIM, |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 938 | ((color >> 24) & 0xff) / 255f, 0); |
| 939 | } |
| 940 | } |
| 941 | |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 942 | // TODO: Should each user have there own stacks? |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 943 | @Override |
Wale Ogunwale | 498e8c9 | 2015-02-13 09:42:46 -0800 | [diff] [blame] | 944 | void switchUser() { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 945 | super.switchUser(); |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 946 | int top = mChildren.size(); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 947 | for (int taskNdx = 0; taskNdx < top; ++taskNdx) { |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 948 | Task task = mChildren.get(taskNdx); |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 949 | if (mService.isCurrentProfileLocked(task.mUserId) || task.showForAllUsers()) { |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 950 | mChildren.remove(taskNdx); |
| 951 | mChildren.add(task); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 952 | --top; |
| 953 | } |
| 954 | } |
| 955 | } |
| 956 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 957 | /** |
| 958 | * Adjusts the stack bounds if the IME is visible. |
| 959 | * |
| 960 | * @param imeWin The IME window. |
| 961 | */ |
Keisuke Kuroyanagi | 19d9a8f | 2016-05-12 16:49:02 -0700 | [diff] [blame] | 962 | void setAdjustedForIme(WindowState imeWin, boolean forceUpdate) { |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 963 | mImeWin = imeWin; |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 964 | mImeGoingAway = false; |
Keisuke Kuroyanagi | 19d9a8f | 2016-05-12 16:49:02 -0700 | [diff] [blame] | 965 | if (!mAdjustedForIme || forceUpdate) { |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 966 | mAdjustedForIme = true; |
| 967 | mAdjustImeAmount = 0f; |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 968 | mAdjustDividerAmount = 0f; |
| 969 | updateAdjustForIme(0f, 0f, true /* force */); |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 970 | } |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | boolean isAdjustedForIme() { |
Chong Zhang | 5117e27 | 2016-05-03 12:47:34 -0700 | [diff] [blame] | 974 | return mAdjustedForIme; |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 975 | } |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 976 | |
| 977 | boolean isAnimatingForIme() { |
| 978 | return mImeWin != null && mImeWin.isAnimatingLw(); |
| 979 | } |
| 980 | |
| 981 | /** |
| 982 | * Update the stack's bounds (crop or position) according to the IME window's |
| 983 | * current position. When IME window is animated, the bottom stack is animated |
| 984 | * together to track the IME window's current position, and the top stack is |
| 985 | * cropped as necessary. |
| 986 | * |
| 987 | * @return true if a traversal should be performed after the adjustment. |
| 988 | */ |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 989 | boolean updateAdjustForIme(float adjustAmount, float adjustDividerAmount, boolean force) { |
| 990 | if (adjustAmount != mAdjustImeAmount |
| 991 | || adjustDividerAmount != mAdjustDividerAmount || force) { |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 992 | mAdjustImeAmount = adjustAmount; |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 993 | mAdjustDividerAmount = adjustDividerAmount; |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 994 | updateAdjustedBounds(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 995 | return isVisible(); |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 996 | } else { |
| 997 | return false; |
Chong Zhang | b58bbcc | 2016-03-23 11:57:36 -0700 | [diff] [blame] | 998 | } |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | /** |
| 1002 | * Resets the adjustment after it got adjusted for the IME. |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 1003 | * @param adjustBoundsNow if true, reset and update the bounds immediately and forget about |
| 1004 | * animations; otherwise, set flag and animates the window away together |
| 1005 | * with IME window. |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1006 | */ |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 1007 | void resetAdjustedForIme(boolean adjustBoundsNow) { |
| 1008 | if (adjustBoundsNow) { |
| 1009 | mImeWin = null; |
| 1010 | mAdjustedForIme = false; |
| 1011 | mImeGoingAway = false; |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 1012 | mAdjustImeAmount = 0f; |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 1013 | mAdjustDividerAmount = 0f; |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 1014 | updateAdjustedBounds(); |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 1015 | mService.setResizeDimLayer(false, getWindowingMode(), 1.0f); |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 1016 | } else { |
| 1017 | mImeGoingAway |= mAdjustedForIme; |
Chong Zhang | b58bbcc | 2016-03-23 11:57:36 -0700 | [diff] [blame] | 1018 | } |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | /** |
| 1022 | * Sets the amount how much we currently minimize our stack. |
| 1023 | * |
| 1024 | * @param minimizeAmount The amount, between 0 and 1. |
| 1025 | * @return Whether the amount has changed and a layout is needed. |
| 1026 | */ |
| 1027 | boolean setAdjustedForMinimizedDock(float minimizeAmount) { |
| 1028 | if (minimizeAmount != mMinimizeAmount) { |
| 1029 | mMinimizeAmount = minimizeAmount; |
| 1030 | updateAdjustedBounds(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1031 | return isVisible(); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1032 | } else { |
| 1033 | return false; |
| 1034 | } |
| 1035 | } |
| 1036 | |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 1037 | boolean shouldIgnoreInput() { |
| 1038 | return isAdjustedForMinimizedDockedStack() || mStackId == DOCKED_STACK_ID && |
| 1039 | isMinimizedDockAndHomeStackResizable(); |
Jorim Jaggi | 409635b | 2016-04-01 15:32:28 -0700 | [diff] [blame] | 1040 | } |
| 1041 | |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 1042 | /** |
| 1043 | * Puts all visible tasks that are adjusted for IME into resizing mode and adds the windows |
| 1044 | * to the list of to be drawn windows the service is waiting for. |
| 1045 | */ |
| 1046 | void beginImeAdjustAnimation() { |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1047 | for (int j = mChildren.size() - 1; j >= 0; j--) { |
| 1048 | final Task task = mChildren.get(j); |
Wale Ogunwale | 44f2180 | 2016-09-02 12:49:48 -0700 | [diff] [blame] | 1049 | if (task.hasContentToDisplay()) { |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 1050 | task.setDragResizing(true, DRAG_RESIZE_MODE_DOCKED_DIVIDER); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1051 | task.setWaitingForDrawnIfResizingChanged(); |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 1052 | } |
| 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | /** |
| 1057 | * Resets the resizing state of all windows. |
| 1058 | */ |
| 1059 | void endImeAdjustAnimation() { |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1060 | for (int j = mChildren.size() - 1; j >= 0; j--) { |
| 1061 | mChildren.get(j).setDragResizing(false, DRAG_RESIZE_MODE_DOCKED_DIVIDER); |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 1062 | } |
| 1063 | } |
| 1064 | |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 1065 | int getMinTopStackBottom(final Rect displayContentRect, int originalStackBottom) { |
| 1066 | return displayContentRect.top + (int) |
| 1067 | ((originalStackBottom - displayContentRect.top) * ADJUSTED_STACK_FRACTION_MIN); |
| 1068 | } |
| 1069 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1070 | private boolean adjustForIME(final WindowState imeWin) { |
| 1071 | final int dockedSide = getDockSide(); |
| 1072 | final boolean dockedTopOrBottom = dockedSide == DOCKED_TOP || dockedSide == DOCKED_BOTTOM; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1073 | if (imeWin == null || !dockedTopOrBottom) { |
| 1074 | return false; |
| 1075 | } |
| 1076 | |
| 1077 | final Rect displayContentRect = mTmpRect; |
| 1078 | final Rect contentBounds = mTmpRect2; |
| 1079 | |
| 1080 | // Calculate the content bounds excluding the area occupied by IME |
| 1081 | getDisplayContent().getContentRect(displayContentRect); |
| 1082 | contentBounds.set(displayContentRect); |
Jorim Jaggi | 5ac2ba2 | 2016-04-11 21:14:12 -0700 | [diff] [blame] | 1083 | int imeTop = Math.max(imeWin.getFrameLw().top, contentBounds.top); |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 1084 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1085 | imeTop += imeWin.getGivenContentInsetsLw().top; |
| 1086 | if (contentBounds.bottom > imeTop) { |
| 1087 | contentBounds.bottom = imeTop; |
| 1088 | } |
| 1089 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1090 | final int yOffset = displayContentRect.bottom - contentBounds.bottom; |
| 1091 | |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 1092 | final int dividerWidth = |
| 1093 | getDisplayContent().mDividerControllerLocked.getContentWidth(); |
| 1094 | final int dividerWidthInactive = |
| 1095 | getDisplayContent().mDividerControllerLocked.getContentWidthInactive(); |
| 1096 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1097 | if (dockedSide == DOCKED_TOP) { |
| 1098 | // If this stack is docked on top, we make it smaller so the bottom stack is not |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 1099 | // occluded by IME. We shift its bottom up by the height of the IME, but |
| 1100 | // leaves at least 30% of the top stack visible. |
| 1101 | final int minTopStackBottom = |
| 1102 | getMinTopStackBottom(displayContentRect, mBounds.bottom); |
| 1103 | final int bottom = Math.max( |
| 1104 | mBounds.bottom - yOffset + dividerWidth - dividerWidthInactive, |
| 1105 | minTopStackBottom); |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 1106 | mTmpAdjustedBounds.set(mBounds); |
| 1107 | mTmpAdjustedBounds.bottom = |
| 1108 | (int) (mAdjustImeAmount * bottom + (1 - mAdjustImeAmount) * mBounds.bottom); |
| 1109 | mFullyAdjustedImeBounds.set(mBounds); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1110 | } else { |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 1111 | // When the stack is on bottom and has no focus, it's only adjusted for divider width. |
| 1112 | final int dividerWidthDelta = dividerWidthInactive - dividerWidth; |
| 1113 | |
| 1114 | // When the stack is on bottom and has focus, it needs to be moved up so as to |
| 1115 | // not occluded by IME, and at the same time adjusted for divider width. |
| 1116 | // We try to move it up by the height of the IME window, but only to the extent |
| 1117 | // that leaves at least 30% of the top stack visible. |
| 1118 | // 'top' is where the top of bottom stack will move to in this case. |
| 1119 | final int topBeforeImeAdjust = mBounds.top - dividerWidth + dividerWidthInactive; |
| 1120 | final int minTopStackBottom = |
| 1121 | getMinTopStackBottom(displayContentRect, mBounds.top - dividerWidth); |
| 1122 | final int top = Math.max( |
| 1123 | mBounds.top - yOffset, minTopStackBottom + dividerWidthInactive); |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 1124 | |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 1125 | mTmpAdjustedBounds.set(mBounds); |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 1126 | // Account for the adjustment for IME and divider width separately. |
| 1127 | // (top - topBeforeImeAdjust) is the amount of movement due to IME only, |
| 1128 | // and dividerWidthDelta is due to divider width change only. |
| 1129 | mTmpAdjustedBounds.top = mBounds.top + |
| 1130 | (int) (mAdjustImeAmount * (top - topBeforeImeAdjust) + |
| 1131 | mAdjustDividerAmount * dividerWidthDelta); |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 1132 | mFullyAdjustedImeBounds.set(mBounds); |
| 1133 | mFullyAdjustedImeBounds.top = top; |
| 1134 | mFullyAdjustedImeBounds.bottom = top + mBounds.height(); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1135 | } |
| 1136 | return true; |
| 1137 | } |
| 1138 | |
| 1139 | private boolean adjustForMinimizedDockedStack(float minimizeAmount) { |
| 1140 | final int dockSide = getDockSide(); |
| 1141 | if (dockSide == DOCKED_INVALID && !mTmpAdjustedBounds.isEmpty()) { |
| 1142 | return false; |
| 1143 | } |
| 1144 | |
| 1145 | if (dockSide == DOCKED_TOP) { |
Winson Chung | 303c6b7 | 2016-10-24 17:12:49 -0700 | [diff] [blame] | 1146 | mService.getStableInsetsLocked(DEFAULT_DISPLAY, mTmpRect); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1147 | int topInset = mTmpRect.top; |
| 1148 | mTmpAdjustedBounds.set(mBounds); |
| 1149 | mTmpAdjustedBounds.bottom = |
| 1150 | (int) (minimizeAmount * topInset + (1 - minimizeAmount) * mBounds.bottom); |
| 1151 | } else if (dockSide == DOCKED_LEFT) { |
| 1152 | mTmpAdjustedBounds.set(mBounds); |
Jorim Jaggi | bcff143 | 2016-04-01 15:49:45 -0700 | [diff] [blame] | 1153 | final int width = mBounds.width(); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1154 | mTmpAdjustedBounds.right = |
| 1155 | (int) (minimizeAmount * mDockedStackMinimizeThickness |
| 1156 | + (1 - minimizeAmount) * mBounds.right); |
Jorim Jaggi | bcff143 | 2016-04-01 15:49:45 -0700 | [diff] [blame] | 1157 | mTmpAdjustedBounds.left = mTmpAdjustedBounds.right - width; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1158 | } else if (dockSide == DOCKED_RIGHT) { |
| 1159 | mTmpAdjustedBounds.set(mBounds); |
| 1160 | mTmpAdjustedBounds.left = |
| 1161 | (int) (minimizeAmount * (mBounds.right - mDockedStackMinimizeThickness) |
| 1162 | + (1 - minimizeAmount) * mBounds.left); |
| 1163 | } |
| 1164 | return true; |
| 1165 | } |
| 1166 | |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 1167 | private boolean isMinimizedDockAndHomeStackResizable() { |
| 1168 | return mDisplayContent.mDividerControllerLocked.isMinimizedDock() |
| 1169 | && mDisplayContent.mDividerControllerLocked.isHomeStackResizable(); |
| 1170 | } |
| 1171 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1172 | /** |
Jorim Jaggi | f97ed92 | 2016-02-18 18:57:07 -0800 | [diff] [blame] | 1173 | * @return the distance in pixels how much the stack gets minimized from it's original size |
| 1174 | */ |
| 1175 | int getMinimizeDistance() { |
| 1176 | final int dockSide = getDockSide(); |
| 1177 | if (dockSide == DOCKED_INVALID) { |
| 1178 | return 0; |
| 1179 | } |
| 1180 | |
| 1181 | if (dockSide == DOCKED_TOP) { |
Winson Chung | 303c6b7 | 2016-10-24 17:12:49 -0700 | [diff] [blame] | 1182 | mService.getStableInsetsLocked(DEFAULT_DISPLAY, mTmpRect); |
Jorim Jaggi | f97ed92 | 2016-02-18 18:57:07 -0800 | [diff] [blame] | 1183 | int topInset = mTmpRect.top; |
| 1184 | return mBounds.bottom - topInset; |
| 1185 | } else if (dockSide == DOCKED_LEFT || dockSide == DOCKED_RIGHT) { |
| 1186 | return mBounds.width() - mDockedStackMinimizeThickness; |
| 1187 | } else { |
| 1188 | return 0; |
| 1189 | } |
| 1190 | } |
| 1191 | |
| 1192 | /** |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1193 | * Updates the adjustment depending on it's current state. |
| 1194 | */ |
Chong Zhang | 5117e27 | 2016-05-03 12:47:34 -0700 | [diff] [blame] | 1195 | private void updateAdjustedBounds() { |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1196 | boolean adjust = false; |
| 1197 | if (mMinimizeAmount != 0f) { |
| 1198 | adjust = adjustForMinimizedDockedStack(mMinimizeAmount); |
| 1199 | } else if (mAdjustedForIme) { |
| 1200 | adjust = adjustForIME(mImeWin); |
| 1201 | } |
| 1202 | if (!adjust) { |
| 1203 | mTmpAdjustedBounds.setEmpty(); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1204 | } |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 1205 | setAdjustedBounds(mTmpAdjustedBounds); |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 1206 | |
Chong Zhang | b8da4a7 | 2016-05-17 15:07:26 -0700 | [diff] [blame] | 1207 | final boolean isImeTarget = (mService.getImeFocusStackLocked() == this); |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 1208 | if (mAdjustedForIme && adjust && !isImeTarget) { |
| 1209 | final float alpha = Math.max(mAdjustImeAmount, mAdjustDividerAmount) |
| 1210 | * IME_ADJUST_DIM_AMOUNT; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 1211 | mService.setResizeDimLayer(true, getWindowingMode(), alpha); |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 1212 | } |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1213 | } |
| 1214 | |
Chong Zhang | 5117e27 | 2016-05-03 12:47:34 -0700 | [diff] [blame] | 1215 | void applyAdjustForImeIfNeeded(Task task) { |
| 1216 | if (mMinimizeAmount != 0f || !mAdjustedForIme || mAdjustedBounds.isEmpty()) { |
| 1217 | return; |
| 1218 | } |
| 1219 | |
| 1220 | final Rect insetBounds = mImeGoingAway ? mBounds : mFullyAdjustedImeBounds; |
| 1221 | task.alignToAdjustedBounds(mAdjustedBounds, insetBounds, getDockSide() == DOCKED_TOP); |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 1222 | mDisplayContent.setLayoutNeeded(); |
Chong Zhang | 5117e27 | 2016-05-03 12:47:34 -0700 | [diff] [blame] | 1223 | } |
| 1224 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1225 | boolean isAdjustedForMinimizedDockedStack() { |
| 1226 | return mMinimizeAmount != 0f; |
| 1227 | } |
| 1228 | |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 1229 | @CallSuper |
| 1230 | @Override |
| 1231 | public void writeToProto(ProtoOutputStream proto, long fieldId) { |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 1232 | final long token = proto.start(fieldId); |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 1233 | super.writeToProto(proto, WINDOW_CONTAINER); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 1234 | proto.write(ID, mStackId); |
| 1235 | for (int taskNdx = mChildren.size() - 1; taskNdx >= 0; taskNdx--) { |
| 1236 | mChildren.get(taskNdx).writeToProto(proto, TASKS); |
| 1237 | } |
| 1238 | proto.write(FILLS_PARENT, mFillsParent); |
| 1239 | mBounds.writeToProto(proto, BOUNDS); |
| 1240 | proto.write(ANIMATION_BACKGROUND_SURFACE_IS_DIMMING, mAnimationBackgroundSurface.isDimming()); |
| 1241 | proto.end(token); |
| 1242 | } |
| 1243 | |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 1244 | public void dump(String prefix, PrintWriter pw) { |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 1245 | pw.println(prefix + "mStackId=" + mStackId); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1246 | pw.println(prefix + "mDeferRemoval=" + mDeferRemoval); |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1247 | pw.println(prefix + "mFillsParent=" + mFillsParent); |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 1248 | pw.println(prefix + "mBounds=" + mBounds.toShortString()); |
Jorim Jaggi | af558e1 | 2016-04-27 22:56:56 -0700 | [diff] [blame] | 1249 | if (mMinimizeAmount != 0f) { |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1250 | pw.println(prefix + "mMinimizeAmount=" + mMinimizeAmount); |
Jorim Jaggi | af558e1 | 2016-04-27 22:56:56 -0700 | [diff] [blame] | 1251 | } |
| 1252 | if (mAdjustedForIme) { |
| 1253 | pw.println(prefix + "mAdjustedForIme=true"); |
| 1254 | pw.println(prefix + "mAdjustImeAmount=" + mAdjustImeAmount); |
| 1255 | pw.println(prefix + "mAdjustDividerAmount=" + mAdjustDividerAmount); |
| 1256 | } |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 1257 | if (!mAdjustedBounds.isEmpty()) { |
| 1258 | pw.println(prefix + "mAdjustedBounds=" + mAdjustedBounds.toShortString()); |
| 1259 | } |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1260 | for (int taskNdx = mChildren.size() - 1; taskNdx >= 0; taskNdx--) { |
| 1261 | mChildren.get(taskNdx).dump(prefix + " ", pw); |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 1262 | } |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 1263 | if (mAnimationBackgroundSurface.isDimming()) { |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 1264 | pw.println(prefix + "mWindowAnimationBackgroundSurface:"); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 1265 | mAnimationBackgroundSurface.printTo(prefix + " ", pw); |
| 1266 | } |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 1267 | if (!mExitingAppTokens.isEmpty()) { |
| 1268 | pw.println(); |
| 1269 | pw.println(" Exiting application tokens:"); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1270 | for (int i = mExitingAppTokens.size() - 1; i >= 0; i--) { |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 1271 | WindowToken token = mExitingAppTokens.get(i); |
| 1272 | pw.print(" Exiting App #"); pw.print(i); |
| 1273 | pw.print(' '); pw.print(token); |
| 1274 | pw.println(':'); |
| 1275 | token.dump(pw, " "); |
| 1276 | } |
| 1277 | } |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 1278 | } |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 1279 | |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 1280 | /** Fullscreen status of the stack without adjusting for other factors in the system like |
| 1281 | * visibility of docked stack. |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1282 | * Most callers should be using {@link #fillsParent} as it take into consideration other |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 1283 | * system factors. */ |
| 1284 | boolean getRawFullscreen() { |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1285 | return mFillsParent; |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 1286 | } |
| 1287 | |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 1288 | @Override |
Wale Ogunwale | 29bfbb8 | 2016-05-12 15:13:52 -0700 | [diff] [blame] | 1289 | public boolean dimFullscreen() { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 1290 | return !isActivityTypeStandard() || fillsParent(); |
Wale Ogunwale | 29bfbb8 | 2016-05-12 15:13:52 -0700 | [diff] [blame] | 1291 | } |
| 1292 | |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1293 | @Override |
| 1294 | boolean fillsParent() { |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 1295 | if (useCurrentBounds()) { |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1296 | return mFillsParent; |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 1297 | } |
| 1298 | // The bounds has been adjusted to accommodate for a docked stack, but the docked stack |
| 1299 | // is not currently visible. Go ahead a represent it as fullscreen to the rest of the |
| 1300 | // system. |
| 1301 | return true; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1302 | } |
| 1303 | |
| 1304 | @Override |
| 1305 | public DisplayInfo getDisplayInfo() { |
| 1306 | return mDisplayContent.getDisplayInfo(); |
| 1307 | } |
| 1308 | |
| 1309 | @Override |
Wale Ogunwale | f0a60a9 | 2017-01-19 09:44:40 -0800 | [diff] [blame] | 1310 | public boolean isAttachedToDisplay() { |
| 1311 | return mDisplayContent != null; |
| 1312 | } |
| 1313 | |
| 1314 | @Override |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 1315 | public String toString() { |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1316 | return "{stackId=" + mStackId + " tasks=" + mChildren + "}"; |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 1317 | } |
Filip Gruszczynski | 923f826 | 2015-09-17 17:41:13 -0700 | [diff] [blame] | 1318 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1319 | String getName() { |
| 1320 | return toShortString(); |
| 1321 | } |
| 1322 | |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 1323 | @Override |
| 1324 | public String toShortString() { |
| 1325 | return "Stack=" + mStackId; |
| 1326 | } |
| 1327 | |
Filip Gruszczynski | 923f826 | 2015-09-17 17:41:13 -0700 | [diff] [blame] | 1328 | /** |
Chong Zhang | c806d90 | 2015-11-30 09:44:27 -0800 | [diff] [blame] | 1329 | * For docked workspace (or workspace that's side-by-side to the docked), provides |
| 1330 | * information which side of the screen was the dock anchored. |
Filip Gruszczynski | 923f826 | 2015-09-17 17:41:13 -0700 | [diff] [blame] | 1331 | */ |
Filip Gruszczynski | 923f826 | 2015-09-17 17:41:13 -0700 | [diff] [blame] | 1332 | int getDockSide() { |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 1333 | return getDockSide(mBounds); |
| 1334 | } |
| 1335 | |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 1336 | private int getDockSide(Rect bounds) { |
| 1337 | if (!inSplitScreenWindowingMode()) { |
Filip Gruszczynski | 923f826 | 2015-09-17 17:41:13 -0700 | [diff] [blame] | 1338 | return DOCKED_INVALID; |
| 1339 | } |
| 1340 | if (mDisplayContent == null) { |
| 1341 | return DOCKED_INVALID; |
| 1342 | } |
| 1343 | mDisplayContent.getLogicalDisplayRect(mTmpRect); |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 1344 | final int orientation = mDisplayContent.getConfiguration().orientation; |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 1345 | return getDockSideUnchecked(bounds, mTmpRect, orientation); |
| 1346 | } |
| 1347 | |
| 1348 | static int getDockSideUnchecked(Rect bounds, Rect displayRect, int orientation) { |
Filip Gruszczynski | 923f826 | 2015-09-17 17:41:13 -0700 | [diff] [blame] | 1349 | if (orientation == Configuration.ORIENTATION_PORTRAIT) { |
| 1350 | // Portrait mode, docked either at the top or the bottom. |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 1351 | if (bounds.top - displayRect.top <= displayRect.bottom - bounds.bottom) { |
Filip Gruszczynski | 923f826 | 2015-09-17 17:41:13 -0700 | [diff] [blame] | 1352 | return DOCKED_TOP; |
| 1353 | } else { |
| 1354 | return DOCKED_BOTTOM; |
| 1355 | } |
| 1356 | } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { |
| 1357 | // Landscape mode, docked either on the left or on the right. |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 1358 | if (bounds.left - displayRect.left <= displayRect.right - bounds.right) { |
Filip Gruszczynski | 923f826 | 2015-09-17 17:41:13 -0700 | [diff] [blame] | 1359 | return DOCKED_LEFT; |
| 1360 | } else { |
| 1361 | return DOCKED_RIGHT; |
| 1362 | } |
| 1363 | } else { |
| 1364 | return DOCKED_INVALID; |
| 1365 | } |
| 1366 | } |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 1367 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1368 | boolean hasTaskForUser(int userId) { |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1369 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 1370 | final Task task = mChildren.get(i); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1371 | if (task.mUserId == userId) { |
| 1372 | return true; |
| 1373 | } |
| 1374 | } |
| 1375 | return false; |
| 1376 | } |
| 1377 | |
| 1378 | int taskIdFromPoint(int x, int y) { |
| 1379 | getBounds(mTmpRect); |
| 1380 | if (!mTmpRect.contains(x, y) || isAdjustedForMinimizedDockedStack()) { |
| 1381 | return -1; |
| 1382 | } |
| 1383 | |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1384 | for (int taskNdx = mChildren.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1385 | final Task task = mChildren.get(taskNdx); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1386 | final WindowState win = task.getTopVisibleAppMainWindow(); |
| 1387 | if (win == null) { |
| 1388 | continue; |
| 1389 | } |
| 1390 | // We need to use the task's dim bounds (which is derived from the visible bounds of its |
| 1391 | // apps windows) for any touch-related tests. Can't use the task's original bounds |
| 1392 | // because it might be adjusted to fit the content frame. For example, the presence of |
| 1393 | // the IME adjusting the windows frames when the app window is the IME target. |
| 1394 | task.getDimBounds(mTmpRect); |
| 1395 | if (mTmpRect.contains(x, y)) { |
| 1396 | return task.mTaskId; |
| 1397 | } |
| 1398 | } |
| 1399 | |
| 1400 | return -1; |
| 1401 | } |
| 1402 | |
| 1403 | void findTaskForResizePoint(int x, int y, int delta, |
| 1404 | DisplayContent.TaskForResizePointSearchResult results) { |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 1405 | if (!getWindowConfiguration().canResizeTask()) { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1406 | results.searchDone = true; |
| 1407 | return; |
| 1408 | } |
| 1409 | |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1410 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 1411 | final Task task = mChildren.get(i); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1412 | if (task.isFullscreen()) { |
| 1413 | results.searchDone = true; |
| 1414 | return; |
| 1415 | } |
| 1416 | |
| 1417 | // We need to use the task's dim bounds (which is derived from the visible bounds of |
| 1418 | // its apps windows) for any touch-related tests. Can't use the task's original |
| 1419 | // bounds because it might be adjusted to fit the content frame. One example is when |
| 1420 | // the task is put to top-left quadrant, the actual visible area would not start at |
| 1421 | // (0,0) after it's adjusted for the status bar. |
| 1422 | task.getDimBounds(mTmpRect); |
| 1423 | mTmpRect.inset(-delta, -delta); |
| 1424 | if (mTmpRect.contains(x, y)) { |
| 1425 | mTmpRect.inset(delta, delta); |
| 1426 | |
| 1427 | results.searchDone = true; |
| 1428 | |
| 1429 | if (!mTmpRect.contains(x, y)) { |
| 1430 | results.taskForResize = task; |
| 1431 | return; |
| 1432 | } |
| 1433 | // User touched inside the task. No need to look further, |
| 1434 | // focus transfer will be handled in ACTION_UP. |
| 1435 | return; |
| 1436 | } |
| 1437 | } |
| 1438 | } |
| 1439 | |
| 1440 | void setTouchExcludeRegion(Task focusedTask, int delta, Region touchExcludeRegion, |
| 1441 | Rect contentRect, Rect postExclude) { |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1442 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 1443 | final Task task = mChildren.get(i); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1444 | AppWindowToken token = task.getTopVisibleAppToken(); |
| 1445 | if (token == null || !token.hasContentToDisplay()) { |
| 1446 | continue; |
| 1447 | } |
| 1448 | |
| 1449 | /** |
| 1450 | * Exclusion region is the region that TapDetector doesn't care about. |
| 1451 | * Here we want to remove all non-focused tasks from the exclusion region. |
| 1452 | * We also remove the outside touch area for resizing for all freeform |
| 1453 | * tasks (including the focused). |
| 1454 | * |
| 1455 | * We save the focused task region once we find it, and add it back at the end. |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 1456 | * |
| 1457 | * If the task is home stack and it is resizable in the minimized state, we want to |
| 1458 | * exclude the docked stack from touch so we need the entire screen area and not just a |
| 1459 | * small portion which the home stack currently is resized to. |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1460 | */ |
| 1461 | |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1462 | if (task.isActivityTypeHome() && isMinimizedDockAndHomeStackResizable()) { |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 1463 | mDisplayContent.getLogicalDisplayRect(mTmpRect); |
| 1464 | } else { |
| 1465 | task.getDimBounds(mTmpRect); |
| 1466 | } |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1467 | |
| 1468 | if (task == focusedTask) { |
| 1469 | // Add the focused task rect back into the exclude region once we are done |
| 1470 | // processing stacks. |
| 1471 | postExclude.set(mTmpRect); |
| 1472 | } |
| 1473 | |
| 1474 | final boolean isFreeformed = task.inFreeformWorkspace(); |
| 1475 | if (task != focusedTask || isFreeformed) { |
| 1476 | if (isFreeformed) { |
| 1477 | // If the task is freeformed, enlarge the area to account for outside |
| 1478 | // touch area for resize. |
| 1479 | mTmpRect.inset(-delta, -delta); |
| 1480 | // Intersect with display content rect. If we have system decor (status bar/ |
| 1481 | // navigation bar), we want to exclude that from the tap detection. |
| 1482 | // Otherwise, if the app is partially placed under some system button (eg. |
| 1483 | // Recents, Home), pressing that button would cause a full series of |
| 1484 | // unwanted transfer focus/resume/pause, before we could go home. |
| 1485 | mTmpRect.intersect(contentRect); |
| 1486 | } |
| 1487 | touchExcludeRegion.op(mTmpRect, Region.Op.DIFFERENCE); |
| 1488 | } |
| 1489 | } |
| 1490 | } |
| 1491 | |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 1492 | public boolean setPinnedStackSize(Rect stackBounds, Rect tempTaskBounds) { |
| 1493 | // Hold the lock since this is called from the BoundsAnimator running on the UiThread |
| 1494 | synchronized (mService.mWindowMap) { |
| 1495 | if (mCancelCurrentBoundsAnimation) { |
| 1496 | return false; |
| 1497 | } |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 1498 | } |
| 1499 | |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 1500 | try { |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 1501 | mService.mActivityManager.resizePinnedStack(stackBounds, tempTaskBounds); |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 1502 | } catch (RemoteException e) { |
| 1503 | // I don't believe you. |
| 1504 | } |
| 1505 | return true; |
| 1506 | } |
| 1507 | |
Robert Carr | ecc06b3 | 2017-04-18 14:25:10 -0700 | [diff] [blame] | 1508 | void onAllWindowsDrawn() { |
Winson Chung | e7ba686 | 2017-05-24 12:13:33 -0700 | [diff] [blame] | 1509 | if (!mBoundsAnimating && !mBoundsAnimatingRequested) { |
Robert Carr | ecc06b3 | 2017-04-18 14:25:10 -0700 | [diff] [blame] | 1510 | return; |
| 1511 | } |
| 1512 | |
| 1513 | mService.mBoundsAnimationController.onAllWindowsDrawn(); |
| 1514 | } |
| 1515 | |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 1516 | @Override // AnimatesBounds |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 1517 | public void onAnimationStart(boolean schedulePipModeChangedCallback, boolean forceUpdate) { |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 1518 | // Hold the lock since this is called from the BoundsAnimator running on the UiThread |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 1519 | synchronized (mService.mWindowMap) { |
Winson Chung | 40a5f93 | 2017-04-13 16:39:36 -0700 | [diff] [blame] | 1520 | mBoundsAnimatingRequested = false; |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 1521 | mBoundsAnimating = true; |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 1522 | mCancelCurrentBoundsAnimation = false; |
Robert Carr | ecc06b3 | 2017-04-18 14:25:10 -0700 | [diff] [blame] | 1523 | |
| 1524 | // If we are changing UI mode, as in the PiP to fullscreen |
| 1525 | // transition, then we need to wait for the window to draw. |
| 1526 | if (schedulePipModeChangedCallback) { |
| 1527 | forAllWindows((w) -> { w.mWinAnimator.resetDrawState(); }, |
| 1528 | false /* traverseTopToBottom */); |
| 1529 | } |
Wale Ogunwale | ce14452 | 2016-02-05 22:51:01 -0800 | [diff] [blame] | 1530 | } |
Winson Chung | 85d3998 | 2017-02-24 15:21:25 -0800 | [diff] [blame] | 1531 | |
| 1532 | if (mStackId == PINNED_STACK_ID) { |
| 1533 | try { |
| 1534 | mService.mActivityManager.notifyPinnedStackAnimationStarted(); |
| 1535 | } catch (RemoteException e) { |
| 1536 | // I don't believe you... |
| 1537 | } |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 1538 | |
| 1539 | final PinnedStackWindowController controller = |
| 1540 | (PinnedStackWindowController) getController(); |
| 1541 | if (schedulePipModeChangedCallback && controller != null) { |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 1542 | // We need to schedule the PiP mode change before the animation up. It is possible |
| 1543 | // in this case for the animation down to not have been completed, so always |
| 1544 | // force-schedule and update to the client to ensure that it is notified that it |
| 1545 | // is no longer in picture-in-picture mode |
| 1546 | controller.updatePictureInPictureModeForPinnedStackAnimation(null, forceUpdate); |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 1547 | } |
Winson Chung | 85d3998 | 2017-02-24 15:21:25 -0800 | [diff] [blame] | 1548 | } |
Wale Ogunwale | ce14452 | 2016-02-05 22:51:01 -0800 | [diff] [blame] | 1549 | } |
| 1550 | |
| 1551 | @Override // AnimatesBounds |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 1552 | public void onAnimationEnd(boolean schedulePipModeChangedCallback, Rect finalStackSize, |
| 1553 | boolean moveToFullscreen) { |
| 1554 | // Hold the lock since this is called from the BoundsAnimator running on the UiThread |
Wale Ogunwale | ce14452 | 2016-02-05 22:51:01 -0800 | [diff] [blame] | 1555 | synchronized (mService.mWindowMap) { |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 1556 | mBoundsAnimating = false; |
Robert Carr | 18f622f | 2017-05-08 11:20:43 -0700 | [diff] [blame] | 1557 | for (int i = 0; i < mChildren.size(); i++) { |
| 1558 | final Task t = mChildren.get(i); |
| 1559 | t.clearPreserveNonFloatingState(); |
| 1560 | } |
Wale Ogunwale | ce14452 | 2016-02-05 22:51:01 -0800 | [diff] [blame] | 1561 | mService.requestTraversal(); |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 1562 | } |
Winson Chung | 85d3998 | 2017-02-24 15:21:25 -0800 | [diff] [blame] | 1563 | |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 1564 | if (mStackId == PINNED_STACK_ID) { |
Robert Carr | 18f622f | 2017-05-08 11:20:43 -0700 | [diff] [blame] | 1565 | // Update to the final bounds if requested. This is done here instead of in the bounds |
| 1566 | // animator to allow us to coordinate this after we notify the PiP mode changed |
| 1567 | |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 1568 | final PinnedStackWindowController controller = |
| 1569 | (PinnedStackWindowController) getController(); |
| 1570 | if (schedulePipModeChangedCallback && controller != null) { |
| 1571 | // We need to schedule the PiP mode change after the animation down, so use the |
| 1572 | // final bounds |
| 1573 | controller.updatePictureInPictureModeForPinnedStackAnimation( |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 1574 | mBoundsAnimationTarget, false /* forceUpdate */); |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 1575 | } |
| 1576 | |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 1577 | if (finalStackSize != null) { |
| 1578 | setPinnedStackSize(finalStackSize, null); |
| 1579 | } |
| 1580 | |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 1581 | try { |
| 1582 | mService.mActivityManager.notifyPinnedStackAnimationEnded(); |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 1583 | if (moveToFullscreen) { |
| 1584 | mService.mActivityManager.moveTasksToFullscreenStack(mStackId, |
| 1585 | true /* onTop */); |
| 1586 | } |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 1587 | } catch (RemoteException e) { |
| 1588 | // I don't believe you... |
| 1589 | } |
| 1590 | } |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 1591 | } |
Filip Gruszczynski | c17d8b7 | 2016-02-03 16:52:59 -0800 | [diff] [blame] | 1592 | |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 1593 | /** |
| 1594 | * @return True if we are currently animating the pinned stack from fullscreen to non-fullscreen |
| 1595 | * bounds and we have a deferred PiP mode changed callback set with the animation. |
| 1596 | */ |
| 1597 | public boolean deferScheduleMultiWindowModeChanged() { |
| 1598 | if (mStackId == PINNED_STACK_ID) { |
| 1599 | return (mBoundsAnimatingRequested || mBoundsAnimating); |
Filip Gruszczynski | c17d8b7 | 2016-02-03 16:52:59 -0800 | [diff] [blame] | 1600 | } |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 1601 | return false; |
Filip Gruszczynski | c17d8b7 | 2016-02-03 16:52:59 -0800 | [diff] [blame] | 1602 | } |
| 1603 | |
Robert Carr | 8f0a3ad | 2017-02-15 19:30:28 -0800 | [diff] [blame] | 1604 | public boolean isForceScaled() { |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 1605 | return mBoundsAnimating; |
| 1606 | } |
| 1607 | |
Winson Chung | 40a5f93 | 2017-04-13 16:39:36 -0700 | [diff] [blame] | 1608 | public boolean isAnimatingBounds() { |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 1609 | return mBoundsAnimating; |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 1610 | } |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 1611 | |
Robert Carr | 18f622f | 2017-05-08 11:20:43 -0700 | [diff] [blame] | 1612 | public boolean lastAnimatingBoundsWasToFullscreen() { |
| 1613 | return mBoundsAnimatingToFullscreen; |
| 1614 | } |
| 1615 | |
Winson Chung | 40a5f93 | 2017-04-13 16:39:36 -0700 | [diff] [blame] | 1616 | public boolean isAnimatingBoundsToFullscreen() { |
Robert Carr | 18f622f | 2017-05-08 11:20:43 -0700 | [diff] [blame] | 1617 | return isAnimatingBounds() && lastAnimatingBoundsWasToFullscreen(); |
Robert Carr | 7e4c90e | 2017-02-15 19:52:38 -0800 | [diff] [blame] | 1618 | } |
| 1619 | |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 1620 | public boolean pinnedStackResizeDisallowed() { |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 1621 | if (mBoundsAnimating && mCancelCurrentBoundsAnimation) { |
| 1622 | return true; |
| 1623 | } |
| 1624 | return false; |
| 1625 | } |
| 1626 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1627 | /** Returns true if a removal action is still being deferred. */ |
| 1628 | boolean checkCompleteDeferredRemoval() { |
| 1629 | if (isAnimating()) { |
| 1630 | return true; |
| 1631 | } |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1632 | if (mDeferRemoval) { |
| 1633 | removeImmediately(); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1634 | } |
| 1635 | |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1636 | return super.checkCompleteDeferredRemoval(); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1637 | } |
| 1638 | |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 1639 | void stepAppWindowsAnimation(long currentTime) { |
| 1640 | super.stepAppWindowsAnimation(currentTime); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1641 | |
| 1642 | // TODO: Why aren't we just using the loop above for this? mAppAnimator.animating isn't set |
| 1643 | // below but is set in the loop above. See if it really matters... |
Wale Ogunwale | 48458e1 | 2017-06-06 10:07:58 -0700 | [diff] [blame] | 1644 | |
| 1645 | // Clear before using. |
| 1646 | mTmpAppTokens.clear(); |
| 1647 | // We copy the list as things can be removed from the exiting token list while we are |
| 1648 | // processing. |
| 1649 | mTmpAppTokens.addAll(mExitingAppTokens); |
| 1650 | for (int i = 0; i < mTmpAppTokens.size(); i++) { |
| 1651 | final AppWindowAnimator appAnimator = mTmpAppTokens.get(i).mAppAnimator; |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1652 | appAnimator.wasAnimating = appAnimator.animating; |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 1653 | if (appAnimator.stepAnimationLocked(currentTime)) { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1654 | mService.mAnimator.setAnimating(true); |
| 1655 | mService.mAnimator.mAppWindowAnimating = true; |
| 1656 | } else if (appAnimator.wasAnimating) { |
| 1657 | // stopped animating, do one more pass through the layout |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 1658 | appAnimator.mAppToken.setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER, |
| 1659 | "exiting appToken " + appAnimator.mAppToken + " done"); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1660 | if (DEBUG_ANIM) Slog.v(TAG_WM, |
| 1661 | "updateWindowsApps...: done animating exiting " + appAnimator.mAppToken); |
| 1662 | } |
| 1663 | } |
Wale Ogunwale | 48458e1 | 2017-06-06 10:07:58 -0700 | [diff] [blame] | 1664 | // Clear to avoid holding reference to tokens. |
| 1665 | mTmpAppTokens.clear(); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1666 | } |
| 1667 | |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1668 | @Override |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1669 | int getOrientation() { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 1670 | return (canSpecifyOrientation()) ? super.getOrientation() : SCREEN_ORIENTATION_UNSET; |
| 1671 | } |
| 1672 | |
| 1673 | private boolean canSpecifyOrientation() { |
| 1674 | final int windowingMode = getWindowingMode(); |
| 1675 | final int activityType = getActivityType(); |
| 1676 | return windowingMode == WINDOWING_MODE_FULLSCREEN |
| 1677 | || activityType == ACTIVITY_TYPE_HOME |
| 1678 | || activityType == ACTIVITY_TYPE_RECENTS |
| 1679 | || activityType == ACTIVITY_TYPE_ASSISTANT; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1680 | } |
Wale Ogunwale | ecbcadd | 2016-02-21 14:18:51 -0800 | [diff] [blame] | 1681 | } |