Merge "Simplifying animation creating logic for app-to-overview" into ub-launcher3-rvc-dev

This commit is contained in:
TreeHugger Robot
2020-05-12 18:42:22 +00:00
committed by Android (Google) Code Review
6 changed files with 50 additions and 79 deletions

View File

@@ -17,7 +17,6 @@ package com.android.quickstep;
import static com.android.launcher3.LauncherState.BACKGROUND_APP;
import static com.android.launcher3.LauncherState.OVERVIEW;
import static com.android.launcher3.anim.Interpolators.FAST_OUT_SLOW_IN;
import static com.android.launcher3.anim.Interpolators.TOUCH_RESPONSE_INTERPOLATOR;
import static com.android.launcher3.statehandlers.DepthController.DEPTH;
import static com.android.systemui.shared.system.RemoteAnimationTargetCompat.MODE_CLOSING;
@@ -75,14 +74,10 @@ final class AppToOverviewAnimationProvider<T extends BaseDraggingActivity> exten
boolean onActivityReady(T activity, Boolean wasVisible) {
activity.<RecentsView>getOverviewPanel().showCurrentTask(mTargetTaskId);
AbstractFloatingView.closeAllOpenViews(activity, wasVisible);
BaseActivityInterface.AnimationFactory factory =
mActivityInterface.prepareRecentsUI(wasVisible,
false /* animate activity */, (controller) -> {
BaseActivityInterface.AnimationFactory factory = mActivityInterface.prepareRecentsUI(
wasVisible, (controller) -> {
controller.dispatchOnStart();
ValueAnimator anim = controller.getAnimationPlayer()
.setDuration(RECENTS_LAUNCH_DURATION);
anim.setInterpolator(FAST_OUT_SLOW_IN);
anim.start();
controller.getAnimationPlayer().end();
});
factory.onRemoteAnimationReceived(null);
factory.createActivityInterface(RECENTS_LAUNCH_DURATION);

View File

@@ -86,8 +86,8 @@ public final class FallbackActivityInterface implements
}
@Override
public AnimationFactory prepareRecentsUI(boolean activityVisible,
boolean animateActivity, Consumer<AnimatorPlaybackController> callback) {
public AnimationFactory prepareRecentsUI(
boolean activityVisible, Consumer<AnimatorPlaybackController> callback) {
RecentsActivity activity = getCreatedActivity();
if (activityVisible) {
return (transitionLength) -> { };
@@ -97,9 +97,7 @@ public final class FallbackActivityInterface implements
rv.setContentAlpha(0);
rv.getClearAllButton().setVisibilityAlpha(0);
rv.setDisallowScrollToClearAll(true);
boolean fromState = !animateActivity;
rv.setInOverviewState(fromState);
rv.setInOverviewState(false);
return new AnimationFactory() {
@@ -132,12 +130,8 @@ public final class FallbackActivityInterface implements
AnimatorPlaybackController.wrap(animatorSet, transitionLength);
// Since we are changing the start position of the UI, reapply the state, at the end
controller.setEndAction(() -> {
boolean endState = true;
rv.setInOverviewState(controller.getInterpolatedProgress() > 0.5 ?
endState : fromState);
});
controller.setEndAction(() ->
rv.setInOverviewState(controller.getInterpolatedProgress() > 0.5));
callback.accept(controller);
}
};

View File

@@ -27,10 +27,9 @@ import static com.android.launcher3.uioverrides.states.QuickstepAtomicAnimationF
import static com.android.quickstep.LauncherSwipeHandler.RECENTS_ATTACH_DURATION;
import static com.android.quickstep.util.WindowSizeStrategy.LAUNCHER_ACTIVITY_SIZE_STRATEGY;
import static com.android.quickstep.views.RecentsView.ADJACENT_PAGE_OFFSET;
import static com.android.quickstep.views.RecentsView.FULLSCREEN_PROGRESS;
import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.graphics.Rect;
import android.util.Log;
@@ -47,6 +46,7 @@ import com.android.launcher3.LauncherInitListener;
import com.android.launcher3.LauncherState;
import com.android.launcher3.allapps.DiscoveryBounce;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.anim.PendingAnimation;
import com.android.launcher3.appprediction.PredictionUiStateManager;
import com.android.launcher3.statehandlers.DepthController;
import com.android.launcher3.statehandlers.DepthController.ClampedDepthProperty;
@@ -134,8 +134,8 @@ public final class LauncherActivityInterface implements BaseActivityInterface<La
}
@Override
public AnimationFactory prepareRecentsUI(boolean activityVisible,
boolean animateActivity, Consumer<AnimatorPlaybackController> callback) {
public AnimationFactory prepareRecentsUI(
boolean activityVisible, Consumer<AnimatorPlaybackController> callback) {
BaseQuickstepLauncher launcher = getCreatedActivity();
final LauncherState startState = launcher.getStateManager().getState();
@@ -145,8 +145,7 @@ public final class LauncherActivityInterface implements BaseActivityInterface<La
}
launcher.getStateManager().setRestState(resetState);
final LauncherState fromState = animateActivity ? BACKGROUND_APP : OVERVIEW;
launcher.getStateManager().goToState(fromState, false);
launcher.getStateManager().goToState(BACKGROUND_APP, false);
// Since all apps is not visible, we can safely reset the scroll position.
// This ensures then the next swipe up to all-apps starts from scroll 0.
launcher.getAppsView().reset(false /* animate */);
@@ -157,7 +156,7 @@ public final class LauncherActivityInterface implements BaseActivityInterface<La
@Override
public void createActivityInterface(long transitionLength) {
createActivityInterfaceInternal(launcher, fromState, transitionLength, callback);
callback.accept(createBackgroundToOverviewAnim(launcher, transitionLength));
// Creating the activity controller animation sometimes reapplies the launcher state
// (because we set the animation as the current state animation), so we reapply the
// attached state here as well to ensure recents is shown/hidden appropriately.
@@ -211,68 +210,45 @@ public final class LauncherActivityInterface implements BaseActivityInterface<La
};
}
private void createActivityInterfaceInternal(Launcher activity, LauncherState fromState,
long transitionLength, Consumer<AnimatorPlaybackController> callback) {
LauncherState endState = OVERVIEW;
if (fromState == endState) {
return;
}
private AnimatorPlaybackController createBackgroundToOverviewAnim(
Launcher activity, long transitionLength) {
PendingAnimation pa = new PendingAnimation(transitionLength * 2);
AnimatorSet anim = new AnimatorSet();
if (!activity.getDeviceProfile().isVerticalBarLayout()
&& SysUINavigationMode.getMode(activity) != Mode.NO_BUTTON) {
// Don't animate the shelf when the mode is NO_BUTTON, because we update it atomically.
anim.play(activity.getStateManager().createStateElementAnimation(
pa.add(activity.getStateManager().createStateElementAnimation(
INDEX_SHELF_ANIM,
fromState.getVerticalProgress(activity),
endState.getVerticalProgress(activity)));
BACKGROUND_APP.getVerticalProgress(activity),
OVERVIEW.getVerticalProgress(activity)));
}
// Animate the blur and wallpaper zoom
DepthController depthController = getDepthController();
float fromDepthRatio = fromState.getDepth(activity);
float toDepthRatio = endState.getDepth(activity);
Animator depthAnimator = ObjectAnimator.ofFloat(depthController,
new ClampedDepthProperty(fromDepthRatio, toDepthRatio),
fromDepthRatio, toDepthRatio);
anim.play(depthAnimator);
float fromDepthRatio = BACKGROUND_APP.getDepth(activity);
float toDepthRatio = OVERVIEW.getDepth(activity);
pa.addFloat(getDepthController(), new ClampedDepthProperty(fromDepthRatio, toDepthRatio),
fromDepthRatio, toDepthRatio, LINEAR);
playScaleDownAnim(anim, activity, fromState, endState);
anim.setDuration(transitionLength * 2);
anim.setInterpolator(LINEAR);
AnimatorPlaybackController controller =
AnimatorPlaybackController.wrap(anim, transitionLength * 2);
// Scale down recents from being full screen to being in overview.
RecentsView recentsView = activity.getOverviewPanel();
pa.addFloat(recentsView, SCALE_PROPERTY,
BACKGROUND_APP.getOverviewScaleAndOffset(activity)[0],
OVERVIEW.getOverviewScaleAndOffset(activity)[0],
LINEAR);
pa.addFloat(recentsView, FULLSCREEN_PROGRESS,
BACKGROUND_APP.getOverviewFullscreenProgress(),
OVERVIEW.getOverviewFullscreenProgress(),
LINEAR);
AnimatorPlaybackController controller = pa.createPlaybackController();
activity.getStateManager().setCurrentUserControlledAnimation(controller);
// Since we are changing the start position of the UI, reapply the state, at the end
controller.setEndAction(() -> {
activity.getStateManager().goToState(
controller.getInterpolatedProgress() > 0.5 ? endState : fromState, false);
});
callback.accept(controller);
}
/**
* Scale down recents from the center task being full screen to being in overview.
*/
private void playScaleDownAnim(AnimatorSet anim, Launcher launcher, LauncherState fromState,
LauncherState endState) {
RecentsView recentsView = launcher.getOverviewPanel();
if (recentsView.getCurrentPageTaskView() == null) {
return;
}
float fromFullscreenProgress = fromState.getOverviewFullscreenProgress();
float endFullscreenProgress = endState.getOverviewFullscreenProgress();
float fromScale = fromState.getOverviewScaleAndOffset(launcher)[0];
float endScale = endState.getOverviewScaleAndOffset(launcher)[0];
Animator scale = ObjectAnimator.ofFloat(recentsView, SCALE_PROPERTY, fromScale, endScale);
Animator applyFullscreenProgress = ObjectAnimator.ofFloat(recentsView,
RecentsView.FULLSCREEN_PROGRESS, fromFullscreenProgress, endFullscreenProgress);
anim.playTogether(scale, applyFullscreenProgress);
controller.setEndAction(() -> activity.getStateManager().goToState(
controller.getInterpolatedProgress() > 0.5 ? OVERVIEW : BACKGROUND_APP, false));
return controller;
}
@Override

View File

@@ -335,8 +335,7 @@ public class LauncherSwipeHandler extends BaseSwipeUpHandler<Launcher, RecentsVi
if (mGestureState.getEndTarget() != HOME) {
Runnable initAnimFactory = () -> {
mAnimationFactory = mActivityInterface.prepareRecentsUI(
mWasLauncherAlreadyVisible, true,
this::onAnimatorPlaybackControllerCreated);
mWasLauncherAlreadyVisible, this::onAnimatorPlaybackControllerCreated);
maybeUpdateRecentsAttachedState(false /* animate */);
};
if (mWasLauncherAlreadyVisible) {

View File

@@ -53,8 +53,8 @@ public interface BaseActivityInterface<T extends BaseDraggingActivity> {
default void onSwipeUpToHomeComplete() { }
void onAssistantVisibilityChanged(float visibility);
AnimationFactory prepareRecentsUI(boolean activityVisible, boolean animateActivity,
Consumer<AnimatorPlaybackController> callback);
AnimationFactory prepareRecentsUI(
boolean activityVisible, Consumer<AnimatorPlaybackController> callback);
ActivityInitListener createActivityInitListener(Predicate<Boolean> onInitListener);

View File

@@ -105,6 +105,13 @@ public class PendingAnimation implements PropertySetter {
add(anim);
}
public <T> void addFloat(T target, FloatProperty<T> property, float from, float to,
TimeInterpolator interpolator) {
Animator anim = ObjectAnimator.ofFloat(target, property, from, to);
anim.setDuration(mDuration).setInterpolator(interpolator);
add(anim);
}
@Override
public <T> void setInt(T target, IntProperty<T> property, int value,
TimeInterpolator interpolator) {