Example usage for org.apache.cordova.api PluginResult getStatus

List of usage examples for org.apache.cordova.api PluginResult getStatus

Introduction

In this page you can find the example usage for org.apache.cordova.api PluginResult getStatus.

Prototype

public int getStatus() 

Source Link

Usage

From source file:com.phono.android.phonegap.Phono.java

License:Apache License

@Override
public synchronized PluginResult execute(String action, JSONArray data, String callbackId) {
    Log.debug("Plugin Called with action " + action + " and data " + data.toString());
    PluginResult result = null;
    JSONObject options = null;/*from   www.j  a v a  2  s.c om*/

    try {
        if (data != null) {
            options = data.getJSONObject(0);
        }
        JSONObject joret = new JSONObject();
        boolean status = false;
        if (ALLOCATEENDPOINT.equals(action)) {
            status = allocateEndpoint(options, joret);
        } else if (CODECS.equals(action)) {
            status = codecs(options, joret);
        } else if (START.equals(action)) {
            status = start(options, joret);
        } else if (STOP.equals(action)) {
            status = stop(options, joret);
        } else if (SHARE.equals(action)) {
            status = share(options, joret);
        } else if (PLAY.equals(action)) {
            status = play(options, joret);
        } else if (MUTE.equals(action)) {
            status = mute(options, joret);
        } else if (ENERGY.equals(action)) {
            status = energy(options, joret);
        } else if (GAIN.equals(action)) {
            status = gain(options, joret);
        } else if (DIGIT.equals(action)) {
            status = digit(options, joret);
        } else if (FREEENDPOINT.equals(action)) {
            status = freeEndpoint(options, joret);
        } else if (LOG.equals(action)) {
            Log.debug(options.getString("message"));
            joret.put(VALUE, "logged");
            status = true;
        }
        Log.debug(action + " returning " + joret.toString());
        result = status ? new PluginResult(Status.OK, joret) : new PluginResult(Status.INVALID_ACTION);
    } catch (JSONException jsonEx) {
        Log.debug(action + "Got JSON Exception " + jsonEx.getMessage());
        result = new PluginResult(Status.JSON_EXCEPTION);
    }
    Log.debug("result=" + result.getStatus() + " " + result.getJSONString());
    return result;
}