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

Commit f54a8d7c authored by Chet Haase's avatar Chet Haase
Browse files

Adding xml declarations for new animation framework

Change-Id: Ic789e47790cf24d1c4b3bcbe9048b992ab93517b
parent 2af53220
Loading
Loading
Loading
Loading
+55 −0
Original line number Diff line number Diff line
@@ -7181,6 +7181,17 @@
 visibility="public"
>
</field>
<field name="ordering"
 type="int"
 transient="false"
 volatile="false"
 value="16843556"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="orderingFromXml"
 type="int"
 transient="false"
@@ -7742,6 +7753,17 @@
 visibility="public"
>
</field>
<field name="propertyName"
 type="int"
 transient="false"
 volatile="false"
 value="16843555"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="protectionLevel"
 type="int"
 transient="false"
@@ -10195,6 +10217,39 @@
 visibility="public"
>
</field>
<field name="valueFrom"
 type="int"
 transient="false"
 volatile="false"
 value="16843552"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="valueTo"
 type="int"
 transient="false"
 volatile="false"
 value="16843553"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="valueType"
 type="int"
 transient="false"
 volatile="false"
 value="16843554"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="variablePadding"
 type="int"
 transient="false"
+73 −0
Original line number Diff line number Diff line
@@ -16,8 +16,11 @@

package android.animation;

