List of usage examples for org.json JSONArray getInt
public int getInt(int index) throws JSONException
From source file:com.liferay.mobile.android.v7.mbmessage.MBMessageService.java
public Integer getThreadAnswersCount(long groupId, long categoryId, long threadId) throws Exception { JSONObject _command = new JSONObject(); try {//from w w w. j a v a 2s . c o m JSONObject _params = new JSONObject(); _params.put("groupId", groupId); _params.put("categoryId", categoryId); _params.put("threadId", threadId); _command.put("/mbmessage/get-thread-answers-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.mbmessage.MBMessageService.java
public Integer getCategoryMessagesCount(long groupId, long categoryId, int status) throws Exception { JSONObject _command = new JSONObject(); try {/* w ww. ja va 2 s . c om*/ JSONObject _params = new JSONObject(); _params.put("groupId", groupId); _params.put("categoryId", categoryId); _params.put("status", status); _command.put("/mbmessage/get-category-messages-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.mirasense.scanditsdk.plugin.PickerControllerBase.java
@Override public void finishDidScanCallback(JSONArray data) { mNextState = 0;/*from w w w . j ava2s . c om*/ if (data != null && data.length() > 0) { try { mNextState = data.getInt(0); } catch (JSONException e) { e.printStackTrace(); } ArrayList<Long> rejectedCodeIds = new ArrayList<Long>(); try { JSONArray jsonData = data.getJSONArray(1); for (int i = 0; i < jsonData.length(); ++i) { rejectedCodeIds.add(jsonData.getLong(i)); } } catch (JSONException e) { e.printStackTrace(); } setRejectedCodeIds(rejectedCodeIds); } synchronized (mSync) { mInFlightDidScanCallbackId.set(0); // zero means no in-flight didScan callback mSync.notifyAll(); } }
From source file:com.intel.xdk.multitouch.MultiTouch.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. *//*www . j av a 2s .co m*/ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if (action.equals("enableMultitouch")) { enableMultitouch(); } else if (action.equals("disableMultitouch")) { disableMultitouch(); } else if (action.equals("queueMultitouchData")) { queueMultitouchData(args.getString(0), args.getInt(1), args.getInt(2)); } else if (action.equals("getMultitouchData")) { String js = getMultitouchData(); JSONArray r = new JSONArray(js); callbackContext.success(r); } else if (action.equals("messagePump")) { JSONObject r = new JSONObject(); r.put("message", new JSONObject(messagePump())); callbackContext.success(r); } else if (action.equals("addMessage")) { addMessage(args.getString(0)); } else if (action.equals("")) { this.enableMultitouch(); } else { return false; } return true; }
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 ww.ja v a 2 s . co 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.ezartech.ezar.videooverlay.ezAR.java
private static int getIntOrNull(JSONArray args, int i) { if (args.isNull(i)) { return Integer.MIN_VALUE; }//from w ww . j a v a 2s . co m try { return args.getInt(i); } catch (JSONException e) { Log.e(TAG, "Can't get double", e); throw new RuntimeException(e); } }
From source file:it.readbeyond.minstrel.media.AudioHandler.java
/** * Executes the request and returns PluginResult. * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackContext The callback context used when calling back into JavaScript. * @return A PluginResult object with a status and message. *//*w w w . j ava 2s .c o m*/ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { CordovaResourceApi resourceApi = webView.getResourceApi(); PluginResult.Status status = PluginResult.Status.OK; String result = ""; if (action.equals("startPlayingAudio")) { String target = args.getString(1); String fileUriStr; try { Uri targetUri = resourceApi.remapUri(Uri.parse(target)); fileUriStr = targetUri.toString(); } catch (IllegalArgumentException e) { fileUriStr = target; } this.startPlayingAudio(args.getString(0), FileHelper.stripFileProtocol(fileUriStr)); } else if (action.equals("seekToAudio")) { this.seekToAudio(args.getString(0), args.getInt(1)); } else if (action.equals("pausePlayingAudio")) { this.pausePlayingAudio(args.getString(0)); } else if (action.equals("stopPlayingAudio")) { this.stopPlayingAudio(args.getString(0)); } else if (action.equals("setVolume")) { try { this.setVolume(args.getString(0), Float.parseFloat(args.getString(1))); } catch (NumberFormatException nfe) { //no-op } } else if (action.equals("getCurrentPositionAudio")) { float f = this.getCurrentPositionAudio(args.getString(0)); callbackContext.sendPluginResult(new PluginResult(status, f)); return true; } else if (action.equals("getDurationAudio")) { float f = this.getDurationAudio(args.getString(0), args.getString(1)); callbackContext.sendPluginResult(new PluginResult(status, f)); return true; } else if (action.equals("create")) { String id = args.getString(0); String src = FileHelper.stripFileProtocol(args.getString(1)); getOrCreatePlayer(id, src); } else if (action.equals("release")) { boolean b = this.release(args.getString(0)); callbackContext.sendPluginResult(new PluginResult(status, b)); return true; } else if (action.equals("messageChannel")) { messageChannel = callbackContext; return true; } else { // Unrecognized action. return false; } callbackContext.sendPluginResult(new PluginResult(status, result)); return true; }
From source file:com.nginious.http.serialize.JsonDeserializer.java
/** * Deserializes property with the specified name in the specified json object into a integer array. * /*from w ww . java2 s. com*/ * @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 int[] deserializeIntArray(JSONObject object, String name) throws SerializerException { try { if (object.has(name)) { JSONArray array = object.getJSONArray(name); int[] outArray = new int[array.length()]; for (int i = 0; i < array.length(); i++) { outArray[i] = array.getInt(i); } return outArray; } return null; } catch (JSONException e) { throw new SerializerException("Can't deserialize integer array property " + name, e); } }
From source file:com.nginious.http.serialize.JsonDeserializer.java
/** * Deserializes property with the specified name in the specified json object into a short array. * // www. j av a2s. c om * @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 short[] deserializeShortArray(JSONObject object, String name) throws SerializerException { try { if (object.has(name)) { JSONArray array = object.getJSONArray(name); short[] outArray = new short[array.length()]; for (int i = 0; i < array.length(); i++) { outArray[i] = (short) array.getInt(i); } return outArray; } return null; } catch (JSONException e) { throw new SerializerException("Can't deserialize short array property " + name, e); } }
From source file:jorge.tolentino.empty.Empty.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. *///from w ww .java2 s.co m public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if (action.equals("vibrate")) { this.vibrate(args.getLong(0)); } else if (action.equals("vibrateWithPattern")) { JSONArray pattern = args.getJSONArray(0); int repeat = args.getInt(1); long[] patternArray = new long[pattern.length()]; for (int i = 0; i < pattern.length(); i++) { patternArray[i] = pattern.getLong(i); } this.vibrateWithPattern(patternArray, repeat); } else if (action.equals("cancelVibration")) { this.cancelVibration(); } else { return false; } // Only alert and confirm are async. callbackContext.success(); return true; }