GuidedStepFragment Refactoring background handling

Changed the way background works, no longer use a dedicated
BackgroundFragment, make background part of GuidedStepFragment.
This need some tuning to make background view part of
GuidedStepFragment transition (and excluded in some cases).

Switch the default Ui Style to be UI_STYLE_ENTRANCE, allows
app launches GuidedStepFragment without using helper method.

Bug: 25671370

Change-Id: Ic68c0cc796d32df6919593d391a6fcfae99258ae
diff --git a/v17/leanback/api/current.txt b/v17/leanback/api/current.txt
index 2cb0338..a4decd8 100644
--- a/v17/leanback/api/current.txt
+++ b/v17/leanback/api/current.txt
@@ -216,7 +216,6 @@
     method public java.util.List<android.support.v17.leanback.widget.GuidedAction> getActions();
     method public android.view.View getButtonActionItemView(int);
     method public java.util.List<android.support.v17.leanback.widget.GuidedAction> getButtonActions();
-    method protected int getContainerIdForBackground();
     method public static android.support.v17.leanback.app.GuidedStepFragment getCurrentGuidedStepFragment(android.app.FragmentManager);
     method public android.support.v17.leanback.widget.GuidanceStylist getGuidanceStylist();
     method public android.support.v17.leanback.widget.GuidedActionsStylist getGuidedActionsStylist();
@@ -232,6 +231,7 @@
     method protected void onAddSharedElementTransition(android.app.FragmentTransaction, android.support.v17.leanback.app.GuidedStepFragment);
     method public void onCreateActions(java.util.List<android.support.v17.leanback.widget.GuidedAction>, android.os.Bundle);
     method public android.support.v17.leanback.widget.GuidedActionsStylist onCreateActionsStylist();
+    method public android.view.View onCreateBackgroundView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle);
     method public void onCreateButtonActions(java.util.List<android.support.v17.leanback.widget.GuidedAction>, android.os.Bundle);
     method public android.support.v17.leanback.widget.GuidedActionsStylist onCreateButtonActionsStylist();
     method public android.support.v17.leanback.widget.GuidanceStylist.Guidance onCreateGuidance(android.os.Bundle);
@@ -240,7 +240,6 @@
     method public void onGuidedActionEdited(android.support.v17.leanback.widget.GuidedAction);
     method public long onGuidedActionEditedAndProceed(android.support.v17.leanback.widget.GuidedAction);
     method public void onGuidedActionFocused(android.support.v17.leanback.widget.GuidedAction);
-    method protected android.app.Fragment onProvideBackgroundFragment();
     method protected void onProvideFragmentTransitions();
     method public int onProvideTheme();
     method public void popBackStackToGuidedStepFragment(java.lang.Class, int);
@@ -251,13 +250,8 @@
     method public void setUiStyle(int);
     field public static final java.lang.String EXTRA_UI_STYLE = "uiStyle";
     field public static final int UI_STYLE_ACTIVITY_ROOT = 2; // 0x2
-    field public static final int UI_STYLE_DEFAULT = 0; // 0x0
     field public static final int UI_STYLE_ENTRANCE = 1; // 0x1
-  }
-
-  public static class GuidedStepFragment.GuidedStepBackgroundFragment extends android.app.Fragment {
-    ctor public GuidedStepFragment.GuidedStepBackgroundFragment();
-    method protected void onProvideFragmentTransitions();
+    field public static final int UI_STYLE_REPLACE = 0; // 0x0
   }
 
   public class GuidedStepSupportFragment extends android.support.v4.app.Fragment {
@@ -276,7 +270,6 @@
     method public java.util.List<android.support.v17.leanback.widget.GuidedAction> getActions();
     method public android.view.View getButtonActionItemView(int);
     method public java.util.List<android.support.v17.leanback.widget.GuidedAction> getButtonActions();
-    method protected int getContainerIdForBackground();
     method public static android.support.v17.leanback.app.GuidedStepSupportFragment getCurrentGuidedStepSupportFragment(android.support.v4.app.FragmentManager);
     method public android.support.v17.leanback.widget.GuidanceStylist getGuidanceStylist();
     method public android.support.v17.leanback.widget.GuidedActionsStylist getGuidedActionsStylist();
@@ -292,6 +285,7 @@
     method protected void onAddSharedElementTransition(android.support.v4.app.FragmentTransaction, android.support.v17.leanback.app.GuidedStepSupportFragment);
     method public void onCreateActions(java.util.List<android.support.v17.leanback.widget.GuidedAction>, android.os.Bundle);
     method public android.support.v17.leanback.widget.GuidedActionsStylist onCreateActionsStylist();
+    method public android.view.View onCreateBackgroundView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle);
     method public void onCreateButtonActions(java.util.List<android.support.v17.leanback.widget.GuidedAction>, android.os.Bundle);
     method public android.support.v17.leanback.widget.GuidedActionsStylist onCreateButtonActionsStylist();
     method public android.support.v17.leanback.widget.GuidanceStylist.Guidance onCreateGuidance(android.os.Bundle);
@@ -300,7 +294,6 @@
     method public void onGuidedActionEdited(android.support.v17.leanback.widget.GuidedAction);
     method public long onGuidedActionEditedAndProceed(android.support.v17.leanback.widget.GuidedAction);
     method public void onGuidedActionFocused(android.support.v17.leanback.widget.GuidedAction);
-    method protected android.support.v4.app.Fragment onProvideBackgroundSupportFragment();
     method protected void onProvideFragmentTransitions();
     method public int onProvideTheme();
     method public void popBackStackToGuidedStepSupportFragment(java.lang.Class, int);
@@ -311,13 +304,8 @@
     method public void setUiStyle(int);
     field public static final java.lang.String EXTRA_UI_STYLE = "uiStyle";
     field public static final int UI_STYLE_ACTIVITY_ROOT = 2; // 0x2
-    field public static final int UI_STYLE_DEFAULT = 0; // 0x0
     field public static final int UI_STYLE_ENTRANCE = 1; // 0x1
