blob: 75a79fd0b55faadb6d4d8badca204fe32bb04770 [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();
Matthew Nge15352e2016-12-20 15:36:29 -0800112 private final Rect mMiddlePositionDockedStackRect = new Rect();
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800113 private boolean mLastVisibility = false;
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100114 private final RemoteCallbackList<IDockedStackListener> mDockedStackListeners
115 = new RemoteCallbackList<>();
Jorim Jaggi50981592015-12-29 17:54:12 +0100116 private final DimLayer mDimLayer;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700117
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800118 private boolean mMinimizedDock;
Chong Zhangbaba7832016-03-24 10:21:26 -0700119 private boolean mAnimatingForMinimizedDockedStack;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800120 private boolean mAnimationStarted;
121 private long mAnimationStartTime;
122 private float mAnimationStart;
123 private float mAnimationTarget;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800124 private long mAnimationDuration;
Jorim Jaggiff71d202016-04-14 13:12:36 -0700125 private boolean mAnimationStartDelayed;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800126 private final Interpolator mMinimizedDockInterpolator;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800127 private float mMaximizeMeetFraction;
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100128 private final Rect mTouchRegion = new Rect();
Chong Zhangbaba7832016-03-24 10:21:26 -0700129 private boolean mAnimatingForIme;
130 private boolean mAdjustedForIme;
Keisuke Kuroyanagi19d9a8f2016-05-12 16:49:02 -0700131 private int mImeHeight;
Jorim Jaggiff71d202016-04-14 13:12:36 -0700132 private WindowState mDelayedImeWin;
Chong Zhangf347ab52016-04-18 21:02:01 -0700133 private boolean mAdjustedForDivider;
134 private float mDividerAnimationStart;
135 private float mDividerAnimationTarget;
Wale Ogunwale10124582016-09-15 20:25:50 -0700136 float mLastAnimationProgress;
137 float mLastDividerProgress;
Jorim Jaggi85639432016-05-06 17:27:55 -0700138 private final DividerSnapAlgorithm[] mSnapAlgorithmForRotation = new DividerSnapAlgorithm[4];
Jorim Jaggi3c5d0f12016-05-24 19:04:30 -0700139 private boolean mImeHideRequested;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800140
141 DockedStackDividerController(WindowManagerService service, DisplayContent displayContent) {
142 mService = service;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700143 mDisplayContent = displayContent;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800144 final Context context = service.mContext;
Jorim Jaggibc5425c2016-03-01 13:51:16 +0100145 mDimLayer = new DimLayer(displayContent.mService, this, displayContent.getDisplayId(),
146 "DockedStackDim");
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800147 mMinimizedDockInterpolator = AnimationUtils.loadInterpolator(
148 context, android.R.interpolator.fast_out_slow_in);
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700149 loadDimens();
150 }
151
Jorim Jaggi85639432016-05-06 17:27:55 -0700152 int getSmallestWidthDpForBounds(Rect bounds) {
153 final DisplayInfo di = mDisplayContent.getDisplayInfo();
154
Jorim Jaggi85639432016-05-06 17:27:55 -0700155 final int baseDisplayWidth = mDisplayContent.mBaseDisplayWidth;
156 final int baseDisplayHeight = mDisplayContent.mBaseDisplayHeight;
157 int minWidth = Integer.MAX_VALUE;
158
159 // Go through all screen orientations and find the orientation in which the task has the
160 // smallest width.
161 for (int rotation = 0; rotation < 4; rotation++) {
162 mTmpRect.set(bounds);
163 mDisplayContent.rotateBounds(di.rotation, rotation, mTmpRect);
164 final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
165 mTmpRect2.set(0, 0,
166 rotated ? baseDisplayHeight : baseDisplayWidth,
167 rotated ? baseDisplayWidth : baseDisplayHeight);
168 final int orientation = mTmpRect2.width() <= mTmpRect2.height()
169 ? ORIENTATION_PORTRAIT
170 : ORIENTATION_LANDSCAPE;
171 final int dockSide = TaskStack.getDockSideUnchecked(mTmpRect, mTmpRect2, orientation);
172 final int position = DockedDividerUtils.calculatePositionForBounds(mTmpRect, dockSide,
173 getContentWidth());
174
175 // Since we only care about feasible states, snap to the closest snap target, like it
176 // would happen when actually rotating the screen.
177 final int snappedPosition = mSnapAlgorithmForRotation[rotation]
178 .calculateNonDismissingSnapTarget(position).position;
179 DockedDividerUtils.calculateBoundsForPosition(snappedPosition, dockSide, mTmpRect,
180 mTmpRect2.width(), mTmpRect2.height(), getContentWidth());
181 mService.mPolicy.getStableInsetsLw(rotation, mTmpRect2.width(), mTmpRect2.height(),
182 mTmpRect3);
Winson Chungbdc646f2017-02-13 12:12:22 -0800183 mService.intersectDisplayInsetBounds(mTmpRect2, mTmpRect3, mTmpRect);
Jorim Jaggi85639432016-05-06 17:27:55 -0700184 minWidth = Math.min(mTmpRect.width(), minWidth);
185 }
186 return (int) (minWidth / mDisplayContent.getDisplayMetrics().density);
187 }
188
Matthew Nge15352e2016-12-20 15:36:29 -0800189 /**
190 * The middlePositionDockedStackRect is half the screen area that sits at the top (portrait) or
191 * left (landscape).
192 *
193 * @return fixed rect for temp stack
194 */
195 Rect getMiddlePositionDockedStackRect() {
196 return mMinimizedDock && isHomeStackResizable() ? mMiddlePositionDockedStackRect : null;
197 }
198
199 void getHomeStackBoundsInDockedMode(Rect outBounds) {
200 final DisplayInfo di = mDisplayContent.getDisplayInfo();
201 mService.mPolicy.getStableInsetsLw(di.rotation, di.logicalWidth, di.logicalHeight,
202 mTmpRect);
203 int dividerSize = mDividerWindowWidth - 2 * mDividerInsets;
204 Configuration configuration = mDisplayContent.getConfiguration();
205 if (configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
206 outBounds.set(0, mTaskHeightInMinimizedMode + dividerSize + mTmpRect.top,
207 di.logicalWidth, di.logicalHeight);
208 } else {
209 outBounds.set(mTaskHeightInMinimizedMode + dividerSize + mTmpRect.left, 0,
210 di.logicalWidth, di.logicalHeight);
211 }
212 }
213
214 boolean isHomeStackResizable() {
215 final TaskStack homeStack = mDisplayContent.getHomeStack();
216 if (homeStack == null) {
217 return false;
218 }
219 final Task homeTask = homeStack.findHomeTask();
220 return homeTask != null && homeTask.isResizeable();
221 }
222
Jorim Jaggi85639432016-05-06 17:27:55 -0700223 private void initSnapAlgorithmForRotations() {
Andrii Kulian441e4492016-09-29 15:25:00 -0700224 final Configuration baseConfig = mDisplayContent.getConfiguration();
Jorim Jaggi85639432016-05-06 17:27:55 -0700225
226 // Initialize the snap algorithms for all 4 screen orientations.
227 final Configuration config = new Configuration();
228 for (int rotation = 0; rotation < 4; rotation++) {
229 final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
230 final int dw = rotated
231 ? mDisplayContent.mBaseDisplayHeight
232 : mDisplayContent.mBaseDisplayWidth;
233 final int dh = rotated
234 ? mDisplayContent.mBaseDisplayWidth
235 : mDisplayContent.mBaseDisplayHeight;
236 mService.mPolicy.getStableInsetsLw(rotation, dw, dh, mTmpRect);
Andrii Kulianb10330d2016-09-16 13:51:46 -0700237 config.unset();
Jorim Jaggi85639432016-05-06 17:27:55 -0700238 config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
239 config.screenWidthDp = (int)
Andrii Kuliandb8e1062016-11-15 18:30:27 -0800240 (mService.mPolicy.getConfigDisplayWidth(dw, dh, rotation, baseConfig.uiMode,
241 mDisplayContent.getDisplayId()) /
Jorim Jaggi85639432016-05-06 17:27:55 -0700242 mDisplayContent.getDisplayMetrics().density);
243 config.screenHeightDp = (int)
Andrii Kuliandb8e1062016-11-15 18:30:27 -0800244 (mService.mPolicy.getConfigDisplayHeight(dw, dh, rotation, baseConfig.uiMode,
245 mDisplayContent.getDisplayId()) /
Jorim Jaggi85639432016-05-06 17:27:55 -0700246 mDisplayContent.getDisplayMetrics().density);
247 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
Matthew Nge15352e2016-12-20 15:36:29 -0800267 /**
268 * Calculates the constant rects {@link mMiddlePositionDockedStackRect} based on orientation,
269 * stable insets and display size.
270 */
271 private void updateConstantRects() {
272 final DisplayInfo di = mDisplayContent.getDisplayInfo();
273 mService.mPolicy.getStableInsetsLw(di.rotation, di.logicalWidth, di.logicalHeight,
274 mTmpRect);
275 int dividerSize = mDividerWindowWidth - 2 * mDividerInsets;
276 Configuration configuration = mDisplayContent.getConfiguration();
277 boolean isHorizontal = configuration.orientation == Configuration.ORIENTATION_PORTRAIT;
278 int middlePosition = DockedDividerUtils.calculateMiddlePosition(isHorizontal, mTmpRect,
279 di.logicalWidth, di.logicalHeight, dividerSize);
280 if (isHorizontal) {
281 mMiddlePositionDockedStackRect.set(0, 0, di.logicalWidth, middlePosition);
282 } else {
283 mMiddlePositionDockedStackRect.set(0, 0, middlePosition, di.logicalHeight);
284 }
285 }
286
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700287 void onConfigurationChanged() {
288 loadDimens();
Matthew Nge15352e2016-12-20 15:36:29 -0800289 updateConstantRects();
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700290 }
291
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100292 boolean isResizing() {
293 return mResizing;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700294 }
295
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100296 int getContentWidth() {
297 return mDividerWindowWidth - 2 * mDividerInsets;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700298 }
299
Jorim Jaggi81ba11e2016-02-03 22:04:22 -0800300 int getContentInsets() {
301 return mDividerInsets;
302 }
303
Chong Zhang198afac2016-04-15 12:03:11 -0700304 int getContentWidthInactive() {
305 return mDividerWindowWidthInactive;
306 }
307
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100308 void setResizing(boolean resizing) {
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800309 if (mResizing != resizing) {
310 mResizing = resizing;
311 resetDragResizingChangeReported();
312 }
313 }
314
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100315 void setTouchRegion(Rect touchRegion) {
316 mTouchRegion.set(touchRegion);
317 }
318
319 void getTouchRegion(Rect outRegion) {
320 outRegion.set(mTouchRegion);
321 outRegion.offset(mWindow.getFrameLw().left, mWindow.getFrameLw().top);
322 }
323
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800324 private void resetDragResizingChangeReported() {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800325 mDisplayContent.forAllWindows(WindowState::resetDragResizingChangeReported,
326 true /* traverseTopToBottom */ );
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100327 }
328
329 void setWindow(WindowState window) {
330 mWindow = window;
Filip Gruszczynski85d5cc42015-12-04 09:21:37 -0800331 reevaluateVisibility(false);
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100332 }
333
Filip Gruszczynski85d5cc42015-12-04 09:21:37 -0800334 void reevaluateVisibility(boolean force) {
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800335 if (mWindow == null) {
336 return;
337 }
Jorim Jaggife762342016-10-13 14:33:27 +0200338 TaskStack stack = mDisplayContent.getDockedStackIgnoringVisibility();
Jorim Jaggi7998e482016-02-12 18:47:06 -0800339
340 // If the stack is invisible, we policy force hide it in WindowAnimator.shouldForceHide
341 final boolean visible = stack != null;
Filip Gruszczynski85d5cc42015-12-04 09:21:37 -0800342 if (mLastVisibility == visible && !force) {
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800343 return;
344 }
345 mLastVisibility = visible;
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100346 notifyDockedDividerVisibilityChanged(visible);
Jorim Jaggi50981592015-12-29 17:54:12 +0100347 if (!visible) {
348 setResizeDimLayer(false, INVALID_STACK_ID, 0f);
349 }
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100350 }
351
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700352 private boolean wasVisible() {
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100353 return mLastVisibility;
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100354 }
355
Chong Zhangf347ab52016-04-18 21:02:01 -0700356 void setAdjustedForIme(
357 boolean adjustedForIme, boolean adjustedForDivider,
Keisuke Kuroyanagi19d9a8f2016-05-12 16:49:02 -0700358 boolean animate, WindowState imeWin, int imeHeight) {
359 if (mAdjustedForIme != adjustedForIme || (adjustedForIme && mImeHeight != imeHeight)
360 || mAdjustedForDivider != adjustedForDivider) {
Jorim Jaggi3070e772016-05-17 16:41:32 -0700361 if (animate && !mAnimatingForMinimizedDockedStack) {
Chong Zhangf347ab52016-04-18 21:02:01 -0700362 startImeAdjustAnimation(adjustedForIme, adjustedForDivider, imeWin);
Jorim Jaggiff71d202016-04-14 13:12:36 -0700363 } else {
Jorim Jaggiff71d202016-04-14 13:12:36 -0700364 // Animation might be delayed, so only notify if we don't run an animation.
Chong Zhangf347ab52016-04-18 21:02:01 -0700365 notifyAdjustedForImeChanged(adjustedForIme || adjustedForDivider, 0 /* duration */);
Jorim Jaggieb88d832016-04-13 20:17:43 -0700366 }
Chong Zhangf347ab52016-04-18 21:02:01 -0700367 mAdjustedForIme = adjustedForIme;
Keisuke Kuroyanagi19d9a8f2016-05-12 16:49:02 -0700368 mImeHeight = imeHeight;
Chong Zhangf347ab52016-04-18 21:02:01 -0700369 mAdjustedForDivider = adjustedForDivider;
Chong Zhangbaba7832016-03-24 10:21:26 -0700370 }
Chong Zhangb58bbcc2016-03-23 11:57:36 -0700371 }
372
Keisuke Kuroyanagi19d9a8f2016-05-12 16:49:02 -0700373 int getImeHeightAdjustedFor() {
374 return mImeHeight;
375 }
376
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700377 void positionDockedStackedDivider(Rect frame) {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700378 TaskStack stack = mDisplayContent.getDockedStackLocked();
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700379 if (stack == null) {
380 // Unfortunately we might end up with still having a divider, even though the underlying
381 // stack was already removed. This is because we are on AM thread and the removal of the
Filip Gruszczynski77049052015-11-09 14:01:21 -0800382 // divider was deferred to WM thread and hasn't happened yet. In that case let's just
383 // keep putting it in the same place it was before the stack was removed to have
384 // continuity and prevent it from jumping to the center. It will get hidden soon.
385 frame.set(mLastRect);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700386 return;
Filip Gruszczynski77049052015-11-09 14:01:21 -0800387 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800388 stack.getDimBounds(mTmpRect);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700389 }
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100390 int side = stack.getDockSide();
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700391 switch (side) {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700392 case DOCKED_LEFT:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100393 frame.set(mTmpRect.right - mDividerInsets, frame.top,
394 mTmpRect.right + frame.width() - mDividerInsets, frame.bottom);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700395 break;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700396 case DOCKED_TOP:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100397 frame.set(frame.left, mTmpRect.bottom - mDividerInsets,
398 mTmpRect.right, mTmpRect.bottom + frame.height() - mDividerInsets);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700399 break;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700400 case DOCKED_RIGHT:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100401 frame.set(mTmpRect.left - frame.width() + mDividerInsets, frame.top,
402 mTmpRect.left + mDividerInsets, frame.bottom);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700403 break;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700404 case DOCKED_BOTTOM:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100405 frame.set(frame.left, mTmpRect.top - frame.height() + mDividerInsets,
406 frame.right, mTmpRect.top + mDividerInsets);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700407 break;
408 }
Filip Gruszczynski77049052015-11-09 14:01:21 -0800409 mLastRect.set(frame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700410 }
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800411
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700412 private void notifyDockedDividerVisibilityChanged(boolean visible) {
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100413 final int size = mDockedStackListeners.beginBroadcast();
414 for (int i = 0; i < size; ++i) {
415 final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i);
416 try {
417 listener.onDividerVisibilityChanged(visible);
418 } catch (RemoteException e) {
419 Slog.e(TAG_WM, "Error delivering divider visibility changed event.", e);
420 }
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800421 }
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100422 mDockedStackListeners.finishBroadcast();
423 }
424
425 void notifyDockedStackExistsChanged(boolean exists) {
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700426 // TODO(multi-display): Perform all actions only for current display.
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100427 final int size = mDockedStackListeners.beginBroadcast();
428 for (int i = 0; i < size; ++i) {
429 final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i);
430 try {
431 listener.onDockedStackExistsChanged(exists);
432 } catch (RemoteException e) {
433 Slog.e(TAG_WM, "Error delivering docked stack exists changed event.", e);
434 }
435 }
436 mDockedStackListeners.finishBroadcast();
Jorim Jaggi3c5d0f12016-05-24 19:04:30 -0700437 if (exists) {
438 InputMethodManagerInternal inputMethodManagerInternal =
439 LocalServices.getService(InputMethodManagerInternal.class);
440 if (inputMethodManagerInternal != null) {
441
442 // Hide the current IME to avoid problems with animations from IME adjustment when
443 // attaching the docked stack.
444 inputMethodManagerInternal.hideCurrentInputMethod();
445 mImeHideRequested = true;
446 }
Jorim Jaggief92d6f2016-03-25 22:07:16 -0700447 }
Matthew Ngb5370b72016-12-13 18:01:22 -0800448 setMinimizedDockedStack(false, false /* animate */);
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100449 }
450
Jorim Jaggi3c5d0f12016-05-24 19:04:30 -0700451 /**
452 * Resets the state that IME hide has been requested. See {@link #isImeHideRequested}.
453 */
454 void resetImeHideRequested() {
455 mImeHideRequested = false;
456 }
457
458 /**
459 * The docked stack divider controller makes sure the IME gets hidden when attaching the docked
460 * stack, to avoid animation problems. This flag indicates whether the request to hide the IME
461 * has been sent in an asynchronous manner, and the IME should be treated as hidden already.
462 *
463 * @return whether IME hide request has been sent
464 */
465 boolean isImeHideRequested() {
466 return mImeHideRequested;
467 }
468
Matthew Nge15352e2016-12-20 15:36:29 -0800469 private void notifyDockedStackMinimizedChanged(boolean minimizedDock, boolean animate,
470 boolean isHomeStackResizable) {
471 long animDuration = 0;
472 if (animate) {
473 final TaskStack stack = mDisplayContent.getStackById(DOCKED_STACK_ID);
474 final long transitionDuration = isAnimationMaximizing()
475 ? mService.mAppTransition.getLastClipRevealTransitionDuration()
476 : DEFAULT_APP_TRANSITION_DURATION;
477 mAnimationDuration = (long)
478 (transitionDuration * mService.getTransitionAnimationScaleLocked());
479 mMaximizeMeetFraction = getClipRevealMeetFraction(stack);
480 animDuration = (long) (mAnimationDuration * mMaximizeMeetFraction);
481 }
Tony Mak853304c2016-04-18 15:17:41 +0100482 mService.mH.removeMessages(NOTIFY_DOCKED_STACK_MINIMIZED_CHANGED);
483 mService.mH.obtainMessage(NOTIFY_DOCKED_STACK_MINIMIZED_CHANGED,
484 minimizedDock ? 1 : 0, 0).sendToTarget();
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800485 final int size = mDockedStackListeners.beginBroadcast();
486 for (int i = 0; i < size; ++i) {
487 final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i);
488 try {
Matthew Nge15352e2016-12-20 15:36:29 -0800489 listener.onDockedStackMinimizedChanged(minimizedDock, animDuration,
490 isHomeStackResizable);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800491 } catch (RemoteException e) {
492 Slog.e(TAG_WM, "Error delivering minimized dock changed event.", e);
493 }
494 }
495 mDockedStackListeners.finishBroadcast();
496 }
497
Jorim Jaggi2917dc42016-04-11 11:39:13 -0700498 void notifyDockSideChanged(int newDockSide) {
499 final int size = mDockedStackListeners.beginBroadcast();
500 for (int i = 0; i < size; ++i) {
501 final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i);
502 try {
503 listener.onDockSideChanged(newDockSide);
504 } catch (RemoteException e) {
505 Slog.e(TAG_WM, "Error delivering dock side changed event.", e);
506 }
507 }
508 mDockedStackListeners.finishBroadcast();
509 }
510
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700511 private void notifyAdjustedForImeChanged(boolean adjustedForIme, long animDuration) {
Jorim Jaggi698e7632016-04-13 21:02:22 -0700512 final int size = mDockedStackListeners.beginBroadcast();
513 for (int i = 0; i < size; ++i) {
514 final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i);
515 try {
516 listener.onAdjustedForImeChanged(adjustedForIme, animDuration);
517 } catch (RemoteException e) {
518 Slog.e(TAG_WM, "Error delivering adjusted for ime changed event.", e);
519 }
520 }
521 mDockedStackListeners.finishBroadcast();
522 }
523
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100524 void registerDockedStackListener(IDockedStackListener listener) {
525 mDockedStackListeners.register(listener);
526 notifyDockedDividerVisibilityChanged(wasVisible());
Wale Ogunwale1666e312016-12-16 11:27:18 -0800527 notifyDockedStackExistsChanged(mDisplayContent.getDockedStackIgnoringVisibility() != null);
Matthew Nge15352e2016-12-20 15:36:29 -0800528 notifyDockedStackMinimizedChanged(mMinimizedDock, false /* animate */,
529 isHomeStackResizable());
Jorim Jaggi698e7632016-04-13 21:02:22 -0700530 notifyAdjustedForImeChanged(mAdjustedForIme, 0 /* animDuration */);
531
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800532 }
Jorim Jaggi50981592015-12-29 17:54:12 +0100533
534 void setResizeDimLayer(boolean visible, int targetStackId, float alpha) {
Robert Carr68e5c9e2016-09-14 10:50:09 -0700535 mService.openSurfaceTransaction();
Wale Ogunwale1666e312016-12-16 11:27:18 -0800536 final TaskStack stack = mDisplayContent.getStackById(targetStackId);
Jorim Jaggibc5425c2016-03-01 13:51:16 +0100537 final TaskStack dockedStack = mDisplayContent.getDockedStackLocked();
538 boolean visibleAndValid = visible && stack != null && dockedStack != null;
Jorim Jaggi7b371dd2016-01-05 15:32:34 +0100539 if (visibleAndValid) {
Jorim Jaggi50981592015-12-29 17:54:12 +0100540 stack.getDimBounds(mTmpRect);
Jorim Jaggi10b89dc2016-01-05 15:40:17 +0100541 if (mTmpRect.height() > 0 && mTmpRect.width() > 0) {
Jorim Jaggi7b371dd2016-01-05 15:32:34 +0100542 mDimLayer.setBounds(mTmpRect);
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700543 mDimLayer.show(getResizeDimLayer(), alpha, 0 /* duration */);
Jorim Jaggi7b371dd2016-01-05 15:32:34 +0100544 } else {
545 visibleAndValid = false;
546 }
547 }
548 if (!visibleAndValid) {
Jorim Jaggi50981592015-12-29 17:54:12 +0100549 mDimLayer.hide();
550 }
Robert Carr68e5c9e2016-09-14 10:50:09 -0700551 mService.closeSurfaceTransaction();
Jorim Jaggi50981592015-12-29 17:54:12 +0100552 }
553
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800554 /**
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700555 * @return The layer used for dimming the apps when dismissing docked/fullscreen stack. Just
556 * above all application surfaces.
557 */
558 private int getResizeDimLayer() {
559 return (mWindow != null) ? mWindow.mLayer - 1 : LAYER_OFFSET_DIM;
560 }
561
562 /**
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800563 * Notifies the docked stack divider controller of a visibility change that happens without
564 * an animation.
565 */
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700566 void notifyAppVisibilityChanged() {
567 checkMinimizeChanged(false /* animate */);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800568 }
569
Jorim Jaggi84afb1a2016-09-28 14:54:04 +0200570 void notifyAppTransitionStarting(ArraySet<AppWindowToken> openingApps, int appTransition) {
Jorim Jaggi936aaeb2016-08-26 19:02:11 -0700571 final boolean wasMinimized = mMinimizedDock;
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700572 checkMinimizeChanged(true /* animate */);
Jorim Jaggi936aaeb2016-08-26 19:02:11 -0700573
574 // We were minimized, and now we are still minimized, but somebody is trying to launch an
575 // app in docked stack, better show recent apps so we actually get unminimized! This catches
576 // any case that was missed in ActivityStarter.postStartActivityUncheckedProcessing because
577 // we couldn't retrace the launch of the app in the docked stack to the launch from
578 // homescreen.
Jorim Jaggi84afb1a2016-09-28 14:54:04 +0200579 if (wasMinimized && mMinimizedDock && containsAppInDockedStack(openingApps)
580 && appTransition != TRANSIT_NONE) {
Jorim Jaggi936aaeb2016-08-26 19:02:11 -0700581 mService.showRecentApps(true /* fromHome */);
582 }
583 }
584
585 /**
586 * @return true if {@param apps} contains an activity in the docked stack, false otherwise.
587 */
588 private boolean containsAppInDockedStack(ArraySet<AppWindowToken> apps) {
589 for (int i = apps.size() - 1; i >= 0; i--) {
590 final AppWindowToken token = apps.valueAt(i);
591 if (token.mTask != null && token.mTask.mStack.mStackId == DOCKED_STACK_ID) {
592 return true;
593 }
594 }
595 return false;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800596 }
597
Jorim Jaggi1ae68bf2016-05-09 18:44:34 -0700598 boolean isMinimizedDock() {
599 return mMinimizedDock;
600 }
601
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700602 private void checkMinimizeChanged(boolean animate) {
Jorim Jaggife762342016-10-13 14:33:27 +0200603 if (mDisplayContent.getDockedStackIgnoringVisibility() == null) {
Jorim Jaggi817a5242016-05-06 15:45:00 -0700604 return;
605 }
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700606 final TaskStack homeStack = mDisplayContent.getHomeStack();
607 if (homeStack == null) {
608 return;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800609 }
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700610 final Task homeTask = homeStack.findHomeTask();
611 if (homeTask == null || !isWithinDisplay(homeTask)) {
612 return;
613 }
Wale Ogunwale1666e312016-12-16 11:27:18 -0800614 final TaskStack fullscreenStack =
615 mDisplayContent.getStackById(FULLSCREEN_WORKSPACE_STACK_ID);
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700616 final boolean homeVisible = homeTask.getTopVisibleAppToken() != null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700617 final boolean homeBehind = (fullscreenStack != null && fullscreenStack.isVisible())
Wale Ogunwale15ead902016-09-02 14:30:11 -0700618 || (homeStack.hasMultipleTaskWithHomeTaskNotTop());
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800619 setMinimizedDockedStack(homeVisible && !homeBehind, animate);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800620 }
621
622 private boolean isWithinDisplay(Task task) {
623 task.mStack.getBounds(mTmpRect);
624 mDisplayContent.getLogicalDisplayRect(mTmpRect2);
625 return mTmpRect.intersect(mTmpRect2);
626 }
627
628 /**
629 * Sets whether the docked stack is currently in a minimized state, i.e. all the tasks in the
630 * docked stack are heavily clipped so you can only see a minimal peek state.
631 *
632 * @param minimizedDock Whether the docked stack is currently minimized.
633 * @param animate Whether to animate the change.
634 */
635 private void setMinimizedDockedStack(boolean minimizedDock, boolean animate) {
Jorim Jaggief92d6f2016-03-25 22:07:16 -0700636 final boolean wasMinimized = mMinimizedDock;
637 mMinimizedDock = minimizedDock;
Jorim Jaggi817a5242016-05-06 15:45:00 -0700638 if (minimizedDock == wasMinimized) {
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800639 return;
640 }
641
Chong Zhang22eff0a2016-07-01 14:48:11 -0700642 final boolean imeChanged = clearImeAdjustAnimation();
643 boolean minimizedChange = false;
Matthew Nge15352e2016-12-20 15:36:29 -0800644 if (isHomeStackResizable()) {
645 notifyDockedStackMinimizedChanged(minimizedDock, true /* animate */,
646 true /* isHomeStackResizable */);
647 minimizedChange = true;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800648 } else {
Matthew Nge15352e2016-12-20 15:36:29 -0800649 if (minimizedDock) {
650 if (animate) {
651 startAdjustAnimation(0f, 1f);
652 } else {
653 minimizedChange |= setMinimizedDockedStack(true);
654 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800655 } else {
Matthew Nge15352e2016-12-20 15:36:29 -0800656 if (animate) {
657 startAdjustAnimation(1f, 0f);
658 } else {
659 minimizedChange |= setMinimizedDockedStack(false);
660 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800661 }
662 }
Chong Zhang22eff0a2016-07-01 14:48:11 -0700663 if (imeChanged || minimizedChange) {
664 if (imeChanged && !minimizedChange) {
665 Slog.d(TAG, "setMinimizedDockedStack: IME adjust changed due to minimizing,"
666 + " minimizedDock=" + minimizedDock
667 + " minimizedChange=" + minimizedChange);
668 }
669 mService.mWindowPlacerLocked.performSurfacePlacement();
670 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800671 }
672
Chong Zhang22eff0a2016-07-01 14:48:11 -0700673 private boolean clearImeAdjustAnimation() {
Wale Ogunwale10124582016-09-15 20:25:50 -0700674 final boolean changed = mDisplayContent.clearImeAdjustAnimation();
Jorim Jaggieb88d832016-04-13 20:17:43 -0700675 mAnimatingForIme = false;
Chong Zhang22eff0a2016-07-01 14:48:11 -0700676 return changed;
Jorim Jaggieb88d832016-04-13 20:17:43 -0700677 }
678
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800679 private void startAdjustAnimation(float from, float to) {
Chong Zhangbaba7832016-03-24 10:21:26 -0700680 mAnimatingForMinimizedDockedStack = true;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800681 mAnimationStarted = false;
682 mAnimationStart = from;
683 mAnimationTarget = to;
684 }
685
Chong Zhangf347ab52016-04-18 21:02:01 -0700686 private void startImeAdjustAnimation(
687 boolean adjustedForIme, boolean adjustedForDivider, WindowState imeWin) {
Chong Zhangf347ab52016-04-18 21:02:01 -0700688
689 // If we're not in an animation, the starting point depends on whether we're adjusted
690 // or not. If we're already in an animation, we start from where the current animation
691 // left off, so that the motion doesn't look discontinuous.
692 if (!mAnimatingForIme) {
693 mAnimationStart = mAdjustedForIme ? 1 : 0;
694 mDividerAnimationStart = mAdjustedForDivider ? 1 : 0;
695 mLastAnimationProgress = mAnimationStart;
696 mLastDividerProgress = mDividerAnimationStart;
697 } else {
698 mAnimationStart = mLastAnimationProgress;
699 mDividerAnimationStart = mLastDividerProgress;
700 }
Jorim Jaggi3070e772016-05-17 16:41:32 -0700701 mAnimatingForIme = true;
702 mAnimationStarted = false;
Chong Zhangf347ab52016-04-18 21:02:01 -0700703 mAnimationTarget = adjustedForIme ? 1 : 0;
704 mDividerAnimationTarget = adjustedForDivider ? 1 : 0;
Jorim Jaggiff71d202016-04-14 13:12:36 -0700705
Wale Ogunwale10124582016-09-15 20:25:50 -0700706 mDisplayContent.beginImeAdjustAnimation();
Jorim Jaggiff71d202016-04-14 13:12:36 -0700707
708 // We put all tasks into drag resizing mode - wait until all of them have completed the
709 // drag resizing switch.
710 if (!mService.mWaitingForDrawn.isEmpty()) {
711 mService.mH.removeMessages(H.WAITING_FOR_DRAWN_TIMEOUT);
712 mService.mH.sendEmptyMessageDelayed(H.WAITING_FOR_DRAWN_TIMEOUT,
713 IME_ADJUST_DRAWN_TIMEOUT);
714 mAnimationStartDelayed = true;
715 if (imeWin != null) {
716
717 // There might be an old window delaying the animation start - clear it.
718 if (mDelayedImeWin != null) {
719 mDelayedImeWin.mWinAnimator.endDelayingAnimationStart();
720 }
721 mDelayedImeWin = imeWin;
722 imeWin.mWinAnimator.startDelayingAnimationStart();
723 }
Jorim Jaggi31883862016-11-04 15:45:30 -0700724
725 // If we are already waiting for something to be drawn, clear out the old one so it
726 // still gets executed.
727 // TODO: Have a real system where we can wait on different windows to be drawn with
728 // different callbacks.
729 if (mService.mWaitingForDrawnCallback != null) {
730 mService.mWaitingForDrawnCallback.run();
731 }
Jorim Jaggiff71d202016-04-14 13:12:36 -0700732 mService.mWaitingForDrawnCallback = () -> {
733 mAnimationStartDelayed = false;
734 if (mDelayedImeWin != null) {
735 mDelayedImeWin.mWinAnimator.endDelayingAnimationStart();
736 }
Chong Zhang22eff0a2016-07-01 14:48:11 -0700737 // If the adjust status changed since this was posted, only notify
738 // the new states and don't animate.
739 long duration = 0;
740 if (mAdjustedForIme == adjustedForIme
741 && mAdjustedForDivider == adjustedForDivider) {
742 duration = IME_ADJUST_ANIM_DURATION;
743 } else {
744 Slog.w(TAG, "IME adjust changed while waiting for drawn:"
745 + " adjustedForIme=" + adjustedForIme
746 + " adjustedForDivider=" + adjustedForDivider
747 + " mAdjustedForIme=" + mAdjustedForIme
748 + " mAdjustedForDivider=" + mAdjustedForDivider);
749 }
Chong Zhangf347ab52016-04-18 21:02:01 -0700750 notifyAdjustedForImeChanged(
Chong Zhang22eff0a2016-07-01 14:48:11 -0700751 mAdjustedForIme || mAdjustedForDivider, duration);
Jorim Jaggiff71d202016-04-14 13:12:36 -0700752 };
753 } else {
Chong Zhangf347ab52016-04-18 21:02:01 -0700754 notifyAdjustedForImeChanged(
755 adjustedForIme || adjustedForDivider, IME_ADJUST_ANIM_DURATION);
Jorim Jaggiff71d202016-04-14 13:12:36 -0700756 }
Jorim Jaggieb88d832016-04-13 20:17:43 -0700757 }
758
Chong Zhang22eff0a2016-07-01 14:48:11 -0700759 private boolean setMinimizedDockedStack(boolean minimized) {
Jorim Jaggife762342016-10-13 14:33:27 +0200760 final TaskStack stack = mDisplayContent.getDockedStackIgnoringVisibility();
Matthew Nge15352e2016-12-20 15:36:29 -0800761 notifyDockedStackMinimizedChanged(minimized, false /* animate */, isHomeStackResizable());
Chong Zhang22eff0a2016-07-01 14:48:11 -0700762 return stack != null && stack.setAdjustedForMinimizedDock(minimized ? 1f : 0f);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800763 }
764
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800765 private boolean isAnimationMaximizing() {
766 return mAnimationTarget == 0f;
767 }
768
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800769 public boolean animate(long now) {
Wale Ogunwale20ec11b2016-04-22 12:11:51 -0700770 if (mWindow == null) {
771 return false;
772 }
Chong Zhangbaba7832016-03-24 10:21:26 -0700773 if (mAnimatingForMinimizedDockedStack) {
774 return animateForMinimizedDockedStack(now);
775 } else if (mAnimatingForIme) {
Jorim Jaggieb88d832016-04-13 20:17:43 -0700776 return animateForIme(now);
Chong Zhangbaba7832016-03-24 10:21:26 -0700777 } else {
Wale Ogunwale20ec11b2016-04-22 12:11:51 -0700778 if (mDimLayer != null && mDimLayer.isDimming()) {
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700779 mDimLayer.setLayer(getResizeDimLayer());
Chong Zhang1402c2e2016-04-21 15:17:47 -0700780 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800781 return false;
782 }
Chong Zhangbaba7832016-03-24 10:21:26 -0700783 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800784
Jorim Jaggieb88d832016-04-13 20:17:43 -0700785 private boolean animateForIme(long now) {
Jorim Jaggiff71d202016-04-14 13:12:36 -0700786 if (!mAnimationStarted || mAnimationStartDelayed) {
Jorim Jaggieb88d832016-04-13 20:17:43 -0700787 mAnimationStarted = true;
788 mAnimationStartTime = now;
789 mAnimationDuration = (long)
Jorim Jaggi698e7632016-04-13 21:02:22 -0700790 (IME_ADJUST_ANIM_DURATION * mService.getWindowAnimationScaleLocked());
Jorim Jaggieb88d832016-04-13 20:17:43 -0700791 }
792 float t = Math.min(1f, (float) (now - mAnimationStartTime) / mAnimationDuration);
793 t = (mAnimationTarget == 1f ? IME_ADJUST_ENTRY_INTERPOLATOR : TOUCH_RESPONSE_INTERPOLATOR)
794 .getInterpolation(t);
Wale Ogunwale10124582016-09-15 20:25:50 -0700795 final boolean updated =
796 mDisplayContent.animateForIme(t, mAnimationTarget, mDividerAnimationTarget);
Jorim Jaggieb88d832016-04-13 20:17:43 -0700797 if (updated) {
798 mService.mWindowPlacerLocked.performSurfacePlacement();
799 }
800 if (t >= 1.0f) {
Chong Zhangf347ab52016-04-18 21:02:01 -0700801 mLastAnimationProgress = mAnimationTarget;
802 mLastDividerProgress = mDividerAnimationTarget;
Jorim Jaggieb88d832016-04-13 20:17:43 -0700803 mAnimatingForIme = false;
804 return false;
805 } else {
806 return true;
807 }
Chong Zhangbaba7832016-03-24 10:21:26 -0700808 }
809
810 private boolean animateForMinimizedDockedStack(long now) {
Wale Ogunwale1666e312016-12-16 11:27:18 -0800811 final TaskStack stack = mDisplayContent.getStackById(DOCKED_STACK_ID);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800812 if (!mAnimationStarted) {
813 mAnimationStarted = true;
814 mAnimationStartTime = now;
Matthew Nge15352e2016-12-20 15:36:29 -0800815 notifyDockedStackMinimizedChanged(mMinimizedDock, true /* animate */,
816 isHomeStackResizable() /* isHomeStackResizable */);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800817 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800818 float t = Math.min(1f, (float) (now - mAnimationStartTime) / mAnimationDuration);
819 t = (isAnimationMaximizing() ? TOUCH_RESPONSE_INTERPOLATOR : mMinimizedDockInterpolator)
820 .getInterpolation(t);
Chong Zhang741c0ba2016-05-27 12:52:11 -0700821 if (stack != null) {
822 if (stack.setAdjustedForMinimizedDock(getMinimizeAmount(stack, t))) {
823 mService.mWindowPlacerLocked.performSurfacePlacement();
824 }
825 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800826 if (t >= 1.0f) {
Chong Zhangbaba7832016-03-24 10:21:26 -0700827 mAnimatingForMinimizedDockedStack = false;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800828 return false;
829 } else {
830 return true;
831 }
832 }
833
Wale Ogunwale10124582016-09-15 20:25:50 -0700834 float getInterpolatedAnimationValue(float t) {
Jorim Jaggieb88d832016-04-13 20:17:43 -0700835 return t * mAnimationTarget + (1 - t) * mAnimationStart;
836 }
837
Wale Ogunwale10124582016-09-15 20:25:50 -0700838 float getInterpolatedDividerValue(float t) {
Chong Zhangf347ab52016-04-18 21:02:01 -0700839 return t * mDividerAnimationTarget + (1 - t) * mDividerAnimationStart;
840 }
841
Jorim Jaggif97ed922016-02-18 18:57:07 -0800842 /**
843 * Gets the amount how much to minimize a stack depending on the interpolated fraction t.
844 */
845 private float getMinimizeAmount(TaskStack stack, float t) {
Jorim Jaggieb88d832016-04-13 20:17:43 -0700846 final float naturalAmount = getInterpolatedAnimationValue(t);
Jorim Jaggif97ed922016-02-18 18:57:07 -0800847 if (isAnimationMaximizing()) {
848 return adjustMaximizeAmount(stack, t, naturalAmount);
849 } else {
850 return naturalAmount;
851 }
852 }
853
854 /**
855 * When maximizing the stack during a clip reveal transition, this adjusts the minimize amount
856 * during the transition such that the edge of the clip reveal rect is met earlier in the
857 * transition so we don't create a visible "hole", but only if both the clip reveal and the
858 * docked stack divider start from about the same portion on the screen.
859 */
860 private float adjustMaximizeAmount(TaskStack stack, float t, float naturalAmount) {
861 if (mMaximizeMeetFraction == 1f) {
862 return naturalAmount;
863 }
864 final int minimizeDistance = stack.getMinimizeDistance();
865 float startPrime = mService.mAppTransition.getLastClipRevealMaxTranslation()
866 / (float) minimizeDistance;
867 final float amountPrime = t * mAnimationTarget + (1 - t) * startPrime;
868 final float t2 = Math.min(t / mMaximizeMeetFraction, 1);
869 return amountPrime * t2 + naturalAmount * (1 - t2);
870 }
871
872 /**
873 * Retrieves the animation fraction at which the docked stack has to meet the clip reveal
874 * edge. See {@link #adjustMaximizeAmount}.
875 */
876 private float getClipRevealMeetFraction(TaskStack stack) {
877 if (!isAnimationMaximizing() || stack == null ||
878 !mService.mAppTransition.hadClipRevealAnimation()) {
879 return 1f;
880 }
881 final int minimizeDistance = stack.getMinimizeDistance();
882 final float fraction = Math.abs(mService.mAppTransition.getLastClipRevealMaxTranslation())
883 / (float) minimizeDistance;
884 final float t = Math.max(0, Math.min(1, (fraction - CLIP_REVEAL_MEET_FRACTION_MIN)
885 / (CLIP_REVEAL_MEET_FRACTION_MAX - CLIP_REVEAL_MEET_FRACTION_MIN)));
886 return CLIP_REVEAL_MEET_EARLIEST
887 + (1 - t) * (CLIP_REVEAL_MEET_LAST - CLIP_REVEAL_MEET_EARLIEST);
888 }
889
Jorim Jaggi50981592015-12-29 17:54:12 +0100890 @Override
Wale Ogunwale29bfbb82016-05-12 15:13:52 -0700891 public boolean dimFullscreen() {
Jorim Jaggi50981592015-12-29 17:54:12 +0100892 return false;
893 }
894
895 @Override
896 public DisplayInfo getDisplayInfo() {
897 return mDisplayContent.getDisplayInfo();
898 }
899
900 @Override
Wale Ogunwalef0a60a92017-01-19 09:44:40 -0800901 public boolean isAttachedToDisplay() {
902 return mDisplayContent != null;
903 }
904
905 @Override
Jorim Jaggi50981592015-12-29 17:54:12 +0100906 public void getDimBounds(Rect outBounds) {
907 // This dim layer user doesn't need this.
908 }
909
910 @Override
911 public String toShortString() {
912 return TAG;
913 }
Robert Carre63e01a2016-04-18 20:27:34 -0700914
915 WindowState getWindow() {
916 return mWindow;
917 }
Jorim Jaggi31f71702016-05-04 16:43:04 -0700918
919 void dump(String prefix, PrintWriter pw) {
920 pw.println(prefix + "DockedStackDividerController");
921 pw.println(prefix + " mLastVisibility=" + mLastVisibility);
922 pw.println(prefix + " mMinimizedDock=" + mMinimizedDock);
923 pw.println(prefix + " mAdjustedForIme=" + mAdjustedForIme);
924 pw.println(prefix + " mAdjustedForDivider=" + mAdjustedForDivider);
925 if (mDimLayer.isDimming()) {
926 pw.println(prefix + " Dim layer is dimming: ");
927 mDimLayer.printTo(prefix + " ", pw);
928 }
929 }
Robert Carre63e01a2016-04-18 20:27:34 -0700930}