Merge "Fix issue #3385839: Fragment.onCreateView is passing in activity..." into honeycomb
This commit is contained in:
committed by
Android (Google) Code Review
commit
4426f643ec
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package android.app;
|
package android.app;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -340,8 +341,48 @@ public class DialogFragment extends Fragment
|
|||||||
mShowsDialog = savedInstanceState.getBoolean(SAVED_SHOWS_DIALOG, mShowsDialog);
|
mShowsDialog = savedInstanceState.getBoolean(SAVED_SHOWS_DIALOG, mShowsDialog);
|
||||||
mBackStackId = savedInstanceState.getInt(SAVED_BACK_STACK_ID, -1);
|
mBackStackId = savedInstanceState.getInt(SAVED_BACK_STACK_ID, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @hide */
|
||||||
|
@Override
|
||||||
|
public LayoutInflater getLayoutInflater(Bundle savedInstanceState) {
|
||||||
|
if (!mShowsDialog) {
|
||||||
|
return super.getLayoutInflater(savedInstanceState);
|
||||||
|
}
|
||||||
|
|
||||||
|
mDialog = onCreateDialog(savedInstanceState);
|
||||||
|
mDestroyed = false;
|
||||||
|
switch (mStyle) {
|
||||||
|
case STYLE_NO_INPUT:
|
||||||
|
mDialog.getWindow().addFlags(
|
||||||
|
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
|
||||||
|
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
|
||||||
|
// fall through...
|
||||||
|
case STYLE_NO_FRAME:
|
||||||
|
case STYLE_NO_TITLE:
|
||||||
|
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
|
}
|
||||||
|
return (LayoutInflater)mDialog.getContext().getSystemService(
|
||||||
|
Context.LAYOUT_INFLATER_SERVICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override to build your own custom Dialog container. This is typically
|
||||||
|
* used to show an AlertDialog instead of a generic Dialog; when doing so,
|
||||||
|
* {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)} does not need
|
||||||
|
* to be implemented since the AlertDialog takes care of its own content.
|
||||||
|
*
|
||||||
|
* <p>This method will be called after {@link #onCreate(Bundle)} and
|
||||||
|
* before {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}. The
|
||||||
|
* default implementation simply instantiates and returns a {@link Dialog}
|
||||||
|
* class.
|
||||||
|
*
|
||||||
|
* @param savedInstanceState The last saved instance state of the Fragment,
|
||||||
|
* or null if this is a freshly created Fragment.
|
||||||
|
*
|
||||||
|
* @return Return a new Dialog instance to be displayed by the Fragment.
|
||||||
|
*/
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
return new Dialog(getActivity(), getTheme());
|
return new Dialog(getActivity(), getTheme());
|
||||||
}
|
}
|
||||||
@@ -367,18 +408,6 @@ public class DialogFragment extends Fragment
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mDialog = onCreateDialog(savedInstanceState);
|
|
||||||
mDestroyed = false;
|
|
||||||
switch (mStyle) {
|
|
||||||
case STYLE_NO_INPUT:
|
|
||||||
mDialog.getWindow().addFlags(
|
|
||||||
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
|
|
||||||
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
|
|
||||||
// fall through...
|
|
||||||
case STYLE_NO_FRAME:
|
|
||||||
case STYLE_NO_TITLE:
|
|
||||||
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
|
||||||
}
|
|
||||||
View view = getView();
|
View view = getView();
|
||||||
if (view != null) {
|
if (view != null) {
|
||||||
if (view.getParent() != null) {
|
if (view.getParent() != null) {
|
||||||
|
|||||||
@@ -849,6 +849,15 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener
|
|||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hide Hack so that DialogFragment can make its Dialog before creating
|
||||||
|
* its views, and the view construction can use the dialog's context for
|
||||||
|
* inflation. Maybe this should become a public API. Note sure.
|
||||||
|
*/
|
||||||
|
public LayoutInflater getLayoutInflater(Bundle savedInstanceState) {
|
||||||
|
return mActivity.getLayoutInflater();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a fragment is being created as part of a view layout
|
* Called when a fragment is being created as part of a view layout
|
||||||
* inflation, typically from setting the content view of an activity. This
|
* inflation, typically from setting the content view of an activity. This
|
||||||
|
|||||||
@@ -705,7 +705,7 @@ final class FragmentManagerImpl extends FragmentManager {
|
|||||||
// For fragments that are part of the content view
|
// For fragments that are part of the content view
|
||||||
// layout, we need to instantiate the view immediately
|
// layout, we need to instantiate the view immediately
|
||||||
// and the inflater will take care of adding it.
|
// and the inflater will take care of adding it.
|
||||||
f.mView = f.onCreateView(mActivity.getLayoutInflater(),
|
f.mView = f.onCreateView(f.getLayoutInflater(f.mSavedFragmentState),
|
||||||
null, f.mSavedFragmentState);
|
null, f.mSavedFragmentState);
|
||||||
if (f.mView != null) {
|
if (f.mView != null) {
|
||||||
f.mView.setSaveFromParentEnabled(false);
|
f.mView.setSaveFromParentEnabled(false);
|
||||||
@@ -727,7 +727,7 @@ final class FragmentManagerImpl extends FragmentManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
f.mContainer = container;
|
f.mContainer = container;
|
||||||
f.mView = f.onCreateView(mActivity.getLayoutInflater(),
|
f.mView = f.onCreateView(f.getLayoutInflater(f.mSavedFragmentState),
|
||||||
container, f.mSavedFragmentState);
|
container, f.mSavedFragmentState);
|
||||||
if (f.mView != null) {
|
if (f.mView != null) {
|
||||||
f.mView.setSaveFromParentEnabled(false);
|
f.mView.setSaveFromParentEnabled(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user