@Override protected Boolean doInBackground(Void... params) { Log.v("TASK", "doInBackground GetLoadPreDataTask"); List<Net> netList = CacheHelper.getCacheNetList(); List<Station> stationList = CacheHelper.getCacheStationList(); if (netList != null && netList.size() > 0 && stationList != null && stationList.size() > 0) { return true; } boolean netSuc = false; boolean stationSuc = false; try { if (netList == null || netList.size() <= 0) { String method = WebServiceHelper.S_getExpNetList; String inputParams = WebServiceHelper.getInputParam( WebServiceHelper.getNetParams(ApplicationHelper.getIMEI(mContext))); String nets = WebServiceHelper.getService(inputParams, method); Log.v("TASK", nets); if (nets != null) { JSONObject obj = new JSONObject(nets); if (ParseJSON.CODE_SUCCESS.equals(obj.getString(ParseJSON.RetCode))) { // 缓存数据 JSONArray ja = obj.getJSONArray(ParseJSON.ResultObj); CacheHelper.setCacheNetList(ParseJSON.parseToNetList(ja)); netSuc = true; } } } else { netSuc = true; } if (stationList == null || stationList.size() <= 0) { String method = WebServiceHelper.S_getStation; String inputParams = WebServiceHelper.getInputParam( WebServiceHelper.getStationParams(ApplicationHelper.getIMEI(mContext))); String stations = WebServiceHelper.getService(inputParams, method); Log.v("TASK", stations); if (stations != null) { JSONObject obj = new JSONObject(stations); if (ParseJSON.CODE_SUCCESS.equals(obj.getString(ParseJSON.RetCode))) { JSONArray ja = obj.getJSONArray(ParseJSON.ResultObj); CacheHelper.setCacheStationList(ParseJSON.parseToStationList(ja)); stationSuc = true; } } } else { stationSuc = true; } return netSuc && stationSuc; } catch (JSONException | IOException | XmlPullParserException e) { e.printStackTrace(); return false; } }
/** * Method to download all available historical currency values for a given time period and store * them into RateHistorical object, which will then be used to populate the database. */ private void getHistRates(String url) { try { String s = moneta.getJson(url); int count = new JSONObject(s).getJSONObject("query").getInt("count"); if (count > 1) { JSONArray jsonArray = new JSONObject(s).getJSONObject("query").getJSONObject("results").getJSONArray("quote"); for (int j = 0; j < jsonArray.length(); j++) { JSONObject _quote = jsonArray.getJSONObject(j); String symbol = _quote .getString("Symbol") .substring(0, 3); // Return value would be EUR and not EUR%3dX String date = _quote.getString("Date"); String open = _quote.getString("Open"); String high = _quote.getString("High"); String low = _quote.getString("Low"); String close = _quote.getString("Close"); String volume = _quote.getString("Volume"); String adj_close = _quote.getString("Adj_Close"); RateHistorical histRate = new RateHistorical(symbol, date, open, high, low, close, volume, adj_close); populateDbWithHistRates(histRate); } } else { JSONObject _quote = new JSONObject(s) .getJSONObject("query") .getJSONObject("results") .getJSONObject("quote"); String symbol = _quote.getString("Symbol").substring(0, 3); // Return value would be EUR and not EUR%3dX String date = _quote.getString("Date"); String open = _quote.getString("Open"); String high = _quote.getString("High"); String low = _quote.getString("Low"); String close = _quote.getString("Close"); String volume = _quote.getString("Volume"); String adj_close = _quote.getString("Adj_Close"); RateHistorical histRate = new RateHistorical(symbol, date, open, high, low, close, volume, adj_close); populateDbWithHistRates(histRate); } } catch (JSONException | IOException e) { e.printStackTrace(); } }
/* * 计算将要传递给 DashboardActivity 的通知数值 */ private void processDataCount() { try { kpiCount = getDataCount(URLs.kTabKpi, kpiUrl); analyseCount = getDataCount(URLs.kTabAnalyse, analyseUrl); appCount = getDataCount(URLs.kTabApp, appUrl); messageCount = getDataCount(URLs.kTabMessage, messageUrl); thursdaySayCount = getDataCount(URLs.kSettingThursdaySay, thursdaySayUrl); /* * 遍历获取 Tab 栏上需要显示的通知数量 ("tab_*" 的值) */ String[] typeString = { URLs.kTabKpi, URLs.kTabAnalyse, URLs.kTabApp, URLs.kTabMessage, URLs.kSettingThursdaySay }; int[] typeCount = {kpiCount, analyseCount, appCount, messageCount, thursdaySayCount}; for (int i = 0; i < typeString.length; i++) { notificationJSON.put( typeString[i], Math.abs(typeCount[i] - notificationJSON.getInt(typeString[i] + "_last"))); notificationJSON.put(typeString[i] + "_last", typeCount[i]); } if ((new File(pgyerVersionPath)).exists()) { pgyerJSON = FileUtil.readConfigFile(pgyerVersionPath); JSONObject responseData = pgyerJSON.getJSONObject(URLs.kData); pgyerCode = responseData.getString("versionCode"); packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0); versionCode = String.valueOf(packageInfo.versionCode); updataCount = pgyerCode.equals(versionCode) ? -1 : 1; } else { updataCount = -1; } passwordCount = userJSON.getString(URLs.kPassword).equals(URLs.MD5(K.kInitPassword)) ? 1 : -1; notificationJSON.put(URLs.kSettingPassword, passwordCount); notificationJSON.put(URLs.kSettingPgyer, updataCount); int settingCount = (notificationJSON.getInt(URLs.kSettingPassword) > 0 || notificationJSON.getInt(URLs.kSettingPgyer) > 0 || notificationJSON.getInt(URLs.kSettingThursdaySay) > 0) ? 1 : 0; notificationJSON.put(URLs.kSetting, settingCount); FileUtil.writeFile(notificationPath, notificationJSON.toString()); } catch (JSONException | IOException | PackageManager.NameNotFoundException e) { e.printStackTrace(); } }
public static void main(String[] args) { try { Token token = new Token("your token here"); GroupList gList = new GroupList(token); ChannelsList cList = new ChannelsList(token); System.out.println("Group List: "); for (ChatRoom room : gList.getGroups()) System.out.println(room.getName() + " " + room.getId()); System.out.println(); System.out.println("Channel List: "); for (ChatRoom room : cList.getGroups()) System.out.println(room.getName() + " " + room.getId()); } catch (JSONException | IOException e) { e.printStackTrace(); } }
@Override protected String doInBackground(String... params) { // replaceAll pour supprimer les espace try { OkHttpClient client = new OkHttpClient(); RequestBody formBody = new FormEncodingBuilder() // new FormBody.Builder() .add("id_diffuseur", id_diffuseur) .add("nom_evenement", params[0]) .add("date_evenement", params[2]) .add("mdp_evenement", params[1]) .build(); Request request = new Request.Builder() .url("http://jukeboxv20.olympe.in/android/ajout_evenement.php") .post(formBody) .build(); Response responses = client.newCall(request).execute(); String jsonData = responses.body().string(); JSONObject jobject = new JSONObject(jsonData); succesRequete = jobject.getInt("success"); if (succesRequete == 1) { Log.i("msg id evenement ", jobject.get("id_evenement").toString()); Log.i("msg nom evenement ", jobject.get("nom_evenement").toString()); return jobject.getString("message"); } else { return jobject.getString("message"); } } catch (JSONException | IOException e) { e.printStackTrace(); } return null; }
public void ConsumoCardView() { String msg = "AVISO:"; try { URL url = new URL("http://www.comunidadesvirtualesonline.com/notifications/singup.php?token="); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); InputStream in = new BufferedInputStream(urlConnection.getInputStream()); BufferedReader streamReader = new BufferedReader(new InputStreamReader(in, "UTF-8")); StringBuilder responseStrBuilder = new StringBuilder(); String inputStr; while ((inputStr = streamReader.readLine()) != null) responseStrBuilder.append(inputStr); JSONObject responsJson = new JSONObject(responseStrBuilder.toString()); /* String JsonTitulo = responsJson.getString("titulo"); String JsonNomestu = responsJson.getString("nombreestu"); String JsonFecha = responsJson.getString("fecha"); */ String JsonTitulo = "HOLA .... !"; String JsonNomestu = "daniel Pardo C."; String JsonFecha = "07/06/06"; TextView CardViewTitulo = (TextView) findViewById(R.id.Titulo); TextView CarViewNombres = (TextView) findViewById(R.id.NombreEstudiante); TextView CardViewFecha = (TextView) findViewById(R.id.fechaNotificacion); CardViewTitulo.setText(JsonTitulo); CarViewNombres.setText(JsonNomestu); CardViewFecha.setText(JsonFecha); } catch (JSONException | IOException e) { e.printStackTrace(); Log.i(msg, "ERROR: " + e); } }