diff options
6 files changed, 84 insertions, 24 deletions
diff --git a/api/current.xml b/api/current.xml index b176309..d935c38 100644 --- a/api/current.xml +++ b/api/current.xml @@ -225218,6 +225218,19 @@ <parameter name="modal" type="boolean"> </parameter> </method> +<method name="setOnDismissListener" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="listener" type="android.widget.PopupWindow.OnDismissListener"> +</parameter> +</method> <method name="setOnItemClickListener" return="void" abstract="false" diff --git a/core/java/android/widget/ListPopupWindow.java b/core/java/android/widget/ListPopupWindow.java index 35e0603..12ff292 100644 --- a/core/java/android/widget/ListPopupWindow.java +++ b/core/java/android/widget/ListPopupWindow.java @@ -604,6 +604,15 @@ public class ListPopupWindow { mDropDownList = null; } + /** + * Set a listener to receive a callback when the popup is dismissed. + * + * @param listener Listener that will be notified when the popup is dismissed. + */ + public void setOnDismissListener(PopupWindow.OnDismissListener listener) { + mPopup.setOnDismissListener(listener); + } + private void removePromptView() { if (mPromptView != null) { final ViewParent parent = mPromptView.getParent(); diff --git a/core/java/com/android/internal/view/menu/ActionMenuView.java b/core/java/com/android/internal/view/menu/ActionMenuView.java index b84789f..e064e2c 100644 --- a/core/java/com/android/internal/view/menu/ActionMenuView.java +++ b/core/java/com/android/internal/view/menu/ActionMenuView.java @@ -25,7 +25,6 @@ import android.view.ViewGroup; import android.widget.ImageButton; import android.widget.LinearLayout; -import java.lang.ref.WeakReference; import java.util.ArrayList; /** @@ -41,7 +40,13 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo private int mMaxItems; private boolean mReserveOverflow; private OverflowMenuButton mOverflowButton; - private WeakReference<MenuPopupHelper> mOverflowPopup; + private MenuPopupHelper mOverflowPopup; + + private Runnable mShowOverflow = new Runnable() { + public void run() { + showOverflowMenu(); + } + }; public ActionMenuView(Context context) { this(context, null); @@ -66,6 +71,7 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo Configuration.SCREENLAYOUT_SIZE_XLARGE; } + @Override public void onConfigurationChanged(Configuration newConfig) { final int screen = newConfig.screenLayout; mReserveOverflow = (screen & Configuration.SCREENLAYOUT_SIZE_MASK) == @@ -75,6 +81,11 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo mMenu.setMaxActionItems(mMaxItems); updateChildren(false); } + + if (mOverflowPopup != null && mOverflowPopup.isShowing()) { + mOverflowPopup.dismiss(); + post(mShowOverflow); + } } private int measureMaxActionButtons() { @@ -172,14 +183,14 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo popup.show(); } }); - mOverflowPopup = new WeakReference<MenuPopupHelper>(popup); + mOverflowPopup = popup; return true; } return false; } public boolean isOverflowMenuShowing() { - MenuPopupHelper popup = mOverflowPopup != null ? mOverflowPopup.get() : null; + MenuPopupHelper popup = mOverflowPopup; if (popup != null) { return popup.isShowing(); } @@ -187,7 +198,7 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo } public boolean hideOverflowMenu() { - MenuPopupHelper popup = mOverflowPopup != null ? mOverflowPopup.get() : null; + MenuPopupHelper popup = mOverflowPopup; if (popup != null) { popup.dismiss(); return true; diff --git a/core/java/com/android/internal/view/menu/MenuPopupHelper.java b/core/java/com/android/internal/view/menu/MenuPopupHelper.java index f52c93c..a12a4d6 100644 --- a/core/java/com/android/internal/view/menu/MenuPopupHelper.java +++ b/core/java/com/android/internal/view/menu/MenuPopupHelper.java @@ -26,6 +26,7 @@ import android.view.View; import android.view.View.MeasureSpec; import android.widget.AdapterView; import android.widget.ListPopupWindow; +import android.widget.PopupWindow; import java.lang.ref.WeakReference; @@ -42,6 +43,12 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On private WeakReference<View> mAnchorView; private boolean mOverflowOnly; + private PopupWindow.OnDismissListener mDismissListener = new PopupWindow.OnDismissListener() { + public void onDismiss() { + mPopup = null; + } + }; + public MenuPopupHelper(Context context, MenuBuilder menu) { this(context, menu, null, false); } @@ -69,6 +76,7 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On mPopup = new ListPopupWindow(mContext, null, 0, com.android.internal.R.style.Widget_Spinner); mPopup.setOnItemClickListener(this); + mPopup.setOnDismissListener(mDismissListener); final MenuAdapter adapter = mOverflowOnly ? mMenu.getOverflowMenuAdapter(MenuBuilder.TYPE_POPUP) : @@ -95,7 +103,6 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On if (isShowing()) { mPopup.dismiss(); } - mPopup = null; } public boolean isShowing() { diff --git a/core/java/com/android/internal/widget/ActionBarView.java b/core/java/com/android/internal/widget/ActionBarView.java index 067d022..b9e4e46 100644 --- a/core/java/com/android/internal/widget/ActionBarView.java +++ b/core/java/com/android/internal/widget/ActionBarView.java @@ -221,6 +221,14 @@ public class ActionBarView extends ViewGroup { return false; } + public void postShowOverflowMenu() { + post(new Runnable() { + public void run() { + showOverflowMenu(); + } + }); + } + public boolean hideOverflowMenu() { if (mMenuView != null) { return mMenuView.hideOverflowMenu(); diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindow.java b/policy/src/com/android/internal/policy/impl/PhoneWindow.java index 2bb4456..2dabf72 100644 --- a/policy/src/com/android/internal/policy/impl/PhoneWindow.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindow.java @@ -364,29 +364,32 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { @Override public void onConfigurationChanged(Configuration newConfig) { - PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, false); - if ((st != null) && (st.menu != null)) { - final MenuBuilder menuBuilder = (MenuBuilder) st.menu; + // Action bars handle their own menu state + if (mActionBar == null) { + PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, false); + if ((st != null) && (st.menu != null)) { + final MenuBuilder menuBuilder = (MenuBuilder) st.menu; - if (st.isOpen) { - // Freeze state - final Bundle state = new Bundle(); - menuBuilder.saveHierarchyState(state); + if (st.isOpen) { + // Freeze state + final Bundle state = new Bundle(); + menuBuilder.saveHierarchyState(state); - // Remove the menu views since they need to be recreated - // according to the new configuration - clearMenuViews(st); + // Remove the menu views since they need to be recreated + // according to the new configuration + clearMenuViews(st); - // Re-open the same menu - reopenMenu(false); + // Re-open the same menu + reopenMenu(false); - // Restore state - menuBuilder.restoreHierarchyState(state); + // Restore state + menuBuilder.restoreHierarchyState(state); - } else { - // Clear menu views so on next menu opening, it will use - // the proper layout - clearMenuViews(st); + } else { + // Clear menu views so on next menu opening, it will use + // the proper layout + clearMenuViews(st); + } } } } @@ -1515,6 +1518,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { static private final String FOCUSED_ID_TAG = "android:focusedViewId"; static private final String VIEWS_TAG = "android:views"; static private final String PANELS_TAG = "android:Panels"; + static private final String ACTION_BAR_TAG = "android:ActionBar"; /** {@inheritDoc} */ @Override @@ -1548,6 +1552,10 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { outState.putSparseParcelableArray(PANELS_TAG, panelStates); } + if (mActionBar != null) { + outState.putBoolean(ACTION_BAR_TAG, mActionBar.isOverflowMenuShowing()); + } + return outState; } @@ -1582,6 +1590,10 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { if (panelStates != null) { restorePanelState(panelStates); } + + if (mActionBar != null && savedInstanceState.getBoolean(ACTION_BAR_TAG)) { + mActionBar.postShowOverflowMenu(); + } } /** |