-  }
-
-  public static class GuidedStepSupportFragment.GuidedStepBackgroundSupportFragment extends android.support.v4.app.Fragment {
-    ctor public GuidedStepSupportFragment.GuidedStepBackgroundSupportFragment();
-    method protected void onProvideFragmentTransitions();
+    field public static final int UI_STYLE_REPLACE = 0; // 0x0
   }
 
   public class HeadersFragment extends android.support.v17.leanback.app.BaseRowFragment {
diff --git a/v17/leanback/res/layout/lb_guidedstep_background.xml b/v17/leanback/res/layout/lb_guidedstep_background.xml
index 66b68c4..08ea47d 100644
--- a/v17/leanback/res/layout/lb_guidedstep_background.xml
+++ b/v17/leanback/res/layout/lb_guidedstep_background.xml
@@ -17,6 +17,7 @@
 <android.support.v17.leanback.widget.NonOverlappingView
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/guidedstep_background"
+    android:transitionName="guidedstep_background"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:background="?attr/guidedStepBackground" />
diff --git a/v17/leanback/res/layout/lb_guidedstep_fragment.xml b/v17/leanback/res/layout/lb_guidedstep_fragment.xml
index 31e2fee..ca6efc4 100644
--- a/v17/leanback/res/layout/lb_guidedstep_fragment.xml
+++ b/v17/leanback/res/layout/lb_guidedstep_fragment.xml
@@ -15,51 +15,57 @@
      limitations under the License.
 -->
 <!-- Layout for the frame of a 2 pane actions fragment. -->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:id="@+id/content_frame"
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/guidedstep_root"
     android:orientation="horizontal"
     android:layout_width="match_parent"
     android:layout_height="match_parent" >
-
-    <android.support.v17.leanback.widget.NonOverlappingFrameLayout
-        android:id="@+id/content_fragment"
-        android:layout_toStartOf="@+id/action_fragment"
-        android:layout_width="0dp"
-        android:layout_weight="1"
-        android:layout_height="match_parent"
-        android:layout_alignParentStart="true" />
-
-    <android.support.v17.leanback.widget.NonOverlappingFrameLayout
-        android:id="@+id/action_fragment_root"
-        android:transitionName="action_fragment_root"
-        android:transitionGroup="false"
+    <LinearLayout
+        android:id="@+id/content_frame"
         android:orientation="horizontal"
-        android:clipToPadding="false"
-        android:clipChildren="false"
-        android:paddingStart="@dimen/lb_guidedactions_section_shadow_width"
-        android:layout_width="0dp"
-        android:layout_weight="?attr/guidedActionContentWidthWeight"
-        android:layout_height="match_parent"
-        android:layout_alignParentEnd="true">
+        android:layout_width="match_parent"
+        android:layout_height="match_parent" >
 
-        <android.support.v17.leanback.widget.NonOverlappingView
-            android:id="@+id/action_fragment_background"
-            android:transitionName="action_fragment_background"
-            android:orientation="horizontal"
-            android:outlineProvider="paddedBounds"
-            android:layout_width="match_parent"
+        <android.support.v17.leanback.widget.NonOverlappingFrameLayout
+            android:id="@+id/content_fragment"
+            android:layout_toStartOf="@+id/action_fragment"
+            android:layout_width="0dp"
+            android:layout_weight="1"
             android:layout_height="match_parent"
-            android:background="?attr/guidedActionsBackground"
-            android:elevation="?attr/guidedActionsElevation" />
+            android:layout_alignParentStart="true" />
 
-        <android.support.v17.leanback.widget.NonOverlappingLinearLayout
-            android:id="@+id/action_fragment"
-            android:transitionName="action_fragment"
+        <android.support.v17.leanback.widget.NonOverlappingFrameLayout
+            android:id="@+id/action_fragment_root"
+            android:transitionName="action_fragment_root"
             android:transitionGroup="false"
             android:orientation="horizontal"
-            android:layout_width="match_parent"
+            android:clipToPadding="false"
+            android:clipChildren="false"
+            android:paddingStart="@dimen/lb_guidedactions_section_shadow_width"
+            android:layout_width="0dp"
+            android:layout_weight="?attr/guidedActionContentWidthWeight"
             android:layout_height="match_parent"
-            android:elevation="@dimen/lb_guidedactions_elevation" />
-    </android.support.v17.leanback.widget.NonOverlappingFrameLayout>
+            android:layout_alignParentEnd="true">
 
-</LinearLayout>
\ No newline at end of file
+            <android.support.v17.leanback.widget.NonOverlappingView
+                android:id="@+id/action_fragment_background"
+                android:transitionName="action_fragment_background"
+                android:orientation="horizontal"
+                android:outlineProvider="paddedBounds"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:background="?attr/guidedActionsBackground"
+                android:elevation="?attr/guidedActionsElevation" />
+
+            <android.support.v17.leanback.widget.NonOverlappingLinearLayout
+                android:id="@+id/action_fragment"
+                android:transitionName="action_fragment"
+                android:transitionGroup="false"
+                android:orientation="horizontal"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:elevation="@dimen/lb_guidedactions_elevation" />
+        </android.support.v17.leanback.widget.NonOverlappingFrameLayout>
+
+    </LinearLayout>
+</FrameLayout>
\ No newline at end of file
diff --git a/v17/leanback/res/transition-v21/lb_guidedstep_activity_enter.xml b/v17/leanback/res/transition-v21/lb_guidedstep_activity_enter.xml
index 7c4dfc3..ef14957 100644
--- a/v17/leanback/res/transition-v21/lb_guidedstep_activity_enter.xml
+++ b/v17/leanback/res/transition-v21/lb_guidedstep_activity_enter.xml
@@ -16,6 +16,13 @@
 -->
 
 <transitionSet xmlns:android="http://schemas.android.com/apk/res/android" >
+  <fade
+      android:interpolator="@android:interpolator/fast_out_linear_in"
+      android:duration="350">
+        <targets>
+            <target android:targetId="@id/guidedstep_background" />
+        </targets>
+  </fade>
   <slide
       android:interpolator="@android:interpolator/fast_out_linear_in"
       android:duration="350"
diff --git a/v17/leanback/res/values/themes.xml b/v17/leanback/res/values/themes.xml
index f3e2eee..056ed1f 100644
--- a/v17/leanback/res/values/themes.xml
+++ b/v17/leanback/res/values/themes.xml
@@ -15,7 +15,7 @@
      limitations under the License.
 -->
 
-<resources>
+<resources xmlns:android="http://schemas.android.com/apk/res/android">
 
     <!-- LeanbackBase may be overridden for specific api levels -->
     <style name="Theme.LeanbackBase" parent="android:Theme.Holo.NoActionBar">
@@ -118,7 +118,8 @@
 
         <item name="android:windowEnterTransition">@transition/lb_guidedstep_activity_enter</item>
 
-        <item name="guidedStepBackground">?android:attr/windowBackground</item>
+        <item name="guidedStepBackground">?android:attr/colorBackground</item>
+        <item name="android:windowBackground">@null</item>
 
         <item name="guidedStepImeAppearingAnimation">@animator/lb_guidedstep_slide_up</item>
         <item name="guidedStepImeDisappearingAnimation">@animator/lb_guidedstep_slide_down</item>
diff --git a/v17/leanback/src/android/support/v17/leanback/app/GuidedStepFragment.java b/v17/leanback/src/android/support/v17/leanback/app/GuidedStepFragment.java
index aca6231..cb6859d 100644
--- a/v17/leanback/src/android/support/v17/leanback/app/GuidedStepFragment.java
+++ b/v17/leanback/src/android/support/v17/leanback/app/GuidedStepFragment.java
@@ -74,6 +74,11 @@
  * <li>{@link #add(FragmentManager, GuidedStepFragment)} or {@link #add(FragmentManager,
  * GuidedStepFragment, int)}, to add GuidedStepFragment on top of existing Fragments or
  * replacing existing GuidedStepFragment when moving forward to next step.</li>
