1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
|
private class GetContacts extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Showing progress dialog
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage("Veuillez patienter...");
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected Void doInBackground(Void... arg0) {
final Calendar mcurrentDate=Calendar.getInstance();
final int mYear = mcurrentDate.get(Calendar.YEAR);
final int mMonth = mcurrentDate.get(Calendar.MONTH);
final int mDay = mcurrentDate.get(Calendar.DAY_OF_MONTH);
mcurrentDate.set(mYear, mMonth, mDay);
String date = dateFormatter.format(mcurrentDate.getTime());
HttpHandler sh = new HttpHandler();
String url = "http://212.73.150.166/api/v1/daily_reports/last_reporting";
// Making a request to url and getting response
String jsonStr = sh.makeServiceCall(url);
Log.e(TAG, "Response from url: " + jsonStr);
if (jsonStr != null) {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
// Getting JSON Object node
JSONObject contacts = jsonObj.getJSONObject("json");
// Phone node is JSON Object
JSONObject phone = contacts.getJSONObject("result");
JSONObject stock_initial = phone.getJSONObject("stock_initial");
final String stock_initial1 = stock_initial.getString("type_1");
final String stock_initial2 = stock_initial.getString("type_2");
final String stock_initialb = stock_initial.getString("box");
Log.e(TAG, "BOX: " + stock_initialb);
JSONObject appro_oci1 = phone.getJSONObject("appro_oci1");
final String appro_oci11 = appro_oci1.getString("type_1");
final String appro_oci12 = appro_oci1.getString("type_2");
final String appro_oci1b = appro_oci1.getString("box");
JSONObject stock_final = phone.getJSONObject("stock_final");
final String stock_final1 = stock_final.getString("type_1");
final String stock_final2 = stock_final.getString("type_2");
final String stock_finalb = stock_final.getString("box");
JSONObject commissions_theoriques = phone.getJSONObject("commissions_theoriques");
final String commissions_theoriques1 = commissions_theoriques.getString("type_1");
final String commissions_theoriques2 = commissions_theoriques.getString("type_2");
final String commissions_theoriquesb = commissions_theoriques.getString("box");
JSONObject somme_ecart = phone.getJSONObject("somme_ecart");
final String somme_ecart1 = somme_ecart.getString("type_1");
final String somme_ecart2 = somme_ecart.getString("type_2");
final String somme_ecartb = somme_ecart.getString("box");
JSONObject commissions = phone.getJSONObject("somme_commissions");
final String somme_commissions1 = commissions.getString("type_1");
final String somme_commissions2 = commissions.getString("type_2");
final String somme_commissionsb = commissions.getString("box");
JSONObject appro_box = phone.getJSONObject("appro_box");
final String appro_box1 = appro_box.getString("type_1");
final String appro_box2 = appro_box.getString("type_2");
final String appro_boxb = appro_box.getString("box");
JSONObject sf_veille = phone.getJSONObject("sf_veille");
final String sf_veille1 = sf_veille.getString("type_1");
final String sf_veille2 = sf_veille.getString("type_2");
final String sf_veilleb = sf_veille.getString("box");
JSONObject rechargement_reel = phone.getJSONObject("rechargement_reel");
final String rechargement_reel1 = rechargement_reel.getString("type_1");
final String rechargement_reel2 = rechargement_reel.getString("type_2");
final String rechargement_reelb = rechargement_reel.getString("box");
int somme1 = Integer.parseInt(somme_commissions1);
int somme2 = Integer.parseInt(somme_commissionsb);
int somme3 = Integer.parseInt(somme_commissions2);
final int somme = somme1 + somme2 + somme3;
int initial1 = Integer.parseInt(stock_initial1);
int initial2 = Integer.parseInt(stock_initialb);
int initial3 = Integer.parseInt(stock_initial2);
final int initial = initial1 + initial2 + initial3;
int appro1 = Integer.parseInt(appro_oci11);
int appro2 = Integer.parseInt(appro_oci1b);
int appro3 = Integer.parseInt(appro_oci12);
final int appro = appro1 + appro2 + appro3;
int final1 = Integer.parseInt(stock_final1);
int final2 = Integer.parseInt(stock_finalb);
int final3 = Integer.parseInt(stock_final2);
final int fina = final1 + final2 + final3;
int theo1 = Integer.parseInt(commissions_theoriques1);
int theo2 = Integer.parseInt(commissions_theoriquesb);
int theo3 = Integer.parseInt(commissions_theoriques2);
final int theo = theo1 + theo2 + theo3;
int ecart1 = Integer.parseInt(somme_ecart1);
int ecart2 = Integer.parseInt(somme_ecartb);
int ecart3 = Integer.parseInt(somme_ecart2);
final int ecart = ecart1 + ecart2 + ecart3;
int appbox1 = Integer.parseInt(appro_box1);
int appbox2 = Integer.parseInt(appro_boxb);
int appbox3 = Integer.parseInt(appro_box2);
final int appbox = appbox1 + appbox2 + appbox3;
int recha1 = Integer.parseInt(rechargement_reel1);
int recha2 = Integer.parseInt(rechargement_reelb);
int recha3 = Integer.parseInt(rechargement_reel2);
final int recha = recha1 + recha2 + recha3;
int sf1 = Integer.parseInt(sf_veille1);
int sf2 = Integer.parseInt(sf_veilleb);
int sf3 = Integer.parseInt(sf_veille2);
final int sf = sf1 + sf2 + sf3;
runOnUiThread(new Runnable() {
@Override
public void run() {
somm.setText(""+somme);
somm2 = (TextView) findViewById(R.id.somme_commissions2);
initia2 = (TextView) findViewById(R.id.stock_initial2);
appr2 = (TextView) findViewById(R.id.appro_oci12);
fin2 = (TextView) findViewById(R.id.stock_final2);
theoriqu2 = (TextView) findViewById(R.id.commissions_theoriques2);
ecar2 = (TextView) findViewById(R.id.somme_ecart2);
approbox2 = (TextView) findViewById(R.id.appro_box2);
net2 = (TextView) findViewById(R.id.rechargement_reel2);
veille2 = (TextView) findViewById(R.id.sf_veille2);
sommb = (TextView) findViewById(R.id.somme_commissionsb);
initiab = (TextView) findViewById(R.id.stock_initialb);
apprb = (TextView) findViewById(R.id.appro_oci1b);
finb = (TextView) findViewById(R.id.stock_finalb);
theoriqub = (TextView) findViewById(R.id.commissions_theoriquesb);
ecarb = (TextView) findViewById(R.id.somme_ecartb);
approboxb = (TextView) findViewById(R.id.appro_boxb);
netb = (TextView) findViewById(R.id.rechargement_reelb);
veilleb = (TextView) findViewById(R.id.sf_veilleb);
somm1 = (TextView) findViewById(R.id.commissions);
initia1 = (TextView) findViewById(R.id.initial);
appr1 = (TextView) findViewById(R.id.oci1);
fin1 = (TextView) findViewById(R.id.fin);
theoriqu1 = (TextView) findViewById(R.id.theoriques);
ecar1 = (TextView) findViewById(R.id.ecart);
approbox1 = (TextView) findViewById(R.id.box);
net1 = (TextView) findViewById(R.id.reel);
veille1 = (TextView) findViewById(R.id.veille);
initiat = (TextView) findViewById(R.id.stock_initialt);
apprt = (TextView) findViewById(R.id.appro_oci1t);
fint = (TextView) findViewById(R.id.stock_finalt);
theoriqut = (TextView) findViewById(R.id.commissions_theoriquest);
ecartt = (TextView) findViewById(R.id.somme_ecartt);
approboxt = (TextView) findViewById(R.id.appro_boxt);
nett = (TextView) findViewById(R.id.rechargement_reelt);
veillet = (TextView) findViewById(R.id.sf_veillet);
somm2.setText(somme_commissions2);
initia2.setText(stock_initial2);
appr2.setText(appro_oci12);
fin2.setText(stock_final2);
theoriqu2.setText(commissions_theoriques2);
ecar2.setText(somme_ecart2);
approbox2.setText(appro_box2);
net2.setText(rechargement_reel2);
veille2.setText(sf_veille2);
sommb.setText(somme_commissionsb);
initiab.setText(stock_initialb);
apprb.setText(appro_oci1b);
finb.setText(stock_finalb);
theoriqub.setText(commissions_theoriquesb);
ecarb.setText(somme_ecartb);
approboxb.setText(appro_boxb);
netb.setText(rechargement_reelb);
veilleb.setText(sf_veilleb);
somm1.setText(somme_commissions1);
// initia1.setText(stock_initial1);
// appr1.setText(appro_oci11);
// fin1.setText(stock_final1);
// theoriqu1.setText(commissions_theoriques1);
// ecar1.setText(somme_ecart1);
// approbox1.setText(appro_box1);
// net1.setText(rechargement_reel1);
// veille1.setText(sf_veille1);
//
// initiat.setText(""+initial);
// apprt.setText(""+appro);
// fint.setText(""+fina);
// theoriqut.setText(""+theo);
// ecartt.setText(""+ecart);
// approboxt.setText(""+appbox);
// nett.setText(""+recha);
// veillet.setText(""+sf);
}
});
} catch (final JSONException e) {
Log.e(TAG, "Json parsing error: " + e.getMessage());
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),
"Json parsing error: " + e.getMessage(),
Toast.LENGTH_LONG)
.show();
}
});
}
} else {
Log.e(TAG, "Couldn't get json from server.");
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),
"Couldn't get json from server. Check LogCat for possible errors!",
Toast.LENGTH_LONG)
.show();
}
});
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
// Dismiss the progress dialog
if (pDialog.isShowing())
pDialog.dismiss();
/**
* Updating parsed JSON data into ListView
* */
}
} |
Partager