// Vibrator pattern for haptic feedback of a long press.
private static final long[] LONG_PRESS_VIBE_PATTERN = {0, 1, 20, 21};
+ // Vibrator pattern for haptic feedback of virtual key press.
+ private static final long[] VIRTUAL_KEY_VIBE_PATTERN = {0, 1, 20, 21};
+
final Object mLock = new Object();
Context mContext;
}
}
- Runnable mEndCallLongPress = new Runnable() {
+ Runnable mPowerLongPress = new Runnable() {
public void run() {
mShouldTurnOffOnKeyUp = false;
performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
/** {@inheritDoc} */
public boolean interceptKeyTi(WindowState win, int code, int metaKeys, boolean down,
- int repeatCount) {
+ int repeatCount, int flags) {
boolean keyguardOn = keyguardOn();
if (false) {
if (!down) {
mHomePressed = false;
- // 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 phoneServ = getPhoneInterface();
- if (phoneServ != null) {
- incomingRinging = phoneServ.isRinging();
+ if ((flags&KeyEvent.FLAG_CANCELED) == 0) {
+ // 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 phoneServ = getPhoneInterface();
+ if (phoneServ != null) {
+ incomingRinging = phoneServ.isRinging();
+ } else {
+ Log.w(TAG, "Unable to find ITelephony interface");
+ }
+ } catch (RemoteException ex) {
+ Log.w(TAG, "RemoteException from getPhoneInterface()", ex);
+ }
+
+ if (incomingRinging) {
+ Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
} else {
- Log.w(TAG, "Unable to find ITelephony interface");
+ launchHomeFromHotKey();
}
- } catch (RemoteException ex) {
- Log.w(TAG, "RemoteException from getPhoneInterface()", ex);
- }
-
- if (incomingRinging) {
- Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
} else {
- launchHomeFromHotKey();
+ Log.i(TAG, "Ignoring HOME; event canceled.");
}
}
}
return true;
}
-
+
// First we always handle the home key here, so applications
// can never break it, although if keyguard is on, we do let
// it handle it, because that gives us the correct 5 second
boolean down = event.value != 0;
if (type == RawInputEvent.EV_KEY) {
- if (code == KeyEvent.KEYCODE_ENDCALL) {
+ if (code == KeyEvent.KEYCODE_ENDCALL
+ || code == KeyEvent.KEYCODE_POWER) {
if (down) {
boolean hungUp = false;
// key repeats are generated by the window manager, and we don't see them
// here, so unless the driver is doing something it shouldn't be, we know
// this is the real press event.
- try {
- ITelephony phoneServ = getPhoneInterface();
- if (phoneServ != null) {
- hungUp = phoneServ.endCall();
- } else {
- Log.w(TAG, "!!! Unable to find ITelephony interface !!!");
+ if (code == KeyEvent.KEYCODE_ENDCALL) {
+ try {
+ ITelephony phoneServ = getPhoneInterface();
+ if (phoneServ != null) {
+ hungUp = phoneServ.endCall();
+ } else {
+ Log.w(TAG, "!!! Unable to find ITelephony interface !!!");
+ }
+ } catch (RemoteException ex) {
+ Log.w(TAG, "ITelephony.endCall() threw RemoteException" + ex);
}
- } catch (RemoteException ex) {
- Log.w(TAG, "ITelephony.endCall() threw RemoteException" + ex);
}
if (hungUp || !screenIsOn) {
mShouldTurnOffOnKeyUp = false;
} else {
// only try to turn off the screen if we didn't already hang up
mShouldTurnOffOnKeyUp = true;
- mHandler.postDelayed(mEndCallLongPress,
+ mHandler.postDelayed(mPowerLongPress,
ViewConfiguration.getGlobalActionKeyTimeout());
result &= ~ACTION_PASS_TO_USER;
}
} else {
- mHandler.removeCallbacks(mEndCallLongPress);
+ mHandler.removeCallbacks(mPowerLongPress);
if (mShouldTurnOffOnKeyUp) {
mShouldTurnOffOnKeyUp = false;
boolean gohome = (mEndcallBehavior & ENDCALL_HOME) != 0;
return false;
}
+ public void keyFeedbackFromInput(KeyEvent event) {
+ if (event.getAction() == KeyEvent.ACTION_DOWN
+ && (event.getFlags()&KeyEvent.FLAG_VIRTUAL_HARD_KEY) != 0) {
+ mVibrator.vibrate(VIRTUAL_KEY_VIBE_PATTERN, -1);
+ }
+ }
+
public void screenOnStoppedLw() {
if (!mKeyguardMediator.isShowing()) {
long curTime = SystemClock.uptimeMillis();