From 279db5ba6080a2b63755233a99b9e0f281d51d02 Mon Sep 17 00:00:00 2001 From: abassawo Date: Sun, 28 Jun 2015 12:07:46 -0400 Subject: [PATCH 1/3] init-commit --- src/main/AndroidManifest.xml | 4 + src/main/java/nyc/c4q/JSONActivity.java | 82 ++++++++++++++++++- src/main/java/nyc/c4q/ListViewActivity.java | 39 +++++++++ src/main/java/nyc/c4q/NetworkActivity.java | 63 ++++++++++++++ src/main/java/nyc/c4q/json/Zipcode.java | 32 ++++++++ src/main/res/layout/activity_listview.xml | 25 ++++-- .../nyc/c4q/Part2NetworkActivityTests.java | 1 + 7 files changed, 238 insertions(+), 8 deletions(-) diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index ea076f1..31cfc3b 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -4,6 +4,10 @@ android:versionCode="2" android:versionName="1.0.0-SNAPSHOT"> + + + + zipcodes; + private JSONArray jsonArray; + private String path; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_json); + path = getExternalCacheDir().toString(); + zipcodes = new ArrayList(); + Zipcode x = new Zipcode(11101); + x.setCity("ASTORIA"); + x.setLoc("-73.939393,40.750316"); + x.setPop(23142); + Zipcode y = new Zipcode(10010); + Zipcode z = new Zipcode(11121); + zipcodes.add(x); + zipcodes.add(y); + zipcodes.add(z); Button savejson = (Button) findViewById(R.id.savejson); - Button loadjson = (Button) findViewById(R.id.loadjson); + final Button loadjson = (Button) findViewById(R.id.loadjson); Button addjson = (Button) findViewById(R.id.addjson); final TextView _id = (TextView) findViewById(R.id.field_idvalue); @@ -45,6 +76,11 @@ protected void onCreate(Bundle savedInstanceState) { addjson.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + File directory = getExternalCacheDir(); + File file = new File(directory, "zipcodes.json"); + //fixme + + } }); @@ -53,6 +89,42 @@ public void onClick(View v) { public void onClick(View v) { File directory = getExternalCacheDir(); File file = new File(directory, "zipcodes.json"); + JSONArray array = new JSONArray(); + + for (Zipcode c : zipcodes) { + array.put(c); + } + + Writer writer = null; + + + + try { + + OutputStream out = new ObjectOutputStream(new FileOutputStream(path)); + + JsonWriter jsonWriter = new JsonWriter(writer); + writer = new OutputStreamWriter(out); + writer.write(array.toString()); + jsonWriter.name("zipcodes").value("unittest"); + jsonWriter.beginArray(); + jsonWriter.value(zipcodes.get(0).toString()); + jsonWriter.value(zipcodes.get(1).toString()); + jsonWriter.value(zipcodes.get(2).toString()); + jsonWriter.endArray(); + } catch(Exception e){ + + } + finally { + if (writer != null) + try { + writer.close(); + } catch(Exception e){ + + } + + } + } }); @@ -64,5 +136,13 @@ public void onClick(View v) { File file = new File(directory, "zipcodes.json"); } }); + + + + } + + + + } diff --git a/src/main/java/nyc/c4q/ListViewActivity.java b/src/main/java/nyc/c4q/ListViewActivity.java index 78104c6..ebf92ef 100644 --- a/src/main/java/nyc/c4q/ListViewActivity.java +++ b/src/main/java/nyc/c4q/ListViewActivity.java @@ -2,8 +2,14 @@ import android.app.Activity; import android.os.Bundle; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.BaseAdapter; +import android.widget.ListView; import android.widget.TextView; + public class ListViewActivity extends Activity { public static final String[] COLORS = { @@ -25,5 +31,38 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_listview); textLog = (TextView) findViewById(R.id.textLog); + ListView listview = (ListView) findViewById(R.id.list); + + CustomAdapter listadapter = new CustomAdapter(); + listview.setAdapter(listadapter); + } + + private class CustomAdapter extends BaseAdapter { + + + @Override + public int getCount() { + return COLORS.length; + } + + @Override + public Object getItem(int position) { + return COLORS[position]; + } + + @Override + public long getItemId(int position) { + return 0; + } + + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + if (convertView == null){ + convertView = getLayoutInflater().inflate(R.layout.listview_tile, parent, false); + } + + return convertView; + } } } diff --git a/src/main/java/nyc/c4q/NetworkActivity.java b/src/main/java/nyc/c4q/NetworkActivity.java index 3604cfc..2a1ac56 100644 --- a/src/main/java/nyc/c4q/NetworkActivity.java +++ b/src/main/java/nyc/c4q/NetworkActivity.java @@ -16,9 +16,15 @@ import com.squareup.okhttp.RequestBody; import com.squareup.okhttp.Response; +import org.json.JSONException; +import org.json.JSONObject; + import java.io.BufferedInputStream; +import java.io.BufferedReader; import java.io.DataOutputStream; +import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; @@ -34,6 +40,8 @@ public class NetworkActivity extends Activity { public Button httpbinpost; public Button httpbinpostokhttp; public Button cleartextlog; + private String urlGetString; + private String url = "https://httpbin.org/get?"; final public String urlParams = "custname=james+dean&custtel=347-841-6090&custemail=hello%40c4q.nyc&size=small&topping=cheese&delivery=18%3A15&comments=Leave+it+by+the+garage+door.+Don't+ask+any+questions."; // Code =========================== @@ -50,6 +58,15 @@ protected void onCreate(Bundle savedInstanceState) { httptextlog = (TextView) findViewById(R.id.httptextlog); httptextlog.setMovementMethod(new ScrollingMovementMethod()); + urlGetString = "https://httpbin.org/get?custname=james+dean&custtel=347-841-6090&custemail=hello%40c4q.nyc&size=small&topping=cheese&delivery=18%3A15&comments=Leave+it+by+the+garage+door.+Don%27t+ask+any+questions."; + String urlPostString="https://httpbin.org/post"; + String httpbingeString; + String httpbingetokhttpString; + String httpbinpostString; + String httpbinpostokhttpString; + + + /* The goal is to use AsyncTasks here. Shortcut to create URL in Java: @@ -76,6 +93,7 @@ protected void onCreate(Bundle savedInstanceState) { httpbinget.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + } }); @@ -103,5 +121,50 @@ public void onClick(View v) { httptextlog.setText("cleared HTTP response"); } }); + + + + } + public class AsyncTestTask extends AsyncTask{ + + @Override + protected String doInBackground(Void... params){ + { + HttpURLConnection connection = null; + InputStream inputStream = null; + try { + URL url = new URL(urlGetString + urlParams); + Log.d("test url", url.toString()); + connection = (HttpURLConnection) url.openConnection(); + inputStream = connection.getInputStream(); + BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); + StringBuilder builder = new StringBuilder(); + String line = ""; + while ((line = reader.readLine()) != null) { + builder.append(line + "\n"); + } + return builder.toString(); + + } catch (Exception e) { + + } finally { + if (connection != null) { + connection.disconnect(); + } + + } + + } + return "testing"; + } + + @Override + protected void onPostExecute(String s) { + httptextlog.setText(s); + + } + + + } } diff --git a/src/main/java/nyc/c4q/json/Zipcode.java b/src/main/java/nyc/c4q/json/Zipcode.java index 6d4761f..11788a0 100644 --- a/src/main/java/nyc/c4q/json/Zipcode.java +++ b/src/main/java/nyc/c4q/json/Zipcode.java @@ -1,4 +1,36 @@ package nyc.c4q.json; public class Zipcode { + private int id, pop; + String city; + String state; + + public void setPop(int pop) { + this.pop = pop; + } + + public void setCity(String city) { + this.city = city; + } + + public void setState(String state) { + this.state = state; + } + + public void setLoc(String loc) { + this.loc = loc; + } + + String loc; + public Zipcode(int id){ + this.id = id; + } + + + +// assertThat(result, containsString("\"_id\":\"11101\"")); +// assertThat(result, containsString("\"pop\":23142")); +// assertThat(result, containsString("\"city\":\"ASTORIA\"")); +// assertThat(result, containsString("\"state\":\"NY\"")); +// assertThat(result, containsString("\"loc\":[-73.939393,40.750316]")); } diff --git a/src/main/res/layout/activity_listview.xml b/src/main/res/layout/activity_listview.xml index 0d4b9d6..549b27a 100644 --- a/src/main/res/layout/activity_listview.xml +++ b/src/main/res/layout/activity_listview.xml @@ -9,20 +9,31 @@ + android:layout_width="0dp" + android:layout_height="match_parent" + android:layout_weight="3" + android:text="You have not clicked anything." /> + android:layout_width="match_parent" + android:layout_weight="9" + android:layout_height="0dp"/> + + + \ No newline at end of file diff --git a/src/test/java/nyc/c4q/Part2NetworkActivityTests.java b/src/test/java/nyc/c4q/Part2NetworkActivityTests.java index 3a561c6..f85090f 100644 --- a/src/test/java/nyc/c4q/Part2NetworkActivityTests.java +++ b/src/test/java/nyc/c4q/Part2NetworkActivityTests.java @@ -61,6 +61,7 @@ public void test13NetworkActivityHTTPUrlConnectionGETOKHTTP() throws Exception { @Test public void test14Missing() { + // TODO // FREE question for now. } From f9e9ba1599ab263f41a0340ceb6fca9b0936ef2d Mon Sep 17 00:00:00 2001 From: abassawo Date: Sun, 28 Jun 2015 13:00:24 -0400 Subject: [PATCH 2/3] lunch --- src/main/java/nyc/c4q/JSONActivity.java | 15 ++-- .../java/nyc/c4q/NotificationActivity.java | 70 ++++++++++++++++++- src/main/res/layout/activity_listview.xml | 14 ++-- 3 files changed, 80 insertions(+), 19 deletions(-) diff --git a/src/main/java/nyc/c4q/JSONActivity.java b/src/main/java/nyc/c4q/JSONActivity.java index 6bf011c..8d456b8 100644 --- a/src/main/java/nyc/c4q/JSONActivity.java +++ b/src/main/java/nyc/c4q/JSONActivity.java @@ -54,9 +54,9 @@ protected void onCreate(Bundle savedInstanceState) { zipcodes = new ArrayList(); Zipcode x = new Zipcode(11101); - x.setCity("ASTORIA"); - x.setLoc("-73.939393,40.750316"); - x.setPop(23142); +// x.setCity("ASTORIA"); +// x.setLoc("-73.939393,40.750316"); +// x.setPop(23142); Zipcode y = new Zipcode(10010); Zipcode z = new Zipcode(11121); zipcodes.add(x); @@ -94,15 +94,9 @@ public void onClick(View v) { for (Zipcode c : zipcodes) { array.put(c); } - Writer writer = null; - - - try { - - OutputStream out = new ObjectOutputStream(new FileOutputStream(path)); - + OutputStream out = new ObjectOutputStream(new FileOutputStream(path + "zipcodes.json")); JsonWriter jsonWriter = new JsonWriter(writer); writer = new OutputStreamWriter(out); writer.write(array.toString()); @@ -119,6 +113,7 @@ public void onClick(View v) { if (writer != null) try { writer.close(); + } catch(Exception e){ } diff --git a/src/main/java/nyc/c4q/NotificationActivity.java b/src/main/java/nyc/c4q/NotificationActivity.java index f1f56ad..b6674c6 100644 --- a/src/main/java/nyc/c4q/NotificationActivity.java +++ b/src/main/java/nyc/c4q/NotificationActivity.java @@ -1,8 +1,12 @@ package nyc.c4q; import android.app.Activity; +import android.app.Notification; import android.app.NotificationManager; +import android.content.Context; +import android.graphics.drawable.Drawable; import android.os.Bundle; +import android.view.View; import android.widget.Button; public class NotificationActivity extends Activity { @@ -11,19 +15,81 @@ public class NotificationActivity extends Activity { public static final int ID_SWIPE_NOTIFICATION = 2; public static final int ID_PERMANENT_NOTIFICATION = 3; public static final int ID_BUTTON_NOTIFICATION = 4; - + Notification autoCancel; + Notification swipeNotification; + Notification permNotification; + Notification btnNotification; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_notification); + Context c = getApplicationContext(); + Notification.Builder builder = new Notification.Builder(c).setSmallIcon(R.drawable.c4qfavicon); + autoCancel = builder.setAutoCancel(true) + .setContentTitle("default@c4q.nyc").setContentText("Touch me to dismiss me!"). + build(); + + swipeNotification = builder.setAutoCancel(false).setContentTitle("swipe@c4q.nyc").setContentText("Swipe right if you want to meet me. Otherwise, I'm not going away.") + .build(); + + notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + permNotification = new Notification.Builder(c) + .setContentTitle("permanent@c4q.nyc") + .setSmallIcon(R.drawable.c4qfavicon).setOngoing(true) + .setContentText("I'm staying planted right here").build(); + + btnNotification = new Notification.Builder(c) + .setContentTitle("permanent@c4q.nyc") + .setSmallIcon(R.drawable.c4qfavicon).setOngoing(true) + .setContentText("I'm staying planted right here").build(); + + + + Button autocancelnotification = (Button) findViewById(R.id.autocancelnotification); Button swipenotification = (Button) findViewById(R.id.swipenotification); Button permanentnotification = (Button) findViewById(R.id.permanentnotification); - Button dismisspermanentnotification = (Button) findViewById(R.id.dismisspermanentnotification); + final Button dismisspermanentnotification = (Button) findViewById(R.id.dismisspermanentnotification); Button buttonnotification = (Button) findViewById(R.id.buttonnotification); + + autocancelnotification.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + notificationManager.notify(0, autoCancel); + } + }); + + swipenotification.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + notificationManager.notify(0, swipeNotification); + } + }); + permanentnotification.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + notificationManager.notify(0, permNotification); + } + }); + dismisspermanentnotification.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + notificationManager.cancelAll(); + } + }); + buttonnotification.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + notificationManager.notify(0, btnNotification); + } + }); + + + + } } diff --git a/src/main/res/layout/activity_listview.xml b/src/main/res/layout/activity_listview.xml index 549b27a..6838bba 100644 --- a/src/main/res/layout/activity_listview.xml +++ b/src/main/res/layout/activity_listview.xml @@ -21,6 +21,13 @@ android:layout_weight="3" android:text="You have not clicked anything." /> + + - - \ No newline at end of file From 2406ddf5627cc0e027b1f4efe6da7b4d14aed3a4 Mon Sep 17 00:00:00 2001 From: abassawo Date: Sun, 28 Jun 2015 16:48:07 -0400 Subject: [PATCH 3/3] attempt rebase --- src/main/java/nyc/c4q/JSONActivity.java | 194 +++++++++++------- src/main/java/nyc/c4q/ListViewActivity.java | 26 ++- src/main/java/nyc/c4q/NetworkActivity.java | 28 ++- .../java/nyc/c4q/NotificationActivity.java | 10 +- src/main/java/nyc/c4q/json/Zipcode.java | 29 ++- 5 files changed, 185 insertions(+), 102 deletions(-) diff --git a/src/main/java/nyc/c4q/JSONActivity.java b/src/main/java/nyc/c4q/JSONActivity.java index 8d456b8..421acf9 100644 --- a/src/main/java/nyc/c4q/JSONActivity.java +++ b/src/main/java/nyc/c4q/JSONActivity.java @@ -1,6 +1,7 @@ package nyc.c4q; import android.app.Activity; +import android.content.Context; import android.os.Bundle; import android.os.Environment; import android.util.Log; @@ -13,11 +14,15 @@ import org.json.JSONArray; import org.json.JSONException; +import java.io.BufferedReader; import java.io.File; +import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.io.ObjectOutputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; @@ -34,9 +39,11 @@ import java.io.FileWriter; import java.io.IOException; import com.google.gson.stream.JsonWriter; +import com.google.gson.JsonElement; import nyc.c4q.json.Zipcode; +import nyc.c4q.json.ZipcodeDeserializer; public class JSONActivity extends Activity { @@ -45,97 +52,128 @@ public class JSONActivity extends Activity { private String path; @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_json); - - path = getExternalCacheDir().toString(); - - zipcodes = new ArrayList(); - - Zipcode x = new Zipcode(11101); -// x.setCity("ASTORIA"); -// x.setLoc("-73.939393,40.750316"); -// x.setPop(23142); - Zipcode y = new Zipcode(10010); - Zipcode z = new Zipcode(11121); - zipcodes.add(x); - zipcodes.add(y); - zipcodes.add(z); - Button savejson = (Button) findViewById(R.id.savejson); - final Button loadjson = (Button) findViewById(R.id.loadjson); - Button addjson = (Button) findViewById(R.id.addjson); - - final TextView _id = (TextView) findViewById(R.id.field_idvalue); - final TextView pop = (TextView) findViewById(R.id.fieldpopvalue); - final TextView city = (TextView) findViewById(R.id.fieldcityvalue); - final TextView state = (TextView) findViewById(R.id.fieldstatevalue); - final TextView _lat = (TextView) findViewById(R.id.fieldloclatvalue); - final TextView _long = (TextView) findViewById(R.id.fieldloclongvalue); - - addjson.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - File directory = getExternalCacheDir(); - File file = new File(directory, "zipcodes.json"); - //fixme - - - } - }); - - savejson.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - File directory = getExternalCacheDir(); - File file = new File(directory, "zipcodes.json"); - JSONArray array = new JSONArray(); - - for (Zipcode c : zipcodes) { - array.put(c); - } - Writer writer = null; - try { - OutputStream out = new ObjectOutputStream(new FileOutputStream(path + "zipcodes.json")); - JsonWriter jsonWriter = new JsonWriter(writer); - writer = new OutputStreamWriter(out); - writer.write(array.toString()); - jsonWriter.name("zipcodes").value("unittest"); - jsonWriter.beginArray(); - jsonWriter.value(zipcodes.get(0).toString()); - jsonWriter.value(zipcodes.get(1).toString()); - jsonWriter.value(zipcodes.get(2).toString()); - jsonWriter.endArray(); - } catch(Exception e){ + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_json); + + path = getExternalCacheDir().getPath(); + + zipcodes = new ArrayList(); + + Zipcode x = new Zipcode(11101); + x.setCity("ASTORIA"); + x.setLoc("-73.939393,40.750316"); + x.setPop(23142); + Zipcode y = new Zipcode(10010); + Zipcode z = new Zipcode(11121); + zipcodes.add(x); + zipcodes.add(y); + zipcodes.add(z); + + Button savejson = (Button) findViewById(R.id.savejson); + final Button loadjson = (Button) findViewById(R.id.loadjson); + final Button addjson = (Button) findViewById(R.id.addjson); + + final TextView _id = (TextView) findViewById(R.id.field_idvalue); + final TextView pop = (TextView) findViewById(R.id.fieldpopvalue); + final TextView city = (TextView) findViewById(R.id.fieldcityvalue); + final TextView state = (TextView) findViewById(R.id.fieldstatevalue); + final TextView _lat = (TextView) findViewById(R.id.fieldloclatvalue); + final TextView _long = (TextView) findViewById(R.id.fieldloclongvalue); + + addjson.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + File directory = getExternalCacheDir(); + File file = new File(directory, "zipcodes.json"); + jsonArray = new JSONArray(); + for(Zipcode c : zipcodes){ + jsonArray.put(c); + } + + } - finally { - if (writer != null) - try { - writer.close(); + }); + + savejson.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + File directory = getExternalCacheDir(); + File file = new File(directory, "zipcodes.json"); + String filename = "zipcodes.json"; + + Writer writer = null; + Context mContext = getApplicationContext(); + try { + FileOutputStream out = mContext.openFileOutput(filename, Context.MODE_PRIVATE); + writer = new OutputStreamWriter(out); + writer.write(file.toString()); + + writer.write(zipcodes.toString()); + writer.flush(); + writer.close(); + + + + } catch(Exception e){ + + } finally{ + if (writer != null) + try { + writer.close(); + } catch(Exception e){ + + } + + } - } catch(Exception e){ - } } + }); + + + loadjson.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + String zipcodeObj = ""; + File directory = getExternalCacheDir(); + File file = new File(directory, "zipcodes.json"); + try { + - } - }); + FileInputStream fileInputStr = new FileInputStream(file); + int size = fileInputStr.available(); + byte[] buffer = new byte[size]; + fileInputStr.read(buffer); + fileInputStr.close(); + String response = new String(buffer); +// BufferedReader inputReader = new BufferedReader(new InputStreamReader(fileInputStr, "UTF-8"), 8); +// StringBuilder strBuilder = new StringBuilder(); +// String line = null; +// while ((line = inputReader.readLine()) != null) { +// strBuilder.append(line + "\n"); + //} + // fileInputStr.close(); + //zipcodeObj= strBuilder.toString(); + } catch (Exception e) { - loadjson.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - File directory = getExternalCacheDir(); - File file = new File(directory, "zipcodes.json"); - } - }); + } + + + + String fileName = directory + "/" + "zipcodes.json"; + BufferedReader reader = null; + + } + }); - } + } diff --git a/src/main/java/nyc/c4q/ListViewActivity.java b/src/main/java/nyc/c4q/ListViewActivity.java index ebf92ef..9b50623 100644 --- a/src/main/java/nyc/c4q/ListViewActivity.java +++ b/src/main/java/nyc/c4q/ListViewActivity.java @@ -1,7 +1,9 @@ package nyc.c4q; import android.app.Activity; +import android.graphics.Color; import android.os.Bundle; +import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; @@ -47,22 +49,38 @@ public int getCount() { @Override public Object getItem(int position) { + return COLORS[position]; } @Override public long getItemId(int position) { - return 0; + return position; } - @Override - public View getView(int position, View convertView, ViewGroup parent) { + public View getView(final int position, View convertView, ViewGroup parent) { + if (convertView == null){ - convertView = getLayoutInflater().inflate(R.layout.listview_tile, parent, false); + LayoutInflater inflater = getLayoutInflater(); + convertView = getLayoutInflater().inflate(R.layout.listview_tile, null); + + //convertView.setBackgroundResource(Color.parseColor(COLORS[position])); //fixme } + convertView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + textLog.setText("You clicked on Item " + COLORS[position]); + } + }); + + return convertView; } + } + + + } diff --git a/src/main/java/nyc/c4q/NetworkActivity.java b/src/main/java/nyc/c4q/NetworkActivity.java index 2a1ac56..10653be 100644 --- a/src/main/java/nyc/c4q/NetworkActivity.java +++ b/src/main/java/nyc/c4q/NetworkActivity.java @@ -16,6 +16,10 @@ import com.squareup.okhttp.RequestBody; import com.squareup.okhttp.Response; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.impl.client.DefaultHttpClient; import org.json.JSONException; import org.json.JSONObject; @@ -40,6 +44,7 @@ public class NetworkActivity extends Activity { public Button httpbinpost; public Button httpbinpostokhttp; public Button cleartextlog; + private String mResponse; private String urlGetString; private String url = "https://httpbin.org/get?"; final public String urlParams = "custname=james+dean&custtel=347-841-6090&custemail=hello%40c4q.nyc&size=small&topping=cheese&delivery=18%3A15&comments=Leave+it+by+the+garage+door.+Don't+ask+any+questions."; @@ -106,12 +111,14 @@ public void onClick(View v) { httpbinpost.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + httptextlog.setText(mResponse); } }); httpbinpostokhttp.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + } }); @@ -131,11 +138,22 @@ public class AsyncTestTask extends AsyncTask{ protected String doInBackground(Void... params){ { HttpURLConnection connection = null; + InputStream inputStream = null; try { - URL url = new URL(urlGetString + urlParams); + String replaced = String.format("https://httpbin.org/get?%s", urlParams); + URL url = new URL(replaced); Log.d("test url", url.toString()); connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.connect(); + + + HttpClient client = new DefaultHttpClient(); + + HttpPost post = new HttpPost("https://httpbin.org/post" + replaced); + HttpResponse response = client.execute(post); + inputStream = connection.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); StringBuilder builder = new StringBuilder(); @@ -143,7 +161,7 @@ protected String doInBackground(Void... params){ while ((line = reader.readLine()) != null) { builder.append(line + "\n"); } - return builder.toString(); + return response.toString(); } catch (Exception e) { @@ -153,14 +171,14 @@ protected String doInBackground(Void... params){ } } - } - return "testing"; + return " "; } @Override protected void onPostExecute(String s) { - httptextlog.setText(s); + mResponse = s; + httptextlog.setText(mResponse); } diff --git a/src/main/java/nyc/c4q/NotificationActivity.java b/src/main/java/nyc/c4q/NotificationActivity.java index b6674c6..880660d 100644 --- a/src/main/java/nyc/c4q/NotificationActivity.java +++ b/src/main/java/nyc/c4q/NotificationActivity.java @@ -39,7 +39,7 @@ protected void onCreate(Bundle savedInstanceState) { permNotification = new Notification.Builder(c) .setContentTitle("permanent@c4q.nyc") .setSmallIcon(R.drawable.c4qfavicon).setOngoing(true) - .setContentText("I'm staying planted right here").build(); + .setContentText("I'm staying planted right here.").build(); btnNotification = new Notification.Builder(c) .setContentTitle("permanent@c4q.nyc") @@ -59,20 +59,20 @@ protected void onCreate(Bundle savedInstanceState) { autocancelnotification.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - notificationManager.notify(0, autoCancel); + notificationManager.notify(ID_AUTOCANCEL_NOTIFICATION, autoCancel); } }); swipenotification.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - notificationManager.notify(0, swipeNotification); + notificationManager.notify(ID_SWIPE_NOTIFICATION, swipeNotification); } }); permanentnotification.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - notificationManager.notify(0, permNotification); + notificationManager.notify(ID_PERMANENT_NOTIFICATION, permNotification); } }); dismisspermanentnotification.setOnClickListener(new View.OnClickListener() { @@ -84,7 +84,7 @@ public void onClick(View v) { buttonnotification.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - notificationManager.notify(0, btnNotification); + notificationManager.notifyAll(); } }); diff --git a/src/main/java/nyc/c4q/json/Zipcode.java b/src/main/java/nyc/c4q/json/Zipcode.java index 11788a0..58e0d82 100644 --- a/src/main/java/nyc/c4q/json/Zipcode.java +++ b/src/main/java/nyc/c4q/json/Zipcode.java @@ -1,9 +1,16 @@ package nyc.c4q.json; +import org.json.JSONException; +import org.json.JSONObject; + public class Zipcode { - private int id, pop; - String city; - String state; + public int _id, pop; + public String city; + public String state; + + private String JSON_id, JSON_pop, + JSON_city, JSON_loc; + public void setPop(int pop) { this.pop = pop; @@ -23,14 +30,16 @@ public void setLoc(String loc) { String loc; public Zipcode(int id){ - this.id = id; + this._id = id; } + public JSONObject toJSON() throws JSONException { + JSONObject json = new JSONObject(); + json.put(JSON_id, _id); + json.put(JSON_city, city); + json.put(JSON_loc, loc); + json.put(JSON_pop, pop); + return json; + } - -// assertThat(result, containsString("\"_id\":\"11101\"")); -// assertThat(result, containsString("\"pop\":23142")); -// assertThat(result, containsString("\"city\":\"ASTORIA\"")); -// assertThat(result, containsString("\"state\":\"NY\"")); -// assertThat(result, containsString("\"loc\":[-73.939393,40.750316]")); }