Skip to content

Instantly share code, notes, and snippets.

@jen6
Created July 13, 2015 14:42
Show Gist options
  • Save jen6/189d10cb52243f9635fc to your computer and use it in GitHub Desktop.
Save jen6/189d10cb52243f9635fc to your computer and use it in GitHub Desktop.
public class BusPostSetter {
public HttpClient http = new DefaultHttpClient();
public CookieStore cookieStore = new BasicCookieStore();
// 쿠키스토어랑 httpclient를 퍼블릭으로 선언
public RbPreference pre = new RbPreference(this);
// 프리레퍼런스 사용할 객체 선언
public BusPostSetter() {
}
public BusPostSetter(String Title, String Content, String Want) {
try {
HttpContext context = new BasicHttpContext();
HttpPost httpPost = new HttpPost("http://makeall.ml:8989/board/bus");
ArrayList<NameValuePair> nameValuePairs =
new ArrayList<NameValuePair>(3);
nameValuePairs.add(new BasicNameValuePair("Title", Title));
nameValuePairs.add(new BasicNameValuePair("Content", Content)); //post 파라미터 셋팅
nameValuePairs.add(new BasicNameValuePair("Want", Want));
UrlEncodedFormEntity entityRequest =
new UrlEncodedFormEntity(nameValuePairs, "UTF-8");
httpPost.setEntity(entityRequest);
HttpResponse responsePost = http.execute(httpPost);
// 리턴값
Log.d("msg", "login");
}
catch (Exception e) {
e.printStackTrace();
}
}
public boolean post() {}
}
class BusList{
int Id, Want;
String Title, Content;
}
public class BusListGetter extends AsyncTask<Void, Void, Void> {
//실행 new GetContacts().execute();
private ProgressDialog pDialog;
// URL to get contacts JSON
private String url = "http://makeall.ml:8989/board/buslist/1";
// JSON Node names
private static final String TAG_TITLE = "Title";
private static final String TAG_CONTENT = "Content";
private static final String TAG_WANT = "Want";
ArrayList<HashMap<String, String>> gulList = new ArrayList<HashMap<String, String>>();
@Override
protected void onPreExecute() {
super.onPreExecute();
// Showing progress dialog
//pDialog = new ProgressDialog(main.this);
//pDialog.setMessage("Please wait...");
//pDialog.setCancelable(false);
//pDialog.show();
}
@Override
protected Void doInBackground(Void... arg0) {
// Creating service handler class instance
ServiceHandler sh = new ServiceHandler();
// Making a request to url and getting response
String jsonStr = sh.makeServiceCall(url, ServiceHandler.GET);
Log.d("Response: ", "> " + jsonStr);
if (jsonStr != null) {
try {
JSONArray gul = new JSONArray(jsonStr);
// Getting JSON Array node
// looping through All Contacts
for (int i = 0; i < gul.length(); i++) {
JSONObject c = gul.getJSONObject(i);
String content = c. getString(TAG_CONTENT);
String title = c. getString(TAG_TITLE);
String want = c. getString(TAG_WANT);
// tmp hashmap for single contact
HashMap<String, String> gulMap = new HashMap<String, String>();
// adding each child node to HashMap key => value
gulMap.put(TAG_WANT, want);
gulMap.put(TAG_TITLE, title);
gulMap.put(TAG_CONTENT, content);
// adding contact to contact list
gulList.add(gulMap);
}
} catch (JSONException e) {
e.printStackTrace();
}
} else {
Log.e("ServiceHandler", "Couldn't get any data from the url");
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
// Dismiss the progress dialog
if (pDialog.isShowing())
pDialog.dismiss();
}
public BusList[] Get(int idx){}
}
class Bus{
int Id, WriterId, Want;
String Writer, Title, Content;
}
class BusGetter {
public BusGetter(){}
public Bus Get(int Id){}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment