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

Commit 811ed106 authored by Chet Haase's avatar Chet Haase
Browse files

Make Fragments use the new animation APIs

Change-Id: I3e3c271234c737491b6ae37821f16434f4563b1d
parent 943fbb4f
Loading
Loading
Loading
Loading
+87 −151
Original line number Diff line number Diff line
@@ -1482,6 +1482,28 @@
 visibility="public"
>
</field>
<field name="animator_fade_in"
 type="int"
 transient="false"
 volatile="false"
 value="17432609"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="animator_fade_out"
 type="int"
 transient="false"
 volatile="false"
 value="17432610"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="anticipate_interpolator"
 type="int"
 transient="false"
@@ -4310,6 +4332,50 @@
 visibility="public"
>
</field>
<field name="fragmentCloseEnterAnimation"
 type="int"
 transient="false"
 volatile="false"
 value="16843560"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="fragmentCloseExitAnimation"
 type="int"
 transient="false"
 volatile="false"
 value="16843561"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="fragmentOpenEnterAnimation"
 type="int"
 transient="false"
 volatile="false"
 value="16843558"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="fragmentOpenExitAnimation"
 type="int"
 transient="false"
 volatile="false"
 value="16843559"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="freezesText"
 type="int"
 transient="false"
@@ -20806,6 +20872,19 @@
<parameter name="sequenceItems" type="android.animation.Animatable...">
</parameter>
</method>
<method name="setTarget"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="target" type="java.lang.Object">
</parameter>
</method>
</class>
<class name="Sequencer.Builder"
 extends="java.lang.Object"
@@ -27905,8 +27984,8 @@
<parameter name="savedInstanceState" type="android.os.Bundle">
</parameter>
</method>
<method name="onCreateAnimation"
 return="android.view.animation.Animation"
<method name="onCreateAnimatable"
 return="android.animation.Animatable"
 abstract="false"
 native="false"
 synchronized="false"
@@ -28412,39 +28491,6 @@
<parameter name="fragment" type="android.app.Fragment">
</parameter>
</method>
<field name="TRANSIT_ACTIVITY_CLOSE"
 type="int"
 transient="false"
 volatile="false"
 value="8199"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="TRANSIT_ACTIVITY_OPEN"
 type="int"
 transient="false"
 volatile="false"
 value="4102"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="TRANSIT_ENTER"
 type="int"
 transient="false"
 volatile="false"
 value="4097"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="TRANSIT_ENTER_MASK"
 type="int"
 transient="false"
@@ -28456,17 +28502,6 @@
 visibility="public"
>
</field>
<field name="TRANSIT_EXIT"
 type="int"
 transient="false"
 volatile="false"
 value="8194"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="TRANSIT_EXIT_MASK"
 type="int"
 transient="false"
@@ -28478,88 +28513,33 @@
 visibility="public"
>
</field>
<field name="TRANSIT_HIDE"
 type="int"
 transient="false"
 volatile="false"
 value="8196"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="TRANSIT_NONE"
 type="int"
 transient="false"
 volatile="false"
 value="0"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="TRANSIT_PREVIEW_DONE"
 type="int"
 transient="false"
 volatile="false"
 value="5"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="TRANSIT_SHOW"
 type="int"
 transient="false"
 volatile="false"
 value="4099"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="TRANSIT_TASK_CLOSE"
<field name="TRANSIT_FRAGMENT_CLOSE"
 type="int"
 transient="false"
 volatile="false"
 value="8201"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="TRANSIT_TASK_OPEN"
 type="int"
 transient="false"
 volatile="false"
 value="4104"
 value="8194"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="TRANSIT_TASK_TO_BACK"
<field name="TRANSIT_FRAGMENT_OPEN"
 type="int"
 transient="false"
 volatile="false"
 value="8203"
 value="4097"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="TRANSIT_TASK_TO_FRONT"
