List of usage examples for org.json JSONArray getString
public String getString(int index) throws JSONException
From source file:com.doylestowncoder.plugin.mobileaccessibility.MobileAccessibility.java
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { try {//from w ww. j a v a 2s . c om if (action.equals("isScreenReaderRunning")) { isScreenReaderRunning(callbackContext); return true; } else if (action.equals("isClosedCaptioningEnabled")) { isClosedCaptioningEnabled(callbackContext); return true; } else if (action.equals("isTouchExplorationEnabled")) { isTouchExplorationEnabled(callbackContext); return true; } else if (action.equals("postNotification")) { if (args.length() > 1) { String string = args.getString(1); if (!string.isEmpty()) { announceForAccessibility(string, callbackContext); } } return true; } else if (action.equals("getTextZoom")) { getTextZoom(callbackContext); return true; } else if (action.equals("setTextZoom")) { if (args.length() > 0) { double textZoom = args.getDouble(0); if (textZoom > 0) { setTextZoom(textZoom, callbackContext); } } return true; } else if (action.equals("updateTextZoom")) { updateTextZoom(callbackContext); return true; } else if (action.equals("start")) { start(callbackContext); return true; } else if (action.equals("stop")) { stop(); return true; } } catch (JSONException e) { e.printStackTrace(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); } return false; }
From source file:org.jboss.aerogear.cordova.push.PushPlugin.java
private List<String> convert(String categories) throws JSONException { List<String> categoryList = null; if (categories != null) { categoryList = new ArrayList<String>(); final JSONArray jsonArray = new JSONArray(categories); for (int i = 0; i < jsonArray.length(); i++) { categoryList.add(jsonArray.getString(i)); }//from w w w. jav a 2s . c om } return categoryList; }
From source file:com.jumpbyte.mobile.plugin.PdfViewer.java
/** * Executes the request and returns PluginResult. * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackId The callback id used when calling back into JavaScript. * @return A PluginResult object with a status and message. */// w w w . ja v a2s. c om public PluginResult execute(String action, JSONArray args, String callbackId) { PluginResult.Status status = PluginResult.Status.OK; String result = ""; try { if (action.equals("showPdf")) { result = this.showPdf(args.getString(0)); if (result.length() > 0) { status = PluginResult.Status.ERROR; } } return new PluginResult(status, result); } catch (JSONException e) { return new PluginResult(PluginResult.Status.JSON_EXCEPTION); } }
From source file:de.jaetzold.philips.hue.HueBridge.java
private void parseGroups(JSONObject groupsJson) { final Iterator<?> keys = groupsJson.keys(); while (keys.hasNext()) { Object key = keys.next(); try {/*from w ww . j a v a2 s. com*/ Integer id = Integer.parseInt((String) key); HueLightGroup group = groups.get(id); if (group == null) { group = new HueLightGroup(this, id); groups.put(id, group); } final JSONObject lightJson = groupsJson.getJSONObject((String) key); group.name = lightJson.getString("name"); final JSONArray lightsArray = lightJson.getJSONArray("lights"); for (int i = 0; i < lightsArray.length(); i++) { Integer lightId = Integer.parseInt(lightsArray.getString(i)); final HueLightBulb light = getLight(lightId); if (light == null) { //noinspection ThrowCaughtLocally throw new HueCommException("Can not find light with id " + lightId); } else { group.lights.put(lightId, light); } } } catch (Exception e) { if (e instanceof HueCommException) { throw e; } else { throw new HueCommException("Groups result parsing failed. Probably some unexpected format?", e); } } } }
From source file:com.remcob00.cordova.youtube.YouTube.java
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { cordova.setActivityResultCallback(YouTube.this); if (action.equals("playVideo")) { if (args.length() == 2) { Intent youtubeIntent = YouTubeStandalonePlayer.createVideoIntent(cordova.getActivity(), args.getString(0), args.getString(1)); cordova.startActivityForResult(this, youtubeIntent, 2300010); return true; } else if (args.length() == 5) { Intent youtubeIntent = YouTubeStandalonePlayer.createVideoIntent(cordova.getActivity(), args.getString(0), args.getString(1), args.getInt(2), args.getBoolean(3), args.getBoolean(4)); cordova.startActivityForResult(this, youtubeIntent, 2300010); return true; } else {//from w w w. j ava2 s .c om return false; } } else if (action.endsWith("playPlaylist")) { if (args.length() == 2) { Intent youtubeIntent = YouTubeStandalonePlayer.createPlaylistIntent(cordova.getActivity(), args.getString(0), args.getString(1)); cordova.startActivityForResult(this, youtubeIntent, 2300010); return true; } else if (args.length() == 6) { Intent youtubeIntent = YouTubeStandalonePlayer.createPlaylistIntent(cordova.getActivity(), args.getString(0), args.getString(1), args.getInt(2), args.getInt(3), args.getBoolean(4), args.getBoolean(5)); cordova.startActivityForResult(this, youtubeIntent, 2300010); return true; } else { return false; } } else if (action.endsWith("playVideos")) { List<String> videos = new ArrayList<String>(); for (int i = 0; i < args.getJSONArray(1).length(); i++) { videos.add(args.getJSONArray(1).getString(i)); } if (args.length() == 2) { Intent youtubeIntent = YouTubeStandalonePlayer.createVideosIntent(cordova.getActivity(), args.getString(0), videos); cordova.startActivityForResult(this, youtubeIntent, 2300010); return true; } else if (args.length() == 6) { Intent youtubeIntent = YouTubeStandalonePlayer.createVideosIntent(cordova.getActivity(), args.getString(0), videos, args.getInt(2), args.getInt(3), args.getBoolean(4), args.getBoolean(5)); cordova.startActivityForResult(this, youtubeIntent, 2300010); return true; } else { return false; } } return false; }
From source file:com.jennifer.ui.chart.widget.LegendWidget.java
private JSONArray getLegendIcon(JSONObject brushObject) { JSONArray arr = new JSONArray(); JSONArray data = JSONUtil.clone(brushObject.getJSONArray("target")); if (key != null && key.length() > 0) { data = chart.data();// ww w. jav a 2s.c o m } int count = data.length(); for (int i = 0; i < count; i++) { String text = ""; if (key != null && key.length() > 0) { text = chart.series(key).optString("text", data.getJSONObject(i).getString(key)); } else { String target = data.getString(i); text = chart.series(target).optString("text", target); } double rectWidth = (fontWidth - 4) * text.length(); double width = Math.min(rectWidth, fontHeight); double height = width; Transform group = root.group(new JSONObject().put("class", "legend icon")); Transform rect = group.rect(new JSONObject().put("x", 0).put("y", 0).put("width", width) .put("height", height).put("fill", chart.color(i, brushObject.optJSONArray("colors")))); group.text(new JSONObject().put("x", width + 4).put("y", fontHeight - 3) // 3 is top, bottom font margin .put("font-family", chart.theme("fontFamily")).put("font-size", chart.theme("legendFontSize")) .put("fill", chart.theme("legendFontColor")).put("text-anchor", "start")).textNode(text); arr.put(new JSONObject().put("width", width + 4 + rectWidth + (i == count - 1 ? 0 : 10)) .put("height", height + 4).put("icon", group) ); } return arr; }
From source file:com.chess.genesis.net.SyncClient.java
private void sync_recent(final JSONObject json) { try {//from w w w . j a va 2 s .co m final JSONArray ids = json.getJSONArray("gameids"); final ExecutorService pool = Executors.newCachedThreadPool(); for (int i = 0, len = ids.length(); i < len; i++) { if (error) return; final NetworkClient nc = new NetworkClient(context, handle); nc.game_status(ids.getString(i)); pool.submit(nc); lock++; } // Save sync time final PrefEdit pref = new PrefEdit(context); pref.putLong(R.array.pf_lastgamesync, json.getLong("time")); pref.commit(); } catch (final JSONException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:com.chess.genesis.net.SyncClient.java
private ArrayList<String> getNeedList(final JSONArray ids) { try {//from w w w.j av a 2s.c om final ArrayList<String> list_need = new ArrayList<String>(ids.length()); for (int i = 0, len = ids.length(); i < len; i++) list_need.add(ids.getString(i)); if (syncType == ACTIVE_SYNC || syncType == ARCHIVE_SYNC) return list_need; final GameDataDB db = new GameDataDB(context); final List<String> list = gameType == Enums.ONLINE_GAME ? db.getOnlineGameIds() : db.getArchiveGameIds(); db.close(); final ArrayList<String> list_have = new ArrayList<String>(list.size()); for (final String item : list) list_have.add(item); list_need.removeAll(list_have); return list_need; } catch (final JSONException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:edu.jhu.cvrg.waveform.utility.WebServiceUtility.java
public static Map<String, String> annotationJSONLookup(String restURL, String... key) { Map<String, String> ret = null; URL url;/* w w w. j av a 2 s . c o m*/ HttpURLConnection conn = null; try { if (System.currentTimeMillis() > waitUntil) { url = new URL(restURL); conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("Accept", "application/json"); BufferedReader in = new BufferedReader(new InputStreamReader((conn.getInputStream()))); String jsonSrc = in.readLine(); in.close(); JSONObject jsonObject = new JSONObject(jsonSrc); ret = new HashMap<String, String>(); for (int i = 0; i < key.length; i++) { Object atr = jsonObject.get(key[i]); String value = ""; if (atr instanceof JSONArray) { JSONArray array = ((JSONArray) atr); for (int j = 0; j < array.length(); j++) { value += array.getString(j); } } else { value = atr.toString(); } if (value.isEmpty()) { value = "No " + key[i] + " found"; } ret.put(key[i], value); } } else { log.warn("Waiting the bioportal server"); } } catch (MalformedURLException mue) { mue.printStackTrace(); } catch (IOException ioe) { //wait for 1 minute waitUntil = System.currentTimeMillis() + (1000 * 60); log.error(ioe.getMessage()); } catch (JSONException e) { e.printStackTrace(); } return ret; }
From source file:com.norman0406.slimgress.API.Common.EntityBase.java
public EntityBase(JSONArray json) throws JSONException { if (json.length() != 3) throw new JSONException("invalid array size"); mEntityGuid = json.getString(0); mEntityTimestamp = json.getString(1); }