OSDN Git Service

A little cleanup.
authorDianne Hackborn <hackbod@google.com>
Sun, 9 Sep 2012 00:03:52 +0000 (17:03 -0700)
committerDianne Hackborn <hackbod@google.com>
Sun, 9 Sep 2012 21:41:34 +0000 (14:41 -0700)
Change-Id: Ie33fd1b02011606e67ce08df3cce887c07680c60

api/current.txt
core/java/android/app/Fragment.java
core/java/android/app/FragmentManager.java

index 9d7bb14..f975bf8 100644 (file)
@@ -3353,6 +3353,7 @@ package android.app {
     method public final android.app.FragmentManager getFragmentManager();
     method public final int getId();
     method public android.app.LoaderManager getLoaderManager();
+    method public final android.app.Fragment getParentFragment();
     method public final android.content.res.Resources getResources();
     method public final boolean getRetainInstance();
     method public final java.lang.String getString(int);
index 3ff9df5..c5a382d 100644 (file)
@@ -615,7 +615,7 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
                     + " did not call through to super.onViewStateRestored()");
         }
     }
-    
+
     final void setIndex(int index, Fragment parent) {
         mIndex = index;
         if (parent != null) {
@@ -623,8 +623,8 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
         } else {
             mWho = "android:fragment:" + mIndex;
         }
-   }
-    
+    }
+
     final boolean isInBackStack() {
         return mBackStackNesting > 0;
     }
@@ -832,6 +832,14 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
     }
 
     /**
+     * Returns the parent Fragment containing this Fragment.  If this Fragment
+     * is attached directly to an Activity, returns null.
+     */
+    final public Fragment getParentFragment() {
+        return mParentFragment;
+    }
+
+    /**
      * Return true if the fragment is currently added to its activity.
      */
     final public boolean isAdded() {
@@ -1180,20 +1188,7 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
     public void onCreate(Bundle savedInstanceState) {
         mCalled = true;
     }
-    
-    /**
-     * Called immediately after {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}
-     * has returned, but before any saved state has been restored in to the view.
-     * This gives subclasses a chance to initialize themselves once
-     * they know their view hierarchy has been completely created.  The fragment's
-     * view hierarchy is not however attached to its parent at this point.
-     * @param view The View returned by {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}.
-     * @param savedInstanceState If non-null, this fragment is being re-constructed
-     * from a previous saved state as given here.
-     */
-    public void onViewCreated(View view, Bundle savedInstanceState) {
-    }
-    
+
     /**
      * Called to have the fragment instantiate its user interface view.
      * This is optional, and non-graphical fragments can return null (which
@@ -1217,6 +1212,19 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
             Bundle savedInstanceState) {
         return null;
     }
+
+    /**
+     * Called immediately after {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}
+     * has returned, but before any saved state has been restored in to the view.
+     * This gives subclasses a chance to initialize themselves once
+     * they know their view hierarchy has been completely created.  The fragment's
+     * view hierarchy is not however attached to its parent at this point.
+     * @param view The View returned by {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}.
+     * @param savedInstanceState If non-null, this fragment is being re-constructed
+     * from a previous saved state as given here.
+     */
+    public void onViewCreated(View view, Bundle savedInstanceState) {
+    }
     
     /**
      * Get the root view for the fragment's layout (the one returned by {@link #onCreateView}),
@@ -1237,7 +1245,7 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
      * as this callback tells the fragment when it is fully associated with
      * the new activity instance.  This is called after {@link #onCreateView}
      * and before {@link #onViewStateRestored(Bundle)}.
-     * 
+     *
      * @param savedInstanceState If the fragment is being re-created from
      * a previous saved state, this is the state.
      */
@@ -1252,7 +1260,7 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
      * whether check box widgets are currently checked.  This is called
      * after {@link #onActivityCreated(Bundle)} and before
      * {@link #onStart()}.
-     * 
+     *
      * @param savedInstanceState If the fragment is being re-created from
      * a previous saved state, this is the state.
      */
@@ -1590,10 +1598,6 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
             writer.print(prefix); writer.print("mActivity=");
                     writer.println(mActivity);
         }
-        if (mChildFragmentManager != null) {
-            writer.print(prefix); writer.print("mChildFragmentManager=");
-                    writer.println(mChildFragmentManager);
-        }
         if (mParentFragment != null) {
             writer.print(prefix); writer.print("mParentFragment=");
                     writer.println(mParentFragment);
@@ -1633,7 +1637,7 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
             mLoaderManager.dump(prefix + "  ", fd, writer, args);
         }
         if (mChildFragmentManager != null) {
-            writer.print(prefix); writer.println("Child Fragment Manager:");
+            writer.print(prefix); writer.println("Child " + mChildFragmentManager + ":");
             mChildFragmentManager.dump(prefix + "  ", fd, writer, args);
         }
     }
@@ -1662,6 +1666,9 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
     }
 
     void performCreate(Bundle savedInstanceState) {
+        if (mChildFragmentManager != null) {
+            mChildFragmentManager.noteStateNotSaved();
+        }
         mCalled = false;
         onCreate(savedInstanceState);
         if (!mCalled) {
@@ -1680,7 +1687,18 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
         }
     }
 
