Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.wm; |
| 18 | |
Wale Ogunwale | b62139d | 2017-09-20 15:37:35 -0700 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 20 | import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 21 | import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; |
| 22 | import static android.content.res.Configuration.ORIENTATION_PORTRAIT; |
| 23 | import static android.view.Surface.ROTATION_270; |
| 24 | import static android.view.Surface.ROTATION_90; |
Jorim Jaggi | bc5425c | 2016-03-01 13:51:16 +0100 | [diff] [blame] | 25 | import static android.view.WindowManager.DOCKED_BOTTOM; |
Matthew Ng | cb1b8e4 | 2017-10-20 16:29:23 -0700 | [diff] [blame] | 26 | import static android.view.WindowManager.DOCKED_INVALID; |
Jorim Jaggi | bc5425c | 2016-03-01 13:51:16 +0100 | [diff] [blame] | 27 | import static android.view.WindowManager.DOCKED_LEFT; |
| 28 | import static android.view.WindowManager.DOCKED_RIGHT; |
| 29 | import static android.view.WindowManager.DOCKED_TOP; |
| 30 | import static com.android.server.wm.AppTransition.DEFAULT_APP_TRANSITION_DURATION; |
| 31 | import static com.android.server.wm.AppTransition.TOUCH_RESPONSE_INTERPOLATOR; |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 32 | import static android.view.WindowManager.TRANSIT_NONE; |
Jorim Jaggi | bc5425c | 2016-03-01 13:51:16 +0100 | [diff] [blame] | 33 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 34 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 35 | import static com.android.server.wm.WindowManagerService.H.NOTIFY_DOCKED_STACK_MINIMIZED_CHANGED; |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 36 | import static com.android.server.wm.WindowManagerService.LAYER_OFFSET_DIM; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 37 | import static com.android.server.wm.DockedStackDividerControllerProto.MINIMIZED_DOCK; |
Jorim Jaggi | bc5425c | 2016-03-01 13:51:16 +0100 | [diff] [blame] | 38 | |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 39 | import android.content.Context; |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 40 | import android.content.res.Configuration; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 41 | import android.graphics.Rect; |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 42 | import android.os.RemoteCallbackList; |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 43 | import android.os.RemoteException; |
Jorim Jaggi | 936aaeb | 2016-08-26 19:02:11 -0700 | [diff] [blame] | 44 | import android.util.ArraySet; |
Filip Gruszczynski | 7704905 | 2015-11-09 14:01:21 -0800 | [diff] [blame] | 45 | import android.util.Slog; |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 46 | import android.util.proto.ProtoOutputStream; |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 47 | import android.view.DisplayCutout; |
Jorim Jaggi | 5098159 | 2015-12-29 17:54:12 +0100 | [diff] [blame] | 48 | import android.view.DisplayInfo; |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 49 | import android.view.IDockedStackListener; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 50 | import android.view.animation.AnimationUtils; |
| 51 | import android.view.animation.Interpolator; |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 52 | import android.view.animation.PathInterpolator; |
Jorim Jaggi | 3c5d0f1 | 2016-05-24 19:04:30 -0700 | [diff] [blame] | 53 | import android.view.inputmethod.InputMethodManagerInternal; |
Jorim Jaggi | 5098159 | 2015-12-29 17:54:12 +0100 | [diff] [blame] | 54 | |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 55 | import com.android.internal.policy.DividerSnapAlgorithm; |
| 56 | import com.android.internal.policy.DockedDividerUtils; |
Jorim Jaggi | 3c5d0f1 | 2016-05-24 19:04:30 -0700 | [diff] [blame] | 57 | import com.android.server.LocalServices; |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 58 | import com.android.server.wm.WindowManagerService.H; |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 59 | |
Jorim Jaggi | 31f7170 | 2016-05-04 16:43:04 -0700 | [diff] [blame] | 60 | import java.io.PrintWriter; |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 61 | |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 62 | /** |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 63 | * Keeps information about the docked stack divider. |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 64 | */ |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 65 | public class DockedStackDividerController { |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 66 | |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 67 | private static final String TAG = TAG_WITH_CLASS_NAME ? "DockedStackDividerController" : TAG_WM; |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 68 | |
Jorim Jaggi | f97ed92 | 2016-02-18 18:57:07 -0800 | [diff] [blame] | 69 | /** |
| 70 | * The fraction during the maximize/clip reveal animation the divider meets the edge of the clip |
| 71 | * revealing surface at the earliest. |
| 72 | */ |
| 73 | private static final float CLIP_REVEAL_MEET_EARLIEST = 0.6f; |
| 74 | |
| 75 | /** |
| 76 | * The fraction during the maximize/clip reveal animation the divider meets the edge of the clip |
| 77 | * revealing surface at the latest. |
| 78 | */ |
| 79 | private static final float CLIP_REVEAL_MEET_LAST = 1f; |
| 80 | |
| 81 | /** |
| 82 | * If the app translates at least CLIP_REVEAL_MEET_FRACTION_MIN * minimize distance, we start |
| 83 | * meet somewhere between {@link #CLIP_REVEAL_MEET_LAST} and {@link #CLIP_REVEAL_MEET_EARLIEST}. |
| 84 | */ |
| 85 | private static final float CLIP_REVEAL_MEET_FRACTION_MIN = 0.4f; |
| 86 | |
| 87 | /** |
| 88 | * If the app translates equals or more than CLIP_REVEAL_MEET_FRACTION_MIN * minimize distance, |
| 89 | * we meet at {@link #CLIP_REVEAL_MEET_EARLIEST}. |
| 90 | */ |
| 91 | private static final float CLIP_REVEAL_MEET_FRACTION_MAX = 0.8f; |
| 92 | |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 93 | private static final Interpolator IME_ADJUST_ENTRY_INTERPOLATOR = |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 94 | new PathInterpolator(0.2f, 0f, 0.1f, 1f); |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 95 | |
Jorim Jaggi | 698e763 | 2016-04-13 21:02:22 -0700 | [diff] [blame] | 96 | private static final long IME_ADJUST_ANIM_DURATION = 280; |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 97 | |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 98 | private static final long IME_ADJUST_DRAWN_TIMEOUT = 200; |
| 99 | |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 100 | private static final int DIVIDER_WIDTH_INACTIVE_DP = 4; |
| 101 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 102 | private final WindowManagerService mService; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 103 | private final DisplayContent mDisplayContent; |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 104 | private int mDividerWindowWidth; |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 105 | private int mDividerWindowWidthInactive; |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 106 | private int mDividerInsets; |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 107 | private int mTaskHeightInMinimizedMode; |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 108 | private boolean mResizing; |
| 109 | private WindowState mWindow; |
| 110 | private final Rect mTmpRect = new Rect(); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 111 | private final Rect mTmpRect2 = new Rect(); |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 112 | private final Rect mTmpRect3 = new Rect(); |
Filip Gruszczynski | 7704905 | 2015-11-09 14:01:21 -0800 | [diff] [blame] | 113 | private final Rect mLastRect = new Rect(); |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 114 | private boolean mLastVisibility = false; |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 115 | private final RemoteCallbackList<IDockedStackListener> mDockedStackListeners |
| 116 | = new RemoteCallbackList<>(); |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 117 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 118 | private boolean mMinimizedDock; |
Matthew Ng | cb1b8e4 | 2017-10-20 16:29:23 -0700 | [diff] [blame] | 119 | private int mOriginalDockedSide = DOCKED_INVALID; |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 120 | private boolean mAnimatingForMinimizedDockedStack; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 121 | private boolean mAnimationStarted; |
| 122 | private long mAnimationStartTime; |
| 123 | private float mAnimationStart; |
| 124 | private float mAnimationTarget; |
Jorim Jaggi | 8fe7e0a | 2016-02-12 19:43:39 -0800 | [diff] [blame] | 125 | private long mAnimationDuration; |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 126 | private boolean mAnimationStartDelayed; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 127 | private final Interpolator mMinimizedDockInterpolator; |
Jorim Jaggi | f97ed92 | 2016-02-18 18:57:07 -0800 | [diff] [blame] | 128 | private float mMaximizeMeetFraction; |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 129 | private final Rect mTouchRegion = new Rect(); |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 130 | private boolean mAnimatingForIme; |
| 131 | private boolean mAdjustedForIme; |
Keisuke Kuroyanagi | 19d9a8f | 2016-05-12 16:49:02 -0700 | [diff] [blame] | 132 | private int mImeHeight; |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 133 | private WindowState mDelayedImeWin; |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 134 | private boolean mAdjustedForDivider; |
| 135 | private float mDividerAnimationStart; |
| 136 | private float mDividerAnimationTarget; |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 137 | float mLastAnimationProgress; |
| 138 | float mLastDividerProgress; |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 139 | private final DividerSnapAlgorithm[] mSnapAlgorithmForRotation = new DividerSnapAlgorithm[4]; |
Jorim Jaggi | 3c5d0f1 | 2016-05-24 19:04:30 -0700 | [diff] [blame] | 140 | private boolean mImeHideRequested; |
Jorim Jaggi | f93ac2b | 2017-10-25 15:20:24 +0200 | [diff] [blame] | 141 | private final Rect mLastDimLayerRect = new Rect(); |
| 142 | private float mLastDimLayerAlpha; |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 143 | private TaskStack mDimmedStack; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 144 | |
| 145 | DockedStackDividerController(WindowManagerService service, DisplayContent displayContent) { |
| 146 | mService = service; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 147 | mDisplayContent = displayContent; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 148 | final Context context = service.mContext; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 149 | mMinimizedDockInterpolator = AnimationUtils.loadInterpolator( |
| 150 | context, android.R.interpolator.fast_out_slow_in); |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 151 | loadDimens(); |
| 152 | } |
| 153 | |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 154 | int getSmallestWidthDpForBounds(Rect bounds) { |
| 155 | final DisplayInfo di = mDisplayContent.getDisplayInfo(); |
| 156 | |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 157 | final int baseDisplayWidth = mDisplayContent.mBaseDisplayWidth; |
| 158 | final int baseDisplayHeight = mDisplayContent.mBaseDisplayHeight; |
| 159 | int minWidth = Integer.MAX_VALUE; |
| 160 | |
| 161 | // Go through all screen orientations and find the orientation in which the task has the |
| 162 | // smallest width. |
| 163 | for (int rotation = 0; rotation < 4; rotation++) { |
| 164 | mTmpRect.set(bounds); |
| 165 | mDisplayContent.rotateBounds(di.rotation, rotation, mTmpRect); |
| 166 | final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270); |
| 167 | mTmpRect2.set(0, 0, |
| 168 | rotated ? baseDisplayHeight : baseDisplayWidth, |
| 169 | rotated ? baseDisplayWidth : baseDisplayHeight); |
| 170 | final int orientation = mTmpRect2.width() <= mTmpRect2.height() |
| 171 | ? ORIENTATION_PORTRAIT |
| 172 | : ORIENTATION_LANDSCAPE; |
Matthew Ng | 62c7846 | 2018-04-09 14:43:21 -0700 | [diff] [blame] | 173 | final int dockSide = getDockSide(mTmpRect, mTmpRect2, orientation); |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 174 | final int position = DockedDividerUtils.calculatePositionForBounds(mTmpRect, dockSide, |
| 175 | getContentWidth()); |
| 176 | |
Adrian Roos | 2aa0fcd | 2018-02-19 18:07:49 +0100 | [diff] [blame] | 177 | final DisplayCutout displayCutout = mDisplayContent.calculateDisplayCutoutForRotation( |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 178 | rotation).getDisplayCutout(); |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 179 | |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 180 | // Since we only care about feasible states, snap to the closest snap target, like it |
| 181 | // would happen when actually rotating the screen. |
| 182 | final int snappedPosition = mSnapAlgorithmForRotation[rotation] |
| 183 | .calculateNonDismissingSnapTarget(position).position; |
| 184 | DockedDividerUtils.calculateBoundsForPosition(snappedPosition, dockSide, mTmpRect, |
| 185 | mTmpRect2.width(), mTmpRect2.height(), getContentWidth()); |
| 186 | mService.mPolicy.getStableInsetsLw(rotation, mTmpRect2.width(), mTmpRect2.height(), |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 187 | displayCutout, mTmpRect3); |
Winson Chung | bdc646f | 2017-02-13 12:12:22 -0800 | [diff] [blame] | 188 | mService.intersectDisplayInsetBounds(mTmpRect2, mTmpRect3, mTmpRect); |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 189 | minWidth = Math.min(mTmpRect.width(), minWidth); |
| 190 | } |
| 191 | return (int) (minWidth / mDisplayContent.getDisplayMetrics().density); |
| 192 | } |
| 193 | |
Matthew Ng | 62c7846 | 2018-04-09 14:43:21 -0700 | [diff] [blame] | 194 | /** |
| 195 | * Get the current docked side. Determined by its location of {@param bounds} within |
| 196 | * {@param displayRect} but if both are the same, it will try to dock to each side and determine |
| 197 | * if allowed in its respected {@param orientation}. |
| 198 | * |
| 199 | * @param bounds bounds of the docked task to get which side is docked |
| 200 | * @param displayRect bounds of the display that contains the docked task |
| 201 | * @param orientation the origination of device |
| 202 | * @return current docked side |
| 203 | */ |
| 204 | int getDockSide(Rect bounds, Rect displayRect, int orientation) { |
| 205 | if (orientation == Configuration.ORIENTATION_PORTRAIT) { |
| 206 | // Portrait mode, docked either at the top or the bottom. |
| 207 | final int diff = (displayRect.bottom - bounds.bottom) - (bounds.top - displayRect.top); |
| 208 | if (diff > 0) { |
| 209 | return DOCKED_TOP; |
| 210 | } else if (diff < 0) { |
| 211 | return DOCKED_BOTTOM; |
| 212 | } |
| 213 | return canPrimaryStackDockTo(DOCKED_TOP) ? DOCKED_TOP : DOCKED_BOTTOM; |
| 214 | } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { |
| 215 | // Landscape mode, docked either on the left or on the right. |
| 216 | final int diff = (displayRect.right - bounds.right) - (bounds.left - displayRect.left); |
| 217 | if (diff > 0) { |
| 218 | return DOCKED_LEFT; |
| 219 | } else if (diff < 0) { |
| 220 | return DOCKED_RIGHT; |
| 221 | } |
| 222 | return canPrimaryStackDockTo(DOCKED_LEFT) ? DOCKED_LEFT : DOCKED_RIGHT; |
| 223 | } |
| 224 | return DOCKED_INVALID; |
| 225 | } |
| 226 | |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 227 | void getHomeStackBoundsInDockedMode(Rect outBounds) { |
| 228 | final DisplayInfo di = mDisplayContent.getDisplayInfo(); |
| 229 | mService.mPolicy.getStableInsetsLw(di.rotation, di.logicalWidth, di.logicalHeight, |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 230 | di.displayCutout, mTmpRect); |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 231 | int dividerSize = mDividerWindowWidth - 2 * mDividerInsets; |
| 232 | Configuration configuration = mDisplayContent.getConfiguration(); |
Matthew Ng | a9e173d | 2017-05-17 15:03:18 -0700 | [diff] [blame] | 233 | // The offset in the left (landscape)/top (portrait) is calculated with the minimized |
| 234 | // offset value with the divider size and any system insets in that direction. |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 235 | if (configuration.orientation == Configuration.ORIENTATION_PORTRAIT) { |
| 236 | outBounds.set(0, mTaskHeightInMinimizedMode + dividerSize + mTmpRect.top, |
| 237 | di.logicalWidth, di.logicalHeight); |
| 238 | } else { |
Matthew Ng | 62c7846 | 2018-04-09 14:43:21 -0700 | [diff] [blame] | 239 | // In landscape also inset the left/right side with the statusbar height to match the |
Matthew Ng | a9e173d | 2017-05-17 15:03:18 -0700 | [diff] [blame] | 240 | // minimized size height in portrait mode. |
Matthew Ng | 62c7846 | 2018-04-09 14:43:21 -0700 | [diff] [blame] | 241 | final TaskStack stack = mDisplayContent.getSplitScreenPrimaryStackIgnoringVisibility(); |
| 242 | final int primaryTaskWidth = mTaskHeightInMinimizedMode + dividerSize + mTmpRect.top; |
| 243 | int left = mTmpRect.left; |
| 244 | int right = di.logicalWidth - mTmpRect.right; |
| 245 | if (stack != null) { |
| 246 | if (stack.getDockSide() == DOCKED_LEFT) { |
| 247 | left += primaryTaskWidth; |
| 248 | } else if (stack.getDockSide() == DOCKED_RIGHT) { |
| 249 | right -= primaryTaskWidth; |
| 250 | } |
| 251 | } |
| 252 | outBounds.set(left, 0, right, di.logicalHeight); |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 253 | } |
| 254 | } |
| 255 | |
| 256 | boolean isHomeStackResizable() { |
| 257 | final TaskStack homeStack = mDisplayContent.getHomeStack(); |
| 258 | if (homeStack == null) { |
| 259 | return false; |
| 260 | } |
| 261 | final Task homeTask = homeStack.findHomeTask(); |
| 262 | return homeTask != null && homeTask.isResizeable(); |
| 263 | } |
| 264 | |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 265 | private void initSnapAlgorithmForRotations() { |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 266 | final Configuration baseConfig = mDisplayContent.getConfiguration(); |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 267 | |
| 268 | // Initialize the snap algorithms for all 4 screen orientations. |
| 269 | final Configuration config = new Configuration(); |
| 270 | for (int rotation = 0; rotation < 4; rotation++) { |
| 271 | final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270); |
| 272 | final int dw = rotated |
| 273 | ? mDisplayContent.mBaseDisplayHeight |
| 274 | : mDisplayContent.mBaseDisplayWidth; |
| 275 | final int dh = rotated |
| 276 | ? mDisplayContent.mBaseDisplayWidth |
| 277 | : mDisplayContent.mBaseDisplayHeight; |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 278 | final DisplayCutout displayCutout = |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 279 | mDisplayContent.calculateDisplayCutoutForRotation(rotation).getDisplayCutout(); |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 280 | mService.mPolicy.getStableInsetsLw(rotation, dw, dh, displayCutout, mTmpRect); |
Andrii Kulian | b10330d | 2016-09-16 13:51:46 -0700 | [diff] [blame] | 281 | config.unset(); |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 282 | config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE; |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 283 | |
| 284 | final int displayId = mDisplayContent.getDisplayId(); |
| 285 | final int appWidth = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 286 | baseConfig.uiMode, displayId, displayCutout); |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 287 | final int appHeight = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation, |
Adrian Roos | bed538e | 2018-02-21 17:50:07 +0100 | [diff] [blame] | 288 | baseConfig.uiMode, displayId, displayCutout); |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 289 | mService.mPolicy.getNonDecorInsetsLw(rotation, dw, dh, displayCutout, mTmpRect); |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 290 | final int leftInset = mTmpRect.left; |
| 291 | final int topInset = mTmpRect.top; |
| 292 | |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 293 | config.windowConfiguration.setAppBounds(leftInset /*left*/, topInset /*top*/, |
| 294 | leftInset + appWidth /*right*/, topInset + appHeight /*bottom*/); |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 295 | |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 296 | final float density = mDisplayContent.getDisplayMetrics().density; |
| 297 | config.screenWidthDp = (int) (mService.mPolicy.getConfigDisplayWidth(dw, dh, |
| 298 | rotation, baseConfig.uiMode, displayId, displayCutout) / density); |
| 299 | config.screenHeightDp = (int) (mService.mPolicy.getConfigDisplayHeight(dw, dh, |
| 300 | rotation, baseConfig.uiMode, displayId, displayCutout) / density); |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 301 | final Context rotationContext = mService.mContext.createConfigurationContext(config); |
| 302 | mSnapAlgorithmForRotation[rotation] = new DividerSnapAlgorithm( |
| 303 | rotationContext.getResources(), dw, dh, getContentWidth(), |
| 304 | config.orientation == ORIENTATION_PORTRAIT, mTmpRect); |
| 305 | } |
| 306 | } |
| 307 | |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 308 | private void loadDimens() { |
| 309 | final Context context = mService.mContext; |
| 310 | mDividerWindowWidth = context.getResources().getDimensionPixelSize( |
| 311 | com.android.internal.R.dimen.docked_stack_divider_thickness); |
| 312 | mDividerInsets = context.getResources().getDimensionPixelSize( |
| 313 | com.android.internal.R.dimen.docked_stack_divider_insets); |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 314 | mDividerWindowWidthInactive = WindowManagerService.dipToPixel( |
| 315 | DIVIDER_WIDTH_INACTIVE_DP, mDisplayContent.getDisplayMetrics()); |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 316 | mTaskHeightInMinimizedMode = context.getResources().getDimensionPixelSize( |
| 317 | com.android.internal.R.dimen.task_height_of_minimized_mode); |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 318 | initSnapAlgorithmForRotations(); |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | void onConfigurationChanged() { |
| 322 | loadDimens(); |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 323 | } |
| 324 | |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 325 | boolean isResizing() { |
| 326 | return mResizing; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 329 | int getContentWidth() { |
| 330 | return mDividerWindowWidth - 2 * mDividerInsets; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 331 | } |
| 332 | |
Jorim Jaggi | 81ba11e | 2016-02-03 22:04:22 -0800 | [diff] [blame] | 333 | int getContentInsets() { |
| 334 | return mDividerInsets; |
| 335 | } |
| 336 | |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 337 | int getContentWidthInactive() { |
| 338 | return mDividerWindowWidthInactive; |
| 339 | } |
| 340 | |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 341 | void setResizing(boolean resizing) { |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 342 | if (mResizing != resizing) { |
| 343 | mResizing = resizing; |
| 344 | resetDragResizingChangeReported(); |
| 345 | } |
| 346 | } |
| 347 | |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 348 | void setTouchRegion(Rect touchRegion) { |
| 349 | mTouchRegion.set(touchRegion); |
| 350 | } |
| 351 | |
| 352 | void getTouchRegion(Rect outRegion) { |
| 353 | outRegion.set(mTouchRegion); |
| 354 | outRegion.offset(mWindow.getFrameLw().left, mWindow.getFrameLw().top); |
| 355 | } |
| 356 | |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 357 | private void resetDragResizingChangeReported() { |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 358 | mDisplayContent.forAllWindows(WindowState::resetDragResizingChangeReported, |
| 359 | true /* traverseTopToBottom */ ); |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | void setWindow(WindowState window) { |
| 363 | mWindow = window; |
Filip Gruszczynski | 85d5cc4 | 2015-12-04 09:21:37 -0800 | [diff] [blame] | 364 | reevaluateVisibility(false); |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 365 | } |
| 366 | |
Filip Gruszczynski | 85d5cc4 | 2015-12-04 09:21:37 -0800 | [diff] [blame] | 367 | void reevaluateVisibility(boolean force) { |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 368 | if (mWindow == null) { |
| 369 | return; |
| 370 | } |
Matthew Ng | 64e77cf | 2017-10-31 14:01:31 -0700 | [diff] [blame] | 371 | TaskStack stack = mDisplayContent.getSplitScreenPrimaryStackIgnoringVisibility(); |
Jorim Jaggi | 7998e48 | 2016-02-12 18:47:06 -0800 | [diff] [blame] | 372 | |
| 373 | // If the stack is invisible, we policy force hide it in WindowAnimator.shouldForceHide |
| 374 | final boolean visible = stack != null; |
Filip Gruszczynski | 85d5cc4 | 2015-12-04 09:21:37 -0800 | [diff] [blame] | 375 | if (mLastVisibility == visible && !force) { |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 376 | return; |
| 377 | } |
| 378 | mLastVisibility = visible; |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 379 | notifyDockedDividerVisibilityChanged(visible); |
Jorim Jaggi | 5098159 | 2015-12-29 17:54:12 +0100 | [diff] [blame] | 380 | if (!visible) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 381 | setResizeDimLayer(false, WINDOWING_MODE_UNDEFINED, 0f); |
Jorim Jaggi | 5098159 | 2015-12-29 17:54:12 +0100 | [diff] [blame] | 382 | } |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 383 | } |
| 384 | |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 385 | private boolean wasVisible() { |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 386 | return mLastVisibility; |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 387 | } |
| 388 | |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 389 | void setAdjustedForIme( |
| 390 | boolean adjustedForIme, boolean adjustedForDivider, |
Keisuke Kuroyanagi | 19d9a8f | 2016-05-12 16:49:02 -0700 | [diff] [blame] | 391 | boolean animate, WindowState imeWin, int imeHeight) { |
| 392 | if (mAdjustedForIme != adjustedForIme || (adjustedForIme && mImeHeight != imeHeight) |
| 393 | || mAdjustedForDivider != adjustedForDivider) { |
Jorim Jaggi | 3070e77 | 2016-05-17 16:41:32 -0700 | [diff] [blame] | 394 | if (animate && !mAnimatingForMinimizedDockedStack) { |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 395 | startImeAdjustAnimation(adjustedForIme, adjustedForDivider, imeWin); |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 396 | } else { |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 397 | // Animation might be delayed, so only notify if we don't run an animation. |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 398 | notifyAdjustedForImeChanged(adjustedForIme || adjustedForDivider, 0 /* duration */); |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 399 | } |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 400 | mAdjustedForIme = adjustedForIme; |
Keisuke Kuroyanagi | 19d9a8f | 2016-05-12 16:49:02 -0700 | [diff] [blame] | 401 | mImeHeight = imeHeight; |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 402 | mAdjustedForDivider = adjustedForDivider; |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 403 | } |
Chong Zhang | b58bbcc | 2016-03-23 11:57:36 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Keisuke Kuroyanagi | 19d9a8f | 2016-05-12 16:49:02 -0700 | [diff] [blame] | 406 | int getImeHeightAdjustedFor() { |
| 407 | return mImeHeight; |
| 408 | } |
| 409 | |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 410 | void positionDockedStackedDivider(Rect frame) { |
Matthew Ng | 0808af3 | 2018-05-07 12:11:13 -0700 | [diff] [blame] | 411 | TaskStack stack = mDisplayContent.getSplitScreenPrimaryStackIgnoringVisibility(); |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 412 | if (stack == null) { |
| 413 | // Unfortunately we might end up with still having a divider, even though the underlying |
| 414 | // stack was already removed. This is because we are on AM thread and the removal of the |
Filip Gruszczynski | 7704905 | 2015-11-09 14:01:21 -0800 | [diff] [blame] | 415 | // divider was deferred to WM thread and hasn't happened yet. In that case let's just |
| 416 | // keep putting it in the same place it was before the stack was removed to have |
| 417 | // continuity and prevent it from jumping to the center. It will get hidden soon. |
| 418 | frame.set(mLastRect); |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 419 | return; |
Filip Gruszczynski | 7704905 | 2015-11-09 14:01:21 -0800 | [diff] [blame] | 420 | } else { |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 421 | stack.getDimBounds(mTmpRect); |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 422 | } |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 423 | int side = stack.getDockSide(); |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 424 | switch (side) { |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 425 | case DOCKED_LEFT: |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 426 | frame.set(mTmpRect.right - mDividerInsets, frame.top, |
| 427 | mTmpRect.right + frame.width() - mDividerInsets, frame.bottom); |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 428 | break; |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 429 | case DOCKED_TOP: |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 430 | frame.set(frame.left, mTmpRect.bottom - mDividerInsets, |
| 431 | mTmpRect.right, mTmpRect.bottom + frame.height() - mDividerInsets); |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 432 | break; |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 433 | case DOCKED_RIGHT: |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 434 | frame.set(mTmpRect.left - frame.width() + mDividerInsets, frame.top, |
| 435 | mTmpRect.left + mDividerInsets, frame.bottom); |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 436 | break; |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 437 | case DOCKED_BOTTOM: |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 438 | frame.set(frame.left, mTmpRect.top - frame.height() + mDividerInsets, |
| 439 | frame.right, mTmpRect.top + mDividerInsets); |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 440 | break; |
| 441 | } |
Filip Gruszczynski | 7704905 | 2015-11-09 14:01:21 -0800 | [diff] [blame] | 442 | mLastRect.set(frame); |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 443 | } |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 444 | |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 445 | private void notifyDockedDividerVisibilityChanged(boolean visible) { |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 446 | final int size = mDockedStackListeners.beginBroadcast(); |
| 447 | for (int i = 0; i < size; ++i) { |
| 448 | final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i); |
| 449 | try { |
| 450 | listener.onDividerVisibilityChanged(visible); |
| 451 | } catch (RemoteException e) { |
| 452 | Slog.e(TAG_WM, "Error delivering divider visibility changed event.", e); |
| 453 | } |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 454 | } |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 455 | mDockedStackListeners.finishBroadcast(); |
| 456 | } |
| 457 | |
Matthew Ng | cb1b8e4 | 2017-10-20 16:29:23 -0700 | [diff] [blame] | 458 | /** |
| 459 | * Checks if the primary stack is allowed to dock to a specific side based on its original dock |
| 460 | * side. |
| 461 | * |
| 462 | * @param dockSide the side to see if it is valid |
| 463 | * @return true if the side provided is valid |
| 464 | */ |
| 465 | boolean canPrimaryStackDockTo(int dockSide) { |
Matthew Ng | 62c7846 | 2018-04-09 14:43:21 -0700 | [diff] [blame] | 466 | final DisplayInfo di = mDisplayContent.getDisplayInfo(); |
| 467 | return mService.mPolicy.isDockSideAllowed(dockSide, mOriginalDockedSide, di.logicalWidth, |
| 468 | di.logicalHeight, di.rotation); |
Matthew Ng | cb1b8e4 | 2017-10-20 16:29:23 -0700 | [diff] [blame] | 469 | } |
| 470 | |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 471 | void notifyDockedStackExistsChanged(boolean exists) { |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 472 | // TODO(multi-display): Perform all actions only for current display. |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 473 | final int size = mDockedStackListeners.beginBroadcast(); |
| 474 | for (int i = 0; i < size; ++i) { |
| 475 | final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i); |
| 476 | try { |
| 477 | listener.onDockedStackExistsChanged(exists); |
| 478 | } catch (RemoteException e) { |
| 479 | Slog.e(TAG_WM, "Error delivering docked stack exists changed event.", e); |
| 480 | } |
| 481 | } |
| 482 | mDockedStackListeners.finishBroadcast(); |
Jorim Jaggi | 3c5d0f1 | 2016-05-24 19:04:30 -0700 | [diff] [blame] | 483 | if (exists) { |
| 484 | InputMethodManagerInternal inputMethodManagerInternal = |
| 485 | LocalServices.getService(InputMethodManagerInternal.class); |
| 486 | if (inputMethodManagerInternal != null) { |
| 487 | |
| 488 | // Hide the current IME to avoid problems with animations from IME adjustment when |
| 489 | // attaching the docked stack. |
| 490 | inputMethodManagerInternal.hideCurrentInputMethod(); |
| 491 | mImeHideRequested = true; |
| 492 | } |
Matthew Ng | e8b052a | 2018-01-16 14:33:47 -0800 | [diff] [blame] | 493 | |
| 494 | // If a primary stack was just created, it will not have access to display content at |
| 495 | // this point so pass it from here to get a valid dock side. |
Matthew Ng | cb1b8e4 | 2017-10-20 16:29:23 -0700 | [diff] [blame] | 496 | final TaskStack stack = mDisplayContent.getSplitScreenPrimaryStackIgnoringVisibility(); |
Matthew Ng | e8b052a | 2018-01-16 14:33:47 -0800 | [diff] [blame] | 497 | mOriginalDockedSide = stack.getDockSideForDisplay(mDisplayContent); |
Matthew Ng | bc527a3 | 2017-06-19 16:42:31 -0700 | [diff] [blame] | 498 | return; |
Jorim Jaggi | ef92d6f | 2016-03-25 22:07:16 -0700 | [diff] [blame] | 499 | } |
Matthew Ng | cb1b8e4 | 2017-10-20 16:29:23 -0700 | [diff] [blame] | 500 | mOriginalDockedSide = DOCKED_INVALID; |
Matthew Ng | bc527a3 | 2017-06-19 16:42:31 -0700 | [diff] [blame] | 501 | setMinimizedDockedStack(false /* minimizedDock */, false /* animate */); |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 502 | |
| 503 | if (mDimmedStack != null) { |
| 504 | mDimmedStack.stopDimming(); |
| 505 | mDimmedStack = null; |
| 506 | } |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 507 | } |
| 508 | |
Jorim Jaggi | 3c5d0f1 | 2016-05-24 19:04:30 -0700 | [diff] [blame] | 509 | /** |
| 510 | * Resets the state that IME hide has been requested. See {@link #isImeHideRequested}. |
| 511 | */ |
| 512 | void resetImeHideRequested() { |
| 513 | mImeHideRequested = false; |
| 514 | } |
| 515 | |
| 516 | /** |
| 517 | * The docked stack divider controller makes sure the IME gets hidden when attaching the docked |
| 518 | * stack, to avoid animation problems. This flag indicates whether the request to hide the IME |
| 519 | * has been sent in an asynchronous manner, and the IME should be treated as hidden already. |
| 520 | * |
| 521 | * @return whether IME hide request has been sent |
| 522 | */ |
| 523 | boolean isImeHideRequested() { |
| 524 | return mImeHideRequested; |
| 525 | } |
| 526 | |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 527 | private void notifyDockedStackMinimizedChanged(boolean minimizedDock, boolean animate, |
| 528 | boolean isHomeStackResizable) { |
| 529 | long animDuration = 0; |
| 530 | if (animate) { |
Wale Ogunwale | b62139d | 2017-09-20 15:37:35 -0700 | [diff] [blame] | 531 | final TaskStack stack = |
Matthew Ng | 64e77cf | 2017-10-31 14:01:31 -0700 | [diff] [blame] | 532 | mDisplayContent.getSplitScreenPrimaryStackIgnoringVisibility(); |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 533 | final long transitionDuration = isAnimationMaximizing() |
| 534 | ? mService.mAppTransition.getLastClipRevealTransitionDuration() |
| 535 | : DEFAULT_APP_TRANSITION_DURATION; |
| 536 | mAnimationDuration = (long) |
| 537 | (transitionDuration * mService.getTransitionAnimationScaleLocked()); |
| 538 | mMaximizeMeetFraction = getClipRevealMeetFraction(stack); |
| 539 | animDuration = (long) (mAnimationDuration * mMaximizeMeetFraction); |
| 540 | } |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 541 | mService.mH.removeMessages(NOTIFY_DOCKED_STACK_MINIMIZED_CHANGED); |
| 542 | mService.mH.obtainMessage(NOTIFY_DOCKED_STACK_MINIMIZED_CHANGED, |
| 543 | minimizedDock ? 1 : 0, 0).sendToTarget(); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 544 | final int size = mDockedStackListeners.beginBroadcast(); |
| 545 | for (int i = 0; i < size; ++i) { |
| 546 | final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i); |
| 547 | try { |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 548 | listener.onDockedStackMinimizedChanged(minimizedDock, animDuration, |
| 549 | isHomeStackResizable); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 550 | } catch (RemoteException e) { |
| 551 | Slog.e(TAG_WM, "Error delivering minimized dock changed event.", e); |
| 552 | } |
| 553 | } |
| 554 | mDockedStackListeners.finishBroadcast(); |
| 555 | } |
| 556 | |
Jorim Jaggi | 2917dc4 | 2016-04-11 11:39:13 -0700 | [diff] [blame] | 557 | void notifyDockSideChanged(int newDockSide) { |
| 558 | final int size = mDockedStackListeners.beginBroadcast(); |
| 559 | for (int i = 0; i < size; ++i) { |
| 560 | final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i); |
| 561 | try { |
| 562 | listener.onDockSideChanged(newDockSide); |
| 563 | } catch (RemoteException e) { |
| 564 | Slog.e(TAG_WM, "Error delivering dock side changed event.", e); |
| 565 | } |
| 566 | } |
| 567 | mDockedStackListeners.finishBroadcast(); |
| 568 | } |
| 569 | |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 570 | private void notifyAdjustedForImeChanged(boolean adjustedForIme, long animDuration) { |
Jorim Jaggi | 698e763 | 2016-04-13 21:02:22 -0700 | [diff] [blame] | 571 | final int size = mDockedStackListeners.beginBroadcast(); |
| 572 | for (int i = 0; i < size; ++i) { |
| 573 | final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i); |
| 574 | try { |
| 575 | listener.onAdjustedForImeChanged(adjustedForIme, animDuration); |
| 576 | } catch (RemoteException e) { |
| 577 | Slog.e(TAG_WM, "Error delivering adjusted for ime changed event.", e); |
| 578 | } |
| 579 | } |
| 580 | mDockedStackListeners.finishBroadcast(); |
| 581 | } |
| 582 | |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 583 | void registerDockedStackListener(IDockedStackListener listener) { |
| 584 | mDockedStackListeners.register(listener); |
| 585 | notifyDockedDividerVisibilityChanged(wasVisible()); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 586 | notifyDockedStackExistsChanged( |
Matthew Ng | 64e77cf | 2017-10-31 14:01:31 -0700 | [diff] [blame] | 587 | mDisplayContent.getSplitScreenPrimaryStackIgnoringVisibility() != null); |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 588 | notifyDockedStackMinimizedChanged(mMinimizedDock, false /* animate */, |
| 589 | isHomeStackResizable()); |
Jorim Jaggi | 698e763 | 2016-04-13 21:02:22 -0700 | [diff] [blame] | 590 | notifyAdjustedForImeChanged(mAdjustedForIme, 0 /* animDuration */); |
| 591 | |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 592 | } |
Jorim Jaggi | 5098159 | 2015-12-29 17:54:12 +0100 | [diff] [blame] | 593 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 594 | /** |
| 595 | * Shows a dim layer with {@param alpha} if {@param visible} is true and |
| 596 | * {@param targetWindowingMode} isn't |
| 597 | * {@link android.app.WindowConfiguration#WINDOWING_MODE_UNDEFINED} and there is a stack on the |
| 598 | * display in that windowing mode. |
| 599 | */ |
| 600 | void setResizeDimLayer(boolean visible, int targetWindowingMode, float alpha) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 601 | // TODO: Maybe only allow split-screen windowing modes? |
| 602 | final TaskStack stack = targetWindowingMode != WINDOWING_MODE_UNDEFINED |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 603 | ? mDisplayContent.getTopStackInWindowingMode(targetWindowingMode) |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 604 | : null; |
Matthew Ng | 64e77cf | 2017-10-31 14:01:31 -0700 | [diff] [blame] | 605 | final TaskStack dockedStack = mDisplayContent.getSplitScreenPrimaryStack(); |
Jorim Jaggi | bc5425c | 2016-03-01 13:51:16 +0100 | [diff] [blame] | 606 | boolean visibleAndValid = visible && stack != null && dockedStack != null; |
chaviw | 783729c | 2018-01-25 15:14:10 -0800 | [diff] [blame] | 607 | |
| 608 | // Ensure an old dim that was shown for the docked stack divider is removed so we don't end |
| 609 | // up with dim layers that can no longer be removed. |
| 610 | if (mDimmedStack != null && mDimmedStack != stack) { |
| 611 | mDimmedStack.stopDimming(); |
| 612 | mDimmedStack = null; |
| 613 | } |
| 614 | |
Jorim Jaggi | 7b371dd | 2016-01-05 15:32:34 +0100 | [diff] [blame] | 615 | if (visibleAndValid) { |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 616 | mDimmedStack = stack; |
| 617 | stack.dim(alpha); |
Jorim Jaggi | 7b371dd | 2016-01-05 15:32:34 +0100 | [diff] [blame] | 618 | } |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 619 | if (!visibleAndValid && stack != null) { |
| 620 | mDimmedStack = null; |
| 621 | stack.stopDimming(); |
Jorim Jaggi | 5098159 | 2015-12-29 17:54:12 +0100 | [diff] [blame] | 622 | } |
Jorim Jaggi | 5098159 | 2015-12-29 17:54:12 +0100 | [diff] [blame] | 623 | } |
| 624 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 625 | /** |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 626 | * @return The layer used for dimming the apps when dismissing docked/fullscreen stack. Just |
| 627 | * above all application surfaces. |
| 628 | */ |
| 629 | private int getResizeDimLayer() { |
| 630 | return (mWindow != null) ? mWindow.mLayer - 1 : LAYER_OFFSET_DIM; |
| 631 | } |
| 632 | |
| 633 | /** |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 634 | * Notifies the docked stack divider controller of a visibility change that happens without |
| 635 | * an animation. |
| 636 | */ |
Jorim Jaggi | d3ec507 | 2016-04-28 15:57:47 -0700 | [diff] [blame] | 637 | void notifyAppVisibilityChanged() { |
| 638 | checkMinimizeChanged(false /* animate */); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 639 | } |
| 640 | |
Jorim Jaggi | 84afb1a | 2016-09-28 14:54:04 +0200 | [diff] [blame] | 641 | void notifyAppTransitionStarting(ArraySet<AppWindowToken> openingApps, int appTransition) { |
Jorim Jaggi | 936aaeb | 2016-08-26 19:02:11 -0700 | [diff] [blame] | 642 | final boolean wasMinimized = mMinimizedDock; |
Jorim Jaggi | d3ec507 | 2016-04-28 15:57:47 -0700 | [diff] [blame] | 643 | checkMinimizeChanged(true /* animate */); |
Jorim Jaggi | 936aaeb | 2016-08-26 19:02:11 -0700 | [diff] [blame] | 644 | |
| 645 | // We were minimized, and now we are still minimized, but somebody is trying to launch an |
Matthew Ng | 8e26552 | 2017-02-13 11:09:37 -0800 | [diff] [blame] | 646 | // app in docked stack, better show recent apps so we actually get unminimized! However do |
| 647 | // not do this if keyguard is dismissed such as when the device is unlocking. This catches |
Jorim Jaggi | 936aaeb | 2016-08-26 19:02:11 -0700 | [diff] [blame] | 648 | // any case that was missed in ActivityStarter.postStartActivityUncheckedProcessing because |
| 649 | // we couldn't retrace the launch of the app in the docked stack to the launch from |
| 650 | // homescreen. |
Jorim Jaggi | 84afb1a | 2016-09-28 14:54:04 +0200 | [diff] [blame] | 651 | if (wasMinimized && mMinimizedDock && containsAppInDockedStack(openingApps) |
Matthew Ng | 8e26552 | 2017-02-13 11:09:37 -0800 | [diff] [blame] | 652 | && appTransition != TRANSIT_NONE && |
| 653 | !AppTransition.isKeyguardGoingAwayTransit(appTransition)) { |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 654 | if (mService.mAmInternal.isRecentsComponentHomeActivity(mService.mCurrentUserId)) { |
| 655 | // When the home activity is the recents component and we are already minimized, |
| 656 | // then there is nothing to do here since home is already visible |
| 657 | } else { |
| 658 | mService.showRecentApps(); |
| 659 | } |
Jorim Jaggi | 936aaeb | 2016-08-26 19:02:11 -0700 | [diff] [blame] | 660 | } |
| 661 | } |
| 662 | |
| 663 | /** |
| 664 | * @return true if {@param apps} contains an activity in the docked stack, false otherwise. |
| 665 | */ |
| 666 | private boolean containsAppInDockedStack(ArraySet<AppWindowToken> apps) { |
| 667 | for (int i = apps.size() - 1; i >= 0; i--) { |
| 668 | final AppWindowToken token = apps.valueAt(i); |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 669 | if (token.getTask() != null && token.inSplitScreenPrimaryWindowingMode()) { |
Jorim Jaggi | 936aaeb | 2016-08-26 19:02:11 -0700 | [diff] [blame] | 670 | return true; |
| 671 | } |
| 672 | } |
| 673 | return false; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 674 | } |
| 675 | |
Jorim Jaggi | 1ae68bf | 2016-05-09 18:44:34 -0700 | [diff] [blame] | 676 | boolean isMinimizedDock() { |
| 677 | return mMinimizedDock; |
| 678 | } |
| 679 | |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 680 | void checkMinimizeChanged(boolean animate) { |
Matthew Ng | 64e77cf | 2017-10-31 14:01:31 -0700 | [diff] [blame] | 681 | if (mDisplayContent.getSplitScreenPrimaryStackIgnoringVisibility() == null) { |
Jorim Jaggi | 817a524 | 2016-05-06 15:45:00 -0700 | [diff] [blame] | 682 | return; |
| 683 | } |
Jorim Jaggi | d3ec507 | 2016-04-28 15:57:47 -0700 | [diff] [blame] | 684 | final TaskStack homeStack = mDisplayContent.getHomeStack(); |
| 685 | if (homeStack == null) { |
| 686 | return; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 687 | } |
Jorim Jaggi | d3ec507 | 2016-04-28 15:57:47 -0700 | [diff] [blame] | 688 | final Task homeTask = homeStack.findHomeTask(); |
| 689 | if (homeTask == null || !isWithinDisplay(homeTask)) { |
| 690 | return; |
| 691 | } |
Matthew Ng | 8e26552 | 2017-02-13 11:09:37 -0800 | [diff] [blame] | 692 | |
| 693 | // Do not minimize when dock is already minimized while keyguard is showing and not |
| 694 | // occluded such as unlocking the screen |
Adrian Roos | b56b3c3 | 2018-05-17 17:32:26 +0200 | [diff] [blame] | 695 | if (mMinimizedDock && mService.mKeyguardOrAodShowingOnDefaultDisplay) { |
Matthew Ng | 8e26552 | 2017-02-13 11:09:37 -0800 | [diff] [blame] | 696 | return; |
| 697 | } |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 698 | final TaskStack topSecondaryStack = mDisplayContent.getTopStackInWindowingMode( |
Wale Ogunwale | b62139d | 2017-09-20 15:37:35 -0700 | [diff] [blame] | 699 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
Winson Chung | f557c3b | 2018-03-16 10:55:20 -0700 | [diff] [blame] | 700 | final RecentsAnimationController recentsAnim = mService.getRecentsAnimationController(); |
| 701 | final boolean minimizedForRecentsAnimation = recentsAnim != null && |
| 702 | recentsAnim.isSplitScreenMinimized(); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 703 | boolean homeVisible = homeTask.getTopVisibleAppToken() != null; |
| 704 | if (homeVisible && topSecondaryStack != null) { |
| 705 | // Home should only be considered visible if it is greater or equal to the top secondary |
| 706 | // stack in terms of z-order. |
| 707 | homeVisible = homeStack.compareTo(topSecondaryStack) >= 0; |
| 708 | } |
Winson Chung | f557c3b | 2018-03-16 10:55:20 -0700 | [diff] [blame] | 709 | setMinimizedDockedStack(homeVisible || minimizedForRecentsAnimation, animate); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | private boolean isWithinDisplay(Task task) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 713 | task.getBounds(mTmpRect); |
| 714 | mDisplayContent.getBounds(mTmpRect2); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 715 | return mTmpRect.intersect(mTmpRect2); |
| 716 | } |
| 717 | |
| 718 | /** |
| 719 | * Sets whether the docked stack is currently in a minimized state, i.e. all the tasks in the |
| 720 | * docked stack are heavily clipped so you can only see a minimal peek state. |
| 721 | * |
| 722 | * @param minimizedDock Whether the docked stack is currently minimized. |
| 723 | * @param animate Whether to animate the change. |
| 724 | */ |
| 725 | private void setMinimizedDockedStack(boolean minimizedDock, boolean animate) { |
Jorim Jaggi | ef92d6f | 2016-03-25 22:07:16 -0700 | [diff] [blame] | 726 | final boolean wasMinimized = mMinimizedDock; |
| 727 | mMinimizedDock = minimizedDock; |
Jorim Jaggi | 817a524 | 2016-05-06 15:45:00 -0700 | [diff] [blame] | 728 | if (minimizedDock == wasMinimized) { |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 729 | return; |
| 730 | } |
| 731 | |
Chong Zhang | 22eff0a | 2016-07-01 14:48:11 -0700 | [diff] [blame] | 732 | final boolean imeChanged = clearImeAdjustAnimation(); |
| 733 | boolean minimizedChange = false; |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 734 | if (isHomeStackResizable()) { |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 735 | notifyDockedStackMinimizedChanged(minimizedDock, animate, |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 736 | true /* isHomeStackResizable */); |
| 737 | minimizedChange = true; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 738 | } else { |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 739 | if (minimizedDock) { |
| 740 | if (animate) { |
| 741 | startAdjustAnimation(0f, 1f); |
| 742 | } else { |
| 743 | minimizedChange |= setMinimizedDockedStack(true); |
| 744 | } |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 745 | } else { |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 746 | if (animate) { |
| 747 | startAdjustAnimation(1f, 0f); |
| 748 | } else { |
| 749 | minimizedChange |= setMinimizedDockedStack(false); |
| 750 | } |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 751 | } |
| 752 | } |
Chong Zhang | 22eff0a | 2016-07-01 14:48:11 -0700 | [diff] [blame] | 753 | if (imeChanged || minimizedChange) { |
| 754 | if (imeChanged && !minimizedChange) { |
| 755 | Slog.d(TAG, "setMinimizedDockedStack: IME adjust changed due to minimizing," |
| 756 | + " minimizedDock=" + minimizedDock |
| 757 | + " minimizedChange=" + minimizedChange); |
| 758 | } |
| 759 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
| 760 | } |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 761 | } |
| 762 | |
Chong Zhang | 22eff0a | 2016-07-01 14:48:11 -0700 | [diff] [blame] | 763 | private boolean clearImeAdjustAnimation() { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 764 | final boolean changed = mDisplayContent.clearImeAdjustAnimation(); |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 765 | mAnimatingForIme = false; |
Chong Zhang | 22eff0a | 2016-07-01 14:48:11 -0700 | [diff] [blame] | 766 | return changed; |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 767 | } |
| 768 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 769 | private void startAdjustAnimation(float from, float to) { |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 770 | mAnimatingForMinimizedDockedStack = true; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 771 | mAnimationStarted = false; |
| 772 | mAnimationStart = from; |
| 773 | mAnimationTarget = to; |
| 774 | } |
| 775 | |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 776 | private void startImeAdjustAnimation( |
| 777 | boolean adjustedForIme, boolean adjustedForDivider, WindowState imeWin) { |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 778 | |
| 779 | // If we're not in an animation, the starting point depends on whether we're adjusted |
| 780 | // or not. If we're already in an animation, we start from where the current animation |
| 781 | // left off, so that the motion doesn't look discontinuous. |
| 782 | if (!mAnimatingForIme) { |
| 783 | mAnimationStart = mAdjustedForIme ? 1 : 0; |
| 784 | mDividerAnimationStart = mAdjustedForDivider ? 1 : 0; |
| 785 | mLastAnimationProgress = mAnimationStart; |
| 786 | mLastDividerProgress = mDividerAnimationStart; |
| 787 | } else { |
| 788 | mAnimationStart = mLastAnimationProgress; |
| 789 | mDividerAnimationStart = mLastDividerProgress; |
| 790 | } |
Jorim Jaggi | 3070e77 | 2016-05-17 16:41:32 -0700 | [diff] [blame] | 791 | mAnimatingForIme = true; |
| 792 | mAnimationStarted = false; |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 793 | mAnimationTarget = adjustedForIme ? 1 : 0; |
| 794 | mDividerAnimationTarget = adjustedForDivider ? 1 : 0; |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 795 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 796 | mDisplayContent.beginImeAdjustAnimation(); |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 797 | |
| 798 | // We put all tasks into drag resizing mode - wait until all of them have completed the |
| 799 | // drag resizing switch. |
| 800 | if (!mService.mWaitingForDrawn.isEmpty()) { |
| 801 | mService.mH.removeMessages(H.WAITING_FOR_DRAWN_TIMEOUT); |
| 802 | mService.mH.sendEmptyMessageDelayed(H.WAITING_FOR_DRAWN_TIMEOUT, |
| 803 | IME_ADJUST_DRAWN_TIMEOUT); |
| 804 | mAnimationStartDelayed = true; |
| 805 | if (imeWin != null) { |
| 806 | |
| 807 | // There might be an old window delaying the animation start - clear it. |
| 808 | if (mDelayedImeWin != null) { |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 809 | mDelayedImeWin.endDelayingAnimationStart(); |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 810 | } |
| 811 | mDelayedImeWin = imeWin; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 812 | imeWin.startDelayingAnimationStart(); |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 813 | } |
Jorim Jaggi | 3188386 | 2016-11-04 15:45:30 -0700 | [diff] [blame] | 814 | |
| 815 | // If we are already waiting for something to be drawn, clear out the old one so it |
| 816 | // still gets executed. |
| 817 | // TODO: Have a real system where we can wait on different windows to be drawn with |
| 818 | // different callbacks. |
| 819 | if (mService.mWaitingForDrawnCallback != null) { |
| 820 | mService.mWaitingForDrawnCallback.run(); |
| 821 | } |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 822 | mService.mWaitingForDrawnCallback = () -> { |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 823 | synchronized (mService.mWindowMap) { |
| 824 | mAnimationStartDelayed = false; |
| 825 | if (mDelayedImeWin != null) { |
| 826 | mDelayedImeWin.endDelayingAnimationStart(); |
| 827 | } |
| 828 | // If the adjust status changed since this was posted, only notify |
| 829 | // the new states and don't animate. |
| 830 | long duration = 0; |
| 831 | if (mAdjustedForIme == adjustedForIme |
| 832 | && mAdjustedForDivider == adjustedForDivider) { |
| 833 | duration = IME_ADJUST_ANIM_DURATION; |
| 834 | } else { |
| 835 | Slog.w(TAG, "IME adjust changed while waiting for drawn:" |
| 836 | + " adjustedForIme=" + adjustedForIme |
| 837 | + " adjustedForDivider=" + adjustedForDivider |
| 838 | + " mAdjustedForIme=" + mAdjustedForIme |
| 839 | + " mAdjustedForDivider=" + mAdjustedForDivider); |
| 840 | } |
| 841 | notifyAdjustedForImeChanged( |
| 842 | mAdjustedForIme || mAdjustedForDivider, duration); |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 843 | } |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 844 | }; |
| 845 | } else { |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 846 | notifyAdjustedForImeChanged( |
| 847 | adjustedForIme || adjustedForDivider, IME_ADJUST_ANIM_DURATION); |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 848 | } |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 849 | } |
| 850 | |
Chong Zhang | 22eff0a | 2016-07-01 14:48:11 -0700 | [diff] [blame] | 851 | private boolean setMinimizedDockedStack(boolean minimized) { |
Matthew Ng | 64e77cf | 2017-10-31 14:01:31 -0700 | [diff] [blame] | 852 | final TaskStack stack = mDisplayContent.getSplitScreenPrimaryStackIgnoringVisibility(); |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 853 | notifyDockedStackMinimizedChanged(minimized, false /* animate */, isHomeStackResizable()); |
Chong Zhang | 22eff0a | 2016-07-01 14:48:11 -0700 | [diff] [blame] | 854 | return stack != null && stack.setAdjustedForMinimizedDock(minimized ? 1f : 0f); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 855 | } |
| 856 | |
Jorim Jaggi | 8fe7e0a | 2016-02-12 19:43:39 -0800 | [diff] [blame] | 857 | private boolean isAnimationMaximizing() { |
| 858 | return mAnimationTarget == 0f; |
| 859 | } |
| 860 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 861 | public boolean animate(long now) { |
Wale Ogunwale | 20ec11b | 2016-04-22 12:11:51 -0700 | [diff] [blame] | 862 | if (mWindow == null) { |
| 863 | return false; |
| 864 | } |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 865 | if (mAnimatingForMinimizedDockedStack) { |
| 866 | return animateForMinimizedDockedStack(now); |
| 867 | } else if (mAnimatingForIme) { |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 868 | return animateForIme(now); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 869 | } |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 870 | return false; |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 871 | } |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 872 | |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 873 | private boolean animateForIme(long now) { |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 874 | if (!mAnimationStarted || mAnimationStartDelayed) { |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 875 | mAnimationStarted = true; |
| 876 | mAnimationStartTime = now; |
| 877 | mAnimationDuration = (long) |
Jorim Jaggi | 698e763 | 2016-04-13 21:02:22 -0700 | [diff] [blame] | 878 | (IME_ADJUST_ANIM_DURATION * mService.getWindowAnimationScaleLocked()); |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 879 | } |
| 880 | float t = Math.min(1f, (float) (now - mAnimationStartTime) / mAnimationDuration); |
| 881 | t = (mAnimationTarget == 1f ? IME_ADJUST_ENTRY_INTERPOLATOR : TOUCH_RESPONSE_INTERPOLATOR) |
| 882 | .getInterpolation(t); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 883 | final boolean updated = |
| 884 | mDisplayContent.animateForIme(t, mAnimationTarget, mDividerAnimationTarget); |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 885 | if (updated) { |
| 886 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
| 887 | } |
| 888 | if (t >= 1.0f) { |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 889 | mLastAnimationProgress = mAnimationTarget; |
| 890 | mLastDividerProgress = mDividerAnimationTarget; |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 891 | mAnimatingForIme = false; |
| 892 | return false; |
| 893 | } else { |
| 894 | return true; |
| 895 | } |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | private boolean animateForMinimizedDockedStack(long now) { |
Matthew Ng | 64e77cf | 2017-10-31 14:01:31 -0700 | [diff] [blame] | 899 | final TaskStack stack = mDisplayContent.getSplitScreenPrimaryStackIgnoringVisibility(); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 900 | if (!mAnimationStarted) { |
| 901 | mAnimationStarted = true; |
| 902 | mAnimationStartTime = now; |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 903 | notifyDockedStackMinimizedChanged(mMinimizedDock, true /* animate */, |
| 904 | isHomeStackResizable() /* isHomeStackResizable */); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 905 | } |
Jorim Jaggi | 8fe7e0a | 2016-02-12 19:43:39 -0800 | [diff] [blame] | 906 | float t = Math.min(1f, (float) (now - mAnimationStartTime) / mAnimationDuration); |
| 907 | t = (isAnimationMaximizing() ? TOUCH_RESPONSE_INTERPOLATOR : mMinimizedDockInterpolator) |
| 908 | .getInterpolation(t); |
Chong Zhang | 741c0ba | 2016-05-27 12:52:11 -0700 | [diff] [blame] | 909 | if (stack != null) { |
| 910 | if (stack.setAdjustedForMinimizedDock(getMinimizeAmount(stack, t))) { |
| 911 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
| 912 | } |
| 913 | } |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 914 | if (t >= 1.0f) { |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 915 | mAnimatingForMinimizedDockedStack = false; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 916 | return false; |
| 917 | } else { |
| 918 | return true; |
| 919 | } |
| 920 | } |
| 921 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 922 | float getInterpolatedAnimationValue(float t) { |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 923 | return t * mAnimationTarget + (1 - t) * mAnimationStart; |
| 924 | } |
| 925 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 926 | float getInterpolatedDividerValue(float t) { |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 927 | return t * mDividerAnimationTarget + (1 - t) * mDividerAnimationStart; |
| 928 | } |
| 929 | |
Jorim Jaggi | f97ed92 | 2016-02-18 18:57:07 -0800 | [diff] [blame] | 930 | /** |
| 931 | * Gets the amount how much to minimize a stack depending on the interpolated fraction t. |
| 932 | */ |
| 933 | private float getMinimizeAmount(TaskStack stack, float t) { |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 934 | final float naturalAmount = getInterpolatedAnimationValue(t); |
Jorim Jaggi | f97ed92 | 2016-02-18 18:57:07 -0800 | [diff] [blame] | 935 | if (isAnimationMaximizing()) { |
| 936 | return adjustMaximizeAmount(stack, t, naturalAmount); |
| 937 | } else { |
| 938 | return naturalAmount; |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | /** |
| 943 | * When maximizing the stack during a clip reveal transition, this adjusts the minimize amount |
| 944 | * during the transition such that the edge of the clip reveal rect is met earlier in the |
| 945 | * transition so we don't create a visible "hole", but only if both the clip reveal and the |
| 946 | * docked stack divider start from about the same portion on the screen. |
| 947 | */ |
| 948 | private float adjustMaximizeAmount(TaskStack stack, float t, float naturalAmount) { |
| 949 | if (mMaximizeMeetFraction == 1f) { |
| 950 | return naturalAmount; |
| 951 | } |
| 952 | final int minimizeDistance = stack.getMinimizeDistance(); |
| 953 | float startPrime = mService.mAppTransition.getLastClipRevealMaxTranslation() |
| 954 | / (float) minimizeDistance; |
| 955 | final float amountPrime = t * mAnimationTarget + (1 - t) * startPrime; |
| 956 | final float t2 = Math.min(t / mMaximizeMeetFraction, 1); |
| 957 | return amountPrime * t2 + naturalAmount * (1 - t2); |
| 958 | } |
| 959 | |
| 960 | /** |
| 961 | * Retrieves the animation fraction at which the docked stack has to meet the clip reveal |
| 962 | * edge. See {@link #adjustMaximizeAmount}. |
| 963 | */ |
| 964 | private float getClipRevealMeetFraction(TaskStack stack) { |
| 965 | if (!isAnimationMaximizing() || stack == null || |
| 966 | !mService.mAppTransition.hadClipRevealAnimation()) { |
| 967 | return 1f; |
| 968 | } |
| 969 | final int minimizeDistance = stack.getMinimizeDistance(); |
| 970 | final float fraction = Math.abs(mService.mAppTransition.getLastClipRevealMaxTranslation()) |
| 971 | / (float) minimizeDistance; |
| 972 | final float t = Math.max(0, Math.min(1, (fraction - CLIP_REVEAL_MEET_FRACTION_MIN) |
| 973 | / (CLIP_REVEAL_MEET_FRACTION_MAX - CLIP_REVEAL_MEET_FRACTION_MIN))); |
| 974 | return CLIP_REVEAL_MEET_EARLIEST |
| 975 | + (1 - t) * (CLIP_REVEAL_MEET_LAST - CLIP_REVEAL_MEET_EARLIEST); |
| 976 | } |
| 977 | |
Jorim Jaggi | 5098159 | 2015-12-29 17:54:12 +0100 | [diff] [blame] | 978 | public String toShortString() { |
| 979 | return TAG; |
| 980 | } |
Robert Carr | e63e01a | 2016-04-18 20:27:34 -0700 | [diff] [blame] | 981 | |
| 982 | WindowState getWindow() { |
| 983 | return mWindow; |
| 984 | } |
Jorim Jaggi | 31f7170 | 2016-05-04 16:43:04 -0700 | [diff] [blame] | 985 | |
| 986 | void dump(String prefix, PrintWriter pw) { |
| 987 | pw.println(prefix + "DockedStackDividerController"); |
| 988 | pw.println(prefix + " mLastVisibility=" + mLastVisibility); |
| 989 | pw.println(prefix + " mMinimizedDock=" + mMinimizedDock); |
| 990 | pw.println(prefix + " mAdjustedForIme=" + mAdjustedForIme); |
| 991 | pw.println(prefix + " mAdjustedForDivider=" + mAdjustedForDivider); |
Jorim Jaggi | 31f7170 | 2016-05-04 16:43:04 -0700 | [diff] [blame] | 992 | } |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 993 | |
| 994 | void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 995 | final long token = proto.start(fieldId); |
| 996 | proto.write(MINIMIZED_DOCK, mMinimizedDock); |
| 997 | proto.end(token); |
| 998 | } |
Robert Carr | e63e01a | 2016-04-18 20:27:34 -0700 | [diff] [blame] | 999 | } |