diff options
6 files changed, 97 insertions, 25 deletions
diff --git a/core/java/com/android/internal/app/ActionBarImpl.java b/core/java/com/android/internal/app/ActionBarImpl.java index 0be42d603c3a..dd2ad6c764dd 100644 --- a/core/java/com/android/internal/app/ActionBarImpl.java +++ b/core/java/com/android/internal/app/ActionBarImpl.java @@ -531,6 +531,8 @@ public class ActionBarImpl extends ActionBar { } public void onMenuModeChange(MenuBuilder menu) { + invalidate(); + mUpperContextView.showOverflowMenu(); } } diff --git a/core/java/com/android/internal/view/StandaloneActionMode.java b/core/java/com/android/internal/view/StandaloneActionMode.java index e6d6ba04d807..ab80c588f8fd 100644 --- a/core/java/com/android/internal/view/StandaloneActionMode.java +++ b/core/java/com/android/internal/view/StandaloneActionMode.java @@ -135,5 +135,7 @@ public class StandaloneActionMode extends ActionMode implements MenuBuilder.Call } public void onMenuModeChange(MenuBuilder menu) { + invalidate(); + mContextView.showOverflowMenu(); } } diff --git a/core/java/com/android/internal/view/menu/ActionMenuView.java b/core/java/com/android/internal/view/menu/ActionMenuView.java index d00a99ee1fd4..cb5f17980d99 100644 --- a/core/java/com/android/internal/view/menu/ActionMenuView.java +++ b/core/java/com/android/internal/view/menu/ActionMenuView.java @@ -148,14 +148,28 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo public boolean showOverflowMenu() { if (mOverflowButton != null) { - MenuPopupHelper popup = new MenuPopupHelper(getContext(), mMenu, mOverflowButton, true); - popup.show(); + final MenuPopupHelper popup = + new MenuPopupHelper(getContext(), mMenu, mOverflowButton, true); + // Post this for later; we might still need a layout for the anchor to be right. + post(new Runnable() { + public void run() { + popup.show(); + } + }); mOverflowPopup = new WeakReference<MenuPopupHelper>(popup); return true; } return false; } + public boolean isOverflowMenuShowing() { + MenuPopupHelper popup = mOverflowPopup != null ? mOverflowPopup.get() : null; + if (popup != null) { + return popup.isShowing(); + } + return false; + } + public boolean hideOverflowMenu() { MenuPopupHelper popup = mOverflowPopup != null ? mOverflowPopup.get() : null; if (popup != null) { @@ -177,7 +191,7 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo final Resources res = context.getResources(); setClickable(true); setFocusable(true); - // TODO setTitle() to a localized string for accessibility + setContentDescription(res.getString(com.android.internal.R.string.more_item_label)); setImageDrawable(res.getDrawable(com.android.internal.R.drawable.ic_menu_more)); setVisibility(VISIBLE); setEnabled(true); @@ -189,7 +203,8 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo return true; } - showOverflowMenu(); + // Change to overflow mode + mMenu.getCallback().onMenuModeChange(mMenu); return true; } } diff --git a/core/java/com/android/internal/widget/ActionBarContextView.java b/core/java/com/android/internal/widget/ActionBarContextView.java index 5518b3edc317..6a476d00eb09 100644 --- a/core/java/com/android/internal/widget/ActionBarContextView.java +++ b/core/java/com/android/internal/widget/ActionBarContextView.java @@ -163,6 +163,27 @@ public class ActionBarContextView extends ViewGroup { mMenuView = null; } + public boolean showOverflowMenu() { + if (mMenuView != null) { + return mMenuView.showOverflowMenu(); + } + return false; + } + + public boolean hideOverflowMenu() { + if (mMenuView != null) { + return mMenuView.hideOverflowMenu(); + } + return false; + } + + public boolean isOverflowMenuShowing() { + if (mMenuView != null) { + return mMenuView.isOverflowMenuShowing(); + } + return false; + } + @Override protected LayoutParams generateDefaultLayoutParams() { // Used by custom views if they don't supply layout params. Everything else diff --git a/core/java/com/android/internal/widget/ActionBarView.java b/core/java/com/android/internal/widget/ActionBarView.java index 3c40bb07f87e..73d3c9574a3c 100644 --- a/core/java/com/android/internal/widget/ActionBarView.java +++ b/core/java/com/android/internal/widget/ActionBarView.java @@ -219,6 +219,13 @@ public class ActionBarView extends ViewGroup { return false; } + public boolean isOverflowMenuShowing() { + if (mMenuView != null) { + return mMenuView.isOverflowMenuShowing(); + } + return false; + } + public boolean isOverflowReserved() { return mMenuView != null && mMenuView.isOverflowReserved(); } diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindow.java b/policy/src/com/android/internal/policy/impl/PhoneWindow.java index 9e4015bb4ef7..546c0f447c6c 100644 --- a/policy/src/com/android/internal/policy/impl/PhoneWindow.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindow.java @@ -599,7 +599,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { // The panel key was pushed, so set the chording key mPanelChordingKey = keyCode; mPanelMayLongPress = false; - + PanelFeatureState st = getPanelState(featureId, true); if (!st.isOpen) { if (getContext().getResources().getConfiguration().keyboard @@ -608,7 +608,6 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { } return preparePanel(st, event); } - } else if (mPanelMayLongPress && mPanelChordingKey == keyCode && (event.getFlags()&KeyEvent.FLAG_LONG_PRESS) != 0) { // We have had a long press while in a state where this @@ -643,25 +642,40 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { } boolean playSoundEffect = false; - PanelFeatureState st = getPanelState(featureId, true); - if (st.isOpen || st.isHandled) { + final PanelFeatureState st = getPanelState(featureId, true); + if (featureId == FEATURE_OPTIONS_PANEL && mActionBar != null) { + if (mActionBar.isOverflowReserved()) { + if (!mActionBar.isOverflowMenuShowing()) { + final Callback cb = getCallback(); + if (cb != null) { + if (cb.onPreparePanel(featureId, st.createdPanelView, st.menu)) { + playSoundEffect = mActionBar.showOverflowMenu(); + } + } + } else { + playSoundEffect = mActionBar.hideOverflowMenu(); + } + } + } else { + if (st.isOpen || st.isHandled) { - // Play the sound effect if the user closed an open menu (and not if - // they just released a menu shortcut) - playSoundEffect = st.isOpen; + // Play the sound effect if the user closed an open menu (and not if + // they just released a menu shortcut) + playSoundEffect = st.isOpen; - // Close menu - closePanel(st, true); + // Close menu + closePanel(st, true); - } else if (st.isPrepared) { + } else if (st.isPrepared) { - // Write 'menu opened' to event log - EventLog.writeEvent(50001, 0); + // Write 'menu opened' to event log + EventLog.writeEvent(50001, 0); - // Show menu - openPanel(st, event); + // Show menu + openPanel(st, event); - playSoundEffect = true; + playSoundEffect = true; + } } if (playSoundEffect) { @@ -841,6 +855,21 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { } private void reopenMenu(boolean toggleMenuMode) { + if (mActionBar != null) { + if (!mActionBar.isOverflowMenuShowing() || !toggleMenuMode) { + final Callback cb = getCallback(); + if (cb != null) { + final PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, true); + if (cb.onPreparePanel(FEATURE_OPTIONS_PANEL, st.createdPanelView, st.menu)) { + mActionBar.showOverflowMenu(); + } + } + } else { + mActionBar.hideOverflowMenu(); + } + return; + } + PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, true); // Save the future expanded mode state since closePanel will reset it @@ -1387,12 +1416,8 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { } case KeyEvent.KEYCODE_MENU: { - if (mActionBar != null && mActionBar.isOverflowReserved()) { - mActionBar.showOverflowMenu(); - } else { - onKeyUpPanel(featureId < 0 ? FEATURE_OPTIONS_PANEL : featureId, - event); - } + onKeyUpPanel(featureId < 0 ? FEATURE_OPTIONS_PANEL : featureId, + event); return true; } |