Example usage for org.json JSONArray getInt

List of usage examples for org.json JSONArray getInt

Introduction

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

Prototype

public int getInt(int index) throws JSONException 

Source Link

Document

Get the int value associated with an index.

Usage

From source file:com.jennifer.ui.chart.grid.DateGrid.java

public void drawBefore() {
    initDomain();/*from  ww w  . ja  v a 2  s  . c o  m*/

    int max = chart.area("height");

    if (orient == Orient.TOP || orient == Orient.BOTTOM) {
        max = chart.area("width");
    }

    JSONArray range = (JSONArray) new JSONArray().put(0).put(max);

    TimeScale timeScale = (TimeScale) this.scale;

    timeScale.domain(options.getJSONArray("domain")).rangeRound(range);

    boolean realtime = options.optBoolean("realtime", false);
    JSONArray step = JSONUtil.clone(options.getJSONArray("step"));

    if (realtime) {
        this.ticks = timeScale.realTicks(step.getString(0), step.getInt(1));
    } else {
        this.ticks = timeScale.ticks(step.getString(0), step.getInt(1));
    }

    // step = [this.time.days, 1];
    this.bar = 6;

    this.values = new JSONArray();

    for (int i = 0, len = this.ticks.length(); i < len; i++) {
        this.values.put(this.scale.get(this.ticks.getDouble(i)));
    }
}

From source file:net.zorgblub.typhon.dto.PageOffsets.java

private static List<List<Integer>> readOffsets(JSONArray jsonArray) throws JSONException {

    List<List<Integer>> result = new ArrayList<List<Integer>>();

    for (int i = 0; i < jsonArray.length(); i++) {
        List<Integer> sublist = new ArrayList<>();

        JSONArray subArray = new JSONArray(jsonArray.getString(i));

        for (int j = 0; j < subArray.length(); j++) {
            int val = subArray.getInt(j);
            sublist.add(val);
        }//from  w ww.  j  a v a  2 s  . co  m

        result.add(sublist);
    }

    return result;
}

From source file:com.macadamian.blinkup.BlinkUpPlugin.java

private boolean startBlinkUp(final Activity activity, final BlinkupController controller, JSONArray data) {
    int timeoutMs;
    try {/*from  w w  w.  j  a  v  a2 s  .  c o m*/
        mApiKey = data.getString(START_BLINKUP_ARG_API_KEY);
        mDeveloperPlanId = data.getString(START_BLINKUP_ARG_DEVELOPER_PLAN_ID);
        mIsInDevelopment = data.getBoolean(START_BLINKUP_IS_IN_DEVELOPMENT);
        timeoutMs = data.getInt(START_BLINKUP_ARG_TIMEOUT_MS);
    } catch (JSONException exc) {
        BlinkUpPluginResult.sendPluginErrorToCallback(ERROR_INVALID_ARGUMENTS);
        return false;
    }

    // if api key not valid, send error message and quit
    if (!apiKeyFormatValid()) {
        BlinkUpPluginResult.sendPluginErrorToCallback(ERROR_INVALID_API_KEY);
        return false;
    } else if (mDeveloperPlanId == null || mDeveloperPlanId.isEmpty()) {
        BlinkUpPluginResult.sendPluginErrorToCallback(ERROR_INVALID_ARGUMENTS);
        return false;
    }

    controller.intentBlinkupComplete = createBlinkUpCompleteIntent(activity, timeoutMs);

    // default is to run on WebCore thread, we have UI so need UI thread
    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            presentBlinkUp(activity, controller);
        }
    });
    return true;
}

From source file:com.macadamian.blinkup.BlinkUpPlugin.java

