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