diff options
| author | Jorim Jaggi <jjaggi@google.com> | 2020-03-02 20:22:34 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-03-02 20:22:34 +0000 |
| commit | 96cc10c2deabbfb063cf649401d89f2762eb7d1e (patch) | |
| tree | b84e3bcab740079609662cbcbfd27cf7d31c247c /core/java | |
| parent | 432e0c744003eead66f5765067f43f30cdac122a (diff) | |
| parent | 580aef5a82c80317549eaeda81b646a0a44ec860 (diff) | |
Merge "Various inset fixes" into rvc-dev
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/view/InsetsAnimationControlImpl.java | 17 | ||||
| -rw-r--r-- | core/java/android/view/InsetsController.java | 47 | ||||
| -rw-r--r-- | core/java/android/view/InsetsSourceConsumer.java | 3 | ||||
| -rw-r--r-- | core/java/android/view/InsetsState.java | 22 | ||||
| -rw-r--r-- | core/java/android/view/WindowInsetsAnimation.java | 5 |
5 files changed, 69 insertions, 25 deletions
diff --git a/core/java/android/view/InsetsAnimationControlImpl.java b/core/java/android/view/InsetsAnimationControlImpl.java index 9247f4a29bdd..44ecb545c37f 100644 --- a/core/java/android/view/InsetsAnimationControlImpl.java +++ b/core/java/android/view/InsetsAnimationControlImpl.java @@ -76,8 +76,8 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll private boolean mFinished; private boolean mCancelled; private boolean mShownOnFinish; - private float mCurrentAlpha; - private float mPendingAlpha; + private float mCurrentAlpha = 1.0f; + private float mPendingAlpha = 1.0f; @VisibleForTesting public InsetsAnimationControlImpl(SparseArray<InsetsSourceControl> controls, Rect frame, @@ -153,7 +153,7 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll } mPendingFraction = sanitize(fraction); mPendingInsets = sanitize(insets); - mPendingAlpha = 1 - sanitize(alpha); + mPendingAlpha = sanitize(alpha); mController.scheduleApplyChangeInsets(); } @@ -182,7 +182,8 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll mController.applySurfaceParams(params.toArray(new SurfaceParams[params.size()])); mCurrentInsets = mPendingInsets; mAnimation.setFraction(mPendingFraction); - mCurrentAlpha = 1 - alphaOffset; + mCurrentAlpha = mPendingAlpha; + mAnimation.setAlpha(mPendingAlpha); if (mFinished) { mController.notifyFinished(this, mShownOnFinish); } @@ -238,7 +239,8 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll private Insets getInsetsFromState(InsetsState state, Rect frame, @Nullable @InternalInsetsSide SparseIntArray typeSideMap) { - return state.calculateInsets(frame, false /* isScreenRound */, + return state.calculateInsets(frame, null /* ignoringVisibilityState */, + false /* isScreenRound */, false /* alwaysConsumeSystemBars */, null /* displayCutout */, null /* legacyContentInsets */, null /* legacyStableInsets */, LayoutParams.SOFT_INPUT_ADJUST_RESIZE /* legacySoftInputMode*/, @@ -257,8 +259,8 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll return alpha >= 1 ? 1 : (alpha <= 0 ? 0 : alpha); } - private void updateLeashesForSide(@InternalInsetsSide int side, int offset, int inset, - int maxInset, ArrayList<SurfaceParams> surfaceParams, InsetsState state, Float alpha) { + private void updateLeashesForSide(@InternalInsetsSide int side, int offset, int maxInset, + int inset, ArrayList<SurfaceParams> surfaceParams, InsetsState state, Float alpha) { ArraySet<InsetsSourceControl> items = mSideSourceMap.get(side); if (items == null) { return; @@ -273,6 +275,7 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll mTmpFrame.set(source.getFrame()); addTranslationToMatrix(side, offset, mTmpMatrix, mTmpFrame); + state.getSource(source.getType()).setVisible(side == ISIDE_FLOATING || inset != 0); state.getSource(source.getType()).setFrame(mTmpFrame); // If the system is controlling the insets source, the leash can be null. diff --git a/core/java/android/view/InsetsController.java b/core/java/android/view/InsetsController.java index 4cb8e1388858..573d8fc65c84 100644 --- a/core/java/android/view/InsetsController.java +++ b/core/java/android/view/InsetsController.java @@ -233,6 +233,12 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation final InsetsAnimationControlImpl control; final @AnimationType int type; + + /** + * Whether {@link WindowInsetsAnimation.Callback#onStart(WindowInsetsAnimation, Bounds)} has + * been dispatched already for this animation. + */ + boolean startDispatched; } /** @@ -276,9 +282,9 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation private final SparseArray<InsetsSourceControl> mTmpControlArray = new SparseArray<>(); private final ArrayList<RunningAnimation> mRunningAnimations = new ArrayList<>(); - private final ArrayList<WindowInsetsAnimation> mRunningInsetsAnimations = new ArrayList<>(); - private final List<WindowInsetsAnimation> mUnmodifiableRunningInsetsAnimations = - Collections.unmodifiableList(mRunningInsetsAnimations); + private final ArrayList<WindowInsetsAnimation> mTmpRunningAnims = new ArrayList<>(); + private final List<WindowInsetsAnimation> mUnmodifiableTmpRunningAnims = + Collections.unmodifiableList(mTmpRunningAnims); private final ArrayList<InsetsAnimationControlImpl> mTmpFinishedControls = new ArrayList<>(); private WindowInsets mLastInsets; @@ -294,6 +300,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation private int mLastLegacySoftInputMode; private int mLastLegacySystemUiFlags; + private DisplayCutout mLastDisplayCutout; private boolean mStartingAnimation; private SyncRtSurfaceTransactionApplier mApplier; @@ -329,20 +336,28 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation } mTmpFinishedControls.clear(); + mTmpRunningAnims.clear(); InsetsState state = new InsetsState(mState, true /* copySources */); for (int i = mRunningAnimations.size() - 1; i >= 0; i--) { - InsetsAnimationControlImpl control = mRunningAnimations.get(i).control; + RunningAnimation runningAnimation = mRunningAnimations.get(i); + InsetsAnimationControlImpl control = runningAnimation.control; + + // Keep track of running animation to be dispatched. Aggregate it here such that if + // it gets finished within applyChangeInsets we still dispatch it to onProgress. + if (runningAnimation.startDispatched) { + mTmpRunningAnims.add(control.getAnimation()); + } if (control.applyChangeInsets(state)) { mTmpFinishedControls.add(control); } } - WindowInsets insets = state.calculateInsets(mFrame, mLastInsets.isRound(), - mLastInsets.shouldAlwaysConsumeSystemBars(), mLastInsets.getDisplayCutout(), - mLastLegacyContentInsets, mLastLegacyStableInsets, mLastLegacySoftInputMode, - mLastLegacySystemUiFlags, null /* typeSideMap */); + WindowInsets insets = state.calculateInsets(mFrame, mState /* ignoringVisibilityState*/, + mLastInsets.isRound(), mLastInsets.shouldAlwaysConsumeSystemBars(), + mLastDisplayCutout, mLastLegacyContentInsets, mLastLegacyStableInsets, + mLastLegacySoftInputMode, mLastLegacySystemUiFlags, null /* typeSideMap */); mViewRoot.mView.dispatchWindowInsetsAnimationProgress(insets, - mUnmodifiableRunningInsetsAnimations); + mUnmodifiableTmpRunningAnims); for (int i = mTmpFinishedControls.size() - 1; i >= 0; i--) { dispatchAnimationEnd(mTmpFinishedControls.get(i).getAnimation()); @@ -394,8 +409,10 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation mLastLegacyStableInsets.set(legacyStableInsets); mLastLegacySoftInputMode = legacySoftInputMode; mLastLegacySystemUiFlags = legacySystemUiFlags; - mLastInsets = mState.calculateInsets(mFrame, isScreenRound, alwaysConsumeSystemBars, cutout, - legacyContentInsets, legacyStableInsets, legacySoftInputMode, legacySystemUiFlags, + mLastDisplayCutout = cutout; + mLastInsets = mState.calculateInsets(mFrame, null /* ignoringVisibilityState*/, + isScreenRound, alwaysConsumeSystemBars, cutout, legacyContentInsets, + legacyStableInsets, legacySoftInputMode, legacySystemUiFlags, null /* typeSideMap */); return mLastInsets; } @@ -584,7 +601,6 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation frame, mState, listener, typesReady, this, durationMs, interpolator, fade, layoutInsetsDuringAnimation, animationType); mRunningAnimations.add(new RunningAnimation(controller, animationType)); - mRunningInsetsAnimations.add(controller.getAnimation()); cancellationSignal.setOnCancelListener(controller::onCancelled); return cancellationSignal; } @@ -736,7 +752,6 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation for (int i = mRunningAnimations.size() - 1; i >= 0; i--) { if (mRunningAnimations.get(i).control == control) { mRunningAnimations.remove(i); - mRunningInsetsAnimations.remove(i); break; } } @@ -903,6 +918,12 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation if (controller.isCancelled()) { return true; } + for (int i = mRunningAnimations.size() - 1; i >= 0; i--) { + RunningAnimation runningAnimation = mRunningAnimations.get(i); + if (runningAnimation.control == controller) { + runningAnimation.startDispatched = true; + } + } mViewRoot.mView.dispatchWindowInsetsAnimationStart(animation, bounds); mStartingAnimation = true; listener.onReady(controller, types); diff --git a/core/java/android/view/InsetsSourceConsumer.java b/core/java/android/view/InsetsSourceConsumer.java index 6d07a13091bd..92ac4259c349 100644 --- a/core/java/android/view/InsetsSourceConsumer.java +++ b/core/java/android/view/InsetsSourceConsumer.java @@ -160,7 +160,8 @@ public class InsetsSourceConsumer { } boolean applyLocalVisibilityOverride() { - final boolean isVisible = mState.getSource(mType).isVisible(); + InsetsSource source = mState.peekSource(mType); + final boolean isVisible = source != null && source.isVisible(); final boolean hasControl = mSourceControl != null; // We still need to let the legacy app know the visibility change even if we don't have the diff --git a/core/java/android/view/InsetsState.java b/core/java/android/view/InsetsState.java index c877c454be91..b740c58ec15f 100644 --- a/core/java/android/view/InsetsState.java +++ b/core/java/android/view/InsetsState.java @@ -147,10 +147,13 @@ public class InsetsState implements Parcelable { * Calculates {@link WindowInsets} based on the current source configuration. * * @param frame The frame to calculate the insets relative to. + * @param ignoringVisibilityState {@link InsetsState} used to calculate + * {@link WindowInsets#getInsetsIgnoringVisibility(int)} information, or pass + * {@code null} to use this state to calculate that information. * @return The calculated insets. */ - public WindowInsets calculateInsets(Rect frame, boolean isScreenRound, - boolean alwaysConsumeSystemBars, DisplayCutout cutout, + public WindowInsets calculateInsets(Rect frame, @Nullable InsetsState ignoringVisibilityState, + boolean isScreenRound, boolean alwaysConsumeSystemBars, DisplayCutout cutout, @Nullable Rect legacyContentInsets, @Nullable Rect legacyStableInsets, int legacySoftInputMode, int legacySystemUiFlags, @Nullable @InternalInsetsSide SparseIntArray typeSideMap) { @@ -188,8 +191,15 @@ public class InsetsState implements Parcelable { // IME won't be reported in max insets as the size depends on the EditorInfo of the IME // target. if (source.getType() != ITYPE_IME) { - processSource(source, relativeFrameMax, true /* ignoreVisibility */, - typeMaxInsetsMap, null /* typeSideMap */, null /* typeVisibilityMap */); + InsetsSource ignoringVisibilitySource = ignoringVisibilityState != null + ? ignoringVisibilityState.getSource(type) + : source; + if (ignoringVisibilitySource == null) { + continue; + } + processSource(ignoringVisibilitySource, relativeFrameMax, + true /* ignoreVisibility */, typeMaxInsetsMap, null /* typeSideMap */, + null /* typeVisibilityMap */); } } final int softInputAdjustMode = legacySoftInputMode & SOFT_INPUT_MASK_ADJUST; @@ -297,6 +307,10 @@ public class InsetsState implements Parcelable { return mSources.computeIfAbsent(type, InsetsSource::new); } + public @Nullable InsetsSource peekSource(@InternalInsetsType int type) { + return mSources.get(type); + } + public void setDisplayFrame(Rect frame) { mDisplayFrame.set(frame); } diff --git a/core/java/android/view/WindowInsetsAnimation.java b/core/java/android/view/WindowInsetsAnimation.java index 396da4acb5bc..e32648809f8f 100644 --- a/core/java/android/view/WindowInsetsAnimation.java +++ b/core/java/android/view/WindowInsetsAnimation.java @@ -264,6 +264,11 @@ public final class WindowInsetsAnimation { WindowInsets.insetInsets( mUpperBound, insets.left, insets.top, insets.right, insets.bottom)); } + + @Override + public String toString() { + return "Bounds{lower=" + mLowerBound + " upper=" + mUpperBound + "}"; + } } /** |
