You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by bo...@apache.org on 2012/07/25 21:54:44 UTC
[2/2] android commit: Utility Methods based on Feedback
Utility Methods based on Feedback
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/commit/b234b0bd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/b234b0bd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/b234b0bd
Branch: refs/heads/master
Commit: b234b0bded73cf878fdc8521a337bef6b2f8fb62
Parents: b9b2c6a
Author: Joe Bowser <bo...@apache.org>
Authored: Tue Jul 24 15:54:01 2012 -0700
Committer: Joe Bowser <bo...@apache.org>
Committed: Tue Jul 24 15:54:01 2012 -0700
----------------------------------------------------------------------
.../src/org/apache/cordova/CordovaWebView.java | 58 +++++++++++++++
framework/src/org/apache/cordova/DroidGap.java | 49 +++----------
2 files changed, 69 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/b234b0bd/framework/src/org/apache/cordova/CordovaWebView.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java
index f36403b..234ff65 100755
--- a/framework/src/org/apache/cordova/CordovaWebView.java
+++ b/framework/src/org/apache/cordova/CordovaWebView.java
@@ -785,4 +785,62 @@ public class CordovaWebView extends WebView {
{
return this.bound;
}
+
+ public void handlePause(boolean keepRunning)
+ {
+ // Send pause event to JavaScript
+ this.loadUrl("javascript:try{cordova.fireDocumentEvent('pause');}catch(e){console.log('exception firing pause event from native');};");
+
+ // Forward to plugins
+ if (this.pluginManager != null) {
+ this.pluginManager.onPause(keepRunning);
+ }
+
+ // If app doesn't want to run in background
+ if (keepRunning) {
+ // Pause JavaScript timers (including setInterval)
+ this.pauseTimers();
+ }
+
+ }
+
+ public void handleResume(boolean keepRunning, boolean activityResultKeepRunning)
+ {
+
+ // Send resume event to JavaScript
+ this.loadUrl("javascript:try{cordova.fireDocumentEvent('resume');}catch(e){console.log('exception firing resume event from native');};");
+
+ // Forward to plugins
+ if (this.pluginManager != null) {
+ this.pluginManager.onResume(keepRunning);
+ }
+
+ // If app doesn't want to run in background
+ if (!keepRunning || activityResultKeepRunning) {
+ // Resume JavaScript timers (including setInterval)
+ this.resumeTimers();
+ }
+ }
+
+ public void handleDestroy()
+ {
+ // Send destroy event to JavaScript
+ this.loadUrl("javascript:try{cordova.require('cordova/channel').onDestroy.fire();}catch(e){console.log('exception firing destroy event from native');};");
+
+ // Load blank page so that JavaScript onunload is called
+ this.loadUrl("about:blank");
+
+ // Forward to plugins
+ if (this.pluginManager != null) {
+ this.pluginManager.onDestroy();
+ }
+ }
+
+ public void onNewIntent(Intent intent)
+ {
+ //Forward to plugins
+ if (this.pluginManager != null) {
+ this.pluginManager.onNewIntent(intent);
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/b234b0bd/framework/src/org/apache/cordova/DroidGap.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/DroidGap.java b/framework/src/org/apache/cordova/DroidGap.java
index fe47df4..f48e211 100755
--- a/framework/src/org/apache/cordova/DroidGap.java
+++ b/framework/src/org/apache/cordova/DroidGap.java
@@ -38,6 +38,7 @@ import android.graphics.Color;
import android.media.AudioManager;
import android.os.Bundle;
import android.os.Handler;
+import android.util.Log;
import android.view.Display;
import android.view.KeyEvent;
import android.view.Menu;
@@ -600,6 +601,8 @@ public class DroidGap extends Activity implements CordovaInterface {
protected void onPause() {
super.onPause();
+ LOG.d(TAG, "Paused the application!");
+
// Don't process pause if shutting down, since onDestroy() will be called
if (this.activityState == ACTIVITY_EXITING) {
return;
@@ -608,19 +611,9 @@ public class DroidGap extends Activity implements CordovaInterface {
if (this.appView == null) {
return;
}
-
- // Send pause event to JavaScript
- this.appView.loadUrl("javascript:try{cordova.fireDocumentEvent('pause');}catch(e){console.log('exception firing pause event from native');};");
-
- // Forward to plugins
- if (this.appView.pluginManager != null) {
- this.appView.pluginManager.onPause(this.keepRunning);
- }
-
- // If app doesn't want to run in background
- if (!this.keepRunning) {
- // Pause JavaScript timers (including setInterval)
- this.appView.pauseTimers();
+ else
+ {
+ this.appView.handlePause(this.keepRunning);
}
// hide the splash screen to avoid leaking a window
@@ -633,11 +626,9 @@ public class DroidGap extends Activity implements CordovaInterface {
**/
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
-
//Forward to plugins
- if ((this.appView != null) && (this.appView.pluginManager != null)) {
- this.appView.pluginManager.onNewIntent(intent);
- }
+ if (this.appView != null)
+ this.appView.onNewIntent(intent);
}
@Override
@@ -647,6 +638,7 @@ public class DroidGap extends Activity implements CordovaInterface {
protected void onResume() {
super.onResume();
+ LOG.d(TAG, "Resuming the App");
if (this.activityState == ACTIVITY_STARTING) {
this.activityState = ACTIVITY_RUNNING;
return;
@@ -656,13 +648,7 @@ public class DroidGap extends Activity implements CordovaInterface {
return;
}
- // Send resume event to JavaScript
- this.appView.loadUrl("javascript:try{cordova.fireDocumentEvent('resume');}catch(e){console.log('exception firing resume event from native');};");
-
- // Forward to plugins
- if (this.appView.pluginManager != null) {
- this.appView.pluginManager.onResume(this.keepRunning || this.activityResultKeepRunning);
- }
+ this.appView.handleResume(this.keepRunning, this.activityResultKeepRunning);
// If app doesn't want to run in background
if (!this.keepRunning || this.activityResultKeepRunning) {
@@ -672,9 +658,6 @@ public class DroidGap extends Activity implements CordovaInterface {
this.keepRunning = this.activityResultKeepRunning;
this.activityResultKeepRunning = false;
}
-
- // Resume JavaScript timers (including setInterval)
- this.appView.resumeTimers();
}
}
@@ -690,17 +673,7 @@ public class DroidGap extends Activity implements CordovaInterface {
this.removeSplashScreen();
if (this.appView != null) {
-
- // Send destroy event to JavaScript
- this.appView.loadUrl("javascript:try{cordova.require('cordova/channel').onDestroy.fire();}catch(e){console.log('exception firing destroy event from native');};");
-
- // Load blank page so that JavaScript onunload is called
- this.appView.loadUrl("about:blank");
-
- // Forward to plugins
- if (this.appView.pluginManager != null) {
- this.appView.pluginManager.onDestroy();
- }
+ appView.handleDestroy();
}
else {
this.endActivity();