blob: 85eae0212373395c4ca22f48f24e5aae007f8e20 [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;
228 config.screenWidthDp = (int)
Andrii Kuliandb8e1062016-11-15 18:30:27 -0800229 (mService.mPolicy.getConfigDisplayWidth(dw, dh, rotation, baseConfig.uiMode,
230 mDisplayContent.getDisplayId()) /
Jorim Jaggi85639432016-05-06 17:27:55 -0700231 mDisplayContent.getDisplayMetrics().density);
232 config.screenHeightDp = (int)
Andrii Kuliandb8e1062016-11-15 18:30:27 -0800233 (mService.mPolicy.getConfigDisplayHeight(dw, dh, rotation, baseConfig.uiMode,
234 mDisplayContent.getDisplayId()) /
Jorim Jaggi85639432016-05-06 17:27:55 -0700235 mDisplayContent.getDisplayMetrics().density);
236 final Context rotationContext = mService.mContext.createConfigurationContext(config);
237 mSnapAlgorithmForRotation[rotation] = new DividerSnapAlgorithm(
238 rotationContext.getResources(), dw, dh, getContentWidth(),
239 config.orientation == ORIENTATION_PORTRAIT, mTmpRect);
240 }
241 }
242
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700243 private void loadDimens() {
244 final Context context = mService.mContext;
245 mDividerWindowWidth = context.getResources().getDimensionPixelSize(
246 com.android.internal.R.dimen.docked_stack_divider_thickness);
247 mDividerInsets = context.getResources().getDimensionPixelSize(
248 com.android.internal.R.dimen.docked_stack_divider_insets);
Chong Zhang198afac2016-04-15 12:03:11 -0700249 mDividerWindowWidthInactive = WindowManagerService.dipToPixel(
250 DIVIDER_WIDTH_INACTIVE_DP, mDisplayContent.getDisplayMetrics());
Matthew Nge15352e2016-12-20 15:36:29 -0800251 mTaskHeightInMinimizedMode = context.getResources().getDimensionPixelSize(
252 com.android.internal.R.dimen.task_height_of_minimized_mode);
Jorim Jaggi85639432016-05-06 17:27:55 -0700253 initSnapAlgorithmForRotations();
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700254 }
255
256 void onConfigurationChanged() {
257 loadDimens();
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700258 }
259
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100260 boolean isResizing() {
261 return mResizing;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700262 }
263
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100264 int getContentWidth() {
265 return mDividerWindowWidth - 2 * mDividerInsets;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700266 }
267
Jorim Jaggi81ba11e2016-02-03 22:04:22 -0800268 int getContentInsets() {
269 return mDividerInsets;
270 }
271
Chong Zhang198afac2016-04-15 12:03:11 -0700272 int getContentWidthInactive() {
273 return mDividerWindowWidthInactive;
274 }
275
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100276 void setResizing(boolean resizing) {
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800277 if (mResizing != resizing) {
278 mResizing = resizing;
279 resetDragResizingChangeReported();
280 }
281 }
282
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100283 void setTouchRegion(Rect touchRegion) {
284 mTouchRegion.set(touchRegion);
285 }
286
287 void getTouchRegion(Rect outRegion) {
288 outRegion.set(mTouchRegion);
289 outRegion.offset(mWindow.getFrameLw().left, mWindow.getFrameLw().top);
290 }
291
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800292 private void resetDragResizingChangeReported() {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800293 mDisplayContent.forAllWindows(WindowState::resetDragResizingChangeReported,
294 true /* traverseTopToBottom */ );
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100295 }
296
297 void setWindow(WindowState window) {
298 mWindow = window;
Filip Gruszczynski85d5cc42015-12-04 09:21:37 -0800299 reevaluateVisibility(false);
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100300 }
301
Filip Gruszczynski85d5cc42015-12-04 09:21:37 -0800302 void reevaluateVisibility(boolean force) {
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800303 if (mWindow == null) {
304 return;
305 }
Jorim Jaggife762342016-10-13 14:33:27 +0200306 TaskStack stack = mDisplayContent.getDockedStackIgnoringVisibility();
Jorim Jaggi7998e482016-02-12 18:47:06 -0800307
308 // If the stack is invisible, we policy force hide it in WindowAnimator.shouldForceHide
309 final boolean visible = stack != null;
Filip Gruszczynski85d5cc42015-12-04 09:21:37 -0800310 if (mLastVisibility == visible && !force) {
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800311 return;
312 }
313 mLastVisibility = visible;
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100314 notifyDockedDividerVisibilityChanged(visible);
Jorim Jaggi50981592015-12-29 17:54:12 +0100315 if (!visible) {
316 setResizeDimLayer(false, INVALID_STACK_ID, 0f);
317 }
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100318 }
319
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700320 private boolean wasVisible() {
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100321 return mLastVisibility;
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100322 }
323
Chong Zhangf347ab52016-04-18 21:02:01 -0700324 void setAdjustedForIme(
325 boolean adjustedForIme, boolean adjustedForDivider,
Keisuke Kuroyanagi19d9a8f2016-05-12 16:49:02 -0700326 boolean animate, WindowState imeWin, int imeHeight) {
327 if (mAdjustedForIme != adjustedForIme || (adjustedForIme && mImeHeight != imeHeight)
328 || mAdjustedForDivider != adjustedForDivider) {
Jorim Jaggi3070e772016-05-17 16:41:32 -0700329 if (animate && !mAnimatingForMinimizedDockedStack) {
Chong Zhangf347ab52016-04-18 21:02:01 -0700330 startImeAdjustAnimation(adjustedForIme, adjustedForDivider, imeWin);
Jorim Jaggiff71d202016-04-14 13:12:36 -0700331 } else {
Jorim Jaggiff71d202016-04-14 13:12:36 -0700332 // Animation might be delayed, so only notify if we don't run an animation.
Chong Zhangf347ab52016-04-18 21:02:01 -0700333 notifyAdjustedForImeChanged(adjustedForIme || adjustedForDivider, 0 /* duration */);
Jorim Jaggieb88d832016-04-13 20:17:43 -0700334 }
Chong Zhangf347ab52016-04-18 21:02:01 -0700335 mAdjustedForIme = adjustedForIme;
Keisuke Kuroyanagi19d9a8f2016-05-12 16:49:02 -0700336 mImeHeight = imeHeight;
Chong Zhangf347ab52016-04-18 21:02:01 -0700337 mAdjustedForDivider = adjustedForDivider;
Chong Zhangbaba7832016-03-24 10:21:26 -0700338 }
Chong Zhangb58bbcc2016-03-23 11:57:36 -0700339 }
340
Keisuke Kuroyanagi19d9a8f2016-05-12 16:49:02 -0700341 int getImeHeightAdjustedFor() {
342 return mImeHeight;
343 }
344
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700345 void positionDockedStackedDivider(Rect frame) {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700346 TaskStack stack = mDisplayContent.getDockedStackLocked();
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700347 if (stack == null) {
348 // Unfortunately we might end up with still having a divider, even though the underlying
349 // stack was already removed. This is because we are on AM thread and the removal of the
Filip Gruszczynski77049052015-11-09 14:01:21 -0800350 // divider was deferred to WM thread and hasn't happened yet. In that case let's just
351 // keep putting it in the same place it was before the stack was removed to have
352 // continuity and prevent it from jumping to the center. It will get hidden soon.
353 frame.set(mLastRect);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700354 return;
Filip Gruszczynski77049052015-11-09 14:01:21 -0800355 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800356 stack.getDimBounds(mTmpRect);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700357 }
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100358 int side = stack.getDockSide();
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700359 switch (side) {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700360 case DOCKED_LEFT:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100361 frame.set(mTmpRect.right - mDividerInsets, frame.top,
362 mTmpRect.right + frame.width() - mDividerInsets, frame.bottom);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700363 break;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700364 case DOCKED_TOP:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100365 frame.set(frame.left, mTmpRect.bottom - mDividerInsets,
366 mTmpRect.right, mTmpRect.bottom + frame.height() - mDividerInsets);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700367 break;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700368 case DOCKED_RIGHT:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100369 frame.set(mTmpRect.left - frame.width() + mDividerInsets, frame.top,
370 mTmpRect.left + mDividerInsets, frame.bottom);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700371 break;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700372 case DOCKED_BOTTOM:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100373 frame.set(frame.left, mTmpRect.top - frame.height() + mDividerInsets,
374 frame.right, mTmpRect.top + mDividerInsets);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700375 break;
376 }
Filip Gruszczynski77049052015-11-09 14:01:21 -0800377 mLastRect.set(frame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700378 }
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800379
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700380 private void notifyDockedDividerVisibilityChanged(boolean visible) {
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100381 final int size = mDockedStackListeners.beginBroadcast();
382 for (int i = 0; i < size; ++i) {
383 final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i);
384 try {
385 listener.onDividerVisibilityChanged(visible);
386 } catch (RemoteException e) {
387 Slog.e(TAG_WM, "Error delivering divider visibility changed event.", e);
388 }
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800389 }
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100390 mDockedStackListeners.finishBroadcast();
391 }
392
393 void notifyDockedStackExistsChanged(boolean exists) {
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700394 // TODO(multi-display): Perform all actions only for current display.
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100395 final int size = mDockedStackListeners.beginBroadcast();
396 for (int i = 0; i < size; ++i) {
397 final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i);
398 try {
399 listener.onDockedStackExistsChanged(exists);
400 } catch (RemoteException e) {
401 Slog.e(TAG_WM, "Error delivering docked stack exists changed event.", e);
402 }
403 }
404 mDockedStackListeners.finishBroadcast();
Jorim Jaggi3c5d0f12016-05-24 19:04:30 -0700405 if (exists) {
406 InputMethodManagerInternal inputMethodManagerInternal =
407 LocalServices.getService(InputMethodManagerInternal.class);
408 if (inputMethodManagerInternal != null) {
409
410 // Hide the current IME to avoid problems with animations from IME adjustment when
411 // attaching the docked stack.
412 inputMethodManagerInternal.hideCurrentInputMethod();
413 mImeHideRequested = true;
414 }
Jorim Jaggief92d6f2016-03-25 22:07:16 -0700415 }
Matthew Ngb5370b72016-12-13 18:01:22 -0800416 setMinimizedDockedStack(false, false /* animate */);
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100417 }
418
Jorim Jaggi3c5d0f12016-05-24 19:04:30 -0700419 /**
420 * Resets the state that IME hide has been requested. See {@link #isImeHideRequested}.
421 */
422 void resetImeHideRequested() {
423 mImeHideRequested = false;
424 }
425
426 /**
427 * The docked stack divider controller makes sure the IME gets hidden when attaching the docked
428 * stack, to avoid animation problems. This flag indicates whether the request to hide the IME
429 * has been sent in an asynchronous manner, and the IME should be treated as hidden already.
430 *
431 * @return whether IME hide request has been sent
432 */
433 boolean isImeHideRequested() {
434 return mImeHideRequested;
435 }
436
Matthew Nge15352e2016-12-20 15:36:29 -0800437 private void notifyDockedStackMinimizedChanged(boolean minimizedDock, boolean animate,
438 boolean isHomeStackResizable) {
439 long animDuration = 0;
440 if (animate) {
441 final TaskStack stack = mDisplayContent.getStackById(DOCKED_STACK_ID);
442 final long transitionDuration = isAnimationMaximizing()
443 ? mService.mAppTransition.getLastClipRevealTransitionDuration()
444 : DEFAULT_APP_TRANSITION_DURATION;
445 mAnimationDuration = (long)
446 (transitionDuration * mService.getTransitionAnimationScaleLocked());
447 mMaximizeMeetFraction = getClipRevealMeetFraction(stack);
448 animDuration = (long) (mAnimationDuration * mMaximizeMeetFraction);
449 }
Tony Mak853304c2016-04-18 15:17:41 +0100450 mService.mH.removeMessages(NOTIFY_DOCKED_STACK_MINIMIZED_CHANGED);
451 mService.mH.obtainMessage(NOTIFY_DOCKED_STACK_MINIMIZED_CHANGED,
452 minimizedDock ? 1 : 0, 0).sendToTarget();
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800453 final int size = mDockedStackListeners.beginBroadcast();
454 for (int i = 0; i < size; ++i) {
455 final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i);
456 try {
Matthew Nge15352e2016-12-20 15:36:29 -0800457 listener.onDockedStackMinimizedChanged(minimizedDock, animDuration,
458 isHomeStackResizable);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800459 } catch (RemoteException e) {
460 Slog.e(TAG_WM, "Error delivering minimized dock changed event.", e);
461 }
462 }
463 mDockedStackListeners.finishBroadcast();
464 }
465
Jorim Jaggi2917dc42016-04-11 11:39:13 -0700466 void notifyDockSideChanged(int newDockSide) {
467 final int size = mDockedStackListeners.beginBroadcast();
468 for (int i = 0; i < size; ++i) {
469 final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i);
470 try {
471 listener.onDockSideChanged(newDockSide);
472 } catch (RemoteException e) {
473 Slog.e(TAG_WM, "Error delivering dock side changed event.", e);
474 }
475 }
476 mDockedStackListeners.finishBroadcast();
477 }
478
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700479 private void notifyAdjustedForImeChanged(boolean adjustedForIme, long animDuration) {
Jorim Jaggi698e7632016-04-13 21:02:22 -0700480 final int size = mDockedStackListeners.beginBroadcast();
481 for (int i = 0; i < size; ++i) {
482 final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i);
483 try {
484 listener.onAdjustedForImeChanged(adjustedForIme, animDuration);
485 } catch (RemoteException e) {
486 Slog.e(TAG_WM, "Error delivering adjusted for ime changed event.", e);
487 }
488 }
489 mDockedStackListeners.finishBroadcast();
490 }
491
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100492 void registerDockedStackListener(IDockedStackListener listener) {
493 mDockedStackListeners.register(listener);
494 notifyDockedDividerVisibilityChanged(wasVisible());
Wale Ogunwale1666e312016-12-16 11:27:18 -0800495 notifyDockedStackExistsChanged(mDisplayContent.getDockedStackIgnoringVisibility() != null);
Matthew Nge15352e2016-12-20 15:36:29 -0800496 notifyDockedStackMinimizedChanged(mMinimizedDock, false /* animate */,
497 isHomeStackResizable());
Jorim Jaggi698e7632016-04-13 21:02:22 -0700498 notifyAdjustedForImeChanged(mAdjustedForIme, 0 /* animDuration */);
499
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800500 }
Jorim Jaggi50981592015-12-29 17:54:12 +0100501
502 void setResizeDimLayer(boolean visible, int targetStackId, float alpha) {
Robert Carr68e5c9e2016-09-14 10:50:09 -0700503 mService.openSurfaceTransaction();
Wale Ogunwale1666e312016-12-16 11:27:18 -0800504 final TaskStack stack = mDisplayContent.getStackById(targetStackId);
Jorim Jaggibc5425c2016-03-01 13:51:16 +0100505 final TaskStack dockedStack = mDisplayContent.getDockedStackLocked();
506 boolean visibleAndValid = visible && stack != null && dockedStack != null;
Jorim Jaggi7b371dd2016-01-05 15:32:34 +0100507 if (visibleAndValid) {
Jorim Jaggi50981592015-12-29 17:54:12 +0100508 stack.getDimBounds(mTmpRect);
Jorim Jaggi10b89dc2016-01-05 15:40:17 +0100509 if (mTmpRect.height() > 0 && mTmpRect.width() > 0) {
Jorim Jaggi7b371dd2016-01-05 15:32:34 +0100510 mDimLayer.setBounds(mTmpRect);
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700511 mDimLayer.show(getResizeDimLayer(), alpha, 0 /* duration */);
Jorim Jaggi7b371dd2016-01-05 15:32:34 +0100512 } else {
513 visibleAndValid = false;
514 }
515 }
516 if (!visibleAndValid) {
Jorim Jaggi50981592015-12-29 17:54:12 +0100517 mDimLayer.hide();
518 }
Robert Carr68e5c9e2016-09-14 10:50:09 -0700519 mService.closeSurfaceTransaction();
Jorim Jaggi50981592015-12-29 17:54:12 +0100520 }
521
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800522 /**
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700523 * @return The layer used for dimming the apps when dismissing docked/fullscreen stack. Just
524 * above all application surfaces.
525 */
526 private int getResizeDimLayer() {
527 return (mWindow != null) ? mWindow.mLayer - 1 : LAYER_OFFSET_DIM;
528 }
529
530 /**
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800531 * Notifies the docked stack divider controller of a visibility change that happens without
532 * an animation.
533 */
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700534 void notifyAppVisibilityChanged() {
535 checkMinimizeChanged(false /* animate */);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800536 }
537
Jorim Jaggi84afb1a2016-09-28 14:54:04 +0200538 void notifyAppTransitionStarting(ArraySet<AppWindowToken> openingApps, int appTransition) {
Jorim Jaggi936aaeb2016-08-26 19:02:11 -0700539 final boolean wasMinimized = mMinimizedDock;
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700540 checkMinimizeChanged(true /* animate */);
Jorim Jaggi936aaeb2016-08-26 19:02:11 -0700541
542 // We were minimized, and now we are still minimized, but somebody is trying to launch an
Matthew Ng8e265522017-02-13 11:09:37 -0800543 // app in docked stack, better show recent apps so we actually get unminimized! However do
544 // not do this if keyguard is dismissed such as when the device is unlocking. This catches
Jorim Jaggi936aaeb2016-08-26 19:02:11 -0700545 // any case that was missed in ActivityStarter.postStartActivityUncheckedProcessing because
546 // we couldn't retrace the launch of the app in the docked stack to the launch from
547 // homescreen.
Jorim Jaggi84afb1a2016-09-28 14:54:04 +0200548 if (wasMinimized && mMinimizedDock && containsAppInDockedStack(openingApps)
Matthew Ng8e265522017-02-13 11:09:37 -0800549 && appTransition != TRANSIT_NONE &&
550 !AppTransition.isKeyguardGoingAwayTransit(appTransition)) {
Jorim Jaggi936aaeb2016-08-26 19:02:11 -0700551 mService.showRecentApps(true /* fromHome */);
552 }
553 }
554
555 /**
556 * @return true if {@param apps} contains an activity in the docked stack, false otherwise.
557 */
558 private boolean containsAppInDockedStack(ArraySet<AppWindowToken> apps) {
559 for (int i = apps.size() - 1; i >= 0; i--) {
560 final AppWindowToken token = apps.valueAt(i);
Bryce Lee6d410262017-02-28 15:30:17 -0800561 if (token.getTask() != null && token.getTask().mStack.mStackId == DOCKED_STACK_ID) {
Jorim Jaggi936aaeb2016-08-26 19:02:11 -0700562 return true;
563 }
564 }
565 return false;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800566 }
567
Jorim Jaggi1ae68bf2016-05-09 18:44:34 -0700568 boolean isMinimizedDock() {
569 return mMinimizedDock;
570 }
571
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700572 private void checkMinimizeChanged(boolean animate) {
Jorim Jaggife762342016-10-13 14:33:27 +0200573 if (mDisplayContent.getDockedStackIgnoringVisibility() == null) {
Jorim Jaggi817a5242016-05-06 15:45:00 -0700574 return;
575 }
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700576 final TaskStack homeStack = mDisplayContent.getHomeStack();
577 if (homeStack == null) {
578 return;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800579 }
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700580 final Task homeTask = homeStack.findHomeTask();
581 if (homeTask == null || !isWithinDisplay(homeTask)) {
582 return;
583 }
Matthew Ng8e265522017-02-13 11:09:37 -0800584
585 // Do not minimize when dock is already minimized while keyguard is showing and not
586 // occluded such as unlocking the screen
587 if (mMinimizedDock && mService.mPolicy.isKeyguardShowingAndNotOccluded()) {
588 return;
589 }
Wale Ogunwale1666e312016-12-16 11:27:18 -0800590 final TaskStack fullscreenStack =
591 mDisplayContent.getStackById(FULLSCREEN_WORKSPACE_STACK_ID);
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700592 final boolean homeVisible = homeTask.getTopVisibleAppToken() != null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700593 final boolean homeBehind = (fullscreenStack != null && fullscreenStack.isVisible())
Wale Ogunwale15ead902016-09-02 14:30:11 -0700594 || (homeStack.hasMultipleTaskWithHomeTaskNotTop());
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800595 setMinimizedDockedStack(homeVisible && !homeBehind, animate);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800596 }
597
598 private boolean isWithinDisplay(Task task) {
599 task.mStack.getBounds(mTmpRect);
600 mDisplayContent.getLogicalDisplayRect(mTmpRect2);
601 return mTmpRect.intersect(mTmpRect2);
602 }
603
604 /**
605 * Sets whether the docked stack is currently in a minimized state, i.e. all the tasks in the
606 * docked stack are heavily clipped so you can only see a minimal peek state.
607 *
608 * @param minimizedDock Whether the docked stack is currently minimized.
609 * @param animate Whether to animate the change.
610 */
611 private void setMinimizedDockedStack(boolean minimizedDock, boolean animate) {
Jorim Jaggief92d6f2016-03-25 22:07:16 -0700612 final boolean wasMinimized = mMinimizedDock;
613 mMinimizedDock = minimizedDock;
Jorim Jaggi817a5242016-05-06 15:45:00 -0700614 if (minimizedDock == wasMinimized) {
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800615 return;
616 }
617
Chong Zhang22eff0a2016-07-01 14:48:11 -0700618 final boolean imeChanged = clearImeAdjustAnimation();
619 boolean minimizedChange = false;
Matthew Nge15352e2016-12-20 15:36:29 -0800620 if (isHomeStackResizable()) {
621 notifyDockedStackMinimizedChanged(minimizedDock, true /* animate */,
622 true /* isHomeStackResizable */);
623 minimizedChange = true;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800624 } else {
Matthew Nge15352e2016-12-20 15:36:29 -0800625 if (minimizedDock) {
626 if (animate) {
627 startAdjustAnimation(0f, 1f);
628 } else {
629 minimizedChange |= setMinimizedDockedStack(true);
630 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800631 } else {
Matthew Nge15352e2016-12-20 15:36:29 -0800632 if (animate) {
633 startAdjustAnimation(1f, 0f);
634 } else {
635 minimizedChange |= setMinimizedDockedStack(false);
636 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800637 }
638 }
Chong Zhang22eff0a2016-07-01 14:48:11 -0700639 if (imeChanged || minimizedChange) {
640 if (imeChanged && !minimizedChange) {
641 Slog.d(TAG, "setMinimizedDockedStack: IME adjust changed due to minimizing,"
642 + " minimizedDock=" + minimizedDock
643 + " minimizedChange=" + minimizedChange);
644 }
645 mService.mWindowPlacerLocked.performSurfacePlacement();
646 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800647 }
648
Chong Zhang22eff0a2016-07-01 14:48:11 -0700649 private boolean clearImeAdjustAnimation() {
Wale Ogunwale10124582016-09-15 20:25:50 -0700650 final boolean changed = mDisplayContent.clearImeAdjustAnimation();
Jorim Jaggieb88d832016-04-13 20:17:43 -0700651 mAnimatingForIme = false;
Chong Zhang22eff0a2016-07-01 14:48:11 -0700652 return changed;
Jorim Jaggieb88d832016-04-13 20:17:43 -0700653 }
654
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800655 private void startAdjustAnimation(float from, float to) {
Chong Zhangbaba7832016-03-24 10:21:26 -0700656 mAnimatingForMinimizedDockedStack = true;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800657 mAnimationStarted = false;
658 mAnimationStart = from;
659 mAnimationTarget = to;
660 }
661
Chong Zhangf347ab52016-04-18 21:02:01 -0700662 private void startImeAdjustAnimation(
663 boolean adjustedForIme, boolean adjustedForDivider, WindowState imeWin) {
Chong Zhangf347ab52016-04-18 21:02:01 -0700664
665 // If we're not in an animation, the starting point depends on whether we're adjusted
666 // or not. If we're already in an animation, we start from where the current animation
667 // left off, so that the motion doesn't look discontinuous.
668 if (!mAnimatingForIme) {
669 mAnimationStart = mAdjustedForIme ? 1 : 0;
670 mDividerAnimationStart = mAdjustedForDivider ? 1 : 0;
671 mLastAnimationProgress = mAnimationStart;
672 mLastDividerProgress = mDividerAnimationStart;
673 } else {
674 mAnimationStart = mLastAnimationProgress;
675 mDividerAnimationStart = mLastDividerProgress;
676 }
Jorim Jaggi3070e772016-05-17 16:41:32 -0700677 mAnimatingForIme = true;
678 mAnimationStarted = false;
Chong Zhangf347ab52016-04-18 21:02:01 -0700679 mAnimationTarget = adjustedForIme ? 1 : 0;
680 mDividerAnimationTarget = adjustedForDivider ? 1 : 0;
Jorim Jaggiff71d202016-04-14 13:12:36 -0700681
Wale Ogunwale10124582016-09-15 20:25:50 -0700682 mDisplayContent.beginImeAdjustAnimation();
Jorim Jaggiff71d202016-04-14 13:12:36 -0700683
684 // We put all tasks into drag resizing mode - wait until all of them have completed the
685 // drag resizing switch.
686 if (!mService.mWaitingForDrawn.isEmpty()) {
687 mService.mH.removeMessages(H.WAITING_FOR_DRAWN_TIMEOUT);
688 mService.mH.sendEmptyMessageDelayed(H.WAITING_FOR_DRAWN_TIMEOUT,
689 IME_ADJUST_DRAWN_TIMEOUT);
690 mAnimationStartDelayed = true;
691 if (imeWin != null) {
692
693 // There might be an old window delaying the animation start - clear it.
694 if (mDelayedImeWin != null) {
695 mDelayedImeWin.mWinAnimator.endDelayingAnimationStart();
696 }
697 mDelayedImeWin = imeWin;
698 imeWin.mWinAnimator.startDelayingAnimationStart();
699 }
Jorim Jaggi31883862016-11-04 15:45:30 -0700700
701 // If we are already waiting for something to be drawn, clear out the old one so it
702 // still gets executed.
703 // TODO: Have a real system where we can wait on different windows to be drawn with
704 // different callbacks.
705 if (mService.mWaitingForDrawnCallback != null) {
706 mService.mWaitingForDrawnCallback.run();
707 }
Jorim Jaggiff71d202016-04-14 13:12:36 -0700708 mService.mWaitingForDrawnCallback = () -> {
709 mAnimationStartDelayed = false;
710 if (mDelayedImeWin != null) {
711 mDelayedImeWin.mWinAnimator.endDelayingAnimationStart();
712 }
Chong Zhang22eff0a2016-07-01 14:48:11 -0700713 // If the adjust status changed since this was posted, only notify
714 // the new states and don't animate.
715 long duration = 0;
716 if (mAdjustedForIme == adjustedForIme
717 && mAdjustedForDivider == adjustedForDivider) {
718 duration = IME_ADJUST_ANIM_DURATION;
719 } else {
720 Slog.w(TAG, "IME adjust changed while waiting for drawn:"
721 + " adjustedForIme=" + adjustedForIme
722 + " adjustedForDivider=" + adjustedForDivider
723 + " mAdjustedForIme=" + mAdjustedForIme
724 + " mAdjustedForDivider=" + mAdjustedForDivider);
725 }
Chong Zhangf347ab52016-04-18 21:02:01 -0700726 notifyAdjustedForImeChanged(
Chong Zhang22eff0a2016-07-01 14:48:11 -0700727 mAdjustedForIme || mAdjustedForDivider, duration);
Jorim Jaggiff71d202016-04-14 13:12:36 -0700728 };
729 } else {
Chong Zhangf347ab52016-04-18 21:02:01 -0700730 notifyAdjustedForImeChanged(
731 adjustedForIme || adjustedForDivider, IME_ADJUST_ANIM_DURATION);
Jorim Jaggiff71d202016-04-14 13:12:36 -0700732 }
Jorim Jaggieb88d832016-04-13 20:17:43 -0700733 }
734
Chong Zhang22eff0a2016-07-01 14:48:11 -0700735 private boolean setMinimizedDockedStack(boolean minimized) {
Jorim Jaggife762342016-10-13 14:33:27 +0200736 final TaskStack stack = mDisplayContent.getDockedStackIgnoringVisibility();
Matthew Nge15352e2016-12-20 15:36:29 -0800737 notifyDockedStackMinimizedChanged(minimized, false /* animate */, isHomeStackResizable());
Chong Zhang22eff0a2016-07-01 14:48:11 -0700738 return stack != null && stack.setAdjustedForMinimizedDock(minimized ? 1f : 0f);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800739 }
740
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800741 private boolean isAnimationMaximizing() {
742 return mAnimationTarget == 0f;
743 }
744
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800745 public boolean animate(long now) {
Wale Ogunwale20ec11b2016-04-22 12:11:51 -0700746 if (mWindow == null) {
747 return false;
748 }
Chong Zhangbaba7832016-03-24 10:21:26 -0700749 if (mAnimatingForMinimizedDockedStack) {
750 return animateForMinimizedDockedStack(now);
751 } else if (mAnimatingForIme) {
Jorim Jaggieb88d832016-04-13 20:17:43 -0700752 return animateForIme(now);
Chong Zhangbaba7832016-03-24 10:21:26 -0700753 } else {
Wale Ogunwale20ec11b2016-04-22 12:11:51 -0700754 if (mDimLayer != null && mDimLayer.isDimming()) {
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700755 mDimLayer.setLayer(getResizeDimLayer());
Chong Zhang1402c2e2016-04-21 15:17:47 -0700756 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800757 return false;
758 }
Chong Zhangbaba7832016-03-24 10:21:26 -0700759 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800760
Jorim Jaggieb88d832016-04-13 20:17:43 -0700761 private boolean animateForIme(long now) {
Jorim Jaggiff71d202016-04-14 13:12:36 -0700762 if (!mAnimationStarted || mAnimationStartDelayed) {
Jorim Jaggieb88d832016-04-13 20:17:43 -0700763 mAnimationStarted = true;
764 mAnimationStartTime = now;
765 mAnimationDuration = (long)
Jorim Jaggi698e7632016-04-13 21:02:22 -0700766 (IME_ADJUST_ANIM_DURATION * mService.getWindowAnimationScaleLocked());
Jorim Jaggieb88d832016-04-13 20:17:43 -0700767 }
768 float t = Math.min(1f, (float) (now - mAnimationStartTime) / mAnimationDuration);
769 t = (mAnimationTarget == 1f ? IME_ADJUST_ENTRY_INTERPOLATOR : TOUCH_RESPONSE_INTERPOLATOR)
770 .getInterpolation(t);
Wale Ogunwale10124582016-09-15 20:25:50 -0700771 final boolean updated =
772 mDisplayContent.animateForIme(t, mAnimationTarget, mDividerAnimationTarget);
Jorim Jaggieb88d832016-04-13 20:17:43 -0700773 if (updated) {
774 mService.mWindowPlacerLocked.performSurfacePlacement();
775 }
776 if (t >= 1.0f) {
Chong Zhangf347ab52016-04-18 21:02:01 -0700777 mLastAnimationProgress = mAnimationTarget;
778 mLastDividerProgress = mDividerAnimationTarget;
Jorim Jaggieb88d832016-04-13 20:17:43 -0700779 mAnimatingForIme = false;
780 return false;
781 } else {
782 return true;
783 }
Chong Zhangbaba7832016-03-24 10:21:26 -0700784 }
785
786 private boolean animateForMinimizedDockedStack(long now) {
Wale Ogunwale1666e312016-12-16 11:27:18 -0800787 final TaskStack stack = mDisplayContent.getStackById(DOCKED_STACK_ID);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800788 if (!mAnimationStarted) {
789 mAnimationStarted = true;
790 mAnimationStartTime = now;
Matthew Nge15352e2016-12-20 15:36:29 -0800791 notifyDockedStackMinimizedChanged(mMinimizedDock, true /* animate */,
792 isHomeStackResizable() /* isHomeStackResizable */);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800793 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800794 float t = Math.min(1f, (float) (now - mAnimationStartTime) / mAnimationDuration);
795 t = (isAnimationMaximizing() ? TOUCH_RESPONSE_INTERPOLATOR : mMinimizedDockInterpolator)
796 .getInterpolation(t);
Chong Zhang741c0ba2016-05-27 12:52:11 -0700797 if (stack != null) {
798 if (stack.setAdjustedForMinimizedDock(getMinimizeAmount(stack, t))) {
799 mService.mWindowPlacerLocked.performSurfacePlacement();
800 }
801 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800802 if (t >= 1.0f) {
Chong Zhangbaba7832016-03-24 10:21:26 -0700803 mAnimatingForMinimizedDockedStack = false;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800804 return false;
805 } else {
806 return true;
807 }
808 }
809
Wale Ogunwale10124582016-09-15 20:25:50 -0700810 float getInterpolatedAnimationValue(float t) {
Jorim Jaggieb88d832016-04-13 20:17:43 -0700811 return t * mAnimationTarget + (1 - t) * mAnimationStart;
812 }
813
Wale Ogunwale10124582016-09-15 20:25:50 -0700814 float getInterpolatedDividerValue(float t) {
Chong Zhangf347ab52016-04-18 21:02:01 -0700815 return t * mDividerAnimationTarget + (1 - t) * mDividerAnimationStart;
816 }
817
Jorim Jaggif97ed922016-02-18 18:57:07 -0800818 /**
819 * Gets the amount how much to minimize a stack depending on the interpolated fraction t.
820 */
821 private float getMinimizeAmount(TaskStack stack, float t) {
Jorim Jaggieb88d832016-04-13 20:17:43 -0700822 final float naturalAmount = getInterpolatedAnimationValue(t);
Jorim Jaggif97ed922016-02-18 18:57:07 -0800823 if (isAnimationMaximizing()) {
824 return adjustMaximizeAmount(stack, t, naturalAmount);
825 } else {
826 return naturalAmount;
827 }
828 }
829
830 /**
831 * When maximizing the stack during a clip reveal transition, this adjusts the minimize amount
832 * during the transition such that the edge of the clip reveal rect is met earlier in the
833 * transition so we don't create a visible "hole", but only if both the clip reveal and the
834 * docked stack divider start from about the same portion on the screen.
835 */
836 private float adjustMaximizeAmount(TaskStack stack, float t, float naturalAmount) {
837 if (mMaximizeMeetFraction == 1f) {
838 return naturalAmount;
839 }
840 final int minimizeDistance = stack.getMinimizeDistance();
841 float startPrime = mService.mAppTransition.getLastClipRevealMaxTranslation()
842 / (float) minimizeDistance;
843 final float amountPrime = t * mAnimationTarget + (1 - t) * startPrime;
844 final float t2 = Math.min(t / mMaximizeMeetFraction, 1);
845 return amountPrime * t2 + naturalAmount * (1 - t2);
846 }
847
848 /**
849 * Retrieves the animation fraction at which the docked stack has to meet the clip reveal
850 * edge. See {@link #adjustMaximizeAmount}.
851 */
852 private float getClipRevealMeetFraction(TaskStack stack) {
853 if (!isAnimationMaximizing() || stack == null ||
854 !mService.mAppTransition.hadClipRevealAnimation()) {
855 return 1f;
856 }
857 final int minimizeDistance = stack.getMinimizeDistance();
858 final float fraction = Math.abs(mService.mAppTransition.getLastClipRevealMaxTranslation())
859 / (float) minimizeDistance;
860 final float t = Math.max(0, Math.min(1, (fraction - CLIP_REVEAL_MEET_FRACTION_MIN)
861 / (CLIP_REVEAL_MEET_FRACTION_MAX - CLIP_REVEAL_MEET_FRACTION_MIN)));
862 return CLIP_REVEAL_MEET_EARLIEST
863 + (1 - t) * (CLIP_REVEAL_MEET_LAST - CLIP_REVEAL_MEET_EARLIEST);
864 }
865
Jorim Jaggi50981592015-12-29 17:54:12 +0100866 @Override
Wale Ogunwale29bfbb82016-05-12 15:13:52 -0700867 public boolean dimFullscreen() {
Jorim Jaggi50981592015-12-29 17:54:12 +0100868 return false;
869 }
870
871 @Override
872 public DisplayInfo getDisplayInfo() {
873 return mDisplayContent.getDisplayInfo();
874 }
875
876 @Override
Wale Ogunwalef0a60a92017-01-19 09:44:40 -0800877 public boolean isAttachedToDisplay() {
878 return mDisplayContent != null;
879 }
880
881 @Override
Jorim Jaggi50981592015-12-29 17:54:12 +0100882 public void getDimBounds(Rect outBounds) {
883 // This dim layer user doesn't need this.
884 }
885
886 @Override
887 public String toShortString() {
888 return TAG;
889 }
Robert Carre63e01a2016-04-18 20:27:34 -0700890
891 WindowState getWindow() {
892 return mWindow;
893 }
Jorim Jaggi31f71702016-05-04 16:43:04 -0700894
895 void dump(String prefix, PrintWriter pw) {
896 pw.println(prefix + "DockedStackDividerController");
897 pw.println(prefix + " mLastVisibility=" + mLastVisibility);
898 pw.println(prefix + " mMinimizedDock=" + mMinimizedDock);
899 pw.println(prefix + " mAdjustedForIme=" + mAdjustedForIme);
900 pw.println(prefix + " mAdjustedForDivider=" + mAdjustedForDivider);
901 if (mDimLayer.isDimming()) {
902 pw.println(prefix + " Dim layer is dimming: ");
903 mDimLayer.printTo(prefix + " ", pw);
904 }
905 }
Robert Carre63e01a2016-04-18 20:27:34 -0700906}