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

Commit 46d259d9 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Updating launch transition for transparent activities

When a transparent activity is started from recents, animate the launcher
NORMAL state instead of animating the launcher UI separately

Change-Id: Ibfc9f7096f668e0129042b8a69ed5130029df797
parent e4a97a5c
Loading
Loading
Loading
Loading
+48 −20
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.launcher3;

import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY;
import static com.android.launcher3.LauncherState.NORMAL;
import static com.android.launcher3.allapps.AllAppsTransitionController.ALL_APPS_PROGRESS;
import static com.android.systemui.shared.recents.utilities.Utilities.getNextFrameNumber;
import static com.android.systemui.shared.recents.utilities.Utilities.getSurface;
@@ -48,6 +49,7 @@ import android.view.animation.Interpolator;
import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener;
import com.android.launcher3.InsettableFrameLayout.LayoutParams;
import com.android.launcher3.allapps.AllAppsTransitionController;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.anim.Interpolators;
import com.android.launcher3.anim.PropertyListBuilder;
import com.android.launcher3.dragndrop.DragLayer;
@@ -227,7 +229,7 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag
        // Resolve the opening task id
        int openingTaskId = -1;
        for (RemoteAnimationTargetCompat target : targets) {
            if (target.mode == RemoteAnimationTargetCompat.MODE_OPENING) {
            if (target.mode == MODE_OPENING) {
                openingTaskId = target.taskId;
                break;
            }
@@ -247,8 +249,36 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag
        }

        // Found a visible recents task that matches the opening app, lets launch the app from there
        return new LauncherTransitionAnimator(getRecentsLauncherAnimator(recentsView, taskView),
                getRecentsWindowAnimator(taskView, targets));
        Animator launcherAnim;
        AnimatorListenerAdapter windowAnimEndListener;
        boolean launcherClosing = launcherIsATargetWithMode(targets, MODE_CLOSING);
        if (launcherClosing) {
            launcherAnim = getRecentsLauncherAnimator(recentsView, taskView);
            windowAnimEndListener = new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    // Make sure recents gets fixed up by resetting task alphas and scales, etc.
                    mLauncher.getStateManager().reapplyState();
                }
            };
        } else {
            AnimatorPlaybackController controller =
                    mLauncher.getStateManager()
                            .createAnimationToNewWorkspace(NORMAL, RECENTS_LAUNCH_DURATION);
            controller.dispatchOnStart();
            launcherAnim = controller.getAnimationPlayer().setDuration(RECENTS_LAUNCH_DURATION);
            windowAnimEndListener = new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    mLauncher.getStateManager().goToState(NORMAL, false);
                }
            };
        }

        MutableBoolean skipLauncherChanges = new MutableBoolean(!launcherClosing);
        Animator windowAnim = getRecentsWindowAnimator(taskView, skipLauncherChanges, targets);
        windowAnim.addListener(windowAnimEndListener);
        return new LauncherTransitionAnimator(launcherAnim, windowAnim, skipLauncherChanges);
    }

    /**
@@ -318,7 +348,7 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag
        launcherAnimator.play(allAppsSlideOut);

        Workspace workspace = mLauncher.getWorkspace();
        float[] workspaceScaleAndTranslation = LauncherState.NORMAL
        float[] workspaceScaleAndTranslation = NORMAL
                .getWorkspaceScaleAndTranslation(mLauncher);
        Animator recenterWorkspace = LauncherAnimUtils.ofPropertyValuesHolder(
                workspace, new PropertyListBuilder()
@@ -338,7 +368,7 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag
     * @return Animator that controls the window of the opening targets for the recents launch
     * animation.
     */
    private ValueAnimator getRecentsWindowAnimator(TaskView v,
    private ValueAnimator getRecentsWindowAnimator(TaskView v, MutableBoolean skipLauncherChanges,
            RemoteAnimationTargetCompat[] targets) {
        Rect taskViewBounds = new Rect();
        mDragLayer.getDescendantRectRelativeToSelf(v, taskViewBounds);
@@ -374,6 +404,7 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag
                final float percent = animation.getAnimatedFraction();
                TaskWindowBounds tw = recentsInterpolator.interpolate(percent);

                if (!skipLauncherChanges.value) {
                    v.setScaleX(tw.taskScale);
                    v.setScaleY(tw.taskScale);
                    v.setTranslationX(tw.taskX);
@@ -381,6 +412,7 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag
                    // Defer fading out the view until after the app window gets faded in
                    v.setAlpha(getValue(1f, 0f, 75, 75,
                            appAnimator.getDuration() * percent, Interpolators.LINEAR));
                }

                matrix.setScale(tw.winScale, tw.winScale);
                matrix.postTranslate(tw.winX, tw.winY);
@@ -402,7 +434,10 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag
                        matrix.postTranslate(target.position.x, target.position.y);
                        t.setMatrix(target.leash, matrix);
                        t.setWindowCrop(target.leash, crop);
                        t.deferTransactionUntil(target.leash, surface, getNextFrameNumber(surface));

                        if (!skipLauncherChanges.value) {
                            t.deferTransactionUntil(target.leash, surface, frameNumber);
                        }
                    }
                    if (isFirstFrame) {
                        t.show(target.leash);
@@ -414,13 +449,6 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag
                isFirstFrame = false;
            }
        });
        appAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                // Make sure recents gets fixed up by resetting task alphas and scales, etc.
                mLauncher.getStateManager().reapplyState();
            }
        });
        return appAnimator;
    }

+11 −0
Original line number Diff line number Diff line
@@ -27,11 +27,20 @@ import android.animation.AnimatorSet;
 */
public class LauncherTransitionAnimator {

    private final MutableBoolean mLauncherAnimCancelState;

    private AnimatorSet mAnimatorSet;
    private Animator mLauncherAnimator;
    private Animator mWindowAnimator;

    LauncherTransitionAnimator(Animator launcherAnimator, Animator windowAnimator) {
        this(launcherAnimator, windowAnimator, new MutableBoolean(false));
    }


    LauncherTransitionAnimator(Animator launcherAnimator, Animator windowAnimator,
            MutableBoolean launcherAnimCancelState) {
        mLauncherAnimCancelState = launcherAnimCancelState;
        if (launcherAnimator != null) {
            mLauncherAnimator = launcherAnimator;
        }
@@ -50,6 +59,7 @@ public class LauncherTransitionAnimator {

    public void cancel() {
        mAnimatorSet.cancel();
        mLauncherAnimCancelState.value = true;
    }

    public boolean isRunning() {
@@ -58,6 +68,7 @@ public class LauncherTransitionAnimator {

    public void finishLauncherAnimation() {
        if (mLauncherAnimator != null) {
            mLauncherAnimCancelState.value = true;
            mLauncherAnimator.end();
        }
    }
+25 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.launcher3;

public class MutableBoolean {
    public boolean value;

    public MutableBoolean(boolean value) {
        this.value = value;
    }
}