Skip to content

Commit 8727a73

Browse files
Dianne HackbornAndroid (Google) Code Review
authored andcommitted
Merge "A little cleanup." into jb-mr1-dev
2 parents 47b2efc + 1b8ecc5 commit 8727a73

File tree

3 files changed

+53
-31
lines changed

3 files changed

+53
-31
lines changed

api/current.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3353,6 +3353,7 @@ package android.app {
33533353
method public final android.app.FragmentManager getFragmentManager();
33543354
method public final int getId();
33553355
method public android.app.LoaderManager getLoaderManager();
3356+
method public final android.app.Fragment getParentFragment();
33563357
method public final android.content.res.Resources getResources();
33573358
method public final boolean getRetainInstance();
33583359
method public final java.lang.String getString(int);

core/java/android/app/Fragment.java

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -615,16 +615,16 @@ final void restoreViewState(Bundle savedInstanceState) {
615615
+ " did not call through to super.onViewStateRestored()");
616616
}
617617
}
618-
618+
619619
final void setIndex(int index, Fragment parent) {
620620
mIndex = index;
621621
if (parent != null) {
622622
mWho = parent.mWho + ":" + mIndex;
623623
} else {
624624
mWho = "android:fragment:" + mIndex;
625625
}
626-
}
627-
626+
}
627+
628628
final boolean isInBackStack() {
629629
return mBackStackNesting > 0;
630630
}
@@ -831,6 +831,14 @@ final public FragmentManager getChildFragmentManager() {
831831
return mChildFragmentManager;
832832
}
833833

