Example usage for org.json JSONArray getBoolean

List of usage examples for org.json JSONArray getBoolean

Introduction

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

Prototype

public boolean getBoolean(int index) throws JSONException 

Source Link

Document

Get the boolean value associated with an index.

Usage

From source file:com.liferay.mobile.android.v7.dlfileentry.DLFileEntryService.java

public Boolean isKeepFileVersionLabel(long fileEntryId, boolean majorVersion, JSONObjectWrapper serviceContext)
        throws Exception {
    JSONObject _command = new JSONObject();

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

        _params.put("fileEntryId", fileEntryId);
        _params.put("majorVersion", majorVersion);
        mangleWrapper(_params, "serviceContext", "com.liferay.portal.kernel.service.ServiceContext",
                serviceContext);

        _command.put("/dlfileentry/is-keep-file-version-label", _params);
    } catch (JSONException _je) {
        throw new Exception(_je);
    }

    JSONArray _result = session.invoke(_command);

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

    return _result.getBoolean(0);
}

From source file:com.liferay.mobile.android.v7.dlfileentry.DLFileEntryService.java

public Boolean isKeepFileVersionLabel(long fileEntryId, JSONObjectWrapper serviceContext) throws Exception {
    JSONObject _command = new JSONObject();

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

        _params.put("fileEntryId", fileEntryId);
        mangleWrapper(_params, "serviceContext", "com.liferay.portal.kernel.service.ServiceContext",
                serviceContext);

        _command.put("/dlfileentry/is-keep-file-version-label", _params);
    } catch (JSONException _je) {
        throw new Exception(_je);
    }

    JSONArray _result = session.invoke(_command);

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

    return _result.getBoolean(0);
}

From source file:com.cranberrygame.cordova.plugin.navigationbar.NavigationBar.java

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    PluginResult result = null;/*from  ww w .  j  a  v  a2s . co  m*/

    //args.length()
    //args.getString(0)
    //args.getString(1)
    //args.getInt(0)
    //args.getInt(1)
    //args.getBoolean(0)
    //args.getBoolean(1)
    //JSONObject json = args.optJSONObject(0);
    //json.optString("adUnit")
    //json.optString("adUnitFullScreen")
    //JSONObject inJson = json.optJSONObject("inJson");

    if (action.equals("setUp")) {
        //Activity activity = cordova.getActivity();
        //webView
        //
        final boolean autoHideNavigationBar = args.getBoolean(0);

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                _setUp(autoHideNavigationBar);

                PluginResult pr = new PluginResult(PluginResult.Status.OK);
                //pr.setKeepCallback(true);
                delayedCC.sendPluginResult(pr);
                //PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
                //pr.setKeepCallback(true);
                //delayedCC.sendPluginResult(pr);               
            }
        });

        return true;
    } else if (action.equals("hideNavigationBar")) {
        //Activity activity=cordova.getActivity();
        //webView
        //

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                _hideNavigationBar();

                PluginResult pr = new PluginResult(PluginResult.Status.OK);
                //pr.setKeepCallback(true);
                delayedCC.sendPluginResult(pr);
                //PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
                //pr.setKeepCallback(true);
                //delayedCC.sendPluginResult(pr);               
            }
        });

        return true;
    }

    return false; // Returning false results in a "MethodNotFound" error.
}

From source file:com.polyvi.xface.extension.advancedfiletransfer.XAdvancedFileTransferExt.java

