@Override public boolean onPostExecute(RequestInfo req) { switch (req.getStatusCode()) { case HttpStatus.SC_OK: Item item = new Item(PostActivity.this); HashMap<Integer, String> map = new HashMap<Integer, String>(); for (Gc value : items) { if (value.gcid == 0) { continue; } map.put(value.gcid, value.name); } item.setGcList(map); ArrayAdapter<String> adapter = new ArrayAdapter<String>( context, android.R.layout.simple_spinner_item, item.getGcValues()); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spin.setAdapter(adapter); break; default: Utility.log(PostActivity.this, "error:" + req.getStatusCode()); break; } return true; }
public void post() { init(); if (validation() == false) { String msg = ""; for (String errMsg : errorMessages) { msg += errMsg + "\n"; } msg = msg.replaceAll("\\n$", ""); Toast.makeText(PostActivity.this, msg, Toast.LENGTH_LONG).show(); return; } String url = String.format( POST_API, item.spotId, pref.getString("settings_uid", null), pref.getString("settings_passwd_md5", null), "andrggr", "3wdfhwsedefn437wof4yw7yt54wt", gc, value, chkDate, inout, height, floor, URLEncoder.encode(message)); // デバッグ設定 if (Utility.isDebuggable(context)) { url += "&dev=y"; } Utility.log(PostActivity.this, url); // 検索の実行 task = new ApiTask(context, this); task.setEnableDialog(true); task.execute(url); }
/** 初期化 */ private void init() { chkDate = calendar.getTimeInMillis() / 1000; value = editValue.getText().toString(); message = editComment.getText().toString(); floor = item.getFloorKey(spinFloor.getSelectedItem().toString()); gc = item.getGcKey(spinGc.getSelectedItem().toString()); height = item.getHeightKey(spinHeight.getSelectedItem().toString()); inout = item.getInoutKey(spinInout.getSelectedItem().toString()); Utility.log( PostActivity.this, "floor:" + floor + " height:" + height + " inout:" + inout + " gc:" + gc); }
@Override public boolean onSuccess(HttpResponse response, RequestInfo reqInfo) { String startTag = null; String key = null; String xml = MyHttpClient.getString(MyHttpClient.getInputStream(response)); XmlPullParser parser = Xml.newPullParser(); try { parser.setInput(new StringReader(xml)); int eventType = parser.getEventType(); Utility.log(context, "eventType:" + eventType); while (eventType != XmlPullParser.END_DOCUMENT) { switch (eventType) { case XmlPullParser.START_DOCUMENT: // Utility.log(this, "START_DOCUMENT"); break; case XmlPullParser.END_DOCUMENT: // Utility.log(this, "END_DOCUMENT"); break; case XmlPullParser.START_TAG: // Utility.log(this, "START_TAG"); key = parser.getName(); Utility.log(context, "key:" + key); startTag = key; break; case XmlPullParser.END_TAG: // Utility.log(this, "END_TAG"); break; case XmlPullParser.TEXT: // Utility.log(this, "TEXT"); if (key != null) { String value = parser.getText(); Utility.log(context, "value:" + value); if (key.equals("Version")) { version = value; } else if (key.equals("Result")) { if (value.trim().equals("OK")) { result = 1; } else { result = Integer.valueOf(value.trim()); } } else if (key.equals("Uid")) { uid = value; } } key = null; break; } eventType = parser.next(); } } catch (Exception e) { e.printStackTrace(); return false; } return true; }
@Override public boolean onSuccess(HttpResponse response, RequestInfo reqInfo) { items = new ArrayList<Gc>(); Gc gc = new Gc(); String startTag = null; String key = null; String xml = MyHttpClient.getString(MyHttpClient.getInputStream(response)); Utility.log(context, xml); XmlPullParser parser = Xml.newPullParser(); try { parser.setInput(new StringReader(xml)); int eventType = parser.getEventType(); Utility.log(context, "eventType:" + eventType); while (eventType != XmlPullParser.END_DOCUMENT) { switch (eventType) { case XmlPullParser.START_DOCUMENT: // Utility.log(this, "START_DOCUMENT"); break; case XmlPullParser.END_DOCUMENT: // Utility.log(this, "END_DOCUMENT"); break; case XmlPullParser.START_TAG: // Utility.log(this, "START_TAG"); key = parser.getName(); // Utility.log(this, "key:" + key); if (key.compareTo("Item") == 0) { startTag = key; gc = new Gc(); } else if (key.compareTo("GetGcid") == 0) { startTag = key; } break; case XmlPullParser.END_TAG: // Utility.log(this, "END_TAG"); if (parser.getName().compareTo("Item") == 0) { items.add(gc); } break; case XmlPullParser.TEXT: // Utility.log(this, "TEXT"); if (key != null) { String value = parser.getText(); if (startTag.equals("GetGcid")) { if (key.equals("Version")) { resultInfo.version = value; } else if (key.equals("Status")) { resultInfo.status = Boolean.valueOf(value); } } else { gc.setField(key, value); } } key = null; break; } eventType = parser.next(); } } catch (Exception e) { e.printStackTrace(); } return false; }