Merge "Fix Fragment.onInflate() to actually work correctly." into honeycomb-mr1

This commit is contained in:
Dianne Hackborn
2011-03-03 22:23:07 -08:00
committed by Android (Google) Code Review
6 changed files with 140 additions and 17 deletions

View File

@@ -30379,6 +30379,21 @@
<parameter name="hidden" type="boolean"> <parameter name="hidden" type="boolean">
</parameter> </parameter>
</method> </method>
<method name="onInflate"
return="void"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="deprecated"
visibility="public"
>
<parameter name="attrs" type="android.util.AttributeSet">
</parameter>
<parameter name="savedInstanceState" type="android.os.Bundle">
</parameter>
</method>
<method name="onInflate" <method name="onInflate"
return="void" return="void"
abstract="false" abstract="false"
@@ -30389,6 +30404,8 @@
deprecated="not deprecated" deprecated="not deprecated"
visibility="public" visibility="public"
> >
<parameter name="activity" type="android.app.Activity">
</parameter>
<parameter name="attrs" type="android.util.AttributeSet"> <parameter name="attrs" type="android.util.AttributeSet">
</parameter> </parameter>
<parameter name="savedInstanceState" type="android.os.Bundle"> <parameter name="savedInstanceState" type="android.os.Bundle">
@@ -143820,6 +143837,21 @@
<parameter name="key" type="java.lang.String"> <parameter name="key" type="java.lang.String">
</parameter> </parameter>
</method> </method>
<method name="getCharSequence"
return="java.lang.CharSequence"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="key" type="java.lang.String">
</parameter>
<parameter name="defaultValue" type="java.lang.CharSequence">
</parameter>
</method>
<method name="getCharSequenceArray" <method name="getCharSequenceArray"
return="java.lang.CharSequence[]" return="java.lang.CharSequence[]"
abstract="false" abstract="false"
@@ -144153,6 +144185,21 @@
<parameter name="key" type="java.lang.String"> <parameter name="key" type="java.lang.String">
</parameter> </parameter>
</method> </method>
<method name="getString"
return="java.lang.String"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="key" type="java.lang.String">
</parameter>
<parameter name="defaultValue" type="java.lang.String">
</parameter>
</method>
<method name="getStringArray" <method name="getStringArray"
return="java.lang.String[]" return="java.lang.String[]"
abstract="false" abstract="false"

View File

@@ -4137,7 +4137,7 @@ public class Activity extends ContextThemeWrapper
fragment.mInLayout = true; fragment.mInLayout = true;
fragment.mImmediateActivity = this; fragment.mImmediateActivity = this;
fragment.mFragmentManager = mFragments; fragment.mFragmentManager = mFragments;
fragment.onInflate(attrs, fragment.mSavedFragmentState); fragment.onInflate(this, attrs, fragment.mSavedFragmentState);
mFragments.addFragment(fragment, true); mFragments.addFragment(fragment, true);
} else if (fragment.mInLayout) { } else if (fragment.mInLayout) {
@@ -4156,7 +4156,7 @@ public class Activity extends ContextThemeWrapper
// from last saved state), then give it the attributes to // from last saved state), then give it the attributes to
// initialize itself. // initialize itself.
if (!fragment.mRetaining) { if (!fragment.mRetaining) {
fragment.onInflate(attrs, fragment.mSavedFragmentState); fragment.onInflate(this, attrs, fragment.mSavedFragmentState);
} }
mFragments.moveToState(fragment); mFragments.moveToState(fragment);
} }

View File

