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