// Get IOB and COB only, dont update chart public static JSONObject getIOBCOB(Activity a) { List<Stats> statList = Stats.updateActiveBarChart(a.getBaseContext()); JSONObject reply = new JSONObject(); if (statList.size() > 0) { try { reply.put("iob", String.format(Locale.ENGLISH, "%.2f", statList.get(0).iob)); reply.put("cob", String.format(Locale.ENGLISH, "%.2f", statList.get(0).cob)); } catch (JSONException e) { Crashlytics.logException(e); e.printStackTrace(); } return reply; } else { try { reply.put("iob", String.format(Locale.ENGLISH, "%.2f", 0.00)); reply.put("cob", String.format(Locale.ENGLISH, "%.2f", 0.00)); } catch (JSONException e) { Crashlytics.logException(e); e.printStackTrace(); } return reply; } }
// Updates Stats public static JSONObject updateChart(Activity a) { JSONObject reply = new JSONObject(); List<Stats> statList = Stats.updateActiveBarChart(a.getBaseContext()); if (iobcobChart != null || statList != null || statList.size() > 0) { // reloads charts with Treatment data iobcobChart.setColumnChartData(extendedGraphBuilder.iobcobFutureChart(statList)); try { reply.put("iob", String.format(Locale.ENGLISH, "%.2f", statList.get(0).iob)); reply.put("cob", String.format(Locale.ENGLISH, "%.2f", statList.get(0).cob)); } catch (JSONException e) { Crashlytics.logException(e); e.printStackTrace(); } return reply; } else { try { reply.put("iob", String.format(Locale.ENGLISH, "%.2f", 0.00)); reply.put("cob", String.format(Locale.ENGLISH, "%.2f", 0.00)); } catch (JSONException e) { Crashlytics.logException(e); e.printStackTrace(); } return reply; } }