diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml
index ea076f1..0e60e19 100644
--- a/src/main/AndroidManifest.xml
+++ b/src/main/AndroidManifest.xml
@@ -4,6 +4,9 @@
android:versionCode="2"
android:versionName="1.0.0-SNAPSHOT">
+
+
+
zipcodes;
+ Zipcode z;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -42,17 +52,39 @@ protected void onCreate(Bundle savedInstanceState) {
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) {
+ z = new Zipcode("11101", "ASTORIA", "NY", 23142, new double[] {-73.939393,40.750316});
+ zipcodes.add(z);
+
+
}
});
savejson.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
+ String result = "\"_id\":\"" + z.get_id() + "\"pop\":\"" + "" + z.getPop() + "\"city\":\"" + z.getCity() + "\"state\":\"" + z.getState() + "" + "\"loc\":\"" + "" + z.getLoc()[0] + "" + "\"loc\":\"" + "" + z.getLoc()[1] + "";
File directory = getExternalCacheDir();
File file = new File(directory, "zipcodes.json");
+ FileWriter fileWriter = null;
+ try {
+ fileWriter = new FileWriter(file, false);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ try {
+ fileWriter.write(result);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ try {
+ fileWriter.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
});
@@ -62,6 +94,24 @@ public void onClick(View v) {
public void onClick(View v) {
File directory = getExternalCacheDir();
File file = new File(directory, "zipcodes.json");
+ String result= "";
+
+ try {
+ FileInputStream fis = new FileInputStream("zipcodes.json");
+ DataInputStream in = new DataInputStream(fis);
+ BufferedReader br =
+ new BufferedReader(new InputStreamReader(in));
+ String strLine;
+ while ((strLine = br.readLine()) != null) {
+ result +=strLine;
+ }
+ in.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+
+
}
});
}
diff --git a/src/main/java/nyc/c4q/ListViewActivity.java b/src/main/java/nyc/c4q/ListViewActivity.java
index 78104c6..88d0637 100644
--- a/src/main/java/nyc/c4q/ListViewActivity.java
+++ b/src/main/java/nyc/c4q/ListViewActivity.java
@@ -1,9 +1,20 @@
package nyc.c4q;
import android.app.Activity;
+import android.content.Intent;
import android.os.Bundle;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Adapter;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.BaseAdapter;
+import android.widget.EditText;
+import android.widget.ListView;
import android.widget.TextView;
+import java.util.ArrayList;
+
public class ListViewActivity extends Activity {
public static final String[] COLORS = {
@@ -19,11 +30,28 @@ public class ListViewActivity extends Activity {
"#bf538d"
};
public TextView textLog;
+ public ListView listView;
+ public EditText adapterCount;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listview);
textLog = (TextView) findViewById(R.id.textLog);
+ listView = (ListView) findViewById(R.id.list);
+ adapterCount = (EditText) findViewById(R.id.adapterCount);
+ // int n = Integer.parseInt(adapterCount.getText().toString());
+
+
+ ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1, COLORS);
+ listView.setAdapter(adapter);
+
+ listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView> adapterView, View view, int i, long l) {
+ textLog.setText("You clicked on Item(position=" + i + ", color=" + ListViewActivity.COLORS[i] + ")");
+ }
+ });
+
}
}
diff --git a/src/main/java/nyc/c4q/NetworkActivity.java b/src/main/java/nyc/c4q/NetworkActivity.java
index 3604cfc..eae7f19 100644
--- a/src/main/java/nyc/c4q/NetworkActivity.java
+++ b/src/main/java/nyc/c4q/NetworkActivity.java
@@ -7,6 +7,7 @@
import android.util.Log;
import android.view.View;
import android.widget.Button;
+import android.widget.ListView;
import android.widget.TextView;
import com.squareup.okhttp.FormEncodingBuilder;
@@ -16,10 +17,18 @@
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.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
@@ -76,12 +85,20 @@ protected void onCreate(Bundle savedInstanceState) {
httpbinget.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
+ MyAsync myAsync = new MyAsync();
+ myAsync.execute(String.format("https://httpbin.org/get?%s", urlParams));
+
+
}
});
httpbingetokhttp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
+ String replaced = String.format("https://httpbin.org/get?%s", urlParams).replaceAll("\\+"," ");
+ MyAsync myAsync = new MyAsync();
+ myAsync.execute(replaced);
+
}
});
@@ -97,6 +114,7 @@ public void onClick(View v) {
}
});
+
cleartextlog.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -104,4 +122,47 @@ public void onClick(View v) {
}
});
}
+
+ class MyAsync extends AsyncTask {
+
+ protected String doInBackground(String... strings) {
+ BufferedReader reader = null;
+ String line;
+
+ URL urlString = null;
+ try {
+ urlString = new URL(strings[0]);
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+ HttpURLConnection connection = null;
+ try {
+ connection = (HttpURLConnection) urlString.openConnection();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ StringBuilder stringBuilder = new StringBuilder();
+ try {
+ reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ try {
+ while ((line = reader.readLine()) != null) {
+ stringBuilder.append(line + "\n");
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ String resultString = stringBuilder.toString();
+ return resultString;
+ }
+
+ @Override
+ protected void onPostExecute(String result) {
+ httptextlog = (TextView) findViewById(R.id.httptextlog);
+ httptextlog.setText(result);
+ }
+ }
}
diff --git a/src/main/java/nyc/c4q/NotificationActivity.java b/src/main/java/nyc/c4q/NotificationActivity.java
index f1f56ad..abf7d60 100644
--- a/src/main/java/nyc/c4q/NotificationActivity.java
+++ b/src/main/java/nyc/c4q/NotificationActivity.java
@@ -1,8 +1,15 @@
package nyc.c4q;
import android.app.Activity;
+import android.app.Notification;
import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
import android.os.Bundle;
+import android.os.Handler;
+import android.support.v4.app.NotificationCompat;
+import android.view.View;
import android.widget.Button;
public class NotificationActivity extends Activity {
@@ -19,11 +26,60 @@ protected void onCreate(Bundle savedInstanceState) {
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+
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);
Button buttonnotification = (Button) findViewById(R.id.buttonnotification);
+
+ autocancelnotification.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(NotificationActivity.this);
+ builder.setContentTitle("default@c4q.nyc");
+ builder.setContentText("Touch me to dismiss me!");
+ builder.setSmallIcon(R.drawable.c4qfavicon);
+
+ //disappears when the user read it
+ builder.setAutoCancel(true);
+
+ Notification notification = builder.build();
+ notificationManager.notify(ID_AUTOCANCEL_NOTIFICATION, notification);
+
+ }
+ });
+
+
+ swipenotification.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(NotificationActivity.this);
+ builder.setContentTitle("swipe@c4q.nyc");
+ builder.setContentText("Swipe right if you want to meet me. Otherwise, I'm not going away.");
+ builder.setSmallIcon(R.drawable.c4qfavicon);
+
+
+ //disappears when the user read it
+ builder.setAutoCancel(true);
+
+ Notification notification = builder.build();
+ notificationManager.notify(ID_SWIPE_NOTIFICATION, notification);
+
+ }
+ });
+
+ dismisspermanentnotification.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ notificationManager.cancel(NotificationActivity.ID_PERMANENT_NOTIFICATION);
+
+ }
+ });
+
}
}
+
+
+
diff --git a/src/main/java/nyc/c4q/json/Zipcode.java b/src/main/java/nyc/c4q/json/Zipcode.java
index 6d4761f..525eca0 100644
--- a/src/main/java/nyc/c4q/json/Zipcode.java
+++ b/src/main/java/nyc/c4q/json/Zipcode.java
@@ -1,4 +1,59 @@
package nyc.c4q.json;
public class Zipcode {
+ public String _id;
+ public String city;
+ public String state;
+ public int pop;
+ public double[] loc;
+
+ public Zipcode(String _id, String city,String state, int pop, double[] loc) {
+ this._id = _id;
+ this.city = city;
+ this.state = state;
+ this.pop = pop;
+ this.loc = loc;
+ }
+
+ public String get_id() {
+ return _id;
+ }
+
+ public void set_id(String _id) {
+ this._id = _id;
+ }
+
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public String getState() {
+ return state;
+ }
+
+ public void setState(String state) {
+ this.state = state;
+ }
+
+ public int getPop() {
+ return pop;
+ }
+
+ public void setPop(int pop) {
+ this.pop = pop;
+ }
+
+
+ public double[] getLoc() {
+ return loc;
+ }
+
+ public void setLoc(double[] loc) {
+ this.loc = loc;
+ }
}
diff --git a/src/main/res/layout/activity_listview.xml b/src/main/res/layout/activity_listview.xml
index 0d4b9d6..b0eac76 100644
--- a/src/main/res/layout/activity_listview.xml
+++ b/src/main/res/layout/activity_listview.xml
@@ -9,20 +9,30 @@
+ 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_height="0dp"
+ android:layout_weight="9"/>
\ No newline at end of file