Enable onMessage() to return a value.

This commit is contained in:
Bryce Curtis 2012-05-15 10:00:02 -05:00
parent 9f5f4973ae
commit d683bd3744
6 changed files with 24 additions and 8 deletions

View File

@ -140,8 +140,9 @@ public class AudioHandler extends Plugin {
*
* @param id The message id
* @param data The message data
* @return Object to stop propagation or null
*/
public void onMessage(String id, Object data) {
public Object onMessage(String id, Object data) {
// If phone message
if (id.equals("telephone")) {
@ -167,6 +168,7 @@ public class AudioHandler extends Plugin {
this.pausedForPhone.clear();
}
}
return null;
}
//--------------------------------------------------------------------------

View File

@ -1050,8 +1050,9 @@ public class DroidGap extends Activity implements CordovaInterface {
*
* @param id The message id
* @param data The message data
* @return Object or null
*/
public void onMessage(String id, Object data) {
public Object onMessage(String id, Object data) {
LOG.d(TAG, "onMessage(" + id + "," + data + ")");
if ("splashscreen".equals(id)) {
if ("hide".equals(data.toString())) {
@ -1079,6 +1080,7 @@ public class DroidGap extends Activity implements CordovaInterface {
else if ("exit".equals(id)) {
this.endActivity();
}
return null;
}
}

View File

@ -73,7 +73,8 @@ public interface CordovaInterface {
*
* @param id The message id
* @param data The message data
* @return Object or null
*/
public void onMessage(String id, Object data);
public Object onMessage(String id, Object data);
}

View File

@ -94,8 +94,9 @@ public interface IPlugin {
*
* @param id The message id
* @param data The message data
* @return Object to stop propagation or null
*/
public void onMessage(String id, Object data);
public Object onMessage(String id, Object data);
/**
* Called when an activity you launched exits, giving you the requestCode you started it with,

View File

@ -107,8 +107,10 @@ public abstract class Plugin implements IPlugin {
*
* @param id The message id
* @param data The message data
* @return Object to stop propagation or null
*/
public void onMessage(String id, Object data) {
public Object onMessage(String id, Object data) {
return null;
}
/**

View File

@ -314,14 +314,22 @@ public class PluginManager {
*
* @param id The message id
* @param data The message data
* @return
*/
public void postMessage(String id, Object data) {
this.ctx.onMessage(id, data);
public Object postMessage(String id, Object data) {
Object obj = this.ctx.onMessage(id, data);
if (obj != null) {
return obj;
}
for (PluginEntry entry : this.entries.values()) {
if (entry.plugin != null) {
entry.plugin.onMessage(id, data);
obj = entry.plugin.onMessage(id, data);
if (obj != null) {
return obj;
}
}
}
return null;
}
/**