From 9d5aa9406c20df986e8b22443fd265252ae62803 Mon Sep 17 00:00:00 2001 From: Bryce Curtis Date: Tue, 5 Jul 2011 23:21:32 -0500 Subject: [PATCH] Loading plugins from res/xml/plugins.xml --- framework/res/xml/plugins.xml | 20 +++++++++++++ framework/src/com/phonegap/DroidGap.java | 17 ----------- .../src/com/phonegap/api/PluginManager.java | 30 +++++++++++++++++++ 3 files changed, 50 insertions(+), 17 deletions(-) create mode 100755 framework/res/xml/plugins.xml diff --git a/framework/res/xml/plugins.xml b/framework/res/xml/plugins.xml new file mode 100755 index 00000000..bf170607 --- /dev/null +++ b/framework/res/xml/plugins.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/framework/src/com/phonegap/DroidGap.java b/framework/src/com/phonegap/DroidGap.java index 3830722e..3648ffdd 100755 --- a/framework/src/com/phonegap/DroidGap.java +++ b/framework/src/com/phonegap/DroidGap.java @@ -291,23 +291,6 @@ public class DroidGap extends PhonegapActivity { this.callbackServer = new CallbackServer(); this.pluginManager = new PluginManager(appView, this); - this.addService("App", "com.phonegap.App"); - this.addService("Geolocation", "com.phonegap.GeoBroker"); - this.addService("Device", "com.phonegap.Device"); - this.addService("Accelerometer", "com.phonegap.AccelListener"); - this.addService("Compass", "com.phonegap.CompassListener"); - this.addService("Media", "com.phonegap.AudioHandler"); - this.addService("Camera", "com.phonegap.CameraLauncher"); - this.addService("Contacts", "com.phonegap.ContactManager"); - this.addService("Crypto", "com.phonegap.CryptoHandler"); - this.addService("File", "com.phonegap.FileUtils"); - this.addService("Location", "com.phonegap.GeoBroker"); // Always add Location, even though it is built-in on 2.x devices. Let JavaScript decide which one to use. - this.addService("Network Status", "com.phonegap.NetworkManager"); - this.addService("Notification", "com.phonegap.Notification"); - this.addService("Storage", "com.phonegap.Storage"); - this.addService("Temperature", "com.phonegap.TempListener"); - this.addService("FileTransfer", "com.phonegap.FileTransfer"); - this.addService("Capture", "com.phonegap.Capture"); } /** diff --git a/framework/src/com/phonegap/api/PluginManager.java b/framework/src/com/phonegap/api/PluginManager.java index 393c6a29..7f34bc84 100755 --- a/framework/src/com/phonegap/api/PluginManager.java +++ b/framework/src/com/phonegap/api/PluginManager.java @@ -7,13 +7,16 @@ */ package com.phonegap.api; +import java.io.IOException; import java.util.HashMap; import java.util.Map.Entry; import org.json.JSONArray; import org.json.JSONException; +import org.xmlpull.v1.XmlPullParserException; import android.content.Intent; +import android.content.res.XmlResourceParser; import android.webkit.WebView; /** @@ -39,6 +42,33 @@ public final class PluginManager { public PluginManager(WebView app, PhonegapActivity ctx) { this.ctx = ctx; this.app = app; + this.loadPlugins(); + } + + /** + * Load plugins from res/xml/plugins.xml + */ + public void loadPlugins() { + XmlResourceParser xml = ctx.getResources().getXml(com.phonegap.R.xml.plugins); + int eventType = -1; + while (eventType != XmlResourceParser.END_DOCUMENT) { + if (eventType == XmlResourceParser.START_TAG) { + String strNode = xml.getName(); + if (strNode.equals("plugin")) { + String name = xml.getAttributeValue(null, "name"); + String value = xml.getAttributeValue(null, "value"); + System.out.println("Plugin: "+name+" => "+value); + this.addService(name, value); + } + } + try { + eventType = xml.next(); + } catch (XmlPullParserException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } } /**