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.liferay.mobile.android.v62.user.UserService.java

public Long getUserIdByEmailAddress(long companyId, String emailAddress) throws Exception {
    JSONObject _command = new JSONObject();

    try {/* w  w  w. ja  v  a 2 s. c  om*/
        JSONObject _params = new JSONObject();

        _params.put("companyId", companyId);
        _params.put("emailAddress", checkNull(emailAddress));

        _command.put("/user/get-user-id-by-email-address", _params);
    } catch (JSONException _je) {
        throw new Exception(_je);
    }

    JSONArray _result = session.invoke(_command);

    if (_result == null) {
        return null;
    }

    return _result.getLong(0);
}

From source file:com.liferay.mobile.android.v62.user.UserService.java

public Long getUserIdByScreenName(long companyId, String screenName) throws Exception {
    JSONObject _command = new JSONObject();

    try {//w  w  w. j av a 2  s  . co  m
        JSONObject _params = new JSONObject();

        _params.put("companyId", companyId);
        _params.put("screenName", checkNull(screenName));

        _command.put("/user/get-user-id-by-screen-name", _params);
    } catch (JSONException _je) {
        throw new Exception(_je);
    }

    JSONArray _result = session.invoke(_command);

    if (_result == null) {
        return null;
    }

    return _result.getLong(0);
}

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

public void _updateStats(Card card, String type, long cnt) {
    String key = type + "Today";
    long did = card.getDid();
    ArrayList<JSONObject> list = mCol.getDecks().parents(did);
    list.add(mCol.getDecks().get(did));//from  w  w w  .  java 2  s .co m
    for (JSONObject g : list) {
        try {
            JSONArray a = g.getJSONArray(key);
            // add
            a.put(1, a.getLong(1) + cnt);
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }
        mCol.getDecks().save(g);
    }
}

From source file:com.jennifer.ui.util.scale.TimeScale.java

public long maxLong() {
    JSONArray domain = this.domain();
    return Math.max(domain.getLong(0), domain.getLong(domain.length() - 1));
}

From source file:com.jennifer.ui.util.scale.TimeScale.java

public long minLong() {
    JSONArray domain = this.domain();
    return Math.min(domain.getLong(0), domain.getLong(domain.length() - 1));
}

From source file:com.jennifer.ui.util.scale.TimeScale.java

public JSONArray ticks(String type, int step) {
    long start = this.minLong();
    long end = this.maxLong();

    JSONArray times = new JSONArray();

    while (start < end) {
        times.put(start);//w w w . j  av  a  2 s. c  o m

        start = TimeUtil.add(start, type, step);
    }

    if (start > end) {
        start = end;
    }

    times.put(start);

    double first = this.get(times.getLong(0));
    double second = this.get(times.getLong(1));

    _rangeBand = second - first;

    return times;

}

From source file:com.jennifer.ui.util.scale.TimeScale.java

public JSONArray realTicks(String type, int step) {
    long start = this.minLong();
    long end = this.maxLong();

    JSONArray times = new JSONArray();

    Calendar c = Calendar.getInstance();

    Date date = TimeUtil.get(start);
    Date realStart = null;// www.  j a va  2  s  .c o  m

    c.setTime(date);
    if (Time.YEARS.equals(type)) {
        c.set(c.get(Calendar.YEAR), 1, 1, 0, 0, 0);
    } else if (Time.MONTHS.equals(type)) {
        c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), 1, 0, 0, 0);
    } else if (Time.DAYS.equals(type)) {
        c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DATE), 0, 0, 0);
    } else if (Time.HOURS.equals(type)) {
        c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DATE), c.get(Calendar.HOUR_OF_DAY), 0,
                0);
    } else if (Time.MINUTES.equals(type)) {
        c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DATE), c.get(Calendar.HOUR_OF_DAY),
                c.get(Calendar.MINUTE), 0);
    } else if (Time.SECONDS.equals(type)) {
        c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DATE), c.get(Calendar.HOUR_OF_DAY),
                c.get(Calendar.MINUTE), c.get(Calendar.SECOND));
    }

    realStart = c.getTime();

    long start2 = realStart.getTime();
    while (start2 < end) {
        times.put(start2);

        start2 = TimeUtil.add(start2, type, step);
    }

    double first = this.get(times.getLong(1));
    double second = this.get(times.getLong(2));

    _rangeBand = second - first;

    return times;
}

From source file:com.phonegap.FileUtils.java

