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

Commit 84c949f3 authored by Chet Haase's avatar Chet Haase
Browse files

Make behavior of ABSOLUTE pivot values more intuitive

Currently, you must call initialize() on RotateAnimation or
ScaleAnimation prior to calling start(). The reason is that the
actual pivot point used in calculating the transform is not set
until that method is called. This makes sense in the typical case
where the animation is running on a View and is using values relative
to the size of the View or of its parent. But if the caller sets the
values to be ABSOLUTE types instead, the sizes of the view and the parent
are irrelevant and the call to initialize() should not be needed (and
is not intuitive).

This fix automatically sets the internal pivot values in the case where
the value types are ABSOLUTE.

Change-Id: I74a0e462486efae08aa76e72c0d19d82f2a2677e
parent 01583ef7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -323,7 +323,7 @@ public abstract class Animation implements Cloneable {
    /**
     * Initialize this animation with the dimensions of the object being
     * animated as well as the objects parents. (This is to support animation
     * sizes being specifed relative to these dimensions.)
     * sizes being specified relative to these dimensions.)
     *
     * <p>Objects that interpret Animations should call this method when
     * the sizes of the object being animated and its parent are known, and
+17 −0
Original line number Diff line number Diff line
@@ -66,6 +66,8 @@ public class RotateAnimation extends Animation {
        mPivotYValue = d.value;

        a.recycle();

        initializePivotPoint();
    }

    /**
@@ -107,6 +109,7 @@ public class RotateAnimation extends Animation {
        mPivotYType = ABSOLUTE;
        mPivotXValue = pivotX;
        mPivotYValue = pivotY;
        initializePivotPoint();
    }

    /**
@@ -143,6 +146,20 @@ public class RotateAnimation extends Animation {
        mPivotXType = pivotXType;
        mPivotYValue = pivotYValue;
        mPivotYType = pivotYType;
        initializePivotPoint();
    }

    /**
     * Called at the end of constructor methods to initialize, if possible, values for
     * the pivot point. This is only possible for ABSOLUTE pivot values.
     */
    private void initializePivotPoint() {
        if (mPivotXType == ABSOLUTE) {
            mPivotX = mPivotXValue;
        }
        if (mPivotYType == ABSOLUTE) {
            mPivotY = mPivotYValue;
        }
    }

    @Override
+17 −0
Original line number Diff line number Diff line
@@ -128,6 +128,8 @@ public class ScaleAnimation extends Animation {
        mPivotYValue = d.value;

        a.recycle();

        initializePivotPoint();
    }

    /**
@@ -178,6 +180,7 @@ public class ScaleAnimation extends Animation {
        mPivotYType = ABSOLUTE;
        mPivotXValue = pivotX;
        mPivotYValue = pivotY;
        initializePivotPoint();
    }

    /**
@@ -218,6 +221,20 @@ public class ScaleAnimation extends Animation {
        mPivotXType = pivotXType;
        mPivotYValue = pivotYValue;
        mPivotYType = pivotYType;
        initializePivotPoint();
    }

    /**
     * Called at the end of constructor methods to initialize, if possible, values for
     * the pivot point. This is only possible for ABSOLUTE pivot values.
     */
    private void initializePivotPoint() {
        if (mPivotXType == ABSOLUTE) {
            mPivotX = mPivotXValue;
        }
        if (mPivotYType == ABSOLUTE) {
            mPivotY = mPivotYValue;
        }
    }

    @Override