mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-07 23:03:11 +08:00
Make sure JavaScript PhoneGap code is initialized and deviceready is fired for a new HTML page loaded from link in initial index.html.
This commit is contained in:
parent
9f1730ae47
commit
13679fe00d
@ -110,7 +110,7 @@ PhoneGap.Channel.join = function(h, c) {
|
|||||||
(!c[j].fired?c[j].subscribeOnce(f):i--);
|
(!c[j].fired?c[j].subscribeOnce(f):i--);
|
||||||
}
|
}
|
||||||
if (!i) h();
|
if (!i) h();
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -152,7 +152,9 @@ PhoneGap.onNativeReady = new PhoneGap.Channel();
|
|||||||
// _nativeReady is global variable that the native side can set
|
// _nativeReady is global variable that the native side can set
|
||||||
// to signify that the native code is ready. It is a global since
|
// to signify that the native code is ready. It is a global since
|
||||||
// it may be called before any PhoneGap JS is ready.
|
// it may be called before any PhoneGap JS is ready.
|
||||||
|
try {
|
||||||
if (_nativeReady) { PhoneGap.onNativeReady.fire(); }
|
if (_nativeReady) { PhoneGap.onNativeReady.fire(); }
|
||||||
|
} catch (e) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* onDeviceReady is fired only after both onDOMContentLoaded and
|
* onDeviceReady is fired only after both onDOMContentLoaded and
|
||||||
@ -166,6 +168,11 @@ PhoneGap.onDeviceReady.subscribeOnce(function() {
|
|||||||
|
|
||||||
PhoneGap.Channel.join(function() {
|
PhoneGap.Channel.join(function() {
|
||||||
PhoneGap.onDeviceReady.fire();
|
PhoneGap.onDeviceReady.fire();
|
||||||
|
|
||||||
|
// Fire the onresume event, since first one happens before JavaScript is loaded
|
||||||
|
var e = document.createEvent('Events');
|
||||||
|
e.initEvent('onresume');
|
||||||
|
document.dispatchEvent(e);
|
||||||
}, [ PhoneGap.onDOMContentLoaded, PhoneGap.onNativeReady ]);
|
}, [ PhoneGap.onDOMContentLoaded, PhoneGap.onNativeReady ]);
|
||||||
|
|
||||||
|
|
||||||
@ -326,4 +333,5 @@ PhoneGap.close = function(context, func, params) {
|
|||||||
return func.apply(context, params);
|
return func.apply(context, params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
@ -108,6 +108,8 @@ public class DroidGap extends Activity {
|
|||||||
appView.setWebChromeClient(new GapClient(this));
|
appView.setWebChromeClient(new GapClient(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
appView.setWebViewClient(new GapViewClient(this));
|
||||||
|
|
||||||
appView.setInitialScale(100);
|
appView.setInitialScale(100);
|
||||||
appView.setVerticalScrollBarEnabled(false);
|
appView.setVerticalScrollBarEnabled(false);
|
||||||
|
|
||||||
@ -387,6 +389,21 @@ public class DroidGap extends Activity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class GapViewClient extends WebViewClient {
|
||||||
|
|
||||||
|
Context mCtx;
|
||||||
|
|
||||||
|
public GapViewClient(Context ctx) {
|
||||||
|
mCtx = ctx;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPageFinished (WebView view, String url) {
|
||||||
|
// Try firing the onNativeReady event in JS. If it fails because the JS is
|
||||||
|
// not loaded yet then just set a flag so that the onNativeReady can be fired
|
||||||
|
// from the JS side when the JS gets to that code.
|
||||||
|
appView.loadUrl("javascript:try{ PhoneGap.onNativeReady.fire(); console.log('FIRE!');}catch(e){_nativeReady = true; console.log('native=TRUE');}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event)
|
public boolean onKeyDown(int keyCode, KeyEvent event)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user