diff options
| author | Dianne Hackborn <hackbod@google.com> | 2011-01-24 23:58:13 -0800 |
|---|---|---|
| committer | Dianne Hackborn <hackbod@google.com> | 2011-01-25 11:28:39 -0800 |
| commit | 7187ccb93ee8adbb745fcbb901cfacfeed397a23 (patch) | |
| tree | cc1a17e2e05e8b4898a3ff9f2f5978275d272412 /core/java/android/app/DialogFragment.java | |
| parent | 774f9be5dc02e8a7f742008872c6214e517cb8a3 (diff) | |
Fix issue #3385839: Fragment.onCreateView is passing in activity...
...context for a DialogFragment
Change-Id: I434ebca64d2738da4c27321db8dbbded2cbe167d
Diffstat (limited to 'core/java/android/app/DialogFragment.java')
| -rw-r--r-- | core/java/android/app/DialogFragment.java | 53 |
1 files changed, 41 insertions, 12 deletions
diff --git a/core/java/android/app/DialogFragment.java b/core/java/android/app/DialogFragment.java index 0bc89e722719..8bdd086eb466 100644 --- a/core/java/android/app/DialogFragment.java +++ b/core/java/android/app/DialogFragment.java @@ -16,6 +16,7 @@ package android.app; +import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; import android.view.LayoutInflater; @@ -340,8 +341,48 @@ public class DialogFragment extends Fragment mShowsDialog = savedInstanceState.getBoolean(SAVED_SHOWS_DIALOG, mShowsDialog); 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) { return new Dialog(getActivity(), getTheme()); } @@ -367,18 +408,6 @@ public class DialogFragment extends Fragment 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(); if (view != null) { if (view.getParent() != null) { |
