mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 15:12:51 +08:00
Merge branch 'master' into 4.0.x (loadUrl->sendEvent)
Conflicts: framework/src/org/apache/cordova/CordovaWebView.java
This commit is contained in:
commit
311bdbd360
21
framework/assets/www/cordova.js
vendored
21
framework/assets/www/cordova.js
vendored
@ -1,5 +1,5 @@
|
||||
// Platform: android
|
||||
// 12489aed3d93ecc98adfc2091fe566067f2d39fc
|
||||
// 07125ef9d481fab81c2c29eafec253846f05a8ca
|
||||
/*
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
@ -1555,12 +1555,27 @@ function onMessageFromNative(msg) {
|
||||
|
||||
switch (action)
|
||||
{
|
||||
// Button events
|
||||
case 'backbutton':
|
||||
case 'menubutton':
|
||||
case 'searchbutton':
|
||||
// App life cycle events
|
||||
case 'pause':
|
||||
case 'resume':
|
||||
// Keyboard events
|
||||
case 'hidekeyboard':
|
||||
case 'showkeyboard':
|
||||
cordova.fireDocumentEvent(action);
|
||||
// Volume events
|
||||
case 'volumedownbutton':
|
||||
case 'volumeupbutton':
|
||||
try {
|
||||
cordova.fireDocumentEvent(action);
|
||||
} catch(e) {
|
||||
console.log('exception firing ' + action + ' event from native:' + e);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new Error('Unknown event action ' + msg.action);
|
||||
throw new Error('Unknown event action ' + action);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,6 +89,7 @@ public class AndroidWebView extends WebView implements CordovaWebView {
|
||||
private Whitelist internalWhitelist;
|
||||
private Whitelist externalWhitelist;
|
||||
private CordovaPreferences preferences;
|
||||
private CoreAndroid appPlugin;
|
||||
// The URL passed to loadUrl(), not necessarily the URL of the current page.
|
||||
String loadedUrl;
|
||||
|
||||
@ -471,11 +472,11 @@ public class AndroidWebView extends WebView implements CordovaWebView {
|
||||
if(boundKeyCodes.contains(keyCode))
|
||||
{
|
||||
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
|
||||
this.loadUrl("javascript:cordova.fireDocumentEvent('volumedownbutton');");
|
||||
sendJavascriptEvent("volumedownbutton");
|
||||
return true;
|
||||
}
|
||||
else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
|
||||
this.loadUrl("javascript:cordova.fireDocumentEvent('volumeupbutton');");
|
||||
sendJavascriptEvent("volumeupbutton");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@ -519,7 +520,7 @@ public class AndroidWebView extends WebView implements CordovaWebView {
|
||||
// The webview is currently displayed
|
||||
// If back key is bound, then send event to JavaScript
|
||||
if (isButtonPlumbedToJs(KeyEvent.KEYCODE_BACK)) {
|
||||
this.loadUrl("javascript:cordova.fireDocumentEvent('backbutton');");
|
||||
sendJavascriptEvent("backbutton");
|
||||
return true;
|
||||
} else {
|
||||
// If not bound
|
||||
@ -534,14 +535,14 @@ public class AndroidWebView extends WebView implements CordovaWebView {
|
||||
// Legacy
|
||||
else if (keyCode == KeyEvent.KEYCODE_MENU) {
|
||||
if (this.lastMenuEventTime < event.getEventTime()) {
|
||||
this.loadUrl("javascript:cordova.fireDocumentEvent('menubutton');");
|
||||
sendJavascriptEvent("menubutton");
|
||||
}
|
||||
this.lastMenuEventTime = event.getEventTime();
|
||||
return super.onKeyUp(keyCode, event);
|
||||
}
|
||||
// If search key
|
||||
else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
|
||||
this.loadUrl("javascript:cordova.fireDocumentEvent('searchbutton');");
|
||||
sendJavascriptEvent("searchbutton");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -549,6 +550,18 @@ public class AndroidWebView extends WebView implements CordovaWebView {
|
||||
return super.onKeyUp(keyCode, event);
|
||||
}
|
||||
|
||||
private void sendJavascriptEvent(String event) {
|
||||
if (appPlugin == null) {
|
||||
appPlugin = (CoreAndroid)this.pluginManager.getPlugin(CoreAndroid.PLUGIN_NAME);
|
||||
}
|
||||
|
||||
if (appPlugin == null) {
|
||||
LOG.w(TAG, "Unable to fire event without existing plugin");
|
||||
return;
|
||||
}
|
||||
appPlugin.fireJavascriptEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setButtonPlumbedToJs(int keyCode, boolean override) {
|
||||
switch (keyCode) {
|
||||
@ -577,7 +590,7 @@ public class AndroidWebView extends WebView implements CordovaWebView {
|
||||
{
|
||||
LOG.d(TAG, "Handle the pause");
|
||||
// Send pause event to JavaScript
|
||||
this.loadUrl("javascript:try{cordova.fireDocumentEvent('pause');}catch(e){console.log('exception firing pause event from native');};");
|
||||
sendJavascriptEvent("pause");
|
||||
|
||||
// Forward to plugins
|
||||
if (this.pluginManager != null) {
|
||||
@ -593,7 +606,7 @@ public class AndroidWebView extends WebView implements CordovaWebView {
|
||||
|
||||
public void handleResume(boolean keepRunning, boolean activityResultKeepRunning)
|
||||
{
|
||||
this.loadUrl("javascript:try{cordova.fireDocumentEvent('resume');}catch(e){console.log('exception firing resume event from native');};");
|
||||
sendJavascriptEvent("resume");
|
||||
|
||||
// Forward to plugins
|
||||
if (this.pluginManager != null) {
|
||||
|
Loading…
Reference in New Issue
Block a user