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

Commit b2820aea authored by Johannes Gallmann's avatar Johannes Gallmann
Browse files

Add app movement for IME predictive back and adjustPan

Bug: 322836622
Flag: ACONFIG android.view.inputmethod.predictive_back_ime DISABLED
Test: separate CL
Change-Id: I671e99c14372f000fdd58b9e5a7d016ae451d70c
parent 08c01f0d
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.view;

import static android.view.InsetsController.ANIMATION_TYPE_USER;
import static android.view.WindowInsets.Type.ime;
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN;
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;

@@ -60,6 +61,7 @@ public class ImeBackAnimationController implements OnBackAnimationCallback {
    private float mLastProgress = 0f;
    private boolean mTriggerBack = false;
    private boolean mIsPreCommitAnimationInProgress = false;
    private int mStartRootScrollY = 0;

    public ImeBackAnimationController(ViewRootImpl viewRoot) {
        mInsetsController = viewRoot.getInsetsController();
@@ -96,6 +98,7 @@ public class ImeBackAnimationController implements OnBackAnimationCallback {
                    public void onReady(@NonNull WindowInsetsAnimationController controller,
                            @WindowInsets.Type.InsetsType int types) {
                        mWindowInsetsAnimationController = controller;
                        if (isAdjustPan()) mStartRootScrollY = mViewRoot.mScrollY;
                        if (mIsPreCommitAnimationInProgress) {
                            setPreCommitProgress(mLastProgress);
                        } else {
@@ -146,6 +149,10 @@ public class ImeBackAnimationController implements OnBackAnimationCallback {
            float imeHeight = shownY - hiddenY;
            float interpolatedProgress = BACK_GESTURE.getInterpolation(progress);
            int newY = (int) (imeHeight - interpolatedProgress * (imeHeight * PEEK_FRACTION));
            if (mStartRootScrollY != 0) {
                mViewRoot.setScrollY(
                        (int) (mStartRootScrollY * (1 - interpolatedProgress * PEEK_FRACTION)));
            }
            mWindowInsetsAnimationController.setInsetsAndAlpha(Insets.of(0, 0, 0, newY), 1f,
                    progress);
        }
@@ -199,6 +206,19 @@ public class ImeBackAnimationController implements OnBackAnimationCallback {
            mInsetsController.setPredictiveBackImeHideAnimInProgress(true);
            notifyHideIme();
        }
        if (mStartRootScrollY != 0) {
            // RootView is panned, ensure that it is scrolled back to the intended scroll position
            if (triggerBack) {
                // requesting ime as invisible
                mInsetsController.setRequestedVisibleTypes(0, ime());
                // changes the animation state and notifies RootView of changed insets, which
                // causes it to reset its scrollY to 0f (animated)
                mInsetsController.onAnimationStateChanged(ime(), /*running*/ true);
            } else {
                // This causes RootView to update its scroll back to the panned position
                mInsetsController.getHost().notifyInsetsChanged();
            }
        }
    }

    private void notifyHideIme() {
@@ -222,6 +242,7 @@ public class ImeBackAnimationController implements OnBackAnimationCallback {
        mTriggerBack = false;
        mIsPreCommitAnimationInProgress = false;
        mInsetsController.setPredictiveBackImeHideAnimInProgress(false);
        mStartRootScrollY = 0;
    }

    private void resetPostCommitAnimator() {
@@ -236,6 +257,11 @@ public class ImeBackAnimationController implements OnBackAnimationCallback {
                == SOFT_INPUT_ADJUST_RESIZE;
    }

    private boolean isAdjustPan() {
        return (mViewRoot.mWindowAttributes.softInputMode & SOFT_INPUT_MASK_ADJUST)
                == SOFT_INPUT_ADJUST_PAN;
    }

    private boolean isHideAnimationInProgress() {
        return mPostCommitAnimator != null && mTriggerBack;
    }
+6 −1
Original line number Diff line number Diff line
@@ -66,7 +66,12 @@ public final class ImeInsetsSourceConsumer extends InsetsSourceConsumer {
                    "ImeInsetsSourceConsumer#onAnimationFinished",
                    mController.getHost().getInputMethodManager(), null /* icProto */);
        }
        final boolean insetsChanged = super.onAnimationStateChanged(running);
        boolean insetsChanged = super.onAnimationStateChanged(running);
        if (running && !isShowRequested() && mController.isPredictiveBackImeHideAnimInProgress()) {
            // IME predictive back animation switched from pre-commit to post-commit.
            insetsChanged |= applyLocalVisibilityOverride();
        }

        if (!isShowRequested()) {
            mIsRequestedVisibleAwaitingLeash = false;
            if (!running && !mHasPendingRequest) {
+1 −1
Original line number Diff line number Diff line
@@ -1620,7 +1620,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        onAnimationStateChanged(removedTypes, false /* running */);
    }

    private void onAnimationStateChanged(@InsetsType int types, boolean running) {
    void onAnimationStateChanged(@InsetsType int types, boolean running) {
        boolean insetsChanged = false;
        for (int i = mSourceConsumers.size() - 1; i >= 0; i--) {
            final InsetsSourceConsumer consumer = mSourceConsumers.valueAt(i);
+7 −0
Original line number Diff line number Diff line
@@ -5881,6 +5881,13 @@ public final class ViewRootImpl implements ViewParent,
        return handled;
    }
    void setScrollY(int scrollY) {
        if (mScroller != null) {
            mScroller.abortAnimation();
        }
        mScrollY = scrollY;
    }
    /**
     * @hide
     */