List of usage examples for org.json JSONArray getInt
public int getInt(int index) throws JSONException
From source file:com.hichinaschool.flashcards.libanki.Models.java
/** Given a joined field string, return available template ordinals */ public ArrayList<Integer> availOrds(JSONObject m, String flds) { try {//from w w w. java 2 s . c o m if (m.getInt("type") == Sched.MODEL_CLOZE) { return _availClozeOrds(m, flds); } String[] fields = Utils.splitFields(flds); for (String f : fields) { f = f.trim(); } ArrayList<Integer> avail = new ArrayList<Integer>(); JSONArray reqArray = m.getJSONArray("req"); for (int i = 0; i < reqArray.length(); i++) { JSONArray sr = reqArray.getJSONArray(i); int ord = sr.getInt(0); String type = sr.getString(1); JSONArray req = sr.getJSONArray(2); if (type.equals("none")) { // unsatisfiable template continue; } else if (type.equals("all")) { // AND requirement? boolean ok = true; for (int j = 0; j < req.length(); j++) { int idx = req.getInt(j); if (fields[idx] == null || fields[idx].length() == 0) { // missing and was required ok = false; break; } } if (!ok) { continue; } } else if (type.equals("any")) { // OR requirement? boolean ok = false; for (int j = 0; j < req.length(); j++) { int idx = req.getInt(j); if (fields[idx] != null && fields[idx].length() != 0) { // missing and was required ok = true; break; } } if (!ok) { continue; } } avail.add(ord); } return avail; } catch (JSONException e) { throw new RuntimeException(e); } }
From source file:com.phonegap.bossbolo.plugin.BoloPlugin.java
public void setLoaded(JSONArray args, final CallbackContext callbackContext) { int loaded = 1; try {//from ww w.ja v a 2 s .c om loaded = args.getInt(0); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } CustomGlobal.getInstance().setLoaded(loaded); callbackContext.success(); }
From source file:com.liferay.mobile.android.v62.bookmarksentry.BookmarksEntryService.java
public Integer getEntriesCount(long groupId, long folderId) throws Exception { JSONObject _command = new JSONObject(); try {// www . j a v a2 s . co m JSONObject _params = new JSONObject(); _params.put("groupId", groupId); _params.put("folderId", folderId); _command.put("/bookmarksentry/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.v62.bookmarksentry.BookmarksEntryService.java
public Integer getEntriesCount(long groupId, long folderId, int status) throws Exception { JSONObject _command = new JSONObject(); try {// w ww .j a v a2 s . c om JSONObject _params = new JSONObject(); _params.put("groupId", groupId); _params.put("folderId", folderId); _params.put("status", status); _command.put("/bookmarksentry/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.v62.bookmarksentry.BookmarksEntryService.java
public Integer getFoldersEntriesCount(long groupId, JSONArray folderIds) throws Exception { JSONObject _command = new JSONObject(); try {/*from ww w.j a va2s .c o m*/ JSONObject _params = new JSONObject(); _params.put("groupId", groupId); _params.put("folderIds", checkNull(folderIds)); _command.put("/bookmarksentry/get-folders-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.v62.bookmarksentry.BookmarksEntryService.java
public Integer getGroupEntriesCount(long groupId) throws Exception { JSONObject _command = new JSONObject(); try {//from ww w. ja v a2s.c o m JSONObject _params = new JSONObject(); _params.put("groupId", groupId); _command.put("/bookmarksentry/get-group-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.v62.bookmarksentry.BookmarksEntryService.java
public Integer getGroupEntriesCount(long groupId, long userId) throws Exception { JSONObject _command = new JSONObject(); try {// www . jav a2s . c o m JSONObject _params = new JSONObject(); _params.put("groupId", groupId); _params.put("userId", userId); _command.put("/bookmarksentry/get-group-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.v62.bookmarksentry.BookmarksEntryService.java
public Integer getGroupEntriesCount(long groupId, long userId, long rootFolderId) throws Exception { JSONObject _command = new JSONObject(); try {/*from w w w .ja v a 2s .c om*/ JSONObject _params = new JSONObject(); _params.put("groupId", groupId); _params.put("userId", userId); _params.put("rootFolderId", rootFolderId); _command.put("/bookmarksentry/get-group-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:org.potpie.cordova.plugins.chromecast.ChromecastPlugin.java
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if (action.equals("startReceiverListener")) { receiverCallback = callbackContext; PluginResult result = new PluginResult(PluginResult.Status.OK, new JSONObject()); result.setKeepCallback(true);/*from ww w . j a v a 2 s. c o m*/ receiverCallback.sendPluginResult(result); return true; } else if (action.equals("setReceiver")) { int index = args.getInt(0); try { RouteInfo route = routes.get(index); System.out.println("route :" + index + " " + route.getId() + " selected"); mediaRouter.selectRoute(route); callbackContext.success(); return true; } catch (IndexOutOfBoundsException e) { callbackContext.error("Receiver not found"); return false; } } else if (action.equals("cast")) { String mediaurl = args.getString(0); try { System.out.println("cast :" + mediaurl); startCast(mediaurl); callbackContext.success(); return true; } catch (IOException e) { callbackContext.error("cast failed :" + e.getMessage()); return false; } } else if (action.equals("pause")) { try { System.out.println("pause"); pause(); callbackContext.success(); return true; } catch (IOException e) { callbackContext.error("pause failed :" + e.getMessage()); return false; } } else if (action.equals("play")) { try { int position = args.getInt(0); System.out.println("play :" + position); play(position); callbackContext.success(); return true; } catch (IOException e) { callbackContext.error("play failed :" + e.getMessage()); return false; } } else if (action.equals("stopCast")) { try { System.out.println("stopCast"); stopCast(); callbackContext.success(); return true; } catch (IOException e) { callbackContext.error("stop cast failed :" + e.getMessage()); return false; } } else if (action.equals("startStatusListener")) { statusCallback = callbackContext; callbackContext.sendPluginResult(getStatus(null)); return true; } else { callbackContext.error("Invalid action"); return false; } }
From source file:com.liferay.mobile.android.v62.ddmstructure.DDMStructureService.java
public Integer searchCount(long companyId, JSONArray groupIds, JSONArray classNameIds, String keywords) throws Exception { JSONObject _command = new JSONObject(); try {/*w w w .j a va 2 s. c o m*/ JSONObject _params = new JSONObject(); _params.put("companyId", companyId); _params.put("groupIds", checkNull(groupIds)); _params.put("classNameIds", checkNull(classNameIds)); _params.put("keywords", checkNull(keywords)); _command.put("/ddmstructure/search-count", _params); } catch (JSONException _je) { throw new Exception(_je); } JSONArray _result = session.invoke(_command); if (_result == null) { return null; } return _result.getInt(0); }