+    View performCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        if (mChildFragmentManager != null) {
+            mChildFragmentManager.noteStateNotSaved();
+        }
+        return onCreateView(inflater, container, savedInstanceState);
+    }
+
     void performActivityCreated(Bundle savedInstanceState) {
+        if (mChildFragmentManager != null) {
+            mChildFragmentManager.noteStateNotSaved();
+        }
         mCalled = false;
         onActivityCreated(savedInstanceState);
         if (!mCalled) {
@@ -1713,6 +1731,7 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
 
     void performResume() {
         if (mChildFragmentManager != null) {
+            mChildFragmentManager.noteStateNotSaved();
             mChildFragmentManager.execPendingActions();
         }
         mCalled = false;
index eaaf0d7..7f11437 100644 (file)
@@ -834,7 +834,9 @@ final class FragmentManagerImpl extends FragmentManager {
                         throw new SuperNotCalledException("Fragment " + f
                                 + " did not call through to super.onAttach()");
                     }
-                    mActivity.onAttachFragment(f);
+                    if (f.mParentFragment == null) {
+                        mActivity.onAttachFragment(f);
+                    }
 
                     if (!f.mRetaining) {
                         f.performCreate(f.mSavedFragmentState);
@@ -844,8 +846,8 @@ final class FragmentManagerImpl extends FragmentManager {
                         // For fragments that are part of the content view
                         // layout, we need to instantiate the view immediately
                         // and the inflater will take care of adding it.
-                        f.mView = f.onCreateView(f.getLayoutInflater(f.mSavedFragmentState),
-                                null, f.mSavedFragmentState);
+                        f.mView = f.performCreateView(f.getLayoutInflater(
+                                f.mSavedFragmentState), null, f.mSavedFragmentState);
                         if (f.mView != null) {
                             f.mView.setSaveFromParentEnabled(false);
                             if (f.mHidden) f.mView.setVisibility(View.GONE);
@@ -868,8 +870,8 @@ final class FragmentManagerImpl extends FragmentManager {
                                 }
                             }
                             f.mContainer = container;
-                            f.mView = f.onCreateView(f.getLayoutInflater(f.mSavedFragmentState),
-                                    container, f.mSavedFragmentState);
+                            f.mView = f.performCreateView(f.getLayoutInflater(
+                                    f.mSavedFragmentState), container, f.mSavedFragmentState);
                             if (f.mView != null) {
                                 f.mView.setSaveFromParentEnabled(false);
                                 if (container != null) {
@@ -885,7 +887,7 @@ final class FragmentManagerImpl extends FragmentManager {
                                 f.onViewCreated(f.mView, f.mSavedFragmentState);
                             }
                         }
-                        
+
                         f.performActivityCreated(f.mSavedFragmentState);
                         if (f.mView != null) {
                             f.restoreViewState(f.mSavedFragmentState);
@@ -1824,7 +1826,7 @@ final class FragmentManagerImpl extends FragmentManager {
     public void dispatchDestroyView() {
         moveToState(Fragment.CREATED, false);
     }
-    
+
     public void dispatchDestroy() {
         mDestroyed = true;
         execPendingActions();