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.google.cast.samples.tictactoe.GameChannel.java

/**
 * Processes all Text messages received from the receiver device and performs the appropriate
 * action for the message. Recognizable messages are of the form:
 *
 * <ul>/*from  w w  w  .  jav  a2s  . com*/
 * <li> KEY_JOINED: a player joined the current game
 * <li> KEY_MOVED: a player made a move
 * <li> KEY_ENDGAME: the game has ended in one of the END_STATE_* states
 * <li> KEY_ERROR: a game error has occurred
 * <li> KEY_BOARD_LAYOUT_RESPONSE: the board has been laid out in some new configuration
 * </ul>
 *
 * <p>No other messages are recognized.
 */
@Override
public void onMessageReceived(CastDevice castDevice, String namespace, String message) {
    try {
        Log.d(TAG, "onTextMessageReceived: " + message);
        JSONObject payload = new JSONObject(message);
        Log.d(TAG, "payload: " + payload);
        if (payload.has(KEY_EVENT)) {
            String event = payload.getString(KEY_EVENT);
            if (KEY_JOINED.equals(event)) {
                Log.d(TAG, "JOINED");
                try {
                    String player = payload.getString(KEY_PLAYER);
                    String opponentName = payload.getString(KEY_OPPONENT);
                    onGameJoined(player, opponentName);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            } else if (KEY_MOVED.equals(event)) {
                Log.d(TAG, "MOVED");
                try {
                    String player = payload.getString(KEY_PLAYER);
                    int row = payload.getInt(KEY_ROW);
                    int column = payload.getInt(KEY_COLUMN);
                    boolean isGameOver = payload.getBoolean(KEY_GAME_OVER);
                    onGameMove(player, row, column, isGameOver);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            } else if (KEY_ENDGAME.equals(event)) {
                Log.d(TAG, "ENDGAME");
                try {
                    String endState = payload.getString(KEY_END_STATE);
                    int winningLocation = -1;
                    if (END_STATE_ABANDONED.equals(endState) == false) {
                        winningLocation = payload.getInt(KEY_WINNING_LOCATION);
                    }
                    onGameEnd(endState, winningLocation);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            } else if (KEY_ERROR.equals(event)) {
                Log.d(TAG, "ERROR");
                try {
                    String errorMessage = payload.getString(KEY_MESSAGE);
                    onGameError(errorMessage);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            } else if (KEY_BOARD_LAYOUT_RESPONSE.equals(event)) {
                Log.d(TAG, "Board Layout");
                int[][] boardLayout = new int[3][3];
                try {
                    JSONArray boardJSONArray = payload.getJSONArray(KEY_BOARD);
                    for (int i = 0; i < 3; ++i) {
                        for (int j = 0; j < 3; ++j) {
                            boardLayout[i][j] = boardJSONArray.getInt(i * 3 + j);
                        }
                    }
                    onGameBoardLayout(boardLayout);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        } else {
            Log.w(TAG, "Unknown payload: " + payload);
        }
    } catch (JSONException e) {
        Log.w(TAG, "Message doesn't contain an expected key.", e);
    }
}

From source file:com.liferay.mobile.android.v7.journalfolder.JournalFolderService.java

public Integer getFoldersCount(long groupId, long parentFolderId, int status) throws Exception {
    JSONObject _command = new JSONObject();

    try {//w ww  .j av  a 2s . c  om
        JSONObject _params = new JSONObject();

        _params.put("groupId", groupId);
        _params.put("parentFolderId", parentFolderId);
        _params.put("status", status);

        _command.put("/journal.journalfolder/get-folders-count", _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.v7.journalfolder.JournalFolderService.java

public Integer getFoldersCount(long groupId, long parentFolderId) throws Exception {
    JSONObject _command = new JSONObject();

    try {/*from  ww w . ja  va  2  s.  c  o m*/
        JSONObject _params = new JSONObject();

        _params.put("groupId", groupId);
        _params.put("parentFolderId", parentFolderId);

        _command.put("/journal.journalfolder/get-folders-count", _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.v7.journalfolder.JournalFolderService.java

public Integer getFoldersAndArticlesCount(long groupId, long folderId) throws Exception {
    JSONObject _command = new JSONObject();

    try {/*from   ww  w .ja va2 s  . c o m*/
        JSONObject _params = new JSONObject();

        _params.put("groupId", groupId);
        _params.put("folderId", folderId);

        _command.put("/journal.journalfolder/get-folders-and-articles-count", _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.v7.journalfolder.JournalFolderService.java

public Integer getFoldersAndArticlesCount(long groupId, JSONArray folderIds, int status) throws Exception {
    JSONObject _command = new JSONObject();

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

        _params.put("groupId", groupId);
        _params.put("folderIds", checkNull(folderIds));
        _params.put("status", status);

        _command.put("/journal.journalfolder/get-folders-and-articles-count", _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.v7.journalfolder.JournalFolderService.java

public Integer getFoldersAndArticlesCount(long groupId, long userId, long folderId, int status)
        throws Exception {
    JSONObject _command = new JSONObject();

    try {/* ww  w  .j  ava  2 s.c o m*/
        JSONObject _params = new JSONObject();

        _params.put("groupId", groupId);
        _params.put("userId", userId);
        _params.put("folderId", folderId);
        _params.put("status", status);

        _command.put("/journal.journalfolder/get-folders-and-articles-count", _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.v7.journalfolder.JournalFolderService.java

public Integer getFoldersAndArticlesCount(long groupId, long folderId, int status) throws Exception {
    JSONObject _command = new JSONObject();

    try {/*from   w w  w  .  j  a va2 s . com*/
        JSONObject _params = new JSONObject();

        _params.put("groupId", groupId);
        _params.put("folderId", folderId);
        _params.put("status", status);

        _command.put("/journal.journalfolder/get-folders-and-articles-count", _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.intel.xdk.device.Device.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.
 *///w  w  w .j a  v  a  2  s. c  o  m
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    if (action.equals("openWebPage")) {
        this.openWebPage(args.getString(0));
    } else if (action.equals("getRemoteData")) {
        //String success = args.getString(3);
        //String error = args.getString(4);
        if (args.length() <= 3) {
            getRemoteData(args.getString(0), args.getString(1), args.getString(2), callbackContext);
        } else {
            getRemoteData(args.getString(0), args.getString(1), args.getString(2), args.getString(3),
                    args.getString(4));
        }

    } else if (action.equals("getRemoteDataExt")) {
        final JSONObject json = args.getJSONObject(0);
        cordova.getThreadPool().execute(new Runnable() {

            @Override
            public void run() {
                Device.this.getRemoteDataExt(json);
            }

        });
    } else if (action.equals("getRemoteDataWithID")) {
        String success = args.getString(4);
        String error = args.getString(5);
        if (success == "null" && error == "null") {
            this.getRemoteDataWithID(args.getString(0), args.getString(1), args.getString(2), args.getInt(3),
                    callbackContext);
        } else {
            this.getRemoteDataWithID(args.getString(0), args.getString(1), args.getString(2), args.getInt(3),
                    args.getString(4), args.getString(5));
        }
    } else if (action.equals("hideStatusBar")) {
        this.hideStatusBar();
    } else if (action.equals("launchExternal")) {
        this.launchExternal(args.getString(0));
    } else if (action.equals("managePower")) {
        this.managePower(args.getBoolean(0), args.getBoolean(1));
    } else if (action.equals("runInstallNativeApp")) {
        this.runInstallNativeApp(args.getString(0), args.getString(1), args.getString(2), args.getString(3));
    } else if (action.equals("sendEmail")) {
        this.sendEmail(args.getString(0), args.getString(1), args.getString(2), args.getBoolean(3),
                args.getString(4), args.getString(5));
    } else if (action.equals("sendSMS")) {
        this.sendSMS(args.getString(0), args.getString(1));
    } else if (action.equals("setAutoRotate")) {
        this.setAutoRotate(args.getBoolean(0));
    } else if (action.equals("setRotateOrientation")) {
        this.setRotateOrientation(args.getString(0));
    } else if (action.equals("setBasicAuthentication")) {
        this.setBasicAuthentication(args.getString(0), args.getString(1), args.getString(2));
    } else if (action.equals("showRemoteSite")) {
        this.showRemoteSite(args.getString(0), args.getInt(1), args.getInt(2), args.getInt(3), args.getInt(4));
    } else if (action.equals("showRemoteSiteExt")) {
        this.showRemoteSite(args.getString(0), args.getInt(1), args.getInt(2), args.getInt(3), args.getInt(4),
                args.getInt(5), args.getInt(6));
    } else if (action.equals("closeRemoteSite")) {
        this.closeRemoteSite();
    } else if (action.equals("updateConnection")) {
        this.updateConnection();
    } else if (action.equals("mainViewExecute")) {
        this.mainViewExecute(args.getString(0));
    } else if (action.equals("copyToClipboard")) {
        this.copyToClipboard(args.getString(0));
    } else if (action.equals("initialize")) {
        this.initialize();
    } else {
        return false;
    }

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

From source file:com.liferay.mobile.android.v7.assetentry.AssetEntryService.java

public Integer getEntriesCount(JSONObjectWrapper entryQuery) throws Exception {
    JSONObject _command = new JSONObject();

    try {/*  w w  w . j  a v a  2s.c  o  m*/
        JSONObject _params = new JSONObject();

        mangleWrapper(_params, "entryQuery", "com.liferay.asset.kernel.service.persistence.AssetEntryQuery",
                entryQuery);

        _command.put("/assetentry/get-entries-count", _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.v7.assetentry.AssetEntryService.java

public Integer getCompanyEntriesCount(long companyId) throws Exception {
    JSONObject _command = new JSONObject();

    try {//  ww w.  ja  va 2  s  .  c  om
        JSONObject _params = new JSONObject();

        _params.put("companyId", companyId);

        _command.put("/assetentry/get-company-entries-count", _params);
    } catch (JSONException _je) {
        throw new Exception(_je);
    }

    JSONArray _result = session.invoke(_command);

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

    return _result.getInt(0);
}