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

Commit 44d66384 authored by George Mount's avatar George Mount
Browse files

Allow custom transitions from XML.

Bug 15699798

Change-Id: I841289a72d7c08bb24b3e18380c79ba7960f9b22
parent 45b161d2
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -73,6 +73,11 @@ import java.util.List;
 *
 * {@sample development/samples/ApiDemos/res/transition/explode_move_together.xml MultipleTransform}
 *
 * <p>Custom transition classes may be instantiated with a <code>transition</code> tag:</p>
 * <pre>&lt;transition class="my.app.transition.CustomTransition"/></pre>
 * <p>Custom transition classes loaded from XML must have a public nullary (no argument)
 * constructor.</p>
 *
 * <p>Note that attributes for the transition are not required, just as they are
 * optional when declared in code; Transitions created from XML resources will use
 * the same defaults as their code-created equivalents. Here is a slightly more
+25 −0
Original line number Diff line number Diff line
@@ -182,6 +182,8 @@ public class TransitionInflater {
                createTransitionFromXml(parser, attrs, ((TransitionSet) transition));
                a.recycle();
                newTransition = true;
            } else if ("transition".equals(name)) {
                transition = createCustomTransition(attrs);
            } else if ("targets".equals(name)) {
                if (parser.getDepth() - 1 > depth && transition != null) {
                    // We're inside the child tag - add targets to the child
@@ -206,6 +208,29 @@ public class TransitionInflater {
        return transition;
    }

    private Transition createCustomTransition(AttributeSet attrs) {
        String className = attrs.getAttributeValue(null, "class");

        if (className == null) {
            throw new RuntimeException("transition tag must have a 'class' attribute");
        }

        try {
            Class c = Class.forName(className);
            if (!Transition.class.isAssignableFrom(c)) {
                throw new RuntimeException("transition class must be a Transition: " + className);
            }
            return (Transition) c.newInstance();
        } catch (InstantiationException e) {
            throw new RuntimeException("Could not instantiate transition class", e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException("Could not access default constructor for transition class "
                    + className, e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException("Could not find transition class " + className, e);
        }
    }

    private Slide createSlideTransition(AttributeSet attrs) {
        TypedArray a = mContext.obtainStyledAttributes(attrs,
                com.android.internal.R.styleable.Slide);