<field name="TRANSIT_NONE"
 type="int"
 transient="false"
 volatile="false"
 value="4106"
 value="0"
 static="true"
 final="true"
 deprecated="not deprecated"
@@ -28577,50 +28557,6 @@
 visibility="public"
>
</field>
<field name="TRANSIT_WALLPAPER_CLOSE"
 type="int"
 transient="false"
 volatile="false"
 value="8204"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="TRANSIT_WALLPAPER_INTRA_CLOSE"
 type="int"
 transient="false"
 volatile="false"
 value="8207"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="TRANSIT_WALLPAPER_INTRA_OPEN"
 type="int"
 transient="false"
 volatile="false"
 value="4110"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="TRANSIT_WALLPAPER_OPEN"
 type="int"
 transient="false"
 volatile="false"
 value="4109"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
</interface>
<class name="Instrumentation"
 extends="java.lang.Object"
+18 −0
Original line number Diff line number Diff line
@@ -139,6 +139,24 @@ public final class Sequencer extends Animatable {
        return childList;
    }

    /**
     * Sets the target object for all current {@link #getChildAnimations() child animations}
     * of this Sequencer that take targets ({@link android.animation.PropertyAnimator} and
     * Sequencer).
     *
     * @param target The object being animated
     */
    public void setTarget(Object target) {
        for (Node node : mNodes) {
            Animatable animation = node.animation;
            if (animation instanceof Sequencer) {
                ((Sequencer)animation).setTarget(target);
            } else if (animation instanceof PropertyAnimator) {
                ((PropertyAnimator)animation).setTarget(target);
            }
        }
    }

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

package android.app;

import android.animation.Animatable;
import android.content.ComponentCallbacks;
import android.content.Context;
import android.content.Intent;
@@ -35,7 +36,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnCreateContextMenuListener;
import android.view.animation.Animation;
import android.widget.AdapterView;

import java.lang.reflect.InvocationTargetException;
@@ -495,7 +495,10 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener
        mCalled = true;
    }
    
    public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
    /**
     * Called when a fragment loads an animation.
     */
    public Animatable onCreateAnimatable(int transit, boolean enter, int nextAnim) {
        return null;
    }
    
+46 −112
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package android.app;

import android.animation.Animatable;
import android.animation.PropertyAnimator;
import android.animation.Sequencer;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.os.Handler;
@@ -28,7 +31,6 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;