/**
 * Executes the request and returns PluginResult.
 * //ww  w.  ja  va  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 = "";
    //System.out.println("FileUtils.execute("+action+")");

    try {
        if (action.equals("testSaveLocationExists")) {
            boolean b = DirectoryManager.testSaveLocationExists();
            return new PluginResult(status, b);
        } else if (action.equals("getFreeDiskSpace")) {
            long l = DirectoryManager.getFreeDiskSpace();
            return new PluginResult(status, l);
        } else if (action.equals("testFileExists")) {
            boolean b = DirectoryManager.testFileExists(args.getString(0));
            return new PluginResult(status, b);
        } else if (action.equals("testDirectoryExists")) {
            boolean b = DirectoryManager.testFileExists(args.getString(0));
            return new PluginResult(status, b);
        } else if (action.equals("deleteDirectory")) {
            boolean b = DirectoryManager.deleteDirectory(args.getString(0));
            return new PluginResult(status, b);
        } else if (action.equals("deleteFile")) {
            boolean b = DirectoryManager.deleteFile(args.getString(0));
            return new PluginResult(status, b);
        } else if (action.equals("createDirectory")) {
            boolean b = DirectoryManager.createDirectory(args.getString(0));
            return new PluginResult(status, b);
        } else if (action.equals("getRootPaths")) {
            return new PluginResult(status, DirectoryManager.getRootPaths());
        } else if (action.equals("readAsText")) {
            try {
                String s = this.readAsText(args.getString(0), args.getString(1));
                return new PluginResult(status, s);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
                return new PluginResult(PluginResult.Status.ERROR, FileUtils.NOT_FOUND_ERR);
            } catch (IOException e) {
                e.printStackTrace();
                return new PluginResult(PluginResult.Status.ERROR, FileUtils.NOT_READABLE_ERR);
            }
        } else if (action.equals("readAsDataURL")) {
            try {
                String s = this.readAsDataURL(args.getString(0));
                return new PluginResult(status, s);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
                return new PluginResult(PluginResult.Status.ERROR, FileUtils.NOT_FOUND_ERR);
            } catch (IOException e) {
                e.printStackTrace();
                return new PluginResult(PluginResult.Status.ERROR, FileUtils.NOT_READABLE_ERR);
            }
        } else if (action.equals("writeAsText")) {
            try {
                this.writeAsText(args.getString(0), args.getString(1), args.getBoolean(2));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
                return new PluginResult(PluginResult.Status.ERROR, FileUtils.NOT_FOUND_ERR);
            } catch (IOException e) {
                e.printStackTrace();
                return new PluginResult(PluginResult.Status.ERROR, FileUtils.NOT_READABLE_ERR);
            }
        } else if (action.equals("write")) {
            try {
                long fileSize = this.write(args.getString(0), args.getString(1), args.getLong(2));
                return new PluginResult(status, fileSize);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
                return new PluginResult(PluginResult.Status.ERROR, FileUtils.NOT_FOUND_ERR);
            } catch (IOException e) {
                e.printStackTrace();
                return new PluginResult(PluginResult.Status.ERROR, FileUtils.NOT_READABLE_ERR);
            }
        } else if (action.equals("truncate")) {
            try {
                long fileSize = this.truncateFile(args.getString(0), args.getLong(1));
                return new PluginResult(status, fileSize);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
                return new PluginResult(PluginResult.Status.ERROR, FileUtils.NOT_FOUND_ERR);
            } catch (IOException e) {
                e.printStackTrace();
                return new PluginResult(PluginResult.Status.ERROR, FileUtils.NOT_READABLE_ERR);
            }
        } else if (action.equals("getFile")) {
            JSONObject obj = DirectoryManager.getFile(args.getString(0));
            return new PluginResult(status, obj);
        }
        return new PluginResult(status, result);
    } catch (JSONException e) {
        e.printStackTrace();
        return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
    }
}

From source file:no.opentech.shoppinglist.file.JSONHandler.java

public ArrayList<Item> createItemListFromJSON(String json) {
    ArrayList<Item> itemList = new ArrayList<Item>();
    JSONArray jsonItems;
    try {//  w  w w .  j  ava2s.  co m
        jsonItems = new JSONArray(json);
        if ((jsonItems.length() % 6) != 0)
            return null;
        for (int i = 0; i < jsonItems.length(); i += 6) {
            Item item = new Item();
            item.setName(jsonItems.getString(i));
            item.setDescription(jsonItems.getString(i + 1));
            item.setUsageCounter(jsonItems.getInt(i + 2));
            item.setAvgNumberInLine(jsonItems.getInt(i + 3));
            Date first = new Date();
            first.setTime(jsonItems.getLong(i + 4));
            Date last = new Date();
            last.setTime(jsonItems.getLong(i + 5));
            item.setFirstSeen(first);
            item.setLastSeen(last);
            itemList.add(item);
        }
    } catch (JSONException e) {
        return null;
    }
    return itemList;
}

From source file:org.apache.cordova.dialogs.Notification.java

/**
 * Executes the request and returns PluginResult.
 *
 * @param action            The action to execute.
 * @param args              JSONArray of arguments for the plugin.
 * @param callbackContext   The callback context used when calling back into JavaScript.
 * @return                  True when the action was valid, false otherwise.
 *///ww  w .j  av a2 s .  c  o m
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    /*
     * Don't run any of these if the current activity is finishing
     * in order to avoid android.view.WindowManager$BadTokenException
     * crashing the app. Just return true here since false should only
     * be returned in the event of an invalid action.
     */
    if (this.cordova.getActivity().isFinishing())
        return true;

    if (action.equals("beep")) {
        this.beep(args.getLong(0));
    } else if (action.equals("alert")) {
        this.alert(args.getString(0), args.getString(1), args.getString(2), callbackContext);
        return true;
    } else if (action.equals("confirm")) {
        this.confirm(args.getString(0), args.getString(1), args.getJSONArray(2), callbackContext);
        return true;
    } else if (action.equals("prompt")) {
        this.prompt(args.getString(0), args.getString(1), args.getJSONArray(2), args.getString(3),
                callbackContext);
        return true;
    } 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();
    } else {
        return false;
    }

    // Only alert and confirm are async.
    callbackContext.success();
    return true;
}