Merge "Fixing animation jittering during swipe-up" into ub-launcher3-rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
f0f3fb2cbd
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.launcher3.anim;
|
package com.android.launcher3.anim;
|
||||||
|
|
||||||
|
import static com.android.launcher3.Utilities.boundToRange;
|
||||||
import static com.android.launcher3.anim.Interpolators.LINEAR;
|
import static com.android.launcher3.anim.Interpolators.LINEAR;
|
||||||
import static com.android.launcher3.anim.Interpolators.clampToProgress;
|
import static com.android.launcher3.anim.Interpolators.clampToProgress;
|
||||||
import static com.android.launcher3.anim.Interpolators.scrollInterpolatorForVelocity;
|
import static com.android.launcher3.anim.Interpolators.scrollInterpolatorForVelocity;
|
||||||
@@ -30,8 +31,6 @@ import android.content.Context;
|
|||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.android.launcher3.Utilities;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -54,11 +53,8 @@ public class AnimatorPlaybackController implements ValueAnimator.AnimatorUpdateL
|
|||||||
* to float (animation-fraction * total duration) to int conversion.
|
* to float (animation-fraction * total duration) to int conversion.
|
||||||
*/
|
*/
|
||||||
public static AnimatorPlaybackController wrap(AnimatorSet anim, long duration) {
|
public static AnimatorPlaybackController wrap(AnimatorSet anim, long duration) {
|
||||||
/**
|
|
||||||
* TODO: use {@link AnimatorSet#setCurrentPlayTime(long)} once b/68382377 is fixed.
|
|
||||||
*/
|
|
||||||
ArrayList<Holder> childAnims = new ArrayList<>();
|
ArrayList<Holder> childAnims = new ArrayList<>();
|
||||||
addAnimationHoldersRecur(anim, SpringProperty.DEFAULT, childAnims);
|
addAnimationHoldersRecur(anim, duration, SpringProperty.DEFAULT, childAnims);
|
||||||
|
|
||||||
return new AnimatorPlaybackController(anim, duration, childAnims);
|
return new AnimatorPlaybackController(anim, duration, childAnims);
|
||||||
}
|
}
|
||||||
@@ -152,7 +148,7 @@ public class AnimatorPlaybackController implements ValueAnimator.AnimatorUpdateL
|
|||||||
float scaleInverse = 1 / Math.abs(scale);
|
float scaleInverse = 1 / Math.abs(scale);
|
||||||
float scaledVelocity = velocity * scaleInverse;
|
float scaledVelocity = velocity * scaleInverse;
|
||||||
|
|
||||||
float nextFrameProgress = Utilities.boundToRange(getProgressFraction()
|
float nextFrameProgress = boundToRange(getProgressFraction()
|
||||||
+ scaledVelocity * getSingleFrameMs(context), 0f, 1f);
|
+ scaledVelocity * getSingleFrameMs(context), 0f, 1f);
|
||||||
|
|
||||||
// Update setters for spring
|
// Update setters for spring
|
||||||
@@ -176,8 +172,8 @@ public class AnimatorPlaybackController implements ValueAnimator.AnimatorUpdateL
|
|||||||
springDuration = Math.max(expectedDurationL, springDuration);
|
springDuration = Math.max(expectedDurationL, springDuration);
|
||||||
|
|
||||||
float expectedDuration = expectedDurationL;
|
float expectedDuration = expectedDurationL;
|
||||||
h.setter = (a, l) -> a.setCurrentFraction(
|
h.mapper = (progress, globalEndProgress) ->
|
||||||
mAnimationPlayer.getCurrentPlayTime() / expectedDuration);
|
mAnimationPlayer.getCurrentPlayTime() / expectedDuration;
|
||||||
h.anim.setInterpolator(s::getInterpolatedValue);
|
h.anim.setInterpolator(s::getInterpolatedValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -237,9 +233,9 @@ public class AnimatorPlaybackController implements ValueAnimator.AnimatorUpdateL
|
|||||||
if (mTargetCancelled) {
|
if (mTargetCancelled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
long playPos = clampDuration(fraction);
|
float progress = boundToRange(fraction, 0, 1);
|
||||||
for (Holder holder : mChildAnimations) {
|
for (Holder holder : mChildAnimations) {
|
||||||
holder.setter.set(holder.anim, playPos);
|
holder.setProgress(progress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -361,14 +357,14 @@ public class AnimatorPlaybackController implements ValueAnimator.AnimatorUpdateL
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for setting position of value animator
|
* Interface for mapping progress to animation progress
|
||||||
*/
|
*/
|
||||||
private interface PositionSetter {
|
private interface ProgressMapper {
|
||||||
|
|
||||||
PositionSetter DEFAULT = (anim, playPos) ->
|
ProgressMapper DEFAULT = (progress, globalEndProgress) ->
|
||||||
anim.setCurrentPlayTime(Math.min(playPos, anim.getDuration()));
|
progress > globalEndProgress ? 1 : (progress / globalEndProgress);
|
||||||
|
|
||||||
void set(ValueAnimator anim, long position);
|
float getProgress(float progress, float globalProgress);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -382,27 +378,34 @@ public class AnimatorPlaybackController implements ValueAnimator.AnimatorUpdateL
|
|||||||
|
|
||||||
public final TimeInterpolator interpolator;
|
public final TimeInterpolator interpolator;
|
||||||
|
|
||||||
public PositionSetter setter;
|
public final float globalEndProgress;
|
||||||
|
|
||||||
Holder(Animator anim, SpringProperty springProperty) {
|
public ProgressMapper mapper;
|
||||||
|
|
||||||
|
Holder(Animator anim, float globalDuration, SpringProperty springProperty) {
|
||||||
this.anim = (ValueAnimator) anim;
|
this.anim = (ValueAnimator) anim;
|
||||||
this.springProperty = springProperty;
|
this.springProperty = springProperty;
|
||||||
this.interpolator = this.anim.getInterpolator();
|
this.interpolator = this.anim.getInterpolator();
|
||||||
this.setter = PositionSetter.DEFAULT;
|
this.globalEndProgress = anim.getDuration() / globalDuration;
|
||||||
|
this.mapper = ProgressMapper.DEFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProgress(float progress) {
|
||||||
|
anim.setCurrentFraction(mapper.getProgress(progress, globalEndProgress));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
anim.setInterpolator(interpolator);
|
anim.setInterpolator(interpolator);
|
||||||
setter = PositionSetter.DEFAULT;
|
mapper = ProgressMapper.DEFAULT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void addAnimationHoldersRecur(
|
static void addAnimationHoldersRecur(Animator anim, long globalDuration,
|
||||||
Animator anim, SpringProperty springProperty, ArrayList<Holder> out) {
|
SpringProperty springProperty, ArrayList<Holder> out) {
|
||||||
long forceDuration = anim.getDuration();
|
long forceDuration = anim.getDuration();
|
||||||
TimeInterpolator forceInterpolator = anim.getInterpolator();
|
TimeInterpolator forceInterpolator = anim.getInterpolator();
|
||||||
if (anim instanceof ValueAnimator) {
|
if (anim instanceof ValueAnimator) {
|
||||||
out.add(new Holder(anim, springProperty));
|
out.add(new Holder(anim, globalDuration, springProperty));
|
||||||
} else if (anim instanceof AnimatorSet) {
|
} else if (anim instanceof AnimatorSet) {
|
||||||
for (Animator child : ((AnimatorSet) anim).getChildAnimations()) {
|
for (Animator child : ((AnimatorSet) anim).getChildAnimations()) {
|
||||||
if (forceDuration > 0) {
|
if (forceDuration > 0) {
|
||||||
@@ -411,7 +414,7 @@ public class AnimatorPlaybackController implements ValueAnimator.AnimatorUpdateL
|
|||||||
if (forceInterpolator != null) {
|
if (forceInterpolator != null) {
|
||||||
child.setInterpolator(forceInterpolator);
|
child.setInterpolator(forceInterpolator);
|
||||||
}
|
}
|
||||||
addAnimationHoldersRecur(child, springProperty, out);
|
addAnimationHoldersRecur(child, globalDuration, springProperty, out);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("Unknown animation type " + anim);
|
throw new RuntimeException("Unknown animation type " + anim);
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ public class PendingAnimation implements PropertySetter {
|
|||||||
|
|
||||||
public void add(Animator a, SpringProperty springProperty) {
|
public void add(Animator a, SpringProperty springProperty) {
|
||||||
mAnim.play(a);
|
mAnim.play(a);
|
||||||
addAnimationHoldersRecur(a, springProperty, mAnimHolders);
|
addAnimationHoldersRecur(a, mDuration, springProperty, mAnimHolders);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void finish(boolean isSuccess, int logAction) {
|
public void finish(boolean isSuccess, int logAction) {
|
||||||
@@ -150,7 +150,7 @@ public class PendingAnimation implements PropertySetter {
|
|||||||
}
|
}
|
||||||
if (mAnimHolders.isEmpty()) {
|
if (mAnimHolders.isEmpty()) {
|
||||||
// Add a dummy animation to that the duration is respected
|
// Add a dummy animation to that the duration is respected
|
||||||
add(ValueAnimator.ofFloat(0, 1));
|
add(ValueAnimator.ofFloat(0, 1).setDuration(mDuration));
|
||||||
}
|
}
|
||||||
return mAnim;
|
return mAnim;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user