List of usage examples for android.util JsonReader nextInt
public int nextInt() throws IOException
From source file:com.fuzz.android.limelight.util.JSONTool.java
/** * @param reader/*from w w w.j a va 2 s. co m*/ * @return the generated Act object from the JSON * @throws IOException */ public static Act readAct(JsonReader reader) throws IOException { int id = -1; String message = null; int messageResId = -1; int graphResId = -1; boolean isActionBarItem = false; double xOffset = -1; double yOffset = -1; int textColor = -1; int textBackgroundColor = -1; float textSize = -1; boolean textBackgroundTransparent = false; String animation = null; String activityName = null; reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if (name.equals("id")) id = reader.nextInt(); else if (name.equals("message")) message = reader.nextString(); else if (name.equals("message_res_id")) messageResId = reader.nextInt(); else if (name.equals("graphic_res_id")) graphResId = reader.nextInt(); else if (name.equals("is_action_bar_item")) isActionBarItem = reader.nextBoolean(); else if (name.equals("x_offset")) xOffset = reader.nextDouble(); else if (name.equals("y_offset")) yOffset = reader.nextDouble(); else if (name.equals("text_color")) textColor = reader.nextInt(); else if (name.equals("text_background_color")) textBackgroundColor = reader.nextInt(); else if (name.equals("text_size")) textSize = reader.nextLong(); else if (name.equals("text_background_transparent")) textBackgroundTransparent = reader.nextBoolean(); else if (name.equals("animation")) animation = reader.nextString(); else if (name.equals("activity_name")) activityName = reader.nextString(); else reader.skipValue(); } reader.endObject(); Act act = new Act(); act.setId(id); act.setMessage(message); act.setMessageResID(messageResId); act.setGraphicResID(graphResId); act.setIsActionBarItem(isActionBarItem); act.setDisplacement(xOffset, yOffset); act.setTextColor(textColor); act.setTextBackgroundColor(textBackgroundColor); act.setTextSize(textSize); act.setTransparentBackground(textBackgroundTransparent); act.setAnimation(animation); act.setActivityName(activityName); act.getLayout(); return act; }
From source file:pedromendes.tempodeespera.HospitalDetailActivity.java
public void fillQueue(JsonReader reader, EmergencyQueue queue) throws IOException { reader.nextName();//from ww w . j av a 2 s .c o m int time = reader.nextInt(); reader.nextName(); int length = reader.nextInt(); queue.setTime(time); queue.setLength(length); }
From source file:com.fuzz.android.limelight.util.JSONTool.java
/** * @param reader//from ww w.jav a 2 s . com * @return the generated ChapterTransition object from JSON * @throws IOException */ public static ChapterTransition readTransition(JsonReader reader) throws IOException { long time = -1; int itemPosition = -1; int childId = -1; int anchorId = -1; String message = null; int messageResId = -1; int grapicResID = -1; boolean isActionBarItem = false; double xOffset = -1; double yOffset = -1; int textColor = -1; int textBackgroundColor = -1; float textSize = -1; boolean textBackgroundTransparent = false; String animation = null; while (reader.hasNext()) { try { String name = reader.nextName(); if (name.equals("time")) time = reader.nextLong(); else if (name.equals("item_position")) itemPosition = reader.nextInt(); else if (name.equals("child_id")) childId = reader.nextInt(); else if (name.equals("id")) anchorId = reader.nextInt(); else if (name.equals("message")) message = reader.nextString(); else if (name.equals("message_res_id")) messageResId = reader.nextInt(); else if (name.equals("graphic_res_id")) grapicResID = reader.nextInt(); else if (name.equals("is_action_bar_item")) isActionBarItem = reader.nextBoolean(); else if (name.equals("x_offset")) xOffset = reader.nextDouble(); else if (name.equals("y_offset")) yOffset = reader.nextDouble(); else if (name.equals("text_color")) textColor = reader.nextInt(); else if (name.equals("text_background_color")) textBackgroundColor = reader.nextInt(); else if (name.equals("text_size")) textSize = reader.nextLong(); else if (name.equals("text_background_transparent")) textBackgroundTransparent = reader.nextBoolean(); else if (name.equals("animation")) animation = reader.nextString(); } catch (IllegalStateException e) { reader.nextNull(); e.printStackTrace(); } } reader.endObject(); ChapterTransition transition = new ChapterTransition(); transition.setTime(time); transition.setItemPosition(itemPosition); transition.setChildID(childId); transition.setId(anchorId); transition.setMessage(message); transition.setMessageResID(messageResId); transition.setGraphicResID(grapicResID); transition.setIsActionBarItem(isActionBarItem); transition.setDisplacement(xOffset, yOffset); transition.setTextColor(textColor); transition.setTextBackgroundColor(textBackgroundColor); transition.setTextSize(textSize); transition.setTransparentBackground(textBackgroundTransparent); transition.setAnimation(animation); return transition; }
From source file:com.morlunk.leeroy.LeeroyUpdateService.java
private void handleCheckUpdates(Intent intent, boolean notify, ResultReceiver receiver) { List<LeeroyApp> appList = LeeroyApp.getApps(getPackageManager()); if (appList.size() == 0) { return;// ww w . j a va 2 s . c o m } List<LeeroyAppUpdate> updates = new LinkedList<>(); List<LeeroyApp> notUpdatedApps = new LinkedList<>(); List<LeeroyException> exceptions = new LinkedList<>(); for (LeeroyApp app : appList) { try { String paramUrl = app.getJenkinsUrl() + "/api/json?tree=lastSuccessfulBuild[number,url]"; URL url = new URL(paramUrl); URLConnection conn = url.openConnection(); Reader reader = new InputStreamReader(conn.getInputStream()); JsonReader jsonReader = new JsonReader(reader); jsonReader.beginObject(); jsonReader.nextName(); jsonReader.beginObject(); int latestSuccessfulBuild = 0; String buildUrl = null; while (jsonReader.hasNext()) { String name = jsonReader.nextName(); if ("number".equals(name)) { latestSuccessfulBuild = jsonReader.nextInt(); } else if ("url".equals(name)) { buildUrl = jsonReader.nextString(); } else { throw new RuntimeException("Unknown key " + name); } } jsonReader.endObject(); jsonReader.endObject(); jsonReader.close(); if (latestSuccessfulBuild > app.getJenkinsBuild()) { LeeroyAppUpdate update = new LeeroyAppUpdate(); update.app = app; update.newBuild = latestSuccessfulBuild; update.newBuildUrl = buildUrl; updates.add(update); } else { notUpdatedApps.add(app); } } catch (MalformedURLException e) { e.printStackTrace(); CharSequence appName = app.getApplicationInfo().loadLabel(getPackageManager()); exceptions.add(new LeeroyException(app, getString(R.string.invalid_url, appName), e)); } catch (IOException e) { e.printStackTrace(); exceptions.add(new LeeroyException(app, e)); } } if (notify) { NotificationManagerCompat nm = NotificationManagerCompat.from(this); if (updates.size() > 0) { NotificationCompat.Builder ncb = new NotificationCompat.Builder(this); ncb.setSmallIcon(R.drawable.ic_stat_update); ncb.setTicker(getString(R.string.updates_available)); ncb.setContentTitle(getString(R.string.updates_available)); ncb.setContentText(getString(R.string.num_updates, updates.size())); ncb.setPriority(NotificationCompat.PRIORITY_LOW); ncb.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); Intent appIntent = new Intent(this, AppListActivity.class); appIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); ncb.setContentIntent( PendingIntent.getActivity(this, 0, appIntent, PendingIntent.FLAG_CANCEL_CURRENT)); ncb.setAutoCancel(true); NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(); for (LeeroyAppUpdate update : updates) { CharSequence appName = update.app.getApplicationInfo().loadLabel(getPackageManager()); style.addLine(getString(R.string.notify_app_update, appName, update.app.getJenkinsBuild(), update.newBuild)); } style.setSummaryText(getString(R.string.app_name)); ncb.setStyle(style); ncb.setNumber(updates.size()); nm.notify(NOTIFICATION_UPDATE, ncb.build()); } if (exceptions.size() > 0) { NotificationCompat.Builder ncb = new NotificationCompat.Builder(this); ncb.setSmallIcon(R.drawable.ic_stat_error); ncb.setTicker(getString(R.string.error_checking_updates)); ncb.setContentTitle(getString(R.string.error_checking_updates)); ncb.setContentText(getString(R.string.click_to_retry)); ncb.setPriority(NotificationCompat.PRIORITY_LOW); ncb.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); ncb.setContentIntent(PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT)); ncb.setAutoCancel(true); ncb.setNumber(exceptions.size()); nm.notify(NOTIFICATION_ERROR, ncb.build()); } } if (receiver != null) { Bundle results = new Bundle(); results.putParcelableArrayList(EXTRA_UPDATE_LIST, new ArrayList<>(updates)); results.putParcelableArrayList(EXTRA_NO_UPDATE_LIST, new ArrayList<>(notUpdatedApps)); results.putParcelableArrayList(EXTRA_EXCEPTION_LIST, new ArrayList<>(exceptions)); receiver.send(0, results); } }
From source file:br.com.thinkti.android.filechooserfrag.fragFileChooserQuizlet.java
private List<RowData> openPage() throws Exception { this.errorDescription = null; this.errorTitle = null; List<RowData> list = new ArrayList<RowData>(); InputStream inputStream = null; try {//from w ww . j a v a2 s . c om if (!blnPrivate) { URL url = new URL(getCatalogUrl()); /*HttpURLConnection connection = (HttpURLConnection) url.openConnection(); if ( connection.getResponseCode() >= 400 ) { inputStream = connection.getErrorStream(); } else { inputStream = connection.getInputStream(); }*/ inputStream = org.liberty.android.fantastischmemo.downloader.quizlet.lib.makeApiCall(url, _main.QuizletAccessToken); } else { inputStream = org.liberty.android.fantastischmemo.downloader.quizlet.lib .getUserPrivateCardsets(_main.QuizletUser, _main.QuizletAccessToken); } JsonReader reader = new JsonReader(new InputStreamReader(inputStream, "UTF-8")); if (!blnPrivate) { reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if ("total_pages".equals(name)) { this.totalPages = reader.nextInt(); if (page > totalPages) { } } else if ("total_results".equals(name)) { this.totalResults = reader.nextInt(); } else if ("page".equals(name)) { this.page = reader.nextInt(); } else if ("error_title".equals(name)) { errorTitle = reader.nextString(); } else if ("error_description".equals(name)) { errorDescription = reader.nextString(); } else if ("sets".equals(name)) { getSets(reader, list); } else { reader.skipValue(); } } reader.endObject(); } else { getSets(reader, list); } } finally { if (inputStream != null) { inputStream.close(); } } return list; }
From source file:br.com.thinkti.android.filechooserfrag.fragFileChooserQuizlet.java
RowData parseSetJson(JsonReader reader) throws IOException { reader.beginObject();/*from ww w . j a v a2 s . c o m*/ RowData rowData = new RowData(); while (reader.hasNext()) { String name = reader.nextName(); if (name.equals("title")) { rowData.name = reader.nextString(); } else if (name.equals("description")) { rowData.description = reader.nextString(); if (rowData.description.length() > 200) rowData.description = rowData.description.substring(0, 100); } else if (name.equals("id")) { rowData.id = reader.nextInt(); } else if (name.equals("term_count")) { rowData.numCards = reader.nextInt(); } else if (name.equals("modified_date")) { long value = reader.nextLong(); rowData.lastModified = Data.SHORT_DATE_FORMAT.format(new Date(value * 1000)); Log.d(Data.APP_ID, " modified_date value=" + value + " formatted=" + rowData.lastModified + " now=" + (new Date().getTime())); } else { reader.skipValue(); } } reader.endObject(); return rowData; }
From source file:ngo.music.soundcloudplayer.controller.SongController.java
/** * get stack of songs played//from w w w.j a v a 2 s .c om * * @return */ public ArrayList<Object[]> getSongsPlayed() { File file = new File(MusicPlayerService.getInstance().getApplicationContext() .getExternalFilesDir(Context.ACCESSIBILITY_SERVICE), filename); if (!file.exists()) { try { file.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } ArrayList<Object[]> songs = new ArrayList<Object[]>(); try { FileInputStream fileReader = new FileInputStream(file); JsonReader reader = new JsonReader(new InputStreamReader(fileReader)); String id = null; reader.beginArray(); while (reader.hasNext()) { reader.beginObject(); while (reader.hasNext()) { Object[] object = new Object[2]; id = reader.nextName(); object[0] = getSong(id); object[1] = Integer.valueOf(reader.nextInt()); if (object[0] != null) { songs.add(object); } } reader.endObject(); } reader.endArray(); reader.close(); } catch (Exception e) { Log.e("get songPlayed", e.toString()); return songs; } return songs; }
From source file:br.com.thinkti.android.filechooserfrag.fragFileChooserQuizlet.java
private List<typVok> openSet(String id) throws Exception { this.errorDescription = null; this.errorTitle = null; InputStream inputStream = null; List<typVok> list = new ArrayList<typVok>(); String Kom = ""; _main.vok.title = ""; try {// ww w. ja v a2s .co m URL url = new URL(getDeckUrl(id)); /* HttpURLConnection connection = (HttpURLConnection) url.openConnection(); if ( connection.getResponseCode() >= 400 ) { inputStream = connection.getErrorStream(); } else { inputStream = connection.getInputStream(); } */ inputStream = org.liberty.android.fantastischmemo.downloader.quizlet.lib.makeApiCall(url, _main.QuizletAccessToken); JsonReader reader = new JsonReader(new InputStreamReader(inputStream, "UTF-8")); reader.beginArray(); while (reader.hasNext()) { reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if ("id".equals(name)) { long intId = reader.nextLong(); /*if (page > totalPages) { }*/ } else if ("url".equals(name)) { String strUrl = reader.nextString(); } else if ("title".equals(name)) { String title = reader.nextString(); _main.vok.title = title; } else if ("created_by".equals(name)) { String created_by = reader.nextString(); Kom = _main.getString(R.string.created_by) + " " + created_by + " " + _main.getString((R.string.at)) + " <link://https://quizlet.com/ Quizlet/>"; } else if ("term_count".equals(name)) { int term_count = reader.nextInt(); } else if ("lang_terms".equals(name)) { String lang_terms = reader.nextString(); try { _LangWord = new Locale(lang_terms.replace("-", "_")); } catch (Throwable ex) { } } else if ("lang_definitions".equals(name)) { String lang_definitions = reader.nextString(); try { _LangMeaning = (new Locale(lang_definitions.replace("-", "_"))); } catch (Throwable ex) { } } else if ("terms".equals(name)) { reader.beginArray(); while (reader.hasNext()) { typVok v = parseSetDataJson(reader); String kom = v.Kom; v.Kom = Kom; if (!lib.libString.IsNullOrEmpty(kom)) { v.Kom += " " + kom; } list.add(v); } reader.endArray(); } else { reader.skipValue(); } } reader.endObject(); } reader.endArray(); } finally { if (inputStream != null) { inputStream.close(); } } return list; }