summaryrefslogtreecommitdiffstats
path: root/policy
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2013-05-09 13:34:33 -0700
committerJeff Brown <jeffbrown@google.com>2013-05-20 23:34:03 +0000
commitcaca88150cc22a9324b6fed89ecdf394e68cf6f8 (patch)
treee617655e497ad00d9d9e5e4ae93d34788e9ba6f2 /policy
parentb11672de5272f6dcf7e8f4a9d88f2925cdc4c2dd (diff)
downloadframeworks_base-caca88150cc22a9324b6fed89ecdf394e68cf6f8.zip
frameworks_base-caca88150cc22a9324b6fed89ecdf394e68cf6f8.tar.gz
frameworks_base-caca88150cc22a9324b6fed89ecdf394e68cf6f8.tar.bz2
Support double-tap home to go to recents.
Add config resources to enable the following behavior for certain devices: * press home - go home * long-press home - launch assist intent * double-tap home - open recents Bug: 8891502 Change-Id: I4564d9e4d127f782ed5bd8eb613ef8f2255176cc (cherry picked from commit b7805698035622a633b2d76f7ca60169aaa9f0ca)
Diffstat (limited to 'policy')
-rw-r--r--policy/src/com/android/internal/policy/impl/PhoneWindowManager.java235
1 files changed, 143 insertions, 92 deletions
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
index ba51671..a4275a3 100644
--- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -141,6 +141,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
// core/res/res/values/config.xml
static final int LONG_PRESS_HOME_NOTHING = 0;
static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
+ static final int LONG_PRESS_HOME_ASSIST = 2;
+
+ static final int DOUBLE_TAP_HOME_NOTHING = 0;
+ static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
static final int APPLICATION_MEDIA_SUBLAYER = -2;
static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
@@ -195,6 +199,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
WindowManagerFuncs mWindowManagerFuncs;
PowerManager mPowerManager;
IStatusBarService mStatusBarService;
+ boolean mPreloadedRecentApps;
final Object mServiceAquireLock = new Object();
Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
SearchManager mSearchManager;
@@ -399,7 +404,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
boolean mShowingDream;
boolean mDreamingLockscreen;
boolean mHomePressed;
- boolean mHomeLongPressed;
+ boolean mHomeConsumed;
+ boolean mHomeDoubleTapPending;
Intent mHomeIntent;
Intent mCarDockIntent;
Intent mDeskDockIntent;
@@ -432,7 +438,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
int mOverscanBottom = 0;
// What we do when the user long presses on home
- private int mLongPressOnHomeBehavior = -1;
+ private int mLongPressOnHomeBehavior;
+
+ // What we do when the user double-taps on home
+ private int mDoubleTapOnHomeBehavior;
// Screenshot trigger states
// Time to volume and power must be pressed within this interval of each other.
@@ -743,36 +752,35 @@ public class PhoneWindowManager implements WindowManagerPolicy {
}
private void handleLongPressOnHome() {
- // We can't initialize this in init() since the configuration hasn't been loaded yet.
- if (mLongPressOnHomeBehavior < 0) {
- mLongPressOnHomeBehavior
- = mContext.getResources().getInteger(R.integer.config_longPressOnHomeBehavior);
- if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
- mLongPressOnHomeBehavior > LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
- mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
- }
- }
-
if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
+ mHomeConsumed = true;
performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
- sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS);
- // Eat the longpress so it won't dismiss the recent apps dialog when
- // the user lets go of the home key
- mHomeLongPressed = true;
- try {
- IStatusBarService statusbar = getStatusBarService();
- if (statusbar != null) {
- statusbar.toggleRecentApps();
- }
- } catch (RemoteException e) {
- Slog.e(TAG, "RemoteException when showing recent apps", e);
- // re-acquire status bar service next time it is needed.
- mStatusBarService = null;
+ if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
+ toggleRecentApps();
+ } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
+ launchAssistAction();
}
}
}
+ private void handleDoubleTapOnHome() {
+ if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
+ mHomeConsumed = true;
+ toggleRecentApps();
+ }
+ }
+
+ private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
+ @Override
+ public void run() {
+ if (mHomeDoubleTapPending) {
+ mHomeDoubleTapPending = false;
+ launchHomeFromHotKey();
+ }
+ }
+ };
+
/**
* Create (if necessary) and show or dismiss the recent apps dialog according
* according to the requested behavior.
@@ -877,6 +885,21 @@ public class PhoneWindowManager implements WindowManagerPolicy {
com.android.internal.R.integer.config_lidNavigationAccessibility);
mLidControlsSleep = mContext.getResources().getBoolean(
com.android.internal.R.bool.config_lidControlsSleep);
+
+ mLongPressOnHomeBehavior = mContext.getResources().getInteger(
+ com.android.internal.R.integer.config_longPressOnHomeBehavior);
+ if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
+ mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
+ mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
+ }
+
+ mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
+ com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
+ if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
+ mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
+ mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
+ }
+
// register for dock events
IntentFilter filter = new IntentFilter();
filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
@@ -1902,48 +1925,44 @@ public class PhoneWindowManager implements WindowManagerPolicy {
// If we have released the home key, and didn't do anything else
// while it was pressed, then it is time to go home!
if (!down) {
- final boolean homeWasLongPressed = mHomeLongPressed;
+ cancelPreloadRecentApps();
+
mHomePressed = false;
- mHomeLongPressed = false;
- if (!homeWasLongPressed) {
- if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
- try {
- IStatusBarService statusbar = getStatusBarService();
- if (statusbar != null) {
- statusbar.cancelPreloadRecentApps();
- }
- } catch (RemoteException e) {
- Slog.e(TAG, "RemoteException when showing recent apps", e);
- // re-acquire status bar service next time it is needed.
- mStatusBarService = null;
- }
- }
+ if (mHomeConsumed) {
+ mHomeConsumed = false;
+ return -1;
+ }
- mHomePressed = false;
- if (!canceled) {
- // If an incoming call is ringing, HOME is totally disabled.
- // (The user is already on the InCallScreen at this point,
- // and his ONLY options are to answer or reject the call.)
- boolean incomingRinging = false;
- try {
- ITelephony telephonyService = getTelephonyService();
- if (telephonyService != null) {
- incomingRinging = telephonyService.isRinging();
- }
- } catch (RemoteException ex) {
- Log.w(TAG, "RemoteException from getPhoneInterface()", ex);
- }
+ if (canceled) {
+ Log.i(TAG, "Ignoring HOME; event canceled.");
+ return -1;
+ }
- if (incomingRinging) {
- Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
- } else {
- launchHomeFromHotKey();
- }
- } else {
- Log.i(TAG, "Ignoring HOME; event canceled.");
+ // If an incoming call is ringing, HOME is totally disabled.
+ // (The user is already on the InCallScreen at this point,
+ // and his ONLY options are to answer or reject the call.)
+ try {
+ ITelephony telephonyService = getTelephonyService();
+ if (telephonyService != null && telephonyService.isRinging()) {
+ Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
+ return -1;
}
+ } catch (RemoteException ex) {
+ Log.w(TAG, "RemoteException from getPhoneInterface()", ex);
+ }
+
+ // Delay handling home if a double-tap is possible.
+ if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
+ mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
+ mHomeDoubleTapPending = true;
+ mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
+ ViewConfiguration.getDoubleTapTimeout());
return -1;
}
+
+ // Go home!
+ launchHomeFromHotKey();
+ return -1;
}
// If a system window has focus, then it doesn't make sense
@@ -1964,25 +1983,21 @@ public class PhoneWindowManager implements WindowManagerPolicy {
}
}
}
- if (down) {
- if (!mHomePressed && mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
- try {
- IStatusBarService statusbar = getStatusBarService();
- if (statusbar != null) {
- statusbar.preloadRecentApps();
- }
- } catch (RemoteException e) {
- Slog.e(TAG, "RemoteException when preloading recent apps", e);
- // re-acquire status bar service next time it is needed.
- mStatusBarService = null;
- }
+
+ // Remember that home is pressed and handle special actions.
+ if (repeatCount == 0) {
+ mHomePressed = true;
+ if (mHomeDoubleTapPending) {
+ mHomeDoubleTapPending = false;
+ mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
+ handleDoubleTapOnHome();
+ } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
+ || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
+ preloadRecentApps();
}
- if (repeatCount == 0) {
- mHomePressed = true;
- } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
- if (!keyguardOn) {
- handleLongPressOnHome();
- }
+ } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
+ if (!keyguardOn) {
+ handleLongPressOnHome();
}
}
return -1;
@@ -2029,19 +2044,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
return 0;
} else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
if (!keyguardOn) {
- try {
- IStatusBarService statusbar = getStatusBarService();
- if (statusbar != null) {
- if (down && repeatCount == 0) {
- statusbar.preloadRecentApps();
- } else if (!down) {
- statusbar.toggleRecentApps();
- }
- }
- } catch (RemoteException e) {
- Slog.e(TAG, "RemoteException when preloading recent apps", e);
- // re-acquire status bar service next time it is needed.
- mStatusBarService = null;
+ if (down && repeatCount == 0) {
+ preloadRecentApps();
+ } else if (!down) {
+ toggleRecentApps();
}
}
return -1;
@@ -2307,6 +2313,51 @@ public class PhoneWindowManager implements WindowManagerPolicy {
return mSearchManager;
}
+ private void preloadRecentApps() {
+ mPreloadedRecentApps = true;
+ try {
+ IStatusBarService statusbar = getStatusBarService();
+ if (statusbar != null) {
+ statusbar.preloadRecentApps();
+ }
+ } catch (RemoteException e) {
+ Slog.e(TAG, "RemoteException when preloading recent apps", e);
+ // re-acquire status bar service next time it is needed.
+ mStatusBarService = null;
+ }
+ }
+
+ private void cancelPreloadRecentApps() {
+ if (mPreloadedRecentApps) {
+ mPreloadedRecentApps = false;
+ try {
+ IStatusBarService statusbar = getStatusBarService();
+ if (statusbar != null) {
+ statusbar.cancelPreloadRecentApps();
+ }
+ } catch (RemoteException e) {
+ Slog.e(TAG, "RemoteException when showing recent apps", e);
+ // re-acquire status bar service next time it is needed.
+ mStatusBarService = null;
+ }
+ }
+ }
+
+ private void toggleRecentApps() {
+ mPreloadedRecentApps = false; // preloading no longer needs to be canceled
+ sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS);
+ try {
+ IStatusBarService statusbar = getStatusBarService();
+ if (statusbar != null) {
+ statusbar.toggleRecentApps();
+ }
+ } catch (RemoteException e) {
+ Slog.e(TAG, "RemoteException when showing recent apps", e);
+ // re-acquire status bar service next time it is needed.
+ mStatusBarService = null;
+ }
+ }
+
/**
* A home key -> launch home action was detected. Take the appropriate action
* given the situation with the keyguard.