Search in sources :

Example 1 with PluginEntry

use of org.apache.cordova.PluginEntry in project phonegap-facebook-plugin by Wizcorp.

the class PluginManager method loadPlugins.

/**
     * Load plugins from res/xml/config.xml
     */
public void loadPlugins() {
    // First checking the class namespace for config.xml
    int id = this.ctx.getActivity().getResources().getIdentifier("config", "xml", this.ctx.getActivity().getClass().getPackage().getName());
    if (id == 0) {
        // If we couldn't find config.xml there, we'll look in the namespace from AndroidManifest.xml
        id = this.ctx.getActivity().getResources().getIdentifier("config", "xml", this.ctx.getActivity().getPackageName());
        if (id == 0) {
            this.pluginConfigurationMissing();
            //We have the error, we need to exit without crashing!
            return;
        }
    }
    XmlResourceParser xml = this.ctx.getActivity().getResources().getXml(id);
    int eventType = -1;
    String service = "", pluginClass = "", paramType = "";
    boolean onload = false;
    boolean insideFeature = false;
    while (eventType != XmlResourceParser.END_DOCUMENT) {
        if (eventType == XmlResourceParser.START_TAG) {
            String strNode = xml.getName();
            if (strNode.equals("url-filter")) {
                Log.w(TAG, "Plugin " + service + " is using deprecated tag <url-filter>");
                if (urlMap.get(service) == null) {
                    urlMap.put(service, new ArrayList<String>(2));
                }
                List<String> filters = urlMap.get(service);
                filters.add(xml.getAttributeValue(null, "value"));
            } else if (strNode.equals("feature")) {
                //Check for supported feature sets  aka. plugins (Accelerometer, Geolocation, etc)
                //Set the bit for reading params
                insideFeature = true;
                service = xml.getAttributeValue(null, "name");
            } else if (insideFeature && strNode.equals("param")) {
                paramType = xml.getAttributeValue(null, "name");
                if (// check if it is using the older service param
                paramType.equals("service"))
                    service = xml.getAttributeValue(null, "value");
                else if (paramType.equals("package") || paramType.equals("android-package"))
                    pluginClass = xml.getAttributeValue(null, "value");
                else if (paramType.equals("onload"))
                    onload = "true".equals(xml.getAttributeValue(null, "value"));
            }
        } else if (eventType == XmlResourceParser.END_TAG) {
            String strNode = xml.getName();
            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
                service = "";
                pluginClass = "";
                insideFeature = false;
            }
        }
        try {
            eventType = xml.next();
        } catch (XmlPullParserException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) PluginEntry(org.apache.cordova.PluginEntry) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Example 2 with PluginEntry

use of org.apache.cordova.PluginEntry in project phonegap-facebook-plugin by Wizcorp.

the class PluginManager method getPlugin.

/**
     * Get the plugin object that implements the service.
     * If the plugin object does not already exist, then create it.
     * If the service doesn't exist, then return null.
     *
     * @param service       The name of the service.
     * @return              CordovaPlugin or null
     */
public CordovaPlugin getPlugin(String service) {
    PluginEntry entry = this.entries.get(service);
    if (entry == null) {
        return null;
    }
    CordovaPlugin plugin = entry.plugin;
    if (plugin == null) {
        plugin = entry.createPlugin(this.app, this.ctx);
    }
    return plugin;
}
Also used : CordovaPlugin(org.apache.cordova.CordovaPlugin) PluginEntry(org.apache.cordova.PluginEntry)

Example 3 with PluginEntry

use of org.apache.cordova.PluginEntry in project phonegap-facebook-plugin by Wizcorp.

the class PluginManager method addService.

/**
     * Add a plugin class that implements a service to the service entry table.
     * This does not create the plugin object instance.
     *
     * @param service           The service name
     * @param className         The plugin class name
     */
public void addService(String service, String className) {
    PluginEntry entry = new PluginEntry(service, className, false);
    this.addService(entry);
}
Also used : PluginEntry(org.apache.cordova.PluginEntry)

Example 4 with PluginEntry

use of org.apache.cordova.PluginEntry in project phonegap-facebook-plugin by Wizcorp.

the class PluginManager method init.

/**
     * Init when loading a new HTML page into webview.
     */
public void init() {
    LOG.d(TAG, "init()");
    // If first time, then load plugins from config.xml file
    if (this.firstRun) {
        this.loadPlugins();
        this.firstRun = false;
    } else // Stop plugins on current HTML page and discard plugin objects
    {
        this.onPause(false);
        this.onDestroy();
        this.clearPluginObjects();
    }
    // Insert PluginManager service
    this.addService(new PluginEntry("PluginManager", new PluginManagerService()));
    // Start up all plugins that have onload specified
    this.startupPlugins();
}
Also used : PluginEntry(org.apache.cordova.PluginEntry)

Aggregations

PluginEntry (org.apache.cordova.PluginEntry)4 XmlResourceParser (android.content.res.XmlResourceParser)1 IOException (java.io.IOException)1 CordovaPlugin (org.apache.cordova.CordovaPlugin)1 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)1