Example usage for org.json JSONArray getLong

List of usage examples for org.json JSONArray getLong

Introduction

In this page you can find the example usage for org.json JSONArray getLong.

Prototype

public long getLong(int index) throws JSONException 

Source Link

Document

Get the long value associated with an index.

Usage

From source file:com.phonegap.Notification.java

/**
 * Executes the request and returns PluginResult.
 * //from w w  w . j  a v a  2 s . c  o  m
 * @param action       The action to execute.
 * @param args          JSONArry of arguments for the plugin.
 * @param callbackId   The callback id used when calling back into JavaScript.
 * @return             A PluginResult object with a status and message.
 */
public PluginResult execute(String action, JSONArray args, String callbackId) {
    PluginResult.Status status = PluginResult.Status.OK;
    String result = "";

    try {
        if (action.equals("beep")) {
            this.beep(args.getLong(0));
        } else if (action.equals("vibrate")) {
            this.vibrate(args.getLong(0));
        } else if (action.equals("alert")) {
            this.alert(args.getString(0), args.getString(1), args.getString(2), callbackId);
            PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
            r.setKeepCallback(true);
            return r;
        } else if (action.equals("confirm")) {
            this.confirm(args.getString(0), args.getString(1), args.getString(2), callbackId);
            PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
            r.setKeepCallback(true);
            return r;
        } else if (action.equals("activityStart")) {
            this.activityStart(args.getString(0), args.getString(1));
        } else if (action.equals("activityStop")) {
            this.activityStop();
        } else if (action.equals("progressStart")) {
            this.progressStart(args.getString(0), args.getString(1));
        } else if (action.equals("progressValue")) {
            this.progressValue(args.getInt(0));
        } else if (action.equals("progressStop")) {
            this.progressStop();
        }
        return new PluginResult(status, result);
    } catch (JSONException e) {
        return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
    }
}

From source file:com.hichinaschool.flashcards.libanki.Utils.java

public static long[] jsonArrayToLongArray(JSONArray jsonArray) throws JSONException {
    long[] ar = new long[jsonArray.length()];
    for (int i = 0; i < jsonArray.length(); i++) {
        ar[i] = jsonArray.getLong(i);
    }/*from  www . j a  va 2  s .  c  o m*/
    return ar;
}

From source file:com.sesamtv.cordova.chromecast.ChromeCast.java

private boolean executeActions(final String action, final JSONArray args, final CallbackContext callbackContext)
        throws JSONException {
    switch (Actions.valueOf(action)) {
    case sendMessage:
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                try {
                    String channelName = args.getString(0);
                    String msg = args.getString(1);
                    sendMessage(channelName, msg, callbackContext);
                } catch (Exception e) {
                    callbackContext.error(e.getMessage());
                }//  w w  w.j  ava2 s . c o m
            }
        });
        break;

    case loadMedia:
        loadMediaAction(args.getJSONObject(0), callbackContext);
        break;
    case pauseMedia:
        pauseMediaAction(callbackContext);
        break;
    case stopMedia:
        stopMediaAction(callbackContext, args);
        break;
    case playMedia:
        playMediaAction(callbackContext);
        break;
    case seekMediaBy:
        try {
            seekMediaByAction(args.getLong(0));
            callbackContext.success();
        } catch (IOException e) {
            callbackContext.error(e.getMessage());
        }
        break;
    case seekMedia:
        try {
            seekMediaAction(args.getLong(0));
            callbackContext.success();
        } catch (IOException e) {
            callbackContext.error(e.getMessage());
        }
        break;
    case setDeviceVolume:
        final double vol = args.getDouble(0);
        Log.d(TAG, "setVolume " + vol);
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                setVolumeAction(vol, callbackContext);
            }
        });
        break;
    case setDeviceVolumeBy:
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                try {
                    setVolumeByAction(args.getDouble(0), callbackContext);
                } catch (JSONException e) {
                    callbackContext.error(e.getMessage());
                }
            }
        });
        break;
    case setMuted:
        final boolean muted = args.getBoolean(0);
        Log.d(TAG, "setMuted " + muted);
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                setDeviceMutedAction(muted, callbackContext);
            }
        });
        break;
    case toggleMuted:
        Log.d(TAG, "toggleMuted ");
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                toggleDeviceMutedAction(callbackContext);
            }
        });
        break;
    case getMediaStatus:
        Log.d(TAG, "getMediaStatus");
        callbackContext.sendPluginResult(getMediaStatus());
        break;
    case stopApplication:
        try {
            Log.d(TAG, "stopCast");
            stopApplication();
            callbackContext.success();
        } catch (Exception e) {
            callbackContext.error("stop cast failed :" + e.getMessage());
            return false;
        }
        break;

    default:
        callbackContext.error("Invalid action: " + action);

    }
    return true;
}