Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 android.view; |
| 18 | |
Yunfan Chen | fae0aea | 2020-02-22 20:57:57 +0900 | [diff] [blame] | 19 | import static android.view.InsetsState.ITYPE_CAPTION_BAR; |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 20 | import static android.view.InsetsState.ITYPE_IME; |
Jorim Jaggi | 33a2183 | 2020-04-06 14:15:46 +0200 | [diff] [blame] | 21 | import static android.view.InsetsState.toInternalType; |
Jorim Jaggi | 5ed50cc | 2019-01-23 16:59:42 +0100 | [diff] [blame] | 22 | import static android.view.InsetsState.toPublicType; |
| 23 | import static android.view.WindowInsets.Type.all; |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 24 | import static android.view.WindowInsets.Type.ime; |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 25 | |
Jorim Jaggi | 6d5c801 | 2020-02-28 01:40:27 +0100 | [diff] [blame] | 26 | import android.animation.AnimationHandler; |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 27 | import android.animation.Animator; |
| 28 | import android.animation.AnimatorListenerAdapter; |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 29 | import android.animation.TypeEvaluator; |
Jorim Jaggi | 5875cca | 2020-03-17 13:44:57 +0100 | [diff] [blame] | 30 | import android.animation.ValueAnimator; |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 31 | import android.annotation.IntDef; |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 32 | import android.annotation.NonNull; |
Jorim Jaggi | dd3304e | 2020-01-20 17:24:51 +0100 | [diff] [blame] | 33 | import android.annotation.Nullable; |
Jorim Jaggi | 02a741f | 2018-12-12 17:40:19 -0800 | [diff] [blame] | 34 | import android.graphics.Insets; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 35 | import android.graphics.Rect; |
Adrian Roos | 3406fb9 | 2020-02-10 18:38:59 -0800 | [diff] [blame] | 36 | import android.os.CancellationSignal; |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 37 | import android.os.Handler; |
Jorim Jaggi | cb28ae6 | 2020-05-14 17:46:32 +0200 | [diff] [blame] | 38 | import android.os.Trace; |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 39 | import android.util.ArraySet; |
Taran Singh | 85661e3 | 2020-05-07 14:45:34 -0700 | [diff] [blame] | 40 | import android.util.Log; |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 41 | import android.util.Pair; |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 42 | import android.util.SparseArray; |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 43 | import android.view.InsetsSourceConsumer.ShowResult; |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 44 | import android.view.InsetsState.InternalInsetsType; |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 45 | import android.view.SurfaceControl.Transaction; |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 46 | import android.view.WindowInsets.Type; |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 47 | import android.view.WindowInsets.Type.InsetsType; |
Adrian Roos | db5b0c2 | 2020-02-12 15:05:27 -0800 | [diff] [blame] | 48 | import android.view.WindowInsetsAnimation.Bounds; |
Jorim Jaggi | 4e04eb2 | 2020-01-09 16:42:14 +0100 | [diff] [blame] | 49 | import android.view.WindowManager.LayoutParams.SoftInputModeFlags; |
Jorim Jaggi | 7974259 | 2019-01-18 17:36:10 +0100 | [diff] [blame] | 50 | import android.view.animation.Interpolator; |
Jorim Jaggi | 5875cca | 2020-03-17 13:44:57 +0100 | [diff] [blame] | 51 | import android.view.animation.LinearInterpolator; |
Jorim Jaggi | 7974259 | 2019-01-18 17:36:10 +0100 | [diff] [blame] | 52 | import android.view.animation.PathInterpolator; |
Jorim Jaggi | bf87c15 | 2020-04-22 17:18:25 +0200 | [diff] [blame] | 53 | import android.view.inputmethod.InputMethodManager; |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 54 | |
| 55 | import com.android.internal.annotations.VisibleForTesting; |
Jorim Jaggi | 6d5c801 | 2020-02-28 01:40:27 +0100 | [diff] [blame] | 56 | import com.android.internal.graphics.SfVsyncFrameCallbackProvider; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 57 | |
| 58 | import java.io.PrintWriter; |
Jorim Jaggi | a51168a | 2019-12-27 15:17:44 +0100 | [diff] [blame] | 59 | import java.lang.annotation.Retention; |
| 60 | import java.lang.annotation.RetentionPolicy; |
Jorim Jaggi | 5bb571d | 2018-11-06 14:42:04 +0100 | [diff] [blame] | 61 | import java.util.ArrayList; |
Adrian Roos | db5b0c2 | 2020-02-12 15:05:27 -0800 | [diff] [blame] | 62 | import java.util.Collections; |
| 63 | import java.util.List; |
Jorim Jaggi | ed35b17 | 2020-03-06 00:13:57 +0100 | [diff] [blame] | 64 | import java.util.Objects; |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 65 | import java.util.function.BiFunction; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * Implements {@link WindowInsetsController} on the client. |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 69 | * @hide |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 70 | */ |
Yunfan Chen | 02abf55 | 2019-12-05 14:51:09 +0900 | [diff] [blame] | 71 | public class InsetsController implements WindowInsetsController, InsetsAnimationControlCallbacks { |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 72 | |
Adrian Roos | a79b885 | 2020-05-26 21:25:15 +0200 | [diff] [blame] | 73 | private int mTypesBeingCancelled; |
| 74 | |
Jorim Jaggi | bf87c15 | 2020-04-22 17:18:25 +0200 | [diff] [blame] | 75 | public interface Host { |
| 76 | |
| 77 | Handler getHandler(); |
| 78 | |
| 79 | /** |
| 80 | * Notifies host that {@link InsetsController#getState()} has changed. |
| 81 | */ |
| 82 | void notifyInsetsChanged(); |
| 83 | |
| 84 | void dispatchWindowInsetsAnimationPrepare(@NonNull WindowInsetsAnimation animation); |
| 85 | Bounds dispatchWindowInsetsAnimationStart( |
| 86 | @NonNull WindowInsetsAnimation animation, @NonNull Bounds bounds); |
| 87 | WindowInsets dispatchWindowInsetsAnimationProgress(@NonNull WindowInsets insets, |
| 88 | @NonNull List<WindowInsetsAnimation> runningAnimations); |
| 89 | void dispatchWindowInsetsAnimationEnd(@NonNull WindowInsetsAnimation animation); |
| 90 | |
| 91 | /** |
| 92 | * Requests host to apply surface params in synchronized manner. |
| 93 | */ |
| 94 | void applySurfaceParams(final SyncRtSurfaceTransactionApplier.SurfaceParams... params); |
| 95 | |
| 96 | /** |
| 97 | * @see ViewRootImpl#updateCompatSysUiVisibility(int, boolean, boolean) |
| 98 | */ |
| 99 | void updateCompatSysUiVisibility(@InternalInsetsType int type, boolean visible, |
| 100 | boolean hasControl); |
| 101 | |
| 102 | /** |
| 103 | * Called when insets have been modified by the client and should be reported back to WM. |
| 104 | */ |
| 105 | void onInsetsModified(InsetsState insetsState); |
| 106 | |
| 107 | /** |
| 108 | * @return Whether the host has any callbacks it wants to synchronize the animations with. |
| 109 | * If there are no callbacks, the animation will be off-loaded to another thread and |
| 110 | * slightly different animation curves are picked. |
| 111 | */ |
| 112 | boolean hasAnimationCallbacks(); |
| 113 | |
| 114 | /** |
| 115 | * @see WindowInsetsController#setSystemBarsAppearance |
| 116 | */ |
| 117 | void setSystemBarsAppearance(@Appearance int appearance, @Appearance int mask); |
| 118 | |
| 119 | /** |
| 120 | * @see WindowInsetsController#getSystemBarsAppearance() |
| 121 | */ |
| 122 | @Appearance int getSystemBarsAppearance(); |
| 123 | |
| 124 | /** |
| 125 | * @see WindowInsetsController#setSystemBarsBehavior |
| 126 | */ |
| 127 | void setSystemBarsBehavior(@Behavior int behavior); |
| 128 | |
| 129 | /** |
| 130 | * @see WindowInsetsController#getSystemBarsBehavior |
| 131 | */ |
| 132 | @Behavior int getSystemBarsBehavior(); |
| 133 | |
| 134 | /** |
| 135 | * Releases a surface and ensure that this is done after {@link #applySurfaceParams} has |
| 136 | * finished applying params. |
| 137 | */ |
| 138 | void releaseSurfaceControlFromRt(SurfaceControl surfaceControl); |
| 139 | |
| 140 | /** |
| 141 | * If this host is a view hierarchy, adds a pre-draw runnable to ensure proper ordering as |
| 142 | * described in {@link WindowInsetsAnimation.Callback#onPrepare}. |
| 143 | * |
| 144 | * If this host isn't a view hierarchy, the runnable can be executed immediately. |
| 145 | */ |
| 146 | void addOnPreDrawRunnable(Runnable r); |
| 147 | |
| 148 | /** |
| 149 | * Adds a runnbale to be executed during {@link Choreographer#CALLBACK_INSETS_ANIMATION} |
| 150 | * phase. |
| 151 | */ |
| 152 | void postInsetsAnimationCallback(Runnable r); |
| 153 | |
| 154 | /** |
| 155 | * Obtains {@link InputMethodManager} instance from host. |
| 156 | */ |
| 157 | InputMethodManager getInputMethodManager(); |
Taran Singh | 85661e3 | 2020-05-07 14:45:34 -0700 | [diff] [blame] | 158 | |
| 159 | /** |
| 160 | * @return title of the rootView, if it has one. |
| 161 | * Note: this method is for debugging purposes only. |
| 162 | */ |
| 163 | @Nullable |
| 164 | String getRootViewTitle(); |
Jorim Jaggi | bf87c15 | 2020-04-22 17:18:25 +0200 | [diff] [blame] | 165 | } |
| 166 | |
Taran Singh | 85661e3 | 2020-05-07 14:45:34 -0700 | [diff] [blame] | 167 | private static final String TAG = "InsetsController"; |
Jorim Jaggi | 7974259 | 2019-01-18 17:36:10 +0100 | [diff] [blame] | 168 | private static final int ANIMATION_DURATION_SHOW_MS = 275; |
| 169 | private static final int ANIMATION_DURATION_HIDE_MS = 340; |
Jorim Jaggi | 5875cca | 2020-03-17 13:44:57 +0100 | [diff] [blame] | 170 | |
| 171 | private static final int ANIMATION_DURATION_SYNC_IME_MS = 285; |
| 172 | private static final int ANIMATION_DURATION_UNSYNC_IME_MS = 200; |
| 173 | |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 174 | private static final int PENDING_CONTROL_TIMEOUT_MS = 2000; |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 175 | |
Jorim Jaggi | 5875cca | 2020-03-17 13:44:57 +0100 | [diff] [blame] | 176 | public static final Interpolator SYSTEM_BARS_INTERPOLATOR = |
| 177 | new PathInterpolator(0.4f, 0f, 0.2f, 1f); |
| 178 | private static final Interpolator SYNC_IME_INTERPOLATOR = |
| 179 | new PathInterpolator(0.2f, 0f, 0f, 1f); |
| 180 | private static final Interpolator LINEAR_OUT_SLOW_IN_INTERPOLATOR = |
| 181 | new PathInterpolator(0, 0, 0.2f, 1f); |
| 182 | private static final Interpolator FAST_OUT_LINEAR_IN_INTERPOLATOR = |
| 183 | new PathInterpolator(0.4f, 0f, 1f, 1f); |
Tarandeep Singh | 54554e2 | 2019-11-01 14:43:05 -0700 | [diff] [blame] | 184 | |
Taran Singh | 85661e3 | 2020-05-07 14:45:34 -0700 | [diff] [blame] | 185 | static final boolean DEBUG = false; |
| 186 | static final boolean WARN = false; |
| 187 | |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 188 | /** |
Jorim Jaggi | a51168a | 2019-12-27 15:17:44 +0100 | [diff] [blame] | 189 | * Layout mode during insets animation: The views should be laid out as if the changing inset |
| 190 | * types are fully shown. Before starting the animation, {@link View#onApplyWindowInsets} will |
| 191 | * be called as if the changing insets types are shown, which will result in the views being |
| 192 | * laid out as if the insets are fully shown. |
| 193 | */ |
Yunfan Chen | b5d2db7 | 2019-12-06 15:43:43 +0900 | [diff] [blame] | 194 | public static final int LAYOUT_INSETS_DURING_ANIMATION_SHOWN = 0; |
Jorim Jaggi | a51168a | 2019-12-27 15:17:44 +0100 | [diff] [blame] | 195 | |
| 196 | /** |
| 197 | * Layout mode during insets animation: The views should be laid out as if the changing inset |
| 198 | * types are fully hidden. Before starting the animation, {@link View#onApplyWindowInsets} will |
| 199 | * be called as if the changing insets types are hidden, which will result in the views being |
| 200 | * laid out as if the insets are fully hidden. |
| 201 | */ |
Yunfan Chen | b5d2db7 | 2019-12-06 15:43:43 +0900 | [diff] [blame] | 202 | public static final int LAYOUT_INSETS_DURING_ANIMATION_HIDDEN = 1; |
Jorim Jaggi | a51168a | 2019-12-27 15:17:44 +0100 | [diff] [blame] | 203 | |
| 204 | /** |
| 205 | * Determines the behavior of how the views should be laid out during an insets animation that |
| 206 | * is controlled by the application by calling {@link #controlWindowInsetsAnimation}. |
| 207 | * <p> |
| 208 | * When the animation is system-initiated, the layout mode is always chosen such that the |
| 209 | * pre-animation layout will represent the opposite of the starting state, i.e. when insets |
| 210 | * are appearing, {@link #LAYOUT_INSETS_DURING_ANIMATION_SHOWN} will be used. When insets |
| 211 | * are disappearing, {@link #LAYOUT_INSETS_DURING_ANIMATION_HIDDEN} will be used. |
| 212 | */ |
| 213 | @Retention(RetentionPolicy.SOURCE) |
| 214 | @IntDef(value = {LAYOUT_INSETS_DURING_ANIMATION_SHOWN, |
| 215 | LAYOUT_INSETS_DURING_ANIMATION_HIDDEN}) |
| 216 | @interface LayoutInsetsDuringAnimation { |
| 217 | } |
| 218 | |
Jorim Jaggi | 1f2c7eb | 2020-01-08 00:07:13 +0100 | [diff] [blame] | 219 | /** Not running an animation. */ |
| 220 | @VisibleForTesting |
| 221 | public static final int ANIMATION_TYPE_NONE = -1; |
| 222 | |
| 223 | /** Running animation will show insets */ |
| 224 | @VisibleForTesting |
| 225 | public static final int ANIMATION_TYPE_SHOW = 0; |
| 226 | |
| 227 | /** Running animation will hide insets */ |
| 228 | @VisibleForTesting |
| 229 | public static final int ANIMATION_TYPE_HIDE = 1; |
| 230 | |
| 231 | /** Running animation is controlled by user via {@link #controlWindowInsetsAnimation} */ |
| 232 | @VisibleForTesting |
| 233 | public static final int ANIMATION_TYPE_USER = 2; |
| 234 | |
| 235 | @Retention(RetentionPolicy.SOURCE) |
| 236 | @IntDef(value = {ANIMATION_TYPE_NONE, ANIMATION_TYPE_SHOW, ANIMATION_TYPE_HIDE, |
| 237 | ANIMATION_TYPE_USER}) |
| 238 | @interface AnimationType { |
| 239 | } |
| 240 | |
Jorim Jaggi | a51168a | 2019-12-27 15:17:44 +0100 | [diff] [blame] | 241 | /** |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 242 | * Translation animation evaluator. |
| 243 | */ |
| 244 | private static TypeEvaluator<Insets> sEvaluator = (fraction, startValue, endValue) -> Insets.of( |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 245 | (int) (startValue.left + fraction * (endValue.left - startValue.left)), |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 246 | (int) (startValue.top + fraction * (endValue.top - startValue.top)), |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 247 | (int) (startValue.right + fraction * (endValue.right - startValue.right)), |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 248 | (int) (startValue.bottom + fraction * (endValue.bottom - startValue.bottom))); |
| 249 | |
| 250 | /** |
Yunfan Chen | 4523d5d | 2020-01-16 16:54:00 +0900 | [diff] [blame] | 251 | * The default implementation of listener, to be used by InsetsController and InsetsPolicy to |
| 252 | * animate insets. |
| 253 | */ |
| 254 | public static class InternalAnimationControlListener |
| 255 | implements WindowInsetsAnimationControlListener { |
Tarandeep Singh | 54554e2 | 2019-11-01 14:43:05 -0700 | [diff] [blame] | 256 | |
| 257 | private WindowInsetsAnimationController mController; |
Jorim Jaggi | 5875cca | 2020-03-17 13:44:57 +0100 | [diff] [blame] | 258 | private ValueAnimator mAnimator; |
Jorim Jaggi | 6d5c801 | 2020-02-28 01:40:27 +0100 | [diff] [blame] | 259 | private final boolean mShow; |
Jorim Jaggi | 5875cca | 2020-03-17 13:44:57 +0100 | [diff] [blame] | 260 | private final boolean mHasAnimationCallbacks; |
| 261 | private final @InsetsType int mRequestedTypes; |
| 262 | private final long mDurationMs; |
Tiger Huang | f232119 | 2020-05-21 22:16:14 +0800 | [diff] [blame] | 263 | private final boolean mDisable; |
Tarandeep Singh | 54554e2 | 2019-11-01 14:43:05 -0700 | [diff] [blame] | 264 | |
Jorim Jaggi | 6d5c801 | 2020-02-28 01:40:27 +0100 | [diff] [blame] | 265 | private ThreadLocal<AnimationHandler> mSfAnimationHandlerThreadLocal = |
| 266 | new ThreadLocal<AnimationHandler>() { |
| 267 | @Override |
| 268 | protected AnimationHandler initialValue() { |
| 269 | AnimationHandler handler = new AnimationHandler(); |
| 270 | handler.setProvider(new SfVsyncFrameCallbackProvider()); |
| 271 | return handler; |
| 272 | } |
| 273 | }; |
| 274 | |
Jorim Jaggi | 5875cca | 2020-03-17 13:44:57 +0100 | [diff] [blame] | 275 | public InternalAnimationControlListener(boolean show, boolean hasAnimationCallbacks, |
Tiger Huang | f232119 | 2020-05-21 22:16:14 +0800 | [diff] [blame] | 276 | int requestedTypes, boolean disable) { |
Tarandeep Singh | 54554e2 | 2019-11-01 14:43:05 -0700 | [diff] [blame] | 277 | mShow = show; |
Jorim Jaggi | 5875cca | 2020-03-17 13:44:57 +0100 | [diff] [blame] | 278 | mHasAnimationCallbacks = hasAnimationCallbacks; |
| 279 | mRequestedTypes = requestedTypes; |
| 280 | mDurationMs = calculateDurationMs(); |
Tiger Huang | f232119 | 2020-05-21 22:16:14 +0800 | [diff] [blame] | 281 | mDisable = disable; |
Tarandeep Singh | 54554e2 | 2019-11-01 14:43:05 -0700 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | @Override |
| 285 | public void onReady(WindowInsetsAnimationController controller, int types) { |
| 286 | mController = controller; |
Taran Singh | 85661e3 | 2020-05-07 14:45:34 -0700 | [diff] [blame] | 287 | if (DEBUG) Log.d(TAG, "default animation onReady types: " + types); |
Jorim Jaggi | a51168a | 2019-12-27 15:17:44 +0100 | [diff] [blame] | 288 | |
Tiger Huang | f232119 | 2020-05-21 22:16:14 +0800 | [diff] [blame] | 289 | if (mDisable) { |
| 290 | onAnimationFinish(); |
| 291 | return; |
| 292 | } |
Jorim Jaggi | 5875cca | 2020-03-17 13:44:57 +0100 | [diff] [blame] | 293 | mAnimator = ValueAnimator.ofFloat(0f, 1f); |
| 294 | mAnimator.setDuration(mDurationMs); |
| 295 | mAnimator.setInterpolator(new LinearInterpolator()); |
| 296 | Insets start = mShow |
| 297 | ? controller.getHiddenStateInsets() |
| 298 | : controller.getShownStateInsets(); |
| 299 | Insets end = mShow |
| 300 | ? controller.getShownStateInsets() |
| 301 | : controller.getHiddenStateInsets(); |
| 302 | Interpolator insetsInterpolator = getInterpolator(); |
| 303 | Interpolator alphaInterpolator = getAlphaInterpolator(); |
| 304 | mAnimator.addUpdateListener(animation -> { |
| 305 | float rawFraction = animation.getAnimatedFraction(); |
| 306 | float alphaFraction = mShow |
| 307 | ? rawFraction |
| 308 | : 1 - rawFraction; |
| 309 | float insetsFraction = insetsInterpolator.getInterpolation(rawFraction); |
| 310 | controller.setInsetsAndAlpha( |
| 311 | sEvaluator.evaluate(insetsFraction, start, end), |
| 312 | alphaInterpolator.getInterpolation(alphaFraction), |
| 313 | rawFraction); |
Taran Singh | 85661e3 | 2020-05-07 14:45:34 -0700 | [diff] [blame] | 314 | if (DEBUG) Log.d(TAG, "Default animation setInsetsAndAlpha fraction: " |
| 315 | + insetsFraction); |
Jorim Jaggi | 5875cca | 2020-03-17 13:44:57 +0100 | [diff] [blame] | 316 | }); |
Tarandeep Singh | 54554e2 | 2019-11-01 14:43:05 -0700 | [diff] [blame] | 317 | mAnimator.addListener(new AnimatorListenerAdapter() { |
| 318 | |
| 319 | @Override |
| 320 | public void onAnimationEnd(Animator animation) { |
| 321 | onAnimationFinish(); |
| 322 | } |
| 323 | }); |
Jorim Jaggi | 5875cca | 2020-03-17 13:44:57 +0100 | [diff] [blame] | 324 | if (!mHasAnimationCallbacks) { |
Jorim Jaggi | 6d5c801 | 2020-02-28 01:40:27 +0100 | [diff] [blame] | 325 | mAnimator.setAnimationHandler(mSfAnimationHandlerThreadLocal.get()); |
| 326 | } |
Tarandeep Singh | 54554e2 | 2019-11-01 14:43:05 -0700 | [diff] [blame] | 327 | mAnimator.start(); |
| 328 | } |
| 329 | |
| 330 | @Override |
Adrian Roos | 5d557ed | 2020-03-17 20:04:35 +0100 | [diff] [blame] | 331 | public void onFinished(WindowInsetsAnimationController controller) { |
Taran Singh | 85661e3 | 2020-05-07 14:45:34 -0700 | [diff] [blame] | 332 | if (DEBUG) Log.d(TAG, "InternalAnimationControlListener onFinished types:" |
| 333 | + Type.toString(mRequestedTypes)); |
Adrian Roos | 5d557ed | 2020-03-17 20:04:35 +0100 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | @Override |
| 337 | public void onCancelled(WindowInsetsAnimationController controller) { |
Tarandeep Singh | 54554e2 | 2019-11-01 14:43:05 -0700 | [diff] [blame] | 338 | // Animator can be null when it is cancelled before onReady() completes. |
| 339 | if (mAnimator != null) { |
| 340 | mAnimator.cancel(); |
| 341 | } |
Taran Singh | 85661e3 | 2020-05-07 14:45:34 -0700 | [diff] [blame] | 342 | if (DEBUG) Log.d(TAG, "InternalAnimationControlListener onCancelled types:" |
| 343 | + mRequestedTypes); |
Tarandeep Singh | 54554e2 | 2019-11-01 14:43:05 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Jorim Jaggi | 5875cca | 2020-03-17 13:44:57 +0100 | [diff] [blame] | 346 | Interpolator getInterpolator() { |
| 347 | if ((mRequestedTypes & ime()) != 0) { |
| 348 | if (mHasAnimationCallbacks) { |
| 349 | return SYNC_IME_INTERPOLATOR; |
| 350 | } else if (mShow) { |
| 351 | return LINEAR_OUT_SLOW_IN_INTERPOLATOR; |
| 352 | } else { |
| 353 | return FAST_OUT_LINEAR_IN_INTERPOLATOR; |
| 354 | } |
| 355 | } else { |
| 356 | return SYSTEM_BARS_INTERPOLATOR; |
| 357 | } |
Tarandeep Singh | 54554e2 | 2019-11-01 14:43:05 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Jorim Jaggi | 5875cca | 2020-03-17 13:44:57 +0100 | [diff] [blame] | 360 | Interpolator getAlphaInterpolator() { |
| 361 | if ((mRequestedTypes & ime()) != 0) { |
| 362 | if (mHasAnimationCallbacks) { |
| 363 | return input -> 1f; |
| 364 | } else if (mShow) { |
| 365 | |
| 366 | // Alpha animation takes half the time with linear interpolation; |
| 367 | return input -> Math.min(1f, 2 * input); |
| 368 | } else { |
| 369 | return FAST_OUT_LINEAR_IN_INTERPOLATOR; |
| 370 | } |
| 371 | } else { |
| 372 | return input -> 1f; |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | protected void onAnimationFinish() { |
| 377 | mController.finish(mShow); |
Taran Singh | 85661e3 | 2020-05-07 14:45:34 -0700 | [diff] [blame] | 378 | if (DEBUG) Log.d(TAG, "onAnimationFinish showOnFinish: " + mShow); |
Tarandeep Singh | 54554e2 | 2019-11-01 14:43:05 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Yunfan Chen | b5d2db7 | 2019-12-06 15:43:43 +0900 | [diff] [blame] | 381 | /** |
| 382 | * To get the animation duration in MS. |
| 383 | */ |
| 384 | public long getDurationMs() { |
Jorim Jaggi | 5875cca | 2020-03-17 13:44:57 +0100 | [diff] [blame] | 385 | return mDurationMs; |
| 386 | } |
| 387 | |
| 388 | private long calculateDurationMs() { |
| 389 | if ((mRequestedTypes & ime()) != 0) { |
| 390 | if (mHasAnimationCallbacks) { |
| 391 | return ANIMATION_DURATION_SYNC_IME_MS; |
| 392 | } else { |
| 393 | return ANIMATION_DURATION_UNSYNC_IME_MS; |
| 394 | } |
| 395 | } else { |
| 396 | return mShow ? ANIMATION_DURATION_SHOW_MS : ANIMATION_DURATION_HIDE_MS; |
Tarandeep Singh | 54554e2 | 2019-11-01 14:43:05 -0700 | [diff] [blame] | 397 | } |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 398 | } |
| 399 | } |
| 400 | |
Jorim Jaggi | 1f2c7eb | 2020-01-08 00:07:13 +0100 | [diff] [blame] | 401 | /** |
| 402 | * Represents a running animation |
| 403 | */ |
| 404 | private static class RunningAnimation { |
| 405 | |
Jorim Jaggi | 6d5c801 | 2020-02-28 01:40:27 +0100 | [diff] [blame] | 406 | RunningAnimation(InsetsAnimationControlRunner runner, int type) { |
| 407 | this.runner = runner; |
Jorim Jaggi | 1f2c7eb | 2020-01-08 00:07:13 +0100 | [diff] [blame] | 408 | this.type = type; |
| 409 | } |
| 410 | |
Jorim Jaggi | 6d5c801 | 2020-02-28 01:40:27 +0100 | [diff] [blame] | 411 | final InsetsAnimationControlRunner runner; |
Jorim Jaggi | 1f2c7eb | 2020-01-08 00:07:13 +0100 | [diff] [blame] | 412 | final @AnimationType int type; |
Jorim Jaggi | 580aef5 | 2020-02-26 18:28:28 +0100 | [diff] [blame] | 413 | |
| 414 | /** |
| 415 | * Whether {@link WindowInsetsAnimation.Callback#onStart(WindowInsetsAnimation, Bounds)} has |
| 416 | * been dispatched already for this animation. |
| 417 | */ |
| 418 | boolean startDispatched; |
Jorim Jaggi | 1f2c7eb | 2020-01-08 00:07:13 +0100 | [diff] [blame] | 419 | } |
| 420 | |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 421 | /** |
| 422 | * Represents a control request that we had to defer because we are waiting for the IME to |
| 423 | * process our show request. |
| 424 | */ |
| 425 | private static class PendingControlRequest { |
| 426 | |
| 427 | PendingControlRequest(@InsetsType int types, WindowInsetsAnimationControlListener listener, |
| 428 | long durationMs, Interpolator interpolator, @AnimationType int animationType, |
Adrian Roos | 3406fb9 | 2020-02-10 18:38:59 -0800 | [diff] [blame] | 429 | @LayoutInsetsDuringAnimation int layoutInsetsDuringAnimation, |
Jorim Jaggi | 6d5c801 | 2020-02-28 01:40:27 +0100 | [diff] [blame] | 430 | CancellationSignal cancellationSignal, boolean useInsetsAnimationThread) { |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 431 | this.types = types; |
| 432 | this.listener = listener; |
| 433 | this.durationMs = durationMs; |
| 434 | this.interpolator = interpolator; |
| 435 | this.animationType = animationType; |
| 436 | this.layoutInsetsDuringAnimation = layoutInsetsDuringAnimation; |
Adrian Roos | 3406fb9 | 2020-02-10 18:38:59 -0800 | [diff] [blame] | 437 | this.cancellationSignal = cancellationSignal; |
Jorim Jaggi | 6d5c801 | 2020-02-28 01:40:27 +0100 | [diff] [blame] | 438 | this.useInsetsAnimationThread = useInsetsAnimationThread; |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | final @InsetsType int types; |
| 442 | final WindowInsetsAnimationControlListener listener; |
| 443 | final long durationMs; |
| 444 | final Interpolator interpolator; |
| 445 | final @AnimationType int animationType; |
| 446 | final @LayoutInsetsDuringAnimation int layoutInsetsDuringAnimation; |
Adrian Roos | 3406fb9 | 2020-02-10 18:38:59 -0800 | [diff] [blame] | 447 | final CancellationSignal cancellationSignal; |
Jorim Jaggi | 6d5c801 | 2020-02-28 01:40:27 +0100 | [diff] [blame] | 448 | final boolean useInsetsAnimationThread; |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 449 | } |
Yunfan Chen | 4523d5d | 2020-01-16 16:54:00 +0900 | [diff] [blame] | 450 | |
Tiger Huang | 173480f | 2020-04-29 01:05:42 +0800 | [diff] [blame] | 451 | /** The local state */ |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 452 | private final InsetsState mState = new InsetsState(); |
Tiger Huang | 173480f | 2020-04-29 01:05:42 +0800 | [diff] [blame] | 453 | |
| 454 | /** The state dispatched from server */ |
| 455 | private final InsetsState mLastDispatchedState = new InsetsState(); |
| 456 | |
| 457 | /** The state sent to server */ |
| 458 | private final InsetsState mRequestedState = new InsetsState(); |
Jorim Jaggi | e35c059 | 2018-11-06 16:21:08 +0100 | [diff] [blame] | 459 | |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 460 | private final Rect mFrame = new Rect(); |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 461 | private final BiFunction<InsetsController, Integer, InsetsSourceConsumer> mConsumerCreator; |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 462 | private final SparseArray<InsetsSourceConsumer> mSourceConsumers = new SparseArray<>(); |
Jorim Jaggi | bf87c15 | 2020-04-22 17:18:25 +0200 | [diff] [blame] | 463 | private final Host mHost; |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 464 | private final Handler mHandler; |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 465 | |
| 466 | private final SparseArray<InsetsSourceControl> mTmpControlArray = new SparseArray<>(); |
Jorim Jaggi | 1f2c7eb | 2020-01-08 00:07:13 +0100 | [diff] [blame] | 467 | private final ArrayList<RunningAnimation> mRunningAnimations = new ArrayList<>(); |
Jorim Jaggi | 580aef5 | 2020-02-26 18:28:28 +0100 | [diff] [blame] | 468 | private final ArrayList<WindowInsetsAnimation> mTmpRunningAnims = new ArrayList<>(); |
| 469 | private final List<WindowInsetsAnimation> mUnmodifiableTmpRunningAnims = |
| 470 | Collections.unmodifiableList(mTmpRunningAnims); |
Jorim Jaggi | 5ed50cc | 2019-01-23 16:59:42 +0100 | [diff] [blame] | 471 | private final ArrayList<InsetsAnimationControlImpl> mTmpFinishedControls = new ArrayList<>(); |
Jorim Jaggi | 02a741f | 2018-12-12 17:40:19 -0800 | [diff] [blame] | 472 | private WindowInsets mLastInsets; |
| 473 | |
| 474 | private boolean mAnimCallbackScheduled; |
| 475 | |
| 476 | private final Runnable mAnimCallback; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 477 | |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 478 | /** Pending control request that is waiting on IME to be ready to be shown */ |
| 479 | private PendingControlRequest mPendingImeControlRequest; |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 480 | |
Jorim Jaggi | 648e588 | 2019-01-24 13:24:02 +0100 | [diff] [blame] | 481 | private int mLastLegacySoftInputMode; |
Jorim Jaggi | 7f76187 | 2020-01-10 18:24:27 +0100 | [diff] [blame] | 482 | private int mLastLegacySystemUiFlags; |
Jorim Jaggi | 580aef5 | 2020-02-26 18:28:28 +0100 | [diff] [blame] | 483 | private DisplayCutout mLastDisplayCutout; |
Jorim Jaggi | a51168a | 2019-12-27 15:17:44 +0100 | [diff] [blame] | 484 | private boolean mStartingAnimation; |
Yunfan Chen | fae0aea | 2020-02-22 20:57:57 +0900 | [diff] [blame] | 485 | private int mCaptionInsetsHeight = 0; |
Tiger Huang | f232119 | 2020-05-21 22:16:14 +0800 | [diff] [blame] | 486 | private boolean mAnimationsDisabled; |
Jorim Jaggi | 648e588 | 2019-01-24 13:24:02 +0100 | [diff] [blame] | 487 | |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 488 | private Runnable mPendingControlTimeout = this::abortPendingImeControlRequest; |
Jorim Jaggi | ed35b17 | 2020-03-06 00:13:57 +0100 | [diff] [blame] | 489 | private final ArrayList<OnControllableInsetsChangedListener> mControllableInsetsChangedListeners |
| 490 | = new ArrayList<>(); |
| 491 | |
| 492 | /** Set of inset types for which an animation was started since last resetting this field */ |
| 493 | private @InsetsType int mLastStartedAnimTypes; |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 494 | |
Jorim Jaggi | bf87c15 | 2020-04-22 17:18:25 +0200 | [diff] [blame] | 495 | public InsetsController(Host host) { |
| 496 | this(host, (controller, type) -> { |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 497 | if (type == ITYPE_IME) { |
| 498 | return new ImeInsetsSourceConsumer(controller.mState, Transaction::new, controller); |
| 499 | } else { |
| 500 | return new InsetsSourceConsumer(type, controller.mState, Transaction::new, |
| 501 | controller); |
| 502 | } |
Jorim Jaggi | bf87c15 | 2020-04-22 17:18:25 +0200 | [diff] [blame] | 503 | }, host.getHandler()); |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | @VisibleForTesting |
Jorim Jaggi | bf87c15 | 2020-04-22 17:18:25 +0200 | [diff] [blame] | 507 | public InsetsController(Host host, |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 508 | BiFunction<InsetsController, Integer, InsetsSourceConsumer> consumerCreator, |
| 509 | Handler handler) { |
Jorim Jaggi | bf87c15 | 2020-04-22 17:18:25 +0200 | [diff] [blame] | 510 | mHost = host; |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 511 | mConsumerCreator = consumerCreator; |
| 512 | mHandler = handler; |
Jorim Jaggi | 02a741f | 2018-12-12 17:40:19 -0800 | [diff] [blame] | 513 | mAnimCallback = () -> { |
| 514 | mAnimCallbackScheduled = false; |
Jorim Jaggi | 1f2c7eb | 2020-01-08 00:07:13 +0100 | [diff] [blame] | 515 | if (mRunningAnimations.isEmpty()) { |
Jorim Jaggi | 02a741f | 2018-12-12 17:40:19 -0800 | [diff] [blame] | 516 | return; |
| 517 | } |
| 518 | |
Jorim Jaggi | 5ed50cc | 2019-01-23 16:59:42 +0100 | [diff] [blame] | 519 | mTmpFinishedControls.clear(); |
Jorim Jaggi | 580aef5 | 2020-02-26 18:28:28 +0100 | [diff] [blame] | 520 | mTmpRunningAnims.clear(); |
Jorim Jaggi | 02a741f | 2018-12-12 17:40:19 -0800 | [diff] [blame] | 521 | InsetsState state = new InsetsState(mState, true /* copySources */); |
Jorim Jaggi | 1f2c7eb | 2020-01-08 00:07:13 +0100 | [diff] [blame] | 522 | for (int i = mRunningAnimations.size() - 1; i >= 0; i--) { |
Jorim Jaggi | 580aef5 | 2020-02-26 18:28:28 +0100 | [diff] [blame] | 523 | RunningAnimation runningAnimation = mRunningAnimations.get(i); |
Taran Singh | 85661e3 | 2020-05-07 14:45:34 -0700 | [diff] [blame] | 524 | if (DEBUG) Log.d(TAG, "Running animation type: " + runningAnimation.type); |
Jorim Jaggi | 6d5c801 | 2020-02-28 01:40:27 +0100 | [diff] [blame] | 525 | InsetsAnimationControlRunner runner = runningAnimation.runner; |
| 526 | if (runner instanceof InsetsAnimationControlImpl) { |
| 527 | InsetsAnimationControlImpl control = (InsetsAnimationControlImpl) runner; |
Jorim Jaggi | 580aef5 | 2020-02-26 18:28:28 +0100 | [diff] [blame] | 528 | |
Jorim Jaggi | 6d5c801 | 2020-02-28 01:40:27 +0100 | [diff] [blame] | 529 | // Keep track of running animation to be dispatched. Aggregate it here such that |
| 530 | // if it gets finished within applyChangeInsets we still dispatch it to |
| 531 | // onProgress. |
| 532 | if (runningAnimation.startDispatched) { |
| 533 | mTmpRunningAnims.add(control.getAnimation()); |
| 534 | } |
| 535 | |
| 536 | if (control.applyChangeInsets(state)) { |
| 537 | mTmpFinishedControls.add(control); |
| 538 | } |
Jorim Jaggi | 5ed50cc | 2019-01-23 16:59:42 +0100 | [diff] [blame] | 539 | } |
Jorim Jaggi | 02a741f | 2018-12-12 17:40:19 -0800 | [diff] [blame] | 540 | } |
Jorim Jaggi | 5ed50cc | 2019-01-23 16:59:42 +0100 | [diff] [blame] | 541 | |
Jorim Jaggi | 580aef5 | 2020-02-26 18:28:28 +0100 | [diff] [blame] | 542 | WindowInsets insets = state.calculateInsets(mFrame, mState /* ignoringVisibilityState*/, |
| 543 | mLastInsets.isRound(), mLastInsets.shouldAlwaysConsumeSystemBars(), |
Jorim Jaggi | 22488d3 | 2020-03-19 01:12:44 +0100 | [diff] [blame] | 544 | mLastDisplayCutout, mLastLegacySoftInputMode, mLastLegacySystemUiFlags, |
| 545 | null /* typeSideMap */); |
Jorim Jaggi | bf87c15 | 2020-04-22 17:18:25 +0200 | [diff] [blame] | 546 | mHost.dispatchWindowInsetsAnimationProgress(insets, mUnmodifiableTmpRunningAnims); |
Taran Singh | 85661e3 | 2020-05-07 14:45:34 -0700 | [diff] [blame] | 547 | if (DEBUG) { |
| 548 | for (WindowInsetsAnimation anim : mUnmodifiableTmpRunningAnims) { |
| 549 | Log.d(TAG, String.format("Running animation type: %d, progress: %f", |
| 550 | anim.getTypeMask(), anim.getInterpolatedFraction())); |
| 551 | } |
| 552 | } |
Jorim Jaggi | 5ed50cc | 2019-01-23 16:59:42 +0100 | [diff] [blame] | 553 | |
| 554 | for (int i = mTmpFinishedControls.size() - 1; i >= 0; i--) { |
Adrian Roos | db5b0c2 | 2020-02-12 15:05:27 -0800 | [diff] [blame] | 555 | dispatchAnimationEnd(mTmpFinishedControls.get(i).getAnimation()); |
Jorim Jaggi | 5ed50cc | 2019-01-23 16:59:42 +0100 | [diff] [blame] | 556 | } |
Jorim Jaggi | 02a741f | 2018-12-12 17:40:19 -0800 | [diff] [blame] | 557 | }; |
Jorim Jaggi | c8d6038 | 2018-10-31 17:06:06 +0100 | [diff] [blame] | 558 | } |
| 559 | |
Jorim Jaggi | 5ed50cc | 2019-01-23 16:59:42 +0100 | [diff] [blame] | 560 | @VisibleForTesting |
| 561 | public void onFrameChanged(Rect frame) { |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 562 | if (mFrame.equals(frame)) { |
| 563 | return; |
| 564 | } |
Jorim Jaggi | bf87c15 | 2020-04-22 17:18:25 +0200 | [diff] [blame] | 565 | mHost.notifyInsetsChanged(); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 566 | mFrame.set(frame); |
| 567 | } |
| 568 | |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 569 | @Override |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 570 | public InsetsState getState() { |
| 571 | return mState; |
| 572 | } |
| 573 | |
Jorim Jaggi | 49b9f6c | 2020-03-24 22:28:38 +0100 | [diff] [blame] | 574 | @Override |
| 575 | public boolean isRequestedVisible(int type) { |
| 576 | return getSourceConsumer(type).isRequestedVisible(); |
| 577 | } |
| 578 | |
Jorim Jaggi | 3182ef1 | 2020-01-30 00:16:18 +0100 | [diff] [blame] | 579 | public InsetsState getLastDispatchedState() { |
Tiger Huang | 173480f | 2020-04-29 01:05:42 +0800 | [diff] [blame] | 580 | return mLastDispatchedState; |
Jorim Jaggi | 3182ef1 | 2020-01-30 00:16:18 +0100 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | @VisibleForTesting |
| 584 | public boolean onStateChanged(InsetsState state) { |
Jorim Jaggi | ed31259 | 2020-05-25 16:46:56 +0200 | [diff] [blame] | 585 | boolean stateChanged = !mState.equals(state, true /* excludingCaptionInsets */, |
| 586 | false /* excludeInvisibleIme */) |
Yunfan Chen | fae0aea | 2020-02-22 20:57:57 +0900 | [diff] [blame] | 587 | || !captionInsetsUnchanged(); |
Jorim Jaggi | ed31259 | 2020-05-25 16:46:56 +0200 | [diff] [blame] | 588 | if (!stateChanged && mLastDispatchedState.equals(state)) { |
Jorim Jaggi | c8d6038 | 2018-10-31 17:06:06 +0100 | [diff] [blame] | 589 | return false; |
| 590 | } |
Taran Singh | 85661e3 | 2020-05-07 14:45:34 -0700 | [diff] [blame] | 591 | if (DEBUG) Log.d(TAG, "onStateChanged: " + state); |
Jorim Jaggi | 33a2183 | 2020-04-06 14:15:46 +0200 | [diff] [blame] | 592 | updateState(state); |
Jorim Jaggi | ed31259 | 2020-05-25 16:46:56 +0200 | [diff] [blame] | 593 | |
| 594 | boolean localStateChanged = !mState.equals(mLastDispatchedState, |
| 595 | true /* excludingCaptionInsets */, true /* excludeInvisibleIme */); |
Tiger Huang | 173480f | 2020-04-29 01:05:42 +0800 | [diff] [blame] | 596 | mLastDispatchedState.set(state, true /* copySources */); |
Jorim Jaggi | ed31259 | 2020-05-25 16:46:56 +0200 | [diff] [blame] | 597 | |
Jorim Jaggi | c8d6038 | 2018-10-31 17:06:06 +0100 | [diff] [blame] | 598 | applyLocalVisibilityOverride(); |
Jorim Jaggi | 22488d3 | 2020-03-19 01:12:44 +0100 | [diff] [blame] | 599 | if (localStateChanged) { |
Jorim Jaggi | ed31259 | 2020-05-25 16:46:56 +0200 | [diff] [blame] | 600 | if (DEBUG) Log.d(TAG, "onStateChanged, notifyInsetsChanged, send state to WM: " + mState); |
Jorim Jaggi | bf87c15 | 2020-04-22 17:18:25 +0200 | [diff] [blame] | 601 | mHost.notifyInsetsChanged(); |
Tiger Huang | 173480f | 2020-04-29 01:05:42 +0800 | [diff] [blame] | 602 | updateRequestedState(); |
Jorim Jaggi | e35c059 | 2018-11-06 16:21:08 +0100 | [diff] [blame] | 603 | } |
Jorim Jaggi | 33a2183 | 2020-04-06 14:15:46 +0200 | [diff] [blame] | 604 | return true; |
| 605 | } |
| 606 | |
| 607 | private void updateState(InsetsState newState) { |
| 608 | mState.setDisplayFrame(newState.getDisplayFrame()); |
Jorim Jaggi | bfa95a7 | 2020-06-18 22:51:49 +0200 | [diff] [blame] | 609 | for (int i = 0; i < InsetsState.SIZE; i++) { |
| 610 | InsetsSource source = newState.peekSource(i); |
| 611 | if (source == null) continue;; |
Yohei Yukawa | f35971d | 2020-06-16 21:31:35 +0000 | [diff] [blame] | 612 | getSourceConsumer(source.getType()).updateSource(source); |
Jorim Jaggi | 33a2183 | 2020-04-06 14:15:46 +0200 | [diff] [blame] | 613 | } |
Jorim Jaggi | bfa95a7 | 2020-06-18 22:51:49 +0200 | [diff] [blame] | 614 | for (int i = 0; i < InsetsState.SIZE; i++) { |
| 615 | InsetsSource source = mState.peekSource(i); |
| 616 | if (source == null) continue; |
Jorim Jaggi | 33a2183 | 2020-04-06 14:15:46 +0200 | [diff] [blame] | 617 | if (newState.peekSource(source.getType()) == null) { |
| 618 | mState.removeSource(source.getType()); |
| 619 | } |
| 620 | } |
Yunfan Chen | fae0aea | 2020-02-22 20:57:57 +0900 | [diff] [blame] | 621 | if (mCaptionInsetsHeight != 0) { |
| 622 | mState.getSource(ITYPE_CAPTION_BAR).setFrame(new Rect(mFrame.left, mFrame.top, |
| 623 | mFrame.right, mFrame.top + mCaptionInsetsHeight)); |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | private boolean captionInsetsUnchanged() { |
| 628 | if (mState.peekSource(ITYPE_CAPTION_BAR) == null |
| 629 | && mCaptionInsetsHeight == 0) { |
| 630 | return true; |
| 631 | } |
| 632 | if (mState.peekSource(ITYPE_CAPTION_BAR) != null |
| 633 | && mCaptionInsetsHeight |
| 634 | == mState.peekSource(ITYPE_CAPTION_BAR).getFrame().height()) { |
| 635 | return true; |
| 636 | } |
| 637 | return false; |
Jorim Jaggi | 2751c29 | 2020-03-20 23:46:38 +0100 | [diff] [blame] | 638 | } |
| 639 | |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 640 | /** |
| 641 | * @see InsetsState#calculateInsets |
| 642 | */ |
Jorim Jaggi | 5bb571d | 2018-11-06 14:42:04 +0100 | [diff] [blame] | 643 | @VisibleForTesting |
| 644 | public WindowInsets calculateInsets(boolean isScreenRound, |
Jorim Jaggi | 22488d3 | 2020-03-19 01:12:44 +0100 | [diff] [blame] | 645 | boolean alwaysConsumeSystemBars, DisplayCutout cutout, |
| 646 | int legacySoftInputMode, int legacySystemUiFlags) { |
Jorim Jaggi | 648e588 | 2019-01-24 13:24:02 +0100 | [diff] [blame] | 647 | mLastLegacySoftInputMode = legacySoftInputMode; |
Jorim Jaggi | 7f76187 | 2020-01-10 18:24:27 +0100 | [diff] [blame] | 648 | mLastLegacySystemUiFlags = legacySystemUiFlags; |
Jorim Jaggi | 580aef5 | 2020-02-26 18:28:28 +0100 | [diff] [blame] | 649 | mLastDisplayCutout = cutout; |
| 650 | mLastInsets = mState.calculateInsets(mFrame, null /* ignoringVisibilityState*/, |
Jorim Jaggi | 22488d3 | 2020-03-19 01:12:44 +0100 | [diff] [blame] | 651 | isScreenRound, alwaysConsumeSystemBars, cutout, |
| 652 | legacySoftInputMode, legacySystemUiFlags, |
Jorim Jaggi | 5bb571d | 2018-11-06 14:42:04 +0100 | [diff] [blame] | 653 | null /* typeSideMap */); |
Jorim Jaggi | 02a741f | 2018-12-12 17:40:19 -0800 | [diff] [blame] | 654 | return mLastInsets; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 655 | } |
| 656 | |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 657 | /** |
Jorim Jaggi | 22488d3 | 2020-03-19 01:12:44 +0100 | [diff] [blame] | 658 | * @see InsetsState#calculateVisibleInsets(Rect, int) |
Jorim Jaggi | 4e04eb2 | 2020-01-09 16:42:14 +0100 | [diff] [blame] | 659 | */ |
Jorim Jaggi | 22488d3 | 2020-03-19 01:12:44 +0100 | [diff] [blame] | 660 | public Rect calculateVisibleInsets(@SoftInputModeFlags int softInputMode) { |
| 661 | return mState.calculateVisibleInsets(mFrame, softInputMode); |
Jorim Jaggi | 4e04eb2 | 2020-01-09 16:42:14 +0100 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | /** |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 665 | * Called when the server has dispatched us a new set of inset controls. |
| 666 | */ |
| 667 | public void onControlsChanged(InsetsSourceControl[] activeControls) { |
| 668 | if (activeControls != null) { |
| 669 | for (InsetsSourceControl activeControl : activeControls) { |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 670 | if (activeControl != null) { |
| 671 | // TODO(b/122982984): Figure out why it can be null. |
| 672 | mTmpControlArray.put(activeControl.getType(), activeControl); |
| 673 | } |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 674 | } |
| 675 | } |
| 676 | |
Tiger Huang | 173480f | 2020-04-29 01:05:42 +0800 | [diff] [blame] | 677 | final boolean hasControl = mTmpControlArray.size() > 0; |
| 678 | final int[] showTypes = new int[1]; |
| 679 | final int[] hideTypes = new int[1]; |
Jorim Jaggi | 3182ef1 | 2020-01-30 00:16:18 +0100 | [diff] [blame] | 680 | |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 681 | // Ensure to update all existing source consumers |
| 682 | for (int i = mSourceConsumers.size() - 1; i >= 0; i--) { |
| 683 | final InsetsSourceConsumer consumer = mSourceConsumers.valueAt(i); |
| 684 | final InsetsSourceControl control = mTmpControlArray.get(consumer.getType()); |
| 685 | |
| 686 | // control may be null, but we still need to update the control to null if it got |
| 687 | // revoked. |
Jorim Jaggi | 3182ef1 | 2020-01-30 00:16:18 +0100 | [diff] [blame] | 688 | consumer.setControl(control, showTypes, hideTypes); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | // Ensure to create source consumers if not available yet. |
| 692 | for (int i = mTmpControlArray.size() - 1; i >= 0; i--) { |
| 693 | final InsetsSourceControl control = mTmpControlArray.valueAt(i); |
Jorim Jaggi | 3182ef1 | 2020-01-30 00:16:18 +0100 | [diff] [blame] | 694 | InsetsSourceConsumer consumer = getSourceConsumer(control.getType()); |
| 695 | consumer.setControl(control, showTypes, hideTypes); |
| 696 | |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 697 | } |
| 698 | mTmpControlArray.clear(); |
Jorim Jaggi | ed35b17 | 2020-03-06 00:13:57 +0100 | [diff] [blame] | 699 | |
| 700 | // Do not override any animations that the app started in the OnControllableInsetsChanged |
| 701 | // listeners. |
| 702 | int animatingTypes = invokeControllableInsetsChangedListeners(); |
| 703 | showTypes[0] &= ~animatingTypes; |
| 704 | hideTypes[0] &= ~animatingTypes; |
| 705 | |
Jorim Jaggi | 3182ef1 | 2020-01-30 00:16:18 +0100 | [diff] [blame] | 706 | if (showTypes[0] != 0) { |
| 707 | applyAnimation(showTypes[0], true /* show */, false /* fromIme */); |
| 708 | } |
| 709 | if (hideTypes[0] != 0) { |
| 710 | applyAnimation(hideTypes[0], false /* show */, false /* fromIme */); |
| 711 | } |
Jorim Jaggi | bfa95a7 | 2020-06-18 22:51:49 +0200 | [diff] [blame] | 712 | if (hasControl && mRequestedState.hasSources()) { |
Tiger Huang | 173480f | 2020-04-29 01:05:42 +0800 | [diff] [blame] | 713 | // We might have changed our requested visibilities while we don't have the control, |
| 714 | // so we need to update our requested state once we have control. Otherwise, our |
| 715 | // requested state at the server side might be incorrect. |
| 716 | updateRequestedState(); |
| 717 | } |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | @Override |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 721 | public void show(@InsetsType int types) { |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 722 | show(types, false /* fromIme */); |
| 723 | } |
| 724 | |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 725 | @VisibleForTesting |
| 726 | public void show(@InsetsType int types, boolean fromIme) { |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 727 | // Handle pending request ready in case there was one set. |
| 728 | if (fromIme && mPendingImeControlRequest != null) { |
| 729 | PendingControlRequest pendingRequest = mPendingImeControlRequest; |
| 730 | mPendingImeControlRequest = null; |
| 731 | mHandler.removeCallbacks(mPendingControlTimeout); |
Adrian Roos | 5ad8cd2 | 2020-03-12 18:30:54 +0000 | [diff] [blame] | 732 | controlAnimationUnchecked( |
| 733 | pendingRequest.types, pendingRequest.cancellationSignal, |
Adrian Roos | 3406fb9 | 2020-02-10 18:38:59 -0800 | [diff] [blame] | 734 | pendingRequest.listener, mFrame, |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 735 | true /* fromIme */, pendingRequest.durationMs, pendingRequest.interpolator, |
Jorim Jaggi | 5875cca | 2020-03-17 13:44:57 +0100 | [diff] [blame] | 736 | pendingRequest.animationType, |
Jorim Jaggi | 6d5c801 | 2020-02-28 01:40:27 +0100 | [diff] [blame] | 737 | pendingRequest.layoutInsetsDuringAnimation, |
| 738 | pendingRequest.useInsetsAnimationThread); |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 739 | return; |
| 740 | } |
| 741 | |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 742 | // TODO: Support a ResultReceiver for IME. |
| 743 | // TODO(b/123718661): Make show() work for multi-session IME. |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 744 | int typesReady = 0; |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 745 | final ArraySet<Integer> internalTypes = InsetsState.toInternalType(types); |
| 746 | for (int i = internalTypes.size() - 1; i >= 0; i--) { |
Jorim Jaggi | 1f2c7eb | 2020-01-08 00:07:13 +0100 | [diff] [blame] | 747 | @InternalInsetsType int internalType = internalTypes.valueAt(i); |
| 748 | @AnimationType int animationType = getAnimationType(internalType); |
| 749 | InsetsSourceConsumer consumer = getSourceConsumer(internalType); |
Jorim Jaggi | 3182ef1 | 2020-01-30 00:16:18 +0100 | [diff] [blame] | 750 | if (consumer.isRequestedVisible() && animationType == ANIMATION_TYPE_NONE |
Jorim Jaggi | 1f2c7eb | 2020-01-08 00:07:13 +0100 | [diff] [blame] | 751 | || animationType == ANIMATION_TYPE_SHOW) { |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 752 | // no-op: already shown or animating in (because window visibility is |
| 753 | // applied before starting animation). |
Taran Singh | 85661e3 | 2020-05-07 14:45:34 -0700 | [diff] [blame] | 754 | if (DEBUG) Log.d(TAG, String.format( |
| 755 | "show ignored for type: %d animType: %d requestedVisible: %s", |
| 756 | consumer.getType(), animationType, consumer.isRequestedVisible())); |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 757 | continue; |
| 758 | } |
Adrian Roos | a2d2ba7 | 2020-05-25 17:44:55 +0200 | [diff] [blame] | 759 | if (fromIme && animationType == ANIMATION_TYPE_USER) { |
| 760 | // App is already controlling the IME, don't cancel it. |
| 761 | continue; |
| 762 | } |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 763 | typesReady |= InsetsState.toPublicType(consumer.getType()); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 764 | } |
Taran Singh | 85661e3 | 2020-05-07 14:45:34 -0700 | [diff] [blame] | 765 | if (DEBUG) Log.d(TAG, "show typesReady: " + typesReady); |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 766 | applyAnimation(typesReady, true /* show */, fromIme); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | @Override |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 770 | public void hide(@InsetsType int types) { |
Taran Singh | d7fc586 | 2019-10-10 14:45:17 +0200 | [diff] [blame] | 771 | hide(types, false /* fromIme */); |
| 772 | } |
| 773 | |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 774 | void hide(@InsetsType int types, boolean fromIme) { |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 775 | int typesReady = 0; |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 776 | final ArraySet<Integer> internalTypes = InsetsState.toInternalType(types); |
| 777 | for (int i = internalTypes.size() - 1; i >= 0; i--) { |
Jorim Jaggi | 1f2c7eb | 2020-01-08 00:07:13 +0100 | [diff] [blame] | 778 | @InternalInsetsType int internalType = internalTypes.valueAt(i); |
| 779 | @AnimationType int animationType = getAnimationType(internalType); |
| 780 | InsetsSourceConsumer consumer = getSourceConsumer(internalType); |
Jorim Jaggi | 3182ef1 | 2020-01-30 00:16:18 +0100 | [diff] [blame] | 781 | if (!consumer.isRequestedVisible() && animationType == ANIMATION_TYPE_NONE |
Jorim Jaggi | 1f2c7eb | 2020-01-08 00:07:13 +0100 | [diff] [blame] | 782 | || animationType == ANIMATION_TYPE_HIDE) { |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 783 | // no-op: already hidden or animating out. |
| 784 | continue; |
| 785 | } |
| 786 | typesReady |= InsetsState.toPublicType(consumer.getType()); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 787 | } |
Taran Singh | d7fc586 | 2019-10-10 14:45:17 +0200 | [diff] [blame] | 788 | applyAnimation(typesReady, false /* show */, fromIme /* fromIme */); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 789 | } |
| 790 | |
Jorim Jaggi | 5bb571d | 2018-11-06 14:42:04 +0100 | [diff] [blame] | 791 | @Override |
Adrian Roos | 5ad8cd2 | 2020-03-12 18:30:54 +0000 | [diff] [blame] | 792 | public void controlWindowInsetsAnimation(@InsetsType int types, long durationMillis, |
Jorim Jaggi | dd3304e | 2020-01-20 17:24:51 +0100 | [diff] [blame] | 793 | @Nullable Interpolator interpolator, |
Adrian Roos | 5ad8cd2 | 2020-03-12 18:30:54 +0000 | [diff] [blame] | 794 | @Nullable CancellationSignal cancellationSignal, |
Jorim Jaggi | dd3304e | 2020-01-20 17:24:51 +0100 | [diff] [blame] | 795 | @NonNull WindowInsetsAnimationControlListener listener) { |
Adrian Roos | 5ad8cd2 | 2020-03-12 18:30:54 +0000 | [diff] [blame] | 796 | controlWindowInsetsAnimation(types, cancellationSignal, listener, |
| 797 | false /* fromIme */, durationMillis, interpolator, ANIMATION_TYPE_USER); |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 798 | } |
| 799 | |
Adrian Roos | 5ad8cd2 | 2020-03-12 18:30:54 +0000 | [diff] [blame] | 800 | private void controlWindowInsetsAnimation(@InsetsType int types, |
| 801 | @Nullable CancellationSignal cancellationSignal, |
| 802 | WindowInsetsAnimationControlListener listener, |
| 803 | boolean fromIme, long durationMs, @Nullable Interpolator interpolator, |
| 804 | @AnimationType int animationType) { |
Adrian Roos | 8d04bcb | 2020-05-29 18:01:04 +0200 | [diff] [blame] | 805 | if ((mState.calculateUncontrollableInsetsFromFrame(mFrame) & types) != 0) { |
Adrian Roos | 5d557ed | 2020-03-17 20:04:35 +0100 | [diff] [blame] | 806 | listener.onCancelled(null); |
Adrian Roos | 5ad8cd2 | 2020-03-12 18:30:54 +0000 | [diff] [blame] | 807 | return; |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 808 | } |
Jorim Jaggi | 5875cca | 2020-03-17 13:44:57 +0100 | [diff] [blame] | 809 | |
Adrian Roos | 5ad8cd2 | 2020-03-12 18:30:54 +0000 | [diff] [blame] | 810 | controlAnimationUnchecked(types, cancellationSignal, listener, mFrame, fromIme, durationMs, |
Jorim Jaggi | 5875cca | 2020-03-17 13:44:57 +0100 | [diff] [blame] | 811 | interpolator, animationType, getLayoutInsetsDuringAnimationMode(types), |
Jorim Jaggi | 6d5c801 | 2020-02-28 01:40:27 +0100 | [diff] [blame] | 812 | false /* useInsetsAnimationThread */); |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 813 | } |
| 814 | |
Adrian Roos | 5ad8cd2 | 2020-03-12 18:30:54 +0000 | [diff] [blame] | 815 | private void controlAnimationUnchecked(@InsetsType int types, |
| 816 | @Nullable CancellationSignal cancellationSignal, |
Tarandeep Singh | 54554e2 | 2019-11-01 14:43:05 -0700 | [diff] [blame] | 817 | WindowInsetsAnimationControlListener listener, Rect frame, boolean fromIme, |
Jorim Jaggi | 5875cca | 2020-03-17 13:44:57 +0100 | [diff] [blame] | 818 | long durationMs, Interpolator interpolator, |
Jorim Jaggi | dd3304e | 2020-01-20 17:24:51 +0100 | [diff] [blame] | 819 | @AnimationType int animationType, |
Jorim Jaggi | 6d5c801 | 2020-02-28 01:40:27 +0100 | [diff] [blame] | 820 | @LayoutInsetsDuringAnimation int layoutInsetsDuringAnimation, |
| 821 | boolean useInsetsAnimationThread) { |
Adrian Roos | a79b885 | 2020-05-26 21:25:15 +0200 | [diff] [blame] | 822 | if ((types & mTypesBeingCancelled) != 0) { |
| 823 | throw new IllegalStateException("Cannot start a new insets animation of " |
| 824 | + Type.toString(types) |
| 825 | + " while an existing " + Type.toString(mTypesBeingCancelled) |
| 826 | + " is being cancelled."); |
| 827 | } |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 828 | if (types == 0) { |
| 829 | // nothing to animate. |
Adrian Roos | 5d557ed | 2020-03-17 20:04:35 +0100 | [diff] [blame] | 830 | listener.onCancelled(null); |
Taran Singh | 85661e3 | 2020-05-07 14:45:34 -0700 | [diff] [blame] | 831 | if (DEBUG) Log.d(TAG, "no types to animate in controlAnimationUnchecked"); |
Adrian Roos | 5ad8cd2 | 2020-03-12 18:30:54 +0000 | [diff] [blame] | 832 | return; |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 833 | } |
Jorim Jaggi | 5ed50cc | 2019-01-23 16:59:42 +0100 | [diff] [blame] | 834 | cancelExistingControllers(types); |
Taran Singh | 85661e3 | 2020-05-07 14:45:34 -0700 | [diff] [blame] | 835 | if (DEBUG) Log.d(TAG, "controlAnimation types: " + types); |
Jorim Jaggi | ed35b17 | 2020-03-06 00:13:57 +0100 | [diff] [blame] | 836 | mLastStartedAnimTypes |= types; |
Jorim Jaggi | 5ed50cc | 2019-01-23 16:59:42 +0100 | [diff] [blame] | 837 | |
Tiger Huang | 969c608 | 2019-12-24 20:08:57 +0800 | [diff] [blame] | 838 | final ArraySet<Integer> internalTypes = InsetsState.toInternalType(types); |
Yunfan Chen | 02abf55 | 2019-12-05 14:51:09 +0900 | [diff] [blame] | 839 | final SparseArray<InsetsSourceControl> controls = new SparseArray<>(); |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 840 | |
Yunfan Chen | 02abf55 | 2019-12-05 14:51:09 +0900 | [diff] [blame] | 841 | Pair<Integer, Boolean> typesReadyPair = collectSourceControls( |
Jorim Jaggi | 3182ef1 | 2020-01-30 00:16:18 +0100 | [diff] [blame] | 842 | fromIme, internalTypes, controls, animationType); |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 843 | int typesReady = typesReadyPair.first; |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 844 | boolean imeReady = typesReadyPair.second; |
Taran Singh | 85661e3 | 2020-05-07 14:45:34 -0700 | [diff] [blame] | 845 | if (DEBUG) Log.d(TAG, String.format( |
| 846 | "controlAnimationUnchecked, typesReady: %s imeReady: %s", typesReady, imeReady)); |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 847 | if (!imeReady) { |
| 848 | // IME isn't ready, all requested types will be animated once IME is ready |
| 849 | abortPendingImeControlRequest(); |
Adrian Roos | 3406fb9 | 2020-02-10 18:38:59 -0800 | [diff] [blame] | 850 | final PendingControlRequest request = new PendingControlRequest(types, |
| 851 | listener, durationMs, |
Jorim Jaggi | 6d5c801 | 2020-02-28 01:40:27 +0100 | [diff] [blame] | 852 | interpolator, animationType, layoutInsetsDuringAnimation, cancellationSignal, |
| 853 | useInsetsAnimationThread); |
Adrian Roos | 3406fb9 | 2020-02-10 18:38:59 -0800 | [diff] [blame] | 854 | mPendingImeControlRequest = request; |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 855 | mHandler.postDelayed(mPendingControlTimeout, PENDING_CONTROL_TIMEOUT_MS); |
Taran Singh | 85661e3 | 2020-05-07 14:45:34 -0700 | [diff] [blame] | 856 | if (DEBUG) Log.d(TAG, "Ime not ready. Create pending request"); |
Adrian Roos | 5ad8cd2 | 2020-03-12 18:30:54 +0000 | [diff] [blame] | 857 | if (cancellationSignal != null) { |
| 858 | cancellationSignal.setOnCancelListener(() -> { |
| 859 | if (mPendingImeControlRequest == request) { |
Taran Singh | 85661e3 | 2020-05-07 14:45:34 -0700 | [diff] [blame] | 860 | if (DEBUG) Log.d(TAG, |
| 861 | "Cancellation signal abortPendingImeControlRequest"); |
Adrian Roos | 5ad8cd2 | 2020-03-12 18:30:54 +0000 | [diff] [blame] | 862 | abortPendingImeControlRequest(); |
| 863 | } |
| 864 | }); |
| 865 | } |
| 866 | return; |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 867 | } |
| 868 | |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 869 | if (typesReady == 0) { |
Taran Singh | 85661e3 | 2020-05-07 14:45:34 -0700 | [diff] [blame] | 870 | if (DEBUG) Log.d(TAG, "No types ready. onCancelled()"); |
Adrian Roos | 5d557ed | 2020-03-17 20:04:35 +0100 | [diff] [blame] | 871 | listener.onCancelled(null); |
Adrian Roos | 5ad8cd2 | 2020-03-12 18:30:54 +0000 | [diff] [blame] | 872 | return; |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 873 | } |
| 874 | |
Jorim Jaggi | 6d5c801 | 2020-02-28 01:40:27 +0100 | [diff] [blame] | 875 | |
| 876 | final InsetsAnimationControlRunner runner = useInsetsAnimationThread |
| 877 | ? new InsetsAnimationThreadControlRunner(controls, |
Jorim Jaggi | 5875cca | 2020-03-17 13:44:57 +0100 | [diff] [blame] | 878 | frame, mState, listener, typesReady, this, durationMs, interpolator, |
Jorim Jaggi | bf87c15 | 2020-04-22 17:18:25 +0200 | [diff] [blame] | 879 | animationType, mHost.getHandler()) |
Jorim Jaggi | 6d5c801 | 2020-02-28 01:40:27 +0100 | [diff] [blame] | 880 | : new InsetsAnimationControlImpl(controls, |
Jorim Jaggi | 5875cca | 2020-03-17 13:44:57 +0100 | [diff] [blame] | 881 | frame, mState, listener, typesReady, this, durationMs, interpolator, |
Jorim Jaggi | 6d5c801 | 2020-02-28 01:40:27 +0100 | [diff] [blame] | 882 | animationType); |
| 883 | mRunningAnimations.add(new RunningAnimation(runner, animationType)); |
Taran Singh | 85661e3 | 2020-05-07 14:45:34 -0700 | [diff] [blame] | 884 | if (DEBUG) Log.d(TAG, "Animation added to runner. useInsetsAnimationThread: " |
| 885 | + useInsetsAnimationThread); |
Adrian Roos | 5ad8cd2 | 2020-03-12 18:30:54 +0000 | [diff] [blame] | 886 | if (cancellationSignal != null) { |
Adrian Roos | a79b885 | 2020-05-26 21:25:15 +0200 | [diff] [blame] | 887 | cancellationSignal.setOnCancelListener(() -> { |
| 888 | cancelAnimation(runner, true /* invokeCallback */); |
| 889 | }); |
Adrian Roos | 5ad8cd2 | 2020-03-12 18:30:54 +0000 | [diff] [blame] | 890 | } |
Jorim Jaggi | 6d5c801 | 2020-02-28 01:40:27 +0100 | [diff] [blame] | 891 | if (layoutInsetsDuringAnimation == LAYOUT_INSETS_DURING_ANIMATION_SHOWN) { |
| 892 | showDirectly(types); |
| 893 | } else { |
| 894 | hideDirectly(types, false /* animationFinished */, animationType); |
| 895 | } |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | /** |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 899 | * @return Pair of (types ready to animate, IME ready to animate). |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 900 | */ |
Yunfan Chen | 02abf55 | 2019-12-05 14:51:09 +0900 | [diff] [blame] | 901 | private Pair<Integer, Boolean> collectSourceControls(boolean fromIme, |
Jorim Jaggi | 3182ef1 | 2020-01-30 00:16:18 +0100 | [diff] [blame] | 902 | ArraySet<Integer> internalTypes, SparseArray<InsetsSourceControl> controls, |
| 903 | @AnimationType int animationType) { |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 904 | int typesReady = 0; |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 905 | boolean imeReady = true; |
Jorim Jaggi | 5bb571d | 2018-11-06 14:42:04 +0100 | [diff] [blame] | 906 | for (int i = internalTypes.size() - 1; i >= 0; i--) { |
Tarandeep Singh | b9538cd | 2020-02-20 17:51:18 -0800 | [diff] [blame] | 907 | final InsetsSourceConsumer consumer = getSourceConsumer(internalTypes.valueAt(i)); |
Jorim Jaggi | 3182ef1 | 2020-01-30 00:16:18 +0100 | [diff] [blame] | 908 | boolean show = animationType == ANIMATION_TYPE_SHOW |
| 909 | || animationType == ANIMATION_TYPE_USER; |
| 910 | boolean canRun = false; |
| 911 | if (show) { |
Taran Singh | d7fc586 | 2019-10-10 14:45:17 +0200 | [diff] [blame] | 912 | // Show request |
| 913 | switch(consumer.requestShow(fromIme)) { |
| 914 | case ShowResult.SHOW_IMMEDIATELY: |
Jorim Jaggi | 3182ef1 | 2020-01-30 00:16:18 +0100 | [diff] [blame] | 915 | canRun = true; |
Taran Singh | d7fc586 | 2019-10-10 14:45:17 +0200 | [diff] [blame] | 916 | break; |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 917 | case ShowResult.IME_SHOW_DELAYED: |
| 918 | imeReady = false; |
Taran Singh | 85661e3 | 2020-05-07 14:45:34 -0700 | [diff] [blame] | 919 | if (DEBUG) Log.d(TAG, "requestShow IME_SHOW_DELAYED"); |
Taran Singh | d7fc586 | 2019-10-10 14:45:17 +0200 | [diff] [blame] | 920 | break; |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 921 | case ShowResult.IME_SHOW_FAILED: |
Taran Singh | 85661e3 | 2020-05-07 14:45:34 -0700 | [diff] [blame] | 922 | if (WARN) Log.w(TAG, "requestShow IME_SHOW_FAILED. fromIme: " |
| 923 | + fromIme); |
Taran Singh | d7fc586 | 2019-10-10 14:45:17 +0200 | [diff] [blame] | 924 | // IME cannot be shown (since it didn't have focus), proceed |
| 925 | // with animation of other types. |
Taran Singh | d7fc586 | 2019-10-10 14:45:17 +0200 | [diff] [blame] | 926 | break; |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 927 | } |
Jorim Jaggi | 5bb571d | 2018-11-06 14:42:04 +0100 | [diff] [blame] | 928 | } else { |
Taran Singh | d7fc586 | 2019-10-10 14:45:17 +0200 | [diff] [blame] | 929 | // Hide request |
| 930 | // TODO: Move notifyHidden() to beginning of the hide animation |
| 931 | // (when visibility actually changes using hideDirectly()). |
| 932 | if (!fromIme) { |
| 933 | consumer.notifyHidden(); |
| 934 | } |
Jorim Jaggi | 3182ef1 | 2020-01-30 00:16:18 +0100 | [diff] [blame] | 935 | canRun = true; |
| 936 | } |
| 937 | if (!canRun) { |
Taran Singh | 85661e3 | 2020-05-07 14:45:34 -0700 | [diff] [blame] | 938 | if (WARN) Log.w(TAG, String.format( |
| 939 | "collectSourceControls can't continue show for type: %s fromIme: %b", |
| 940 | InsetsState.typeToString(consumer.getType()), fromIme)); |
Jorim Jaggi | 3182ef1 | 2020-01-30 00:16:18 +0100 | [diff] [blame] | 941 | continue; |
Jorim Jaggi | 5bb571d | 2018-11-06 14:42:04 +0100 | [diff] [blame] | 942 | } |
Tiger Huang | 969c608 | 2019-12-24 20:08:57 +0800 | [diff] [blame] | 943 | final InsetsSourceControl control = consumer.getControl(); |
| 944 | if (control != null) { |
Rob Carr | 3a367c4 | 2020-03-10 15:51:35 -0700 | [diff] [blame] | 945 | controls.put(consumer.getType(), new InsetsSourceControl(control)); |
Jorim Jaggi | 3182ef1 | 2020-01-30 00:16:18 +0100 | [diff] [blame] | 946 | typesReady |= toPublicType(consumer.getType()); |
| 947 | } else if (animationType == ANIMATION_TYPE_SHOW) { |
Taran Singh | 85661e3 | 2020-05-07 14:45:34 -0700 | [diff] [blame] | 948 | if (DEBUG) Log.d(TAG, "collectSourceControls no control for show(). fromIme: " |
| 949 | + fromIme); |
Jorim Jaggi | 3182ef1 | 2020-01-30 00:16:18 +0100 | [diff] [blame] | 950 | // We don't have a control at the moment. However, we still want to update requested |
| 951 | // visibility state such that in case we get control, we can apply show animation. |
| 952 | consumer.show(fromIme); |
| 953 | } else if (animationType == ANIMATION_TYPE_HIDE) { |
| 954 | consumer.hide(); |
Tiger Huang | 969c608 | 2019-12-24 20:08:57 +0800 | [diff] [blame] | 955 | } |
Jorim Jaggi | 5bb571d | 2018-11-06 14:42:04 +0100 | [diff] [blame] | 956 | } |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 957 | return new Pair<>(typesReady, imeReady); |
Jorim Jaggi | 5bb571d | 2018-11-06 14:42:04 +0100 | [diff] [blame] | 958 | } |
| 959 | |
Jorim Jaggi | a51168a | 2019-12-27 15:17:44 +0100 | [diff] [blame] | 960 | private @LayoutInsetsDuringAnimation int getLayoutInsetsDuringAnimationMode( |
| 961 | @InsetsType int types) { |
| 962 | |
| 963 | final ArraySet<Integer> internalTypes = InsetsState.toInternalType(types); |
| 964 | |
| 965 | // Generally, we want to layout the opposite of the current state. This is to make animation |
| 966 | // callbacks easy to use: The can capture the layout values and then treat that as end-state |
| 967 | // during the animation. |
| 968 | // |
| 969 | // However, if controlling multiple sources, we want to treat it as shown if any of the |
| 970 | // types is currently hidden. |
| 971 | for (int i = internalTypes.size() - 1; i >= 0; i--) { |
| 972 | InsetsSourceConsumer consumer = mSourceConsumers.get(internalTypes.valueAt(i)); |
| 973 | if (consumer == null) { |
| 974 | continue; |
| 975 | } |
| 976 | if (!consumer.isRequestedVisible()) { |
| 977 | return LAYOUT_INSETS_DURING_ANIMATION_SHOWN; |
| 978 | } |
| 979 | } |
| 980 | return LAYOUT_INSETS_DURING_ANIMATION_HIDDEN; |
| 981 | } |
| 982 | |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 983 | private void cancelExistingControllers(@InsetsType int types) { |
Adrian Roos | a79b885 | 2020-05-26 21:25:15 +0200 | [diff] [blame] | 984 | final int originalmTypesBeingCancelled = mTypesBeingCancelled; |
| 985 | mTypesBeingCancelled |= types; |
| 986 | try { |
| 987 | for (int i = mRunningAnimations.size() - 1; i >= 0; i--) { |
| 988 | InsetsAnimationControlRunner control = mRunningAnimations.get(i).runner; |
| 989 | if ((control.getTypes() & types) != 0) { |
| 990 | cancelAnimation(control, true /* invokeCallback */); |
| 991 | } |
Jorim Jaggi | 5ed50cc | 2019-01-23 16:59:42 +0100 | [diff] [blame] | 992 | } |
Adrian Roos | a79b885 | 2020-05-26 21:25:15 +0200 | [diff] [blame] | 993 | if ((types & ime()) != 0) { |
| 994 | abortPendingImeControlRequest(); |
| 995 | } |
| 996 | } finally { |
| 997 | mTypesBeingCancelled = originalmTypesBeingCancelled; |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 998 | } |
| 999 | } |
| 1000 | |
| 1001 | private void abortPendingImeControlRequest() { |
| 1002 | if (mPendingImeControlRequest != null) { |
Adrian Roos | 5d557ed | 2020-03-17 20:04:35 +0100 | [diff] [blame] | 1003 | mPendingImeControlRequest.listener.onCancelled(null); |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 1004 | mPendingImeControlRequest = null; |
| 1005 | mHandler.removeCallbacks(mPendingControlTimeout); |
Taran Singh | 85661e3 | 2020-05-07 14:45:34 -0700 | [diff] [blame] | 1006 | if (DEBUG) Log.d(TAG, "abortPendingImeControlRequest"); |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 1007 | } |
Jorim Jaggi | 5ed50cc | 2019-01-23 16:59:42 +0100 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | @VisibleForTesting |
Yunfan Chen | 02abf55 | 2019-12-05 14:51:09 +0900 | [diff] [blame] | 1011 | @Override |
Jorim Jaggi | 6d5c801 | 2020-02-28 01:40:27 +0100 | [diff] [blame] | 1012 | public void notifyFinished(InsetsAnimationControlRunner runner, boolean shown) { |
| 1013 | cancelAnimation(runner, false /* invokeCallback */); |
Taran Singh | 85661e3 | 2020-05-07 14:45:34 -0700 | [diff] [blame] | 1014 | if (DEBUG) Log.d(TAG, "notifyFinished. shown: " + shown); |
Tarandeep Singh | 54554e2 | 2019-11-01 14:43:05 -0700 | [diff] [blame] | 1015 | if (shown) { |
Jorim Jaggi | 6d5c801 | 2020-02-28 01:40:27 +0100 | [diff] [blame] | 1016 | showDirectly(runner.getTypes()); |
Tarandeep Singh | 54554e2 | 2019-11-01 14:43:05 -0700 | [diff] [blame] | 1017 | } else { |
Jorim Jaggi | 6d5c801 | 2020-02-28 01:40:27 +0100 | [diff] [blame] | 1018 | hideDirectly(runner.getTypes(), true /* animationFinished */, |
| 1019 | runner.getAnimationType()); |
Tarandeep Singh | 54554e2 | 2019-11-01 14:43:05 -0700 | [diff] [blame] | 1020 | } |
Jorim Jaggi | 5ed50cc | 2019-01-23 16:59:42 +0100 | [diff] [blame] | 1021 | } |
| 1022 | |
Yunfan Chen | 02abf55 | 2019-12-05 14:51:09 +0900 | [diff] [blame] | 1023 | @Override |
| 1024 | public void applySurfaceParams(final SyncRtSurfaceTransactionApplier.SurfaceParams... params) { |
Jorim Jaggi | bf87c15 | 2020-04-22 17:18:25 +0200 | [diff] [blame] | 1025 | mHost.applySurfaceParams(params); |
Yunfan Chen | 02abf55 | 2019-12-05 14:51:09 +0900 | [diff] [blame] | 1026 | } |
| 1027 | |
Jorim Jaggi | 5ed50cc | 2019-01-23 16:59:42 +0100 | [diff] [blame] | 1028 | void notifyControlRevoked(InsetsSourceConsumer consumer) { |
Jorim Jaggi | 1f2c7eb | 2020-01-08 00:07:13 +0100 | [diff] [blame] | 1029 | for (int i = mRunningAnimations.size() - 1; i >= 0; i--) { |
Jorim Jaggi | 6d5c801 | 2020-02-28 01:40:27 +0100 | [diff] [blame] | 1030 | InsetsAnimationControlRunner control = mRunningAnimations.get(i).runner; |
Jorim Jaggi | 5ed50cc | 2019-01-23 16:59:42 +0100 | [diff] [blame] | 1031 | if ((control.getTypes() & toPublicType(consumer.getType())) != 0) { |
Jorim Jaggi | 1f2c7eb | 2020-01-08 00:07:13 +0100 | [diff] [blame] | 1032 | cancelAnimation(control, true /* invokeCallback */); |
Jorim Jaggi | 5ed50cc | 2019-01-23 16:59:42 +0100 | [diff] [blame] | 1033 | } |
| 1034 | } |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 1035 | if (consumer.getType() == ITYPE_IME) { |
| 1036 | abortPendingImeControlRequest(); |
| 1037 | } |
Jorim Jaggi | 5ed50cc | 2019-01-23 16:59:42 +0100 | [diff] [blame] | 1038 | } |
| 1039 | |
Jorim Jaggi | 6d5c801 | 2020-02-28 01:40:27 +0100 | [diff] [blame] | 1040 | private void cancelAnimation(InsetsAnimationControlRunner control, boolean invokeCallback) { |
Taran Singh | 85661e3 | 2020-05-07 14:45:34 -0700 | [diff] [blame] | 1041 | if (DEBUG) Log.d(TAG, String.format("cancelAnimation of types: %d, animType: %d", |
| 1042 | control.getTypes(), control.getAnimationType())); |
Jorim Jaggi | 1f2c7eb | 2020-01-08 00:07:13 +0100 | [diff] [blame] | 1043 | if (invokeCallback) { |
Jorim Jaggi | 6d5c801 | 2020-02-28 01:40:27 +0100 | [diff] [blame] | 1044 | control.cancel(); |
Jorim Jaggi | 1f2c7eb | 2020-01-08 00:07:13 +0100 | [diff] [blame] | 1045 | } |
| 1046 | for (int i = mRunningAnimations.size() - 1; i >= 0; i--) { |
Jorim Jaggi | 33a2183 | 2020-04-06 14:15:46 +0200 | [diff] [blame] | 1047 | RunningAnimation runningAnimation = mRunningAnimations.get(i); |
| 1048 | if (runningAnimation.runner == control) { |
Jorim Jaggi | 1f2c7eb | 2020-01-08 00:07:13 +0100 | [diff] [blame] | 1049 | mRunningAnimations.remove(i); |
Jorim Jaggi | 33a2183 | 2020-04-06 14:15:46 +0200 | [diff] [blame] | 1050 | ArraySet<Integer> types = toInternalType(control.getTypes()); |
| 1051 | for (int j = types.size() - 1; j >= 0; j--) { |
| 1052 | if (getSourceConsumer(types.valueAt(j)).notifyAnimationFinished()) { |
Jorim Jaggi | bf87c15 | 2020-04-22 17:18:25 +0200 | [diff] [blame] | 1053 | mHost.notifyInsetsChanged(); |
Jorim Jaggi | 33a2183 | 2020-04-06 14:15:46 +0200 | [diff] [blame] | 1054 | } |
| 1055 | } |
Adrian Roos | a79b885 | 2020-05-26 21:25:15 +0200 | [diff] [blame] | 1056 | if (invokeCallback && runningAnimation.startDispatched) { |
| 1057 | dispatchAnimationEnd(runningAnimation.runner.getAnimation()); |
| 1058 | } |
Jorim Jaggi | 1f2c7eb | 2020-01-08 00:07:13 +0100 | [diff] [blame] | 1059 | break; |
| 1060 | } |
| 1061 | } |
Jorim Jaggi | 5ed50cc | 2019-01-23 16:59:42 +0100 | [diff] [blame] | 1062 | } |
| 1063 | |
Jorim Jaggi | c8d6038 | 2018-10-31 17:06:06 +0100 | [diff] [blame] | 1064 | private void applyLocalVisibilityOverride() { |
| 1065 | for (int i = mSourceConsumers.size() - 1; i >= 0; i--) { |
| 1066 | final InsetsSourceConsumer controller = mSourceConsumers.valueAt(i); |
| 1067 | controller.applyLocalVisibilityOverride(); |
| 1068 | } |
| 1069 | } |
| 1070 | |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 1071 | @VisibleForTesting |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 1072 | public @NonNull InsetsSourceConsumer getSourceConsumer(@InternalInsetsType int type) { |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 1073 | InsetsSourceConsumer controller = mSourceConsumers.get(type); |
| 1074 | if (controller != null) { |
| 1075 | return controller; |
| 1076 | } |
Jorim Jaggi | d7f10ed | 2020-01-08 21:41:55 +0100 | [diff] [blame] | 1077 | controller = mConsumerCreator.apply(this, type); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 1078 | mSourceConsumers.put(type, controller); |
| 1079 | return controller; |
| 1080 | } |
| 1081 | |
Jorim Jaggi | 5bb571d | 2018-11-06 14:42:04 +0100 | [diff] [blame] | 1082 | @VisibleForTesting |
| 1083 | public void notifyVisibilityChanged() { |
Jorim Jaggi | bf87c15 | 2020-04-22 17:18:25 +0200 | [diff] [blame] | 1084 | mHost.notifyInsetsChanged(); |
Tiger Huang | 173480f | 2020-04-29 01:05:42 +0800 | [diff] [blame] | 1085 | updateRequestedState(); |
Jorim Jaggi | e35c059 | 2018-11-06 16:21:08 +0100 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | /** |
Tiger Huang | 2ab590a | 2020-05-19 21:55:13 +0800 | [diff] [blame] | 1089 | * @see ViewRootImpl#updateCompatSysUiVisibility(int, boolean, boolean) |
| 1090 | */ |
| 1091 | public void updateCompatSysUiVisibility(@InternalInsetsType int type, boolean visible, |
| 1092 | boolean hasControl) { |
| 1093 | mHost.updateCompatSysUiVisibility(type, visible, hasControl); |
| 1094 | } |
| 1095 | |
| 1096 | /** |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 1097 | * Called when current window gains focus. |
| 1098 | */ |
| 1099 | public void onWindowFocusGained() { |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 1100 | getSourceConsumer(ITYPE_IME).onWindowFocusGained(); |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | /** |
| 1104 | * Called when current window loses focus. |
| 1105 | */ |
| 1106 | public void onWindowFocusLost() { |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 1107 | getSourceConsumer(ITYPE_IME).onWindowFocusLost(); |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 1108 | } |
| 1109 | |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 1110 | /** |
| 1111 | * Used by {@link ImeInsetsSourceConsumer} when IME decides to be shown/hidden. |
| 1112 | * @hide |
| 1113 | */ |
| 1114 | @VisibleForTesting |
| 1115 | public void applyImeVisibility(boolean setVisible) { |
| 1116 | if (setVisible) { |
| 1117 | show(Type.IME, true /* fromIme */); |
| 1118 | } else { |
| 1119 | hide(Type.IME); |
| 1120 | } |
| 1121 | } |
| 1122 | |
Jorim Jaggi | 1f2c7eb | 2020-01-08 00:07:13 +0100 | [diff] [blame] | 1123 | @VisibleForTesting |
| 1124 | public @AnimationType int getAnimationType(@InternalInsetsType int type) { |
| 1125 | for (int i = mRunningAnimations.size() - 1; i >= 0; i--) { |
Jorim Jaggi | 6d5c801 | 2020-02-28 01:40:27 +0100 | [diff] [blame] | 1126 | InsetsAnimationControlRunner control = mRunningAnimations.get(i).runner; |
Jorim Jaggi | 1f2c7eb | 2020-01-08 00:07:13 +0100 | [diff] [blame] | 1127 | if (control.controlsInternalType(type)) { |
| 1128 | return mRunningAnimations.get(i).type; |
| 1129 | } |
| 1130 | } |
| 1131 | return ANIMATION_TYPE_NONE; |
Tarandeep Singh | 93ea15a | 2019-11-26 11:09:14 -0800 | [diff] [blame] | 1132 | } |
| 1133 | |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 1134 | /** |
Tiger Huang | 173480f | 2020-04-29 01:05:42 +0800 | [diff] [blame] | 1135 | * Sends the local visibility state back to window manager if it is changed. |
Jorim Jaggi | e35c059 | 2018-11-06 16:21:08 +0100 | [diff] [blame] | 1136 | */ |
Tiger Huang | 173480f | 2020-04-29 01:05:42 +0800 | [diff] [blame] | 1137 | private void updateRequestedState() { |
| 1138 | boolean changed = false; |
Jorim Jaggi | e35c059 | 2018-11-06 16:21:08 +0100 | [diff] [blame] | 1139 | for (int i = mSourceConsumers.size() - 1; i >= 0; i--) { |
| 1140 | final InsetsSourceConsumer consumer = mSourceConsumers.valueAt(i); |
Tiger Huang | 173480f | 2020-04-29 01:05:42 +0800 | [diff] [blame] | 1141 | final @InternalInsetsType int type = consumer.getType(); |
| 1142 | if (type == ITYPE_CAPTION_BAR) { |
| 1143 | continue; |
| 1144 | } |
Jorim Jaggi | e35c059 | 2018-11-06 16:21:08 +0100 | [diff] [blame] | 1145 | if (consumer.getControl() != null) { |
Tiger Huang | 173480f | 2020-04-29 01:05:42 +0800 | [diff] [blame] | 1146 | final InsetsSource localSource = mState.getSource(type); |
| 1147 | if (!localSource.equals(mRequestedState.peekSource(type))) { |
Tiger Huang | fbfc3ab | 2020-05-06 01:02:31 +0800 | [diff] [blame] | 1148 | // Our requested state is stale. Update it here and send it to window manager. |
Tiger Huang | 173480f | 2020-04-29 01:05:42 +0800 | [diff] [blame] | 1149 | mRequestedState.addSource(new InsetsSource(localSource)); |
| 1150 | changed = true; |
| 1151 | } |
Tiger Huang | fbfc3ab | 2020-05-06 01:02:31 +0800 | [diff] [blame] | 1152 | if (!localSource.equals(mLastDispatchedState.peekSource(type))) { |
| 1153 | // The server state is not what we expected. This can happen while we don't have |
| 1154 | // the control. Since we have the control now, we need to send our request again |
| 1155 | // to modify the server state. |
| 1156 | changed = true; |
| 1157 | } |
Jorim Jaggi | e35c059 | 2018-11-06 16:21:08 +0100 | [diff] [blame] | 1158 | } |
| 1159 | } |
Tiger Huang | 173480f | 2020-04-29 01:05:42 +0800 | [diff] [blame] | 1160 | if (!changed) { |
| 1161 | return; |
| 1162 | } |
| 1163 | mHost.onInsetsModified(mRequestedState); |
Jorim Jaggi | c8d6038 | 2018-10-31 17:06:06 +0100 | [diff] [blame] | 1164 | } |
| 1165 | |
Taran Singh | 8321a2a4 | 2020-04-21 17:26:50 -0700 | [diff] [blame] | 1166 | @VisibleForTesting |
| 1167 | public void applyAnimation(@InsetsType final int types, boolean show, boolean fromIme) { |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 1168 | if (types == 0) { |
| 1169 | // nothing to animate. |
Taran Singh | 85661e3 | 2020-05-07 14:45:34 -0700 | [diff] [blame] | 1170 | if (DEBUG) Log.d(TAG, "applyAnimation, nothing to animate"); |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 1171 | return; |
| 1172 | } |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 1173 | |
Jorim Jaggi | bf87c15 | 2020-04-22 17:18:25 +0200 | [diff] [blame] | 1174 | boolean hasAnimationCallbacks = mHost.hasAnimationCallbacks(); |
Tiger Huang | f232119 | 2020-05-21 22:16:14 +0800 | [diff] [blame] | 1175 | final InternalAnimationControlListener listener = new InternalAnimationControlListener( |
| 1176 | show, hasAnimationCallbacks, types, mAnimationsDisabled); |
Jorim Jaggi | 5875cca | 2020-03-17 13:44:57 +0100 | [diff] [blame] | 1177 | |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 1178 | // Show/hide animations always need to be relative to the display frame, in order that shown |
| 1179 | // and hidden state insets are correct. |
Tarandeep Singh | 54554e2 | 2019-11-01 14:43:05 -0700 | [diff] [blame] | 1180 | controlAnimationUnchecked( |
Adrian Roos | 5ad8cd2 | 2020-03-12 18:30:54 +0000 | [diff] [blame] | 1181 | types, null /* cancellationSignal */, listener, mState.getDisplayFrame(), fromIme, |
Jorim Jaggi | 5875cca | 2020-03-17 13:44:57 +0100 | [diff] [blame] | 1182 | listener.getDurationMs(), listener.getInterpolator(), |
| 1183 | show ? ANIMATION_TYPE_SHOW : ANIMATION_TYPE_HIDE, |
| 1184 | show ? LAYOUT_INSETS_DURING_ANIMATION_SHOWN : LAYOUT_INSETS_DURING_ANIMATION_HIDDEN, |
| 1185 | !hasAnimationCallbacks /* useInsetsAnimationThread */); |
| 1186 | |
Jorim Jaggi | 6d5c801 | 2020-02-28 01:40:27 +0100 | [diff] [blame] | 1187 | } |
| 1188 | |
Tarandeep Singh | b9538cd | 2020-02-20 17:51:18 -0800 | [diff] [blame] | 1189 | private void hideDirectly( |
| 1190 | @InsetsType int types, boolean animationFinished, @AnimationType int animationType) { |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 1191 | final ArraySet<Integer> internalTypes = InsetsState.toInternalType(types); |
| 1192 | for (int i = internalTypes.size() - 1; i >= 0; i--) { |
Tarandeep Singh | b9538cd | 2020-02-20 17:51:18 -0800 | [diff] [blame] | 1193 | getSourceConsumer(internalTypes.valueAt(i)).hide(animationFinished, animationType); |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 1194 | } |
| 1195 | } |
| 1196 | |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 1197 | private void showDirectly(@InsetsType int types) { |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 1198 | final ArraySet<Integer> internalTypes = InsetsState.toInternalType(types); |
| 1199 | for (int i = internalTypes.size() - 1; i >= 0; i--) { |
Jorim Jaggi | 3182ef1 | 2020-01-30 00:16:18 +0100 | [diff] [blame] | 1200 | getSourceConsumer(internalTypes.valueAt(i)).show(false /* fromIme */); |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 1201 | } |
| 1202 | } |
| 1203 | |
| 1204 | /** |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 1205 | * Cancel on-going animation to show/hide {@link InsetsType}. |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 1206 | */ |
| 1207 | @VisibleForTesting |
Jorim Jaggi | 31e5254 | 2020-05-04 23:23:25 +0200 | [diff] [blame] | 1208 | public void cancelExistingAnimations() { |
Jorim Jaggi | 5ed50cc | 2019-01-23 16:59:42 +0100 | [diff] [blame] | 1209 | cancelExistingControllers(all()); |
Tarandeep Singh | 22f2b4c | 2019-01-10 19:41:30 -0800 | [diff] [blame] | 1210 | } |
| 1211 | |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 1212 | void dump(String prefix, PrintWriter pw) { |
| 1213 | pw.println(prefix); pw.println("InsetsController:"); |
| 1214 | mState.dump(prefix + " ", pw); |
| 1215 | } |
Jorim Jaggi | 02a741f | 2018-12-12 17:40:19 -0800 | [diff] [blame] | 1216 | |
Jorim Jaggi | fae3e27 | 2019-01-14 14:05:05 +0100 | [diff] [blame] | 1217 | @VisibleForTesting |
Yunfan Chen | 02abf55 | 2019-12-05 14:51:09 +0900 | [diff] [blame] | 1218 | @Override |
Jorim Jaggi | a51168a | 2019-12-27 15:17:44 +0100 | [diff] [blame] | 1219 | public void startAnimation(InsetsAnimationControlImpl controller, |
Adrian Roos | db5b0c2 | 2020-02-12 15:05:27 -0800 | [diff] [blame] | 1220 | WindowInsetsAnimationControlListener listener, int types, |
Jorim Jaggi | 6d5c801 | 2020-02-28 01:40:27 +0100 | [diff] [blame] | 1221 | WindowInsetsAnimation animation, Bounds bounds) { |
Jorim Jaggi | bf87c15 | 2020-04-22 17:18:25 +0200 | [diff] [blame] | 1222 | mHost.dispatchWindowInsetsAnimationPrepare(animation); |
| 1223 | mHost.addOnPreDrawRunnable(() -> { |
| 1224 | if (controller.isCancelled()) { |
Taran Singh | 85661e3 | 2020-05-07 14:45:34 -0700 | [diff] [blame] | 1225 | if (WARN) Log.w(TAG, "startAnimation canceled before preDraw"); |
Jorim Jaggi | bf87c15 | 2020-04-22 17:18:25 +0200 | [diff] [blame] | 1226 | return; |
Jorim Jaggi | a51168a | 2019-12-27 15:17:44 +0100 | [diff] [blame] | 1227 | } |
Jorim Jaggi | cb28ae6 | 2020-05-14 17:46:32 +0200 | [diff] [blame] | 1228 | Trace.asyncTraceBegin(Trace.TRACE_TAG_VIEW, |
| 1229 | "InsetsAnimation: " + WindowInsets.Type.toString(types), types); |
Jorim Jaggi | bf87c15 | 2020-04-22 17:18:25 +0200 | [diff] [blame] | 1230 | for (int i = mRunningAnimations.size() - 1; i >= 0; i--) { |
| 1231 | RunningAnimation runningAnimation = mRunningAnimations.get(i); |
| 1232 | if (runningAnimation.runner == controller) { |
| 1233 | runningAnimation.startDispatched = true; |
| 1234 | } |
| 1235 | } |
| 1236 | mHost.dispatchWindowInsetsAnimationStart(animation, bounds); |
| 1237 | mStartingAnimation = true; |
| 1238 | controller.mReadyDispatched = true; |
| 1239 | listener.onReady(controller, types); |
| 1240 | mStartingAnimation = false; |
Jorim Jaggi | a51168a | 2019-12-27 15:17:44 +0100 | [diff] [blame] | 1241 | }); |
Jorim Jaggi | 02a741f | 2018-12-12 17:40:19 -0800 | [diff] [blame] | 1242 | } |
| 1243 | |
Jorim Jaggi | fae3e27 | 2019-01-14 14:05:05 +0100 | [diff] [blame] | 1244 | @VisibleForTesting |
Adrian Roos | db5b0c2 | 2020-02-12 15:05:27 -0800 | [diff] [blame] | 1245 | public void dispatchAnimationEnd(WindowInsetsAnimation animation) { |
Jorim Jaggi | cb28ae6 | 2020-05-14 17:46:32 +0200 | [diff] [blame] | 1246 | Trace.asyncTraceEnd(Trace.TRACE_TAG_VIEW, |
| 1247 | "InsetsAnimation: " + WindowInsets.Type.toString(animation.getTypeMask()), |
| 1248 | animation.getTypeMask()); |
Jorim Jaggi | bf87c15 | 2020-04-22 17:18:25 +0200 | [diff] [blame] | 1249 | mHost.dispatchWindowInsetsAnimationEnd(animation); |
Jorim Jaggi | 02a741f | 2018-12-12 17:40:19 -0800 | [diff] [blame] | 1250 | } |
| 1251 | |
Jorim Jaggi | fae3e27 | 2019-01-14 14:05:05 +0100 | [diff] [blame] | 1252 | @VisibleForTesting |
Yunfan Chen | 02abf55 | 2019-12-05 14:51:09 +0900 | [diff] [blame] | 1253 | @Override |
Adrian Roos | 6a4448f | 2020-04-01 15:01:08 +0200 | [diff] [blame] | 1254 | public void scheduleApplyChangeInsets(InsetsAnimationControlRunner runner) { |
| 1255 | if (mStartingAnimation || runner.getAnimationType() == ANIMATION_TYPE_USER) { |
Jorim Jaggi | a51168a | 2019-12-27 15:17:44 +0100 | [diff] [blame] | 1256 | mAnimCallback.run(); |
| 1257 | mAnimCallbackScheduled = false; |
| 1258 | return; |
| 1259 | } |
Jorim Jaggi | 02a741f | 2018-12-12 17:40:19 -0800 | [diff] [blame] | 1260 | if (!mAnimCallbackScheduled) { |
Jorim Jaggi | bf87c15 | 2020-04-22 17:18:25 +0200 | [diff] [blame] | 1261 | mHost.postInsetsAnimationCallback(mAnimCallback); |
Jorim Jaggi | 02a741f | 2018-12-12 17:40:19 -0800 | [diff] [blame] | 1262 | mAnimCallbackScheduled = true; |
| 1263 | } |
| 1264 | } |
Jorim Jaggi | b7848b7 | 2018-12-28 14:38:21 +0100 | [diff] [blame] | 1265 | |
| 1266 | @Override |
Tiger Huang | 7238a05 | 2020-01-10 20:37:01 +0800 | [diff] [blame] | 1267 | public void setSystemBarsAppearance(@Appearance int appearance, @Appearance int mask) { |
Jorim Jaggi | bf87c15 | 2020-04-22 17:18:25 +0200 | [diff] [blame] | 1268 | mHost.setSystemBarsAppearance(appearance, mask); |
Jorim Jaggi | b7848b7 | 2018-12-28 14:38:21 +0100 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | @Override |
Tiger Huang | 7238a05 | 2020-01-10 20:37:01 +0800 | [diff] [blame] | 1272 | public @Appearance int getSystemBarsAppearance() { |
Jorim Jaggi | bf87c15 | 2020-04-22 17:18:25 +0200 | [diff] [blame] | 1273 | return mHost.getSystemBarsAppearance(); |
Tiger Huang | 7238a05 | 2020-01-10 20:37:01 +0800 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | @Override |
Yunfan Chen | fae0aea | 2020-02-22 20:57:57 +0900 | [diff] [blame] | 1277 | public void setCaptionInsetsHeight(int height) { |
| 1278 | mCaptionInsetsHeight = height; |
| 1279 | } |
| 1280 | |
| 1281 | @Override |
Jorim Jaggi | b7848b7 | 2018-12-28 14:38:21 +0100 | [diff] [blame] | 1282 | public void setSystemBarsBehavior(@Behavior int behavior) { |
Jorim Jaggi | bf87c15 | 2020-04-22 17:18:25 +0200 | [diff] [blame] | 1283 | mHost.setSystemBarsBehavior(behavior); |
Jorim Jaggi | b7848b7 | 2018-12-28 14:38:21 +0100 | [diff] [blame] | 1284 | } |
Tiger Huang | 7238a05 | 2020-01-10 20:37:01 +0800 | [diff] [blame] | 1285 | |
| 1286 | @Override |
| 1287 | public @Appearance int getSystemBarsBehavior() { |
Jorim Jaggi | bf87c15 | 2020-04-22 17:18:25 +0200 | [diff] [blame] | 1288 | return mHost.getSystemBarsBehavior(); |
Tiger Huang | 7238a05 | 2020-01-10 20:37:01 +0800 | [diff] [blame] | 1289 | } |
Rob Carr | 521e363 | 2020-03-09 11:22:30 -0700 | [diff] [blame] | 1290 | |
Tiger Huang | f232119 | 2020-05-21 22:16:14 +0800 | [diff] [blame] | 1291 | @Override |
| 1292 | public void setAnimationsDisabled(boolean disable) { |
| 1293 | mAnimationsDisabled = disable; |
| 1294 | } |
| 1295 | |
Jorim Jaggi | ed35b17 | 2020-03-06 00:13:57 +0100 | [diff] [blame] | 1296 | private @InsetsType int calculateControllableTypes() { |
Jorim Jaggi | ed35b17 | 2020-03-06 00:13:57 +0100 | [diff] [blame] | 1297 | @InsetsType int result = 0; |
| 1298 | for (int i = mSourceConsumers.size() - 1; i >= 0; i--) { |
| 1299 | InsetsSourceConsumer consumer = mSourceConsumers.valueAt(i); |
Yohei Yukawa | f35971d | 2020-06-16 21:31:35 +0000 | [diff] [blame] | 1300 | if (consumer.getControl() != null) { |
Jorim Jaggi | ed35b17 | 2020-03-06 00:13:57 +0100 | [diff] [blame] | 1301 | result |= toPublicType(consumer.mType); |
| 1302 | } |
| 1303 | } |
Adrian Roos | 8d04bcb | 2020-05-29 18:01:04 +0200 | [diff] [blame] | 1304 | return result & ~mState.calculateUncontrollableInsetsFromFrame(mFrame); |
Jorim Jaggi | ed35b17 | 2020-03-06 00:13:57 +0100 | [diff] [blame] | 1305 | } |
| 1306 | |
| 1307 | /** |
| 1308 | * @return The types that are now animating due to a listener invoking control/show/hide |
| 1309 | */ |
| 1310 | private @InsetsType int invokeControllableInsetsChangedListeners() { |
| 1311 | mLastStartedAnimTypes = 0; |
| 1312 | @InsetsType int types = calculateControllableTypes(); |
| 1313 | int size = mControllableInsetsChangedListeners.size(); |
| 1314 | for (int i = 0; i < size; i++) { |
| 1315 | mControllableInsetsChangedListeners.get(i).onControllableInsetsChanged(this, types); |
| 1316 | } |
| 1317 | return mLastStartedAnimTypes; |
| 1318 | } |
| 1319 | |
| 1320 | @Override |
| 1321 | public void addOnControllableInsetsChangedListener( |
| 1322 | OnControllableInsetsChangedListener listener) { |
| 1323 | Objects.requireNonNull(listener); |
| 1324 | mControllableInsetsChangedListeners.add(listener); |
| 1325 | listener.onControllableInsetsChanged(this, calculateControllableTypes()); |
| 1326 | } |
| 1327 | |
| 1328 | @Override |
| 1329 | public void removeOnControllableInsetsChangedListener( |
| 1330 | OnControllableInsetsChangedListener listener) { |
| 1331 | Objects.requireNonNull(listener); |
| 1332 | mControllableInsetsChangedListeners.remove(listener); |
| 1333 | } |
| 1334 | |
Jorim Jaggi | bf87c15 | 2020-04-22 17:18:25 +0200 | [diff] [blame] | 1335 | @Override |
Rob Carr | 521e363 | 2020-03-09 11:22:30 -0700 | [diff] [blame] | 1336 | public void releaseSurfaceControlFromRt(SurfaceControl sc) { |
Jorim Jaggi | bf87c15 | 2020-04-22 17:18:25 +0200 | [diff] [blame] | 1337 | mHost.releaseSurfaceControlFromRt(sc); |
| 1338 | } |
| 1339 | |
| 1340 | Host getHost() { |
| 1341 | return mHost; |
Rob Carr | 521e363 | 2020-03-09 11:22:30 -0700 | [diff] [blame] | 1342 | } |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 1343 | } |