@@ -858,33 +858,58 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener
return mActivity.getLayoutInflater(); return mActivity.getLayoutInflater();
} }
/**
* @deprecated Use {@link #onInflate(Activity, AttributeSet, Bundle)} instead.
*/
@Deprecated
public void onInflate(AttributeSet attrs, Bundle savedInstanceState) {
mCalled = true;
}
/** /**
* 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
* will be called immediately after the fragment is created from a <fragment> * may be called immediately after the fragment is created from a <fragment>
* tag in a layout file. Note this is <em>before</em> the fragment's * tag in a layout file. Note this is <em>before</em> the fragment's
* {@link #onAttach(Activity)} has been called; all you should do here is * {@link #onAttach(Activity)} has been called; all you should do here is
* parse the attributes and save them away. A convenient thing to do is * parse the attributes and save them away.
* simply copy them into a Bundle that is given to {@link #setArguments(Bundle)}.
* *
* <p>This is called every time the fragment is inflated, even if it is * <p>This is called every time the fragment is inflated, even if it is
* being inflated into a new instance with saved state. Because a fragment's * being inflated into a new instance with saved state. It typically makes
* arguments are retained across instances, it may make no sense to re-parse * sense to re-parse the parameters each time, to allow them to change with
* the attributes into new arguments. You may want to first check * different configurations.</p>
* {@link #getArguments()} and only parse the attributes if it returns null, *
* the assumption being that if it is non-null those are the same arguments * <p>Here is a typical implementation of a fragment that can take parameters
* from the first time the fragment was inflated. (That said, you may want * both through attributes supplied here as well from {@link #getArguments()}:</p>
* to have layouts change for different configurations such as landscape *
* and portrait, which can have different attributes. If so, you will need * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentArguments.java
* to re-parse the attributes each time this is called to generate new * fragment}
* arguments.)</p> *
* <p>Note that parsing the XML attributes uses a "styleable" resource. The
* declaration for the styleable used here is:</p>
*
* {@sample development/samples/ApiDemos/res/values/attrs.xml fragment_arguments}
* *
* <p>The fragment can then be declared within its activity's content layout
* through a tag like this:</p>
*
* {@sample development/samples/ApiDemos/res/layout/fragment_arguments.xml from_attributes}
*
* <p>This fragment can also be created dynamically from arguments given
* at runtime in the arguments Bundle; here is an example of doing so at
* creation of the containing activity:</p>
*
* {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentArguments.java
* create}
*
* @param activity The Activity that is inflating this fragment.
* @param attrs The attributes at the tag where the fragment is * @param attrs The attributes at the tag where the fragment is
* being created. * being created.
* @param savedInstanceState If the fragment is being re-created from * @param savedInstanceState If the fragment is being re-created from
* a previous saved state, this is the state. * a previous saved state, this is the state.
*/ */
public void onInflate(AttributeSet attrs, Bundle savedInstanceState) { public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) {
onInflate(attrs, savedInstanceState);
mCalled = true; mCalled = true;
} }

View File

@@ -660,6 +660,12 @@ final class FragmentManagerImpl extends FragmentManager {
} }
if (f.mState < newState) { if (f.mState < newState) {
// For fragments that are created from a layout, when restoring from
// state we don't want to allow them to be created until they are
// being reloaded from the layout.
if (f.mFromLayout && !f.mInLayout) {
return;
}
if (f.mAnimatingAway != null) { if (f.mAnimatingAway != null) {
// The fragment is currently being animated... but! Now we // The fragment is currently being animated... but! Now we
// want to move our state back up. Give up on waiting for the // want to move our state back up. Give up on waiting for the

View File

@@ -1028,7 +1028,6 @@ public final class Bundle implements Parcelable, Cloneable {
} }
} }
/** /**
* Returns the value associated with the given key, or null if * Returns the value associated with the given key, or null if
* no mapping of the desired type exists for the given key or a null * no mapping of the desired type exists for the given key or a null
@@ -1051,6 +1050,28 @@ public final class Bundle implements Parcelable, Cloneable {
} }
} }
/**
* Returns the value associated with the given key, or defaultValue if
* no mapping of the desired type exists for the given key.
*
* @param key a String, or null
* @param defaultValue Value to return if key does not exist
* @return a String value, or null
*/
public String getString(String key, String defaultValue) {
unparcel();
Object o = mMap.get(key);
if (o == null) {
return defaultValue;
}
try {
return (String) o;
} catch (ClassCastException e) {
typeWarning(key, o, "String", e);
return defaultValue;
}
}
/** /**
* Returns the value associated with the given key, or null if * Returns the value associated with the given key, or null if
* no mapping of the desired type exists for the given key or a null * no mapping of the desired type exists for the given key or a null
@@ -1073,6 +1094,28 @@ public final class Bundle implements Parcelable, Cloneable {
} }
} }
/**
* Returns the value associated with the given key, or defaultValue if
* no mapping of the desired type exists for the given key.
*
* @param key a String, or null
* @param defaultValue Value to return if key does not exist
* @return a CharSequence value, or null
*/
public CharSequence getCharSequence(String key, CharSequence defaultValue) {
unparcel();
Object o = mMap.get(key);
if (o == null) {
return defaultValue;
}
try {
return (CharSequence) o;
} catch (ClassCastException e) {
typeWarning(key, o, "CharSequence", e);
return defaultValue;
}
}
/** /**
* Returns the value associated with the given key, or null if * Returns the value associated with the given key, or null if
* no mapping of the desired type exists for the given key or a null * no mapping of the desired type exists for the given key or a null

View File

@@ -1860,8 +1860,10 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
}); });
} }
mSwitchingDialog = mDialogBuilder.create(); mSwitchingDialog = mDialogBuilder.create();
mSwitchingDialog.setCanceledOnTouchOutside(true);
mSwitchingDialog.getWindow().setType( mSwitchingDialog.getWindow().setType(
WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG); WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG);
mSwitchingDialog.getWindow().getAttributes().setTitle("Select input method");
mSwitchingDialog.show(); mSwitchingDialog.show();
} }
} }