npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cordova-annotated-plugin-android

v1.0.4

Published

Enhanced CordovaPlugin class

Downloads

5,716

Readme

cordova-annotated-plugin-androidNPM version NPM downloads

With this plugin, a cordova plugin can be implemented in this way:

public class MyPlugin extends AnnotatedCordovaPlugin {
    @PluginAction
    private void pluginAction1(int firstOption, String secondOption, CallbackContext callbackContext) {
        ...
    }
}

AnnotatedCordovaPlugin extends original CordovaPlugin, so all methods are still accessible.

This plugin helps developers of cordova plugins to forget of the embarrassing and complicated way to develop a cordova plugin. Usually the developer had to implement a plugin like this (see Android Plugin Development Guide):

public class MyPlugin extends CordovaPlugin {
    @Override
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
        if ("pluginAction1".equals(action)) {
            JSONObject options = args.optJSONObject(0);
            pluginAction1(options, callbackContext);

        } else if ("pluginAction1".equals(action)) {
            JSONObject options = args.optJSONObject(0);
            pluginAction2(options, callbackContext);

        } else if ("moreActions".equals(action)) {
            ...
        } else {
            LOG.d("PLUGIN_TAG", String.format("Unknown action: %s", action));
            return false;
        }

        return true;
    }

    private void pluginAction1(JSONObject options, CallbackContext callbackContext) {
        if (options == null) {
            return new callbackContext.error("options is null, please specify options");
        }
        callbackContext.success();
    }
}

PluginAction annotation

It has 3 parameters, all of them optional:

  • thread (ExecutionThread): enum, can be MAIN, UI, WORKER (defaults to MAIN)
  • actionName (String): the name of the method as it will be called from Javascript (defaults to java annotated method name)
  • isAutofinish (boolean): if callbackContext.success() has not been called and isAutofinish is set to true, when method finishes, callbackContext.success() will be called (defaults to true)
public class MyPlugin extends AnnotatedCordovaPlugin {
    @PluginAction(thread=ExecutionThread.UI, actionName="anotherName", isAutofinish=false)
    private void pluginAction1(int firstOption, String secondOption, CallbackContext callbackContext) {
        ...
        if (iWantSuccess) {
            callbackContext.success();
        } else {
            callbackContext.error();
        }
    }
}

Then from javascript:

myPlugin.anotherName = function (options, successCallback, failureCallback) {
    cordova.exec(successCallback, failureCallback, 'MyPlugin', 'anotherName', options);
};

myPlugin.anotherName([1, 'second']);

Agreements

  • Inspired on https://github.com/chemerisuk/cordova-annotated-plugin-android

Why this rewritting of chemerisuk plugin?

  • Implements proguard defaults
  • Implements auto finish (automatically calls callbackContext.success() if it has not been called yet)
  • Documentation has been rewritten
  • Methods have been heavily refactored and simplified to improve maintenance