Update PluginManager to accept plugins that implement IPlugin rather than extend Plugin

This commit is contained in:
Dave Johnson 2011-07-07 00:08:11 -07:00
parent ce9d577415
commit 090890b22a

View File

@ -27,7 +27,7 @@ import android.webkit.WebView;
*/ */
public final class PluginManager { public final class PluginManager {
private HashMap<String, Plugin> plugins = new HashMap<String,Plugin>(); private HashMap<String, IPlugin> plugins = new HashMap<String,IPlugin>();
private HashMap<String, String> services = new HashMap<String,String>(); private HashMap<String, String> services = new HashMap<String,String>();
private final PhonegapActivity ctx; private final PhonegapActivity ctx;
@ -105,7 +105,7 @@ public final class PluginManager {
c = getClassByName(clazz); c = getClassByName(clazz);
} }
if (isPhoneGapPlugin(c)) { if (isPhoneGapPlugin(c)) {
final Plugin plugin = this.addPlugin(clazz, c); final IPlugin plugin = this.addPlugin(clazz, c);
final PhonegapActivity ctx = this.ctx; final PhonegapActivity ctx = this.ctx;
runAsync = async && !plugin.isSynch(action); runAsync = async && !plugin.isSynch(action);
if (runAsync) { if (runAsync) {
@ -201,12 +201,12 @@ public final class PluginManager {
* @return The plugin * @return The plugin
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private Plugin addPlugin(String className, Class clazz) { private IPlugin addPlugin(String className, Class clazz) {
if (this.plugins.containsKey(className)) { if (this.plugins.containsKey(className)) {
return this.getPlugin(className); return this.getPlugin(className);
} }
try { try {
Plugin plugin = (Plugin)clazz.newInstance(); IPlugin plugin = (IPlugin)clazz.newInstance();
this.plugins.put(className, plugin); this.plugins.put(className, plugin);
plugin.setContext(this.ctx); plugin.setContext(this.ctx);
plugin.setView(this.app); plugin.setView(this.app);
@ -225,8 +225,8 @@ public final class PluginManager {
* @param className The class of the loaded plugin. * @param className The class of the loaded plugin.
* @return * @return
*/ */
private Plugin getPlugin(String className) { private IPlugin getPlugin(String className) {
Plugin plugin = this.plugins.get(className); IPlugin plugin = this.plugins.get(className);
return plugin; return plugin;
} }
@ -247,11 +247,11 @@ 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,Plugin>> s = this.plugins.entrySet(); java.util.Set<Entry<String,IPlugin>> s = this.plugins.entrySet();
java.util.Iterator<Entry<String,Plugin>> it = s.iterator(); java.util.Iterator<Entry<String,IPlugin>> it = s.iterator();
while(it.hasNext()) { while(it.hasNext()) {
Entry<String,Plugin> entry = it.next(); Entry<String,IPlugin> entry = it.next();
Plugin plugin = entry.getValue(); IPlugin plugin = entry.getValue();
plugin.onPause(multitasking); plugin.onPause(multitasking);
} }
} }
@ -262,11 +262,11 @@ 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,Plugin>> s = this.plugins.entrySet(); java.util.Set<Entry<String,IPlugin>> s = this.plugins.entrySet();
java.util.Iterator<Entry<String,Plugin>> it = s.iterator(); java.util.Iterator<Entry<String,IPlugin>> it = s.iterator();
while(it.hasNext()) { while(it.hasNext()) {
Entry<String,Plugin> entry = it.next(); Entry<String,IPlugin> entry = it.next();
Plugin plugin = entry.getValue(); IPlugin plugin = entry.getValue();
plugin.onResume(multitasking); plugin.onResume(multitasking);
} }
} }
@ -275,11 +275,11 @@ public final class PluginManager {
* 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,Plugin>> s = this.plugins.entrySet(); java.util.Set<Entry<String,IPlugin>> s = this.plugins.entrySet();
java.util.Iterator<Entry<String,Plugin>> it = s.iterator(); java.util.Iterator<Entry<String,IPlugin>> it = s.iterator();
while(it.hasNext()) { while(it.hasNext()) {
Entry<String,Plugin> entry = it.next(); Entry<String,IPlugin> entry = it.next();
Plugin plugin = entry.getValue(); IPlugin plugin = entry.getValue();
plugin.onDestroy(); plugin.onDestroy();
} }
} }
@ -288,11 +288,11 @@ 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,Plugin>> s = this.plugins.entrySet(); java.util.Set<Entry<String,IPlugin>> s = this.plugins.entrySet();
java.util.Iterator<Entry<String,Plugin>> it = s.iterator(); java.util.Iterator<Entry<String,IPlugin>> it = s.iterator();
while(it.hasNext()) { while(it.hasNext()) {
Entry<String,Plugin> entry = it.next(); Entry<String,IPlugin> entry = it.next();
Plugin plugin = entry.getValue(); IPlugin plugin = entry.getValue();
plugin.onNewIntent(intent); plugin.onNewIntent(intent);
} }
} }