mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-04 09:56:49 +00:00
Moving some methods related to task launch animation to
recents view and related classes. This allows the common animation to be used in fallback activity. Bug: 75979063 Change-Id: I2b5bf5e66406621305b9a076793434f9c5cecdfd
This commit is contained in:
@@ -17,7 +17,6 @@
|
||||
package com.android.launcher3;
|
||||
|
||||
import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY;
|
||||
import static com.android.launcher3.LauncherState.ALL_APPS_HEADER_EXTRA;
|
||||
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;
|
||||
@@ -53,7 +52,6 @@ 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;
|
||||
import com.android.launcher3.graphics.DrawableFactory;
|
||||
import com.android.launcher3.shortcuts.DeepShortcutView;
|
||||
@@ -93,8 +91,8 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag
|
||||
private static final int CLOSING_TRANSITION_DURATION_MS = 350;
|
||||
|
||||
// Progress = 0: All apps is fully pulled up, Progress = 1: All apps is fully pulled down.
|
||||
private static final float ALL_APPS_PROGRESS_OFF_SCREEN = 1.3059858f;
|
||||
private static final float ALL_APPS_PROGRESS_OVERSHOOT = 0.99581414f;
|
||||
public static final float ALL_APPS_PROGRESS_OFF_SCREEN = 1.3059858f;
|
||||
public static final float ALL_APPS_PROGRESS_OVERSHOOT = 0.99581414f;
|
||||
|
||||
private final DragLayer mDragLayer;
|
||||
private final Launcher mLauncher;
|
||||
@@ -148,7 +146,14 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag
|
||||
|
||||
@Override
|
||||
public AnimatorSet getAnimator(RemoteAnimationTargetCompat[] targetCompats) {
|
||||
AnimatorSet anim = createLaunchAnimatorForView(v, targetCompats);
|
||||
Animator[] anims = composeRecentsLaunchAnimator(v, targetCompats);
|
||||
AnimatorSet anim = new AnimatorSet();
|
||||
if (anims != null) {
|
||||
anim.playTogether(anims);
|
||||
} else {
|
||||
anim.play(getLauncherAnimators(v, targetCompats));
|
||||
anim.play(getWindowAnimators(v, targetCompats));
|
||||
}
|
||||
mLauncher.getStateManager().setCurrentAnimation(anim);
|
||||
return anim;
|
||||
}
|
||||
@@ -167,19 +172,6 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag
|
||||
return getDefaultActivityLaunchOptions(launcher, v);
|
||||
}
|
||||
|
||||
private AnimatorSet createLaunchAnimatorForView(View v, RemoteAnimationTargetCompat[] targets) {
|
||||
Animator[] anims = composeRecentsLaunchAnimator(v, new AnimConfig(targets,
|
||||
RECENTS_LAUNCH_DURATION, Interpolators.TOUCH_RESPONSE_INTERPOLATOR));
|
||||
AnimatorSet anim = new AnimatorSet();
|
||||
if (anims != null) {
|
||||
anim.playTogether(anims);
|
||||
} else {
|
||||
anim.play(getLauncherAnimators(v, targets));
|
||||
anim.play(getWindowAnimators(v, targets));
|
||||
}
|
||||
return anim;
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to find a TaskView that corresponds with the component of the launched view.
|
||||
*
|
||||
@@ -238,32 +230,21 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag
|
||||
return taskView;
|
||||
}
|
||||
|
||||
public AnimatorSet composeUserControlledRecentsLaunchAnimator(TaskView v, AnimConfig config) {
|
||||
Animator[] anims = composeRecentsLaunchAnimator(v, config);
|
||||
AnimatorSet anim = new AnimatorSet();
|
||||
anim.playTogether(anims);
|
||||
return anim;
|
||||
}
|
||||
|
||||
/**
|
||||
* Composes the animations for a launch from the recents list if possible.
|
||||
*/
|
||||
private Animator[] composeRecentsLaunchAnimator(View v, AnimConfig config) {
|
||||
private Animator[] composeRecentsLaunchAnimator(View v,
|
||||
RemoteAnimationTargetCompat[] targets) {
|
||||
// Ensure recents is actually visible
|
||||
if (!mLauncher.getStateManager().getState().overviewUi) {
|
||||
return null;
|
||||
}
|
||||
|
||||
RecentsView recentsView = mLauncher.getOverviewPanel();
|
||||
boolean launcherClosing = launcherIsATargetWithMode(config.targets, MODE_CLOSING);
|
||||
if (config.userControlled) {
|
||||
// We don't pass any targets when creating a user-controlled animation. In this case,
|
||||
// assume launcher is closing.
|
||||
launcherClosing = true;
|
||||
}
|
||||
boolean launcherClosing = launcherIsATargetWithMode(targets, MODE_CLOSING);
|
||||
boolean skipLauncherChanges = !launcherClosing;
|
||||
|
||||
TaskView taskView = findTaskViewToLaunch(mLauncher, v, config.targets);
|
||||
TaskView taskView = findTaskViewToLaunch(mLauncher, v, targets);
|
||||
if (taskView == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -272,7 +253,10 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag
|
||||
Animator launcherAnim;
|
||||
final AnimatorListenerAdapter windowAnimEndListener;
|
||||
if (launcherClosing) {
|
||||
launcherAnim = getRecentsLauncherAnimator(recentsView, taskView, config);
|
||||
launcherAnim = recentsView.createAdjacentPageAnimForTaskLaunch(taskView);
|
||||
launcherAnim.setInterpolator(Interpolators.TOUCH_RESPONSE_INTERPOLATOR);
|
||||
launcherAnim.setDuration(RECENTS_LAUNCH_DURATION);
|
||||
|
||||
// Make sure recents gets fixed up by resetting task alphas and scales, etc.
|
||||
windowAnimEndListener = mReapplyStateListener;
|
||||
} else {
|
||||
@@ -289,150 +273,25 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag
|
||||
};
|
||||
}
|
||||
|
||||
Animator windowAnim = getRecentsWindowAnimator(taskView, skipLauncherChanges, config);
|
||||
if (!config.userControlled) {
|
||||
// Don't reset properties if the animation is user-controlled, as we will run the
|
||||
// "real" (not user controlled) animation from where they left off when they let go.
|
||||
windowAnim.addListener(windowAnimEndListener);
|
||||
}
|
||||
Animator windowAnim = getRecentsWindowAnimator(taskView, skipLauncherChanges, targets);
|
||||
windowAnim.addListener(windowAnimEndListener);
|
||||
return new Animator[] {launcherAnim, windowAnim};
|
||||
}
|
||||
|
||||
/**
|
||||
* Animate adjacent tasks off screen while scaling up, and translate hotseat off screen as well.
|
||||
*
|
||||
* If launching one of the adjacent tasks, parallax the center task and other adjacent task
|
||||
* to the right.
|
||||
*/
|
||||
private Animator getRecentsLauncherAnimator(RecentsView recentsView, TaskView v,
|
||||
AnimConfig config) {
|
||||
AnimatorSet launcherAnimator = new AnimatorSet();
|
||||
|
||||
int launchedTaskIndex = recentsView.indexOfChild(v);
|
||||
int centerTaskIndex = recentsView.getCurrentPage();
|
||||
boolean launchingCenterTask = launchedTaskIndex == centerTaskIndex;
|
||||
boolean isRtl = recentsView.isRtl();
|
||||
|
||||
RecentsAnimationInterpolator recentsInterpolator = getRecentsInterpolator(v);
|
||||
TaskWindowBounds endInterpolation = recentsInterpolator.interpolate(1);
|
||||
float toScale = endInterpolation.taskScale;
|
||||
float toTranslationY = endInterpolation.taskY;
|
||||
float displacementX = v.getWidth() * (toScale - v.getScaleX());
|
||||
if (launchingCenterTask) {
|
||||
|
||||
if (launchedTaskIndex - 1 >= 0) {
|
||||
TaskView adjacentPage1 = (TaskView) recentsView.getPageAt(launchedTaskIndex - 1);
|
||||
ObjectAnimator adjacentTask1ScaleAndTranslate =
|
||||
LauncherAnimUtils.ofPropertyValuesHolder(adjacentPage1,
|
||||
new PropertyListBuilder()
|
||||
.scale(adjacentPage1.getScaleX() * toScale)
|
||||
.translationY(toTranslationY)
|
||||
.translationX(isRtl ? displacementX : -displacementX)
|
||||
.build());
|
||||
adjacentTask1ScaleAndTranslate.setInterpolator(config.interpolator);
|
||||
adjacentTask1ScaleAndTranslate.setDuration(config.duration);
|
||||
launcherAnimator.play(adjacentTask1ScaleAndTranslate);
|
||||
}
|
||||
if (launchedTaskIndex + 1 < recentsView.getPageCount()) {
|
||||
TaskView adjacentTask2 = (TaskView) recentsView.getPageAt(launchedTaskIndex + 1);
|
||||
ObjectAnimator adjacentTask2ScaleAndTranslate =
|
||||
LauncherAnimUtils.ofPropertyValuesHolder(adjacentTask2,
|
||||
new PropertyListBuilder()
|
||||
.scale(adjacentTask2.getScaleX() * toScale)
|
||||
.translationY(toTranslationY)
|
||||
.translationX(isRtl ? -displacementX : displacementX)
|
||||
.build());
|
||||
adjacentTask2ScaleAndTranslate.setInterpolator(config.interpolator);
|
||||
adjacentTask2ScaleAndTranslate.setDuration(config.duration);
|
||||
launcherAnimator.play(adjacentTask2ScaleAndTranslate);
|
||||
}
|
||||
} else {
|
||||
// We are launching an adjacent task, so parallax the center and other adjacent task.
|
||||
TaskView centerTask = (TaskView) recentsView.getPageAt(centerTaskIndex);
|
||||
ObjectAnimator centerTaskParallaxOffscreen =
|
||||
LauncherAnimUtils.ofPropertyValuesHolder(centerTask,
|
||||
new PropertyListBuilder()
|
||||
.translationX(isRtl ? -displacementX : displacementX)
|
||||
.build());
|
||||
centerTaskParallaxOffscreen.setInterpolator(config.interpolator);
|
||||
centerTaskParallaxOffscreen.setDuration(config.duration);
|
||||
launcherAnimator.play(centerTaskParallaxOffscreen);
|
||||
int otherAdjacentTaskIndex = centerTaskIndex + (centerTaskIndex - launchedTaskIndex);
|
||||
if (otherAdjacentTaskIndex >= 0
|
||||
&& otherAdjacentTaskIndex < recentsView.getPageCount()) {
|
||||
TaskView otherAdjacentTask = (TaskView) recentsView.getPageAt(
|
||||
otherAdjacentTaskIndex);
|
||||
ObjectAnimator otherAdjacentTaskParallaxOffscreen =
|
||||
LauncherAnimUtils.ofPropertyValuesHolder(otherAdjacentTask,
|
||||
new PropertyListBuilder()
|
||||
.translationX(isRtl ? -displacementX : displacementX)
|
||||
.scale(1)
|
||||
.build());
|
||||
otherAdjacentTaskParallaxOffscreen.setInterpolator(config.interpolator);
|
||||
otherAdjacentTaskParallaxOffscreen.setDuration(config.duration);
|
||||
launcherAnimator.play(otherAdjacentTaskParallaxOffscreen);
|
||||
}
|
||||
}
|
||||
|
||||
float allAppsProgressOffscreen = ALL_APPS_PROGRESS_OFF_SCREEN;
|
||||
LauncherState state = mLauncher.getStateManager().getState();
|
||||
if ((state.getVisibleElements(mLauncher) & ALL_APPS_HEADER_EXTRA) != 0) {
|
||||
float maxShiftRange = mDeviceProfile.heightPx;
|
||||
float currShiftRange = mLauncher.getAllAppsController().getShiftRange();
|
||||
allAppsProgressOffscreen = 1f + (maxShiftRange - currShiftRange) / maxShiftRange;
|
||||
}
|
||||
Animator allAppsSlideOut = ObjectAnimator.ofFloat(mLauncher.getAllAppsController(),
|
||||
ALL_APPS_PROGRESS, allAppsProgressOffscreen);
|
||||
allAppsSlideOut.setInterpolator(config.interpolator);
|
||||
allAppsSlideOut.setDuration(config.duration);
|
||||
launcherAnimator.play(allAppsSlideOut);
|
||||
|
||||
Workspace workspace = mLauncher.getWorkspace();
|
||||
float[] workspaceScaleAndTranslation = NORMAL
|
||||
.getWorkspaceScaleAndTranslation(mLauncher);
|
||||
Animator recenterWorkspace = LauncherAnimUtils.ofPropertyValuesHolder(
|
||||
workspace, new PropertyListBuilder()
|
||||
.translationX(workspaceScaleAndTranslation[1])
|
||||
.translationY(workspaceScaleAndTranslation[2])
|
||||
.build());
|
||||
recenterWorkspace.setInterpolator(config.interpolator);
|
||||
recenterWorkspace.setDuration(config.duration);
|
||||
launcherAnimator.play(recenterWorkspace);
|
||||
CellLayout currentWorkspacePage = (CellLayout) workspace.getPageAt(
|
||||
workspace.getCurrentPage());
|
||||
|
||||
return launcherAnimator;
|
||||
}
|
||||
|
||||
private RecentsAnimationInterpolator getRecentsInterpolator(TaskView v) {
|
||||
Rect taskViewBounds = new Rect();
|
||||
mDragLayer.getDescendantRectRelativeToSelf(v, taskViewBounds);
|
||||
|
||||
// TODO: Use the actual target insets instead of the current thumbnail insets in case the
|
||||
// device state has changed
|
||||
return new RecentsAnimationInterpolator(
|
||||
new Rect(0, 0, mDeviceProfile.widthPx, mDeviceProfile.heightPx),
|
||||
v.getThumbnail().getInsets(),
|
||||
taskViewBounds,
|
||||
new Rect(0, v.getThumbnail().getTop(), 0, 0),
|
||||
v.getScaleX(),
|
||||
v.getTranslationX());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Animator that controls the window of the opening targets for the recents launch
|
||||
* animation.
|
||||
*/
|
||||
private ValueAnimator getRecentsWindowAnimator(TaskView v, boolean skipLauncherChanges,
|
||||
AnimConfig config) {
|
||||
final RecentsAnimationInterpolator recentsInterpolator = getRecentsInterpolator(v);
|
||||
RemoteAnimationTargetCompat[] targets) {
|
||||
final RecentsAnimationInterpolator recentsInterpolator = v.getRecentsInterpolator();
|
||||
|
||||
Rect crop = new Rect();
|
||||
Matrix matrix = new Matrix();
|
||||
|
||||
ValueAnimator appAnimator = ValueAnimator.ofFloat(0, 1);
|
||||
appAnimator.setDuration(config.duration);
|
||||
appAnimator.setInterpolator(config.interpolator);
|
||||
appAnimator.setDuration(RECENTS_LAUNCH_DURATION);
|
||||
appAnimator.setInterpolator(Interpolators.TOUCH_RESPONSE_INTERPOLATOR);
|
||||
appAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
||||
boolean isFirstFrame = true;
|
||||
|
||||
@@ -454,11 +313,9 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag
|
||||
v.setScaleY(tw.taskScale);
|
||||
v.setTranslationX(tw.taskX);
|
||||
v.setTranslationY(tw.taskY);
|
||||
if (!config.userControlled) {
|
||||
// Defer fading out the view until after the app window gets faded in
|
||||
v.setAlpha(getValue(1f, 0f, alphaDuration, alphaDuration,
|
||||
appAnimator.getDuration() * percent, Interpolators.LINEAR));
|
||||
}
|
||||
// Defer fading out the view until after the app window gets faded in
|
||||
v.setAlpha(getValue(1f, 0f, alphaDuration, alphaDuration,
|
||||
appAnimator.getDuration() * percent, Interpolators.LINEAR));
|
||||
}
|
||||
|
||||
matrix.setScale(tw.winScale, tw.winScale);
|
||||
@@ -470,7 +327,7 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag
|
||||
appAnimator.getDuration() * percent, Interpolators.LINEAR);
|
||||
|
||||
TransactionCompat t = new TransactionCompat();
|
||||
for (RemoteAnimationTargetCompat target : config.targets) {
|
||||
for (RemoteAnimationTargetCompat target : targets) {
|
||||
if (target.mode == RemoteAnimationTargetCompat.MODE_OPENING) {
|
||||
t.setAlpha(target.leash, alpha);
|
||||
|
||||
@@ -967,24 +824,4 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag
|
||||
newPercent = i.getInterpolation(newPercent);
|
||||
return end * newPercent + start * (1 - newPercent);
|
||||
}
|
||||
|
||||
public static class AnimConfig {
|
||||
public RemoteAnimationTargetCompat[] targets;
|
||||
public long duration;
|
||||
public Interpolator interpolator;
|
||||
|
||||
public boolean userControlled = false;
|
||||
|
||||
public AnimConfig(RemoteAnimationTargetCompat[] targets, long duration,
|
||||
Interpolator interpolator) {
|
||||
this.targets = targets;
|
||||
this.duration = duration;
|
||||
this.interpolator = interpolator;
|
||||
}
|
||||
|
||||
public AnimConfig(long duration, Interpolator interpolator) {
|
||||
this(new RemoteAnimationTargetCompat[0], duration, interpolator);
|
||||
userControlled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user