android HOME长按之后的键值是多少
home键在KeyEvent中的键值为3.
ublic static final int KEYCODE_HOME = 3;
当用户按下home键的时候(包括长按),程序会进入到PhoneWindowManager.java类中的public boolean interceptKeyBeforeDispatching(WindowState win, int action, int flags,int keyCode, int scanCode, int metaState, int repeatCount, int policyFlags)这个方法中进行处理。如果用户是连续点击home,此时就要执行长按home事件了。
即执行mHandler.postDelayed(mHomeLongPress,ViewConfiguration.getGlobalActionKeyTimeout());对应的代码。也就会跳转到mHomeLongPress这个Runnable接着往下执行。
interceptKeyBeforeDispatching这个方法位于PhoneWindowManager.java中。
位置为:\frameworks\base\policy\src\com\android\internal\policy\impl\PhoneWindowManager.java
public boolean interceptKeyBeforeDispatching(WindowState win, int action, int flags,
int keyCode, int scanCode, int metaState, int repeatCount, int policyFlags) {
final boolean down = (action == KeyEvent.ACTION_DOWN);
...
//4、用户按下home,然后马上释放。此时这个条件成立。将之前postDelayed的事件remove掉。此时就不会执行长按home事件。
if ((keyCode == KeyEvent.KEYCODE_HOME) && !down) {
mHandler.removeCallbacks(mHomeLongPress);
}
//5、第一次按下home,mHomePressed为false。
if (mHomePressed) {
if (keyCode == KeyEvent.KEYCODE_HOME) {
//a、如果用户连续按下home,此时暂时没有up事件。所以就不走这里。
//b、如果用户没有连续按下home,此时过来的是up(move或者http://www.tiecou.com/)事件。即!down为true,执行该方法
if (!down) {
mHomePressed = false;
if (!canceled) {
boolean incomingRinging = false;
try {
ITelephony telephonyService = getTelephonyService();
if (telephonyService != null) {
incomingRinging = telephonyService.isRinging();
}
} catch (RemoteException ex) {
Log.w(TAG, "RemoteException from getPhoneInterface()", ex);
}
if (incomingRinging) {
Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
} else {
//单击home处理
launchHomeFromHotKey();
}
} else {
Log.i(TAG, "Ignoring HOME; event canceled.");
}
}
}
return true;
}
...
// 1、第一次处理home按下
if (keyCode == KeyEvent.KEYCODE_HOME) {
// If a system window has focus, then it doesn't make sense
// right now to interact with applications.
WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
if (attrs != null) {
final int type = attrs.type;
if (type == WindowManager.LayoutParams.TYPE_KEYGUARD
|| type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG) {
// the "app" is keyguard, so give it the key
return false;
}
final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
for (int i=0; i<typeCount; i++) {
if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
// don't do anything, but also don't pass it to the app
return true;
}
}
}
// 2、第一次按下home,会调用postDelayed发送一个延时处理的操作。同时将mHomePressed置为true。
// 如果第5 步没有进入if (!down),此时就要执行长按home方法了。
if (down && repeatCount == 0) {
if (!keyguardOn) {
mHandler.postDelayed(mHomeLongPress, ViewConfiguration.getGlobalActionKeyTimeout());
}
mHomePressed = true;
}
return true;
} //其他键的处理
else if(...){...}
-----------------------------------------------------------------------------------------------------
安卓精英团为你解答
安卓精英团欢迎各位精英加入
那android 4.0的有三个虚拟按键,那第三个虚拟按键的键值是多少呢
这三个按键HOME是在PhoneWindowManager中处理的,其它的是在PhoneStatusBar里处理的。你是问这个吧?