forked from github/cordova-android
9.1.0添加自定义按键监听
This commit is contained in:
parent
c9108d8479
commit
ea67430285
@ -22,8 +22,12 @@ package __ID__;
|
||||
import android.os.Bundle;
|
||||
import org.apache.cordova.*;
|
||||
|
||||
import android.view.KeyEvent;
|
||||
|
||||
public class __ACTIVITY__ extends CordovaActivity
|
||||
{
|
||||
private static final int[] SCAN_KEYCODE = {520, 521, 522, 523};
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
@ -38,4 +42,19 @@ public class __ACTIVITY__ extends CordovaActivity
|
||||
// Set by <content src="index.html" /> in config.xml
|
||||
loadUrl(launchUrl);
|
||||
}
|
||||
@Override
|
||||
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||
if (keyCode >= SCAN_KEYCODE[0] && keyCode <= SCAN_KEYCODE[SCAN_KEYCODE.length - 1]) {
|
||||
}
|
||||
loadUrl("javascript:cordova.fireWindowEvent('native.onKeyUp',{keycode:"+keyCode+"})");
|
||||
return super.onKeyUp(keyCode, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode >= SCAN_KEYCODE[0] && keyCode <= SCAN_KEYCODE[SCAN_KEYCODE.length - 1]) {
|
||||
}
|
||||
loadUrl("javascript:cordova.fireWindowEvent('native.onKeyDown',{keycode:"+keyCode+"})");
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
}
|
||||
|
@ -79,6 +79,13 @@ public class SystemWebView extends WebView implements CordovaWebViewEngine.Engin
|
||||
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
if(event.getKeyCode()>=520 && event.getKeyCode() <=523){
|
||||
if (event.getAction() == KeyEvent.ACTION_UP) {
|
||||
loadUrl("javascript:cordova.fireWindowEvent('native.onKeyUp',{keycode:"+event.getKeyCode()+"})");
|
||||
} else if(event.getAction() == KeyEvent.ACTION_DOWN){
|
||||
loadUrl("javascript:cordova.fireWindowEvent('native.onKeyDown',{keycode:"+event.getKeyCode()+"})");
|
||||
}
|
||||
}
|
||||
Boolean ret = parentEngine.client.onDispatchKeyEvent(event);
|
||||
if (ret != null) {
|
||||
return ret.booleanValue();
|
||||
|
Loading…
Reference in New Issue
Block a user