diff options
Diffstat (limited to 'com_actionbarsherlock/src/com/actionbarsherlock/internal/ActionBarSherlockCompat.java')
-rw-r--r-- | com_actionbarsherlock/src/com/actionbarsherlock/internal/ActionBarSherlockCompat.java | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/com_actionbarsherlock/src/com/actionbarsherlock/internal/ActionBarSherlockCompat.java b/com_actionbarsherlock/src/com/actionbarsherlock/internal/ActionBarSherlockCompat.java index eab4d2153..f080bfe95 100644 --- a/com_actionbarsherlock/src/com/actionbarsherlock/internal/ActionBarSherlockCompat.java +++ b/com_actionbarsherlock/src/com/actionbarsherlock/internal/ActionBarSherlockCompat.java @@ -71,6 +71,8 @@ public class ActionBarSherlockCompat extends ActionBarSherlock implements MenuBu private MenuBuilder mMenu; /** Map between native options items and sherlock items. */ protected HashMap<android.view.MenuItem, MenuItemImpl> mNativeItemMap; + /** Indication of a long-press on the hardware menu key. */ + private boolean mMenuKeyIsLongPress = false; /** Parent view of the window decoration (action bar, mode, etc.). */ private ViewGroup mDecor; @@ -318,6 +320,10 @@ public class ActionBarSherlockCompat extends ActionBarSherlock implements MenuBu public boolean dispatchPrepareOptionsMenu(android.view.Menu menu) { if (DEBUG) Log.d(TAG, "[dispatchPrepareOptionsMenu] android.view.Menu: " + menu); + if (mActionMode != null) { + return false; + } + mMenuIsPrepared = false; if (!preparePanel()) { return false; @@ -416,20 +422,27 @@ public class ActionBarSherlockCompat extends ActionBarSherlock implements MenuBu } } - if (keyCode == KeyEvent.KEYCODE_MENU && event.getAction() == KeyEvent.ACTION_UP && isReservingOverflow()) { - if (mActionMode == null) { - if (wActionBar.isOverflowMenuShowing()) { - wActionBar.hideOverflowMenu(); - } else { - wActionBar.showOverflowMenu(); + boolean result = false; + if (keyCode == KeyEvent.KEYCODE_MENU && isReservingOverflow()) { + if (event.getAction() == KeyEvent.ACTION_DOWN && event.isLongPress()) { + mMenuKeyIsLongPress = true; + } else if (event.getAction() == KeyEvent.ACTION_UP) { + if (!mMenuKeyIsLongPress) { + if (mActionMode == null) { + if (wActionBar.isOverflowMenuShowing()) { + wActionBar.hideOverflowMenu(); + } else { + wActionBar.showOverflowMenu(); + } + } + result = true; } + mMenuKeyIsLongPress = false; } - if (DEBUG) Log.d(TAG, "[dispatchKeyEvent] returning true"); - return true; } - if (DEBUG) Log.d(TAG, "[dispatchKeyEvent] returning false"); - return false; + if (DEBUG) Log.d(TAG, "[dispatchKeyEvent] returning " + result); + return result; } @@ -964,7 +977,7 @@ public class ActionBarSherlockCompat extends ActionBarSherlock implements MenuBu @Override public void run() { //Invalidate if the panel menu hasn't been created before this. - if (mMenu == null) { + if (!mActivity.isFinishing() && mMenu == null) { dispatchInvalidateOptionsMenu(); } } |