Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8619f48f authored by Yigit Boyar's avatar Yigit Boyar
Browse files

Change Animators to reset values when restarted if their target changes

Bug: 15710503
Change-Id: Ib39bf0e13199978ffb389111c225beb30312c965
parent 95a18a8f
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -57,6 +57,11 @@ class FloatKeyframeSet extends KeyframeSet {
        return newSet;
    }

    @Override
    void invalidateCache() {
        firstTime = true;
    }

    public float getFloatValue(float fraction) {
        if (mNumKeyframes == 2) {
            if (firstTime) {
+5 −0
Original line number Diff line number Diff line
@@ -57,6 +57,11 @@ class IntKeyframeSet extends KeyframeSet {
        return newSet;
    }

    @Override
    void invalidateCache() {
        firstTime = true;
    }

    public int getIntValue(float fraction) {
        if (mNumKeyframes == 2) {
            if (firstTime) {
+33 −7
Original line number Diff line number Diff line
@@ -34,6 +34,20 @@ package android.animation;
 * types have lower runtime overhead than other types.</p>
 */
public abstract class Keyframe implements Cloneable {
    /**
     * Flag to indicate whether this keyframe has a valid value. This flag is used when an
     * animation first starts, to populate placeholder keyframes with real values derived
     * from the target object.
     */
    boolean mHasValue;

    /**
     * Flag to indicate whether the value in the keyframe was read from the target object or not.
     * If so, its value will be recalculated if target changes.
     */
    boolean mValueWasSetOnStart;


    /**
     * The time at which mValue will hold true.
     */
@@ -51,12 +65,7 @@ public abstract class Keyframe implements Cloneable {
     */
    private TimeInterpolator mInterpolator = null;

    /**
     * Flag to indicate whether this keyframe has a valid value. This flag is used when an
     * animation first starts, to populate placeholder keyframes with real values derived
     * from the target object.
     */
    boolean mHasValue = false;


    /**
     * Constructs a Keyframe object with the given time and value. The time defines the
@@ -165,6 +174,20 @@ public abstract class Keyframe implements Cloneable {
        return mHasValue;
    }

    /**
     * If the Keyframe's value was acquired from the target object, this flag should be set so that,
     * if target changes, value will be reset.
     *
     * @return boolean Whether this Keyframe's value was retieved from the target object or not.
     */
    boolean valueWasSetOnStart() {
        return mValueWasSetOnStart;
    }

    void setValueWasSetOnStart(boolean valueWasSetOnStart) {
        mValueWasSetOnStart = valueWasSetOnStart;
    }

    /**
     * Gets the value for this Keyframe.
     *
@@ -261,7 +284,8 @@ public abstract class Keyframe implements Cloneable {

        @Override
        public ObjectKeyframe clone() {
            ObjectKeyframe kfClone = new ObjectKeyframe(getFraction(), mHasValue ? mValue : null);
            ObjectKeyframe kfClone = new ObjectKeyframe(getFraction(), hasValue() ? mValue : null);
            kfClone.mValueWasSetOnStart = mValueWasSetOnStart;
            kfClone.setInterpolator(getInterpolator());
            return kfClone;
        }
@@ -310,6 +334,7 @@ public abstract class Keyframe implements Cloneable {
                    new IntKeyframe(getFraction(), mValue) :
                    new IntKeyframe(getFraction());
            kfClone.setInterpolator(getInterpolator());
            kfClone.mValueWasSetOnStart = mValueWasSetOnStart;
            return kfClone;
        }
    }
@@ -356,6 +381,7 @@ public abstract class Keyframe implements Cloneable {
                    new FloatKeyframe(getFraction(), mValue) :
                    new FloatKeyframe(getFraction());
            kfClone.setInterpolator(getInterpolator());
            kfClone.mValueWasSetOnStart = mValueWasSetOnStart;
            return kfClone;
        }
    }
+7 −0
Original line number Diff line number Diff line
@@ -48,6 +48,13 @@ class KeyframeSet {
        mInterpolator = mLastKeyframe.getInterpolator();
    }

    /**
     * If subclass has variables that it calculates based on the Keyframes, it should reset them
     * when this method is called because Keyframe contents might have changed.
     */
    void invalidateCache() {
    }

    public static KeyframeSet ofInt(int... values) {
        int numKeyframes = values.length;
        IntKeyframe keyframes[] = new IntKeyframe[Math.max(numKeyframes,2)];
+1 −4
Original line number Diff line number Diff line
@@ -883,10 +883,7 @@ public final class ObjectAnimator extends ValueAnimator {
        final Object oldTarget = getTarget();
        if (oldTarget != target) {
            mTarget = target == null ? null : new WeakReference<Object>(target);
            if (oldTarget != null && target != null && oldTarget.getClass() == target.getClass()) {
                return;
            }
            // New target type should cause re-initialization prior to starting
            // New target should cause re-initialization prior to starting
            mInitialized = false;
        }
    }
Loading