Skip to content

Commit

Permalink
Propagate resume and pause events from PhoneGap JavaScript to PhoneGap
Browse files Browse the repository at this point in the history
native extension.

The resume and pause callbacks trigger the PluginManager on the native side,
which in turn invokes the onResume and onPause methods for each plugin.
  • Loading branch information
Justin Tyberg committed Mar 24, 2011
1 parent c726bea commit b79e055
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
34 changes: 31 additions & 3 deletions framework/ext/src/com/phonegap/api/PluginManager.java
Expand Up @@ -31,17 +31,27 @@ public final class PluginManager extends Scriptable {
/**
* Field used to invoke Plugin actions.
*/
public static final String FIELD_EXEC = "exec";
public static String FIELD_EXEC = "exec";

/**
* Field used to cleanup Plugins.
*/
public static final String FIELD_DESTROY = "destroy";
public static String FIELD_DESTROY = "destroy";

/**
* Field used to indicate application has been brought to foreground.
*/
public static String FIELD_RESUME = "resume";

/**
* Field used to indicate application has been sent to background
*/
public static String FIELD_PAUSE = "pause";

/**
* Field used to register a Plugin.
*/
public static final String FIELD_ADD_PLUGIN = "addPlugin";
public static String FIELD_ADD_PLUGIN = "addPlugin";

/**
* Loads the appropriate PhoneGap Plugins and invokes their actions.
Expand Down Expand Up @@ -103,6 +113,24 @@ public Object invoke(Object obj, Object[] oargs) throws Exception {
}
};
}
else if (name.equals(FIELD_RESUME)) {
final PluginManagerFunction plugin_mgr = this.pluginManagerFunction;
return new ScriptableFunction() {
public Object invoke(Object obj, Object[] oargs) throws Exception {
plugin_mgr.onResume();
return null;
}
};
}
else if (name.equals(FIELD_PAUSE)) {
final PluginManagerFunction plugin_mgr = this.pluginManagerFunction;
return new ScriptableFunction() {
public Object invoke(Object obj, Object[] oargs) throws Exception {
plugin_mgr.onPause();
return null;
}
};
}
else if (name.equals(FIELD_ADD_PLUGIN)) {
final PluginManager plugin_mgr = this;
return new ScriptableFunction() {
Expand Down
6 changes: 3 additions & 3 deletions framework/ext/src/com/phonegap/api/PluginManagerFunction.java
Expand Up @@ -195,7 +195,7 @@ public Plugin getPlugin(String className) {
}

/**
* Called when Plugin is paused.
* Called when application is paused.
*/
public void onPause() {
Enumeration e = this.plugins.elements();
Expand All @@ -206,7 +206,7 @@ public void onPause() {
}

/**
* Called when Plugin is resumed.
* Called when application is resumed.
*/
public void onResume() {
Enumeration e = this.plugins.elements();
Expand All @@ -217,7 +217,7 @@ public void onResume() {
}

/**
* Called when Plugin is destroyed.
* Called when application is destroyed.
*/
public void onDestroy() {
Enumeration e = this.plugins.elements();
Expand Down
6 changes: 6 additions & 0 deletions javascript/_phonegap.js
Expand Up @@ -221,6 +221,9 @@ PhoneGap.onPause = new PhoneGap.Channel('onPause');
*/
blackberry.app.event.onForeground(function() {
PhoneGap.onResume.fire();

// notify PhoneGap JavaScript Extension
phonegap.PluginManager.resume();
});

/**
Expand All @@ -229,6 +232,9 @@ blackberry.app.event.onForeground(function() {
*/
blackberry.app.event.onBackground(function() {
PhoneGap.onPause.fire();

// notify PhoneGap JavaScript Extension
phonegap.PluginManager.pause();
});

/**
Expand Down

0 comments on commit b79e055

Please sign in to comment.