Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 580aef5a authored by Jorim Jaggi's avatar Jorim Jaggi
Browse files

Various inset fixes

- Fix alpha
- Fix running animation book-keeping
- Fix max insets dispatched during onProgress
- Fix visibility of onProgress
- Fix cutout during onProgress

Bug: 118118435
Change-Id: Ibc0204280407ea6c981b86af6992ef24ff8fb41f
parent e06e29bb
Loading
Loading
Loading
Loading
+10 −7
Original line number Original line Diff line number Diff line
@@ -75,8 +75,8 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
    private boolean mFinished;
    private boolean mFinished;
    private boolean mCancelled;
    private boolean mCancelled;
    private boolean mShownOnFinish;
    private boolean mShownOnFinish;
    private float mCurrentAlpha;
    private float mCurrentAlpha = 1.0f;
    private float mPendingAlpha;
    private float mPendingAlpha = 1.0f;


    @VisibleForTesting
    @VisibleForTesting
    public InsetsAnimationControlImpl(SparseArray<InsetsSourceControl> controls, Rect frame,
    public InsetsAnimationControlImpl(SparseArray<InsetsSourceControl> controls, Rect frame,
@@ -147,7 +147,7 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
        }
        }
        mPendingFraction = sanitize(fraction);
        mPendingFraction = sanitize(fraction);
        mPendingInsets = sanitize(insets);
        mPendingInsets = sanitize(insets);
        mPendingAlpha = 1 - sanitize(alpha);
        mPendingAlpha = sanitize(alpha);
        mController.scheduleApplyChangeInsets();
        mController.scheduleApplyChangeInsets();
    }
    }


@@ -176,7 +176,8 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
        mController.applySurfaceParams(params.toArray(new SurfaceParams[params.size()]));
        mController.applySurfaceParams(params.toArray(new SurfaceParams[params.size()]));
        mCurrentInsets = mPendingInsets;
        mCurrentInsets = mPendingInsets;
        mAnimation.setFraction(mPendingFraction);
        mAnimation.setFraction(mPendingFraction);
        mCurrentAlpha = 1 - alphaOffset;
        mCurrentAlpha = mPendingAlpha;
        mAnimation.setAlpha(mPendingAlpha);
        if (mFinished) {
        if (mFinished) {
            mController.notifyFinished(this, mShownOnFinish);
            mController.notifyFinished(this, mShownOnFinish);
        }
        }
