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

Commit a4e4cd1a authored by Taran Singh's avatar Taran Singh Committed by Android (Google) Code Review
Browse files

Merge "Add alpha support to Insets API"

parents 3d374500 699aa679
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -52801,6 +52801,7 @@ package android.view {
  public static final class WindowInsetsAnimationCallback.InsetsAnimation {
    ctor public WindowInsetsAnimationCallback.InsetsAnimation(int, @Nullable android.view.animation.Interpolator, long);
    method @FloatRange(from=0.0f, to=1.0f) public float getAlpha();
    method public long getDurationMillis();
    method @FloatRange(from=0.0f, to=1.0f) public float getFraction();
    method public float getInterpolatedFraction();
@@ -52817,6 +52818,7 @@ package android.view {
  public interface WindowInsetsAnimationController {
    method public void finish(boolean);
    method public float getCurrentAlpha();
    method @FloatRange(from=0.0f, to=1.0f) public float getCurrentFraction();
    method @NonNull public android.graphics.Insets getCurrentInsets();
    method @NonNull public android.graphics.Insets getHiddenStateInsets();
+28 −8
Original line number Diff line number Diff line
@@ -68,22 +68,26 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
    private final InsetsController mController;
    private final WindowInsetsAnimationCallback.InsetsAnimation mAnimation;
    private final Rect mFrame;
    private final boolean mFade;
    private Insets mCurrentInsets;
    private Insets mPendingInsets;
    private float mPendingFraction;
    private boolean mFinished;
    private boolean mCancelled;
    private boolean mShownOnFinish;
    private float mCurrentAlpha;
    private float mPendingAlpha;

    @VisibleForTesting
    public InsetsAnimationControlImpl(SparseArray<InsetsSourceConsumer> consumers, Rect frame,
            InsetsState state, WindowInsetsAnimationControlListener listener,
            @InsetsType int types,
            Supplier<SyncRtSurfaceTransactionApplier> transactionApplierSupplier,
            InsetsController controller, long durationMs) {
            InsetsController controller, long durationMs, boolean fade) {
        mConsumers = consumers;
        mListener = listener;
        mTypes = types;
        mFade = fade;
        mTransactionApplierSupplier = transactionApplierSupplier;
        mController = controller;
        mInitialInsetsState = new InsetsState(state, true /* copySources */);
@@ -100,6 +104,7 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll

        mAnimation = new WindowInsetsAnimationCallback.InsetsAnimation(mTypes,
                InsetsController.INTERPOLATOR, durationMs);
        mAnimation.setAlpha(getCurrentAlpha());
        mController.dispatchAnimationStarted(mAnimation,
                new AnimationBounds(mHiddenInsets, mShownInsets));
    }
@@ -119,6 +124,11 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
        return mCurrentInsets;
    }

    @Override
    public float getCurrentAlpha() {
        return mCurrentAlpha;
    }

    @Override
    @InsetsType public int getTypes() {
        return mTypes;
@@ -136,6 +146,7 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
        }
        mPendingFraction = sanitize(fraction);
        mPendingInsets = sanitize(insets);
        mPendingAlpha = 1 - sanitize(alpha);
        mController.scheduleApplyChangeInsets();
    }

@@ -148,17 +159,24 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
            return false;
        }
        final Insets offset = Insets.subtract(mShownInsets, mPendingInsets);
        final Float alphaOffset = 1 - mPendingAlpha;
        ArrayList<SurfaceParams> params = new ArrayList<>();
        updateLeashesForSide(ISIDE_LEFT, offset.left, mPendingInsets.left, params, state);
        updateLeashesForSide(ISIDE_TOP, offset.top, mPendingInsets.top, params, state);
        updateLeashesForSide(ISIDE_RIGHT, offset.right, mPendingInsets.right, params, state);
        updateLeashesForSide(ISIDE_BOTTOM, offset.bottom, mPendingInsets.bottom, params, state);
        updateLeashesForSide(ISIDE_FLOATING, 0 /* offset */, 0 /* inset */, params, state);
        updateLeashesForSide(ISIDE_LEFT, offset.left, mShownInsets.left, mPendingInsets.left,
                params, state, alphaOffset);
        updateLeashesForSide(ISIDE_TOP, offset.top, mShownInsets.top, mPendingInsets.top, params,
                state, alphaOffset);
        updateLeashesForSide(ISIDE_RIGHT, offset.right, mShownInsets.right, mPendingInsets.right,
                params, state, alphaOffset);
        updateLeashesForSide(ISIDE_BOTTOM, offset.bottom, mShownInsets.bottom,
                mPendingInsets.bottom, params, state, alphaOffset);
        updateLeashesForSide(ISIDE_FLOATING, 0 /* offset */, 0 /* inset */, 0 /* maxInset */,
                params, state, alphaOffset);

        SyncRtSurfaceTransactionApplier applier = mTransactionApplierSupplier.get();
        applier.scheduleApply(params.toArray(new SurfaceParams[params.size()]));
        mCurrentInsets = mPendingInsets;
        mAnimation.setFraction(mPendingFraction);
        mCurrentAlpha = 1 - alphaOffset;
        if (mFinished) {
            mController.notifyFinished(this, mShownOnFinish);
        }
@@ -233,7 +251,7 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
    }

    private void updateLeashesForSide(@InternalInsetsSide int side, int offset, int inset,
            ArrayList<SurfaceParams> surfaceParams, InsetsState state) {
            int maxInset, ArrayList<SurfaceParams> surfaceParams, InsetsState state, Float alpha) {
        ArraySet<InsetsSourceConsumer> items = mSideSourceMap.get(side);
        if (items == null) {
            return;
@@ -257,7 +275,9 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll

            // If the system is controlling the insets source, the leash can be null.
            if (leash != null) {
                surfaceParams.add(new SurfaceParams(leash, 1f /* alpha */, mTmpMatrix,
                // TODO: use a better interpolation for fade.
                alpha = mFade ? ((float) maxInset / inset * 0.3f + 0.7f) : alpha;
                surfaceParams.add(new SurfaceParams(leash, alpha, mTmpMatrix,
                        null /* windowCrop */, 0 /* layer */, 0f /* cornerRadius*/,
                        side == ISIDE_FLOATING ? consumer.isVisible() : inset != 0 /* visible */));
            }
+5 −4
Original line number Diff line number Diff line
@@ -361,12 +361,12 @@ public class InsetsController implements WindowInsetsController {
            listener.onCancelled();
            return;
        }
        controlAnimationUnchecked(types, listener, mFrame, fromIme, durationMs);
        controlAnimationUnchecked(types, listener, mFrame, fromIme, durationMs, false /* fade */);
    }

    private void controlAnimationUnchecked(@InsetsType int types,
            WindowInsetsAnimationControlListener listener, Rect frame, boolean fromIme,
            long durationMs) {
            long durationMs, boolean fade) {
        if (types == 0) {
            // nothing to animate.
            return;
@@ -397,7 +397,7 @@ public class InsetsController implements WindowInsetsController {

        final InsetsAnimationControlImpl controller = new InsetsAnimationControlImpl(consumers,
                frame, mState, listener, typesReady,
                () -> new SyncRtSurfaceTransactionApplier(mViewRoot.mView), this, durationMs);
                () -> new SyncRtSurfaceTransactionApplier(mViewRoot.mView), this, durationMs, fade);
        mAnimationControls.add(controller);
    }

@@ -588,7 +588,8 @@ public class InsetsController implements WindowInsetsController {
        // Show/hide animations always need to be relative to the display frame, in order that shown
        // and hidden state insets are correct.
        controlAnimationUnchecked(
                types, listener, mState.getDisplayFrame(), fromIme, listener.getDurationMs());
                types, listener, mState.getDisplayFrame(), fromIme, listener.getDurationMs(),
                true /* fade */);
    }

    private void hideDirectly(@InsetsType int types) {
+13 −0
Original line number Diff line number Diff line
@@ -89,6 +89,7 @@ public interface WindowInsetsAnimationCallback {
        private float mFraction;
        @Nullable private final Interpolator mInterpolator;
        private long mDurationMs;
        private float mAlpha;

        public InsetsAnimation(
                @InsetsType int typeMask, @Nullable Interpolator interpolator, long durationMs) {
@@ -177,6 +178,18 @@ public interface WindowInsetsAnimationCallback {
        public void setDuration(long durationMs) {
            mDurationMs = durationMs;
        }

        /**
         * @return alpha of {@link WindowInsets.Type.InsetsType}.
         */
        @FloatRange(from = 0f, to = 1f)
        public float getAlpha() {
            return mAlpha;
        }

        void setAlpha(@FloatRange(from = 0f, to = 1f) float alpha) {
            mAlpha = alpha;
        }
    }

    /**
+6 −0
Original line number Diff line number Diff line
@@ -92,6 +92,12 @@ public interface WindowInsetsAnimationController {
    @FloatRange(from = 0f, to = 1f)
    float getCurrentFraction();

    /**
     * Current alpha value of the window.
     * @return float value between 0 and 1.
     */
    float getCurrentAlpha();

    /**
     * @return The {@link InsetsType}s this object is currently controlling.
     */
Loading