List of usage examples for org.json JSONArray getString
public String getString(int index) throws JSONException
From source file:com.intel.xdk.notification.Notification.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.jav a 2s . c om public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if (action.equals("alert")) { this.alert(args.getString(0), args.getString(1), args.getString(2)); } else if (action.equals("confirm")) { this.confirm(args.getString(0), args.getString(1), args.getString(2), args.getString(3), args.getString(4)); } else if (action.equals("vibrate")) { this.vibrate(); } else if (action.equals("beep")) { this.beep(args.getInt(0)); } else if (action.equals("showBusyIndicator")) { this.showBusyIndicator(); } else if (action.equals("hideBusyIndicator")) { this.hideBusyIndicator(); } else { return false; } // All actions are async. //callbackContext.success(); return true; }
From source file:com.oakesville.mythling.util.MythTvParser.java
/** * @param mediaType/* w ww.j ava 2 s .c o m*/ * @param storageGroup media storage group * @param basePath base path to trim from filename (when no storage group) */ public MediaList parseMediaList(MediaType mediaType, Map<String, StorageGroup> storageGroups, String basePath) throws JSONException, ParseException { MediaList mediaList = new MediaList(); mediaList.setMediaType(mediaType); mediaList.setBasePath(basePath); long startTime = System.currentTimeMillis(); JSONObject list = new JSONObject(json); SortType sortType = appSettings.getMediaSettings().getSortType(); if (list.has("VideoMetadataInfoList")) { // videos, movies, or tvSeries MediaSettings mediaSettings = appSettings.getMediaSettings(); JSONObject infoList = list.getJSONObject("VideoMetadataInfoList"); if (infoList.has("Version")) mediaList.setMythTvVersion(infoList.getString("Version")); mediaList.setRetrieveDate(parseMythDateTime(infoList.getString("AsOf"))); JSONArray vids = infoList.getJSONArray("VideoMetadataInfos"); String[] movieDirs = appSettings.getMovieDirs(); String[] tvSeriesDirs = appSettings.getTvSeriesDirs(); String[] vidExcludeDirs = appSettings.getVidExcludeDirs(); int count = 0; for (int i = 0; i < vids.length(); i++) { JSONObject vid = (JSONObject) vids.get(i); MediaType type = MediaType.videos; // determine type if (mediaSettings.getTypeDeterminer() == MediaTypeDeterminer.directories) { if (vid.has("FileName")) { String filePath = vid.getString("FileName"); if (storageGroups.get(appSettings.getVideoStorageGroup()) == null && filePath.startsWith(basePath + "/")) filePath = filePath.substring(basePath.length() + 1); for (String movieDir : movieDirs) { if (filePath.startsWith(movieDir)) { type = MediaType.movies; break; } } for (String tvDir : tvSeriesDirs) { if (filePath.startsWith(tvDir)) { type = MediaType.tvSeries; break; } } for (String vidExcludeDir : vidExcludeDirs) { if (filePath.startsWith(vidExcludeDir)) { type = null; break; } } } } else if (mediaSettings.getTypeDeterminer() == MediaTypeDeterminer.metadata) { if (vid.has("Season")) { String season = vid.getString("Season"); if (!season.isEmpty() && !season.equals("0")) type = MediaType.tvSeries; } if (type != MediaType.tvSeries && vid.has("Inetref")) { String inetref = vid.getString("Inetref"); if (!inetref.isEmpty() && !inetref.equals("00000000")) type = MediaType.movies; } } if (type == mediaType) { try { mediaList.addItemUnderPathCategory(buildVideoItem(type, vid, storageGroups)); count++; } catch (NumberFormatException ex) { Log.e(TAG, "NumberFormatException for " + type + " at index: " + count); } } } mediaList.setCount(count); } else if (list.has("ProgramList")) { // recordings JSONObject infoList = list.getJSONObject("ProgramList"); if (infoList.has("Version")) mediaList.setMythTvVersion(infoList.getString("Version")); mediaList.setRetrieveDate(parseMythDateTime(infoList.getString("AsOf"))); mediaList.setCount(infoList.getString("Count")); JSONArray recs = infoList.getJSONArray("Programs"); for (int i = 0; i < recs.length(); i++) { JSONObject rec = (JSONObject) recs.get(i); try { Recording recItem = buildRecordingItem(rec, storageGroups); if (!"Deleted".equals(recItem.getRecordingGroup()) && !"LiveTV".equals(recItem.getRecordingGroup())) { ViewType viewType = appSettings.getMediaSettings().getViewType(); if ((viewType == ViewType.list || viewType == ViewType.split) && (sortType == null || sortType == SortType.byTitle)) { // categorize by title Category cat = mediaList.getCategory(recItem.getTitle()); if (cat == null) { cat = new Category(recItem.getTitle(), MediaType.recordings); mediaList.addCategory(cat); } cat.addItem(recItem); } else { mediaList.addItem(recItem); } } else { mediaList.setCount(mediaList.getCount() - 1); // otherwise reported count will be off } } catch (NumberFormatException ex) { Log.e(TAG, "NumberFormatException for recording at index: " + i); } } } else if (list.has("ProgramGuide")) { // live tv JSONObject infoList = list.getJSONObject("ProgramGuide"); if (infoList.has("Version")) mediaList.setMythTvVersion(infoList.getString("Version")); mediaList.setRetrieveDate(parseMythDateTime(infoList.getString("AsOf"))); mediaList.setCount(infoList.getString("Count")); JSONArray chans = infoList.getJSONArray("Channels"); for (int i = 0; i < chans.length(); i++) { JSONObject chanInfo = (JSONObject) chans.get(i); try { Item show = buildLiveTvItem(chanInfo); if (show != null) { mediaList.addItem(show); show.setPath(""); } } catch (NumberFormatException ex) { Log.e(TAG, "NumberFormatException for live TV at index: " + i); } } } else if (mediaType == MediaType.music) { JSONArray strList = list.getJSONArray("StringList"); mediaList.setCount(strList.length()); StorageGroup musicStorageGroup = storageGroups.get(appSettings.getMusicStorageGroup()); Map<String, String> dirToAlbumArt = null; if (appSettings.isMusicArtAlbum()) dirToAlbumArt = new HashMap<String, String>(); for (int i = 0; i < strList.length(); i++) { String filepath = strList.getString(i); int lastSlash = filepath.lastIndexOf('/'); String filename = filepath; String path = ""; if (lastSlash > 0 && filepath.length() > lastSlash + 1) { filename = filepath.substring(lastSlash + 1); path = filepath.substring(0, lastSlash); } String title = filename; String format = null; int lastDot = filename.lastIndexOf('.'); if (lastDot > 0 && filename.length() > lastDot + 1) { title = filename.substring(0, lastDot); format = filename.substring(lastDot + 1); } if ("jpg".equals(format) && "cover".equals(title)) { if (dirToAlbumArt != null) dirToAlbumArt.put(path, title + ".jpg"); } else if ("jpg".equals(format) || "jpeg".equals(format) // TODO: better check for image type || "png".equals(format) || "gif".equals(format)) { if (dirToAlbumArt != null) { String imgPath = dirToAlbumArt.get(title + '.' + format); if (!"cover.jpg".equals(imgPath)) // prefer cover.jpg dirToAlbumArt.put(path, title + '.' + format); } } else { Song song = new Song(String.valueOf(i), title); song.setPath(path); song.setFileBase(path + "/" + title); song.setFormat(format); song.setStorageGroup(musicStorageGroup); mediaList.addItemUnderPathCategory(song); } } if (dirToAlbumArt != null && !dirToAlbumArt.isEmpty()) { // set album art for (Item item : mediaList.getAllItems()) { String art = dirToAlbumArt.get(item.getPath()); if (art != null) ((Song) item).setAlbumArt(art); } } } if (sortType != null) { startTime = System.currentTimeMillis(); mediaList.sort(sortType, true); if (BuildConfig.DEBUG) Log.d(TAG, " -> media list parse/sort time: " + (System.currentTimeMillis() - startTime) + " ms"); } else { if (BuildConfig.DEBUG) Log.d(TAG, " -> media list parse time: " + (System.currentTimeMillis() - startTime) + " ms"); } return mediaList; }
From source file:fr.natoine.model_annotation.AnnotationStatus.java
private String createCheckboxes(String _html, String _className, String _status, String _unique_id, int _cpt, JSONArray _choices, int _choices_length) throws JSONException { _html = _html.concat("<input type=hidden name=\"checkboxes_annotation_added_" + _className.toLowerCase() + "_" + _status + "_" + _cpt + "_" + _unique_id + "\" id=\"checkboxes_annotation_added_" + _className.toLowerCase() + "_" + _status + "_" + _cpt + "_" + _unique_id + "\" value=\"\" />"); for (int j = 0; j < _choices_length; j++) { String _value = _choices.getString(j); _html = createCheckbox(_html, _className, _status, _unique_id, _value, _cpt); }/* ww w. j ava 2s. co m*/ return _html; }
From source file:fr.natoine.model_annotation.AnnotationStatus.java
private String oneRadioButtonOnly(String _html, String _className, String _status, JSONArray _choices) throws JSONException { String _value = _choices.getString(0); _html = _html//from w ww. j ava2 s .c o m .concat("<div class=choice><input type=radio name=\"annotation_added_" + _className.toLowerCase() + "_" + _status + "\" value=\"" + _value + "\" checked /> " + _value + "</div>"); return _html; }
From source file:fr.natoine.model_annotation.AnnotationStatus.java
private String radioButtons(String _html, String _className, String _status, JSONArray _choices, int _choices_length) throws JSONException { if (_choices_length == 1) { //un seul choix, radio bouton gris _html = oneRadioButtonOnly(_html, _className, _status, _choices); } else {/*from w w w.j a v a 2s . c om*/ for (int j = 0; j < _choices_length; j++) { String _value = _choices.getString(j); _html = _html.concat( "<div class=choice><input type=radio name=\"annotation_added_" + _className.toLowerCase() + "_" + _status + "\" value=\"" + _value + "\" /> " + _value + "</div>"); } } return _html; }
From source file:fr.natoine.model_annotation.AnnotationStatus.java
private String formMood(String _html, String _className, String _status, String _unique_id, int _cpt, JSONObject _elt, String _true_cardinalite, int _card) throws JSONException { JSONArray _choices = _elt.getJSONArray("choices"); int _choices_length = _choices.length(); if (_choices_length > 0) { if (_true_cardinalite.equalsIgnoreCase("n") || _card > 1) { //checkboxes _html = _html.concat("<input type=hidden name=\"checkboxes_annotation_added_" + _className.toLowerCase() + "_" + _status + "_" + _cpt + "_" + _unique_id + "\" id=\"checkboxes_annotation_added_" + _className.toLowerCase() + "_" + _status + "_" + _cpt + "_" + _unique_id + "\" value=\"\" />"); for (int j = 0; j < _choices_length; j++) { String _value = _choices.getString(j); //_html = _html.concat("<div class=choice><input type=radio name=annotation_added_mood_" + status + " value=\"" + _value + "\" /> " + _value + "</div>"); String _mood = "<img src=/PortletAnnotation-1.0.0/images/mood_" + _value.replaceAll("", "e").replace("", "e") + ".png title=" + _value + " />"; _html = _html.concat("<div class=choice><input type=checkbox name=\"checkbox_" + _className.toLowerCase() + "_" + _status + "_" + _cpt + "_" + _unique_id + "\" value=\"" + _value + "\" /> " + _mood + "</div>"); }/*from w w w .j av a2 s .co m*/ } else //radioButton { if (_choices_length == 1) { //un seul choix, radio bouton gris String _value = _choices.getString(0); _html = _html.concat("<div class=choice><input type=radio name=\"annotation_added_" + _className.toLowerCase() + "_" + _status + "\" value=\"" + _value + "\" checked/> " + _value + "</div>"); } else { for (int j = 0; j < _choices_length; j++) { String _value = _choices.getString(j); //_html = _html.concat("<div class=choice><input type=radio name=annotation_added_mood_" + status + " value=\"" + _value + "\" /> " + _value + "</div>"); String _mood = "<img src=/PortletAnnotation-1.0.0/images/mood_" + _value.replaceAll("", "e").replace("", "e") + ".png title=" + _value + " />"; _html = _html.concat("<div class=choice><input type=radio name=\"annotation_added_" + _className.toLowerCase() + "_" + _status + "\" value=\"" + _value + "\" /> " + _mood + "</div>"); } } } } else _html = _html.concat("<input name=\"annotation_added_" + _className.toLowerCase() + "_" + _status + "\" type=text value=\"\" />"); return _html; }
From source file:org.jbpm.designer.server.diagram.DiagramBuilder.java
/** * adds all json extension to an diagram * /* w ww. j a v a 2 s.c om*/ * @param modelJSON * @param current * @throws org.json.JSONException */ private static void parseSsextensions(JSONObject modelJSON, Diagram current) throws JSONException { if (modelJSON.has("ssextensions")) { JSONArray array = modelJSON.getJSONArray("ssextensions"); for (int i = 0; i < array.length(); i++) { current.addSsextension(array.getString(i)); } } }
From source file:com.funzio.pure2D.particles.nova.vo.NovaVO.java
protected static ArrayList<String> getListString(final JSONObject json, final String field) throws JSONException { // field check if (!json.has(field)) { return null; }/*ww w . j a v a 2s .c om*/ final ArrayList<String> result = new ArrayList<String>(); try { final JSONArray array = json.getJSONArray(field); if (array != null) { final int size = array.length(); for (int i = 0; i < size; i++) { result.add(array.getString(i)); } } } catch (JSONException e) { // single value result.add(json.optString(field)); } return result; }
From source file:com.funzio.pure2D.particles.nova.vo.NovaVO.java
protected static ArrayList<GLColor> getListColor(final JSONObject json, final String field) throws JSONException { // field check if (!json.has(field)) { return null; }// ww w . j av a 2 s .c om final ArrayList<GLColor> result = new ArrayList<GLColor>(); try { final JSONArray array = json.getJSONArray(field); if (array != null) { final int size = array.length(); for (int i = 0; i < size; i++) { if (array.get(i) instanceof String) { result.add(new GLColor(Color.parseColor(array.getString(i)))); } else { result.add(new GLColor(array.getInt(i))); } } } } catch (JSONException e) { // single value if (json.get(field) instanceof String) { result.add(new GLColor(Color.parseColor(json.getString(field)))); } else { result.add(new GLColor(json.getInt(field))); } } return result; }
From source file:com.conferenceengineer.android.iosched.io.SearchSuggestHandler.java
public ArrayList<ContentProviderOperation> parse(String json) throws IOException { final ArrayList<ContentProviderOperation> batch = Lists.newArrayList(); try {/*from ww w . j a v a 2 s. c o m*/ JSONObject root = new JSONObject(json); JSONArray suggestions = root.getJSONArray("words"); batch.add( ContentProviderOperation .newDelete(ScheduleContract .addCallerIsSyncAdapterParameter(ScheduleContract.SearchSuggest.CONTENT_URI)) .build()); for (int i = 0; i < suggestions.length(); i++) { batch.add(ContentProviderOperation .newInsert(ScheduleContract .addCallerIsSyncAdapterParameter(ScheduleContract.SearchSuggest.CONTENT_URI)) .withValue(SearchManager.SUGGEST_COLUMN_TEXT_1, suggestions.getString(i)).build()); } } catch (JSONException e) { Log.e(Config.LOG_TAG, "Problem building word list", e); } return batch; }