Merge "Allow FragmentContainer to play a role in fragment construction"

This commit is contained in:
Jason Monk
2017-01-18 23:58:35 +00:00
committed by Android (Google) Code Review
6 changed files with 23 additions and 5 deletions

View File

@@ -4592,6 +4592,7 @@ package android.app {
public abstract class FragmentContainer {
ctor public FragmentContainer();
method public android.app.Fragment instantiate(android.content.Context, java.lang.String, android.os.Bundle);
method public abstract android.view.View onFindViewById(int);
method public abstract boolean onHasView();
}

View File

@@ -4749,6 +4749,7 @@ package android.app {
public abstract class FragmentContainer {
ctor public FragmentContainer();
method public android.app.Fragment instantiate(android.content.Context, java.lang.String, android.os.Bundle);
method public abstract android.view.View onFindViewById(int);
method public abstract boolean onHasView();
}

View File

@@ -4602,6 +4602,7 @@ package android.app {
public abstract class FragmentContainer {
ctor public FragmentContainer();
method public android.app.Fragment instantiate(android.content.Context, java.lang.String, android.os.Bundle);
method public abstract android.view.View onFindViewById(int);
method public abstract boolean onHasView();
}

View File

@@ -102,15 +102,19 @@ final class FragmentState implements Parcelable {
mSavedFragmentState = in.readBundle();
}
public Fragment instantiate(FragmentHostCallback host, Fragment parent,
FragmentManagerNonConfig childNonConfig) {
public Fragment instantiate(FragmentHostCallback host, FragmentContainer container,
Fragment parent, FragmentManagerNonConfig childNonConfig) {
if (mInstance == null) {
final Context context = host.getContext();
if (mArguments != null) {
mArguments.setClassLoader(context.getClassLoader());
}
mInstance = Fragment.instantiate(context, mClassName, mArguments);
if (container != null) {
mInstance = container.instantiate(context, mClassName, mArguments);
} else {
mInstance = Fragment.instantiate(context, mClassName, mArguments);
}
if (mSavedFragmentState != null) {
mSavedFragmentState.setClassLoader(context.getClassLoader());

View File

@@ -18,6 +18,8 @@ package android.app;
import android.annotation.IdRes;
import android.annotation.Nullable;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
/**
@@ -35,4 +37,13 @@ public abstract class FragmentContainer {
* Return {@code true} if the container holds any view.
*/
public abstract boolean onHasView();
/**
* Creates an instance of the specified fragment, can be overridden to construct fragments
* with dependencies, or change the fragment being constructed. By default just calls
* {@link Fragment#instantiate(Context, String, Bundle)}.
*/
public Fragment instantiate(Context context, String className, Bundle arguments) {
return Fragment.instantiate(context, className, arguments);
}
}

View File

@@ -2653,7 +2653,7 @@ final class FragmentManagerImpl extends FragmentManager implements LayoutInflate
if (childNonConfigs != null && i < childNonConfigs.size()) {
childNonConfig = childNonConfigs.get(i);
}
Fragment f = fs.instantiate(mHost, mParent, childNonConfig);
Fragment f = fs.instantiate(mHost, mContainer, mParent, childNonConfig);
if (DEBUG) Log.v(TAG, "restoreAllState: active #" + i + ": " + f);
mActive.add(f);
// Now that the fragment is instantiated (or came from being
@@ -3272,7 +3272,7 @@ final class FragmentManagerImpl extends FragmentManager implements LayoutInflate
+ Integer.toHexString(id) + " fname=" + fname
+ " existing=" + fragment);
if (fragment == null) {
fragment = Fragment.instantiate(context, fname);
fragment = mContainer.instantiate(context, fname, null);
fragment.mFromLayout = true;
fragment.mFragmentId = id != 0 ? id : containerId;
fragment.mContainerId = containerId;