Merge branch 'master' of github.com:phonegap/phonegap-android into keyboard

This commit is contained in:
Joe Bowser 2011-05-31 15:41:03 -07:00
commit d00a9f33cd
2 changed files with 48 additions and 22 deletions

View File

@ -666,21 +666,18 @@ public class DroidGap extends PhonegapActivity {
if (this.appView != null) { if (this.appView != null) {
// Make sure pause event is sent if onPause hasn't been called before onDestroy // Make sure pause event is sent if onPause hasn't been called before onDestroy
this.appView.loadUrl("javascript:try{PhoneGap.onPause.fire();}catch(e){};"); this.appView.loadUrl("javascript:try{PhoneGap.onPause.fire();}catch(e){};");
// Send destroy event to JavaScript // Send destroy event to JavaScript
this.appView.loadUrl("javascript:try{PhoneGap.onDestroy.fire();}catch(e){};"); this.appView.loadUrl("javascript:try{PhoneGap.onDestroy.fire();}catch(e){};");
// Load blank page so that JavaScript onunload is called // Load blank page so that JavaScript onunload is called
this.appView.loadUrl("about:blank"); this.appView.loadUrl("about:blank");
// Forward to plugins // Forward to plugins
this.pluginManager.onDestroy(); this.pluginManager.onDestroy();
if (this.callbackServer != null) {
this.callbackServer.destroy();
}
} }
} }
@ -1073,7 +1070,9 @@ public class DroidGap extends PhonegapActivity {
// Try firing the onNativeReady event in JS. If it fails because the JS is // 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 // 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. // from the JS side when the JS gets to that code.
appView.loadUrl("javascript:try{ PhoneGap.onNativeReady.fire();}catch(e){_nativeReady = true;}"); if (!url.equals("about:blank")) {
appView.loadUrl("javascript:try{ PhoneGap.onNativeReady.fire();}catch(e){_nativeReady = true;}");
}
// Make app view visible // Make app view visible
appView.setVisibility(View.VISIBLE); appView.setVisibility(View.VISIBLE);
@ -1089,6 +1088,13 @@ public class DroidGap extends PhonegapActivity {
this.ctx.clearHistory = false; this.ctx.clearHistory = false;
this.ctx.appView.clearHistory(); this.ctx.appView.clearHistory();
} }
// Shutdown if blank loaded
if (url.equals("about:blank")) {
if (this.ctx.callbackServer != null) {
this.ctx.callbackServer.destroy();
}
}
} }
/** /**

View File

@ -57,13 +57,15 @@ public class NetworkManager extends Plugin {
private static final String LOG_TAG = "NetworkManager"; private static final String LOG_TAG = "NetworkManager";
private String connectionCallbackId; private String connectionCallbackId;
ConnectivityManager sockMan; ConnectivityManager sockMan;
TelephonyManager telephonyManager; TelephonyManager telephonyManager;
BroadcastReceiver receiver;
/** /**
* Constructor. * Constructor.
*/ */
public NetworkManager() { public NetworkManager() {
this.receiver = null;
} }
/** /**
@ -76,18 +78,23 @@ public class NetworkManager extends Plugin {
super.setContext(ctx); super.setContext(ctx);
this.sockMan = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); this.sockMan = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
this.telephonyManager = ((TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE)); this.telephonyManager = ((TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE));
this.connectionCallbackId = null;
// We need to listen to connectivity events to update navigator.connection // We need to listen to connectivity events to update navigator.connection
IntentFilter intentFilter = new IntentFilter() ; IntentFilter intentFilter = new IntentFilter() ;
intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
ctx.registerReceiver(new BroadcastReceiver() { if (this.receiver == null) {
@Override this.receiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) { @Override
updateConnectionInfo((NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO)); public void onReceive(Context context, Intent intent) {
} updateConnectionInfo((NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO));
}, intentFilter); }
} };
ctx.registerReceiver(this.receiver, intentFilter);
}
}
/** /**
* Executes the request and returns PluginResult. * Executes the request and returns PluginResult.
* *
@ -135,6 +142,19 @@ public class NetworkManager extends Plugin {
// All methods take a while, so always use async // All methods take a while, so always use async
return false; return false;
} }
/**
* Stop network receiver.
*/
public void onDestroy() {
if (this.receiver != null) {
try {
this.ctx.unregisterReceiver(this.receiver);
} catch (Exception e) {
System.out.println("Error unregistering network receiver: " + e.getMessage());
}
}
}
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
// LOCAL METHODS // LOCAL METHODS