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