/**
 * Old Style of BlinkUp invocation./*from w w  w.j av  a2s.co m*/
 *
 * @deprecated use {@link #startBlinkUp()} instead.
 */
@Deprecated
private boolean invokeBlinkup(final Activity activity, final BlinkupController controller, JSONArray data) {
    int timeoutMs;
    try {
        mApiKey = data.getString(INVOKE_BLINKUP_ARG_API_KEY);
        mDeveloperPlanId = data.getString(INVOKE_BLINKUP_ARG_DEVELOPER_PLAN_ID);
        timeoutMs = data.getInt(INVOKE_BLINKUP_ARG_TIMEOUT_MS);
        mGeneratePlanId = data.getBoolean(INVOKE_BLINKUP_ARG_GENERATE_PLAN_ID);
    } catch (JSONException exc) {
        BlinkUpPluginResult.sendPluginErrorToCallback(ERROR_INVALID_ARGUMENTS);
        return false;
    }

    // if api key not valid, send error message and quit
    if (!apiKeyFormatValid()) {
        BlinkUpPluginResult.sendPluginErrorToCallback(ERROR_INVALID_API_KEY);
        return false;
    }

    controller.intentBlinkupComplete = createBlinkUpCompleteIntent(activity, timeoutMs);

    // default is to run on WebCore thread, we have UI so need UI thread
    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            presentBlinkUp(activity, controller);
        }
    });
    return true;
}

From source file:com.iespuig.attendancemanager.StudentFetchr.java

public ArrayList<Student> fetchStudent(Classblock classBlock) {
    ArrayList<Student> items = new ArrayList<Student>();

    SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(context);
    String schoolName = SP.getString(("schoolName"), "");
    String urlServer = SP.getString("urlServer", "");

    Format formatter = new SimpleDateFormat("ddMMyyyy");

    try {//from  ww  w.  j  ava  2 s.  co m
        String url = Uri.parse(urlServer).buildUpon().appendQueryParameter("action", ACTION_GET_STUDENTS)
                .appendQueryParameter("school", schoolName)
                .appendQueryParameter("login", User.getInstance().getLogin())
                .appendQueryParameter("password", User.getInstance().getPassword())
                .appendQueryParameter("idGroup", String.valueOf(classBlock.getIdGroup()))
                .appendQueryParameter("idClassBlock", String.valueOf(classBlock.getId()))
                .appendQueryParameter("date", formatter.format(classBlock.getDate())).build().toString();

        Log.i(TAG, "url: " + url);

        String data = AtmNet.getUrl(url);
        Log.i(TAG, "url: " + data);

        JSONObject jsonObject = new JSONObject(data);
        JSONArray jsonArray = new JSONArray(jsonObject.getString("data"));

        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject row = jsonArray.getJSONObject(i);

            Student item = new Student();

            item.setId(row.getInt("id"));
            item.setFullname(row.getString("fullname"));
            item.setName(row.getString("name"));
            item.setSurname1(row.getString("surname1"));
            item.setSurname2(row.getString("surname2"));
            item.setMissType(0);
            item.setNotMaterial(false);
            item.setNetworkTransit(false);

            if (row.has("misses")) {
                JSONArray misses = row.getJSONArray("misses");
                for (int j = 0; j < misses.length(); j++) {
                    int miss = misses.getInt(j);
                    if (miss > NOT_MISS && miss <= EXPULSION) {
                        item.setMissType(miss);
                    }
                    if (miss == NOT_MATERIAL)
                        item.setNotMaterial(true);
                }
            }

            items.add(item);
        }
    } catch (IOException ioe) {
        Log.e(TAG, "Failed to fetch items", ioe);

    } catch (JSONException je) {
        Log.e(TAG, "Failed to parse JSON", je);
    }
    return items;
}

From source file:com.theaigames.game.warlight2.MapCreator.java

/**
 * @param mapString : string that represents the map to be created
 * @return : a Map object to use in the game
 *///from   w w  w  .  j  av a2s . co m
