Change API to postMessage() to call a plugin's onMessage() method.

This commit is contained in:
Bryce Curtis 2011-11-22 14:36:00 -06:00
parent 63ae953432
commit 798cb3e347
5 changed files with 24 additions and 44 deletions

View File

@ -136,15 +136,15 @@ public class Device extends Plugin {
String extraData = intent.getStringExtra(TelephonyManager.EXTRA_STATE); String extraData = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if (extraData.equals(TelephonyManager.EXTRA_STATE_RINGING)) { if (extraData.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
LOG.i(TAG, "Telephone RINGING"); LOG.i(TAG, "Telephone RINGING");
myctx.onMessage("telephone", "ringing"); myctx.postMessage("telephone", "ringing");
} }
else if (extraData.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) { else if (extraData.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
LOG.i(TAG, "Telephone OFFHOOK"); LOG.i(TAG, "Telephone OFFHOOK");
myctx.onMessage("telephone", "offhook"); myctx.postMessage("telephone", "offhook");
} }
else if (extraData.equals(TelephonyManager.EXTRA_STATE_IDLE)) { else if (extraData.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
LOG.i(TAG, "Telephone IDLE"); LOG.i(TAG, "Telephone IDLE");
myctx.onMessage("telephone", "idle"); myctx.postMessage("telephone", "idle");
} }
} }
} }

View File

@ -840,10 +840,10 @@ public class DroidGap extends PhonegapActivity {
* @param id The message id * @param id The message id
* @param data The message data * @param data The message data
*/ */
public void onMessage(String id, Object data) { public void postMessage(String id, Object data) {
// Forward to plugins // Forward to plugins
this.pluginManager.onMessage(id, data); this.pluginManager.postMessage(id, data);
} }
/** /**
@ -1835,21 +1835,21 @@ public class DroidGap extends PhonegapActivity {
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) public boolean onCreateOptionsMenu(Menu menu)
{ {
this.onMessage("onCreateOptionsMenu", menu); this.postMessage("onCreateOptionsMenu", menu);
return super.onCreateOptionsMenu(menu); return super.onCreateOptionsMenu(menu);
} }
@Override @Override
public boolean onPrepareOptionsMenu(Menu menu) public boolean onPrepareOptionsMenu(Menu menu)
{ {
this.onMessage("onPrepareOptionsMenu", menu); this.postMessage("onPrepareOptionsMenu", menu);
return super.onPrepareOptionsMenu(menu); return super.onPrepareOptionsMenu(menu);
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) public boolean onOptionsItemSelected(MenuItem item)
{ {
this.onMessage("onOptionsItemSelected", item); this.postMessage("onOptionsItemSelected", item);
return true; return true;
} }
} }

View File

@ -201,7 +201,7 @@ public class NetworkManager extends Plugin {
this.success(result, this.connectionCallbackId); this.success(result, this.connectionCallbackId);
// Send to all plugins // Send to all plugins
this.ctx.onMessage("networkconnection", type); this.ctx.postMessage("networkconnection", type);
} }
/** /**

View File

@ -76,5 +76,5 @@ public abstract class PhonegapActivity extends Activity {
* @param id The message id * @param id The message id
* @param data The message data * @param data The message data
*/ */
abstract public void onMessage(String id, Object data); abstract public void postMessage(String id, Object data);
} }

View File

@ -287,13 +287,9 @@ public final class PluginManager {
* @param multitasking Flag indicating if multitasking is turned on for app * @param multitasking Flag indicating if multitasking is turned on for app
*/ */
public void onPause(boolean multitasking) { public void onPause(boolean multitasking) {
java.util.Set<Entry<String,IPlugin>> s = this.plugins.entrySet(); for (IPlugin plugin : this.plugins.values()) {
java.util.Iterator<Entry<String,IPlugin>> it = s.iterator(); plugin.onPause(multitasking);
while(it.hasNext()) { }
Entry<String,IPlugin> entry = it.next();
IPlugin plugin = entry.getValue();
plugin.onPause(multitasking);
}
} }
/** /**
@ -302,26 +298,18 @@ public final class PluginManager {
* @param multitasking Flag indicating if multitasking is turned on for app * @param multitasking Flag indicating if multitasking is turned on for app
*/ */
public void onResume(boolean multitasking) { public void onResume(boolean multitasking) {
java.util.Set<Entry<String,IPlugin>> s = this.plugins.entrySet(); for (IPlugin plugin : this.plugins.values()) {
java.util.Iterator<Entry<String,IPlugin>> it = s.iterator(); plugin.onResume(multitasking);
while(it.hasNext()) { }
Entry<String,IPlugin> entry = it.next();
IPlugin plugin = entry.getValue();
plugin.onResume(multitasking);
}
} }
/** /**
* The final call you receive before your activity is destroyed. * The final call you receive before your activity is destroyed.
*/ */
public void onDestroy() { public void onDestroy() {
java.util.Set<Entry<String,IPlugin>> s = this.plugins.entrySet(); for (IPlugin plugin : this.plugins.values()) {
java.util.Iterator<Entry<String,IPlugin>> it = s.iterator(); plugin.onDestroy();
while(it.hasNext()) { }
Entry<String,IPlugin> entry = it.next();
IPlugin plugin = entry.getValue();
plugin.onDestroy();
}
} }
/** /**
@ -330,12 +318,8 @@ public final class PluginManager {
* @param id The message id * @param id The message id
* @param data The message data * @param data The message data
*/ */
public void onMessage(String id, Object data) { public void postMessage(String id, Object data) {
java.util.Set<Entry<String,IPlugin>> s = this.plugins.entrySet(); for (IPlugin plugin : this.plugins.values()) {
java.util.Iterator<Entry<String,IPlugin>> it = s.iterator();
while(it.hasNext()) {
Entry<String,IPlugin> entry = it.next();
IPlugin plugin = entry.getValue();
plugin.onMessage(id, data); plugin.onMessage(id, data);
} }
} }
@ -344,13 +328,9 @@ public final class PluginManager {
* Called when the activity receives a new intent. * Called when the activity receives a new intent.
*/ */
public void onNewIntent(Intent intent) { public void onNewIntent(Intent intent) {
java.util.Set<Entry<String,IPlugin>> s = this.plugins.entrySet(); for (IPlugin plugin : this.plugins.values()) {
java.util.Iterator<Entry<String,IPlugin>> it = s.iterator(); plugin.onNewIntent(intent);
while(it.hasNext()) { }
Entry<String,IPlugin> entry = it.next();
IPlugin plugin = entry.getValue();
plugin.onNewIntent(intent);
}
} }
/** /**