blob: cd56ca9251abea2bfc90834790b810e3498984e8 [file] [log] [blame]
Jorim Jaggi5bb571d2018-11-06 14:42:04 +01001/*
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
17package android.view;
18
Tarandeep Singhb9538cd2020-02-20 17:51:18 -080019import static android.view.InsetsController.AnimationType;
Taran Singh85661e32020-05-07 14:45:34 -070020import static android.view.InsetsController.DEBUG;
Tiger Huang332793b2019-10-29 23:21:27 +080021import static android.view.InsetsState.ISIDE_BOTTOM;
22import static android.view.InsetsState.ISIDE_FLOATING;
23import static android.view.InsetsState.ISIDE_LEFT;
24import static android.view.InsetsState.ISIDE_RIGHT;
25import static android.view.InsetsState.ISIDE_TOP;
Jorim Jaggi5bb571d2018-11-06 14:42:04 +010026
Adrian Roos53989972020-03-19 20:15:57 +010027import static com.android.internal.annotations.VisibleForTesting.Visibility.PACKAGE;
28
Jorim Jaggi5bb571d2018-11-06 14:42:04 +010029import android.annotation.Nullable;
30import android.graphics.Insets;
31import android.graphics.Matrix;
32import android.graphics.Rect;
Jorim Jaggi5bb571d2018-11-06 14:42:04 +010033import android.util.ArraySet;
Taran Singh85661e32020-05-07 14:45:34 -070034import android.util.Log;
Jorim Jaggi5bb571d2018-11-06 14:42:04 +010035import android.util.SparseArray;
36import android.util.SparseIntArray;
37import android.util.SparseSetArray;
Tiger Huang332793b2019-10-29 23:21:27 +080038import android.view.InsetsState.InternalInsetsSide;
Jorim Jaggi5bb571d2018-11-06 14:42:04 +010039import android.view.SyncRtSurfaceTransactionApplier.SurfaceParams;
Tiger Huang332793b2019-10-29 23:21:27 +080040import android.view.WindowInsets.Type.InsetsType;
Adrian Roosdb5b0c22020-02-12 15:05:27 -080041import android.view.WindowInsetsAnimation.Bounds;
Jorim Jaggi648e5882019-01-24 13:24:02 +010042import android.view.WindowManager.LayoutParams;
Jorim Jaggidd3304e2020-01-20 17:24:51 +010043import android.view.animation.Interpolator;
Jorim Jaggi5bb571d2018-11-06 14:42:04 +010044
45import com.android.internal.annotations.VisibleForTesting;
46
47import java.util.ArrayList;
Jorim Jaggi5bb571d2018-11-06 14:42:04 +010048
49/**
50 * Implements {@link WindowInsetsAnimationController}
51 * @hide
52 */
53@VisibleForTesting
Jorim Jaggi6d5c8012020-02-28 01:40:27 +010054public class InsetsAnimationControlImpl implements WindowInsetsAnimationController,
55 InsetsAnimationControlRunner {
Jorim Jaggi02a741f2018-12-12 17:40:19 -080056
Taran Singh85661e32020-05-07 14:45:34 -070057 private static final String TAG = "InsetsAnimationCtrlImpl";
58
Jorim Jaggi02a741f2018-12-12 17:40:19 -080059 private final Rect mTmpFrame = new Rect();
Jorim Jaggi5bb571d2018-11-06 14:42:04 +010060
61 private final WindowInsetsAnimationControlListener mListener;
Yunfan Chen02abf552019-12-05 14:51:09 +090062 private final SparseArray<InsetsSourceControl> mControls;
Jorim Jaggi5bb571d2018-11-06 14:42:04 +010063 private final SparseIntArray mTypeSideMap = new SparseIntArray();
Yunfan Chen02abf552019-12-05 14:51:09 +090064 private final SparseSetArray<InsetsSourceControl> mSideSourceMap = new SparseSetArray<>();
Jorim Jaggi5bb571d2018-11-06 14:42:04 +010065
66 /** @see WindowInsetsAnimationController#getHiddenStateInsets */
67 private final Insets mHiddenInsets;
68
69 /** @see WindowInsetsAnimationController#getShownStateInsets */
70 private final Insets mShownInsets;
71 private final Matrix mTmpMatrix = new Matrix();
72 private final InsetsState mInitialInsetsState;
Tarandeep Singhb9538cd2020-02-20 17:51:18 -080073 private final @AnimationType int mAnimationType;
Tiger Huang332793b2019-10-29 23:21:27 +080074 private final @InsetsType int mTypes;
Yunfan Chen02abf552019-12-05 14:51:09 +090075 private final InsetsAnimationControlCallbacks mController;
Adrian Roosdb5b0c22020-02-12 15:05:27 -080076 private final WindowInsetsAnimation mAnimation;
Jorim Jaggi5bb571d2018-11-06 14:42:04 +010077 private Insets mCurrentInsets;
Jorim Jaggi02a741f2018-12-12 17:40:19 -080078 private Insets mPendingInsets;
Tarandeep Singh54554e22019-11-01 14:43:05 -070079 private float mPendingFraction;
Jorim Jaggi5ed50cc2019-01-23 16:59:42 +010080 private boolean mFinished;
81 private boolean mCancelled;
Tarandeep Singh54554e22019-11-01 14:43:05 -070082 private boolean mShownOnFinish;
Jorim Jaggi580aef52020-02-26 18:28:28 +010083 private float mCurrentAlpha = 1.0f;
84 private float mPendingAlpha = 1.0f;
Adrian Roos53989972020-03-19 20:15:57 +010085 @VisibleForTesting(visibility = PACKAGE)
86 public boolean mReadyDispatched;
Jorim Jaggi5bb571d2018-11-06 14:42:04 +010087
88 @VisibleForTesting
Yunfan Chen02abf552019-12-05 14:51:09 +090089 public InsetsAnimationControlImpl(SparseArray<InsetsSourceControl> controls, Rect frame,
Jorim Jaggi5bb571d2018-11-06 14:42:04 +010090 InsetsState state, WindowInsetsAnimationControlListener listener,
Tiger Huang332793b2019-10-29 23:21:27 +080091 @InsetsType int types,
Jorim Jaggidd3304e2020-01-20 17:24:51 +010092 InsetsAnimationControlCallbacks controller, long durationMs, Interpolator interpolator,
Jorim Jaggi5875cca2020-03-17 13:44:57 +010093 @AnimationType int animationType) {
Yunfan Chen02abf552019-12-05 14:51:09 +090094 mControls = controls;
Jorim Jaggi5bb571d2018-11-06 14:42:04 +010095 mListener = listener;
96 mTypes = types;
Jorim Jaggi02a741f2018-12-12 17:40:19 -080097 mController = controller;
98 mInitialInsetsState = new InsetsState(state, true /* copySources */);
Jorim Jaggi5bb571d2018-11-06 14:42:04 +010099 mCurrentInsets = getInsetsFromState(mInitialInsetsState, frame, null /* typeSideMap */);
Jorim Jaggi1f2c7eb2020-01-08 00:07:13 +0100100 mPendingInsets = mCurrentInsets;
Yunfan Chen02abf552019-12-05 14:51:09 +0900101 mHiddenInsets = calculateInsets(mInitialInsetsState, frame, controls, false /* shown */,
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100102 null /* typeSideMap */);
Yunfan Chen02abf552019-12-05 14:51:09 +0900103 mShownInsets = calculateInsets(mInitialInsetsState, frame, controls, true /* shown */,
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100104 mTypeSideMap);
Yunfan Chen02abf552019-12-05 14:51:09 +0900105 buildTypeSourcesMap(mTypeSideMap, mSideSourceMap, mControls);
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100106
Adrian Roosdb5b0c22020-02-12 15:05:27 -0800107 mAnimation = new WindowInsetsAnimation(mTypes, interpolator,
Jorim Jaggidd3304e2020-01-20 17:24:51 +0100108 durationMs);
Tarandeep Singh699aa672019-11-22 23:19:30 -0800109 mAnimation.setAlpha(getCurrentAlpha());
Tarandeep Singhb9538cd2020-02-20 17:51:18 -0800110 mAnimationType = animationType;
Jorim Jaggia51168a2019-12-27 15:17:44 +0100111 mController.startAnimation(this, listener, types, mAnimation,
Jorim Jaggi6d5c8012020-02-28 01:40:27 +0100112 new Bounds(mHiddenInsets, mShownInsets));
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100113 }
114
115 @Override
116 public Insets getHiddenStateInsets() {
117 return mHiddenInsets;
118 }
119
120 @Override
121 public Insets getShownStateInsets() {
122 return mShownInsets;
123 }
124
125 @Override
126 public Insets getCurrentInsets() {
127 return mCurrentInsets;
128 }
129
130 @Override
Tarandeep Singh699aa672019-11-22 23:19:30 -0800131 public float getCurrentAlpha() {
132 return mCurrentAlpha;
133 }
134
135 @Override
Tiger Huang332793b2019-10-29 23:21:27 +0800136 @InsetsType public int getTypes() {
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100137 return mTypes;
138 }
139
Jorim Jaggi6d5c8012020-02-28 01:40:27 +0100140 @Override
141 public @AnimationType int getAnimationType() {
Tarandeep Singhb9538cd2020-02-20 17:51:18 -0800142 return mAnimationType;
143 }
144
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100145 @Override
Tarandeep Singh54554e22019-11-01 14:43:05 -0700146 public void setInsetsAndAlpha(Insets insets, float alpha, float fraction) {
Jorim Jaggif1035882020-03-31 22:47:12 +0200147 setInsetsAndAlpha(insets, alpha, fraction, false /* allowWhenFinished */);
148 }
149
150 private void setInsetsAndAlpha(Insets insets, float alpha, float fraction,
151 boolean allowWhenFinished) {
152 if (!allowWhenFinished && mFinished) {
Jorim Jaggi5ed50cc2019-01-23 16:59:42 +0100153 throw new IllegalStateException(
154 "Can't change insets on an animation that is finished.");
155 }
156 if (mCancelled) {
157 throw new IllegalStateException(
158 "Can't change insets on an animation that is cancelled.");
159 }
Tarandeep Singh54554e22019-11-01 14:43:05 -0700160 mPendingFraction = sanitize(fraction);
Jorim Jaggi02a741f2018-12-12 17:40:19 -0800161 mPendingInsets = sanitize(insets);
Jorim Jaggi580aef52020-02-26 18:28:28 +0100162 mPendingAlpha = sanitize(alpha);
Adrian Roos6a4448f2020-04-01 15:01:08 +0200163 mController.scheduleApplyChangeInsets(this);
Jorim Jaggi02a741f2018-12-12 17:40:19 -0800164 }
165
Jorim Jaggifae3e272019-01-14 14:05:05 +0100166 @VisibleForTesting
Jorim Jaggi5ed50cc2019-01-23 16:59:42 +0100167 /**
168 * @return Whether the finish callback of this animation should be invoked.
169 */
170 public boolean applyChangeInsets(InsetsState state) {
171 if (mCancelled) {
Taran Singh85661e32020-05-07 14:45:34 -0700172 if (DEBUG) Log.d(TAG, "applyChangeInsets canceled");
Jorim Jaggi5ed50cc2019-01-23 16:59:42 +0100173 return false;
174 }
Jorim Jaggi02a741f2018-12-12 17:40:19 -0800175 final Insets offset = Insets.subtract(mShownInsets, mPendingInsets);
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100176 ArrayList<SurfaceParams> params = new ArrayList<>();
Tarandeep Singh699aa672019-11-22 23:19:30 -0800177 updateLeashesForSide(ISIDE_LEFT, offset.left, mShownInsets.left, mPendingInsets.left,
Jorim Jaggi1df5bd22020-03-05 15:52:21 +0100178 params, state, mPendingAlpha);
Tarandeep Singh699aa672019-11-22 23:19:30 -0800179 updateLeashesForSide(ISIDE_TOP, offset.top, mShownInsets.top, mPendingInsets.top, params,
Jorim Jaggi1df5bd22020-03-05 15:52:21 +0100180 state, mPendingAlpha);
Tarandeep Singh699aa672019-11-22 23:19:30 -0800181 updateLeashesForSide(ISIDE_RIGHT, offset.right, mShownInsets.right, mPendingInsets.right,
Jorim Jaggi1df5bd22020-03-05 15:52:21 +0100182 params, state, mPendingAlpha);
Tarandeep Singh699aa672019-11-22 23:19:30 -0800183 updateLeashesForSide(ISIDE_BOTTOM, offset.bottom, mShownInsets.bottom,
Jorim Jaggi1df5bd22020-03-05 15:52:21 +0100184 mPendingInsets.bottom, params, state, mPendingAlpha);
Tarandeep Singh699aa672019-11-22 23:19:30 -0800185 updateLeashesForSide(ISIDE_FLOATING, 0 /* offset */, 0 /* inset */, 0 /* maxInset */,
Jorim Jaggi1df5bd22020-03-05 15:52:21 +0100186 params, state, mPendingAlpha);
Tarandeep Singh95a3dbf2019-10-22 10:39:24 -0700187
Yunfan Chen02abf552019-12-05 14:51:09 +0900188 mController.applySurfaceParams(params.toArray(new SurfaceParams[params.size()]));
Jorim Jaggi02a741f2018-12-12 17:40:19 -0800189 mCurrentInsets = mPendingInsets;
Tarandeep Singh54554e22019-11-01 14:43:05 -0700190 mAnimation.setFraction(mPendingFraction);
Jorim Jaggi580aef52020-02-26 18:28:28 +0100191 mCurrentAlpha = mPendingAlpha;
192 mAnimation.setAlpha(mPendingAlpha);
Jorim Jaggi5ed50cc2019-01-23 16:59:42 +0100193 if (mFinished) {
Taran Singh85661e32020-05-07 14:45:34 -0700194 if (DEBUG) Log.d(TAG, String.format(
195 "notifyFinished shown: %s, currentAlpha: %f, currentInsets: %s",
196 mShownOnFinish, mCurrentAlpha, mCurrentInsets));
Tarandeep Singh54554e22019-11-01 14:43:05 -0700197 mController.notifyFinished(this, mShownOnFinish);
Rob Carr3a367c42020-03-10 15:51:35 -0700198 releaseLeashes();
Jorim Jaggi5ed50cc2019-01-23 16:59:42 +0100199 }
Taran Singh85661e32020-05-07 14:45:34 -0700200 if (DEBUG) Log.d(TAG, "Animation finished abruptly.");
Jorim Jaggi5ed50cc2019-01-23 16:59:42 +0100201 return mFinished;
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100202 }
203
Rob Carr3a367c42020-03-10 15:51:35 -0700204 private void releaseLeashes() {
205 for (int i = mControls.size() - 1; i >= 0; i--) {
206 final InsetsSourceControl c = mControls.valueAt(i);
207 if (c == null) continue;
208 c.release(mController::releaseSurfaceControlFromRt);
209 }
210 }
211
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100212 @Override
Tarandeep Singh54554e22019-11-01 14:43:05 -0700213 public void finish(boolean shown) {
Yunfan Chenb5d2db72019-12-06 15:43:43 +0900214 if (mCancelled || mFinished) {
Taran Singh85661e32020-05-07 14:45:34 -0700215 if (DEBUG) Log.d(TAG, "Animation already canceled or finished, not notifying.");
Jorim Jaggi5ed50cc2019-01-23 16:59:42 +0100216 return;
217 }
Taran Singh04850412020-03-23 15:04:58 -0700218 mShownOnFinish = shown;
Jorim Jaggi5ed50cc2019-01-23 16:59:42 +0100219 mFinished = true;
Jorim Jaggif1035882020-03-31 22:47:12 +0200220 setInsetsAndAlpha(shown ? mShownInsets : mHiddenInsets, 1f /* alpha */, 1f /* fraction */,
221 true /* allowWhenFinished */);
Taran Singh85661e32020-05-07 14:45:34 -0700222
223 if (DEBUG) Log.d(TAG, "notify control request finished for types: " + mTypes);
Adrian Roos5d557ed2020-03-17 20:04:35 +0100224 mListener.onFinished(this);
Jorim Jaggi5ed50cc2019-01-23 16:59:42 +0100225 }
Jorim Jaggi02a741f2018-12-12 17:40:19 -0800226
Tarandeep Singh54554e22019-11-01 14:43:05 -0700227 @Override
Jorim Jaggi5ed50cc2019-01-23 16:59:42 +0100228 @VisibleForTesting
Tarandeep Singh54554e22019-11-01 14:43:05 -0700229 public float getCurrentFraction() {
230 return mAnimation.getFraction();
231 }
232
Jorim Jaggi6d5c8012020-02-28 01:40:27 +0100233 @Override
234 public void cancel() {
Jorim Jaggi5ed50cc2019-01-23 16:59:42 +0100235 if (mFinished) {
236 return;
237 }
238 mCancelled = true;
Adrian Roos53989972020-03-19 20:15:57 +0100239 mListener.onCancelled(mReadyDispatched ? this : null);
Taran Singh85661e32020-05-07 14:45:34 -0700240 if (DEBUG) Log.d(TAG, "notify Control request cancelled for types: " + mTypes);
Rob Carr3a367c42020-03-10 15:51:35 -0700241
242 releaseLeashes();
Jorim Jaggi5ed50cc2019-01-23 16:59:42 +0100243 }
244
Adrian Roos5d557ed2020-03-17 20:04:35 +0100245 @Override
246 public boolean isFinished() {
247 return mFinished;
248 }
249
250 @Override
Jorim Jaggi3182ef12020-01-30 00:16:18 +0100251 public boolean isCancelled() {
252 return mCancelled;
253 }
254
Jorim Jaggi6d5c8012020-02-28 01:40:27 +0100255 @Override
256 public WindowInsetsAnimation getAnimation() {
Jorim Jaggi5ed50cc2019-01-23 16:59:42 +0100257 return mAnimation;
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100258 }
259
Tarandeep Singh54554e22019-11-01 14:43:05 -0700260 WindowInsetsAnimationControlListener getListener() {
261 return mListener;
262 }
263
Jorim Jaggi6d5c8012020-02-28 01:40:27 +0100264 SparseArray<InsetsSourceControl> getControls() {
265 return mControls;
266 }
267
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100268 private Insets calculateInsets(InsetsState state, Rect frame,
Yunfan Chen02abf552019-12-05 14:51:09 +0900269 SparseArray<InsetsSourceControl> controls, boolean shown,
Tiger Huang332793b2019-10-29 23:21:27 +0800270 @Nullable @InternalInsetsSide SparseIntArray typeSideMap) {
Yunfan Chen02abf552019-12-05 14:51:09 +0900271 for (int i = controls.size() - 1; i >= 0; i--) {
272 // control may be null if it got revoked.
273 if (controls.valueAt(i) == null) continue;
274 state.getSource(controls.valueAt(i).getType()).setVisible(shown);
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100275 }
276 return getInsetsFromState(state, frame, typeSideMap);
277 }
278
279 private Insets getInsetsFromState(InsetsState state, Rect frame,
Tiger Huang332793b2019-10-29 23:21:27 +0800280 @Nullable @InternalInsetsSide SparseIntArray typeSideMap) {
Jorim Jaggi580aef52020-02-26 18:28:28 +0100281 return state.calculateInsets(frame, null /* ignoringVisibilityState */,
282 false /* isScreenRound */,
Yunfan Chen02abf552019-12-05 14:51:09 +0900283 false /* alwaysConsumeSystemBars */, null /* displayCutout */,
Jorim Jaggi7f761872020-01-10 18:24:27 +0100284 LayoutParams.SOFT_INPUT_ADJUST_RESIZE /* legacySoftInputMode*/,
285 0 /* legacySystemUiFlags */, typeSideMap)
Jorim Jaggi73f3e8a2019-01-14 13:06:23 +0100286 .getInsets(mTypes);
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100287 }
288
289 private Insets sanitize(Insets insets) {
Tarandeep Singh54554e22019-11-01 14:43:05 -0700290 if (insets == null) {
291 insets = getCurrentInsets();
292 }
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100293 return Insets.max(Insets.min(insets, mShownInsets), mHiddenInsets);
294 }
295
Tarandeep Singh54554e22019-11-01 14:43:05 -0700296 private static float sanitize(float alpha) {
297 return alpha >= 1 ? 1 : (alpha <= 0 ? 0 : alpha);
298 }
299
Jorim Jaggi580aef52020-02-26 18:28:28 +0100300 private void updateLeashesForSide(@InternalInsetsSide int side, int offset, int maxInset,
301 int inset, ArrayList<SurfaceParams> surfaceParams, InsetsState state, Float alpha) {
Yunfan Chen02abf552019-12-05 14:51:09 +0900302 ArraySet<InsetsSourceControl> items = mSideSourceMap.get(side);
Jorim Jaggi956ca412019-01-07 14:49:14 +0100303 if (items == null) {
304 return;
305 }
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100306 // TODO: Implement behavior when inset spans over multiple types
307 for (int i = items.size() - 1; i >= 0; i--) {
Yunfan Chen02abf552019-12-05 14:51:09 +0900308 final InsetsSourceControl control = items.valueAt(i);
309 final InsetsSource source = mInitialInsetsState.getSource(control.getType());
Yunfan Chen02abf552019-12-05 14:51:09 +0900310 final SurfaceControl leash = control.getLeash();
Jorim Jaggi02a741f2018-12-12 17:40:19 -0800311
Tarandeep Singh215929b2019-01-11 18:24:37 -0800312 mTmpMatrix.setTranslate(control.getSurfacePosition().x, control.getSurfacePosition().y);
Jorim Jaggi02a741f2018-12-12 17:40:19 -0800313 mTmpFrame.set(source.getFrame());
Jorim Jaggi67684882019-01-22 17:36:34 +0100314 addTranslationToMatrix(side, offset, mTmpMatrix, mTmpFrame);
Jorim Jaggi02a741f2018-12-12 17:40:19 -0800315
Jorim Jaggi580aef52020-02-26 18:28:28 +0100316 state.getSource(source.getType()).setVisible(side == ISIDE_FLOATING || inset != 0);
Jorim Jaggi02a741f2018-12-12 17:40:19 -0800317 state.getSource(source.getType()).setFrame(mTmpFrame);
Jorim Jaggia12ea562019-01-07 17:47:47 +0100318
319 // If the system is controlling the insets source, the leash can be null.
320 if (leash != null) {
Winson Chung7e895da2020-02-03 13:28:44 -0800321 SurfaceParams params = new SurfaceParams.Builder(leash)
322 .withAlpha(side == ISIDE_FLOATING ? 1 : alpha)
323 .withMatrix(mTmpMatrix)
324 .withVisibility(side == ISIDE_FLOATING
Taran Singh04850412020-03-23 15:04:58 -0700325 ? mShownOnFinish
Winson Chung7e895da2020-02-03 13:28:44 -0800326 : inset != 0 /* visible */)
327 .build();
328 surfaceParams.add(params);
Jorim Jaggia12ea562019-01-07 17:47:47 +0100329 }
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100330 }
331 }
332
Tiger Huang332793b2019-10-29 23:21:27 +0800333 private void addTranslationToMatrix(@InternalInsetsSide int side, int inset, Matrix m,
334 Rect frame) {
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100335 switch (side) {
Tiger Huang332793b2019-10-29 23:21:27 +0800336 case ISIDE_LEFT:
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100337 m.postTranslate(-inset, 0);
Jorim Jaggi02a741f2018-12-12 17:40:19 -0800338 frame.offset(-inset, 0);
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100339 break;
Tiger Huang332793b2019-10-29 23:21:27 +0800340 case ISIDE_TOP:
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100341 m.postTranslate(0, -inset);
Jorim Jaggi02a741f2018-12-12 17:40:19 -0800342 frame.offset(0, -inset);
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100343 break;
Tiger Huang332793b2019-10-29 23:21:27 +0800344 case ISIDE_RIGHT:
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100345 m.postTranslate(inset, 0);
Jorim Jaggi02a741f2018-12-12 17:40:19 -0800346 frame.offset(inset, 0);
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100347 break;
Tiger Huang332793b2019-10-29 23:21:27 +0800348 case ISIDE_BOTTOM:
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100349 m.postTranslate(0, inset);
Jorim Jaggi02a741f2018-12-12 17:40:19 -0800350 frame.offset(0, inset);
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100351 break;
352 }
353 }
354
355 private static void buildTypeSourcesMap(SparseIntArray typeSideMap,
Yunfan Chen02abf552019-12-05 14:51:09 +0900356 SparseSetArray<InsetsSourceControl> sideSourcesMap,
357 SparseArray<InsetsSourceControl> controls) {
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100358 for (int i = typeSideMap.size() - 1; i >= 0; i--) {
Jorim Jaggi956ca412019-01-07 14:49:14 +0100359 final int type = typeSideMap.keyAt(i);
360 final int side = typeSideMap.valueAt(i);
Yunfan Chen02abf552019-12-05 14:51:09 +0900361 final InsetsSourceControl control = controls.get(type);
362 if (control == null) {
Jorim Jaggi956ca412019-01-07 14:49:14 +0100363 // If the types that we are controlling are less than the types that the system has,
Yunfan Chen02abf552019-12-05 14:51:09 +0900364 // there can be some null controllers.
Jorim Jaggi956ca412019-01-07 14:49:14 +0100365 continue;
366 }
Yunfan Chen02abf552019-12-05 14:51:09 +0900367 sideSourcesMap.add(side, control);
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100368 }
369 }
370}