menu. For this method
+ * to be called, you must have first called {@link #setHasMenu}. See
+ * {@link Activity#onCreateOptionsMenu(Menu) Activity.onCreateOptionsMenu}
+ * for more information.
+ *
+ * @param menu The options menu in which you place your items.
+ *
+ * @see #setHasMenu
+ * @see #onPrepareOptionsMenu
+ * @see #onOptionsItemSelected
+ */
+ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ }
+
+ /**
+ * Prepare the Screen's standard options menu to be displayed. This is
+ * called right before the menu is shown, every time it is shown. You can
+ * use this method to efficiently enable/disable items or otherwise
+ * dynamically modify the contents. See
+ * {@link Activity#onPrepareOptionsMenu(Menu) Activity.onPrepareOptionsMenu}
+ * for more information.
+ *
+ * @param menu The options menu as last shown or first initialized by
+ * onCreateOptionsMenu().
+ *
+ * @see #setHasMenu
+ * @see #onCreateOptionsMenu
+ */
+ public void onPrepareOptionsMenu(Menu menu) {
+ }
+
+ /**
+ * This hook is called whenever an item in your options menu is selected.
+ * The default implementation simply returns false to have the normal
+ * processing happen (calling the item's Runnable or sending a message to
+ * its Handler as appropriate). You can use this method for any items
+ * for which you would like to do processing without those other
+ * facilities.
+ *
+ * Derived classes should call through to the base class for it to
+ * perform the default menu handling.
+ *
+ * @param item The menu item that was selected.
+ *
+ * @return boolean Return false to allow normal menu processing to
+ * proceed, true to consume it here.
+ *
+ * @see #onCreateOptionsMenu
+ */
+ public boolean onOptionsItemSelected(MenuItem item) {
+ return false;
+ }
+
+ /**
+ * This hook is called whenever the options menu is being closed (either by the user canceling
+ * the menu with the back/menu button, or when an item is selected).
+ *
+ * @param menu The options menu as last shown or first initialized by
+ * onCreateOptionsMenu().
+ */
+ public void onOptionsMenuClosed(Menu menu) {
+ }
}
diff --git a/core/java/android/app/FragmentManager.java b/core/java/android/app/FragmentManager.java
index a10a19189d669..b837c323483f3 100644
--- a/core/java/android/app/FragmentManager.java
+++ b/core/java/android/app/FragmentManager.java
@@ -23,6 +23,9 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;
import android.util.SparseArray;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
@@ -82,6 +85,8 @@ public class FragmentManager {
int mCurState = Fragment.INITIALIZING;
Activity mActivity;
+ boolean mNeedMenuInvalidate;
+
// Temporary vars for state save and restore.
Bundle mStateBundle = null;
SparseArray mStateArray = null;
@@ -362,6 +367,9 @@ public class FragmentManager {
mAdded.add(fragment);
makeActive(fragment);
fragment.mAdded = true;
+ if (fragment.mHasMenu) {
+ mNeedMenuInvalidate = true;
+ }
if (moveToStateNow) {
moveToState(fragment, mCurState, 0, 0);
}
@@ -374,6 +382,9 @@ public class FragmentManager {
if (inactive) {
makeInactive(fragment);
}
+ if (fragment.mHasMenu) {
+ mNeedMenuInvalidate = true;
+ }
fragment.mAdded = false;
moveToState(fragment, inactive ? Fragment.INITIALIZING : Fragment.CREATED,
transition, transitionStyle);
@@ -391,6 +402,9 @@ public class FragmentManager {
}
fragment.mView.setVisibility(View.GONE);
}
+ if (fragment.mAdded && fragment.mHasMenu) {
+ mNeedMenuInvalidate = true;
+ }
fragment.onHiddenChanged(true);
}
}
@@ -407,6 +421,9 @@ public class FragmentManager {
}
fragment.mView.setVisibility(View.VISIBLE);
}
+ if (fragment.mAdded && fragment.mHasMenu) {
+ mNeedMenuInvalidate = true;
+ }
fragment.onHiddenChanged(false);
}
}
@@ -673,6 +690,7 @@ public class FragmentManager {
"No instantiated fragment for index #" + fms.mAdded[i]);
}
f.mAdded = true;
+ f.mImmediateActivity = mActivity;
mAdded.add(f);
}
} else {
@@ -721,6 +739,59 @@ public class FragmentManager {
mActivity = null;
}
+ public boolean dispatchCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ boolean show = false;
+ if (mActive != null) {
+ for (int i=0; i