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

Commit d02772a4 authored by mattsziklay's avatar mattsziklay
Browse files

Finish the veil fade in if a move occurs.

Separates the veil and icon fade in into two separate animations and
finishes the former if the veil is resized while the aniamtion is running. This gives the appearance of fading in while preventing the adjusted bounds of a task from showing as empty space behind the transparent veil.

Bug: 296920474
Test: Manual
Change-Id: I0954a2f2e4d24a4b1d0c21747e2f5f0f12072ba8
parent 5321c545
Loading
Loading
Loading
Loading
+26 −8
Original line number Diff line number Diff line
@@ -49,11 +49,13 @@ public class ResizeVeil {
    private final Supplier<SurfaceControl.Builder> mSurfaceControlBuilderSupplier;
    private final Supplier<SurfaceControl.Transaction> mSurfaceControlTransactionSupplier;
    private final Drawable mAppIcon;
    private ImageView mIconView;
    private SurfaceControl mParentSurface;
    private SurfaceControl mVeilSurface;
    private final RunningTaskInfo mTaskInfo;
    private SurfaceControlViewHost mViewHost;
    private final Display mDisplay;
    private ValueAnimator mVeilAnimator;

    public ResizeVeil(Context context, Drawable appIcon, RunningTaskInfo taskInfo,
            Supplier<SurfaceControl.Builder> surfaceControlBuilderSupplier, Display display,
@@ -97,8 +99,8 @@ public class ResizeVeil {
        mViewHost = new SurfaceControlViewHost(mContext, mDisplay, windowManager, "ResizeVeil");
        mViewHost.setView(v, lp);

        final ImageView appIcon = mViewHost.getView().findViewById(R.id.veil_application_icon);
        appIcon.setImageDrawable(mAppIcon);
        mIconView = mViewHost.getView().findViewById(R.id.veil_application_icon);
        mIconView.setImageDrawable(mAppIcon);
    }

    /**
@@ -123,17 +125,27 @@ public class ResizeVeil {

        relayout(taskBounds, t);
        if (fadeIn) {
            final ValueAnimator animator = new ValueAnimator();
            animator.setFloatValues(0f, 1f);
            animator.setDuration(RESIZE_ALPHA_DURATION);
            animator.addUpdateListener(animation -> {
                t.setAlpha(mVeilSurface, animator.getAnimatedFraction());
            mVeilAnimator = new ValueAnimator();
            mVeilAnimator.setFloatValues(0f, 1f);
            mVeilAnimator.setDuration(RESIZE_ALPHA_DURATION);
            mVeilAnimator.addUpdateListener(animation -> {
                t.setAlpha(mVeilSurface, mVeilAnimator.getAnimatedFraction());
                t.apply();
            });

            final ValueAnimator iconAnimator = new ValueAnimator();
            iconAnimator.setFloatValues(0f, 1f);
            iconAnimator.setDuration(RESIZE_ALPHA_DURATION);
            iconAnimator.addUpdateListener(animation -> {
                mIconView.setAlpha(animation.getAnimatedFraction());
            });

            t.show(mVeilSurface)
                    .addTransactionCommittedListener(
                            mContext.getMainExecutor(), () -> animator.start())
                            mContext.getMainExecutor(), () -> {
                                mVeilAnimator.start();
                                iconAnimator.start();
                            })
                    .setAlpha(mVeilSurface, 0);
        } else {
            // Show the veil immediately at full opacity.
@@ -172,11 +184,17 @@ public class ResizeVeil {

    /**
     * Calls relayout to update task and veil bounds.
     * Finishes veil fade in if animation is currently running; this is to prevent empty space
     * being visible behind the transparent veil during a fast resize.
     *
     * @param t a transaction to be applied in sync with the veil draw.
     * @param newBounds bounds to update veil to.
     */
    public void updateResizeVeil(SurfaceControl.Transaction t, Rect newBounds) {
        if (mVeilAnimator != null && mVeilAnimator.isStarted()) {
            // TODO(b/300145351): Investigate why ValueAnimator#end does not work here.
            mVeilAnimator.setCurrentPlayTime(RESIZE_ALPHA_DURATION);
        }
        relayout(newBounds, t);
        mViewHost.getView().getViewRootImpl().applyTransactionOnDraw(t);
    }