@@ -232,7 +233,8 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll


    private Insets getInsetsFromState(InsetsState state, Rect frame,
    private Insets getInsetsFromState(InsetsState state, Rect frame,
            @Nullable @InternalInsetsSide SparseIntArray typeSideMap) {
            @Nullable @InternalInsetsSide SparseIntArray typeSideMap) {
        return state.calculateInsets(frame, false /* isScreenRound */,
        return state.calculateInsets(frame, null /* ignoringVisibilityState */,
                false /* isScreenRound */,
                false /* alwaysConsumeSystemBars */, null /* displayCutout */,
                false /* alwaysConsumeSystemBars */, null /* displayCutout */,
                null /* legacyContentInsets */, null /* legacyStableInsets */,
                null /* legacyContentInsets */, null /* legacyStableInsets */,
                LayoutParams.SOFT_INPUT_ADJUST_RESIZE /* legacySoftInputMode*/,
                LayoutParams.SOFT_INPUT_ADJUST_RESIZE /* legacySoftInputMode*/,
@@ -251,8 +253,8 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
        return alpha >= 1 ? 1 : (alpha <= 0 ? 0 : alpha);
        return alpha >= 1 ? 1 : (alpha <= 0 ? 0 : alpha);
    }
    }


    private void updateLeashesForSide(@InternalInsetsSide int side, int offset, int inset,
    private void updateLeashesForSide(@InternalInsetsSide int side, int offset, int maxInset,
            int maxInset, ArrayList<SurfaceParams> surfaceParams, InsetsState state, Float alpha) {
            int inset, ArrayList<SurfaceParams> surfaceParams, InsetsState state, Float alpha) {
        ArraySet<InsetsSourceControl> items = mSideSourceMap.get(side);
        ArraySet<InsetsSourceControl> items = mSideSourceMap.get(side);
        if (items == null) {
        if (items == null) {
            return;
            return;
@@ -267,6 +269,7 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
            mTmpFrame.set(source.getFrame());
            mTmpFrame.set(source.getFrame());
            addTranslationToMatrix(side, offset, mTmpMatrix, mTmpFrame);
            addTranslationToMatrix(side, offset, mTmpMatrix, mTmpFrame);


            state.getSource(source.getType()).setVisible(side == ISIDE_FLOATING || inset != 0);
            state.getSource(source.getType()).setFrame(mTmpFrame);
            state.getSource(source.getType()).setFrame(mTmpFrame);


            // If the system is controlling the insets source, the leash can be null.
            // If the system is controlling the insets source, the leash can be null.
+34 −13
Original line number Original line Diff line number Diff line
@@ -233,6 +233,12 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation


        final InsetsAnimationControlImpl control;
        final InsetsAnimationControlImpl control;
        final @AnimationType int type;
        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 SparseArray<InsetsSourceControl> mTmpControlArray = new SparseArray<>();
    private final ArrayList<RunningAnimation> mRunningAnimations = new ArrayList<>();
    private final ArrayList<RunningAnimation> mRunningAnimations = new ArrayList<>();
    private final ArrayList<WindowInsetsAnimation> mRunningInsetsAnimations = new ArrayList<>();
    private final ArrayList<WindowInsetsAnimation> mTmpRunningAnims = new ArrayList<>();
    private final List<WindowInsetsAnimation> mUnmodifiableRunningInsetsAnimations =
    private final List<WindowInsetsAnimation> mUnmodifiableTmpRunningAnims =
            Collections.unmodifiableList(mRunningInsetsAnimations);
            Collections.unmodifiableList(mTmpRunningAnims);
    private final ArrayList<InsetsAnimationControlImpl> mTmpFinishedControls = new ArrayList<>();
    private final ArrayList<InsetsAnimationControlImpl> mTmpFinishedControls = new ArrayList<>();
    private WindowInsets mLastInsets;
    private WindowInsets mLastInsets;


@@ -294,6 +300,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation


    private int mLastLegacySoftInputMode;
    private int mLastLegacySoftInputMode;
    private int mLastLegacySystemUiFlags;
    private int mLastLegacySystemUiFlags;
    private DisplayCutout mLastDisplayCutout;
    private boolean mStartingAnimation;
    private boolean mStartingAnimation;


    private SyncRtSurfaceTransactionApplier mApplier;
    private SyncRtSurfaceTransactionApplier mApplier;
@@ -329,20 +336,28 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
            }
            }


            mTmpFinishedControls.clear();
            mTmpFinishedControls.clear();
            mTmpRunningAnims.clear();
            InsetsState state = new InsetsState(mState, true /* copySources */);
            InsetsState state = new InsetsState(mState, true /* copySources */);
            for (int i = mRunningAnimations.size() - 1; i >= 0; i--) {
            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)) {
                if (control.applyChangeInsets(state)) {
                    mTmpFinishedControls.add(control);
                    mTmpFinishedControls.add(control);
                }
                }
            }
            }


            WindowInsets insets = state.calculateInsets(mFrame, mLastInsets.isRound(),
            WindowInsets insets = state.calculateInsets(mFrame, mState /* ignoringVisibilityState*/,
                    mLastInsets.shouldAlwaysConsumeSystemBars(), mLastInsets.getDisplayCutout(),
                    mLastInsets.isRound(), mLastInsets.shouldAlwaysConsumeSystemBars(),
                    mLastLegacyContentInsets, mLastLegacyStableInsets, mLastLegacySoftInputMode,
                    mLastDisplayCutout, mLastLegacyContentInsets, mLastLegacyStableInsets,
                    mLastLegacySystemUiFlags, null /* typeSideMap */);
                    mLastLegacySoftInputMode, mLastLegacySystemUiFlags, null /* typeSideMap */);
            mViewRoot.mView.dispatchWindowInsetsAnimationProgress(insets,
            mViewRoot.mView.dispatchWindowInsetsAnimationProgress(insets,
                    mUnmodifiableRunningInsetsAnimations);
                    mUnmodifiableTmpRunningAnims);


            for (int i = mTmpFinishedControls.size() - 1; i >= 0; i--) {
            for (int i = mTmpFinishedControls.size() - 1; i >= 0; i--) {
                dispatchAnimationEnd(mTmpFinishedControls.get(i).getAnimation());
                dispatchAnimationEnd(mTmpFinishedControls.get(i).getAnimation());
@@ -394,8 +409,10 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        mLastLegacyStableInsets.set(legacyStableInsets);
        mLastLegacyStableInsets.set(legacyStableInsets);
        mLastLegacySoftInputMode = legacySoftInputMode;
        mLastLegacySoftInputMode = legacySoftInputMode;
        mLastLegacySystemUiFlags = legacySystemUiFlags;
        mLastLegacySystemUiFlags = legacySystemUiFlags;
        mLastInsets = mState.calculateInsets(mFrame, isScreenRound, alwaysConsumeSystemBars, cutout,
        mLastDisplayCutout = cutout;
                legacyContentInsets, legacyStableInsets, legacySoftInputMode, legacySystemUiFlags,
        mLastInsets = mState.calculateInsets(mFrame, null /* ignoringVisibilityState*/,
                isScreenRound, alwaysConsumeSystemBars, cutout, legacyContentInsets,
                legacyStableInsets, legacySoftInputMode, legacySystemUiFlags,
                null /* typeSideMap */);
                null /* typeSideMap */);
        return mLastInsets;
        return mLastInsets;
    }
    }
@@ -584,7 +601,6 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
                frame, mState, listener, typesReady, this, durationMs, interpolator, fade,
                frame, mState, listener, typesReady, this, durationMs, interpolator, fade,
                layoutInsetsDuringAnimation);
                layoutInsetsDuringAnimation);
        mRunningAnimations.add(new RunningAnimation(controller, animationType));
        mRunningAnimations.add(new RunningAnimation(controller, animationType));
        mRunningInsetsAnimations.add(controller.getAnimation());
        cancellationSignal.setOnCancelListener(controller::onCancelled);
        cancellationSignal.setOnCancelListener(controller::onCancelled);
        return cancellationSignal;
        return cancellationSignal;
    }
    }