import android.content.Context;
import android.content.res.TypedArray;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
@@ -63,6 +66,15 @@ public class Animator extends Animatable {
    private static final int CANCELED   = 2; // cancel() called - need to end it
    private static final int ENDED      = 3; // end() called - need to end it

    /**
     * Enum values used in XML attributes to indicate the value for mValueType
     */
    private static final int VALUE_TYPE_FLOAT       = 0;
    private static final int VALUE_TYPE_INT         = 1;
    private static final int VALUE_TYPE_DOUBLE      = 2;
    private static final int VALUE_TYPE_COLOR       = 3;
    private static final int VALUE_TYPE_CUSTOM      = 4;

    /**
     * Internal variables
     */
@@ -219,6 +231,67 @@ public class Animator extends Animatable {
     */
    public static final int INFINITE = -1;

    /**
     * Creates a new animation whose parameters come from the specified context and
     * attributes set.
     *
     * @param context the application environment
     * @param attrs the set of attributes holding the animation parameters
     */
    public Animator(Context context, AttributeSet attrs) {
        TypedArray a =
                context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.Animator);

        mDuration = (long) a.getInt(com.android.internal.R.styleable.Animator_duration, 0);

        mStartDelay = (long) a.getInt(com.android.internal.R.styleable.Animator_startOffset, 0);

        final int resID =
                a.getResourceId(com.android.internal.R.styleable.Animator_interpolator, 0);
        if (resID > 0) {
            setInterpolator(AnimationUtils.loadInterpolator(context, resID));
        }
        int valueType = a.getInt(com.android.internal.R.styleable.Animator_valueType,
                VALUE_TYPE_FLOAT);

        switch (valueType) {
            case VALUE_TYPE_FLOAT:
                mValueFrom = a.getFloat(com.android.internal.R.styleable.Animator_valueFrom, 0f);
                mValueTo = a.getFloat(com.android.internal.R.styleable.Animator_valueTo, 0f);
                mValueType = float.class;
                break;
            case VALUE_TYPE_INT:
                mValueFrom = a.getInt(com.android.internal.R.styleable.Animator_valueFrom, 0);
                mValueTo = a.getInt(com.android.internal.R.styleable.Animator_valueTo, 0);
                mValueType = int.class;
                break;
            case VALUE_TYPE_DOUBLE:
                mValueFrom = (double)
                        a.getFloat(com.android.internal.R.styleable.Animator_valueFrom, 0f);
                mValueTo = (double)
                        a.getFloat(com.android.internal.R.styleable.Animator_valueTo, 0f);
                mValueType = double.class;
                break;
            case VALUE_TYPE_COLOR:
                mValueFrom = a.getInt(com.android.internal.R.styleable.Animator_valueFrom, 0);
                mValueTo = a.getInt(com.android.internal.R.styleable.Animator_valueTo, 0);
                mEvaluator = new RGBEvaluator();
                mValueType = int.class;
                break;
            case VALUE_TYPE_CUSTOM:
                // TODO: How to get an 'Object' value?
                mValueFrom = a.getFloat(com.android.internal.R.styleable.Animator_valueFrom, 0f);
                mValueTo = a.getFloat(com.android.internal.R.styleable.Animator_valueTo, 0f);
                mValueType = Object.class;
                break;
        }

        mRepeatCount = a.getInt(com.android.internal.R.styleable.Animator_repeatCount, mRepeatCount);
        mRepeatMode = a.getInt(com.android.internal.R.styleable.Animator_repeatMode, RESTART);

        a.recycle();
    }

    private Animator(long duration, Object valueFrom, Object valueTo, Class valueType) {
        mDuration = duration;
        mValueFrom = valueFrom;
+30 −0
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package android.animation;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.Log;

import java.lang.reflect.InvocationTargetException;
@@ -151,6 +154,24 @@ public final class PropertyAnimator extends Animator {
        return mGetter;
    }

    /**
     * Creates a new animation whose parameters come from the specified context and
     * attributes set.
     *
     * @param context the application environment
     * @param attrs the set of attributes holding the animation parameters
     */
    public PropertyAnimator(Context context, AttributeSet attrs) {
        super(context, attrs);

        TypedArray a = context.obtainStyledAttributes(attrs,
                com.android.internal.R.styleable.PropertyAnimator);

        mPropertyName = a.getString(com.android.internal.R.styleable.PropertyAnimator_propertyName);


        a.recycle();
    }
    /**
     * Determine the setter or getter function using the JavaBeans convention of setFoo or
     * getFoo for a property named 'foo'. This function figures out what the name of the
@@ -490,6 +511,15 @@ public final class PropertyAnimator extends Animator {
        return mTarget;
    }

    /**
     * Sets the target object whose property will be animated by this animation
     *
     * @param target The object being animated
     */
    public void setTarget(Object target) {
        mTarget = target;
    }

    /**
     * This method is called with the elapsed fraction of the animation during every
     * animation frame. This function turns the elapsed fraction into an interpolated fraction
+21 −0
Original line number Diff line number Diff line
@@ -16,6 +16,11 @@

package android.animation;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.animation.AnimationUtils;

import java.util.ArrayList;
import java.util.HashMap;

@@ -118,6 +123,22 @@ public final class Sequencer extends Animatable {
        }
    }

    /**
     * Returns the current list of child Animatable objects controlled by this
     * Sequencer. This is a copy of the internal list; modifications to the returned list
     * will not affect the Sequencer, although changes to the underlying Animatable objects
     * will affect those objects being managed by the Sequencer.
     *
     * @return ArrayList<Animatable> The list of child animations of this Sequencer.
     */
    public ArrayList<Animatable> getChildAnimations() {
        ArrayList<Animatable> childList = new ArrayList<Animatable>();
        for (Node node : mNodes) {
            childList.add(node.animation);
        }
        return childList;
    }

    /**
     * This method creates a <code>Builder</code> object, which is used to
     * set up playing constraints. This initial <code>play()</code> method
+118 −6
Original line number Diff line number Diff line
@@ -16,6 +16,12 @@

package android.view.animation;

import android.animation.Animatable;
import android.animation.Animator;
import android.animation.PropertyAnimator;
import android.animation.Sequencer;
import android.content.res.TypedArray;
import android.util.TypedValue;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

@@ -27,12 +33,21 @@ import android.util.Xml;
import android.os.SystemClock;

import java.io.IOException;
import java.util.ArrayList;

/**
 * Defines common utilities for working with animations.
 *
 */
public class AnimationUtils {

    /**
     * These flags are used when parsing Sequencer objects
     */
    private static final int TOGETHER = 0;
    private static final int SEQUENTIALLY = 1;


    /**
     * Returns the current animation time in milliseconds. This time should be used when invoking
     * {@link Animation#setStartTime(long)}. Refer to {@link android.os.SystemClock} for more
@@ -77,6 +92,43 @@ public class AnimationUtils {
        }
    }

    /**
     * Loads an {@link Animation} object from a resource
     *
     * @param context Application context used to access resources
     * @param id The resource id of the animation to load
     * @return The animation object reference by the specified id
     * @throws NotFoundException when the animation cannot be loaded
     * @hide
     */
    public static Animatable loadAnimator(Context context, int id)
            throws NotFoundException {

        XmlResourceParser parser = null;
        try {
            parser = context.getResources().getAnimation(id);
            return createAnimatableFromXml(context, parser);
        } catch (XmlPullParserException ex) {
            NotFoundException rnf = new NotFoundException("Can't load animation resource ID #0x" +
                    Integer.toHexString(id));
            rnf.initCause(ex);
            throw rnf;
        } catch (IOException ex) {
            NotFoundException rnf = new NotFoundException("Can't load animation resource ID #0x" +
                    Integer.toHexString(id));
            rnf.initCause(ex);
            throw rnf;
        } finally {
            if (parser != null) parser.close();
        }
    }

    private static Animatable createAnimatableFromXml(Context c, XmlPullParser parser)
            throws XmlPullParserException, IOException {

        return createAnimatableFromXml(c, parser, Xml.asAttributeSet(parser), null, 0);
    }

    private static Animation createAnimationFromXml(Context c, XmlPullParser parser)
            throws XmlPullParserException, IOException {

@@ -125,6 +177,66 @@ public class AnimationUtils {

    }

    private static Animatable createAnimatableFromXml(Context c, XmlPullParser parser,
            AttributeSet attrs, Sequencer parent, int sequenceOrdering)
            throws XmlPullParserException, IOException {

        Animatable anim = null;
        ArrayList<Animatable> childAnims = null;

        // Make sure we are on a start tag.
        int type;
        int depth = parser.getDepth();

        while (((type=parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth)
               && type != XmlPullParser.END_DOCUMENT) {

            if (type != XmlPullParser.START_TAG) {
                continue;
            }

            String  name = parser.getName();

            if (name.equals("property")) {
                anim = new PropertyAnimator(c, attrs);
            } else if (name.equals("animator")) {
                anim = new Animator(c, attrs);
            } else if (name.equals("sequencer")) {
                anim = new Sequencer();
                TypedArray a = c.obtainStyledAttributes(attrs,
                        com.android.internal.R.styleable.Sequencer);
                int ordering = a.getInt(com.android.internal.R.styleable.Sequencer_ordering,
                        TOGETHER);
                createAnimatableFromXml(c, parser, attrs, (Sequencer) anim,  ordering);
                a.recycle();
            } else {
                throw new RuntimeException("Unknown animator name: " + parser.getName());
            }

            if (parent != null) {
                if (childAnims == null) {
                    childAnims = new ArrayList<Animatable>();
                }
                childAnims.add(anim);
            }
        }
        if (parent != null && childAnims != null) {
            Animatable[] animsArray = new Animatable[childAnims.size()];
            int index = 0;
            for (Animatable a : childAnims) {
                animsArray[index++] = a;
            }
            if (sequenceOrdering == TOGETHER) {
                parent.playTogether(animsArray);
            } else {
                parent.playSequentially(animsArray);
            }
        }

        return anim;

    }

    public static LayoutAnimationController loadLayoutAnimation(Context context, int id)
            throws NotFoundException {
        
Loading