public static Map createMap(String mapString) {
    Map map = new Map();

    //parse the map string
    try {
        JSONObject jsonMap = new JSONObject(mapString);

        // create SuperRegion objects
        JSONArray superRegions = jsonMap.getJSONArray("SuperRegions");
        for (int i = 0; i < superRegions.length(); i++) {
            JSONObject jsonSuperRegion = superRegions.getJSONObject(i);
            map.add(new SuperRegion(jsonSuperRegion.getInt("id"), jsonSuperRegion.getInt("bonus")));
        }

        // create Region object
        JSONArray regions = jsonMap.getJSONArray("Regions");
        for (int i = 0; i < regions.length(); i++) {
            JSONObject jsonRegion = regions.getJSONObject(i);
            SuperRegion superRegion = map.getSuperRegion(jsonRegion.getInt("superRegion"));
            map.add(new Region(jsonRegion.getInt("id"), superRegion));
        }

        // add the Regions' neighbors
        for (int i = 0; i < regions.length(); i++) {
            JSONObject jsonRegion = regions.getJSONObject(i);
            Region region = map.getRegion(jsonRegion.getInt("id"));
            JSONArray neighbors = jsonRegion.getJSONArray("neighbors");
            for (int j = 0; j < neighbors.length(); j++) {
                Region neighbor = map.getRegion(neighbors.getInt(j));
                region.addNeighbor(neighbor);
            }
        }
    } catch (JSONException e) {
        System.err.println("JSON: Can't parse map string: " + e);
    }

    map.sort();

    return map;
}

From source file:com.intel.xdk.camera.Camera.java

/**
     * Executes the request and returns PluginResult.
     */*  ww w . j  a  v  a  2  s .  com*/
     * @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.
     */
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    if (action.equals("clearPictures")) {
        this.clearPictures();
    } else if (action.equals("deletePicture")) {
        this.deletePicture(args.getString(0));
    } else if (action.equals("getInfo")) {
        //get pictureLocation and pictureList
        JSONObject r = new JSONObject();
        r.put("pictureLocation", pictureDir());
        List<String> pictureList = getPictureList();
        r.put("pictureList", new JSONArray(pictureList));
        callbackContext.success(r);
    } else if (action.equals("importPicture")) {
        this.importPicture();
        this.callbackContext = callbackContext;
    } else if (action.equals("takePicture")) {
        this.takePicture(args.getInt(0), args.getString(1), args.getString(2));
        this.callbackContext = callbackContext;
    } else {
        return false;
    }

    // All actions are async.
    //callbackContext.success();
    return true;
}

From source file:com.watabou.pixeldungeon.utils.Bundle.java

public int[] getIntArray(String key) {
    try {/*from  w  w w . ja va  2  s  . co m*/
        JSONArray array = data.getJSONArray(key);
        int length = array.length();
        int[] result = new int[length];
        for (int i = 0; i < length; i++) {
            result[i] = array.getInt(i);
        }
        return result;
    } catch (JSONException e) {
        return null;
    }
}

From source file:com.liferay.mobile.android.v62.portal.PortalService.java

public Integer getBuildNumber() throws Exception {
    JSONObject _command = new JSONObject();

    try {/*from  ww  w  . j  a  v  a2s . c  o m*/
        JSONObject _params = new JSONObject();

        _command.put("/portal/get-build-number", _params);
    } catch (JSONException _je) {
        throw new Exception(_je);
    }

    JSONArray _result = session.invoke(_command);

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

    return _result.getInt(0);
}

From source file:com.liferay.mobile.android.v62.portal.PortalService.java

public Integer testGetBuildNumber() throws Exception {
    JSONObject _command = new JSONObject();

    try {/*from w  w w .  ja  v  a2s  . c o  m*/
        JSONObject _params = new JSONObject();

        _command.put("/portal/test-get-build-number", _params);
    } catch (JSONException _je) {
        throw new Exception(_je);
    }

    JSONArray _result = session.invoke(_command);

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

    return _result.getInt(0);
}