summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Banes <chrisbanes@google.com>2015-11-09 10:39:25 +0000
committerChris Banes <chrisbanes@google.com>2015-11-09 10:41:15 +0000
commit625c9c3db9bb6f6b92ca35b74f26a61a04ec8cd7 (patch)
tree0b6d3b58ceec2b440c3135a4f51cb593ae190719
parentdf83d90f2aed3e0b39193b5ea25014cea1d8c19e (diff)
downloadandroid_frameworks_support-625c9c3db9bb6f6b92ca35b74f26a61a04ec8cd7.tar.gz
android_frameworks_support-625c9c3db9bb6f6b92ca35b74f26a61a04ec8cd7.tar.bz2
android_frameworks_support-625c9c3db9bb6f6b92ca35b74f26a61a04ec8cd7.zip
Allow AppCompat to work with long-press-back-menu gesture
Certain OEMs have re-mapped a long-press on the back button to the menu button. AppCompat will currently show the options menu and instantly dismiss it. This CL adds supports so that it isn't dismissed if it was opened from a long-press of the back button. BUG: 25582858 Change-Id: I69c4160c03349dfae716430c87aeca5c91aa0453
-rw-r--r--v7/appcompat/src/android/support/v7/app/AppCompatDelegateImplV7.java17
1 files changed, 16 insertions, 1 deletions
diff --git a/v7/appcompat/src/android/support/v7/app/AppCompatDelegateImplV7.java b/v7/appcompat/src/android/support/v7/app/AppCompatDelegateImplV7.java
index d2c7b91462..e147b7dbe9 100644
--- a/v7/appcompat/src/android/support/v7/app/AppCompatDelegateImplV7.java
+++ b/v7/appcompat/src/android/support/v7/app/AppCompatDelegateImplV7.java
@@ -115,6 +115,8 @@ class AppCompatDelegateImplV7 extends AppCompatDelegateImplBase
private PanelFeatureState[] mPanels;
private PanelFeatureState mPreparedPanel;
+ private boolean mLongPressBackDown;
+
private boolean mInvalidatePanelMenuPosted;
private int mInvalidatePanelMenuFeatures;
private final Runnable mInvalidatePanelMenuRunnable = new Runnable() {
@@ -874,9 +876,17 @@ class AppCompatDelegateImplV7 extends AppCompatDelegateImplBase
onKeyUpPanel(Window.FEATURE_OPTIONS_PANEL, event);
return true;
case KeyEvent.KEYCODE_BACK:
+ final boolean wasLongPressBackDown = mLongPressBackDown;
+ mLongPressBackDown = false;
+
PanelFeatureState st = getPanelState(Window.FEATURE_OPTIONS_PANEL, false);
if (st != null && st.isOpen) {
- closePanel(st, true);
+ if (!wasLongPressBackDown) {
+ // Certain devices allow opening the options menu via a long press of the
+ // back button. We should only close the open options menu if it wasn't
+ // opened via a long press gesture.
+ closePanel(st, true);
+ }
return true;
}
if (onBackPressed()) {
@@ -895,6 +905,11 @@ class AppCompatDelegateImplV7 extends AppCompatDelegateImplBase
// For empty menus, PhoneWindow's KEYCODE_BACK handling will steals all events,
// not allowing the Activity to call onBackPressed().
return true;
+ case KeyEvent.KEYCODE_BACK:
+ // Certain devices allow opening the options menu via a long press of the back
+ // button. We keep a record of whether the last event is from a long press.
+ mLongPressBackDown = (event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0;
+ break;
}
// On API v7-10 we need to manually call onKeyShortcut() as this is not called