package com.zero.star.tabnyan;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class TabNyanRootFragment extends Fragment {

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		return inflater.inflate(R.layout.fragment_tabnyan_root, container, false);
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);

        initFragment();
	}

	/**
	 * Pop fragment backstack.
	 * @return return true if exists backstack
	 */
	public boolean popBackStack() {
		return getChildFragmentManager().popBackStackImmediate();
	}

	/**
	 * Initialize Fragment.
	 */
	private void initFragment() {

		Bundle args = getArguments();
		String rootClass = args.getString(TabNyanActivity.ROOT_FRAGMENT_ARGS);

		FragmentManager fragmentManager = getChildFragmentManager();
        if (fragmentManager.findFragmentById(R.id.fragment) != null) {
            return;
        }

        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

        Fragment fragment = Fragment.instantiate(getActivity(), rootClass, args);
        fragmentTransaction.replace(R.id.fragment, fragment);

        fragmentTransaction.commit();
	}

	/**
	 * Return Fragment in displayed
	 * @return Fragment
	 */
	Fragment getCurrentFragment() {
	    FragmentManager fragmentManager = getChildFragmentManager();
	    return fragmentManager.findFragmentById(R.id.fragment);
	}

}

@@ -25,16 +25,47 @@
 bnyan;%0A%0A
+import android.content.Intent;%0A
 import a
@@ -367,17 +367,20 @@
 ment %7B%0A%0A
-%09
+    
 @Overrid
@@ -377,25 +377,28 @@
   @Override%0A
-%09
+    
 public View 
@@ -481,26 +481,32 @@
 nceState) %7B%0A
-%09%09
+        
 return infla
@@ -568,21 +568,27 @@
 false);%0A
-%09%7D%0A%0A%09
+    %7D%0A%0A    
 @Overrid
@@ -589,17 +589,20 @@
 verride%0A
-%09
+    
 public v
@@ -652,18 +652,24 @@
 tate) %7B%0A
-%09%09
+        
 super.on
@@ -730,26 +730,35 @@
 ment();%0A
-%09%7D%0A%0A%09/**%0A%09
+    %7D%0A%0A    /**%0A    
  * Pop f
@@ -776,17 +776,20 @@
 kstack.%0A
-%09
+    
  * @retu
@@ -823,22 +823,28 @@
 ckstack%0A
-%09 */%0A%09
+     */%0A    
 public b
@@ -867,18 +867,24 @@
 ack() %7B%0A
-%09%09
+        
 return g
@@ -933,26 +933,35 @@
 iate();%0A
-%09%7D%0A%0A%09/**%0A%09
+    %7D%0A%0A    /**%0A    
  * Initi
@@ -976,22 +976,28 @@
 agment.%0A
-%09 */%0A%09
+     */%0A    
 private 
@@ -1019,18 +1019,24 @@
 nt() %7B%0A%0A
-%09%09
+        
 Bundle a
@@ -1057,18 +1057,24 @@
 ents();%0A
-%09%09
+        
 String r
@@ -1141,10 +1141,16 @@
 );%0A%0A
-%09%09
+        
 Frag
@@ -1582,18 +1582,27 @@
 ();%0A
-%09%7D%0A%0A%09/**%0A%09
+    %7D%0A%0A    /**%0A    
  * R
@@ -1629,17 +1629,20 @@
 splayed%0A
-%09
+    
  * @retu
@@ -1657,14 +1657,20 @@
 ent%0A
-%09 */%0A%09
+     */%0A    
 Frag
@@ -1697,17 +1697,20 @@
 ent() %7B%0A
-%09
+    
     Frag
@@ -1766,17 +1766,20 @@
 ager();%0A
-%09
+    
     retu
@@ -1834,9 +1834,293 @@
 t);%0A
-%09
+    %7D%0A%0A    @Override%0A    public void onActivityResult(int requestCode, int resultCode, Intent data) %7B%0A        super.onActivityResult(requestCode, resultCode, data);%0A        // Call child fragment method%0A        getCurrentFragment().onActivityResult(requestCode, resultCode, data);%0A    
 %7D%0A%0A%7D

Call child fragment onActivityResult method