Update for virtual key haptic feedback, deal with canceled keys.
This commit is contained in:
@@ -676,6 +676,10 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
|
||||
mPanelChordingKey = 0;
|
||||
mKeycodeMenuTimeoutHandler.removeMessages(MSG_MENU_LONG_PRESS);
|
||||
|
||||
if (event.isCanceled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean playSoundEffect = false;
|
||||
PanelFeatureState st = getPanelState(featureId, true);
|
||||
if (st.isOpen || st.isHandled) {
|
||||
@@ -1393,7 +1397,9 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
|
||||
mKeycodeMenuTimeoutHandler.removeMessages(MSG_CAMERA_LONG_PRESS);
|
||||
if (!mKeycodeCameraTimeoutActive) break;
|
||||
mKeycodeCameraTimeoutActive = false;
|
||||
// Add short press behavior here if desired
|
||||
if (!event.isCanceled()) {
|
||||
// Add short press behavior here if desired
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1405,7 +1411,9 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
|
||||
mKeycodeMenuTimeoutHandler.removeMessages(MSG_CALL_LONG_PRESS);
|
||||
if (!mKeycodeCallTimeoutActive) break;
|
||||
mKeycodeCallTimeoutActive = false;
|
||||
startCallActivity();
|
||||
if (!event.isCanceled()) {
|
||||
startCallActivity();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1420,7 +1428,9 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
|
||||
break;
|
||||
}
|
||||
mSearchKeyDownReceived = false;
|
||||
launchDefaultSearch();
|
||||
if (!event.isCanceled()) {
|
||||
launchDefaultSearch();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,6 +149,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
// 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;
|
||||
@@ -373,7 +376,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
}
|
||||
}
|
||||
|
||||
Runnable mEndCallLongPress = new Runnable() {
|
||||
Runnable mPowerLongPress = new Runnable() {
|
||||
public void run() {
|
||||
mShouldTurnOffOnKeyUp = false;
|
||||
performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
|
||||
@@ -775,7 +778,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public boolean interceptKeyTi(WindowState win, int code, int metaKeys, boolean down,
|
||||
int repeatCount) {
|
||||
int repeatCount, int flags) {
|
||||
boolean keyguardOn = keyguardOn();
|
||||
|
||||
if (false) {
|
||||
@@ -800,32 +803,36 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
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();
|
||||
} else {
|
||||
Log.w(TAG, "Unable to find ITelephony interface");
|
||||
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 {
|
||||
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
|
||||
@@ -1470,33 +1477,36 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
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;
|
||||
@@ -1854,6 +1864,13 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user