blob: e3002563a6fd882f795d6067140342276a64dcf0 [file] [log] [blame]
Filip Gruszczynski466f3212015-09-21 17:57:57 -07001/*
2 * Copyright (C) 2012 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
17package com.android.server.wm;
18
Jorim Jaggibc5425c2016-03-01 13:51:16 +010019import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
Jorim Jaggid3ec5072016-04-28 15:57:47 -070020import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
Jorim Jaggibc5425c2016-03-01 13:51:16 +010021import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
Jorim Jaggi85639432016-05-06 17:27:55 -070022import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
23import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
24import static android.view.Surface.ROTATION_270;
25import static android.view.Surface.ROTATION_90;
Jorim Jaggibc5425c2016-03-01 13:51:16 +010026import static android.view.WindowManager.DOCKED_BOTTOM;
27import static android.view.WindowManager.DOCKED_LEFT;
28import static android.view.WindowManager.DOCKED_RIGHT;
29import static android.view.WindowManager.DOCKED_TOP;
30import static com.android.server.wm.AppTransition.DEFAULT_APP_TRANSITION_DURATION;
31import static com.android.server.wm.AppTransition.TOUCH_RESPONSE_INTERPOLATOR;
Jorim Jaggi84afb1a2016-09-28 14:54:04 +020032import static com.android.server.wm.AppTransition.TRANSIT_NONE;
Jorim Jaggibc5425c2016-03-01 13:51:16 +010033import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
34import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Tony Mak853304c2016-04-18 15:17:41 +010035import static com.android.server.wm.WindowManagerService.H.NOTIFY_DOCKED_STACK_MINIMIZED_CHANGED;
Wale Ogunwalec69694a2016-10-18 13:51:15 -070036import static com.android.server.wm.WindowManagerService.LAYER_OFFSET_DIM;
Jorim Jaggibc5425c2016-03-01 13:51:16 +010037
Filip Gruszczynski466f3212015-09-21 17:57:57 -070038import android.content.Context;
Jorim Jaggi85639432016-05-06 17:27:55 -070039import android.content.res.Configuration;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070040import android.graphics.Rect;
Jorim Jaggia6c934e2015-12-21 13:22:31 +010041import android.os.RemoteCallbackList;
Filip Gruszczynski64cdc142015-11-29 21:10:07 -080042import android.os.RemoteException;
Jorim Jaggi936aaeb2016-08-26 19:02:11 -070043import android.util.ArraySet;
Filip Gruszczynski77049052015-11-09 14:01:21 -080044import android.util.Slog;
Jorim Jaggi50981592015-12-29 17:54:12 +010045import android.view.DisplayInfo;
Jorim Jaggia6c934e2015-12-21 13:22:31 +010046import android.view.IDockedStackListener;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -080047import android.view.animation.AnimationUtils;
48import android.view.animation.Interpolator;
Jorim Jaggieb88d832016-04-13 20:17:43 -070049import android.view.animation.PathInterpolator;
Jorim Jaggi3c5d0f12016-05-24 19:04:30 -070050import android.view.inputmethod.InputMethodManagerInternal;
Jorim Jaggi50981592015-12-29 17:54:12 +010051
Jorim Jaggi85639432016-05-06 17:27:55 -070052import com.android.internal.policy.DividerSnapAlgorithm;
53import com.android.internal.policy.DockedDividerUtils;
Jorim Jaggi3c5d0f12016-05-24 19:04:30 -070054import com.android.server.LocalServices;
Jorim Jaggi50981592015-12-29 17:54:12 +010055import com.android.server.wm.DimLayer.DimLayerUser;
Jorim Jaggiff71d202016-04-14 13:12:36 -070056import com.android.server.wm.WindowManagerService.H;
Jorim Jaggi61f39a72015-10-29 16:54:18 +010057
Jorim Jaggi31f71702016-05-04 16:43:04 -070058import java.io.PrintWriter;
Chong Zhangbaba7832016-03-24 10:21:26 -070059
Filip Gruszczynski466f3212015-09-21 17:57:57 -070060/**
Jorim Jaggi61f39a72015-10-29 16:54:18 +010061 * Keeps information about the docked stack divider.
Filip Gruszczynski466f3212015-09-21 17:57:57 -070062 */
Jorim Jaggi50981592015-12-29 17:54:12 +010063public class DockedStackDividerController implements DimLayerUser {
Jorim Jaggi61f39a72015-10-29 16:54:18 +010064
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080065 private static final String TAG = TAG_WITH_CLASS_NAME ? "DockedStackDividerController" : TAG_WM;
Jorim Jaggi61f39a72015-10-29 16:54:18 +010066
Jorim Jaggif97ed922016-02-18 18:57:07 -080067 /**
68 * The fraction during the maximize/clip reveal animation the divider meets the edge of the clip
69 * revealing surface at the earliest.
70 */
71 private static final float CLIP_REVEAL_MEET_EARLIEST = 0.6f;
72
73 /**
74 * The fraction during the maximize/clip reveal animation the divider meets the edge of the clip
75 * revealing surface at the latest.
76 */
77 private static final float CLIP_REVEAL_MEET_LAST = 1f;
78
79 /**
80 * If the app translates at least CLIP_REVEAL_MEET_FRACTION_MIN * minimize distance, we start
81 * meet somewhere between {@link #CLIP_REVEAL_MEET_LAST} and {@link #CLIP_REVEAL_MEET_EARLIEST}.
82 */
83 private static final float CLIP_REVEAL_MEET_FRACTION_MIN = 0.4f;
84
85 /**
86 * If the app translates equals or more than CLIP_REVEAL_MEET_FRACTION_MIN * minimize distance,
87 * we meet at {@link #CLIP_REVEAL_MEET_EARLIEST}.
88 */
89 private static final float CLIP_REVEAL_MEET_FRACTION_MAX = 0.8f;
90
Jorim Jaggieb88d832016-04-13 20:17:43 -070091 private static final Interpolator IME_ADJUST_ENTRY_INTERPOLATOR =
Jorim Jaggiff71d202016-04-14 13:12:36 -070092 new PathInterpolator(0.2f, 0f, 0.1f, 1f);
Jorim Jaggieb88d832016-04-13 20:17:43 -070093
Jorim Jaggi698e7632016-04-13 21:02:22 -070094 private static final long IME_ADJUST_ANIM_DURATION = 280;
Jorim Jaggieb88d832016-04-13 20:17:43 -070095
Jorim Jaggiff71d202016-04-14 13:12:36 -070096 private static final long IME_ADJUST_DRAWN_TIMEOUT = 200;
97
Chong Zhang198afac2016-04-15 12:03:11 -070098 private static final int DIVIDER_WIDTH_INACTIVE_DP = 4;
99
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800100 private final WindowManagerService mService;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700101 private final DisplayContent mDisplayContent;
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700102 private int mDividerWindowWidth;
Chong Zhang198afac2016-04-15 12:03:11 -0700103 private int mDividerWindowWidthInactive;
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700104 private int mDividerInsets;
Matthew Nge15352e2016-12-20 15:36:29 -0800105 private int mTaskHeightInMinimizedMode;
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100106 private boolean mResizing;
107 private WindowState mWindow;
108 private final Rect mTmpRect = new Rect();
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800109 private final Rect mTmpRect2 = new Rect();
Jorim Jaggi85639432016-05-06 17:27:55 -0700110 private final Rect mTmpRect3 = new Rect();
Filip Gruszczynski77049052015-11-09 14:01:21 -0800111 private final Rect mLastRect = new Rect();
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800112 private boolean mLastVisibility = false;
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100113 private final RemoteCallbackList<IDockedStackListener> mDockedStackListeners
114 = new RemoteCallbackList<>();
Jorim Jaggi50981592015-12-29 17:54:12 +0100115 private final DimLayer mDimLayer;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700116
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800117 private boolean mMinimizedDock;
Chong Zhangbaba7832016-03-24 10:21:26 -0700118 private boolean mAnimatingForMinimizedDockedStack;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800119 private boolean mAnimationStarted;
120 private long mAnimationStartTime;
121 private float mAnimationStart;
122 private float mAnimationTarget;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800123 private long mAnimationDuration;
Jorim Jaggiff71d202016-04-14 13:12:36 -0700124 private boolean mAnimationStartDelayed;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800125 private final Interpolator mMinimizedDockInterpolator;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800126 private float mMaximizeMeetFraction;
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100127 private final Rect mTouchRegion = new Rect();
Chong Zhangbaba7832016-03-24 10:21:26 -0700128 private boolean mAnimatingForIme;
129 private boolean mAdjustedForIme;
Keisuke Kuroyanagi19d9a8f2016-05-12 16:49:02 -0700130 private int mImeHeight;
Jorim Jaggiff71d202016-04-14 13:12:36 -0700131 private WindowState mDelayedImeWin;
Chong Zhangf347ab52016-04-18 21:02:01 -0700132 private boolean mAdjustedForDivider;
133 private float mDividerAnimationStart;
134 private float mDividerAnimationTarget;
Wale Ogunwale10124582016-09-15 20:25:50 -0700135 float mLastAnimationProgress;
136 float mLastDividerProgress;
Jorim Jaggi85639432016-05-06 17:27:55 -0700137 private final DividerSnapAlgorithm[] mSnapAlgorithmForRotation = new DividerSnapAlgorithm[4];
Jorim Jaggi3c5d0f12016-05-24 19:04:30 -0700138 private boolean mImeHideRequested;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800139
140 DockedStackDividerController(WindowManagerService service, DisplayContent displayContent) {
141 mService = service;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700142 mDisplayContent = displayContent;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800143 final Context context = service.mContext;
Jorim Jaggibc5425c2016-03-01 13:51:16 +0100144 mDimLayer = new DimLayer(displayContent.mService, this, displayContent.getDisplayId(),
145 "DockedStackDim");
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800146 mMinimizedDockInterpolator = AnimationUtils.loadInterpolator(
147 context, android.R.interpolator.fast_out_slow_in);
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700148 loadDimens();
149 }
150
Jorim Jaggi85639432016-05-06 17:27:55 -0700151 int getSmallestWidthDpForBounds(Rect bounds) {
152 final DisplayInfo di = mDisplayContent.getDisplayInfo();
153
Jorim Jaggi85639432016-05-06 17:27:55 -0700154 final int baseDisplayWidth = mDisplayContent.mBaseDisplayWidth;
155 final int baseDisplayHeight = mDisplayContent.mBaseDisplayHeight;
156 int minWidth = Integer.MAX_VALUE;
157
158 // Go through all screen orientations and find the orientation in which the task has the
159 // smallest width.
160 for (int rotation = 0; rotation < 4; rotation++) {
161 mTmpRect.set(bounds);
162 mDisplayContent.rotateBounds(di.rotation, rotation, mTmpRect);
163 final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
164 mTmpRect2.set(0, 0,
165 rotated ? baseDisplayHeight : baseDisplayWidth,
166 rotated ? baseDisplayWidth : baseDisplayHeight);
167 final int orientation = mTmpRect2.width() <= mTmpRect2.height()
168 ? ORIENTATION_PORTRAIT
169 : ORIENTATION_LANDSCAPE;
170 final int dockSide = TaskStack.getDockSideUnchecked(mTmpRect, mTmpRect2, orientation);
171 final int position = DockedDividerUtils.calculatePositionForBounds(mTmpRect, dockSide,
172 getContentWidth());
173
174 // Since we only care about feasible states, snap to the closest snap target, like it
175 // would happen when actually rotating the screen.
176 final int snappedPosition = mSnapAlgorithmForRotation[rotation]
177 .calculateNonDismissingSnapTarget(position).position;
178 DockedDividerUtils.calculateBoundsForPosition(snappedPosition, dockSide, mTmpRect,
179 mTmpRect2.width(), mTmpRect2.height(), getContentWidth());
180 mService.mPolicy.getStableInsetsLw(rotation, mTmpRect2.width(), mTmpRect2.height(),
181 mTmpRect3);
Winson Chungbdc646f2017-02-13 12:12:22 -0800182 mService.intersectDisplayInsetBounds(mTmpRect2, mTmpRect3, mTmpRect);
Jorim Jaggi85639432016-05-06 17:27:55 -0700183 minWidth = Math.min(mTmpRect.width(), minWidth);
184 }
185 return (int) (minWidth / mDisplayContent.getDisplayMetrics().density);
186 }
187
Matthew Nge15352e2016-12-20 15:36:29 -0800188 void getHomeStackBoundsInDockedMode(Rect outBounds) {
189 final DisplayInfo di = mDisplayContent.getDisplayInfo();
190 mService.mPolicy.getStableInsetsLw(di.rotation, di.logicalWidth, di.logicalHeight,
191 mTmpRect);
192 int dividerSize = mDividerWindowWidth - 2 * mDividerInsets;
193 Configuration configuration = mDisplayContent.getConfiguration();
194 if (configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
195 outBounds.set(0, mTaskHeightInMinimizedMode + dividerSize + mTmpRect.top,
196 di.logicalWidth, di.logicalHeight);
197 } else {
198 outBounds.set(mTaskHeightInMinimizedMode + dividerSize + mTmpRect.left, 0,
199 di.logicalWidth, di.logicalHeight);
200 }
201 }
202
203 boolean isHomeStackResizable() {
204 final TaskStack homeStack = mDisplayContent.getHomeStack();
205 if (homeStack == null) {
206 return false;
207 }
208 final Task homeTask = homeStack.findHomeTask();
209 return homeTask != null && homeTask.isResizeable();
210 }
211
Jorim Jaggi85639432016-05-06 17:27:55 -0700212 private void initSnapAlgorithmForRotations() {
Andrii Kulian441e4492016-09-29 15:25:00 -0700213 final Configuration baseConfig = mDisplayContent.getConfiguration();
Jorim Jaggi85639432016-05-06 17:27:55 -0700214
215 // Initialize the snap algorithms for all 4 screen orientations.
216 final Configuration config = new Configuration();
217 for (int rotation = 0; rotation < 4; rotation++) {
218 final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
219 final int dw = rotated
220 ? mDisplayContent.mBaseDisplayHeight
221 : mDisplayContent.mBaseDisplayWidth;
222 final int dh = rotated
223 ? mDisplayContent.mBaseDisplayWidth
224 : mDisplayContent.mBaseDisplayHeight;
225 mService.mPolicy.getStableInsetsLw(rotation, dw, dh, mTmpRect);
Andrii Kulianb10330d2016-09-16 13:51:46 -0700226 config.unset();
Jorim Jaggi85639432016-05-06 17:27:55 -0700227 config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
Bryce Lee7566d762017-03-30 09:34:15 -0700228
229 final int displayId = mDisplayContent.getDisplayId();
230 final int appWidth = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation,
231 baseConfig.uiMode, displayId);
232 final int appHeight = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation,
233 baseConfig.uiMode, displayId);
234 mService.mPolicy.getNonDecorInsetsLw(rotation, dw, dh, mTmpRect);
235 final int leftInset = mTmpRect.left;
236 final int topInset = mTmpRect.top;
237
238 config.setAppBounds(leftInset /*left*/, topInset /*top*/, leftInset + appWidth /*right*/,
239 topInset + appHeight /*bottom*/);
240
Jorim Jaggi85639432016-05-06 17:27:55 -0700241 config.screenWidthDp = (int)
Andrii Kuliandb8e1062016-11-15 18:30:27 -0800242 (mService.mPolicy.getConfigDisplayWidth(dw, dh, rotation, baseConfig.uiMode,
Bryce Lee7566d762017-03-30 09:34:15 -0700243 displayId) / mDisplayContent.getDisplayMetrics().density);
Jorim Jaggi85639432016-05-06 17:27:55 -0700244 config.screenHeightDp = (int)
Andrii Kuliandb8e1062016-11-15 18:30:27 -0800245 (mService.mPolicy.getConfigDisplayHeight(dw, dh, rotation, baseConfig.uiMode,
Bryce Lee7566d762017-03-30 09:34:15 -0700246 displayId) / mDisplayContent.getDisplayMetrics().density);
Jorim Jaggi85639432016-05-06 17:27:55 -0700247 final Context rotationContext = mService.mContext.createConfigurationContext(config);
248 mSnapAlgorithmForRotation[rotation] = new DividerSnapAlgorithm(
249 rotationContext.getResources(), dw, dh, getContentWidth(),
250 config.orientation == ORIENTATION_PORTRAIT, mTmpRect);
251 }
252 }
253
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700254 private void loadDimens() {
255 final Context context = mService.mContext;
256 mDividerWindowWidth = context.getResources().getDimensionPixelSize(
257 com.android.internal.R.dimen.docked_stack_divider_thickness);
258 mDividerInsets = context.getResources().getDimensionPixelSize(
259 com.android.internal.R.dimen.docked_stack_divider_insets);
Chong Zhang198afac2016-04-15 12:03:11 -0700260 mDividerWindowWidthInactive = WindowManagerService.dipToPixel(
261 DIVIDER_WIDTH_INACTIVE_DP, mDisplayContent.getDisplayMetrics());
Matthew Nge15352e2016-12-20 15:36:29 -0800262 mTaskHeightInMinimizedMode = context.getResources().getDimensionPixelSize(
263 com.android.internal.R.dimen.task_height_of_minimized_mode);
Jorim Jaggi85639432016-05-06 17:27:55 -0700264 initSnapAlgorithmForRotations();
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700265 }
266
267 void onConfigurationChanged() {
268 loadDimens();
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700269 }
270
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100271 boolean isResizing() {
272 return mResizing;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700273 }
274
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100275 int getContentWidth() {
276 return mDividerWindowWidth - 2 * mDividerInsets;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700277 }
278
Jorim Jaggi81ba11e2016-02-03 22:04:22 -0800279 int getContentInsets() {
280 return mDividerInsets;
281 }
282
Chong Zhang198afac2016-04-15 12:03:11 -0700283 int getContentWidthInactive() {
284 return mDividerWindowWidthInactive;
285 }
286
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100287 void setResizing(boolean resizing) {
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800288 if (mResizing != resizing) {
289 mResizing = resizing;
290 resetDragResizingChangeReported();
291 }
292 }
293
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100294 void setTouchRegion(Rect touchRegion) {
295 mTouchRegion.set(touchRegion);
296 }
297
298 void getTouchRegion(Rect outRegion) {
299 outRegion.set(mTouchRegion);
300 outRegion.offset(mWindow.getFrameLw().left, mWindow.getFrameLw().top);
301 }
302
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800303 private void resetDragResizingChangeReported() {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800304 mDisplayContent.forAllWindows(WindowState::resetDragResizingChangeReported,
305 true /* traverseTopToBottom */ );
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100306 }
307
308 void setWindow(WindowState window) {
309 mWindow = window;
Filip Gruszczynski85d5cc42015-12-04 09:21:37 -0800310 reevaluateVisibility(false);
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100311 }
312
Filip Gruszczynski85d5cc42015-12-04 09:21:37 -0800313 void reevaluateVisibility(boolean force) {
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800314 if (mWindow == null) {
315 return;
316 }
Jorim Jaggife762342016-10-13 14:33:27 +0200317 TaskStack stack = mDisplayContent.getDockedStackIgnoringVisibility();
Jorim Jaggi7998e482016-02-12 18:47:06 -0800318
319 // If the stack is invisible, we policy force hide it in WindowAnimator.shouldForceHide
320 final boolean visible = stack != null;
Filip Gruszczynski85d5cc42015-12-04 09:21:37 -0800321 if (mLastVisibility == visible && !force) {
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800322 return;
323 }
324 mLastVisibility = visible;
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100325 notifyDockedDividerVisibilityChanged(visible);
Jorim Jaggi50981592015-12-29 17:54:12 +0100326 if (!visible) {
327 setResizeDimLayer(false, INVALID_STACK_ID, 0f);
328 }
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100329 }
330
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700331 private boolean wasVisible() {
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100332 return mLastVisibility;
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100333 }
334
Chong Zhangf347ab52016-04-18 21:02:01 -0700335 void setAdjustedForIme(
336 boolean adjustedForIme, boolean adjustedForDivider,
Keisuke Kuroyanagi19d9a8f2016-05-12 16:49:02 -0700337 boolean animate, WindowState imeWin, int imeHeight) {
338 if (mAdjustedForIme != adjustedForIme || (adjustedForIme && mImeHeight != imeHeight)
339 || mAdjustedForDivider != adjustedForDivider) {
Jorim Jaggi3070e772016-05-17 16:41:32 -0700340 if (animate && !mAnimatingForMinimizedDockedStack) {
Chong Zhangf347ab52016-04-18 21:02:01 -0700341 startImeAdjustAnimation(adjustedForIme, adjustedForDivider, imeWin);
Jorim Jaggiff71d202016-04-14 13:12:36 -0700342 } else {
Jorim Jaggiff71d202016-04-14 13:12:36 -0700343 // Animation might be delayed, so only notify if we don't run an animation.
Chong Zhangf347ab52016-04-18 21:02:01 -0700344 notifyAdjustedForImeChanged(adjustedForIme || adjustedForDivider, 0 /* duration */);
Jorim Jaggieb88d832016-04-13 20:17:43 -0700345 }
Chong Zhangf347ab52016-04-18 21:02:01 -0700346 mAdjustedForIme = adjustedForIme;
Keisuke Kuroyanagi19d9a8f2016-05-12 16:49:02 -0700347 mImeHeight = imeHeight;
Chong Zhangf347ab52016-04-18 21:02:01 -0700348 mAdjustedForDivider = adjustedForDivider;
Chong Zhangbaba7832016-03-24 10:21:26 -0700349 }
Chong Zhangb58bbcc2016-03-23 11:57:36 -0700350 }
351
Keisuke Kuroyanagi19d9a8f2016-05-12 16:49:02 -0700352 int getImeHeightAdjustedFor() {
353 return mImeHeight;
354 }
355
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700356 void positionDockedStackedDivider(Rect frame) {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700357 TaskStack stack = mDisplayContent.getDockedStackLocked();
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700358 if (stack == null) {
359 // Unfortunately we might end up with still having a divider, even though the underlying
360 // stack was already removed. This is because we are on AM thread and the removal of the
Filip Gruszczynski77049052015-11-09 14:01:21 -0800361 // divider was deferred to WM thread and hasn't happened yet. In that case let's just
362 // keep putting it in the same place it was before the stack was removed to have
363 // continuity and prevent it from jumping to the center. It will get hidden soon.
364 frame.set(mLastRect);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700365 return;
Filip Gruszczynski77049052015-11-09 14:01:21 -0800366 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800367 stack.getDimBounds(mTmpRect);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700368 }
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100369 int side = stack.getDockSide();
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700370 switch (side) {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700371 case DOCKED_LEFT:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100372 frame.set(mTmpRect.right - mDividerInsets, frame.top,
373 mTmpRect.right + frame.width() - mDividerInsets, frame.bottom);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700374 break;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700375 case DOCKED_TOP:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100376 frame.set(frame.left, mTmpRect.bottom - mDividerInsets,
377 mTmpRect.right, mTmpRect.bottom + frame.height() - mDividerInsets);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700378 break;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700379 case DOCKED_RIGHT:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100380 frame.set(mTmpRect.left - frame.width() + mDividerInsets, frame.top,
381 mTmpRect.left + mDividerInsets, frame.bottom);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700382 break;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700383 case DOCKED_BOTTOM:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100384 frame.set(frame.left, mTmpRect.top - frame.height() + mDividerInsets,
385 frame.right, mTmpRect.top + mDividerInsets);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700386 break;
387 }
Filip Gruszczynski77049052015-11-09 14:01:21 -0800388 mLastRect.set(frame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700389 }
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800390
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700391 private void notifyDockedDividerVisibilityChanged(boolean visible) {
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100392 final int size = mDockedStackListeners.beginBroadcast();
393 for (int i = 0; i < size; ++i) {
394 final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i);
395 try {
396 listener.onDividerVisibilityChanged(visible);
397 } catch (RemoteException e) {
398 Slog.e(TAG_WM, "Error delivering divider visibility changed event.", e);
399 }
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800400 }
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100401 mDockedStackListeners.finishBroadcast();
402 }
403
404 void notifyDockedStackExistsChanged(boolean exists) {
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700405 // TODO(multi-display): Perform all actions only for current display.
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100406 final int size = mDockedStackListeners.beginBroadcast();
407 for (int i = 0; i < size; ++i) {
408 final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i);
409 try {
410 listener.onDockedStackExistsChanged(exists);
411 } catch (RemoteException e) {
412 Slog.e(TAG_WM, "Error delivering docked stack exists changed event.", e);
413 }
414 }
415 mDockedStackListeners.finishBroadcast();
Jorim Jaggi3c5d0f12016-05-24 19:04:30 -0700416 if (exists) {
417 InputMethodManagerInternal inputMethodManagerInternal =
418 LocalServices.getService(InputMethodManagerInternal.class);
419 if (inputMethodManagerInternal != null) {
420
421 // Hide the current IME to avoid problems with animations from IME adjustment when
422 // attaching the docked stack.
423 inputMethodManagerInternal.hideCurrentInputMethod();
424 mImeHideRequested = true;
425 }
Jorim Jaggief92d6f2016-03-25 22:07:16 -0700426 }
Matthew Ngb5370b72016-12-13 18:01:22 -0800427 setMinimizedDockedStack(false, false /* animate */);
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100428 }
429
Jorim Jaggi3c5d0f12016-05-24 19:04:30 -0700430 /**
431 * Resets the state that IME hide has been requested. See {@link #isImeHideRequested}.
432 */
433 void resetImeHideRequested() {
434 mImeHideRequested = false;
435 }
436
437 /**
438 * The docked stack divider controller makes sure the IME gets hidden when attaching the docked
439 * stack, to avoid animation problems. This flag indicates whether the request to hide the IME
440 * has been sent in an asynchronous manner, and the IME should be treated as hidden already.
441 *
442 * @return whether IME hide request has been sent
443 */
444 boolean isImeHideRequested() {
445 return mImeHideRequested;
446 }
447
Matthew Nge15352e2016-12-20 15:36:29 -0800448 private void notifyDockedStackMinimizedChanged(boolean minimizedDock, boolean animate,
449 boolean isHomeStackResizable) {
450 long animDuration = 0;
451 if (animate) {
452 final TaskStack stack = mDisplayContent.getStackById(DOCKED_STACK_ID);
453 final long transitionDuration = isAnimationMaximizing()
454 ? mService.mAppTransition.getLastClipRevealTransitionDuration()
455 : DEFAULT_APP_TRANSITION_DURATION;
456 mAnimationDuration = (long)
457 (transitionDuration * mService.getTransitionAnimationScaleLocked());
458 mMaximizeMeetFraction = getClipRevealMeetFraction(stack);
459 animDuration = (long) (mAnimationDuration * mMaximizeMeetFraction);
460 }
Tony Mak853304c2016-04-18 15:17:41 +0100461 mService.mH.removeMessages(NOTIFY_DOCKED_STACK_MINIMIZED_CHANGED);
462 mService.mH.obtainMessage(NOTIFY_DOCKED_STACK_MINIMIZED_CHANGED,
463 minimizedDock ? 1 : 0, 0).sendToTarget();
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800464 final int size = mDockedStackListeners.beginBroadcast();
465 for (int i = 0; i < size; ++i) {
466 final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i);
467 try {
Matthew Nge15352e2016-12-20 15:36:29 -0800468 listener.onDockedStackMinimizedChanged(minimizedDock, animDuration,
469 isHomeStackResizable);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800470 } catch (RemoteException e) {
471 Slog.e(TAG_WM, "Error delivering minimized dock changed event.", e);
472 }
473 }
474 mDockedStackListeners.finishBroadcast();
475 }
476
Jorim Jaggi2917dc42016-04-11 11:39:13 -0700477 void notifyDockSideChanged(int newDockSide) {
478 final int size = mDockedStackListeners.beginBroadcast();
479 for (int i = 0; i < size; ++i) {
480 final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i);
481 try {
482 listener.onDockSideChanged(newDockSide);
483 } catch (RemoteException e) {
484 Slog.e(TAG_WM, "Error delivering dock side changed event.", e);
485 }
486 }
487 mDockedStackListeners.finishBroadcast();
488 }
489
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700490 private void notifyAdjustedForImeChanged(boolean adjustedForIme, long animDuration) {
Jorim Jaggi698e7632016-04-13 21:02:22 -0700491 final int size = mDockedStackListeners.beginBroadcast();
492 for (int i = 0; i < size; ++i) {
493 final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i);
494 try {
495 listener.onAdjustedForImeChanged(adjustedForIme, animDuration);
496 } catch (RemoteException e) {
497 Slog.e(TAG_WM, "Error delivering adjusted for ime changed event.", e);
498 }
499 }
500 mDockedStackListeners.finishBroadcast();
501 }
502
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100503 void registerDockedStackListener(IDockedStackListener listener) {
504 mDockedStackListeners.register(listener);
505 notifyDockedDividerVisibilityChanged(wasVisible());
Wale Ogunwale1666e312016-12-16 11:27:18 -0800506 notifyDockedStackExistsChanged(mDisplayContent.getDockedStackIgnoringVisibility() != null);
Matthew Nge15352e2016-12-20 15:36:29 -0800507 notifyDockedStackMinimizedChanged(mMinimizedDock, false /* animate */,
508 isHomeStackResizable());
Jorim Jaggi698e7632016-04-13 21:02:22 -0700509 notifyAdjustedForImeChanged(mAdjustedForIme, 0 /* animDuration */);
510
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800511 }
Jorim Jaggi50981592015-12-29 17:54:12 +0100512
513 void setResizeDimLayer(boolean visible, int targetStackId, float alpha) {
Robert Carr68e5c9e2016-09-14 10:50:09 -0700514 mService.openSurfaceTransaction();
Wale Ogunwale1666e312016-12-16 11:27:18 -0800515 final TaskStack stack = mDisplayContent.getStackById(targetStackId);
Jorim Jaggibc5425c2016-03-01 13:51:16 +0100516 final TaskStack dockedStack = mDisplayContent.getDockedStackLocked();
517 boolean visibleAndValid = visible && stack != null && dockedStack != null;
Jorim Jaggi7b371dd2016-01-05 15:32:34 +0100518 if (visibleAndValid) {
Jorim Jaggi50981592015-12-29 17:54:12 +0100519 stack.getDimBounds(mTmpRect);
Jorim Jaggi10b89dc2016-01-05 15:40:17 +0100520 if (mTmpRect.height() > 0 && mTmpRect.width() > 0) {
Jorim Jaggi7b371dd2016-01-05 15:32:34 +0100521 mDimLayer.setBounds(mTmpRect);
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700522 mDimLayer.show(getResizeDimLayer(), alpha, 0 /* duration */);
Jorim Jaggi7b371dd2016-01-05 15:32:34 +0100523 } else {
524 visibleAndValid = false;
525 }
526 }
527 if (!visibleAndValid) {
Jorim Jaggi50981592015-12-29 17:54:12 +0100528 mDimLayer.hide();
529 }
Robert Carr68e5c9e2016-09-14 10:50:09 -0700530 mService.closeSurfaceTransaction();
Jorim Jaggi50981592015-12-29 17:54:12 +0100531 }
532
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800533 /**
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700534 * @return The layer used for dimming the apps when dismissing docked/fullscreen stack. Just
535 * above all application surfaces.
536 */
537 private int getResizeDimLayer() {
538 return (mWindow != null) ? mWindow.mLayer - 1 : LAYER_OFFSET_DIM;
539 }
540
541 /**
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800542 * Notifies the docked stack divider controller of a visibility change that happens without
543 * an animation.
544 */
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700545 void notifyAppVisibilityChanged() {
546 checkMinimizeChanged(false /* animate */);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800547 }
548
Jorim Jaggi84afb1a2016-09-28 14:54:04 +0200549 void notifyAppTransitionStarting(ArraySet<AppWindowToken> openingApps, int appTransition) {
Jorim Jaggi936aaeb2016-08-26 19:02:11 -0700550 final boolean wasMinimized = mMinimizedDock;
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700551 checkMinimizeChanged(true /* animate */);
Jorim Jaggi936aaeb2016-08-26 19:02:11 -0700552
553 // We were minimized, and now we are still minimized, but somebody is trying to launch an
Matthew Ng8e265522017-02-13 11:09:37 -0800554 // app in docked stack, better show recent apps so we actually get unminimized! However do
555 // not do this if keyguard is dismissed such as when the device is unlocking. This catches
Jorim Jaggi936aaeb2016-08-26 19:02:11 -0700556 // any case that was missed in ActivityStarter.postStartActivityUncheckedProcessing because
557 // we couldn't retrace the launch of the app in the docked stack to the launch from
558 // homescreen.
Jorim Jaggi84afb1a2016-09-28 14:54:04 +0200559 if (wasMinimized && mMinimizedDock && containsAppInDockedStack(openingApps)
Matthew Ng8e265522017-02-13 11:09:37 -0800560 && appTransition != TRANSIT_NONE &&
561 !AppTransition.isKeyguardGoingAwayTransit(appTransition)) {
Jorim Jaggi936aaeb2016-08-26 19:02:11 -0700562 mService.showRecentApps(true /* fromHome */);
563 }
564 }
565
566 /**
567 * @return true if {@param apps} contains an activity in the docked stack, false otherwise.
568 */
569 private boolean containsAppInDockedStack(ArraySet<AppWindowToken> apps) {
570 for (int i = apps.size() - 1; i >= 0; i--) {
571 final AppWindowToken token = apps.valueAt(i);
Bryce Lee6d410262017-02-28 15:30:17 -0800572 if (token.getTask() != null && token.getTask().mStack.mStackId == DOCKED_STACK_ID) {
Jorim Jaggi936aaeb2016-08-26 19:02:11 -0700573 return true;
574 }
575 }
576 return false;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800577 }
578
Jorim Jaggi1ae68bf2016-05-09 18:44:34 -0700579 boolean isMinimizedDock() {
580 return mMinimizedDock;
581 }
582
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700583 private void checkMinimizeChanged(boolean animate) {
Jorim Jaggife762342016-10-13 14:33:27 +0200584 if (mDisplayContent.getDockedStackIgnoringVisibility() == null) {
Jorim Jaggi817a5242016-05-06 15:45:00 -0700585 return;
586 }
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700587 final TaskStack homeStack = mDisplayContent.getHomeStack();
588 if (homeStack == null) {
589 return;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800590 }
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700591 final Task homeTask = homeStack.findHomeTask();
592 if (homeTask == null || !isWithinDisplay(homeTask)) {
593 return;
594 }
Matthew Ng8e265522017-02-13 11:09:37 -0800595
596 // Do not minimize when dock is already minimized while keyguard is showing and not
597 // occluded such as unlocking the screen
598 if (mMinimizedDock && mService.mPolicy.isKeyguardShowingAndNotOccluded()) {
599 return;
600 }
Wale Ogunwale1666e312016-12-16 11:27:18 -0800601 final TaskStack fullscreenStack =
602 mDisplayContent.getStackById(FULLSCREEN_WORKSPACE_STACK_ID);
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700603 final boolean homeVisible = homeTask.getTopVisibleAppToken() != null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700604 final boolean homeBehind = (fullscreenStack != null && fullscreenStack.isVisible())
Wale Ogunwale15ead902016-09-02 14:30:11 -0700605 || (homeStack.hasMultipleTaskWithHomeTaskNotTop());
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800606 setMinimizedDockedStack(homeVisible && !homeBehind, animate);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800607 }
608
609 private boolean isWithinDisplay(Task task) {
610 task.mStack.getBounds(mTmpRect);
611 mDisplayContent.getLogicalDisplayRect(mTmpRect2);
612 return mTmpRect.intersect(mTmpRect2);
613 }
614
615 /**
616 * Sets whether the docked stack is currently in a minimized state, i.e. all the tasks in the
617 * docked stack are heavily clipped so you can only see a minimal peek state.
618 *
619 * @param minimizedDock Whether the docked stack is currently minimized.
620 * @param animate Whether to animate the change.
621 */
622 private void setMinimizedDockedStack(boolean minimizedDock, boolean animate) {
Jorim Jaggief92d6f2016-03-25 22:07:16 -0700623 final boolean wasMinimized = mMinimizedDock;
624 mMinimizedDock = minimizedDock;
Jorim Jaggi817a5242016-05-06 15:45:00 -0700625 if (minimizedDock == wasMinimized) {
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800626 return;
627 }
628
Chong Zhang22eff0a2016-07-01 14:48:11 -0700629 final boolean imeChanged = clearImeAdjustAnimation();
630 boolean minimizedChange = false;
Matthew Nge15352e2016-12-20 15:36:29 -0800631 if (isHomeStackResizable()) {
632 notifyDockedStackMinimizedChanged(minimizedDock, true /* animate */,
633 true /* isHomeStackResizable */);
634 minimizedChange = true;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800635 } else {
Matthew Nge15352e2016-12-20 15:36:29 -0800636 if (minimizedDock) {
637 if (animate) {
638 startAdjustAnimation(0f, 1f);
639 } else {
640 minimizedChange |= setMinimizedDockedStack(true);
641 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800642 } else {
Matthew Nge15352e2016-12-20 15:36:29 -0800643 if (animate) {
644 startAdjustAnimation(1f, 0f);
645 } else {
646 minimizedChange |= setMinimizedDockedStack(false);
647 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800648 }
649 }
Chong Zhang22eff0a2016-07-01 14:48:11 -0700650 if (imeChanged || minimizedChange) {
651 if (imeChanged && !minimizedChange) {
652 Slog.d(TAG, "setMinimizedDockedStack: IME adjust changed due to minimizing,"
653 + " minimizedDock=" + minimizedDock
654 + " minimizedChange=" + minimizedChange);
655 }
656 mService.mWindowPlacerLocked.performSurfacePlacement();
657 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800658 }
659
Chong Zhang22eff0a2016-07-01 14:48:11 -0700660 private boolean clearImeAdjustAnimation() {
Wale Ogunwale10124582016-09-15 20:25:50 -0700661 final boolean changed = mDisplayContent.clearImeAdjustAnimation();
Jorim Jaggieb88d832016-04-13 20:17:43 -0700662 mAnimatingForIme = false;
Chong Zhang22eff0a2016-07-01 14:48:11 -0700663 return changed;
Jorim Jaggieb88d832016-04-13 20:17:43 -0700664 }
665
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800666 private void startAdjustAnimation(float from, float to) {
Chong Zhangbaba7832016-03-24 10:21:26 -0700667 mAnimatingForMinimizedDockedStack = true;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800668 mAnimationStarted = false;
669 mAnimationStart = from;
670 mAnimationTarget = to;
671 }
672
Chong Zhangf347ab52016-04-18 21:02:01 -0700673 private void startImeAdjustAnimation(
674 boolean adjustedForIme, boolean adjustedForDivider, WindowState imeWin) {
Chong Zhangf347ab52016-04-18 21:02:01 -0700675
676 // If we're not in an animation, the starting point depends on whether we're adjusted
677 // or not. If we're already in an animation, we start from where the current animation
678 // left off, so that the motion doesn't look discontinuous.
679 if (!mAnimatingForIme) {
680 mAnimationStart = mAdjustedForIme ? 1 : 0;
681 mDividerAnimationStart = mAdjustedForDivider ? 1 : 0;
682 mLastAnimationProgress = mAnimationStart;
683 mLastDividerProgress = mDividerAnimationStart;
684 } else {
685 mAnimationStart = mLastAnimationProgress;
686 mDividerAnimationStart = mLastDividerProgress;
687 }
Jorim Jaggi3070e772016-05-17 16:41:32 -0700688 mAnimatingForIme = true;
689 mAnimationStarted = false;
Chong Zhangf347ab52016-04-18 21:02:01 -0700690 mAnimationTarget = adjustedForIme ? 1 : 0;
691 mDividerAnimationTarget = adjustedForDivider ? 1 : 0;
Jorim Jaggiff71d202016-04-14 13:12:36 -0700692
Wale Ogunwale10124582016-09-15 20:25:50 -0700693 mDisplayContent.beginImeAdjustAnimation();
Jorim Jaggiff71d202016-04-14 13:12:36 -0700694
695 // We put all tasks into drag resizing mode - wait until all of them have completed the
696 // drag resizing switch.
697 if (!mService.mWaitingForDrawn.isEmpty()) {
698 mService.mH.removeMessages(H.WAITING_FOR_DRAWN_TIMEOUT);
699 mService.mH.sendEmptyMessageDelayed(H.WAITING_FOR_DRAWN_TIMEOUT,
700 IME_ADJUST_DRAWN_TIMEOUT);
701 mAnimationStartDelayed = true;
702 if (imeWin != null) {
703
704 // There might be an old window delaying the animation start - clear it.
705 if (mDelayedImeWin != null) {
706 mDelayedImeWin.mWinAnimator.endDelayingAnimationStart();
707 }
708 mDelayedImeWin = imeWin;
709 imeWin.mWinAnimator.startDelayingAnimationStart();
710 }
Jorim Jaggi31883862016-11-04 15:45:30 -0700711
712 // If we are already waiting for something to be drawn, clear out the old one so it
713 // still gets executed.
714 // TODO: Have a real system where we can wait on different windows to be drawn with
715 // different callbacks.
716 if (mService.mWaitingForDrawnCallback != null) {
717 mService.mWaitingForDrawnCallback.run();
718 }
Jorim Jaggiff71d202016-04-14 13:12:36 -0700719 mService.mWaitingForDrawnCallback = () -> {
720 mAnimationStartDelayed = false;
721 if (mDelayedImeWin != null) {
722 mDelayedImeWin.mWinAnimator.endDelayingAnimationStart();
723 }
Chong Zhang22eff0a2016-07-01 14:48:11 -0700724 // If the adjust status changed since this was posted, only notify
725 // the new states and don't animate.
726 long duration = 0;
727 if (mAdjustedForIme == adjustedForIme
728 && mAdjustedForDivider == adjustedForDivider) {
729 duration = IME_ADJUST_ANIM_DURATION;
730 } else {
731 Slog.w(TAG, "IME adjust changed while waiting for drawn:"
732 + " adjustedForIme=" + adjustedForIme
733 + " adjustedForDivider=" + adjustedForDivider
734 + " mAdjustedForIme=" + mAdjustedForIme
735 + " mAdjustedForDivider=" + mAdjustedForDivider);
736 }
Chong Zhangf347ab52016-04-18 21:02:01 -0700737 notifyAdjustedForImeChanged(
Chong Zhang22eff0a2016-07-01 14:48:11 -0700738 mAdjustedForIme || mAdjustedForDivider, duration);
Jorim Jaggiff71d202016-04-14 13:12:36 -0700739 };
740 } else {
Chong Zhangf347ab52016-04-18 21:02:01 -0700741 notifyAdjustedForImeChanged(
742 adjustedForIme || adjustedForDivider, IME_ADJUST_ANIM_DURATION);
Jorim Jaggiff71d202016-04-14 13:12:36 -0700743 }
Jorim Jaggieb88d832016-04-13 20:17:43 -0700744 }
745
Chong Zhang22eff0a2016-07-01 14:48:11 -0700746 private boolean setMinimizedDockedStack(boolean minimized) {
Jorim Jaggife762342016-10-13 14:33:27 +0200747 final TaskStack stack = mDisplayContent.getDockedStackIgnoringVisibility();
Matthew Nge15352e2016-12-20 15:36:29 -0800748 notifyDockedStackMinimizedChanged(minimized, false /* animate */, isHomeStackResizable());
Chong Zhang22eff0a2016-07-01 14:48:11 -0700749 return stack != null && stack.setAdjustedForMinimizedDock(minimized ? 1f : 0f);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800750 }
751
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800752 private boolean isAnimationMaximizing() {
753 return mAnimationTarget == 0f;
754 }
755
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800756 public boolean animate(long now) {
Wale Ogunwale20ec11b2016-04-22 12:11:51 -0700757 if (mWindow == null) {
758 return false;
759 }
Chong Zhangbaba7832016-03-24 10:21:26 -0700760 if (mAnimatingForMinimizedDockedStack) {
761 return animateForMinimizedDockedStack(now);
762 } else if (mAnimatingForIme) {
Jorim Jaggieb88d832016-04-13 20:17:43 -0700763 return animateForIme(now);
Chong Zhangbaba7832016-03-24 10:21:26 -0700764 } else {
Wale Ogunwale20ec11b2016-04-22 12:11:51 -0700765 if (mDimLayer != null && mDimLayer.isDimming()) {
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700766 mDimLayer.setLayer(getResizeDimLayer());
Chong Zhang1402c2e2016-04-21 15:17:47 -0700767 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800768 return false;
769 }
Chong Zhangbaba7832016-03-24 10:21:26 -0700770 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800771
Jorim Jaggieb88d832016-04-13 20:17:43 -0700772 private boolean animateForIme(long now) {
Jorim Jaggiff71d202016-04-14 13:12:36 -0700773 if (!mAnimationStarted || mAnimationStartDelayed) {
Jorim Jaggieb88d832016-04-13 20:17:43 -0700774 mAnimationStarted = true;
775 mAnimationStartTime = now;
776 mAnimationDuration = (long)
Jorim Jaggi698e7632016-04-13 21:02:22 -0700777 (IME_ADJUST_ANIM_DURATION * mService.getWindowAnimationScaleLocked());
Jorim Jaggieb88d832016-04-13 20:17:43 -0700778 }
779 float t = Math.min(1f, (float) (now - mAnimationStartTime) / mAnimationDuration);
780 t = (mAnimationTarget == 1f ? IME_ADJUST_ENTRY_INTERPOLATOR : TOUCH_RESPONSE_INTERPOLATOR)
781 .getInterpolation(t);
Wale Ogunwale10124582016-09-15 20:25:50 -0700782 final boolean updated =
783 mDisplayContent.animateForIme(t, mAnimationTarget, mDividerAnimationTarget);
Jorim Jaggieb88d832016-04-13 20:17:43 -0700784 if (updated) {
785 mService.mWindowPlacerLocked.performSurfacePlacement();
786 }
787 if (t >= 1.0f) {
Chong Zhangf347ab52016-04-18 21:02:01 -0700788 mLastAnimationProgress = mAnimationTarget;
789 mLastDividerProgress = mDividerAnimationTarget;
Jorim Jaggieb88d832016-04-13 20:17:43 -0700790 mAnimatingForIme = false;
791 return false;
792 } else {
793 return true;
794 }
Chong Zhangbaba7832016-03-24 10:21:26 -0700795 }
796
797 private boolean animateForMinimizedDockedStack(long now) {
Wale Ogunwale1666e312016-12-16 11:27:18 -0800798 final TaskStack stack = mDisplayContent.getStackById(DOCKED_STACK_ID);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800799 if (!mAnimationStarted) {
800 mAnimationStarted = true;
801 mAnimationStartTime = now;
Matthew Nge15352e2016-12-20 15:36:29 -0800802 notifyDockedStackMinimizedChanged(mMinimizedDock, true /* animate */,
803 isHomeStackResizable() /* isHomeStackResizable */);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800804 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800805 float t = Math.min(1f, (float) (now - mAnimationStartTime) / mAnimationDuration);
806 t = (isAnimationMaximizing() ? TOUCH_RESPONSE_INTERPOLATOR : mMinimizedDockInterpolator)
807 .getInterpolation(t);
Chong Zhang741c0ba2016-05-27 12:52:11 -0700808 if (stack != null) {
809 if (stack.setAdjustedForMinimizedDock(getMinimizeAmount(stack, t))) {
810 mService.mWindowPlacerLocked.performSurfacePlacement();
811 }
812 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800813 if (t >= 1.0f) {
Chong Zhangbaba7832016-03-24 10:21:26 -0700814 mAnimatingForMinimizedDockedStack = false;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800815 return false;
816 } else {
817 return true;
818 }
819 }
820
Wale Ogunwale10124582016-09-15 20:25:50 -0700821 float getInterpolatedAnimationValue(float t) {
Jorim Jaggieb88d832016-04-13 20:17:43 -0700822 return t * mAnimationTarget + (1 - t) * mAnimationStart;
823 }
824
Wale Ogunwale10124582016-09-15 20:25:50 -0700825 float getInterpolatedDividerValue(float t) {
Chong Zhangf347ab52016-04-18 21:02:01 -0700826 return t * mDividerAnimationTarget + (1 - t) * mDividerAnimationStart;
827 }
828
Jorim Jaggif97ed922016-02-18 18:57:07 -0800829 /**
830 * Gets the amount how much to minimize a stack depending on the interpolated fraction t.
831 */
832 private float getMinimizeAmount(TaskStack stack, float t) {
Jorim Jaggieb88d832016-04-13 20:17:43 -0700833 final float naturalAmount = getInterpolatedAnimationValue(t);
Jorim Jaggif97ed922016-02-18 18:57:07 -0800834 if (isAnimationMaximizing()) {
835 return adjustMaximizeAmount(stack, t, naturalAmount);
836 } else {
837 return naturalAmount;
838 }
839 }
840
841 /**
842 * When maximizing the stack during a clip reveal transition, this adjusts the minimize amount
843 * during the transition such that the edge of the clip reveal rect is met earlier in the
844 * transition so we don't create a visible "hole", but only if both the clip reveal and the
845 * docked stack divider start from about the same portion on the screen.
846 */
847 private float adjustMaximizeAmount(TaskStack stack, float t, float naturalAmount) {
848 if (mMaximizeMeetFraction == 1f) {
849 return naturalAmount;
850 }
851 final int minimizeDistance = stack.getMinimizeDistance();
852 float startPrime = mService.mAppTransition.getLastClipRevealMaxTranslation()
853 / (float) minimizeDistance;
854 final float amountPrime = t * mAnimationTarget + (1 - t) * startPrime;
855 final float t2 = Math.min(t / mMaximizeMeetFraction, 1);
856 return amountPrime * t2 + naturalAmount * (1 - t2);
857 }
858
859 /**
860 * Retrieves the animation fraction at which the docked stack has to meet the clip reveal
861 * edge. See {@link #adjustMaximizeAmount}.
862 */
863 private float getClipRevealMeetFraction(TaskStack stack) {
864 if (!isAnimationMaximizing() || stack == null ||
865 !mService.mAppTransition.hadClipRevealAnimation()) {
866 return 1f;
867 }
868 final int minimizeDistance = stack.getMinimizeDistance();
869 final float fraction = Math.abs(mService.mAppTransition.getLastClipRevealMaxTranslation())
870 / (float) minimizeDistance;
871 final float t = Math.max(0, Math.min(1, (fraction - CLIP_REVEAL_MEET_FRACTION_MIN)
872 / (CLIP_REVEAL_MEET_FRACTION_MAX - CLIP_REVEAL_MEET_FRACTION_MIN)));
873 return CLIP_REVEAL_MEET_EARLIEST
874 + (1 - t) * (CLIP_REVEAL_MEET_LAST - CLIP_REVEAL_MEET_EARLIEST);
875 }
876
Jorim Jaggi50981592015-12-29 17:54:12 +0100877 @Override
Wale Ogunwale29bfbb82016-05-12 15:13:52 -0700878 public boolean dimFullscreen() {
Jorim Jaggi50981592015-12-29 17:54:12 +0100879 return false;
880 }
881
882 @Override
883 public DisplayInfo getDisplayInfo() {
884 return mDisplayContent.getDisplayInfo();
885 }
886
887 @Override
Wale Ogunwalef0a60a92017-01-19 09:44:40 -0800888 public boolean isAttachedToDisplay() {
889 return mDisplayContent != null;
890 }
891
892 @Override
Jorim Jaggi50981592015-12-29 17:54:12 +0100893 public void getDimBounds(Rect outBounds) {
894 // This dim layer user doesn't need this.
895 }
896
897 @Override
898 public String toShortString() {
899 return TAG;
900 }
Robert Carre63e01a2016-04-18 20:27:34 -0700901
902 WindowState getWindow() {
903 return mWindow;
904 }
Jorim Jaggi31f71702016-05-04 16:43:04 -0700905
906 void dump(String prefix, PrintWriter pw) {
907 pw.println(prefix + "DockedStackDividerController");
908 pw.println(prefix + " mLastVisibility=" + mLastVisibility);
909 pw.println(prefix + " mMinimizedDock=" + mMinimizedDock);
910 pw.println(prefix + " mAdjustedForIme=" + mAdjustedForIme);
911 pw.println(prefix + " mAdjustedForDivider=" + mAdjustedForDivider);
912 if (mDimLayer.isDimming()) {
913 pw.println(prefix + " Dim layer is dimming: ");
914 mDimLayer.printTo(prefix + " ", pw);
915 }
916 }
Robert Carre63e01a2016-04-18 20:27:34 -0700917}