@Override
public XExtensionResult exec(String action, JSONArray args, XCallbackContext callbackCtx) throws JSONException {
    String source = null;//from w  w w  .j a  v  a 2  s . c om
    String target = null;
    String appId = mWebContext.getApplication().getAppId();
    try {
        if (action.equals(COMMAND_DOWNLOAD)) {
            source = args.getString(0);
            target = args.getString(1);
            download(mWebContext, source, target, callbackCtx);
            XLog.d(CLASS_NAME, "*** About to return a result from download");
            return new XExtensionResult(XExtensionResult.Status.NO_RESULT);
        } else if (action.equals(COMMAND_UPLOAD)) {
            source = args.getString(0);
            target = args.getString(1);
            upload(mWebContext, source, target, callbackCtx);
            XLog.d(CLASS_NAME, "*** About to return a result from upload");
            return new XExtensionResult(XExtensionResult.Status.NO_RESULT);
        } else if (action.equals(COMMAND_PAUSE)) {
            source = args.getString(0);
            mFileTransferManager.pause(appId, source);
            return new XExtensionResult(XExtensionResult.Status.OK);
        } else if (action.equals(COMMAND_CANCEL)) {
            source = args.getString(0);
            target = args.getString(1);
            boolean isUpload = args.getBoolean(2);
            if (isUpload) {
                mFileTransferManager.cancel(appId, source, null, COMMAND_UPLOAD);
            } else {
                target = new File(mWebContext.getWorkSpace(), target).getAbsolutePath();
                mFileTransferManager.cancel(mWebContext.getApplication().getAppId(), source, target,
                        COMMAND_DOWNLOAD);
            }
            return new XExtensionResult(XExtensionResult.Status.OK);
        }

    } catch (FileNotFoundException e) {
        XLog.e(CLASS_NAME, e.getMessage());
        JSONObject error = createFileTransferError(FILE_NOT_FOUND_ERR, source, target);
        return new XExtensionResult(XExtensionResult.Status.ERROR, error);
    } catch (IllegalArgumentException e) {
        XLog.e(CLASS_NAME, e.getMessage());
        JSONObject error = createFileTransferError(INVALID_URL_ERR, source, target);
        return new XExtensionResult(XExtensionResult.Status.ERROR, error);
    } catch (IOException e) {
        XLog.e(CLASS_NAME, e.getMessage());
        JSONObject error = createFileTransferError(CONNECTION_ERR, source, target);
        return new XExtensionResult(XExtensionResult.Status.ERROR, error);
    } catch (JSONException e) {
        XLog.e(CLASS_NAME, e.getMessage(), e);
        return new XExtensionResult(XExtensionResult.Status.JSON_EXCEPTION);
    }
    return new XExtensionResult(XExtensionResult.Status.INVALID_ACTION);
}

From source file:com.frostytornado.cordova.plugin.ad.admob.Plugin.java

private void setUp(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    //Activity activity=cordova.getActivity();
    //webView//from  w  w w.  j a v a2 s .  c o  m
    //args.length()
    //args.getString(0)
    //args.getString(1)
    //args.getInt(0)
    //args.getInt(1)
    //args.getBoolean(0)
    //args.getBoolean(1)
    //JSONObject json = args.optJSONObject(0);
    //json.optString("bannerAdUnit")
    //json.optString("interstitialAdUnit")
    //JSONObject inJson = json.optJSONObject("inJson");
    //final String bannerAdUnit = args.getString(0);
    //final String interstitialAdUnit = args.getString(1);            
    //final boolean isOverlap = args.getBoolean(2);            
    //final boolean isTest = args.getBoolean(3);
    //final String[] zoneIds = new String[args.getJSONArray(4).length()];
    //for (int i = 0; i < args.getJSONArray(4).length(); i++) {
    //   zoneIds[i] = args.getJSONArray(4).getString(i);
    //}         
    //Log.d(LOG_TAG, String.format("%s", bannerAdUnit));         
    //Log.d(LOG_TAG, String.format("%s", interstitialAdUnit));
    //Log.d(LOG_TAG, String.format("%b", isOverlap));
    //Log.d(LOG_TAG, String.format("%b", isTest));      
    final String bannerAdUnit = args.getString(0);
    final String interstitialAdUnit = args.getString(1);
    final boolean isOverlap = args.getBoolean(2);
    final boolean isTest = args.getBoolean(3);
    Log.d(LOG_TAG, String.format("%s", bannerAdUnit));
    Log.d(LOG_TAG, String.format("%s", interstitialAdUnit));
    Log.d(LOG_TAG, String.format("%b", isOverlap));
    Log.d(LOG_TAG, String.format("%b", isTest));

    callbackContextKeepCallback = callbackContext;

    if (isOverlap) {
        pluginDelegate = new AdmobOverlap(this);
    } else {
        pluginDelegate = new AdmobSplit(this);
    }

    cordova.getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            _setUp(bannerAdUnit, interstitialAdUnit, isOverlap, isTest);
        }
    });
}

