From 80d0a0cb4c801e4e5fb2f74534ba9351946b5969 Mon Sep 17 00:00:00 2001 From: Bryce Curtis Date: Tue, 22 Nov 2011 14:36:00 -0600 Subject: [PATCH] Change API to postMessage() to call a plugin's onMessage() method. --- framework/src/com/phonegap/Device.java | 6 +-- framework/src/com/phonegap/DroidGap.java | 10 ++-- .../src/com/phonegap/NetworkManager.java | 2 +- .../com/phonegap/api/PhonegapActivity.java | 2 +- .../src/com/phonegap/api/PluginManager.java | 48 ++++++------------- 5 files changed, 24 insertions(+), 44 deletions(-) diff --git a/framework/src/com/phonegap/Device.java b/framework/src/com/phonegap/Device.java index 4202ef62..f752a8db 100755 --- a/framework/src/com/phonegap/Device.java +++ b/framework/src/com/phonegap/Device.java @@ -136,15 +136,15 @@ public class Device extends Plugin { String extraData = intent.getStringExtra(TelephonyManager.EXTRA_STATE); if (extraData.equals(TelephonyManager.EXTRA_STATE_RINGING)) { LOG.i(TAG, "Telephone RINGING"); - myctx.onMessage("telephone", "ringing"); + myctx.postMessage("telephone", "ringing"); } else if (extraData.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) { LOG.i(TAG, "Telephone OFFHOOK"); - myctx.onMessage("telephone", "offhook"); + myctx.postMessage("telephone", "offhook"); } else if (extraData.equals(TelephonyManager.EXTRA_STATE_IDLE)) { LOG.i(TAG, "Telephone IDLE"); - myctx.onMessage("telephone", "idle"); + myctx.postMessage("telephone", "idle"); } } } diff --git a/framework/src/com/phonegap/DroidGap.java b/framework/src/com/phonegap/DroidGap.java index 812cb0e5..97c62b31 100755 --- a/framework/src/com/phonegap/DroidGap.java +++ b/framework/src/com/phonegap/DroidGap.java @@ -840,10 +840,10 @@ public class DroidGap extends PhonegapActivity { * @param id The message id * @param data The message data */ - public void onMessage(String id, Object data) { + public void postMessage(String id, Object data) { // Forward to plugins - this.pluginManager.onMessage(id, data); + this.pluginManager.postMessage(id, data); } /** @@ -1835,21 +1835,21 @@ public class DroidGap extends PhonegapActivity { @Override public boolean onCreateOptionsMenu(Menu menu) { - this.onMessage("onCreateOptionsMenu", menu); + this.postMessage("onCreateOptionsMenu", menu); return super.onCreateOptionsMenu(menu); } @Override public boolean onPrepareOptionsMenu(Menu menu) { - this.onMessage("onPrepareOptionsMenu", menu); + this.postMessage("onPrepareOptionsMenu", menu); return super.onPrepareOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { - this.onMessage("onOptionsItemSelected", item); + this.postMessage("onOptionsItemSelected", item); return true; } } diff --git a/framework/src/com/phonegap/NetworkManager.java b/framework/src/com/phonegap/NetworkManager.java index aadac661..2be55d1a 100755 --- a/framework/src/com/phonegap/NetworkManager.java +++ b/framework/src/com/phonegap/NetworkManager.java @@ -201,7 +201,7 @@ public class NetworkManager extends Plugin { this.success(result, this.connectionCallbackId); // Send to all plugins - this.ctx.onMessage("networkconnection", type); + this.ctx.postMessage("networkconnection", type); } /** diff --git a/framework/src/com/phonegap/api/PhonegapActivity.java b/framework/src/com/phonegap/api/PhonegapActivity.java index fc5f5e27..cb3c8714 100755 --- a/framework/src/com/phonegap/api/PhonegapActivity.java +++ b/framework/src/com/phonegap/api/PhonegapActivity.java @@ -76,5 +76,5 @@ public abstract class PhonegapActivity extends Activity { * @param id The message id * @param data The message data */ - abstract public void onMessage(String id, Object data); + abstract public void postMessage(String id, Object data); } diff --git a/framework/src/com/phonegap/api/PluginManager.java b/framework/src/com/phonegap/api/PluginManager.java index db10d637..6bf9f66f 100755 --- a/framework/src/com/phonegap/api/PluginManager.java +++ b/framework/src/com/phonegap/api/PluginManager.java @@ -287,13 +287,9 @@ public final class PluginManager { * @param multitasking Flag indicating if multitasking is turned on for app */ public void onPause(boolean multitasking) { - java.util.Set> s = this.plugins.entrySet(); - java.util.Iterator> it = s.iterator(); - while(it.hasNext()) { - Entry entry = it.next(); - IPlugin plugin = entry.getValue(); - plugin.onPause(multitasking); - } + for (IPlugin plugin : this.plugins.values()) { + plugin.onPause(multitasking); + } } /** @@ -302,26 +298,18 @@ public final class PluginManager { * @param multitasking Flag indicating if multitasking is turned on for app */ public void onResume(boolean multitasking) { - java.util.Set> s = this.plugins.entrySet(); - java.util.Iterator> it = s.iterator(); - while(it.hasNext()) { - Entry entry = it.next(); - IPlugin plugin = entry.getValue(); - plugin.onResume(multitasking); - } + for (IPlugin plugin : this.plugins.values()) { + plugin.onResume(multitasking); + } } /** * The final call you receive before your activity is destroyed. */ public void onDestroy() { - java.util.Set> s = this.plugins.entrySet(); - java.util.Iterator> it = s.iterator(); - while(it.hasNext()) { - Entry entry = it.next(); - IPlugin plugin = entry.getValue(); - plugin.onDestroy(); - } + for (IPlugin plugin : this.plugins.values()) { + plugin.onDestroy(); + } } /** @@ -330,12 +318,8 @@ public final class PluginManager { * @param id The message id * @param data The message data */ - public void onMessage(String id, Object data) { - java.util.Set> s = this.plugins.entrySet(); - java.util.Iterator> it = s.iterator(); - while(it.hasNext()) { - Entry entry = it.next(); - IPlugin plugin = entry.getValue(); + public void postMessage(String id, Object data) { + for (IPlugin plugin : this.plugins.values()) { plugin.onMessage(id, data); } } @@ -344,13 +328,9 @@ public final class PluginManager { * Called when the activity receives a new intent. */ public void onNewIntent(Intent intent) { - java.util.Set> s = this.plugins.entrySet(); - java.util.Iterator> it = s.iterator(); - while(it.hasNext()) { - Entry entry = it.next(); - IPlugin plugin = entry.getValue(); - plugin.onNewIntent(intent); - } + for (IPlugin plugin : this.plugins.values()) { + plugin.onNewIntent(intent); + } } /**