blob: c56f6b86aa164717aac0e1dcd2a93cad1ed7413e [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;
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100105 private boolean mResizing;
106 private WindowState mWindow;
107 private final Rect mTmpRect = new Rect();
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800108 private final Rect mTmpRect2 = new Rect();
Jorim Jaggi85639432016-05-06 17:27:55 -0700109 private final Rect mTmpRect3 = new Rect();
Filip Gruszczynski77049052015-11-09 14:01:21 -0800110 private final Rect mLastRect = new Rect();
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800111 private boolean mLastVisibility = false;
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100112 private final RemoteCallbackList<IDockedStackListener> mDockedStackListeners
113 = new RemoteCallbackList<>();
Jorim Jaggi50981592015-12-29 17:54:12 +0100114 private final DimLayer mDimLayer;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700115
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800116 private boolean mMinimizedDock;
Chong Zhangbaba7832016-03-24 10:21:26 -0700117 private boolean mAnimatingForMinimizedDockedStack;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800118 private boolean mAnimationStarted;
119 private long mAnimationStartTime;
120 private float mAnimationStart;
121 private float mAnimationTarget;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800122 private long mAnimationDuration;
Jorim Jaggiff71d202016-04-14 13:12:36 -0700123 private boolean mAnimationStartDelayed;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800124 private final Interpolator mMinimizedDockInterpolator;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800125 private float mMaximizeMeetFraction;
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100126 private final Rect mTouchRegion = new Rect();
Chong Zhangbaba7832016-03-24 10:21:26 -0700127 private boolean mAnimatingForIme;
128 private boolean mAdjustedForIme;
Keisuke Kuroyanagi19d9a8f2016-05-12 16:49:02 -0700129 private int mImeHeight;
Jorim Jaggiff71d202016-04-14 13:12:36 -0700130 private WindowState mDelayedImeWin;
Chong Zhangf347ab52016-04-18 21:02:01 -0700131 private boolean mAdjustedForDivider;
132 private float mDividerAnimationStart;
133 private float mDividerAnimationTarget;
Wale Ogunwale10124582016-09-15 20:25:50 -0700134 float mLastAnimationProgress;
135 float mLastDividerProgress;
Jorim Jaggi85639432016-05-06 17:27:55 -0700136 private final DividerSnapAlgorithm[] mSnapAlgorithmForRotation = new DividerSnapAlgorithm[4];
Jorim Jaggi3c5d0f12016-05-24 19:04:30 -0700137 private boolean mImeHideRequested;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800138
139 DockedStackDividerController(WindowManagerService service, DisplayContent displayContent) {
140 mService = service;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700141 mDisplayContent = displayContent;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800142 final Context context = service.mContext;
Jorim Jaggibc5425c2016-03-01 13:51:16 +0100143 mDimLayer = new DimLayer(displayContent.mService, this, displayContent.getDisplayId(),
144 "DockedStackDim");
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800145 mMinimizedDockInterpolator = AnimationUtils.loadInterpolator(
146 context, android.R.interpolator.fast_out_slow_in);
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700147 loadDimens();
148 }
149
Jorim Jaggi85639432016-05-06 17:27:55 -0700150 int getSmallestWidthDpForBounds(Rect bounds) {
151 final DisplayInfo di = mDisplayContent.getDisplayInfo();
152
153 // If the bounds are fullscreen, return the value of the fullscreen configuration
154 if (bounds == null || (bounds.left == 0 && bounds.top == 0
155 && bounds.right == di.logicalWidth && bounds.bottom == di.logicalHeight)) {
Andrii Kulian441e4492016-09-29 15:25:00 -0700156 return mDisplayContent.getConfiguration().smallestScreenWidthDp;
Jorim Jaggi85639432016-05-06 17:27:55 -0700157 }
158 final int baseDisplayWidth = mDisplayContent.mBaseDisplayWidth;
159 final int baseDisplayHeight = mDisplayContent.mBaseDisplayHeight;
160 int minWidth = Integer.MAX_VALUE;
161
162 // Go through all screen orientations and find the orientation in which the task has the
163 // smallest width.
164 for (int rotation = 0; rotation < 4; rotation++) {
165 mTmpRect.set(bounds);
166 mDisplayContent.rotateBounds(di.rotation, rotation, mTmpRect);
167 final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
168 mTmpRect2.set(0, 0,
169 rotated ? baseDisplayHeight : baseDisplayWidth,
170 rotated ? baseDisplayWidth : baseDisplayHeight);
171 final int orientation = mTmpRect2.width() <= mTmpRect2.height()
172 ? ORIENTATION_PORTRAIT
173 : ORIENTATION_LANDSCAPE;
174 final int dockSide = TaskStack.getDockSideUnchecked(mTmpRect, mTmpRect2, orientation);
175 final int position = DockedDividerUtils.calculatePositionForBounds(mTmpRect, dockSide,
176 getContentWidth());
177
178 // Since we only care about feasible states, snap to the closest snap target, like it
179 // would happen when actually rotating the screen.
180 final int snappedPosition = mSnapAlgorithmForRotation[rotation]
181 .calculateNonDismissingSnapTarget(position).position;
182 DockedDividerUtils.calculateBoundsForPosition(snappedPosition, dockSide, mTmpRect,
183 mTmpRect2.width(), mTmpRect2.height(), getContentWidth());
184 mService.mPolicy.getStableInsetsLw(rotation, mTmpRect2.width(), mTmpRect2.height(),
185 mTmpRect3);
186 mService.subtractInsets(mTmpRect2, mTmpRect3, mTmpRect);
187 minWidth = Math.min(mTmpRect.width(), minWidth);
188 }
189 return (int) (minWidth / mDisplayContent.getDisplayMetrics().density);
190 }
191
192 private void initSnapAlgorithmForRotations() {
Andrii Kulian441e4492016-09-29 15:25:00 -0700193 final Configuration baseConfig = mDisplayContent.getConfiguration();
Jorim Jaggi85639432016-05-06 17:27:55 -0700194
195 // Initialize the snap algorithms for all 4 screen orientations.
196 final Configuration config = new Configuration();
197 for (int rotation = 0; rotation < 4; rotation++) {
198 final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
199 final int dw = rotated
200 ? mDisplayContent.mBaseDisplayHeight
201 : mDisplayContent.mBaseDisplayWidth;
202 final int dh = rotated
203 ? mDisplayContent.mBaseDisplayWidth
204 : mDisplayContent.mBaseDisplayHeight;
205 mService.mPolicy.getStableInsetsLw(rotation, dw, dh, mTmpRect);
Andrii Kulianb10330d2016-09-16 13:51:46 -0700206 config.unset();
Jorim Jaggi85639432016-05-06 17:27:55 -0700207 config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
208 config.screenWidthDp = (int)
209 (mService.mPolicy.getConfigDisplayWidth(dw, dh, rotation, baseConfig.uiMode) /
210 mDisplayContent.getDisplayMetrics().density);
211 config.screenHeightDp = (int)
212 (mService.mPolicy.getConfigDisplayHeight(dw, dh, rotation, baseConfig.uiMode) /
213 mDisplayContent.getDisplayMetrics().density);
214 final Context rotationContext = mService.mContext.createConfigurationContext(config);
215 mSnapAlgorithmForRotation[rotation] = new DividerSnapAlgorithm(
216 rotationContext.getResources(), dw, dh, getContentWidth(),
217 config.orientation == ORIENTATION_PORTRAIT, mTmpRect);
218 }
219 }
220
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700221 private void loadDimens() {
222 final Context context = mService.mContext;
223 mDividerWindowWidth = context.getResources().getDimensionPixelSize(
224 com.android.internal.R.dimen.docked_stack_divider_thickness);
225 mDividerInsets = context.getResources().getDimensionPixelSize(
226 com.android.internal.R.dimen.docked_stack_divider_insets);
Chong Zhang198afac2016-04-15 12:03:11 -0700227 mDividerWindowWidthInactive = WindowManagerService.dipToPixel(
228 DIVIDER_WIDTH_INACTIVE_DP, mDisplayContent.getDisplayMetrics());
Jorim Jaggi85639432016-05-06 17:27:55 -0700229 initSnapAlgorithmForRotations();
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700230 }
231
232 void onConfigurationChanged() {
233 loadDimens();
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700234 }
235
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100236 boolean isResizing() {
237 return mResizing;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700238 }
239
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100240 int getContentWidth() {
241 return mDividerWindowWidth - 2 * mDividerInsets;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700242 }
243
Jorim Jaggi81ba11e2016-02-03 22:04:22 -0800244 int getContentInsets() {
245 return mDividerInsets;
246 }
247
Chong Zhang198afac2016-04-15 12:03:11 -0700248 int getContentWidthInactive() {
249 return mDividerWindowWidthInactive;
250 }
251
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100252 void setResizing(boolean resizing) {
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800253 if (mResizing != resizing) {
254 mResizing = resizing;
255 resetDragResizingChangeReported();
256 }
257 }
258
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100259 void setTouchRegion(Rect touchRegion) {
260 mTouchRegion.set(touchRegion);
261 }
262
263 void getTouchRegion(Rect outRegion) {
264 outRegion.set(mTouchRegion);
265 outRegion.offset(mWindow.getFrameLw().left, mWindow.getFrameLw().top);
266 }
267
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800268 private void resetDragResizingChangeReported() {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800269 mDisplayContent.forAllWindows(WindowState::resetDragResizingChangeReported,
270 true /* traverseTopToBottom */ );
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100271 }
272
273 void setWindow(WindowState window) {
274 mWindow = window;
Filip Gruszczynski85d5cc42015-12-04 09:21:37 -0800275 reevaluateVisibility(false);
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100276 }
277
Filip Gruszczynski85d5cc42015-12-04 09:21:37 -0800278 void reevaluateVisibility(boolean force) {
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800279 if (mWindow == null) {
280 return;
281 }
Jorim Jaggife762342016-10-13 14:33:27 +0200282 TaskStack stack = mDisplayContent.getDockedStackIgnoringVisibility();
Jorim Jaggi7998e482016-02-12 18:47:06 -0800283
284 // If the stack is invisible, we policy force hide it in WindowAnimator.shouldForceHide
285 final boolean visible = stack != null;
Filip Gruszczynski85d5cc42015-12-04 09:21:37 -0800286 if (mLastVisibility == visible && !force) {
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800287 return;
288 }
289 mLastVisibility = visible;
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100290 notifyDockedDividerVisibilityChanged(visible);
Jorim Jaggi50981592015-12-29 17:54:12 +0100291 if (!visible) {
292 setResizeDimLayer(false, INVALID_STACK_ID, 0f);
293 }
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100294 }
295
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700296 private boolean wasVisible() {
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100297 return mLastVisibility;
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100298 }
299
Chong Zhangf347ab52016-04-18 21:02:01 -0700300 void setAdjustedForIme(
301 boolean adjustedForIme, boolean adjustedForDivider,
Keisuke Kuroyanagi19d9a8f2016-05-12 16:49:02 -0700302 boolean animate, WindowState imeWin, int imeHeight) {
303 if (mAdjustedForIme != adjustedForIme || (adjustedForIme && mImeHeight != imeHeight)
304 || mAdjustedForDivider != adjustedForDivider) {
Jorim Jaggi3070e772016-05-17 16:41:32 -0700305 if (animate && !mAnimatingForMinimizedDockedStack) {
Chong Zhangf347ab52016-04-18 21:02:01 -0700306 startImeAdjustAnimation(adjustedForIme, adjustedForDivider, imeWin);
Jorim Jaggiff71d202016-04-14 13:12:36 -0700307 } else {
Jorim Jaggiff71d202016-04-14 13:12:36 -0700308 // Animation might be delayed, so only notify if we don't run an animation.
Chong Zhangf347ab52016-04-18 21:02:01 -0700309 notifyAdjustedForImeChanged(adjustedForIme || adjustedForDivider, 0 /* duration */);
Jorim Jaggieb88d832016-04-13 20:17:43 -0700310 }
Chong Zhangf347ab52016-04-18 21:02:01 -0700311 mAdjustedForIme = adjustedForIme;
Keisuke Kuroyanagi19d9a8f2016-05-12 16:49:02 -0700312 mImeHeight = imeHeight;
Chong Zhangf347ab52016-04-18 21:02:01 -0700313 mAdjustedForDivider = adjustedForDivider;
Chong Zhangbaba7832016-03-24 10:21:26 -0700314 }
Chong Zhangb58bbcc2016-03-23 11:57:36 -0700315 }
316
Keisuke Kuroyanagi19d9a8f2016-05-12 16:49:02 -0700317 int getImeHeightAdjustedFor() {
318 return mImeHeight;
319 }
320
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700321 void positionDockedStackedDivider(Rect frame) {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700322 TaskStack stack = mDisplayContent.getDockedStackLocked();
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700323 if (stack == null) {
324 // Unfortunately we might end up with still having a divider, even though the underlying
325 // stack was already removed. This is because we are on AM thread and the removal of the
Filip Gruszczynski77049052015-11-09 14:01:21 -0800326 // divider was deferred to WM thread and hasn't happened yet. In that case let's just
327 // keep putting it in the same place it was before the stack was removed to have
328 // continuity and prevent it from jumping to the center. It will get hidden soon.
329 frame.set(mLastRect);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700330 return;
Filip Gruszczynski77049052015-11-09 14:01:21 -0800331 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800332 stack.getDimBounds(mTmpRect);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700333 }
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100334 int side = stack.getDockSide();
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700335 switch (side) {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700336 case DOCKED_LEFT:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100337 frame.set(mTmpRect.right - mDividerInsets, frame.top,
338 mTmpRect.right + frame.width() - mDividerInsets, frame.bottom);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700339 break;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700340 case DOCKED_TOP:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100341 frame.set(frame.left, mTmpRect.bottom - mDividerInsets,
342 mTmpRect.right, mTmpRect.bottom + frame.height() - mDividerInsets);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700343 break;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700344 case DOCKED_RIGHT:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100345 frame.set(mTmpRect.left - frame.width() + mDividerInsets, frame.top,
346 mTmpRect.left + mDividerInsets, frame.bottom);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700347 break;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700348 case DOCKED_BOTTOM:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100349 frame.set(frame.left, mTmpRect.top - frame.height() + mDividerInsets,
350 frame.right, mTmpRect.top + mDividerInsets);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700351 break;
352 }
Filip Gruszczynski77049052015-11-09 14:01:21 -0800353 mLastRect.set(frame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700354 }
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800355
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700356 private void notifyDockedDividerVisibilityChanged(boolean visible) {
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100357 final int size = mDockedStackListeners.beginBroadcast();
358 for (int i = 0; i < size; ++i) {
359 final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i);
360 try {
361 listener.onDividerVisibilityChanged(visible);
362 } catch (RemoteException e) {
363 Slog.e(TAG_WM, "Error delivering divider visibility changed event.", e);
364 }
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800365 }
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100366 mDockedStackListeners.finishBroadcast();
367 }
368
369 void notifyDockedStackExistsChanged(boolean exists) {
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700370 // TODO(multi-display): Perform all actions only for current display.
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100371 final int size = mDockedStackListeners.beginBroadcast();
372 for (int i = 0; i < size; ++i) {
373 final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i);
374 try {
375 listener.onDockedStackExistsChanged(exists);
376 } catch (RemoteException e) {
377 Slog.e(TAG_WM, "Error delivering docked stack exists changed event.", e);
378 }
379 }
380 mDockedStackListeners.finishBroadcast();
Jorim Jaggi3c5d0f12016-05-24 19:04:30 -0700381 if (exists) {
382 InputMethodManagerInternal inputMethodManagerInternal =
383 LocalServices.getService(InputMethodManagerInternal.class);
384 if (inputMethodManagerInternal != null) {
385
386 // Hide the current IME to avoid problems with animations from IME adjustment when
387 // attaching the docked stack.
388 inputMethodManagerInternal.hideCurrentInputMethod();
389 mImeHideRequested = true;
390 }
Chong Zhang22eff0a2016-07-01 14:48:11 -0700391 } else if (setMinimizedDockedStack(false)) {
392 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggief92d6f2016-03-25 22:07:16 -0700393 }
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100394 }
395
Jorim Jaggi3c5d0f12016-05-24 19:04:30 -0700396 /**
397 * Resets the state that IME hide has been requested. See {@link #isImeHideRequested}.
398 */
399 void resetImeHideRequested() {
400 mImeHideRequested = false;
401 }
402
403 /**
404 * The docked stack divider controller makes sure the IME gets hidden when attaching the docked
405 * stack, to avoid animation problems. This flag indicates whether the request to hide the IME
406 * has been sent in an asynchronous manner, and the IME should be treated as hidden already.
407 *
408 * @return whether IME hide request has been sent
409 */
410 boolean isImeHideRequested() {
411 return mImeHideRequested;
412 }
413
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700414 private void notifyDockedStackMinimizedChanged(boolean minimizedDock, long animDuration) {
Tony Mak853304c2016-04-18 15:17:41 +0100415 mService.mH.removeMessages(NOTIFY_DOCKED_STACK_MINIMIZED_CHANGED);
416 mService.mH.obtainMessage(NOTIFY_DOCKED_STACK_MINIMIZED_CHANGED,
417 minimizedDock ? 1 : 0, 0).sendToTarget();
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800418 final int size = mDockedStackListeners.beginBroadcast();
419 for (int i = 0; i < size; ++i) {
420 final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i);
421 try {
422 listener.onDockedStackMinimizedChanged(minimizedDock, animDuration);
423 } catch (RemoteException e) {
424 Slog.e(TAG_WM, "Error delivering minimized dock changed event.", e);
425 }
426 }
427 mDockedStackListeners.finishBroadcast();
428 }
429
Jorim Jaggi2917dc42016-04-11 11:39:13 -0700430 void notifyDockSideChanged(int newDockSide) {
431 final int size = mDockedStackListeners.beginBroadcast();
432 for (int i = 0; i < size; ++i) {
433 final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i);
434 try {
435 listener.onDockSideChanged(newDockSide);
436 } catch (RemoteException e) {
437 Slog.e(TAG_WM, "Error delivering dock side changed event.", e);
438 }
439 }
440 mDockedStackListeners.finishBroadcast();
441 }
442
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700443 private void notifyAdjustedForImeChanged(boolean adjustedForIme, long animDuration) {
Jorim Jaggi698e7632016-04-13 21:02:22 -0700444 final int size = mDockedStackListeners.beginBroadcast();
445 for (int i = 0; i < size; ++i) {
446 final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i);
447 try {
448 listener.onAdjustedForImeChanged(adjustedForIme, animDuration);
449 } catch (RemoteException e) {
450 Slog.e(TAG_WM, "Error delivering adjusted for ime changed event.", e);
451 }
452 }
453 mDockedStackListeners.finishBroadcast();
454 }
455
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100456 void registerDockedStackListener(IDockedStackListener listener) {
457 mDockedStackListeners.register(listener);
458 notifyDockedDividerVisibilityChanged(wasVisible());
459 notifyDockedStackExistsChanged(
460 mDisplayContent.mService.mStackIdToStack.get(DOCKED_STACK_ID) != null);
Jorim Jaggief92d6f2016-03-25 22:07:16 -0700461 notifyDockedStackMinimizedChanged(mMinimizedDock, 0 /* animDuration */);
Jorim Jaggi698e7632016-04-13 21:02:22 -0700462 notifyAdjustedForImeChanged(mAdjustedForIme, 0 /* animDuration */);
463
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800464 }
Jorim Jaggi50981592015-12-29 17:54:12 +0100465
466 void setResizeDimLayer(boolean visible, int targetStackId, float alpha) {
Robert Carr68e5c9e2016-09-14 10:50:09 -0700467 mService.openSurfaceTransaction();
Jorim Jaggibc5425c2016-03-01 13:51:16 +0100468 final TaskStack stack = mDisplayContent.mService.mStackIdToStack.get(targetStackId);
469 final TaskStack dockedStack = mDisplayContent.getDockedStackLocked();
470 boolean visibleAndValid = visible && stack != null && dockedStack != null;
Jorim Jaggi7b371dd2016-01-05 15:32:34 +0100471 if (visibleAndValid) {
Jorim Jaggi50981592015-12-29 17:54:12 +0100472 stack.getDimBounds(mTmpRect);
Jorim Jaggi10b89dc2016-01-05 15:40:17 +0100473 if (mTmpRect.height() > 0 && mTmpRect.width() > 0) {
Jorim Jaggi7b371dd2016-01-05 15:32:34 +0100474 mDimLayer.setBounds(mTmpRect);
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700475 mDimLayer.show(getResizeDimLayer(), alpha, 0 /* duration */);
Jorim Jaggi7b371dd2016-01-05 15:32:34 +0100476 } else {
477 visibleAndValid = false;
478 }
479 }
480 if (!visibleAndValid) {
Jorim Jaggi50981592015-12-29 17:54:12 +0100481 mDimLayer.hide();
482 }
Robert Carr68e5c9e2016-09-14 10:50:09 -0700483 mService.closeSurfaceTransaction();
Jorim Jaggi50981592015-12-29 17:54:12 +0100484 }
485
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800486 /**
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700487 * @return The layer used for dimming the apps when dismissing docked/fullscreen stack. Just
488 * above all application surfaces.
489 */
490 private int getResizeDimLayer() {
491 return (mWindow != null) ? mWindow.mLayer - 1 : LAYER_OFFSET_DIM;
492 }
493
494 /**
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800495 * Notifies the docked stack divider controller of a visibility change that happens without
496 * an animation.
497 */
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700498 void notifyAppVisibilityChanged() {
499 checkMinimizeChanged(false /* animate */);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800500 }
501
Jorim Jaggi84afb1a2016-09-28 14:54:04 +0200502 void notifyAppTransitionStarting(ArraySet<AppWindowToken> openingApps, int appTransition) {
Jorim Jaggi936aaeb2016-08-26 19:02:11 -0700503 final boolean wasMinimized = mMinimizedDock;
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700504 checkMinimizeChanged(true /* animate */);
Jorim Jaggi936aaeb2016-08-26 19:02:11 -0700505
506 // We were minimized, and now we are still minimized, but somebody is trying to launch an
507 // app in docked stack, better show recent apps so we actually get unminimized! This catches
508 // any case that was missed in ActivityStarter.postStartActivityUncheckedProcessing because
509 // we couldn't retrace the launch of the app in the docked stack to the launch from
510 // homescreen.
Jorim Jaggi84afb1a2016-09-28 14:54:04 +0200511 if (wasMinimized && mMinimizedDock && containsAppInDockedStack(openingApps)
512 && appTransition != TRANSIT_NONE) {
Jorim Jaggi936aaeb2016-08-26 19:02:11 -0700513 mService.showRecentApps(true /* fromHome */);
514 }
515 }
516
517 /**
518 * @return true if {@param apps} contains an activity in the docked stack, false otherwise.
519 */
520 private boolean containsAppInDockedStack(ArraySet<AppWindowToken> apps) {
521 for (int i = apps.size() - 1; i >= 0; i--) {
522 final AppWindowToken token = apps.valueAt(i);
523 if (token.mTask != null && token.mTask.mStack.mStackId == DOCKED_STACK_ID) {
524 return true;
525 }
526 }
527 return false;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800528 }
529
Jorim Jaggi1ae68bf2016-05-09 18:44:34 -0700530 boolean isMinimizedDock() {
531 return mMinimizedDock;
532 }
533
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700534 private void checkMinimizeChanged(boolean animate) {
Jorim Jaggife762342016-10-13 14:33:27 +0200535 if (mDisplayContent.getDockedStackIgnoringVisibility() == null) {
Jorim Jaggi817a5242016-05-06 15:45:00 -0700536 return;
537 }
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700538 final TaskStack homeStack = mDisplayContent.getHomeStack();
539 if (homeStack == null) {
540 return;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800541 }
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700542 final Task homeTask = homeStack.findHomeTask();
543 if (homeTask == null || !isWithinDisplay(homeTask)) {
544 return;
545 }
546 final TaskStack fullscreenStack
547 = mService.mStackIdToStack.get(FULLSCREEN_WORKSPACE_STACK_ID);
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700548 final boolean homeVisible = homeTask.getTopVisibleAppToken() != null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700549 final boolean homeBehind = (fullscreenStack != null && fullscreenStack.isVisible())
Wale Ogunwale15ead902016-09-02 14:30:11 -0700550 || (homeStack.hasMultipleTaskWithHomeTaskNotTop());
Jiaquan He9bc01a82016-07-08 10:29:38 -0700551 // If the home task is an on-top launcher, we don't want to minimize the docked stack.
552 // Instead we want everything underneath that was visible to remain visible.
553 // See android.R.attr#onTopLauncher.
Wale Ogunwale15ead902016-09-02 14:30:11 -0700554 final boolean isOnTopLauncher = homeStack.topTaskIsOnTopLauncher();
Jiaquan He9bc01a82016-07-08 10:29:38 -0700555 setMinimizedDockedStack(homeVisible && !homeBehind && !isOnTopLauncher, animate);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800556 }
557
558 private boolean isWithinDisplay(Task task) {
559 task.mStack.getBounds(mTmpRect);
560 mDisplayContent.getLogicalDisplayRect(mTmpRect2);
561 return mTmpRect.intersect(mTmpRect2);
562 }
563
564 /**
565 * Sets whether the docked stack is currently in a minimized state, i.e. all the tasks in the
566 * docked stack are heavily clipped so you can only see a minimal peek state.
567 *
568 * @param minimizedDock Whether the docked stack is currently minimized.
569 * @param animate Whether to animate the change.
570 */
571 private void setMinimizedDockedStack(boolean minimizedDock, boolean animate) {
Jorim Jaggief92d6f2016-03-25 22:07:16 -0700572 final boolean wasMinimized = mMinimizedDock;
573 mMinimizedDock = minimizedDock;
Jorim Jaggi817a5242016-05-06 15:45:00 -0700574 if (minimizedDock == wasMinimized) {
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800575 return;
576 }
577
Chong Zhang22eff0a2016-07-01 14:48:11 -0700578 final boolean imeChanged = clearImeAdjustAnimation();
579 boolean minimizedChange = false;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800580 if (minimizedDock) {
581 if (animate) {
582 startAdjustAnimation(0f, 1f);
583 } else {
Chong Zhang22eff0a2016-07-01 14:48:11 -0700584 minimizedChange |= setMinimizedDockedStack(true);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800585 }
586 } else {
587 if (animate) {
588 startAdjustAnimation(1f, 0f);
589 } else {
Chong Zhang22eff0a2016-07-01 14:48:11 -0700590 minimizedChange |= setMinimizedDockedStack(false);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800591 }
592 }
Chong Zhang22eff0a2016-07-01 14:48:11 -0700593 if (imeChanged || minimizedChange) {
594 if (imeChanged && !minimizedChange) {
595 Slog.d(TAG, "setMinimizedDockedStack: IME adjust changed due to minimizing,"
596 + " minimizedDock=" + minimizedDock
597 + " minimizedChange=" + minimizedChange);
598 }
599 mService.mWindowPlacerLocked.performSurfacePlacement();
600 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800601 }
602
Chong Zhang22eff0a2016-07-01 14:48:11 -0700603 private boolean clearImeAdjustAnimation() {
Wale Ogunwale10124582016-09-15 20:25:50 -0700604 final boolean changed = mDisplayContent.clearImeAdjustAnimation();
Jorim Jaggieb88d832016-04-13 20:17:43 -0700605 mAnimatingForIme = false;
Chong Zhang22eff0a2016-07-01 14:48:11 -0700606 return changed;
Jorim Jaggieb88d832016-04-13 20:17:43 -0700607 }
608
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800609 private void startAdjustAnimation(float from, float to) {
Chong Zhangbaba7832016-03-24 10:21:26 -0700610 mAnimatingForMinimizedDockedStack = true;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800611 mAnimationStarted = false;
612 mAnimationStart = from;
613 mAnimationTarget = to;
614 }
615
Chong Zhangf347ab52016-04-18 21:02:01 -0700616 private void startImeAdjustAnimation(
617 boolean adjustedForIme, boolean adjustedForDivider, WindowState imeWin) {
Chong Zhangf347ab52016-04-18 21:02:01 -0700618
619 // If we're not in an animation, the starting point depends on whether we're adjusted
620 // or not. If we're already in an animation, we start from where the current animation
621 // left off, so that the motion doesn't look discontinuous.
622 if (!mAnimatingForIme) {
623 mAnimationStart = mAdjustedForIme ? 1 : 0;
624 mDividerAnimationStart = mAdjustedForDivider ? 1 : 0;
625 mLastAnimationProgress = mAnimationStart;
626 mLastDividerProgress = mDividerAnimationStart;
627 } else {
628 mAnimationStart = mLastAnimationProgress;
629 mDividerAnimationStart = mLastDividerProgress;
630 }
Jorim Jaggi3070e772016-05-17 16:41:32 -0700631 mAnimatingForIme = true;
632 mAnimationStarted = false;
Chong Zhangf347ab52016-04-18 21:02:01 -0700633 mAnimationTarget = adjustedForIme ? 1 : 0;
634 mDividerAnimationTarget = adjustedForDivider ? 1 : 0;
Jorim Jaggiff71d202016-04-14 13:12:36 -0700635
Wale Ogunwale10124582016-09-15 20:25:50 -0700636 mDisplayContent.beginImeAdjustAnimation();
Jorim Jaggiff71d202016-04-14 13:12:36 -0700637
638 // We put all tasks into drag resizing mode - wait until all of them have completed the
639 // drag resizing switch.
640 if (!mService.mWaitingForDrawn.isEmpty()) {
641 mService.mH.removeMessages(H.WAITING_FOR_DRAWN_TIMEOUT);
642 mService.mH.sendEmptyMessageDelayed(H.WAITING_FOR_DRAWN_TIMEOUT,
643 IME_ADJUST_DRAWN_TIMEOUT);
644 mAnimationStartDelayed = true;
645 if (imeWin != null) {
646
647 // There might be an old window delaying the animation start - clear it.
648 if (mDelayedImeWin != null) {
649 mDelayedImeWin.mWinAnimator.endDelayingAnimationStart();
650 }
651 mDelayedImeWin = imeWin;
652 imeWin.mWinAnimator.startDelayingAnimationStart();
653 }
Jorim Jaggi31883862016-11-04 15:45:30 -0700654
655 // If we are already waiting for something to be drawn, clear out the old one so it
656 // still gets executed.
657 // TODO: Have a real system where we can wait on different windows to be drawn with
658 // different callbacks.
659 if (mService.mWaitingForDrawnCallback != null) {
660 mService.mWaitingForDrawnCallback.run();
661 }
Jorim Jaggiff71d202016-04-14 13:12:36 -0700662 mService.mWaitingForDrawnCallback = () -> {
663 mAnimationStartDelayed = false;
664 if (mDelayedImeWin != null) {
665 mDelayedImeWin.mWinAnimator.endDelayingAnimationStart();
666 }
Chong Zhang22eff0a2016-07-01 14:48:11 -0700667 // If the adjust status changed since this was posted, only notify
668 // the new states and don't animate.
669 long duration = 0;
670 if (mAdjustedForIme == adjustedForIme
671 && mAdjustedForDivider == adjustedForDivider) {
672 duration = IME_ADJUST_ANIM_DURATION;
673 } else {
674 Slog.w(TAG, "IME adjust changed while waiting for drawn:"
675 + " adjustedForIme=" + adjustedForIme
676 + " adjustedForDivider=" + adjustedForDivider
677 + " mAdjustedForIme=" + mAdjustedForIme
678 + " mAdjustedForDivider=" + mAdjustedForDivider);
679 }
Chong Zhangf347ab52016-04-18 21:02:01 -0700680 notifyAdjustedForImeChanged(
Chong Zhang22eff0a2016-07-01 14:48:11 -0700681 mAdjustedForIme || mAdjustedForDivider, duration);
Jorim Jaggiff71d202016-04-14 13:12:36 -0700682 };
683 } else {
Chong Zhangf347ab52016-04-18 21:02:01 -0700684 notifyAdjustedForImeChanged(
685 adjustedForIme || adjustedForDivider, IME_ADJUST_ANIM_DURATION);
Jorim Jaggiff71d202016-04-14 13:12:36 -0700686 }
Jorim Jaggieb88d832016-04-13 20:17:43 -0700687 }
688
Chong Zhang22eff0a2016-07-01 14:48:11 -0700689 private boolean setMinimizedDockedStack(boolean minimized) {
Jorim Jaggife762342016-10-13 14:33:27 +0200690 final TaskStack stack = mDisplayContent.getDockedStackIgnoringVisibility();
Jorim Jaggief92d6f2016-03-25 22:07:16 -0700691 notifyDockedStackMinimizedChanged(minimized, 0);
Chong Zhang22eff0a2016-07-01 14:48:11 -0700692 return stack != null && stack.setAdjustedForMinimizedDock(minimized ? 1f : 0f);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800693 }
694
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800695 private boolean isAnimationMaximizing() {
696 return mAnimationTarget == 0f;
697 }
698
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800699 public boolean animate(long now) {
Wale Ogunwale20ec11b2016-04-22 12:11:51 -0700700 if (mWindow == null) {
701 return false;
702 }
Chong Zhangbaba7832016-03-24 10:21:26 -0700703 if (mAnimatingForMinimizedDockedStack) {
704 return animateForMinimizedDockedStack(now);
705 } else if (mAnimatingForIme) {
Jorim Jaggieb88d832016-04-13 20:17:43 -0700706 return animateForIme(now);
Chong Zhangbaba7832016-03-24 10:21:26 -0700707 } else {
Wale Ogunwale20ec11b2016-04-22 12:11:51 -0700708 if (mDimLayer != null && mDimLayer.isDimming()) {
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700709 mDimLayer.setLayer(getResizeDimLayer());
Chong Zhang1402c2e2016-04-21 15:17:47 -0700710 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800711 return false;
712 }
Chong Zhangbaba7832016-03-24 10:21:26 -0700713 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800714
Jorim Jaggieb88d832016-04-13 20:17:43 -0700715 private boolean animateForIme(long now) {
Jorim Jaggiff71d202016-04-14 13:12:36 -0700716 if (!mAnimationStarted || mAnimationStartDelayed) {
Jorim Jaggieb88d832016-04-13 20:17:43 -0700717 mAnimationStarted = true;
718 mAnimationStartTime = now;
719 mAnimationDuration = (long)
Jorim Jaggi698e7632016-04-13 21:02:22 -0700720 (IME_ADJUST_ANIM_DURATION * mService.getWindowAnimationScaleLocked());
Jorim Jaggieb88d832016-04-13 20:17:43 -0700721 }
722 float t = Math.min(1f, (float) (now - mAnimationStartTime) / mAnimationDuration);
723 t = (mAnimationTarget == 1f ? IME_ADJUST_ENTRY_INTERPOLATOR : TOUCH_RESPONSE_INTERPOLATOR)
724 .getInterpolation(t);
Wale Ogunwale10124582016-09-15 20:25:50 -0700725 final boolean updated =
726 mDisplayContent.animateForIme(t, mAnimationTarget, mDividerAnimationTarget);
Jorim Jaggieb88d832016-04-13 20:17:43 -0700727 if (updated) {
728 mService.mWindowPlacerLocked.performSurfacePlacement();
729 }
730 if (t >= 1.0f) {
Chong Zhangf347ab52016-04-18 21:02:01 -0700731 mLastAnimationProgress = mAnimationTarget;
732 mLastDividerProgress = mDividerAnimationTarget;
Jorim Jaggieb88d832016-04-13 20:17:43 -0700733 mAnimatingForIme = false;
734 return false;
735 } else {
736 return true;
737 }
Chong Zhangbaba7832016-03-24 10:21:26 -0700738 }
739
740 private boolean animateForMinimizedDockedStack(long now) {
Jorim Jaggiaf558e12016-04-27 22:56:56 -0700741 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800742 if (!mAnimationStarted) {
743 mAnimationStarted = true;
744 mAnimationStartTime = now;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800745 final long transitionDuration = isAnimationMaximizing()
746 ? mService.mAppTransition.getLastClipRevealTransitionDuration()
747 : DEFAULT_APP_TRANSITION_DURATION;
748 mAnimationDuration = (long)
749 (transitionDuration * mService.getTransitionAnimationScaleLocked());
Jorim Jaggif97ed922016-02-18 18:57:07 -0800750 mMaximizeMeetFraction = getClipRevealMeetFraction(stack);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800751 notifyDockedStackMinimizedChanged(mMinimizedDock,
Jorim Jaggif97ed922016-02-18 18:57:07 -0800752 (long) (mAnimationDuration * mMaximizeMeetFraction));
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800753 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800754 float t = Math.min(1f, (float) (now - mAnimationStartTime) / mAnimationDuration);
755 t = (isAnimationMaximizing() ? TOUCH_RESPONSE_INTERPOLATOR : mMinimizedDockInterpolator)
756 .getInterpolation(t);
Chong Zhang741c0ba2016-05-27 12:52:11 -0700757 if (stack != null) {
758 if (stack.setAdjustedForMinimizedDock(getMinimizeAmount(stack, t))) {
759 mService.mWindowPlacerLocked.performSurfacePlacement();
760 }
761 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800762 if (t >= 1.0f) {
Chong Zhangbaba7832016-03-24 10:21:26 -0700763 mAnimatingForMinimizedDockedStack = false;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800764 return false;
765 } else {
766 return true;
767 }
768 }
769
Wale Ogunwale10124582016-09-15 20:25:50 -0700770 float getInterpolatedAnimationValue(float t) {
Jorim Jaggieb88d832016-04-13 20:17:43 -0700771 return t * mAnimationTarget + (1 - t) * mAnimationStart;
772 }
773
Wale Ogunwale10124582016-09-15 20:25:50 -0700774 float getInterpolatedDividerValue(float t) {
Chong Zhangf347ab52016-04-18 21:02:01 -0700775 return t * mDividerAnimationTarget + (1 - t) * mDividerAnimationStart;
776 }
777
Jorim Jaggif97ed922016-02-18 18:57:07 -0800778 /**
779 * Gets the amount how much to minimize a stack depending on the interpolated fraction t.
780 */
781 private float getMinimizeAmount(TaskStack stack, float t) {
Jorim Jaggieb88d832016-04-13 20:17:43 -0700782 final float naturalAmount = getInterpolatedAnimationValue(t);
Jorim Jaggif97ed922016-02-18 18:57:07 -0800783 if (isAnimationMaximizing()) {
784 return adjustMaximizeAmount(stack, t, naturalAmount);
785 } else {
786 return naturalAmount;
787 }
788 }
789
790 /**
791 * When maximizing the stack during a clip reveal transition, this adjusts the minimize amount
792 * during the transition such that the edge of the clip reveal rect is met earlier in the
793 * transition so we don't create a visible "hole", but only if both the clip reveal and the
794 * docked stack divider start from about the same portion on the screen.
795 */
796 private float adjustMaximizeAmount(TaskStack stack, float t, float naturalAmount) {
797 if (mMaximizeMeetFraction == 1f) {
798 return naturalAmount;
799 }
800 final int minimizeDistance = stack.getMinimizeDistance();
801 float startPrime = mService.mAppTransition.getLastClipRevealMaxTranslation()
802 / (float) minimizeDistance;
803 final float amountPrime = t * mAnimationTarget + (1 - t) * startPrime;
804 final float t2 = Math.min(t / mMaximizeMeetFraction, 1);
805 return amountPrime * t2 + naturalAmount * (1 - t2);
806 }
807
808 /**
809 * Retrieves the animation fraction at which the docked stack has to meet the clip reveal
810 * edge. See {@link #adjustMaximizeAmount}.
811 */
812 private float getClipRevealMeetFraction(TaskStack stack) {
813 if (!isAnimationMaximizing() || stack == null ||
814 !mService.mAppTransition.hadClipRevealAnimation()) {
815 return 1f;
816 }
817 final int minimizeDistance = stack.getMinimizeDistance();
818 final float fraction = Math.abs(mService.mAppTransition.getLastClipRevealMaxTranslation())
819 / (float) minimizeDistance;
820 final float t = Math.max(0, Math.min(1, (fraction - CLIP_REVEAL_MEET_FRACTION_MIN)
821 / (CLIP_REVEAL_MEET_FRACTION_MAX - CLIP_REVEAL_MEET_FRACTION_MIN)));
822 return CLIP_REVEAL_MEET_EARLIEST
823 + (1 - t) * (CLIP_REVEAL_MEET_LAST - CLIP_REVEAL_MEET_EARLIEST);
824 }
825
Jorim Jaggi50981592015-12-29 17:54:12 +0100826 @Override
Wale Ogunwale29bfbb82016-05-12 15:13:52 -0700827 public boolean dimFullscreen() {
Jorim Jaggi50981592015-12-29 17:54:12 +0100828 return false;
829 }
830
831 @Override
832 public DisplayInfo getDisplayInfo() {
833 return mDisplayContent.getDisplayInfo();
834 }
835
836 @Override
837 public void getDimBounds(Rect outBounds) {
838 // This dim layer user doesn't need this.
839 }
840
841 @Override
842 public String toShortString() {
843 return TAG;
844 }
Robert Carre63e01a2016-04-18 20:27:34 -0700845
846 WindowState getWindow() {
847 return mWindow;
848 }
Jorim Jaggi31f71702016-05-04 16:43:04 -0700849
850 void dump(String prefix, PrintWriter pw) {
851 pw.println(prefix + "DockedStackDividerController");
852 pw.println(prefix + " mLastVisibility=" + mLastVisibility);
853 pw.println(prefix + " mMinimizedDock=" + mMinimizedDock);
854 pw.println(prefix + " mAdjustedForIme=" + mAdjustedForIme);
855 pw.println(prefix + " mAdjustedForDivider=" + mAdjustedForDivider);
856 if (mDimLayer.isDimming()) {
857 pw.println(prefix + " Dim layer is dimming: ");
858 mDimLayer.printTo(prefix + " ", pw);
859 }
860 }
Robert Carre63e01a2016-04-18 20:27:34 -0700861}