Merge "Prevent divided by zero if animation is disable" into rvc-dev

This commit is contained in:
TreeHugger Robot
2020-04-27 06:40:58 +00:00
committed by Android (Google) Code Review
4 changed files with 15 additions and 5 deletions

View File

@@ -382,8 +382,8 @@ class Dimmer {
@Override
public void apply(SurfaceControl.Transaction t, SurfaceControl sc, long currentPlayTime) {
float alpha = ((float) currentPlayTime / getDuration()) * (mToAlpha - mFromAlpha)
+ mFromAlpha;
final float fraction = getFraction(currentPlayTime);
final float alpha = fraction * (mToAlpha - mFromAlpha) + mFromAlpha;
t.setAlpha(sc, alpha);
}

View File

@@ -130,6 +130,16 @@ class LocalAnimationAdapter implements AnimationAdapter {
*/
default boolean needsEarlyWakeup() { return false; }
/**
* @return The fraction of the animation, returns 1 if duration is 0.
*
* @param currentPlayTime The current play time.
*/
default float getFraction(float currentPlayTime) {
final float duration = getDuration();
return duration > 0 ? currentPlayTime / duration : 1.0f;
}
void dump(PrintWriter pw, String prefix);
default void dumpDebug(ProtoOutputStream proto, long fieldId) {

View File

@@ -646,8 +646,8 @@ class ScreenRotationAnimation {
@Override
public void apply(SurfaceControl.Transaction t, SurfaceControl leash,
long currentPlayTime) {
float fraction = (float)currentPlayTime / (float)getDuration();
int color = (Integer) va.evaluate(fraction, startColor, endColor);
final float fraction = getFraction(currentPlayTime);
final int color = (Integer) va.evaluate(fraction, startColor, endColor);
Color middleColor = Color.valueOf(color);
rgbTmpFloat[0] = middleColor.red();
rgbTmpFloat[1] = middleColor.green();

View File

@@ -5606,7 +5606,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
@Override
public void apply(Transaction t, SurfaceControl leash, long currentPlayTime) {
final float fraction = (float) currentPlayTime / getDuration();
final float fraction = getFraction(currentPlayTime);
final float v = mInterpolator.getInterpolation(fraction);
t.setPosition(leash, mFrom.x + (mTo.x - mFrom.x) * v,
mFrom.y + (mTo.y - mFrom.y) * v);