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

Commit 55a32272 authored by Jon Miranda's avatar Jon Miranda
Browse files

Add remote animation for unlocking device.

Removed the workaround we had for animating sysui scrim based on SCREEN_OFF
and USER_PRESENT, since it is now properly handled via the unlock animation.

Bug: 65162781
Change-Id: I5341cc1d3b4f0761b8cf58fdc9fc1b895f2a128e
parent 5a763a25
Loading
Loading
Loading
Loading
+56 −11
Original line number Diff line number Diff line
@@ -215,7 +215,8 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag
                        playIconAnimators(anim, v, windowTargetBounds, !isAllOpeningTargetTrs);
                        if (launcherClosing) {
                            Pair<AnimatorSet, Runnable> launcherContentAnimator =
                                    getLauncherContentAnimator(true /* isAppOpening */);
                                    getLauncherContentAnimator(true /* isAppOpening */,
                                            new float[] {0, mContentTransY});
                            anim.play(launcherContentAnimator.first);
                            anim.addListener(new AnimatorListenerAdapter() {
                                @Override
@@ -350,17 +351,16 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag
     *
     * @param isAppOpening True when this is called when an app is opening.
     *                     False when this is called when an app is closing.
     * @param trans Array that contains the start and end translation values for the content.
     */
    private Pair<AnimatorSet, Runnable> getLauncherContentAnimator(boolean isAppOpening) {
    private Pair<AnimatorSet, Runnable> getLauncherContentAnimator(boolean isAppOpening,
            float[] trans) {
        AnimatorSet launcherAnimator = new AnimatorSet();
        Runnable endListener;

        float[] alphas = isAppOpening
                ? new float[] {1, 0}
                : new float[] {0, 1};
        float[] trans = isAppOpening
                ? new float[] {0, mContentTransY}
                : new float[] {-mContentTransY, 0};

        if (mLauncher.isInState(ALL_APPS)) {
            // All Apps in portrait mode is full screen, so we only animate AllAppsContainerView.
@@ -681,10 +681,13 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag
            RemoteAnimationDefinitionCompat definition = new RemoteAnimationDefinitionCompat();
            definition.addRemoteAnimation(WindowManagerWrapper.TRANSIT_WALLPAPER_OPEN,
                    WindowManagerWrapper.ACTIVITY_TYPE_STANDARD,
                    new RemoteAnimationAdapterCompat(getWallpaperOpenRunner(),
                    new RemoteAnimationAdapterCompat(getWallpaperOpenRunner(false /* fromUnlock */),
                            CLOSING_TRANSITION_DURATION_MS, 0 /* statusBarTransitionDelay */));

            // TODO: Transition for unlock to home TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER
            definition.addRemoteAnimation(
                    WindowManagerWrapper.TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER,
                    new RemoteAnimationAdapterCompat(getWallpaperOpenRunner(true /* fromUnlock */),
                            CLOSING_TRANSITION_DURATION_MS, 0 /* statusBarTransitionDelay */));
            new ActivityCompat(mLauncher).registerRemoteAnimations(definition);
        }
    }
@@ -697,7 +700,7 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag
     * @return Runner that plays when user goes to Launcher
     *         ie. pressing home, swiping up from nav bar.
     */
    private RemoteAnimationRunnerCompat getWallpaperOpenRunner() {
    private RemoteAnimationRunnerCompat getWallpaperOpenRunner(boolean fromUnlock) {
        return new LauncherAnimationRunner(mHandler, false /* startAtFrontOfQueue */) {
            @Override
            public void onCreateAnimation(RemoteAnimationTargetCompat[] targetCompats,
@@ -723,7 +726,9 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag

                if (anim == null) {
                    anim = new AnimatorSet();
                    anim.play(getClosingWindowAnimators(targetCompats));
                    anim.play(fromUnlock
                            ? getUnlockWindowAnimator(targetCompats)
                            : getClosingWindowAnimators(targetCompats));

                    // Normally, we run the launcher content animation when we are transitioning
                    // home, but if home is already visible, then we don't want to animate the
@@ -737,9 +742,23 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag
                            || mLauncher.isForceInvisible()) {
                        // Only register the content animation for cancellation when state changes
                        mLauncher.getStateManager().setCurrentAnimation(anim);
                        if (fromUnlock) {
                            Pair<AnimatorSet, Runnable> contentAnimator =
                                    getLauncherContentAnimator(false /* isAppOpening */,
                                            new float[] {mContentTransY, 0});
                            contentAnimator.first.setStartDelay(0);
                            anim.play(contentAnimator.first);
                            anim.addListener(new AnimatorListenerAdapter() {
                                @Override
                                public void onAnimationEnd(Animator animation) {
                                    contentAnimator.second.run();
                                }
                            });
                        } else {
                            createLauncherResumeAnimation(anim);
                        }
                    }
                }

                mLauncher.clearForceInvisibleFlag(INVISIBLE_ALL);
                result.setAnimation(anim);
@@ -747,6 +766,31 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag
        };
    }

    /**
     * Animator that controls the transformations of the windows when unlocking the device.
     */
    private Animator getUnlockWindowAnimator(RemoteAnimationTargetCompat[] targets) {
        SyncRtSurfaceTransactionApplierCompat surfaceApplier =
                new SyncRtSurfaceTransactionApplierCompat(mDragLayer);
        ValueAnimator unlockAnimator = ValueAnimator.ofFloat(0, 1);
        unlockAnimator.setDuration(CLOSING_TRANSITION_DURATION_MS);
        float cornerRadius = RecentsModel.INSTANCE.get(mLauncher).getWindowCornerRadius();
        unlockAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                SurfaceParams[] params = new SurfaceParams[targets.length];
                for (int i = targets.length - 1; i >= 0; i--) {
                    RemoteAnimationTargetCompat target = targets[i];
                    params[i] = new SurfaceParams(target.leash, 1f, null,
                            target.sourceContainerBounds,
                            RemoteAnimationProvider.getLayer(target, MODE_OPENING), cornerRadius);
                }
                surfaceApplier.scheduleApply(params);
            }
        });
        return unlockAnimator;
    }

    /**
     * Animator that controls the transformations of the windows the targets that are closing.
     */
@@ -801,7 +845,8 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag
    private void createLauncherResumeAnimation(AnimatorSet anim) {
        if (mLauncher.isInState(LauncherState.ALL_APPS)) {
            Pair<AnimatorSet, Runnable> contentAnimator =
                    getLauncherContentAnimator(false /* isAppOpening */);
                    getLauncherContentAnimator(false /* isAppOpening */,
                            new float[] {-mContentTransY, 0});
            contentAnimator.first.setStartDelay(LAUNCHER_RESUME_START_DELAY);
            anim.play(contentAnimator.first);
            anim.addListener(new AnimatorListenerAdapter() {
+0 −30
Original line number Diff line number Diff line
@@ -16,16 +16,9 @@

package com.android.launcher3.graphics;

import static android.content.Intent.ACTION_SCREEN_OFF;
import static android.content.Intent.ACTION_USER_PRESENT;

import static com.android.launcher3.icons.GraphicsUtils.setColorAlphaBound;

import android.animation.ObjectAnimator;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
@@ -96,20 +89,6 @@ public class WorkspaceAndHotseatScrim implements
                }
            };

    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            final String action = intent.getAction();
            if (ACTION_SCREEN_OFF.equals(action)) {
                mAnimateScrimOnNextDraw = true;
            } else if (ACTION_USER_PRESENT.equals(action)) {
                // ACTION_USER_PRESENT is sent after onStart/onResume. This covers the case where
                // the user unlocked and the Launcher is not in the foreground.
                mAnimateScrimOnNextDraw = false;
            }
        }
    };

    private static final int DARK_SCRIM_COLOR = 0x55000000;
    private static final int MAX_HOTSEAT_SCRIM_ALPHA = 100;
    private static final int ALPHA_MASK_HEIGHT_DP = 500;
@@ -225,20 +204,11 @@ public class WorkspaceAndHotseatScrim implements
    public void onViewAttachedToWindow(View view) {
        mWallpaperColorInfo.addOnChangeListener(this);
        onExtractedColorsChanged(mWallpaperColorInfo);

        if (mTopScrim != null) {
            IntentFilter filter = new IntentFilter(ACTION_SCREEN_OFF);
            filter.addAction(ACTION_USER_PRESENT); // When the device wakes up + keyguard is gone
            mRoot.getContext().registerReceiver(mReceiver, filter);
        }
    }

    @Override
    public void onViewDetachedFromWindow(View view) {
        mWallpaperColorInfo.removeOnChangeListener(this);
        if (mTopScrim != null) {
            mRoot.getContext().unregisterReceiver(mReceiver);
        }
    }

    @Override