Add differentiating transitions for returning/reentering.

Bug 16550363

Change-Id: I85f9a8bcbc92ce048d06b36579bb05893534f7f8
diff --git a/core/java/android/app/EnterTransitionCoordinator.java b/core/java/android/app/EnterTransitionCoordinator.java
index 1326064..b5d362d 100644
--- a/core/java/android/app/EnterTransitionCoordinator.java
+++ b/core/java/android/app/EnterTransitionCoordinator.java
@@ -256,7 +256,7 @@
     @Override
     protected Transition getViewsTransition() {
         if (mIsReturning) {
-            return getWindow().getExitTransition();
+            return getWindow().getReenterTransition();
         } else {
             return getWindow().getEnterTransition();
         }
@@ -264,7 +264,7 @@
 
     protected Transition getSharedElementTransition() {
         if (mIsReturning) {
-            return getWindow().getSharedElementExitTransition();
+            return getWindow().getSharedElementReenterTransition();
         } else {
             return getWindow().getSharedElementEnterTransition();
         }
diff --git a/core/java/android/app/ExitTransitionCoordinator.java b/core/java/android/app/ExitTransitionCoordinator.java
index 2ce6018..b3fdcc7 100644
--- a/core/java/android/app/ExitTransitionCoordinator.java
+++ b/core/java/android/app/ExitTransitionCoordinator.java
@@ -395,7 +395,7 @@
     @Override
     protected Transition getViewsTransition() {
         if (mIsReturning) {
-            return getWindow().getEnterTransition();
+            return getWindow().getReturnTransition();
         } else {
             return getWindow().getExitTransition();
         }
@@ -403,7 +403,7 @@
 
     protected Transition getSharedElementTransition() {
         if (mIsReturning) {
-            return getWindow().getSharedElementEnterTransition();
+            return getWindow().getSharedElementReturnTransition();
         } else {
             return getWindow().getSharedElementExitTransition();
         }
diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java
index c169d35..e7b3152 100644
--- a/core/java/android/view/Window.java
+++ b/core/java/android/view/Window.java
@@ -1425,6 +1425,21 @@
     public void setEnterTransition(Transition transition) {}
 
     /**
+     * Sets the Transition that will be used to move Views out of the scene when the Window is
+     * preparing to close, for example after a call to
+     * {@link android.app.Activity#finishAfterTransition()}. The exiting
+     * Views will be those that are regular Views or ViewGroups that have
+     * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
+     * {@link android.transition.Visibility} as entering is governed by changing visibility from
+     * {@link View#VISIBLE} to {@link View#INVISIBLE}. If <code>transition</code> is null,
+     * entering Views will remain unaffected. If nothing is set, the default will be to
+     * use the same value as set in {@link #setEnterTransition(android.transition.Transition)}.
+     * @param transition The Transition to use to move Views out of the Scene when the Window
+     *                   is preparing to close.
+     */
+    public void setReturnTransition(Transition transition) {}
+
+    /**
      * Sets the Transition that will be used to move Views out of the scene when starting a
      * new Activity. The exiting Views will be those that are regular Views or ViewGroups that
      * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
@@ -1437,6 +1452,20 @@
     public void setExitTransition(Transition transition) {}
 
     /**
+     * Sets the Transition that will be used to move Views in to the scene when returning from
+     * a previously-started Activity. The entering Views will be those that are regular Views
+     * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions
+     * will extend {@link android.transition.Visibility} as exiting is governed by changing
+     * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null,
+     * the views will remain unaffected. If nothing is set, the default will be to use the same
+     * transition as {@link #setExitTransition(android.transition.Transition)}.
+     * Requires {@link #FEATURE_CONTENT_TRANSITIONS}.
+     * @param transition The Transition to use to move Views into the scene when reentering from a
+     *                   previously-started Activity.
+     */
+    public void setReenterTransition(Transition transition) {}
+
+    /**
      * Returns the transition used to move Views into the initial scene. The entering
      * Views will be those that are regular Views or ViewGroups that have
      * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
@@ -1449,6 +1478,19 @@
     public Transition getEnterTransition() { return null; }
 
     /**
+     * Returns he Transition that will be used to move Views out of the scene when the Window is
+     * preparing to close, for example after a call to
+     * {@link android.app.Activity#finishAfterTransition()}. The exiting
+     * Views will be those that are regular Views or ViewGroups that have
+     * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
+     * {@link android.transition.Visibility} as entering is governed by changing visibility from
+     * {@link View#VISIBLE} to {@link View#INVISIBLE}.
+     * @return The Transition to use to move Views out of the Scene when the Window
+     *         is preparing to close.
+     */
+    public Transition getReturnTransition() { return null; }
+
+    /**
      * Returns the Transition that will be used to move Views out of the scene when starting a
      * new Activity. The exiting Views will be those that are regular Views or ViewGroups that
      * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
@@ -1461,6 +1503,18 @@
     public Transition getExitTransition() { return null; }
 
     /**
+     * Returns the Transition that will be used to move Views in to the scene when returning from
+     * a previously-started Activity. The entering Views will be those that are regular Views
+     * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions
+     * will extend {@link android.transition.Visibility} as exiting is governed by changing
+     * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}.
+     * Requires {@link #FEATURE_CONTENT_TRANSITIONS}.
+     * @return The Transition to use to move Views into the scene when reentering from a
+     *         previously-started Activity.
+     */
+    public Transition getReenterTransition() { return null; }
+
+    /**
      * Sets the Transition that will be used for shared elements transferred into the content
      * Scene. Typical Transitions will affect size and location, such as
      * {@link android.transition.ChangeBounds}. A null
@@ -1472,6 +1526,19 @@
     public void setSharedElementEnterTransition(Transition transition) {}
 
     /**
+     * Sets the Transition that will be used for shared elements transferred back to a
+     * calling Activity. Typical Transitions will affect size and location, such as
+     * {@link android.transition.ChangeBounds}. A null
+     * value will cause transferred shared elements to blink to the final position.
+     * If no value is set, the default will be to use the same value as
+     * {@link #setSharedElementEnterTransition(android.transition.Transition)}.
+     * Requires {@link #FEATURE_CONTENT_TRANSITIONS}.
+     * @param transition The Transition to use for shared elements transferred out of the content
+     *                   Scene.
+     */
+    public void setSharedElementReturnTransition(Transition transition) {}
+
+    /**
      * Returns the Transition that will be used for shared elements transferred into the content
      * Scene. Requires {@link #FEATURE_CONTENT_TRANSITIONS}.
      * @return Transition to use for sharend elements transferred into the content Scene.
@@ -1479,6 +1546,13 @@
     public Transition getSharedElementEnterTransition() { return null; }
 
     /**
+     * Returns the Transition that will be used for shared elements transferred back to a
+     * calling Activity. Requires {@link #FEATURE_CONTENT_TRANSITIONS}.
+     * @return Transition to use for sharend elements transferred into the content Scene.
+     */
+    public Transition getSharedElementReturnTransition() { return null; }
+
+    /**
      * Sets the Transition that will be used for shared elements after starting a new Activity
      * before the shared elements are transferred to the called Activity. If the shared elements
      * must animate during the exit transition, this Transition should be used. Upon completion,
@@ -1490,6 +1564,17 @@
     public void setSharedElementExitTransition(Transition transition) {}
 
     /**
+     * Sets the Transition that will be used for shared elements reentering from a started
+     * Activity after it has returned the shared element to it start location. If no value
+     * is set, this will default to
+     * {@link #setSharedElementExitTransition(android.transition.Transition)}.
+     * Requires {@link #FEATURE_CONTENT_TRANSITIONS}.
+     * @param transition The Transition to use for shared elements in the launching Window
+     *                   after the shared element has returned to the Window.
+     */
+    public void setSharedElementReenterTransition(Transition transition) {}
+
+    /**
      * Returns the Transition to use for shared elements in the launching Window prior
      * to transferring to the launched Activity's Window.
      * Requires {@link #FEATURE_CONTENT_TRANSITIONS}.
@@ -1500,6 +1585,16 @@
     public Transition getSharedElementExitTransition() { return null; }
 
     /**
+     * Returns the Transition that will be used for shared elements reentering from a started
+     * Activity after it has returned the shared element to it start location.
+     * Requires {@link #FEATURE_CONTENT_TRANSITIONS}.
+     *
+     * @return the Transition that will be used for shared elements reentering from a started
+     * Activity after it has returned the shared element to it start location.
+     */
+    public Transition getSharedElementReenterTransition() { return null; }
+
+    /**
      * Controls how the transition set in
      * {@link #setEnterTransition(android.transition.Transition)} overlaps with the exit
      * transition of the calling Activity. When true, the transition will start as soon as possible.
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 5cb3068..d07d0ab 100644
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -464,24 +464,48 @@
         <attr name="windowEnterTransition" format="reference"/>
 
         <!-- Reference to a Transition XML resource defining the desired Transition
+             used to move Views out of the scene when the Window is
+             preparing to close. Corresponds to
+             {@link android.view.Window#setReturnTransition(android.transition.Transition)}. -->
+        <attr name="windowReturnTransition" format="reference"/>
+
+        <!-- Reference to a Transition XML resource defining the desired Transition
              used to move Views out of the Window's content Scene when launching a new Activity.
              Corresponds to
              {@link android.view.Window#setExitTransition(android.transition.Transition)}. -->
         <attr name="windowExitTransition" format="reference"/>
 
         <!-- Reference to a Transition XML resource defining the desired Transition
+             used to move Views in to the scene when returning from a previously-started Activity.
+             Corresponds to
+             {@link android.view.Window#setReenterTransition(android.transition.Transition)}. -->
+        <attr name="windowReenterTransition" format="reference"/>
+
+        <!-- Reference to a Transition XML resource defining the desired Transition
              used to move shared elements transferred into the Window's initial content Scene.
              Corresponds to {@link android.view.Window#setSharedElementEnterTransition(
              android.transition.Transition)}. -->
         <attr name="windowSharedElementEnterTransition" format="reference"/>
 
         <!-- Reference to a Transition XML resource defining the desired Transition
+             used to move shared elements transferred back to a calling Activity.
+             Corresponds to {@link android.view.Window#setSharedElementReturnTransition(
+             android.transition.Transition)}. -->
+        <attr name="windowSharedElementReturnTransition" format="reference"/>
+
+        <!-- Reference to a Transition XML resource defining the desired Transition
              used when starting a new Activity to move shared elements prior to transferring
              to the called Activity.
              Corresponds to {@link android.view.Window#setSharedElementExitTransition(
              android.transition.Transition)}. -->
         <attr name="windowSharedElementExitTransition" format="reference"/>
 
+        <!-- Reference to a Transition XML resource defining the desired Transition
+             used for shared elements transferred back to a calling Activity.
+             Corresponds to {@link android.view.Window#setSharedElementReenterTransition(
+             android.transition.Transition)}. -->
+        <attr name="windowSharedElementReenterTransition" format="reference"/>
+
         <!-- Flag indicating whether this Window's transition should overlap with
              the exiting transition of the calling Activity. Corresponds to
              {@link android.view.Window#setAllowEnterTransitionOverlap(boolean)}. -->
@@ -1751,30 +1775,54 @@
              or a fraction of the screen size in that dimension. -->
         <attr name="windowFixedHeightMajor" format="dimension|fraction" />
         <attr name="windowOutsetBottom" format="dimension" />
-        <!-- Reference to a TransitionManager XML resource defining the desired Transition
+        <!-- Reference to a Transition XML resource defining the desired Transition
              used to move Views into the initial Window's content Scene. Corresponds to
              {@link android.view.Window#setEnterTransition(android.transition.Transition)}. -->
         <attr name="windowEnterTransition"/>
 
-        <!-- Reference to a TransitionManager XML resource defining the desired Transition
+        <!-- Reference to a Transition XML resource defining the desired Transition
+             used to move Views out of the scene when the Window is
+             preparing to close. Corresponds to
+             {@link android.view.Window#setReturnTransition(android.transition.Transition)}. -->
+        <attr name="windowReturnTransition"/>
+
+        <!-- Reference to a Transition XML resource defining the desired Transition
              used to move Views out of the Window's content Scene when launching a new Activity.
              Corresponds to
              {@link android.view.Window#setExitTransition(android.transition.Transition)}. -->
         <attr name="windowExitTransition"/>
 
-        <!-- Reference to a TransitionManager XML resource defining the desired Transition
+        <!-- Reference to a Transition XML resource defining the desired Transition
+             used to move Views in to the scene when returning from a previously-started Activity.
+             Corresponds to
+             {@link android.view.Window#setReenterTransition(android.transition.Transition)}. -->
+        <attr name="windowReenterTransition"/>
+
+        <!-- Reference to a Transition XML resource defining the desired Transition
              used to move shared elements transferred into the Window's initial content Scene.
              Corresponds to {@link android.view.Window#setSharedElementEnterTransition(
              android.transition.Transition)}. -->
         <attr name="windowSharedElementEnterTransition"/>
 
-        <!-- Reference to a TransitionManager XML resource defining the desired Transition
+        <!-- Reference to a Transition XML resource defining the desired Transition
+             used to move shared elements transferred back to a calling Activity.
+             Corresponds to {@link android.view.Window#setSharedElementReturnTransition(
+             android.transition.Transition)}. -->
+        <attr name="windowSharedElementReturnTransition"/>
+
+        <!-- Reference to a Transition XML resource defining the desired Transition
              used when starting a new Activity to move shared elements prior to transferring
              to the called Activity.
              Corresponds to {@link android.view.Window#setSharedElementExitTransition(
              android.transition.Transition)}. -->
         <attr name="windowSharedElementExitTransition"/>
 
+        <!-- Reference to a Transition XML resource defining the desired Transition
+             used for shared elements transferred back to a calling Activity.
+             Corresponds to {@link android.view.Window#setSharedElementReenterTransition(
+             android.transition.Transition)}. -->
+        <attr name="windowSharedElementReenterTransition"/>
+
 
         <!-- Flag indicating whether this Window's transition should overlap with
              the exiting transition of the calling Activity. Corresponds to
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index 0cb14e3..d8f9665 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -2265,6 +2265,10 @@
   <public type="attr" name="windowClipToOutline" />
   <public type="attr" name="datePickerDialogTheme" />
   <public type="attr" name="showText" />
+  <public type="attr" name="windowReturnTransition" />
+  <public type="attr" name="windowReenterTransition" />
+  <public type="attr" name="windowSharedElementReturnTransition" />
+  <public type="attr" name="windowSharedElementReenterTransition" />
 
   <public-padding type="dimen" name="l_resource_pad" end="0x01050010" />