+ * <li>{@link #finishGuidedStepFragments()} can either finish the activity or pop all
+ * GuidedStepFragment from stack.
+ * <li>If app chooses not to use the helper function, it is the app's responsibility to call
+ * {@link #setUiStyle(int)} to select fragment transition and remember the stack entry where it
+ * need pops to.
  * </ul>
  * <h3>Theming and Stylists</h3>
  * <p>
@@ -139,15 +144,13 @@
     private static final String TAG_LEAN_BACK_ACTIONS_FRAGMENT = "leanBackGuidedStepFragment";
     private static final String EXTRA_ACTION_SELECTED_INDEX = "selectedIndex";
 
-    private static final String ENTRY_NAME_DEFAULT = "GuidedStepDefault";
+    private static final String ENTRY_NAME_REPLACE = "GuidedStepDefault";
 
     private static final String ENTRY_NAME_ENTRANCE = "GuidedStepEntrance";
 
-    private static final boolean IS_FRAMEWORK_FRAGMENT = true;
-
     /**
      * Fragment argument name for UI style.  The argument value is persisted in fragment state.
-     * The value is initially {@link #UI_STYLE_DEFAULT} and might be changed in one of the three
+     * The value is initially {@link #UI_STYLE_ENTRANCE} and might be changed in one of the three
      * helper functions:
      * <ul>
      * <li>{@link #addAsRoot(Activity, GuidedStepFragment, int)}</li>
@@ -157,7 +160,7 @@
      * <p>
      * Argument value can be either:
      * <ul>
-     * <li>{@link #UI_STYLE_DEFAULT}</li>
+     * <li>{@link #UI_STYLE_REPLACE}</li>
      * <li>{@link #UI_STYLE_ENTRANCE}</li>
      * <li>{@link #UI_STYLE_ACTIVITY_ROOT}</li>
      * </ul>
@@ -165,42 +168,37 @@
     public static final String EXTRA_UI_STYLE = "uiStyle";
 
     /**
-     * Default value for argument {@link #EXTRA_UI_STYLE}.  The default value is assigned
-     * in GuidedStepFragment constructor.  This is the case that we use GuidedStepFragment to
-     * replace another existing GuidedStepFragment when moving forward to next step. Default
-     * behavior of this style is:
+     * This is the case that we use GuidedStepFragment to replace another existing
+     * GuidedStepFragment when moving forward to next step. Default behavior of this style is:
      * <ul>
-     * <li> Enter transition slides in from END(right), exit transition slide out to START(left).
+     * <li>Enter transition slides in from END(right), exit transition same as
+     * {@link #UI_STYLE_ENTRANCE}.
      * </li>
-     * <li> No background, see {@link #onProvideBackgroundFragment()}.</li>
      * </ul>
      */
-    public static final int UI_STYLE_DEFAULT = 0;
+    public static final int UI_STYLE_REPLACE = 0;
 
     /**
-     * One possible value of argument {@link #EXTRA_UI_STYLE}.  This is the case that we show
-     * GuidedStepFragment on top of other content.  The default behavior of this style:
+     * Default value for argument {@link #EXTRA_UI_STYLE}. The default value is assigned in
+     * GuidedStepFragment constructor. This is the case that we show GuidedStepFragment on top of
+     * other content. The default behavior of this style:
      * <ul>
-     * <li>Enter transition slides in from two sides, exit transition is inherited from
-     * {@link #UI_STYLE_DEFAULT}.  Note: Changing exit transition by UI style is not working because
-     * fragment transition asks for exit transition before UI style is restored in Fragment
+     * <li>Enter transition slides in from two sides, exit transition slide out to START(left).
+     * Background will be faded in. Note: Changing exit transition by UI style is not working
+     * because fragment transition asks for exit transition before UI style is restored in Fragment
      * .onCreate().</li>
-     * <li> {@link #onProvideBackgroundFragment()} will create {@link GuidedStepBackgroundFragment}
-     * to covering underneath content. The activity must provide a container to host background
-     * fragment and override {@link #getContainerIdForBackground()}</li>
      * </ul>
      */
     public static final int UI_STYLE_ENTRANCE = 1;
 
     /**
-     * One possible value of argument {@link #EXTRA_UI_STYLE}.  This is the case that we show first
-     * GuidedStepFragment in a separate activity.  The default behavior of this style:
+     * One possible value of argument {@link #EXTRA_UI_STYLE}. This is the case that we show first
+     * GuidedStepFragment in a separate activity. The default behavior of this style:
      * <ul>
-     * <li> Enter transition is assigned null (will rely on activity transition), exit transition is
-     * same as {@link #UI_STYLE_DEFAULT}.  Note: Changing exit transition by UI style is not working
+     * <li>Enter transition is assigned null (will rely on activity transition), exit transition is
+     * same as {@link #UI_STYLE_ENTRANCE}. Note: Changing exit transition by UI style is not working
      * because fragment transition asks for exit transition before UI style is restored in
      * Fragment.onCreate().</li>
-     * <li> No background, see {@link #onProvideBackgroundFragment()}.
      * </ul>
      */
     public static final int UI_STYLE_ACTIVITY_ROOT = 2;
@@ -342,7 +340,7 @@
      * GuidedStepFragments in the stack, and configuring the fragment-to-fragment custom
      * transitions.  A backstack entry is added, so the fragment will be dismissed when BACK key
      * is pressed.
-     * <li>If current fragment on stack is GuidedStepFragment: assign {@link #UI_STYLE_DEFAULT}
+     * <li>If current fragment on stack is GuidedStepFragment: assign {@link #UI_STYLE_REPLACE}
      * <li>If current fragment on stack is not GuidedStepFragment: assign {@link #UI_STYLE_ENTRANCE}
      * <p>
      * Note: currently fragments added using this method must be created programmatically rather
@@ -360,7 +358,7 @@
      * GuidedStepFragments in the stack, and configuring the fragment-to-fragment custom
      * transitions.  A backstack entry is added, so the fragment will be dismissed when BACK key
      * is pressed.
-     * <li>If current fragment on stack is GuidedStepFragment: assign {@link #UI_STYLE_DEFAULT} and
+     * <li>If current fragment on stack is GuidedStepFragment: assign {@link #UI_STYLE_REPLACE} and
      * {@link #onAddSharedElementTransition(FragmentTransaction, GuidedStepFragment)} will be called
      * to perform shared element transition between GuidedStepFragments.
      * <li>If current fragment on stack is not GuidedStepFragment: assign {@link #UI_STYLE_ENTRANCE}
@@ -375,32 +373,24 @@
     public static int add(FragmentManager fragmentManager, GuidedStepFragment fragment, int id) {
         GuidedStepFragment current = getCurrentGuidedStepFragment(fragmentManager);
         boolean inGuidedStep = current != null;
-        if (IS_FRAMEWORK_FRAGMENT && Build.VERSION.SDK_INT >= 21 && Build.VERSION.SDK_INT < 23
-                && !inGuidedStep && fragment.getContainerIdForBackground() != View.NO_ID) {
-            // workaround b/22631964 for framework fragment
-            fragmentManager.beginTransaction()
-                .replace(id, new DummyFragment(), TAG_LEAN_BACK_ACTIONS_FRAGMENT)
-                .replace(fragment.getContainerIdForBackground(), new DummyFragment())
-                .commit();
-        }
         FragmentTransaction ft = fragmentManager.beginTransaction();
 
-        fragment.setUiStyle(inGuidedStep ? UI_STYLE_DEFAULT : UI_STYLE_ENTRANCE);
+        fragment.setUiStyle(inGuidedStep ? UI_STYLE_REPLACE : UI_STYLE_ENTRANCE);
         ft.addToBackStack(fragment.generateStackEntryName());
         if (current != null) {
             fragment.onAddSharedElementTransition(ft, current);
         }
-        initialBackground(fragment, id, ft);
         return ft.replace(id, fragment, TAG_LEAN_BACK_ACTIONS_FRAGMENT).commit();
     }
 
     /**
-     * Called when this fragment is added to FragmentTransaction with {@link #UI_STYLE_DEFAULT} (aka
-     * when the GuidedStepFragment replacing an existing GuidedStepFragment).
-     * Default implementation establishes connections between background views to morph background
-     * bounds change from disappearing GuidedStepFragment into this GuidedStepFragment.  The default
+     * Called when this fragment is added to FragmentTransaction with {@link #UI_STYLE_REPLACE} (aka
+     * when the GuidedStepFragment replacing an existing GuidedStepFragment). Default implementation
+     * establishes connections between action background views to morph action background bounds
+     * change from disappearing GuidedStepFragment into this GuidedStepFragment. The default
      * implementation heavily relies on {@link GuidedActionsStylist}'s layout, app may override this
      * method when modifying the default layout of {@link GuidedActionsStylist}.
+     *
      * @see GuidedActionsStylist
      * @see #onProvideFragmentTransitions()
      * @param ft The FragmentTransaction to add shared element.
@@ -442,7 +432,7 @@
     /**
      * Generates BackStackEntry name for GuidedStepFragment class or empty String if no entry is
      * associated.  Note {@link #UI_STYLE_ACTIVITY_ROOT} is not allowed and returns empty String.
-     * @param uiStyle {@link #UI_STYLE_DEFAULT} or {@link #UI_STYLE_ENTRANCE}
+     * @param uiStyle {@link #UI_STYLE_REPLACE} or {@link #UI_STYLE_ENTRANCE}
      * @return BackStackEntry name for the GuidedStepFragment or empty String if no entry is
      * associated.
      */
@@ -451,8 +441,8 @@
             return "";
         }
         switch (uiStyle) {
-        case UI_STYLE_DEFAULT:
-            return ENTRY_NAME_DEFAULT + guidedStepFragmentClass.getName();
+        case UI_STYLE_REPLACE:
+            return ENTRY_NAME_REPLACE + guidedStepFragmentClass.getName();
         case UI_STYLE_ENTRANCE:
             return ENTRY_NAME_ENTRANCE + guidedStepFragmentClass.getName();
         case UI_STYLE_ACTIVITY_ROOT:
@@ -473,14 +463,14 @@
     }
 
     /**
-     * Returns true if the backstack represents GuidedStepFragment with {@link #UI_STYLE_DEFAULT};
+     * Returns true if the backstack represents GuidedStepFragment with {@link #UI_STYLE_REPLACE};
      * false otherwise.
      * @param backStackEntryName Name of BackStackEntry.
-     * @return True if the backstack represents GuidedStepFragment with {@link #UI_STYLE_DEFAULT};
+     * @return True if the backstack represents GuidedStepFragment with {@link #UI_STYLE_REPLACE};
      * false otherwise.
      */
     public static boolean isUiStyleDefault(String backStackEntryName) {
-        return backStackEntryName != null && backStackEntryName.startsWith(ENTRY_NAME_DEFAULT);
+        return backStackEntryName != null && backStackEntryName.startsWith(ENTRY_NAME_REPLACE);
     }
 
     /**
@@ -489,8 +479,8 @@
      * @return Class name of GuidedStepFragment.
      */
     public static String getGuidedStepFragmentClassName(String backStackEntryName) {
-        if (backStackEntryName.startsWith(ENTRY_NAME_DEFAULT)) {
-            return backStackEntryName.substring(ENTRY_NAME_DEFAULT.length());
+        if (backStackEntryName.startsWith(ENTRY_NAME_REPLACE)) {
+            return backStackEntryName.substring(ENTRY_NAME_REPLACE.length());
         } else if (backStackEntryName.startsWith(ENTRY_NAME_ENTRANCE)) {
             return backStackEntryName.substring(ENTRY_NAME_ENTRANCE.length());
         } else {
@@ -517,19 +507,9 @@
         FragmentManager fragmentManager = activity.getFragmentManager();
         FragmentTransaction ft = fragmentManager.beginTransaction();
         fragment.setUiStyle(UI_STYLE_ACTIVITY_ROOT);
-        initialBackground(fragment, id, ft);
         return ft.replace(id, fragment, TAG_LEAN_BACK_ACTIONS_FRAGMENT).commit();
     }
 
-    static void initialBackground(GuidedStepFragment fragment, int id, FragmentTransaction ft) {
-        if (fragment.getContainerIdForBackground() != View.NO_ID) {
-            Fragment backgroundFragment = fragment.onProvideBackgroundFragment();
-            if (backgroundFragment != null) {
-                ft.replace(fragment.getContainerIdForBackground(), backgroundFragment);
-            }
-        }
-    }
-
     /**
      * Returns the current GuidedStepFragment on the fragment transaction stack.
      * @return The current GuidedStepFragment, if any, on the fragment transaction stack.
@@ -543,20 +523,6 @@
     }
 
     /**
-     * @hide
-     */
-    public static class DummyFragment extends Fragment {
-
-        @Override
-        public View onCreateView(LayoutInflater inflater, ViewGroup container,
-                Bundle savedInstanceState) {
-            final View v = new View(inflater.getContext());
-            v.setVisibility(View.GONE);
-            return v;
-        }
-    }
-
-    /**
      * Returns the GuidanceStylist that displays guidance information for the user.
      * @return The GuidanceStylist for this fragment.
      */
@@ -754,12 +720,12 @@
      * Called by Constructor to provide fragment transitions.  The default implementation assigns
      * transitions based on {@link #getUiStyle()}:
      * <ul>
-     * <li> {@link #UI_STYLE_DEFAULT} Slide from/to end(right) for enter transition, slide from/to
+     * <li> {@link #UI_STYLE_REPLACE} Slide from/to end(right) for enter transition, slide from/to
      * start(left) for exit transition, shared element enter transition is set to ChangeBounds.
      * <li> {@link #UI_STYLE_ENTRANCE} Enter transition is set to slide from both sides, exit
-     * transition is same as {@link #UI_STYLE_DEFAULT}, no shared element enter transition.
+     * transition is same as {@link #UI_STYLE_REPLACE}, no shared element enter transition.
      * <li> {@link #UI_STYLE_ACTIVITY_ROOT} Enter transition is set to null and app should rely on
-     * activity transition, exit transition is same as {@link #UI_STYLE_DEFAULT}, no shared element
+     * activity transition, exit transition is same as {@link #UI_STYLE_REPLACE}, no shared element
      * enter transition.
      * </ul>
      * <p>
@@ -774,7 +740,8 @@
      */
     protected void onProvideFragmentTransitions() {
         if (Build.VERSION.SDK_INT >= 21) {
-            if (getUiStyle() == UI_STYLE_DEFAULT) {
+            final int uiStyle = getUiStyle();
+            if (uiStyle == UI_STYLE_REPLACE) {
                 Object enterTransition = TransitionHelper.createFadeAndShortSlide(Gravity.END);
                 TransitionHelper.exclude(enterTransition, R.id.action_fragment_background, true);
                 TransitionHelper.exclude(enterTransition, R.id.guided_button_actions_background,
@@ -782,7 +749,32 @@
                 TransitionHelper.exclude(enterTransition, R.id.guided_button_actions_background2,
                         true);
                 TransitionHelper.exclude(enterTransition, R.id.guidedactions_selector, true);
+                TransitionHelper.exclude(enterTransition, R.id.guidedstep_background, true);
                 TransitionHelper.setEnterTransition(this, enterTransition);
+
+                // exit transition is unchanged, same as default UI_STYLE_ENTRANCE
+
+                Object changeBounds = TransitionHelper.createChangeBounds(false);
+                TransitionHelper.setSharedElementEnterTransition(this, changeBounds);
+            } else if (uiStyle == UI_STYLE_ENTRANCE) {
+                Object fade = TransitionHelper.createFadeTransition(TransitionHelper.FADE_IN |
+                        TransitionHelper.FADE_OUT);
+                TransitionHelper.include(fade, R.id.guidedstep_background);
+                Object slide = TransitionHelper.createFadeAndShortSlide(Gravity.END |
+                        Gravity.START);
+                TransitionHelper.include(slide, R.id.content_fragment);
+                TransitionHelper.include(slide, R.id.action_fragment_background);
+                TransitionHelper.include(slide, R.id.guided_button_actions_background);
+                TransitionHelper.include(slide, R.id.guidedactions_selector);
+                TransitionHelper.include(slide, R.id.guidedactions_list);
+                TransitionHelper.include(slide, R.id.guided_button_actions_background2);
+                TransitionHelper.include(slide, R.id.guidedactions_selector2);
+                TransitionHelper.include(slide, R.id.guidedactions_list2);
+                Object enterTransition = TransitionHelper.createTransitionSet(false);
+                TransitionHelper.addTransition(enterTransition, fade);
+                TransitionHelper.addTransition(enterTransition, slide);
+                TransitionHelper.setEnterTransition(this, enterTransition);
+
                 Object exitTransition = TransitionHelper.createFadeAndShortSlide(Gravity.START);
                 TransitionHelper.exclude(exitTransition, R.id.action_fragment_background, true);
                 TransitionHelper.exclude(exitTransition, R.id.guided_button_actions_background,
@@ -791,118 +783,47 @@
                 TransitionHelper.exclude(exitTransition, R.id.guided_button_actions_background2,
                         true);
                 TransitionHelper.exclude(exitTransition, R.id.guidedactions_selector2, true);
+                TransitionHelper.exclude(exitTransition, R.id.guidedstep_background, true);
                 TransitionHelper.setExitTransition(this, exitTransition);
-
-                Object changeBounds = TransitionHelper.createChangeBounds(false);
-                TransitionHelper.setSharedElementEnterTransition(this, changeBounds);
-            } else if (getUiStyle() == UI_STYLE_ENTRANCE) {
-                Object enterTransition = TransitionHelper.createFadeAndShortSlide(Gravity.END |
-                        Gravity.START);
-                TransitionHelper.include(enterTransition, R.id.content_fragment);
-                TransitionHelper.include(enterTransition, R.id.action_fragment_background);
-                TransitionHelper.include(enterTransition, R.id.guided_button_actions_background);
-                TransitionHelper.include(enterTransition, R.id.guidedactions_selector);
-                TransitionHelper.include(enterTransition, R.id.guidedactions_list);
-                TransitionHelper.include(enterTransition, R.id.guided_button_actions_background2);
-                TransitionHelper.include(enterTransition, R.id.guidedactions_selector2);
-                TransitionHelper.include(enterTransition, R.id.guidedactions_list2);
-                TransitionHelper.setEnterTransition(this, enterTransition);
-                // exit transition is unchanged, same as UI_STYLE_DEFAULT
                 // No shared element transition
                 TransitionHelper.setSharedElementEnterTransition(this, null);
-            } else if (getUiStyle() == UI_STYLE_ACTIVITY_ROOT) {
+            } else if (uiStyle == UI_STYLE_ACTIVITY_ROOT) {
                 // for Activity root, we dont need enter transition, use activity transition
                 TransitionHelper.setEnterTransition(this, null);
-                // exit transition is unchanged, same as UI_STYLE_DEFAULT
+                // exit transition is unchanged, same as UI_STYLE_ENTRANCE
                 // No shared element transition
                 TransitionHelper.setSharedElementEnterTransition(this, null);
+            } else {
+                return;
             }
         }
     }
 
     /**
-     * Default implementation of background for covering content below GuidedStepFragment.
-     * It uses current theme attribute guidedStepBackground which by default is read from
-     * android:windowBackground.
+     * Called by onCreateView to inflate background view.  Default implementation loads view
+     * from {@link R.layout#lb_guidedstep_background} which holds a reference to
+     * guidedStepBackground.
+     * @param inflater LayoutInflater to load background view.
+     * @param container Parent view of background view.
+     * @param savedInstanceState
+     * @return Created background view or null if no background.
      */
-    public static class GuidedStepBackgroundFragment extends Fragment {
-        public GuidedStepBackgroundFragment() {
-            onProvideFragmentTransitions();
-        }
-
-        /**
-         * Sets fragment transitions for GuidedStepBackgroundFragment.  Can be overridden.
-         */
-        protected void onProvideFragmentTransitions() {
-            if (Build.VERSION.SDK_INT >= 21) {
-                Object enterTransition = TransitionHelper.createFadeTransition(
-                        TransitionHelper.FADE_IN|TransitionHelper.FADE_OUT);
-                TransitionHelper.setEnterTransition(this, enterTransition);
-            }
-        }
-
-        @Override
-        public View onCreateView(LayoutInflater inflater, ViewGroup container,
-                Bundle savedInstanceState) {
-            Activity activity = getActivity();
-            Context themedContext = null;
-            if (!isGuidedStepTheme(activity)) {
-                // Look up the guidedStepTheme in the activity's currently specified theme.  If it
-                // exists, replace the theme with its value.
-                int resId = R.attr.guidedStepTheme;
-                TypedValue typedValue = new TypedValue();
-                boolean found = activity.getTheme().resolveAttribute(resId, typedValue, true);
-                if (DEBUG) Log.v(TAG, "Found guided step theme reference? " + found);
-                if (found) {
-                    ContextThemeWrapper themeWrapper =
-                            new ContextThemeWrapper(activity, typedValue.resourceId);
-                    if (isGuidedStepTheme(themeWrapper)) {
-                        themedContext = themeWrapper;
-                    }
-                }
-                if (!found) {
-                    Log.e(TAG, "GuidedStepFragment does not have an appropriate theme set.");
-                }
-            }
-
-            if (themedContext != null) {
-                inflater = inflater.cloneInContext(themedContext);
-            }
-
-            return inflater.inflate(R.layout.lb_guidedstep_background, container, false);
-        }
+    public View onCreateBackgroundView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        return inflater.inflate(R.layout.lb_guidedstep_background, container, false);
     }
 
     /**
-     * Creates a background fragment for {@link #UI_STYLE_ENTRANCE}, returns null for other cases.
-     * Subclass may override the default behavior, e.g. provide different backgrounds
-     * for {@link #UI_STYLE_DEFAULT}.  Background fragment will be inserted in {@link
-     * #getContainerIdForBackground()}.
+     * Set UI style to fragment arguments. Default value is {@link #UI_STYLE_ENTRANCE} when fragment
+     * is first initialized. UI style is used to choose different fragment transition animations and
+     * determine if this is the first GuidedStepFragment on backstack. In most cases app does not
+     * directly call this method, app calls helper function
+     * {@link #add(FragmentManager, GuidedStepFragment, int)}. However if the app creates Fragment
+     * transaction and controls backstack by itself, it would need call setUiStyle() to select the
+     * fragment transition to use.
      *
-     * @return fragment that will be inserted below GuidedStepFragment.
-     */
-    protected Fragment onProvideBackgroundFragment() {
-        if (getUiStyle() == UI_STYLE_ENTRANCE) {
-            return new GuidedStepBackgroundFragment();
-        }
-        return null;
-    }
-
-    /**
-     * Returns container id for inserting {@link #onProvideBackgroundFragment()}.  The id should be
-     * different than container id for inserting GuidedStepFragment.
-     * Default value is {@link View#NO_ID}.  Subclass must override to host background fragment.
-     * @return container id for inserting {@link #onProvideBackgroundFragment()}
-     */
-    protected int getContainerIdForBackground() {
-        return View.NO_ID;
-    }
-
-
-    /**
-     * Set UI style to fragment arguments,  UI style cannot be changed after initialization.
-     * @param style {@link #UI_STYLE_ACTIVITY_ROOT} {@link #UI_STYLE_DEFAULT} or
-     * {@link #UI_STYLE_ENTRANCE}.
+     * @param style {@link #UI_STYLE_ACTIVITY_ROOT} {@link #UI_STYLE_REPLACE} or
+     *        {@link #UI_STYLE_ENTRANCE}.
      */
     public void setUiStyle(int style) {
         int oldStyle = getUiStyle();
@@ -923,15 +844,18 @@
     }
 
     /**
-     * Read UI style from fragment arguments.
+     * Read UI style from fragment arguments.  Default value is {@link #UI_STYLE_ENTRANCE} when
+     * fragment is first initialized.  UI style is used to choose different fragment transition
+     * animations and determine if this is the first GuidedStepFragment on backstack.
      *
-     * @return {@link #UI_STYLE_ACTIVITY_ROOT} {@link #UI_STYLE_DEFAULT} or
+     * @return {@link #UI_STYLE_ACTIVITY_ROOT} {@link #UI_STYLE_REPLACE} or
      * {@link #UI_STYLE_ENTRANCE}.
+     * @see #onProvideFragmentTransitions()
      */
     public int getUiStyle() {
         Bundle b = getArguments();
-        if (b == null) return UI_STYLE_DEFAULT;
-        return b.getInt(EXTRA_UI_STYLE, UI_STYLE_DEFAULT);
+        if (b == null) return UI_STYLE_ENTRANCE;
+        return b.getInt(EXTRA_UI_STYLE, UI_STYLE_ENTRANCE);
     }
 
     /**
@@ -982,9 +906,10 @@
         resolveTheme();
         inflater = getThemeInflater(inflater);
 
-        View v = inflater.inflate(R.layout.lb_guidedstep_fragment, container, false);
-        ViewGroup guidanceContainer = (ViewGroup) v.findViewById(R.id.content_fragment);
-        ViewGroup actionContainer = (ViewGroup) v.findViewById(R.id.action_fragment);
+        ViewGroup root = (ViewGroup) inflater.inflate(R.layout.lb_guidedstep_fragment,
+                container, false);
+        ViewGroup guidanceContainer = (ViewGroup) root.findViewById(R.id.content_fragment);
+        ViewGroup actionContainer = (ViewGroup) root.findViewById(R.id.action_fragment);
 
         Guidance guidance = onCreateGuidance(savedInstanceState);
         View guidanceView = mGuidanceStylist.onCreateView(inflater, guidanceContainer, guidance);
@@ -1038,7 +963,7 @@
             TypedValue typedValue = new TypedValue();
             if (ctx.getTheme().resolveAttribute(R.attr.guidedActionContentWidthWeightTwoPanels,
                     typedValue, true)) {
-                View actionsRoot = v.findViewById(R.id.action_fragment_root);
+                View actionsRoot = root.findViewById(R.id.action_fragment_root);
                 float weight = typedValue.getFloat();
                 LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) actionsRoot
                         .getLayoutParams();
@@ -1053,7 +978,11 @@
 
         setSelectedButtonActionPosition(0);
 
-        return v;
+        View backgroundView = onCreateBackgroundView(inflater, root, savedInstanceState);
+        if (backgroundView != null) {
+            root.addView(backgroundView, 0);
+        }
+        return root;
     }
 
     @Override
@@ -1085,6 +1014,8 @@
      * Convenient method to close GuidedStepFragments on top of other content or finish Activity if
      * GuidedStepFragments were started in a separate activity.  Pops all stack entries including
      * {@link #UI_STYLE_ENTRANCE}; if {@link #UI_STYLE_ENTRANCE} is not found, finish the activity.
+     * Note that this method must be paired with {@link #add(FragmentManager, GuidedStepFragment,
+     * int)} which sets up the stack entry name for finding which fragment we need to pop back to.
      */
     public void finishGuidedStepFragments() {
         final FragmentManager fragmentManager = getFragmentManager();
diff --git a/v17/leanback/src/android/support/v17/leanback/app/GuidedStepSupportFragment.java b/v17/leanback/src/android/support/v17/leanback/app/GuidedStepSupportFragment.java
index ca50a37..fae8c50 100644
--- a/v17/leanback/src/android/support/v17/leanback/app/GuidedStepSupportFragment.java
+++ b/v17/leanback/src/android/support/v17/leanback/app/GuidedStepSupportFragment.java
@@ -76,6 +76,11 @@
  * <li>{@link #add(FragmentManager, GuidedStepSupportFragment)} or {@link #add(FragmentManager,
  * GuidedStepSupportFragment, int)}, to add GuidedStepSupportFragment on top of existing Fragments or
  * replacing existing GuidedStepSupportFragment when moving forward to next step.</li>
+ * <li>{@link #finishGuidedStepSupportFragments()} can either finish the activity or pop all
+ * GuidedStepSupportFragment from stack.
+ * <li>If app chooses not to use the helper function, it is the app's responsibility to call
+ * {@link #setUiStyle(int)} to select fragment transition and remember the stack entry where it
+ * need pops to.
  * </ul>
  * <h3>Theming and Stylists</h3>
  * <p>
@@ -141,15 +146,13 @@
     private static final String TAG_LEAN_BACK_ACTIONS_FRAGMENT = "leanBackGuidedStepSupportFragment";
     private static final String EXTRA_ACTION_SELECTED_INDEX = "selectedIndex";
 
-    private static final String ENTRY_NAME_DEFAULT = "GuidedStepDefault";
+    private static final String ENTRY_NAME_REPLACE = "GuidedStepDefault";
 
     private static final String ENTRY_NAME_ENTRANCE = "GuidedStepEntrance";
 
-    private static final boolean IS_FRAMEWORK_FRAGMENT = false;
-
     /**
      * Fragment argument name for UI style.  The argument value is persisted in fragment state.
-     * The value is initially {@link #UI_STYLE_DEFAULT} and might be changed in one of the three
+     * The value is initially {@link #UI_STYLE_ENTRANCE} and might be changed in one of the three
      * helper functions:
      * <ul>
      * <li>{@link #addAsRoot(FragmentActivity, GuidedStepSupportFragment, int)}</li>
@@ -159,7 +162,7 @@
      * <p>
      * Argument value can be either:
      * <ul>
-     * <li>{@link #UI_STYLE_DEFAULT}</li>
+     * <li>{@link #UI_STYLE_REPLACE}</li>
      * <li>{@link #UI_STYLE_ENTRANCE}</li>
      * <li>{@link #UI_STYLE_ACTIVITY_ROOT}</li>
      * </ul>
@@ -167,42 +170,37 @@
     public static final String EXTRA_UI_STYLE = "uiStyle";
 
     /**
-     * Default value for argument {@link #EXTRA_UI_STYLE}.  The default value is assigned
-     * in GuidedStepSupportFragment constructor.  This is the case that we use GuidedStepSupportFragment to
-     * replace another existing GuidedStepSupportFragment when moving forward to next step. Default
-     * behavior of this style is:
+     * This is the case that we use GuidedStepSupportFragment to replace another existing
+     * GuidedStepSupportFragment when moving forward to next step. Default behavior of this style is:
      * <ul>
-     * <li> Enter transition slides in from END(right), exit transition slide out to START(left).
+     * <li>Enter transition slides in from END(right), exit transition same as
+     * {@link #UI_STYLE_ENTRANCE}.
      * </li>
-     * <li> No background, see {@link #onProvideBackgroundSupportFragment()}.</li>
      * </ul>
      */
-    public static final int UI_STYLE_DEFAULT = 0;
+    public static final int UI_STYLE_REPLACE = 0;
 
     /**
-     * One possible value of argument {@link #EXTRA_UI_STYLE}.  This is the case that we show
-     * GuidedStepSupportFragment on top of other content.  The default behavior of this style:
+     * Default value for argument {@link #EXTRA_UI_STYLE}. The default value is assigned in
+     * GuidedStepSupportFragment constructor. This is the case that we show GuidedStepSupportFragment on top of
+     * other content. The default behavior of this style:
      * <ul>
-     * <li>Enter transition slides in from two sides, exit transition is inherited from
-     * {@link #UI_STYLE_DEFAULT}.  Note: Changing exit transition by UI style is not working because
-     * fragment transition asks for exit transition before UI style is restored in Fragment
+     * <li>Enter transition slides in from two sides, exit transition slide out to START(left).
+     * Background will be faded in. Note: Changing exit transition by UI style is not working
+     * because fragment transition asks for exit transition before UI style is restored in Fragment
      * .onCreate().</li>
-     * <li> {@link #onProvideBackgroundSupportFragment()} will create {@link GuidedStepBackgroundSupportFragment}
-     * to covering underneath content. The activity must provide a container to host background
-     * fragment and override {@link #getContainerIdForBackground()}</li>
      * </ul>
      */
     public static final int UI_STYLE_ENTRANCE = 1;
 
     /**
-     * One possible value of argument {@link #EXTRA_UI_STYLE}.  This is the case that we show first
-     * GuidedStepSupportFragment in a separate activity.  The default behavior of this style:
+     * One possible value of argument {@link #EXTRA_UI_STYLE}. This is the case that we show first
+     * GuidedStepSupportFragment in a separate activity. The default behavior of this style:
      * <ul>
-     * <li> Enter transition is assigned null (will rely on activity transition), exit transition is
-     * same as {@link #UI_STYLE_DEFAULT}.  Note: Changing exit transition by UI style is not working
+     * <li>Enter transition is assigned null (will rely on activity transition), exit transition is
+     * same as {@link #UI_STYLE_ENTRANCE}. Note: Changing exit transition by UI style is not working
      * because fragment transition asks for exit transition before UI style is restored in
      * Fragment.onCreate().</li>
-     * <li> No background, see {@link #onProvideBackgroundSupportFragment()}.
      * </ul>
      */
     public static final int UI_STYLE_ACTIVITY_ROOT = 2;
@@ -344,7 +342,7 @@
      * GuidedStepSupportFragments in the stack, and configuring the fragment-to-fragment custom
      * transitions.  A backstack entry is added, so the fragment will be dismissed when BACK key
      * is pressed.
-     * <li>If current fragment on stack is GuidedStepSupportFragment: assign {@link #UI_STYLE_DEFAULT}
+     * <li>If current fragment on stack is GuidedStepSupportFragment: assign {@link #UI_STYLE_REPLACE}
      * <li>If current fragment on stack is not GuidedStepSupportFragment: assign {@link #UI_STYLE_ENTRANCE}
      * <p>
      * Note: currently fragments added using this method must be created programmatically rather
@@ -362,7 +360,7 @@
      * GuidedStepSupportFragments in the stack, and configuring the fragment-to-fragment custom
      * transitions.  A backstack entry is added, so the fragment will be dismissed when BACK key
      * is pressed.
-     * <li>If current fragment on stack is GuidedStepSupportFragment: assign {@link #UI_STYLE_DEFAULT} and
+     * <li>If current fragment on stack is GuidedStepSupportFragment: assign {@link #UI_STYLE_REPLACE} and
      * {@link #onAddSharedElementTransition(FragmentTransaction, GuidedStepSupportFragment)} will be called
      * to perform shared element transition between GuidedStepSupportFragments.
      * <li>If current fragment on stack is not GuidedStepSupportFragment: assign {@link #UI_STYLE_ENTRANCE}
@@ -377,32 +375,24 @@
     public static int add(FragmentManager fragmentManager, GuidedStepSupportFragment fragment, int id) {
         GuidedStepSupportFragment current = getCurrentGuidedStepSupportFragment(fragmentManager);
         boolean inGuidedStep = current != null;
-        if (IS_FRAMEWORK_FRAGMENT && Build.VERSION.SDK_INT >= 21 && Build.VERSION.SDK_INT < 23
-                && !inGuidedStep && fragment.getContainerIdForBackground() != View.NO_ID) {
-            // workaround b/22631964 for framework fragment
-            fragmentManager.beginTransaction()
-                .replace(id, new DummyFragment(), TAG_LEAN_BACK_ACTIONS_FRAGMENT)
-                .replace(fragment.getContainerIdForBackground(), new DummyFragment())
-                .commit();
-        }
         FragmentTransaction ft = fragmentManager.beginTransaction();
 
-        fragment.setUiStyle(inGuidedStep ? UI_STYLE_DEFAULT : UI_STYLE_ENTRANCE);
+        fragment.setUiStyle(inGuidedStep ? UI_STYLE_REPLACE : UI_STYLE_ENTRANCE);
         ft.addToBackStack(fragment.generateStackEntryName());
         if (current != null) {
             fragment.onAddSharedElementTransition(ft, current);
         }
-        initialBackground(fragment, id, ft);
         return ft.replace(id, fragment, TAG_LEAN_BACK_ACTIONS_FRAGMENT).commit();
     }
 
     /**
-     * Called when this fragment is added to FragmentTransaction with {@link #UI_STYLE_DEFAULT} (aka
-     * when the GuidedStepSupportFragment replacing an existing GuidedStepSupportFragment).
-     * Default implementation establishes connections between background views to morph background
-     * bounds change from disappearing GuidedStepSupportFragment into this GuidedStepSupportFragment.  The default
+     * Called when this fragment is added to FragmentTransaction with {@link #UI_STYLE_REPLACE} (aka
+     * when the GuidedStepSupportFragment replacing an existing GuidedStepSupportFragment). Default implementation
+     * establishes connections between action background views to morph action background bounds
+     * change from disappearing GuidedStepSupportFragment into this GuidedStepSupportFragment. The default
      * implementation heavily relies on {@link GuidedActionsStylist}'s layout, app may override this
      * method when modifying the default layout of {@link GuidedActionsStylist}.
+     *
      * @see GuidedActionsStylist
      * @see #onProvideFragmentTransitions()
      * @param ft The FragmentTransaction to add shared element.
@@ -444,7 +434,7 @@
     /**
      * Generates BackStackEntry name for GuidedStepSupportFragment class or empty String if no entry is
      * associated.  Note {@link #UI_STYLE_ACTIVITY_ROOT} is not allowed and returns empty String.
-     * @param uiStyle {@link #UI_STYLE_DEFAULT} or {@link #UI_STYLE_ENTRANCE}
+     * @param uiStyle {@link #UI_STYLE_REPLACE} or {@link #UI_STYLE_ENTRANCE}
      * @return BackStackEntry name for the GuidedStepSupportFragment or empty String if no entry is
      * associated.
      */
@@ -453,8 +443,8 @@
             return "";
         }
         switch (uiStyle) {
-        case UI_STYLE_DEFAULT:
-            return ENTRY_NAME_DEFAULT + guidedStepFragmentClass.getName();
+        case UI_STYLE_REPLACE:
+            return ENTRY_NAME_REPLACE + guidedStepFragmentClass.getName();
         case UI_STYLE_ENTRANCE:
             return ENTRY_NAME_ENTRANCE + guidedStepFragmentClass.getName();
         case UI_STYLE_ACTIVITY_ROOT:
@@ -475,14 +465,14 @@
     }
 
     /**
-     * Returns true if the backstack represents GuidedStepSupportFragment with {@link #UI_STYLE_DEFAULT};
+     * Returns true if the backstack represents GuidedStepSupportFragment with {@link #UI_STYLE_REPLACE};
      * false otherwise.
      * @param backStackEntryName Name of BackStackEntry.
-     * @return True if the backstack represents GuidedStepSupportFragment with {@link #UI_STYLE_DEFAULT};
+     * @return True if the backstack represents GuidedStepSupportFragment with {@link #UI_STYLE_REPLACE};
      * false otherwise.
      */
     public static boolean isUiStyleDefault(String backStackEntryName) {
-        return backStackEntryName != null && backStackEntryName.startsWith(ENTRY_NAME_DEFAULT);
+        return backStackEntryName != null && backStackEntryName.startsWith(ENTRY_NAME_REPLACE);
     }
 
     /**
@@ -491,8 +481,8 @@
      * @return Class name of GuidedStepSupportFragment.
      */
     public static String getGuidedStepSupportFragmentClassName(String backStackEntryName) {
-        if (backStackEntryName.startsWith(ENTRY_NAME_DEFAULT)) {
-            return backStackEntryName.substring(ENTRY_NAME_DEFAULT.length());
+        if (backStackEntryName.startsWith(ENTRY_NAME_REPLACE)) {
+            return backStackEntryName.substring(ENTRY_NAME_REPLACE.length());
         } else if (backStackEntryName.startsWith(ENTRY_NAME_ENTRANCE)) {
             return backStackEntryName.substring(ENTRY_NAME_ENTRANCE.length());
         } else {
@@ -519,19 +509,9 @@
         FragmentManager fragmentManager = activity.getSupportFragmentManager();
         FragmentTransaction ft = fragmentManager.beginTransaction();
         fragment.setUiStyle(UI_STYLE_ACTIVITY_ROOT);
-        initialBackground(fragment, id, ft);
         return ft.replace(id, fragment, TAG_LEAN_BACK_ACTIONS_FRAGMENT).commit();
     }
 
-    static void initialBackground(GuidedStepSupportFragment fragment, int id, FragmentTransaction ft) {
-        if (fragment.getContainerIdForBackground() != View.NO_ID) {
-            Fragment backgroundFragment = fragment.onProvideBackgroundSupportFragment();
-            if (backgroundFragment != null) {
-                ft.replace(fragment.getContainerIdForBackground(), backgroundFragment);
-            }
-        }
-    }
-
     /**
      * Returns the current GuidedStepSupportFragment on the fragment transaction stack.
      * @return The current GuidedStepSupportFragment, if any, on the fragment transaction stack.
@@ -545,20 +525,6 @@
     }
 
     /**
-     * @hide
-     */
-    public static class DummyFragment extends Fragment {
-
-        @Override
-        public View onCreateView(LayoutInflater inflater, ViewGroup container,
-                Bundle savedInstanceState) {
-            final View v = new View(inflater.getContext());
-            v.setVisibility(View.GONE);
-            return v;
-        }
-    }
-
-    /**
      * Returns the GuidanceStylist that displays guidance information for the user.
      * @return The GuidanceStylist for this fragment.
      */
@@ -756,12 +722,12 @@
      * Called by Constructor to provide fragment transitions.  The default implementation assigns
      * transitions based on {@link #getUiStyle()}:
      * <ul>
-     * <li> {@link #UI_STYLE_DEFAULT} Slide from/to end(right) for enter transition, slide from/to
+     * <li> {@link #UI_STYLE_REPLACE} Slide from/to end(right) for enter transition, slide from/to
      * start(left) for exit transition, shared element enter transition is set to ChangeBounds.
      * <li> {@link #UI_STYLE_ENTRANCE} Enter transition is set to slide from both sides, exit
-     * transition is same as {@link #UI_STYLE_DEFAULT}, no shared element enter transition.
+     * transition is same as {@link #UI_STYLE_REPLACE}, no shared element enter transition.
      * <li> {@link #UI_STYLE_ACTIVITY_ROOT} Enter transition is set to null and app should rely on
-     * activity transition, exit transition is same as {@link #UI_STYLE_DEFAULT}, no shared element
+     * activity transition, exit transition is same as {@link #UI_STYLE_REPLACE}, no shared element
      * enter transition.
      * </ul>
      * <p>
@@ -776,7 +742,8 @@
      */
     protected void onProvideFragmentTransitions() {
         if (Build.VERSION.SDK_INT >= 21) {
-            if (getUiStyle() == UI_STYLE_DEFAULT) {
+            final int uiStyle = getUiStyle();
+            if (uiStyle == UI_STYLE_REPLACE) {
                 Object enterTransition = TransitionHelper.createFadeAndShortSlide(Gravity.END);
                 TransitionHelper.exclude(enterTransition, R.id.action_fragment_background, true);
                 TransitionHelper.exclude(enterTransition, R.id.guided_button_actions_background,
@@ -784,7 +751,32 @@
                 TransitionHelper.exclude(enterTransition, R.id.guided_button_actions_background2,
                         true);
                 TransitionHelper.exclude(enterTransition, R.id.guidedactions_selector, true);
+                TransitionHelper.exclude(enterTransition, R.id.guidedstep_background, true);
                 TransitionHelper.setEnterTransition(this, enterTransition);
+
+                // exit transition is unchanged, same as default UI_STYLE_ENTRANCE
+
+                Object changeBounds = TransitionHelper.createChangeBounds(false);
+                TransitionHelper.setSharedElementEnterTransition(this, changeBounds);
+            } else if (uiStyle == UI_STYLE_ENTRANCE) {
+                Object fade = TransitionHelper.createFadeTransition(TransitionHelper.FADE_IN |
+                        TransitionHelper.FADE_OUT);
+                TransitionHelper.include(fade, R.id.guidedstep_background);
+                Object slide = TransitionHelper.createFadeAndShortSlide(Gravity.END |
+                        Gravity.START);
+                TransitionHelper.include(slide, R.id.content_fragment);
+                TransitionHelper.include(slide, R.id.action_fragment_background);
+                TransitionHelper.include(slide, R.id.guided_button_actions_background);
+                TransitionHelper.include(slide, R.id.guidedactions_selector);
+                TransitionHelper.include(slide, R.id.guidedactions_list);
+                TransitionHelper.include(slide, R.id.guided_button_actions_background2);
+                TransitionHelper.include(slide, R.id.guidedactions_selector2);
+                TransitionHelper.include(slide, R.id.guidedactions_list2);
+                Object enterTransition = TransitionHelper.createTransitionSet(false);
+                TransitionHelper.addTransition(enterTransition, fade);
+                TransitionHelper.addTransition(enterTransition, slide);
+                TransitionHelper.setEnterTransition(this, enterTransition);
+
                 Object exitTransition = TransitionHelper.createFadeAndShortSlide(Gravity.START);
                 TransitionHelper.exclude(exitTransition, R.id.action_fragment_background, true);
                 TransitionHelper.exclude(exitTransition, R.id.guided_button_actions_background,
@@ -793,118 +785,47 @@
                 TransitionHelper.exclude(exitTransition, R.id.guided_button_actions_background2,
                         true);
                 TransitionHelper.exclude(exitTransition, R.id.guidedactions_selector2, true);
+                TransitionHelper.exclude(exitTransition, R.id.guidedstep_background, true);
                 TransitionHelper.setExitTransition(this, exitTransition);
-
-                Object changeBounds = TransitionHelper.createChangeBounds(false);
-                TransitionHelper.setSharedElementEnterTransition(this, changeBounds);
-            } else if (getUiStyle() == UI_STYLE_ENTRANCE) {
-                Object enterTransition = TransitionHelper.createFadeAndShortSlide(Gravity.END |
-                        Gravity.START);
-                TransitionHelper.include(enterTransition, R.id.content_fragment);
-                TransitionHelper.include(enterTransition, R.id.action_fragment_background);
-                TransitionHelper.include(enterTransition, R.id.guided_button_actions_background);
-                TransitionHelper.include(enterTransition, R.id.guidedactions_selector);
-                TransitionHelper.include(enterTransition, R.id.guidedactions_list);
-                TransitionHelper.include(enterTransition, R.id.guided_button_actions_background2);
-                TransitionHelper.include(enterTransition, R.id.guidedactions_selector2);
-                TransitionHelper.include(enterTransition, R.id.guidedactions_list2);
-                TransitionHelper.setEnterTransition(this, enterTransition);
-                // exit transition is unchanged, same as UI_STYLE_DEFAULT
                 // No shared element transition
                 TransitionHelper.setSharedElementEnterTransition(this, null);
-            } else if (getUiStyle() == UI_STYLE_ACTIVITY_ROOT) {
+            } else if (uiStyle == UI_STYLE_ACTIVITY_ROOT) {
                 // for Activity root, we dont need enter transition, use activity transition
                 TransitionHelper.setEnterTransition(this, null);
-                // exit transition is unchanged, same as UI_STYLE_DEFAULT
+                // exit transition is unchanged, same as UI_STYLE_ENTRANCE
                 // No shared element transition
                 TransitionHelper.setSharedElementEnterTransition(this, null);
+            } else {
+                return;
             }
         }
     }
 
     /**
-     * Default implementation of background for covering content below GuidedStepSupportFragment.
-     * It uses current theme attribute guidedStepBackground which by default is read from
-     * android:windowBackground.
+     * Called by onCreateView to inflate background view.  Default implementation loads view
+     * from {@link R.layout#lb_guidedstep_background} which holds a reference to
+     * guidedStepBackground.
+     * @param inflater LayoutInflater to load background view.
+     * @param container Parent view of background view.
+     * @param savedInstanceState
+     * @return Created background view or null if no background.
      */
-    public static class GuidedStepBackgroundSupportFragment extends Fragment {
-        public GuidedStepBackgroundSupportFragment() {
-            onProvideFragmentTransitions();
-        }
-
-        /**
-         * Sets fragment transitions for GuidedStepBackgroundSupportFragment.  Can be overridden.
-         */
-        protected void onProvideFragmentTransitions() {
-            if (Build.VERSION.SDK_INT >= 21) {
-                Object enterTransition = TransitionHelper.createFadeTransition(
-                        TransitionHelper.FADE_IN|TransitionHelper.FADE_OUT);
-                TransitionHelper.setEnterTransition(this, enterTransition);
-            }
-        }
-
-        @Override
-        public View onCreateView(LayoutInflater inflater, ViewGroup container,
-                Bundle savedInstanceState) {
-            FragmentActivity activity = getActivity();
-            Context themedContext = null;
-            if (!isGuidedStepTheme(activity)) {
-                // Look up the guidedStepTheme in the activity's currently specified theme.  If it
-                // exists, replace the theme with its value.
-                int resId = R.attr.guidedStepTheme;
-                TypedValue typedValue = new TypedValue();
-                boolean found = activity.getTheme().resolveAttribute(resId, typedValue, true);
-                if (DEBUG) Log.v(TAG, "Found guided step theme reference? " + found);
-                if (found) {
-                    ContextThemeWrapper themeWrapper =
-                            new ContextThemeWrapper(activity, typedValue.resourceId);
-                    if (isGuidedStepTheme(themeWrapper)) {
-                        themedContext = themeWrapper;
-                    }
-                }
-                if (!found) {
-                    Log.e(TAG, "GuidedStepSupportFragment does not have an appropriate theme set.");
-                }
-            }
-
-            if (themedContext != null) {
-                inflater = inflater.cloneInContext(themedContext);
-            }
-
-            return inflater.inflate(R.layout.lb_guidedstep_background, container, false);
-        }
+    public View onCreateBackgroundView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        return inflater.inflate(R.layout.lb_guidedstep_background, container, false);
     }
 
     /**
-     * Creates a background fragment for {@link #UI_STYLE_ENTRANCE}, returns null for other cases.
-     * Subclass may override the default behavior, e.g. provide different backgrounds
-     * for {@link #UI_STYLE_DEFAULT}.  Background fragment will be inserted in {@link
-     * #getContainerIdForBackground()}.
+     * Set UI style to fragment arguments. Default value is {@link #UI_STYLE_ENTRANCE} when fragment
+     * is first initialized. UI style is used to choose different fragment transition animations and
+     * determine if this is the first GuidedStepSupportFragment on backstack. In most cases app does not
+     * directly call this method, app calls helper function
+     * {@link #add(FragmentManager, GuidedStepSupportFragment, int)}. However if the app creates Fragment
+     * transaction and controls backstack by itself, it would need call setUiStyle() to select the
+     * fragment transition to use.
      *
-     * @return fragment that will be inserted below GuidedStepSupportFragment.
-     */
-    protected Fragment onProvideBackgroundSupportFragment() {
-        if (getUiStyle() == UI_STYLE_ENTRANCE) {
-            return new GuidedStepBackgroundSupportFragment();
-        }
-        return null;
-    }
-
-    /**
-     * Returns container id for inserting {@link #onProvideBackgroundSupportFragment()}.  The id should be
-     * different than container id for inserting GuidedStepSupportFragment.
-     * Default value is {@link View#NO_ID}.  Subclass must override to host background fragment.
-     * @return container id for inserting {@link #onProvideBackgroundSupportFragment()}
-     */
-    protected int getContainerIdForBackground() {
-        return View.NO_ID;
-    }
-
-
-    /**
-     * Set UI style to fragment arguments,  UI style cannot be changed after initialization.
-     * @param style {@link #UI_STYLE_ACTIVITY_ROOT} {@link #UI_STYLE_DEFAULT} or
-     * {@link #UI_STYLE_ENTRANCE}.
+     * @param style {@link #UI_STYLE_ACTIVITY_ROOT} {@link #UI_STYLE_REPLACE} or
+     *        {@link #UI_STYLE_ENTRANCE}.
      */
     public void setUiStyle(int style) {
         int oldStyle = getUiStyle();
@@ -925,15 +846,18 @@
     }
 
     /**
-     * Read UI style from fragment arguments.
+     * Read UI style from fragment arguments.  Default value is {@link #UI_STYLE_ENTRANCE} when
+     * fragment is first initialized.  UI style is used to choose different fragment transition
+     * animations and determine if this is the first GuidedStepSupportFragment on backstack.
      *
-     * @return {@link #UI_STYLE_ACTIVITY_ROOT} {@link #UI_STYLE_DEFAULT} or
+     * @return {@link #UI_STYLE_ACTIVITY_ROOT} {@link #UI_STYLE_REPLACE} or
      * {@link #UI_STYLE_ENTRANCE}.
+     * @see #onProvideFragmentTransitions()
      */
     public int getUiStyle() {
         Bundle b = getArguments();
-        if (b == null) return UI_STYLE_DEFAULT;
-        return b.getInt(EXTRA_UI_STYLE, UI_STYLE_DEFAULT);
+        if (b == null) return UI_STYLE_ENTRANCE;
+        return b.getInt(EXTRA_UI_STYLE, UI_STYLE_ENTRANCE);
     }
 
     /**
@@ -984,9 +908,10 @@
         resolveTheme();
         inflater = getThemeInflater(inflater);
 
-        View v = inflater.inflate(R.layout.lb_guidedstep_fragment, container, false);
-        ViewGroup guidanceContainer = (ViewGroup) v.findViewById(R.id.content_fragment);
-        ViewGroup actionContainer = (ViewGroup) v.findViewById(R.id.action_fragment);
+        ViewGroup root = (ViewGroup) inflater.inflate(R.layout.lb_guidedstep_fragment,
+                container, false);
+        ViewGroup guidanceContainer = (ViewGroup) root.findViewById(R.id.content_fragment);
+        ViewGroup actionContainer = (ViewGroup) root.findViewById(R.id.action_fragment);
 
         Guidance guidance = onCreateGuidance(savedInstanceState);
         View guidanceView = mGuidanceStylist.onCreateView(inflater, guidanceContainer, guidance);
@@ -1040,7 +965,7 @@
             TypedValue typedValue = new TypedValue();
             if (ctx.getTheme().resolveAttribute(R.attr.guidedActionContentWidthWeightTwoPanels,
                     typedValue, true)) {
-                View actionsRoot = v.findViewById(R.id.action_fragment_root);
+                View actionsRoot = root.findViewById(R.id.action_fragment_root);
                 float weight = typedValue.getFloat();
                 LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) actionsRoot
                         .getLayoutParams();
@@ -1055,7 +980,11 @@
 
         setSelectedButtonActionPosition(0);
 
-        return v;
+        View backgroundView = onCreateBackgroundView(inflater, root, savedInstanceState);
+        if (backgroundView != null) {
+            root.addView(backgroundView, 0);
+        }
+        return root;
     }
 
     @Override
@@ -1087,6 +1016,8 @@
      * Convenient method to close GuidedStepSupportFragments on top of other content or finish Activity if
      * GuidedStepSupportFragments were started in a separate activity.  Pops all stack entries including
      * {@link #UI_STYLE_ENTRANCE}; if {@link #UI_STYLE_ENTRANCE} is not found, finish the activity.
+     * Note that this method must be paired with {@link #add(FragmentManager, GuidedStepSupportFragment,
+     * int)} which sets up the stack entry name for finding which fragment we need to pop back to.
      */
     public void finishGuidedStepSupportFragments() {
         final FragmentManager fragmentManager = getFragmentManager();