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);
     }
   }
 }
  /**
   * Adds the specified GuidedStepSupportFragment as content of Activity; no backstack entry is
   * added so the activity will be dismissed when BACK key is pressed. {@link
   * #UI_STYLE_ACTIVITY_ROOT} is assigned.
   *
   * <p>Note: currently fragments added using this method must be created programmatically rather
   * than via XML.
   *
   * @param activity The Activity to be used to insert GuidedstepFragment.
   * @param fragment The GuidedStepSupportFragment to be inserted into the fragment stack.
   * @param id The id of container to add GuidedStepSupportFragment, can be android.R.id.content.
   * @return The ID returned by the call FragmentTransaction.replace.
   */
  public static int addAsRoot(
      FragmentActivity activity, GuidedStepSupportFragment fragment, int id) {
    // Workaround b/23764120: call getDecorView() to force requestFeature of ActivityTransition.
    activity.getWindow().getDecorView();

    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();
  }
  /**
   * Adds the specified GuidedStepSupportFragment to the fragment stack, replacing any existing
   * 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 not GuidedStepSupportFragment: assign {@link
   *     #UI_STYLE_ENTRANCE}
   *
   *     <p>Note: currently fragments added using this method must be created programmatically
   *     rather than via XML.
   *
   * @param fragmentManager The FragmentManager to be used in the transaction.
   * @param fragment The GuidedStepSupportFragment to be inserted into the fragment stack.
   * @param id The id of container to add GuidedStepSupportFragment, can be android.R.id.content.
   * @return The ID returned by the call FragmentTransaction.replace.
   */
  public static int add(
      FragmentManager fragmentManager, GuidedStepSupportFragment fragment, int id) {
    boolean inGuidedStep = getCurrentGuidedStepSupportFragment(fragmentManager) != 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();

    ft.addToBackStack(null);
    fragment.setUiStyle(inGuidedStep ? UI_STYLE_DEFAULT : UI_STYLE_ENTRANCE);
    initialBackground(fragment, id, ft);
    return ft.replace(id, fragment, TAG_LEAN_BACK_ACTIONS_FRAGMENT).commit();
  }