[CB-1108] Make onload=true settable as a <feature> <param>

Plus some simplification of code.
This commit is contained in:
Andrew Grieve 2013-05-03 12:18:21 -04:00
parent b7990b7df8
commit 373da39ac2

View File

@ -107,9 +107,8 @@ public class PluginManager {
} }
XmlResourceParser xml = this.ctx.getActivity().getResources().getXml(id); XmlResourceParser xml = this.ctx.getActivity().getResources().getXml(id);
int eventType = -1; int eventType = -1;
String service = "", pluginClass = "", paramType = "", featureName=""; String service = "", pluginClass = "", paramType = "";
boolean onload = false; boolean onload = false;
PluginEntry entry = null;
boolean insideFeature = false; boolean insideFeature = false;
while (eventType != XmlResourceParser.END_DOCUMENT) { while (eventType != XmlResourceParser.END_DOCUMENT) {
if (eventType == XmlResourceParser.START_TAG) { if (eventType == XmlResourceParser.START_TAG) {
@ -118,52 +117,40 @@ public class PluginManager {
if (strNode.equals("plugin")) { if (strNode.equals("plugin")) {
service = xml.getAttributeValue(null, "name"); service = xml.getAttributeValue(null, "name");
pluginClass = xml.getAttributeValue(null, "value"); pluginClass = xml.getAttributeValue(null, "value");
// System.out.println("Plugin: "+name+" => "+value);
Log.d(TAG, "<plugin> tags are deprecated, please use <features> instead. <plugin> will no longer work as of Cordova 3.0"); Log.d(TAG, "<plugin> tags are deprecated, please use <features> instead. <plugin> will no longer work as of Cordova 3.0");
onload = "true".equals(xml.getAttributeValue(null, "onload")); onload = "true".equals(xml.getAttributeValue(null, "onload"));
entry = new PluginEntry(service, pluginClass, onload);
this.addService(entry);
} }
//What is this? //What is this?
else if (strNode.equals("url-filter")) { else if (strNode.equals("url-filter")) {
this.urlMap.put(xml.getAttributeValue(null, "value"), service); this.urlMap.put(xml.getAttributeValue(null, "value"), service);
} }
else if (strNode.equals("feature")) { else if (strNode.equals("feature")) {
insideFeature = true;
//Check for supported feature sets aka. plugins (Accelerometer, Geolocation, etc) //Check for supported feature sets aka. plugins (Accelerometer, Geolocation, etc)
//Set the bit for reading params //Set the bit for reading params
featureName = xml.getAttributeValue(null,"name"); insideFeature = true;
service = xml.getAttributeValue(null, "name");
} }
else if (insideFeature && strNode.equals("param")) { else if (insideFeature && strNode.equals("param")) {
paramType = xml.getAttributeValue(null, "name"); paramType = xml.getAttributeValue(null, "name");
if (paramType.equals("service")) // check if it is using the older service param if (paramType.equals("service")) // check if it is using the older service param
service = xml.getAttributeValue(null, "value"); service = xml.getAttributeValue(null, "value");
else if (paramType.equals("package")) else if (paramType.equals("package") || paramType.equals("android-package"))
pluginClass = xml.getAttributeValue(null,"value"); pluginClass = xml.getAttributeValue(null,"value");
else if (paramType.equals("android-package")) else if (paramType.equals("onload"))
{ onload = "true".equals(xml.getAttributeValue(null, "onload"));
service = featureName;
pluginClass = xml.getAttributeValue(null,"value");
}
if (service.length() > 0 && pluginClass.length() > 0) {
onload = "true".equals(xml.getAttributeValue(null,
"onload"));
entry = new PluginEntry(service, pluginClass, onload);
this.addService(entry);
service = "";
pluginClass = "";
}
} }
} }
else if (eventType == XmlResourceParser.END_TAG) else if (eventType == XmlResourceParser.END_TAG)
{ {
String strNode = xml.getName(); String strNode = xml.getName();
if(strNode.equals("feature")) if (strNode.equals("feature") || strNode.equals("plugin"))
{ {
PluginEntry entry = new PluginEntry(service, pluginClass, onload);
this.addService(entry);
//Empty the strings to prevent plugin loading bugs //Empty the strings to prevent plugin loading bugs
service = ""; service = "";
pluginClass = ""; pluginClass = "";
featureName ="";
insideFeature = false; insideFeature = false;
} }
} }