@@ -735,7 +751,6 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        for (int i = mRunningAnimations.size() - 1; i >= 0; i--) {
        for (int i = mRunningAnimations.size() - 1; i >= 0; i--) {
            if (mRunningAnimations.get(i).control == control) {
            if (mRunningAnimations.get(i).control == control) {
                mRunningAnimations.remove(i);
                mRunningAnimations.remove(i);
                mRunningInsetsAnimations.remove(i);
                break;
                break;
            }
            }
        }
        }
@@ -900,6 +915,12 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
                if (controller.isCancelled()) {
                if (controller.isCancelled()) {
                    return true;
                    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);
                mViewRoot.mView.dispatchWindowInsetsAnimationStart(animation, bounds);
                mStartingAnimation = true;
                mStartingAnimation = true;
                listener.onReady(controller, types);
                listener.onReady(controller, types);
+2 −1
Original line number Original line Diff line number Diff line
@@ -156,7 +156,8 @@ public class InsetsSourceConsumer {
    }
    }


    boolean applyLocalVisibilityOverride() {
    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;
        final boolean hasControl = mSourceControl != null;


        // We still need to let the legacy app know the visibility change even if we don't have the
        // We still need to let the legacy app know the visibility change even if we don't have the
+18 −4
Original line number Original line Diff line number Diff line
@@ -137,10 +137,13 @@ public class InsetsState implements Parcelable {
     * Calculates {@link WindowInsets} based on the current source configuration.
     * Calculates {@link WindowInsets} based on the current source configuration.
     *
     *
     * @param frame The frame to calculate the insets relative to.
     * @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.
     * @return The calculated insets.
     */
     */
    public WindowInsets calculateInsets(Rect frame, boolean isScreenRound,
    public WindowInsets calculateInsets(Rect frame, @Nullable InsetsState ignoringVisibilityState,
            boolean alwaysConsumeSystemBars, DisplayCutout cutout,
            boolean isScreenRound, boolean alwaysConsumeSystemBars, DisplayCutout cutout,
            @Nullable Rect legacyContentInsets, @Nullable Rect legacyStableInsets,
            @Nullable Rect legacyContentInsets, @Nullable Rect legacyStableInsets,
            int legacySoftInputMode, int legacySystemUiFlags,
            int legacySoftInputMode, int legacySystemUiFlags,
            @Nullable @InternalInsetsSide SparseIntArray typeSideMap) {
            @Nullable @InternalInsetsSide SparseIntArray typeSideMap) {
@@ -178,8 +181,15 @@ public class InsetsState implements Parcelable {
            // IME won't be reported in max insets as the size depends on the EditorInfo of the IME
            // IME won't be reported in max insets as the size depends on the EditorInfo of the IME
            // target.
            // target.
            if (source.getType() != ITYPE_IME) {
            if (source.getType() != ITYPE_IME) {
                processSource(source, relativeFrameMax, true /* ignoreVisibility */,
                InsetsSource ignoringVisibilitySource = ignoringVisibilityState != null
                        typeMaxInsetsMap, null /* typeSideMap */, null /* typeVisibilityMap */);
                        ? 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;
        final int softInputAdjustMode = legacySoftInputMode & SOFT_INPUT_MASK_ADJUST;
@@ -287,6 +297,10 @@ public class InsetsState implements Parcelable {
        return mSources.computeIfAbsent(type, InsetsSource::new);
        return mSources.computeIfAbsent(type, InsetsSource::new);
    }
    }


    public @Nullable InsetsSource peekSource(@InternalInsetsType int type) {
        return mSources.get(type);
    }

    public void setDisplayFrame(Rect frame) {
    public void setDisplayFrame(Rect frame) {
        mDisplayFrame.set(frame);
        mDisplayFrame.set(frame);
    }
    }
+5 −0
Original line number Original line Diff line number Diff line
@@ -264,6 +264,11 @@ public final class WindowInsetsAnimation {
                    WindowInsets.insetInsets(
                    WindowInsets.insetInsets(
                            mUpperBound, insets.left, insets.top, insets.right, insets.bottom));
                            mUpperBound, insets.left, insets.top, insets.right, insets.bottom));
        }
        }

        @Override
        public String toString() {
            return "Bounds{lower=" + mLowerBound + " upper=" + mUpperBound + "}";
        }
    }
    }


    /**
    /**
Loading