From 13f92b2b76d723729e716c7aa81214803bf1ad47 Mon Sep 17 00:00:00 2001 From: Bryce Curtis Date: Mon, 14 May 2012 22:51:36 -0500 Subject: [PATCH] Add exit message. --- framework/src/org/apache/cordova/App.java | 2 +- .../apache/cordova/CordovaWebViewClient.java | 3 +- .../src/org/apache/cordova/DroidGap.java | 44 ++++++++++--------- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/framework/src/org/apache/cordova/App.java b/framework/src/org/apache/cordova/App.java index 7df0aa94..48eeb660 100755 --- a/framework/src/org/apache/cordova/App.java +++ b/framework/src/org/apache/cordova/App.java @@ -201,7 +201,7 @@ public class App extends Plugin { * Exit the Android application. */ public void exitApp() { - this.ctx.getActivity().finish(); + this.webView.postMessage("exit", null); } } diff --git a/framework/src/org/apache/cordova/CordovaWebViewClient.java b/framework/src/org/apache/cordova/CordovaWebViewClient.java index 227e251b..b118a90c 100755 --- a/framework/src/org/apache/cordova/CordovaWebViewClient.java +++ b/framework/src/org/apache/cordova/CordovaWebViewClient.java @@ -237,6 +237,7 @@ public class CordovaWebViewClient extends WebViewClient { @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); + LOG.d(TAG, "onPageFinished(" + url + ")"); /** * Because of a timing issue we need to clear this history in onPageFinished as well as @@ -286,7 +287,7 @@ public class CordovaWebViewClient extends WebViewClient { if (this.appView.callbackServer != null) { this.appView.callbackServer.destroy(); } - this.ctx.getActivity().finish(); + appView.postMessage("exit", null); } } diff --git a/framework/src/org/apache/cordova/DroidGap.java b/framework/src/org/apache/cordova/DroidGap.java index 842895d2..bccc8217 100755 --- a/framework/src/org/apache/cordova/DroidGap.java +++ b/framework/src/org/apache/cordova/DroidGap.java @@ -337,6 +337,7 @@ public class DroidGap extends Activity implements CordovaInterface { this.init(); } + // TODO @bc - background color doesn't work // If backgroundColor this.backgroundColor = this.getIntegerProperty("backgroundColor", Color.BLACK); LOG.e(TAG, "Setting background color=" + this.backgroundColor); @@ -655,6 +656,7 @@ public class DroidGap extends Activity implements CordovaInterface { * The final call you receive before your activity is destroyed. */ public void onDestroy() { + LOG.d(TAG, "onDestroy()"); super.onDestroy(); if (this.appView != null) { @@ -749,13 +751,6 @@ public class DroidGap extends Activity implements CordovaInterface { * End this activity by calling finish for activity */ public void endActivity() { - this.finish(); - } - - /** - * Finish for Activity has been called. - */ - public void finish() { this.activityState = ACTIVITY_EXITING; super.finish(); } @@ -902,21 +897,25 @@ public class DroidGap extends Activity implements CordovaInterface { final DroidGap me = this; me.runOnUiThread(new Runnable() { public void run() { - AlertDialog.Builder dlg = new AlertDialog.Builder(me); - dlg.setMessage(message); - dlg.setTitle(title); - dlg.setCancelable(false); - dlg.setPositiveButton(button, - new AlertDialog.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - if (exit) { - me.endActivity(); + try { + AlertDialog.Builder dlg = new AlertDialog.Builder(me); + dlg.setMessage(message); + dlg.setTitle(title); + dlg.setCancelable(false); + dlg.setPositiveButton(button, + new AlertDialog.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + if (exit) { + me.endActivity(); + } } - } - }); - dlg.create(); - dlg.show(); + }); + dlg.create(); + dlg.show(); + } catch (Exception e) { + finish(); + } } }); } @@ -1077,6 +1076,9 @@ public class DroidGap extends Activity implements CordovaInterface { e.printStackTrace(); } } + else if ("exit".equals(id)) { + this.endActivity(); + } } }