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

Commit bc68f5ad authored by George Mount's avatar George Mount
Browse files

Allow Path Animations to support overshooting.

Bug 17458698

Change-Id: I7a29fc8932a28121d7db8b3bf695d91a55ef059b
parent 04c9d29b
Loading
Loading
Loading
Loading
+23 −19
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@ package android.animation;

import android.graphics.Path;
import android.graphics.PointF;
import android.util.MathUtils;

import java.util.ArrayList;

@@ -64,11 +63,12 @@ class PathKeyframes implements Keyframes {

    @Override
    public Object getValue(float fraction) {
        fraction = MathUtils.constrain(fraction, 0, 1);

        int numPoints = mKeyframeData.length / 3;

        if (fraction == 0) {
        if (fraction < 0) {
            return interpolateInRange(fraction, 0, 1);
        } else if (fraction > 1) {
            return interpolateInRange(fraction, numPoints - 2, numPoints - 1);
        } else if (fraction == 0) {
            return pointForIndex(0);
        } else if (fraction == 1) {
            return pointForIndex(numPoints - 1);
@@ -91,8 +91,13 @@ class PathKeyframes implements Keyframes {
            }

            // now high is below the fraction and low is above the fraction
            int startBase = (high * NUM_COMPONENTS);
            int endBase = (low * NUM_COMPONENTS);
            return interpolateInRange(fraction, high, low);
        }
    }

    private PointF interpolateInRange(float fraction, int startIndex, int endIndex) {
        int startBase = (startIndex * NUM_COMPONENTS);
        int endBase = (endIndex * NUM_COMPONENTS);

        float startFraction = mKeyframeData[startBase + FRACTION_OFFSET];
        float endFraction = mKeyframeData[endBase + FRACTION_OFFSET];
@@ -110,7 +115,6 @@ class PathKeyframes implements Keyframes {
        mTempPointF.set(x, y);
        return mTempPointF;
    }
    }

    @Override
    public void invalidateCache() {