834+
/**
835+
* Returns the parent Fragment containing this Fragment. If this Fragment
836+
* is attached directly to an Activity, returns null.
837+
*/
838+
final public Fragment getParentFragment() {
839+
return mParentFragment;
840+
}
841+
834842
/**
835843
* Return true if the fragment is currently added to its activity.
836844
*/
@@ -1180,20 +1188,7 @@ public Animator onCreateAnimator(int transit, boolean enter, int nextAnim) {
11801188
public void onCreate(Bundle savedInstanceState) {
11811189
mCalled = true;
11821190
}
1183-
1184-
/**
1185-
* Called immediately after {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}
1186-
* has returned, but before any saved state has been restored in to the view.
1187-
* This gives subclasses a chance to initialize themselves once
1188-
* they know their view hierarchy has been completely created. The fragment's
1189-
* view hierarchy is not however attached to its parent at this point.
1190-
* @param view The View returned by {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}.
1191-
* @param savedInstanceState If non-null, this fragment is being re-constructed
1192-
* from a previous saved state as given here.
1193-
*/
1194-
public void onViewCreated(View view, Bundle savedInstanceState) {
1195-
}
1196-
1191+
11971192
/**
11981193
* Called to have the fragment instantiate its user interface view.
11991194
* This is optional, and non-graphical fragments can return null (which
@@ -1217,6 +1212,19 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
12171212
Bundle savedInstanceState) {
12181213
return null;
12191214
}
1215+
1216+
/**
1217+
* Called immediately after {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}
1218+
* has returned, but before any saved state has been restored in to the view.
1219+
* This gives subclasses a chance to initialize themselves once
1220+
* they know their view hierarchy has been completely created. The fragment's
1221+
* view hierarchy is not however attached to its parent at this point.
1222+
* @param view The View returned by {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}.
1223+
* @param savedInstanceState If non-null, this fragment is being re-constructed
1224+
* from a previous saved state as given here.
1225+
*/
1226+
public void onViewCreated(View view, Bundle savedInstanceState) {
1227+
}
12201228

12211229
/**
12221230
* Get the root view for the fragment's layout (the one returned by {@link #onCreateView}),
@@ -1237,7 +1245,7 @@ public View getView() {
12371245
* as this callback tells the fragment when it is fully associated with
12381246
* the new activity instance. This is called after {@link #onCreateView}
12391247
* and before {@link #onViewStateRestored(Bundle)}.
1240-
*
1248+
*
12411249
* @param savedInstanceState If the fragment is being re-created from
12421250
* a previous saved state, this is the state.
12431251
*/
@@ -1252,7 +1260,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
12521260
* whether check box widgets are currently checked. This is called
12531261
* after {@link #onActivityCreated(Bundle)} and before
12541262
* {@link #onStart()}.
1255-
*
1263+
*
12561264
* @param savedInstanceState If the fragment is being re-created from
12571265
* a previous saved state, this is the state.
12581266
*/
@@ -1590,10 +1598,6 @@ public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[]
15901598
writer.print(prefix); writer.print("mActivity=");
15911599
writer.println(mActivity);
15921600
}
1593-
if (mChildFragmentManager != null) {
1594-
writer.print(prefix); writer.print("mChildFragmentManager=");
1595-
writer.println(mChildFragmentManager);
1596-
}
15971601
if (mParentFragment != null) {
15981602
writer.print(prefix); writer.print("mParentFragment=");
15991603
writer.println(mParentFragment);
@@ -1633,7 +1637,7 @@ public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[]
16331637
mLoaderManager.dump(prefix + " ", fd, writer, args);
16341638
}
16351639
if (mChildFragmentManager != null) {
1636-
writer.print(prefix); writer.println("Child Fragment Manager:");
1640+
writer.print(prefix); writer.println("Child " + mChildFragmentManager + ":");
16371641
mChildFragmentManager.dump(prefix + " ", fd, writer, args);
16381642
}
16391643
}
@@ -1662,6 +1666,9 @@ public View findViewById(int id) {
16621666
}
16631667

16641668
void performCreate(Bundle savedInstanceState) {
1669+
if (mChildFragmentManager != null) {
1670+
mChildFragmentManager.noteStateNotSaved();
1671+
}
16651672
mCalled = false;
16661673
onCreate(savedInstanceState);
16671674
if (!mCalled) {
@@ -1680,7 +1687,18 @@ void performCreate(Bundle savedInstanceState) {
16801687
}
16811688
}
16821689

1690+
View performCreateView(LayoutInflater inflater, ViewGroup container,
1691+
Bundle savedInstanceState) {
1692+
if (mChildFragmentManager != null) {
1693+
mChildFragmentManager.noteStateNotSaved();
1694+
}
1695+
return onCreateView(inflater, container, savedInstanceState);
1696+
}
1697+
16831698
void performActivityCreated(Bundle savedInstanceState) {
1699+
if (mChildFragmentManager != null) {
1700+
mChildFragmentManager.noteStateNotSaved();
1701+
}
16841702
mCalled = false;
16851703
onActivityCreated(savedInstanceState);
16861704
if (!mCalled) {
@@ -1713,6 +1731,7 @@ void performStart() {
17131731

17141732
void performResume() {
17151733
if (mChildFragmentManager != null) {
1734+
mChildFragmentManager.noteStateNotSaved();
17161735
mChildFragmentManager.execPendingActions();
17171736
}
17181737
mCalled = false;

core/java/android/app/FragmentManager.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,9 @@ void moveToState(Fragment f, int newState, int transit, int transitionStyle,
834834
throw new SuperNotCalledException("Fragment " + f
835835
+ " did not call through to super.onAttach()");
836836
}
837-
mActivity.onAttachFragment(f);
837+
if (f.mParentFragment == null) {
838+
mActivity.onAttachFragment(f);
839+
}
838840

839841
if (!f.mRetaining) {
840842
f.performCreate(f.mSavedFragmentState);
@@ -844,8 +846,8 @@ void moveToState(Fragment f, int newState, int transit, int transitionStyle,
844846
// For fragments that are part of the content view
845847
// layout, we need to instantiate the view immediately
846848
// and the inflater will take care of adding it.
847-
f.mView = f.onCreateView(f.getLayoutInflater(f.mSavedFragmentState),
848-
null, f.mSavedFragmentState);
849+
f.mView = f.performCreateView(f.getLayoutInflater(
850+
f.mSavedFragmentState), null, f.mSavedFragmentState);
849851
if (f.mView != null) {
850852
f.mView.setSaveFromParentEnabled(false);
851853
if (f.mHidden) f.mView.setVisibility(View.GONE);
@@ -868,8 +870,8 @@ void moveToState(Fragment f, int newState, int transit, int transitionStyle,
868870
}
869871
}
870872
f.mContainer = container;
871-
f.mView = f.onCreateView(f.getLayoutInflater(f.mSavedFragmentState),
872-
container, f.mSavedFragmentState);
873+
f.mView = f.performCreateView(f.getLayoutInflater(
874+
f.mSavedFragmentState), container, f.mSavedFragmentState);
873875
if (f.mView != null) {
874876
f.mView.setSaveFromParentEnabled(false);
875877
if (container != null) {
@@ -885,7 +887,7 @@ void moveToState(Fragment f, int newState, int transit, int transitionStyle,
885887
f.onViewCreated(f.mView, f.mSavedFragmentState);
886888
}
887889
}
888-
890+
889891
f.performActivityCreated(f.mSavedFragmentState);
890892
if (f.mView != null) {
891893
f.restoreViewState(f.mSavedFragmentState);
@@ -1824,7 +1826,7 @@ public void dispatchStop() {
18241826
public void dispatchDestroyView() {
18251827
moveToState(Fragment.CREATED, false);
18261828
}
1827-
1829+
18281830
public void dispatchDestroy() {
18291831
mDestroyed = true;
18301832
execPendingActions();

0 commit comments

Comments
 (0)