diff --git a/core/java/android/animation/Animator.java b/core/java/android/animation/Animator.java index 8142ee5806cad..a9d14df8bcf4d 100644 --- a/core/java/android/animation/Animator.java +++ b/core/java/android/animation/Animator.java @@ -23,7 +23,6 @@ import android.compat.annotation.UnsupportedAppUsage; import android.content.pm.ActivityInfo.Config; import android.content.res.ConstantState; import android.os.Build; -import android.util.LongArray; import java.util.ArrayList; @@ -560,36 +559,9 @@ public abstract class Animator implements Cloneable { } /** - * Internal use only. Changes the value of the animator as if currentPlayTime has passed since - * the start of the animation. Therefore, currentPlayTime includes the start delay, and any - * repetition. lastPlayTime is similar and is used to calculate how many repeats have been - * done between the two times. + * Internal use only. */ - void animateValuesInRange(long currentPlayTime, long lastPlayTime) {} - - /** - * Internal use only. This animates any animation that has ended since lastPlayTime. - * If an animation hasn't been finished, no change will be made. - */ - void animateSkipToEnds(long currentPlayTime, long lastPlayTime) {} - - /** - * Internal use only. Adds all start times (after delay) to and end times to times. - * The value must include offset. - */ - void getStartAndEndTimes(LongArray times, long offset) { - long startTime = offset + getStartDelay(); - if (times.indexOf(startTime) < 0) { - times.add(startTime); - } - long duration = getTotalDuration(); - if (duration != DURATION_INFINITE) { - long endTime = duration + offset; - if (times.indexOf(endTime) < 0) { - times.add(endTime); - } - } - } + void animateBasedOnPlayTime(long currentPlayTime, long lastPlayTime, boolean inReverse) {} /** *
An animation listener receives notifications from an animation.
diff --git a/core/java/android/animation/AnimatorSet.java b/core/java/android/animation/AnimatorSet.java
index 54aaafc6c30a1..bc8db029e06d6 100644
--- a/core/java/android/animation/AnimatorSet.java
+++ b/core/java/android/animation/AnimatorSet.java
@@ -23,11 +23,9 @@ import android.os.Looper;
import android.util.AndroidRuntimeException;
import android.util.ArrayMap;
import android.util.Log;
-import android.util.LongArray;
import android.view.animation.Animation;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
@@ -183,11 +181,6 @@ public final class AnimatorSet extends Animator implements AnimationHandler.Anim
*/
private long mPauseTime = -1;
- /**
- * The start and stop times of all descendant animators.
- */
- private long[] mChildStartAndStopTimes;
-
// This is to work around a bug in b/34736819. This needs to be removed once app team
// fixes their side.
private AnimatorListenerAdapter mAnimationEndListener = new AnimatorListenerAdapter() {
@@ -786,25 +779,26 @@ public final class AnimatorSet extends Animator implements AnimationHandler.Anim
@Override
void skipToEndValue(boolean inReverse) {
+ if (!isInitialized()) {
+ throw new UnsupportedOperationException("Children must be initialized.");
+ }
+
// This makes sure the animation events are sorted an up to date.
initAnimation();
- initChildren();
// Calling skip to the end in the sequence that they would be called in a forward/reverse
// run, such that the sequential animations modifying the same property would have
// the right value in the end.
if (inReverse) {
for (int i = mEvents.size() - 1; i >= 0; i--) {
- AnimationEvent event = mEvents.get(i);
- if (event.mEvent == AnimationEvent.ANIMATION_DELAY_ENDED) {
- event.mNode.mAnimation.skipToEndValue(true);
+ if (mEvents.get(i).mEvent == AnimationEvent.ANIMATION_DELAY_ENDED) {
+ mEvents.get(i).mNode.mAnimation.skipToEndValue(true);
}
}
} else {
for (int i = 0; i < mEvents.size(); i++) {
- AnimationEvent event = mEvents.get(i);
- if (event.mEvent == AnimationEvent.ANIMATION_END) {
- event.mNode.mAnimation.skipToEndValue(false);
+ if (mEvents.get(i).mEvent == AnimationEvent.ANIMATION_END) {
+ mEvents.get(i).mNode.mAnimation.skipToEndValue(false);
}
}
}
@@ -820,181 +814,72 @@ public final class AnimatorSet extends Animator implements AnimationHandler.Anim
* {@link android.view.animation.Animation.AnimationListener#onAnimationRepeat(Animation)},
* as needed, based on the last play time and current play time.
*/
- private void animateBasedOnPlayTime(
- long currentPlayTime,
- long lastPlayTime,
- boolean inReverse
- ) {
- if (currentPlayTime < 0 || lastPlayTime < -1) {
+ @Override
+ void animateBasedOnPlayTime(long currentPlayTime, long lastPlayTime, boolean inReverse) {
+ if (currentPlayTime < 0 || lastPlayTime < 0) {
throw new UnsupportedOperationException("Error: Play time should never be negative.");
}
// TODO: take into account repeat counts and repeat callback when repeat is implemented.
+ // Clamp currentPlayTime and lastPlayTime
+ // TODO: Make this more efficient
+
+ // Convert the play times to the forward direction.
if (inReverse) {
- long duration = getTotalDuration();
- if (duration == DURATION_INFINITE) {
- throw new UnsupportedOperationException(
- "Cannot reverse AnimatorSet with infinite duration"
- );
+ if (getTotalDuration() == DURATION_INFINITE) {
+ throw new UnsupportedOperationException("Cannot reverse AnimatorSet with infinite"
+ + " duration");
}
- // Convert the play times to the forward direction.
+ long duration = getTotalDuration() - mStartDelay;
currentPlayTime = Math.min(currentPlayTime, duration);
currentPlayTime = duration - currentPlayTime;
lastPlayTime = duration - lastPlayTime;
+ inReverse = false;
}
- long[] startEndTimes = ensureChildStartAndEndTimes();
- int index = findNextIndex(lastPlayTime, startEndTimes);
- int endIndex = findNextIndex(currentPlayTime, startEndTimes);
-
- // Change values at the start/end times so that values are set in the right order.
- // We don't want an animator that would finish before another to override the value
- // set by another animator that finishes earlier.
- if (currentPlayTime >= lastPlayTime) {
- while (index < endIndex) {
- long playTime = startEndTimes[index];
- if (lastPlayTime != playTime) {
- animateSkipToEnds(playTime, lastPlayTime);
- animateValuesInRange(playTime, lastPlayTime);
- lastPlayTime = playTime;
- }
- index++;
- }
- } else {
- while (index > endIndex) {
- index--;
- long playTime = startEndTimes[index];
- if (lastPlayTime != playTime) {
- animateSkipToEnds(playTime, lastPlayTime);
- animateValuesInRange(playTime, lastPlayTime);
- lastPlayTime = playTime;
- }
- }
- }
- if (currentPlayTime != lastPlayTime) {
- animateSkipToEnds(currentPlayTime, lastPlayTime);
- animateValuesInRange(currentPlayTime, lastPlayTime);
- }
- }
-
- /**
- * Looks through startEndTimes for playTime. If it is in startEndTimes, the index after
- * is returned. Otherwise, it returns the index at which it would be placed if it were
- * to be inserted.
- */
- private int findNextIndex(long playTime, long[] startEndTimes) {
- int index = Arrays.binarySearch(startEndTimes, playTime);
- if (index < 0) {
- index = -index - 1;
- } else {
- index++;
- }
- return index;
- }
-
- @Override
- void animateSkipToEnds(long currentPlayTime, long lastPlayTime) {
- initAnimation();
-
- if (lastPlayTime > currentPlayTime) {
- for (int i = mEvents.size() - 1; i >= 0; i--) {
- AnimationEvent event = mEvents.get(i);
- Node node = event.mNode;
- if (event.mEvent == AnimationEvent.ANIMATION_END
- && node.mStartTime != DURATION_INFINITE
- ) {
- Animator animator = node.mAnimation;
- long start = node.mStartTime + animator.getStartDelay();
- long end = node.mTotalDuration == DURATION_INFINITE
- ? Long.MAX_VALUE : node.mEndTime;
- if (currentPlayTime <= start && start < lastPlayTime) {
- animator.animateSkipToEnds(
- start - node.mStartTime,
- lastPlayTime - node.mStartTime
- );
- } else if (start <= currentPlayTime && currentPlayTime <= end) {
- animator.animateSkipToEnds(
- currentPlayTime - node.mStartTime,
- lastPlayTime - node.mStartTime
- );
- }
- }
- }
- } else {
- int eventsSize = mEvents.size();
- for (int i = 0; i < eventsSize; i++) {
- AnimationEvent event = mEvents.get(i);
- Node node = event.mNode;
- if (event.mEvent == AnimationEvent.ANIMATION_DELAY_ENDED
- && node.mStartTime != DURATION_INFINITE
- ) {
- Animator animator = node.mAnimation;
- long start = node.mStartTime + animator.getStartDelay();
- long end = node.mTotalDuration == DURATION_INFINITE
- ? Long.MAX_VALUE : node.mEndTime;
- if (lastPlayTime < end && end <= currentPlayTime) {
- animator.animateSkipToEnds(
- end - node.mStartTime,
- lastPlayTime - node.mStartTime
- );
- } else if (start <= currentPlayTime && currentPlayTime <= end) {
- animator.animateSkipToEnds(
- currentPlayTime - node.mStartTime,
- lastPlayTime - node.mStartTime
- );
- }
- }
- }
- }
- }
-
- @Override
- void animateValuesInRange(long currentPlayTime, long lastPlayTime) {
- initAnimation();
-
- int eventsSize = mEvents.size();
- for (int i = 0; i < eventsSize; i++) {
+ ArrayList