jasmine1

如何实现双击home弹Recent APP?

0
阅读(1113)

[DESCRIPTION]

如何实现双击 home 弹RecentAPP

你可以参考如下 sample code 自行实现


[SOLUTION]

请修改 phoneWindowManager.Java 的 interceptKeyBeforeQueueing 方法

找到参考位置后, 加入注释所述代码:

//以下是原有代码, 即参考行

if (down && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0

&& event.getRepeatCount() == 0) {

performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);

}

//参考行到此结束

int result = 0; //原为 int result, 请加入初始值.

// mtk sample code for double home CLIck detection BEGIN.

//请在类中补充 boolean homeDownDoubleClick = false; 的定义

//请在类中补充 long lastHomeDownTime=0; 的定义

//请在类中补充 long lastHomeUpTime=0; 的定义

//检测原理: 检测上一次按下的 home key 与本次按下的 home key 时间间隔是否 < 500ms

//if yes, 则认为是双击 home key

if(keyCode == KeyEvent.KEYCODE_HOME){

if(down){

// this is home down

if(((event.getEventTime() - lastHomeDownTime) < 500)){

homeDownDoubleClick = true;

}else{

homeDownDoubleClick = false;

}

lastHomeDownTime = event.getEventTime();

}else{

// then home up comes

Log.d(TAG,"homeDownDoubleClick="+homeDownDoubleClick+",lastHomeDownTime="+lastHomeDownTime+",lastHomeUpTime="+lastHomeUpTime+",thi

s home up="+event.getEventTime());

if(homeDownDoubleClick && ((event.getEventTime() - lastHomeUpTime) < 500)){

Log.d(TAG,"double click on home detected");

try {

IStatusBarService statusbar = getStatusBarService();

if (statusbar != null) {

statusbar.preloadRecentApps();

statusbar.toggleRecentApps();

}

} catch (RemoteException e) {

Slog.e(TAG, "RemoteException when preloading recent apps", e);

mStatusBarService = null;

}

result |= ACTION_WAKE_UP;

return result;

}

lastHomeUpTime = event.getEventTime();

}

}

// mtk sample code for double home click detection END