From ce48f82bfb3bd981426a607a8e64e560214a08d4 Mon Sep 17 00:00:00 2001 From: MadelynTav Date: Sun, 28 Jun 2015 12:05:31 -0400 Subject: [PATCH 1/3] first commit --- src/main/AndroidManifest.xml | 2 ++ src/main/java/nyc/c4q/ListViewActivity.java | 32 ++++++++++++++++++++- src/main/java/nyc/c4q/NetworkActivity.java | 21 +++----------- src/main/res/layout/activity_listview.xml | 28 ++++++++++++------ 4 files changed, 57 insertions(+), 26 deletions(-) diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index ea076f1..bdd2be8 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -4,6 +4,8 @@ android:versionCode="2" android:versionName="1.0.0-SNAPSHOT"> + + adapter = new ArrayAdapter(this, + R.layout.activity_listview, R.id.textLog, COLORS); + listView.setAdapter(adapter); + + for(int i=0;i parent, View view, int position, long id) { + textLog.setText("You clicked on Item(position=" + position + ", color=" + COLORS[position]+")"); + + } + + }); + + } -} + + +} \ No newline at end of file diff --git a/src/main/java/nyc/c4q/NetworkActivity.java b/src/main/java/nyc/c4q/NetworkActivity.java index 3604cfc..f9ba73f 100644 --- a/src/main/java/nyc/c4q/NetworkActivity.java +++ b/src/main/java/nyc/c4q/NetworkActivity.java @@ -1,29 +1,12 @@ package nyc.c4q; import android.app.Activity; -import android.os.AsyncTask; import android.os.Bundle; import android.text.method.ScrollingMovementMethod; -import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.TextView; -import com.squareup.okhttp.FormEncodingBuilder; -import com.squareup.okhttp.HttpUrl; -import com.squareup.okhttp.OkHttpClient; -import com.squareup.okhttp.Request; -import com.squareup.okhttp.RequestBody; -import com.squareup.okhttp.Response; - -import java.io.BufferedInputStream; -import java.io.DataOutputStream; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.net.URLConnection; -import java.util.ArrayList; - public class NetworkActivity extends Activity { // Fields =========================== @@ -76,12 +59,14 @@ protected void onCreate(Bundle savedInstanceState) { httpbinget.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + httptextlog.setText(urlParams); } }); httpbingetokhttp.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + httptextlog.setText(urlParams.replaceAll("\\+"," ")); } }); @@ -104,4 +89,6 @@ public void onClick(View v) { } }); } + + } diff --git a/src/main/res/layout/activity_listview.xml b/src/main/res/layout/activity_listview.xml index 0d4b9d6..6c5ab1b 100644 --- a/src/main/res/layout/activity_listview.xml +++ b/src/main/res/layout/activity_listview.xml @@ -5,24 +5,36 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context="nyc.c4q.ListViewActivity"> + tools:context="nyc.c4q.ListViewActivity" + android:background="#bf538d"> + android:layout_width="0dp" + android:layout_weight="3" + android:onClick="whenClicked" + android:layout_height="match_parent" + 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 From 51d21b66dfd1e971adec7deb74c9f613747fb93e Mon Sep 17 00:00:00 2001 From: MadelynTav Date: Sun, 28 Jun 2015 12:58:27 -0400 Subject: [PATCH 2/3] update --- src/main/java/nyc/c4q/JSONActivity.java | 117 +++++++++++++++--- .../java/nyc/c4q/NotificationActivity.java | 20 +++ src/main/res/layout/json_zipcodetile.xml | 4 +- 3 files changed, 121 insertions(+), 20 deletions(-) diff --git a/src/main/java/nyc/c4q/JSONActivity.java b/src/main/java/nyc/c4q/JSONActivity.java index e2ca42f..048c7ee 100644 --- a/src/main/java/nyc/c4q/JSONActivity.java +++ b/src/main/java/nyc/c4q/JSONActivity.java @@ -2,27 +2,90 @@ import android.app.Activity; import android.os.Bundle; -import android.os.Environment; -import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.TextView; -import com.google.gson.Gson; +import com.google.gson.JsonParser; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; import java.io.File; +import java.io.FileNotFoundException; import java.io.FileReader; -import java.io.FileWriter; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -import java.util.Scanner; import nyc.c4q.json.Zipcode; public class JSONActivity extends Activity { + public List getZipcodes() { + return zipcodes; + } + + public void setZipcodes(List zipcodes) { + this.zipcodes = zipcodes; + } + + public TextView get_long() { + return _long; + } + + public void set_long(TextView _long) { + this._long = _long; + } + + public TextView get_lat() { + return _lat; + } + + public void set_lat(TextView _lat) { + this._lat = _lat; + } + + public TextView getCity() { + return city; + } + + public void setCity(TextView city) { + this.city = city; + } + + public TextView getPop() { + return pop; + } + + public void setPop(TextView pop) { + this.pop = pop; + } + + public TextView get_id() { + return _id; + } + + public void set_id(TextView _id) { + this._id = _id; + } + + public TextView getState() { + return state; + } + + public void setState(TextView state) { + this.state = state; + } + public List zipcodes; + public TextView _id; + public TextView pop; + public TextView city; + public TextView state; + public TextView _lat; + public TextView _long; + @Override protected void onCreate(Bundle savedInstanceState) { @@ -35,12 +98,12 @@ protected void onCreate(Bundle savedInstanceState) { 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); + _id = (TextView) findViewById(R.id.field_idvalue); + pop = (TextView) findViewById(R.id.fieldpopvalue); + city = (TextView) findViewById(R.id.fieldcityvalue); + state = (TextView) findViewById(R.id.fieldstatevalue); + _lat = (TextView) findViewById(R.id.fieldloclatvalue); + _long = (TextView) findViewById(R.id.fieldloclongvalue); addjson.setOnClickListener(new View.OnClickListener() { @Override @@ -49,12 +112,13 @@ public void onClick(View v) { }); savejson.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - File directory = getExternalCacheDir(); - File file = new File(directory, "zipcodes.json"); - } - }); + @Override + public void onClick(View v) { + File directory = getExternalCacheDir(); + File file = new File(directory, "zipcodes.json"); + } + }); + loadjson.setOnClickListener(new View.OnClickListener() { @@ -62,6 +126,23 @@ public void onClick(View v) { public void onClick(View v) { File directory = getExternalCacheDir(); File file = new File(directory, "zipcodes.json"); + JsonParser parser = new JsonParser(); + try { + Object object = parser.parse(new FileReader(file)); + JSONArray jsonObject = (JSONArray) object; + + for (int i = 0; i < jsonObject.length(); i++) { + JSONObject object1 = (JSONObject) jsonObject.get(i); + String id = object1.getString("_id"); + _id.setText(id); + } + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (JSONException e) { + e.printStackTrace(); + } + } }); } diff --git a/src/main/java/nyc/c4q/NotificationActivity.java b/src/main/java/nyc/c4q/NotificationActivity.java index f1f56ad..a4f7d82 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.os.Bundle; +import android.support.v4.app.NotificationCompat; +import android.view.View; import android.widget.Button; public class NotificationActivity extends Activity { @@ -25,5 +29,21 @@ protected void onCreate(Bundle savedInstanceState) { 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) { + NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(NotificationActivity.this) + .setSmallIcon(R.drawable.c4qfavicon) + .setContentTitle("default@c4q.nyc") + .setContentText("Touch me to dismiss me!"); + notificationManager = + (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + Notification notification=mBuilder.build(); + notification.flags =Notification.DEFAULT_LIGHTS|Notification.FLAG_AUTO_CANCEL; + notificationManager.notify(1, notification); + } + }); } } diff --git a/src/main/res/layout/json_zipcodetile.xml b/src/main/res/layout/json_zipcodetile.xml index 0ffc858..ed9c0ee 100644 --- a/src/main/res/layout/json_zipcodetile.xml +++ b/src/main/res/layout/json_zipcodetile.xml @@ -18,12 +18,12 @@ android:textAppearance="?android:attr/textAppearanceLarge" android:typeface="monospace" /> - From d83705df772bb9f1f4f7f0b3e4d838ce9a51bdc6 Mon Sep 17 00:00:00 2001 From: MadelynTav Date: Sun, 28 Jun 2015 17:00:21 -0400 Subject: [PATCH 3/3] final --- src/main/AndroidManifest.xml | 2 + src/main/java/nyc/c4q/JSONActivity.java | 99 ++++++++----------- src/main/java/nyc/c4q/ListViewActivity.java | 8 +- .../java/nyc/c4q/NotificationActivity.java | 71 ++++++++++--- src/main/java/nyc/c4q/json/Zipcode.java | 9 ++ src/main/res/layout/activity_listview.xml | 2 + 6 files changed, 118 insertions(+), 73 deletions(-) diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index bdd2be8..5781f86 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -5,6 +5,8 @@ android:versionName="1.0.0-SNAPSHOT"> + + getZipcodes() { - return zipcodes; - } - - public void setZipcodes(List zipcodes) { - this.zipcodes = zipcodes; - } - - public TextView get_long() { - return _long; - } - - public void set_long(TextView _long) { - this._long = _long; - } - - public TextView get_lat() { - return _lat; - } - - public void set_lat(TextView _lat) { - this._lat = _lat; - } - - public TextView getCity() { - return city; - } - - public void setCity(TextView city) { - this.city = city; - } - - public TextView getPop() { - return pop; - } - - public void setPop(TextView pop) { - this.pop = pop; - } - - public TextView get_id() { - return _id; - } - - public void set_id(TextView _id) { - this._id = _id; - } - - public TextView getState() { - return state; - } - - public void setState(TextView state) { - this.state = state; - } - public List zipcodes; public TextView _id; public TextView pop; @@ -95,7 +41,7 @@ protected void onCreate(Bundle savedInstanceState) { zipcodes = new ArrayList(); 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); _id = (TextView) findViewById(R.id.field_idvalue); @@ -108,6 +54,8 @@ protected void onCreate(Bundle savedInstanceState) { addjson.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + File directory = getExternalCacheDir(); + } }); @@ -116,6 +64,41 @@ public void onClick(View v) { public void onClick(View v) { File directory = getExternalCacheDir(); File file = new File(directory, "zipcodes.json"); + FileWriter fileWriter = null; + try { + fileWriter = new FileWriter(file, false); + fileWriter.write("id:"+_id.getText().toString()); + fileWriter.write("pop"+pop.getText().toString()); + fileWriter.write("city"+city.getText().toString()); + fileWriter.write("state:"+state.getText().toString()); + fileWriter.write("loc:"+_lat.getText().toString()+","+_long.getText().toString()); + fileWriter.close(); + + } catch (IOException e) { + e.printStackTrace(); + } + loadjson.callOnClick(); + + + try { + FileInputStream fis=openFileInput("zipcodes.json"); + StringBuffer buffer= new StringBuffer(); + int read=-1; + while((read=fis.read())!=-1){ + buffer.append((char)read); + } + String output=buffer.toString(); + + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + + } + + } }); diff --git a/src/main/java/nyc/c4q/ListViewActivity.java b/src/main/java/nyc/c4q/ListViewActivity.java index 14cbcb4..c891f41 100644 --- a/src/main/java/nyc/c4q/ListViewActivity.java +++ b/src/main/java/nyc/c4q/ListViewActivity.java @@ -1,11 +1,13 @@ package nyc.c4q; import android.app.Activity; +import android.graphics.Color; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.EditText; +import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; @@ -46,13 +48,15 @@ protected void onCreate(Bundle savedInstanceState) { listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - textLog.setText("You clicked on Item(position=" + position + ", color=" + COLORS[position]+")"); - + textLog.setText("You clicked on Item(position=" + position + ", color=" + COLORS[position] + ")"); + LinearLayout activityLayout= (LinearLayout) findViewById(R.id.header); + activityLayout.setBackgroundColor(Color.parseColor(COLORS[position])); } }); + } diff --git a/src/main/java/nyc/c4q/NotificationActivity.java b/src/main/java/nyc/c4q/NotificationActivity.java index a4f7d82..8c80c92 100644 --- a/src/main/java/nyc/c4q/NotificationActivity.java +++ b/src/main/java/nyc/c4q/NotificationActivity.java @@ -3,14 +3,15 @@ import android.app.Activity; import android.app.Notification; import android.app.NotificationManager; -import android.content.Context; +import android.app.PendingIntent; +import android.content.Intent; import android.os.Bundle; import android.support.v4.app.NotificationCompat; import android.view.View; import android.widget.Button; public class NotificationActivity extends Activity { - NotificationManager notificationManager; + public NotificationManager notificationManager; public static final int ID_AUTOCANCEL_NOTIFICATION = 1; public static final int ID_SWIPE_NOTIFICATION = 2; public static final int ID_PERMANENT_NOTIFICATION = 3; @@ -20,7 +21,6 @@ public class NotificationActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_notification); - notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Button autocancelnotification = (Button) findViewById(R.id.autocancelnotification); @@ -30,20 +30,65 @@ protected void onCreate(Bundle savedInstanceState) { Button buttonnotification = (Button) findViewById(R.id.buttonnotification); + autocancelnotification.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + 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); + PendingIntent notifyPIntent = + PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0); + builder.setContentIntent(notifyPIntent); + builder.setAutoCancel(true); + + notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); + notificationManager.notify(ID_AUTOCANCEL_NOTIFICATION, builder.build()); + + } + }); - autocancelnotification.setOnClickListener(new View.OnClickListener() { + swipenotification.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(NotificationActivity.this) - .setSmallIcon(R.drawable.c4qfavicon) - .setContentTitle("default@c4q.nyc") - .setContentText("Touch me to dismiss me!"); - notificationManager = - (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); - Notification notification=mBuilder.build(); - notification.flags =Notification.DEFAULT_LIGHTS|Notification.FLAG_AUTO_CANCEL; - notificationManager.notify(1, notification); + + Notification.Builder notice2=new Notification.Builder(getApplicationContext()) + .setContentTitle("swipe@c4q.nyc") + .setAutoCancel(true) + .setContentText("swipe@c4q.nyc") + .setSmallIcon(R.drawable.c4qfavicon); + + notificationManager.notify(ID_SWIPE_NOTIFICATION,notice2.build()); + + } + }); + + + permanentnotification.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + NotificationCompat.Builder builder = new NotificationCompat.Builder(NotificationActivity.this); + builder.setContentTitle("permanent@c4q.nyc"); + builder.setContentText("I'm staying planted right here."); + builder.setSmallIcon(R.drawable.c4qfavicon); + PendingIntent notifyPIntent = + PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0); + builder.setContentIntent(notifyPIntent); + builder.setOngoing(true); + + notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); + notificationManager.notify(ID_PERMANENT_NOTIFICATION, builder.build()); + } + }); + + + dismisspermanentnotification.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + notificationManager.cancel(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..1df3fb9 100644 --- a/src/main/java/nyc/c4q/json/Zipcode.java +++ b/src/main/java/nyc/c4q/json/Zipcode.java @@ -1,4 +1,13 @@ package nyc.c4q.json; public class Zipcode { + + public String _id; + public int pop; + public String city; + public String state; + public double loc; + public double _lat; + public double _long; + } diff --git a/src/main/res/layout/activity_listview.xml b/src/main/res/layout/activity_listview.xml index 6c5ab1b..f4d5cc8 100644 --- a/src/main/res/layout/activity_listview.xml +++ b/src/main/res/layout/activity_listview.xml @@ -19,6 +19,7 @@ android:id="@+id/textLog" android:layout_width="0dp" android:layout_weight="3" + android:background="@drawable/c4qfavicon" android:onClick="whenClicked" android:layout_height="match_parent" android:text="You have not clicked anything." /> @@ -34,6 +35,7 @@