From source file:com.trk.aboutme.facebook.SharedPreferencesTokenCachingStrategy.java

private void deserializeKey(String key, Bundle bundle) throws JSONException {
    String jsonString = cache.getString(key, "{}");
    JSONObject json = new JSONObject(jsonString);

    String valueType = json.getString(JSON_VALUE_TYPE);

    if (valueType.equals(TYPE_BOOLEAN)) {
        bundle.putBoolean(key, json.getBoolean(JSON_VALUE));
    } else if (valueType.equals(TYPE_BOOLEAN_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        boolean[] array = new boolean[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = jsonArray.getBoolean(i);
        }//from w w w .  j  av a 2  s .c o m
        bundle.putBooleanArray(key, array);
    } else if (valueType.equals(TYPE_BYTE)) {
        bundle.putByte(key, (byte) json.getInt(JSON_VALUE));
    } else if (valueType.equals(TYPE_BYTE_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        byte[] array = new byte[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = (byte) jsonArray.getInt(i);
        }
        bundle.putByteArray(key, array);
    } else if (valueType.equals(TYPE_SHORT)) {
        bundle.putShort(key, (short) json.getInt(JSON_VALUE));
    } else if (valueType.equals(TYPE_SHORT_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        short[] array = new short[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = (short) jsonArray.getInt(i);
        }
        bundle.putShortArray(key, array);
    } else if (valueType.equals(TYPE_INTEGER)) {
        bundle.putInt(key, json.getInt(JSON_VALUE));
    } else if (valueType.equals(TYPE_INTEGER_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        int[] array = new int[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = jsonArray.getInt(i);
        }
        bundle.putIntArray(key, array);
    } else if (valueType.equals(TYPE_LONG)) {
        bundle.putLong(key, json.getLong(JSON_VALUE));
    } else if (valueType.equals(TYPE_LONG_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        long[] array = new long[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = jsonArray.getLong(i);
        }
        bundle.putLongArray(key, array);
    } else if (valueType.equals(TYPE_FLOAT)) {
        bundle.putFloat(key, (float) json.getDouble(JSON_VALUE));
    } else if (valueType.equals(TYPE_FLOAT_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        float[] array = new float[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = (float) jsonArray.getDouble(i);
        }
        bundle.putFloatArray(key, array);
    } else if (valueType.equals(TYPE_DOUBLE)) {
        bundle.putDouble(key, json.getDouble(JSON_VALUE));
    } else if (valueType.equals(TYPE_DOUBLE_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        double[] array = new double[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = jsonArray.getDouble(i);
        }
        bundle.putDoubleArray(key, array);
    } else if (valueType.equals(TYPE_CHAR)) {
        String charString = json.getString(JSON_VALUE);
        if (charString != null && charString.length() == 1) {
            bundle.putChar(key, charString.charAt(0));
        }
    } else if (valueType.equals(TYPE_CHAR_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        char[] array = new char[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            String charString = jsonArray.getString(i);
            if (charString != null && charString.length() == 1) {
                array[i] = charString.charAt(0);
            }
        }
        bundle.putCharArray(key, array);
    } else if (valueType.equals(TYPE_STRING)) {
        bundle.putString(key, json.getString(JSON_VALUE));
    } else if (valueType.equals(TYPE_STRING_LIST)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        int numStrings = jsonArray.length();
        ArrayList<String> stringList = new ArrayList<String>(numStrings);
        for (int i = 0; i < numStrings; i++) {
            Object jsonStringValue = jsonArray.get(i);
            stringList.add(i, jsonStringValue == JSONObject.NULL ? null : (String) jsonStringValue);
        }
        bundle.putStringArrayList(key, stringList);
    } else if (valueType.equals(TYPE_ENUM)) {
        try {
            String enumType = json.getString(JSON_VALUE_ENUM_TYPE);
            @SuppressWarnings({ "unchecked", "rawtypes" })
            Class<? extends Enum> enumClass = (Class<? extends Enum>) Class.forName(enumType);
            @SuppressWarnings("unchecked")
            Enum<?> enumValue = Enum.valueOf(enumClass, json.getString(JSON_VALUE));
            bundle.putSerializable(key, enumValue);
        } catch (ClassNotFoundException e) {
        } catch (IllegalArgumentException e) {
        }
    }
}

From source file:com.nginious.http.serialize.JsonDeserializer.java

/**
 * Deserializes property with the specified name in the specified json object into a boolean array.
 * /*www. j a  v a  2s .  c o m*/
 * @param object the json object
 * @param name the property name
 * @return the deserialized array or <code>null</code> if property doesn't exist
 * @throws SerializerException if unable to deserialize value
 */
protected boolean[] deserializeBooleanArray(JSONObject object, String name) throws SerializerException {
    try {
        if (object.has(name)) {
            JSONArray array = object.getJSONArray(name);
            boolean[] outArray = new boolean[array.length()];

            for (int i = 0; i < array.length(); i++) {
                outArray[i] = array.getBoolean(i);
            }

            return outArray;
        }

        return null;
    } catch (JSONException e) {
        throw new SerializerException("Can't deserialize boolean array property " + name, e);
    }
}

From source file:com.liferay.mobile.android.v7.commentmanagerjsonws.CommentmanagerjsonwsService.java

public Boolean hasDiscussion(long groupId, String className, long classPK) throws Exception {
    JSONObject _command = new JSONObject();

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

        _params.put("groupId", groupId);
        _params.put("className", checkNull(className));
        _params.put("classPK", classPK);

        _command.put("/comment.commentmanagerjsonws/has-discussion", _params);
    } catch (JSONException _je) {
        throw new Exception(_je);
    }

    JSONArray _result = session.invoke(_command);

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

    return _result.getBoolean(0);
}

From source file:org.apache.cordova.powermanagement.PowerManagement.java

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {

    PluginResult result = null;/* w  w w  .ja v  a2s  .  c  o  m*/
    Log.d("PowerManagementPlugin", "Plugin execute called - " + this.toString());
    Log.d("PowerManagementPlugin", "Action is " + action);

    try {
        if (action.equals("acquire")) {
            if (args.length() > 0 && args.getBoolean(0)) {
                Log.d("PowerManagementPlugin", "Only dim lock");
                result = this.acquire(PowerManager.SCREEN_DIM_WAKE_LOCK);
            } else {
                result = this.acquire(PowerManager.FULL_WAKE_LOCK);
            }
        } else if (action.equals("release")) {
            result = this.release();
        } else if (action.equals("setReleaseOnPause")) {
            try {
                this.releaseOnPause = args.getBoolean(0);
                result = new PluginResult(PluginResult.Status.OK);
            } catch (Exception e) {
                result = new PluginResult(PluginResult.Status.ERROR, "Could not set releaseOnPause");
            }
        }
    } catch (JSONException e) {
        result = new PluginResult(Status.JSON_EXCEPTION, e.getMessage());
    }

    callbackContext.sendPluginResult(result);
    return true;
}

From source file:com.transistorsoft.cordova.bggeo.CDVBackgroundGeolocation.java

private void changePace(CallbackContext callbackContext, JSONArray data) throws JSONException {
    paceChangeCallback = callbackContext;
    Bundle event = new Bundle();
    event.putString("name", BackgroundGeolocationService.ACTION_CHANGE_PACE);
    event.putBoolean("request", true);
    event.putBoolean("isMoving", data.getBoolean(0));
    postEvent(event);/*w w w .j  a v a  2 s.  co  m*/
}