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

Commit 8b7c142c authored by Matt Sziklay's avatar Matt Sziklay Committed by Android (Google) Code Review
Browse files

Merge "Finish the veil fade in if a move occurs." into main

parents 13fb62b5 d02772a4
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);
    }