import java.util.ArrayList;
@@ -106,16 +108,16 @@ public class FragmentManager {
        }
    };
    
    Animation loadAnimation(Fragment fragment, int transit, boolean enter,
    Animatable loadAnimatable(Fragment fragment, int transit, boolean enter,
            int transitionStyle) {
        Animation animObj = fragment.onCreateAnimation(transitionStyle, enter,
        Animatable animObj = fragment.onCreateAnimatable(transit, enter,
                fragment.mNextAnim);
        if (animObj != null) {
            return animObj;
        }
        
        if (fragment.mNextAnim != 0) {
            Animation anim = AnimationUtils.loadAnimation(mActivity, fragment.mNextAnim);
            Animatable anim = AnimationUtils.loadAnimator(mActivity, fragment.mNextAnim);
            if (anim != null) {
                return anim;
            }
@@ -138,7 +140,7 @@ public class FragmentManager {
        }
        
        TypedArray attrs = mActivity.obtainStyledAttributes(transitionStyle,
                com.android.internal.R.styleable.WindowAnimation);
                com.android.internal.R.styleable.FragmentAnimation);
        int anim = attrs.getResourceId(styleIndex, 0);
        attrs.recycle();
        
@@ -146,7 +148,7 @@ public class FragmentManager {
            return null;
        }
        
        return AnimationUtils.loadAnimation(mActivity, anim);
        return AnimationUtils.loadAnimator(mActivity, anim);
    }
    
    void moveToState(Fragment f, int newState, int transit, int transitionStyle) {
@@ -208,10 +210,15 @@ public class FragmentManager {
                            if (f.mView != null) {
                                f.mView.setSaveFromParentEnabled(false);
                                if (container != null) {
                                    Animation anim = loadAnimation(f, transit, true,
                                    Animatable anim = loadAnimatable(f, transit, true,
                                            transitionStyle);
                                    if (anim != null) {
                                        f.mView.setAnimation(anim);
                                        if (anim instanceof Sequencer) {
                                            ((Sequencer)anim).setTarget(f.mView);
                                        } else if (anim instanceof PropertyAnimator) {
                                            ((PropertyAnimator)anim).setTarget(f.mView);
                                        }
                                        anim.start();
                                    }
                                    container.addView(f.mView);
                                    f.restoreViewState();
@@ -290,10 +297,15 @@ public class FragmentManager {
                            }
                            if (f.mContainer != null) {
                                if (mCurState > Fragment.INITIALIZING) {
                                    Animation anim = loadAnimation(f, transit, false,
                                    Animatable anim = loadAnimatable(f, transit, true,
                                            transitionStyle);
                                    if (anim != null) {
                                        f.mView.setAnimation(anim);
                                        if (anim instanceof Sequencer) {
                                            ((Sequencer)anim).setTarget(f.mView);
                                        } else if (anim instanceof PropertyAnimator) {
                                            ((PropertyAnimator)anim).setTarget(f.mView);
                                        }
                                        anim.start();
                                    }
                                }
                                f.mContainer.removeView(f.mView);
@@ -420,10 +432,15 @@ public class FragmentManager {
        if (!fragment.mHidden) {
            fragment.mHidden = true;
            if (fragment.mView != null) {
                Animation anim = loadAnimation(fragment, transition, false,
                Animatable anim = loadAnimatable(fragment, transition, true,
                        transitionStyle);
                if (anim != null) {
                    fragment.mView.setAnimation(anim);
                    if (anim instanceof Sequencer) {
                        ((Sequencer)anim).setTarget(fragment.mView);
                    } else if (anim instanceof PropertyAnimator) {
                        ((PropertyAnimator)anim).setTarget(fragment.mView);
                    }
                    anim.start();
                }
                fragment.mView.setVisibility(View.GONE);
            }
@@ -439,10 +456,15 @@ public class FragmentManager {
        if (fragment.mHidden) {
            fragment.mHidden = false;
            if (fragment.mView != null) {
                Animation anim = loadAnimation(fragment, transition, true,
                Animatable anim = loadAnimatable(fragment, transition, true,
                        transitionStyle);
                if (anim != null) {
                    fragment.mView.setAnimation(anim);
                    if (anim instanceof Sequencer) {
                        ((Sequencer)anim).setTarget(fragment.mView);
                    } else if (anim instanceof PropertyAnimator) {
                        ((PropertyAnimator)anim).setTarget(fragment.mView);
                    }
                    anim.start();
                }
                fragment.mView.setVisibility(View.VISIBLE);
            }
@@ -981,47 +1003,11 @@ public class FragmentManager {
    public static int reverseTransit(int transit) {
        int rev = 0;
        switch (transit) {
            case FragmentTransaction.TRANSIT_ENTER:
                rev = FragmentTransaction.TRANSIT_EXIT;
                break;
            case FragmentTransaction.TRANSIT_EXIT:
                rev = FragmentTransaction.TRANSIT_ENTER;
                break;
            case FragmentTransaction.TRANSIT_SHOW:
                rev = FragmentTransaction.TRANSIT_HIDE;
                break;
            case FragmentTransaction.TRANSIT_HIDE:
                rev = FragmentTransaction.TRANSIT_SHOW;
                break;
            case FragmentTransaction.TRANSIT_ACTIVITY_OPEN:
                rev = FragmentTransaction.TRANSIT_ACTIVITY_CLOSE;
                break;
            case FragmentTransaction.TRANSIT_ACTIVITY_CLOSE:
                rev = FragmentTransaction.TRANSIT_ACTIVITY_OPEN;
            case FragmentTransaction.TRANSIT_FRAGMENT_OPEN:
                rev = FragmentTransaction.TRANSIT_FRAGMENT_CLOSE;
                break;
            case FragmentTransaction.TRANSIT_TASK_OPEN:
                rev = FragmentTransaction.TRANSIT_TASK_CLOSE;
                break;
            case FragmentTransaction.TRANSIT_TASK_CLOSE:
                rev = FragmentTransaction.TRANSIT_TASK_OPEN;
                break;
            case FragmentTransaction.TRANSIT_TASK_TO_FRONT:
                rev = FragmentTransaction.TRANSIT_TASK_TO_BACK;
                break;
            case FragmentTransaction.TRANSIT_TASK_TO_BACK:
                rev = FragmentTransaction.TRANSIT_TASK_TO_FRONT;
                break;
            case FragmentTransaction.TRANSIT_WALLPAPER_OPEN:
                rev = FragmentTransaction.TRANSIT_WALLPAPER_CLOSE;
                break;
            case FragmentTransaction.TRANSIT_WALLPAPER_CLOSE:
                rev = FragmentTransaction.TRANSIT_WALLPAPER_OPEN;
                break;
            case FragmentTransaction.TRANSIT_WALLPAPER_INTRA_OPEN:
                rev = FragmentTransaction.TRANSIT_WALLPAPER_INTRA_CLOSE;
                break;
            case FragmentTransaction.TRANSIT_WALLPAPER_INTRA_CLOSE:
                rev = FragmentTransaction.TRANSIT_WALLPAPER_INTRA_OPEN;
            case FragmentTransaction.TRANSIT_FRAGMENT_CLOSE:
                rev = FragmentTransaction.TRANSIT_FRAGMENT_OPEN;
                break;
        }
        return rev;
@@ -1031,67 +1017,15 @@ public class FragmentManager {
    public static int transitToStyleIndex(int transit, boolean enter) {
        int animAttr = -1;
        switch (transit) {
            case FragmentTransaction.TRANSIT_ENTER:
                animAttr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
                break;
            case FragmentTransaction.TRANSIT_EXIT:
                animAttr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
                break;
            case FragmentTransaction.TRANSIT_SHOW:
                animAttr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
                break;
            case FragmentTransaction.TRANSIT_HIDE:
                animAttr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
                break;
            case FragmentTransaction.TRANSIT_ACTIVITY_OPEN:
                animAttr = enter
                        ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
                        : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
                break;
            case FragmentTransaction.TRANSIT_ACTIVITY_CLOSE:
                animAttr = enter
                        ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
                        : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
                break;
            case FragmentTransaction.TRANSIT_TASK_OPEN:
                animAttr = enter
                        ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
                        : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
                break;
            case FragmentTransaction.TRANSIT_TASK_CLOSE:
                animAttr = enter
                        ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
                        : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
                break;
            case FragmentTransaction.TRANSIT_TASK_TO_FRONT:
                animAttr = enter
                        ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
                        : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
                break;
            case FragmentTransaction.TRANSIT_TASK_TO_BACK:
                animAttr = enter
                        ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
                        : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
                break;
            case FragmentTransaction.TRANSIT_WALLPAPER_OPEN:
                animAttr = enter
                        ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
                        : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
                break;
            case FragmentTransaction.TRANSIT_WALLPAPER_CLOSE:
                animAttr = enter
                        ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
                        : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
                break;
            case FragmentTransaction.TRANSIT_WALLPAPER_INTRA_OPEN:
            case FragmentTransaction.TRANSIT_FRAGMENT_OPEN:
                animAttr = enter
                        ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
                        : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
                    ? com.android.internal.R.styleable.FragmentAnimation_fragmentOpenEnterAnimation
                    : com.android.internal.R.styleable.FragmentAnimation_fragmentOpenExitAnimation;
                break;
            case FragmentTransaction.TRANSIT_WALLPAPER_INTRA_CLOSE:
            case FragmentTransaction.TRANSIT_FRAGMENT_CLOSE:
                animAttr = enter
                        ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
                        : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
                    ? com.android.internal.R.styleable.FragmentAnimation_fragmentCloseEnterAnimation
                    : com.android.internal.R.styleable.FragmentAnimation_fragmentCloseExitAnimation;
                break;
        }
        return animAttr;
+5 −41
Original line number Diff line number Diff line
@@ -100,46 +100,10 @@ public interface FragmentTransaction {
    public final int TRANSIT_UNSET = -1;
    /** No animation for transition. */
    public final int TRANSIT_NONE = 0;
    /** Window has been added to the screen. */
    public final int TRANSIT_ENTER = 1 | TRANSIT_ENTER_MASK;
    /** Window has been removed from the screen. */
    public final int TRANSIT_EXIT = 2 | TRANSIT_EXIT_MASK;
    /** Window has been made visible. */
    public final int TRANSIT_SHOW = 3 | TRANSIT_ENTER_MASK;
    /** Window has been made invisible. */
    public final int TRANSIT_HIDE = 4 | TRANSIT_EXIT_MASK;
    /** The "application starting" preview window is no longer needed, and will
     * animate away to show the real window. */
    public final int TRANSIT_PREVIEW_DONE = 5;
    /** A window in a new activity is being opened on top of an existing one
     * in the same task. */
    public final int TRANSIT_ACTIVITY_OPEN = 6 | TRANSIT_ENTER_MASK;
    /** The window in the top-most activity is being closed to reveal the
     * previous activity in the same task. */
    public final int TRANSIT_ACTIVITY_CLOSE = 7 | TRANSIT_EXIT_MASK;
    /** A window in a new task is being opened on top of an existing one
     * in another activity's task. */
    public final int TRANSIT_TASK_OPEN = 8 | TRANSIT_ENTER_MASK;
    /** A window in the top-most activity is being closed to reveal the
     * previous activity in a different task. */
    public final int TRANSIT_TASK_CLOSE = 9 | TRANSIT_EXIT_MASK;
    /** A window in an existing task is being displayed on top of an existing one
     * in another activity's task. */
    public final int TRANSIT_TASK_TO_FRONT = 10 | TRANSIT_ENTER_MASK;
    /** A window in an existing task is being put below all other tasks. */
    public final int TRANSIT_TASK_TO_BACK = 11 | TRANSIT_EXIT_MASK;
    /** A window in a new activity that doesn't have a wallpaper is being
     * opened on top of one that does, effectively closing the wallpaper. */
    public final int TRANSIT_WALLPAPER_CLOSE = 12 | TRANSIT_EXIT_MASK;
    /** A window in a new activity that does have a wallpaper is being
     * opened on one that didn't, effectively opening the wallpaper. */
    public final int TRANSIT_WALLPAPER_OPEN = 13 | TRANSIT_ENTER_MASK;
    /** A window in a new activity is being opened on top of an existing one,
     * and both are on top of the wallpaper. */
    public final int TRANSIT_WALLPAPER_INTRA_OPEN = 14 | TRANSIT_ENTER_MASK;
    /** The window in the top-most activity is being closed to reveal the
     * previous activity, and both are on top of he wallpaper. */
    public final int TRANSIT_WALLPAPER_INTRA_CLOSE = 15 | TRANSIT_EXIT_MASK;
    /** Fragment is being added */
    public final int TRANSIT_FRAGMENT_OPEN = 1 | TRANSIT_ENTER_MASK;
    /** Fragment is being removed */
    public final int TRANSIT_FRAGMENT_CLOSE = 2 | TRANSIT_EXIT_MASK;

    public FragmentTransaction setCustomAnimations(int enter, int exit);
    
Loading