diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index ea076f1..b6e4c90 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -4,6 +4,8 @@ android:versionCode="2" android:versionName="1.0.0-SNAPSHOT"> + + colors = new ArrayList(); + + + //ArrayAdapter adapter = new ArrayAdapter(ListViewActivity.this, R.layout.listview_tile,COLORS); + //listOfColors.setAdapter(adapter); + + } + + } diff --git a/src/main/java/nyc/c4q/NetworkActivity.java b/src/main/java/nyc/c4q/NetworkActivity.java index 3604cfc..823b716 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 =========================== @@ -104,4 +87,86 @@ public void onClick(View v) { } }); } + /* + private class getUrlParm extends AsyncTask{ + String myUrlLink; + + protected String doInBackground(String... urls){ + try{ + + }catch(IOException e){ + + } + } + } + */ + } + +/** + * private class DownloadData extends AsyncTask { + + String myXmlData; + + protected String doInBackground(String... urls) { //the ... means it will accept 0 or many urls by deinition with this AsyncTask we can proess more than one thing + try { + myXmlData = downloadXML(urls[0]); + + } catch (IOException e) { + return "Unable to download XML file"; + } + + return ""; + } + + protected void onPostExecute(String result){ + Log.d("OnPostExecute", myXmlData); + xmlData = myXmlData; + + } + + private String downloadXML(String theUrl) throws IOException { //if there is an error in this method, thorow it back to the calling method and we want that method to deal with it + int BUFFER_SIZE = 2000; //20000 chara at a time. + InputStream is = null; //the mecanism we will use to do the download + + String xmlContents = ""; //temp container for our data + + try { + URL url = new URL(theUrl); //start opening the url the website address + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); //open a link or a a reference to that website + conn.setReadTimeout(10000); //for whatever the reason we cannot download the file we want to close it gracefully. the maximum time to wait for an input stream read before giving up mill sec + conn.setConnectTimeout(15000); //connection timer same reason as before + conn.setRequestMethod("GET"); // get is a stanard way to access data for a web browser + conn.setDoInput(true); //input data + int response = conn.getResponseCode(); //get a response and see what happens + Log.d("DownloadXML", "The response returned is: " + response); //if the response was okay then it would be 200 + is = conn.getInputStream(); + + InputStreamReader isr = new InputStreamReader(is); //read through whatever we send you + int charRead; + char[] inputBuffer = new char[BUFFER_SIZE]; + try { + while ((charRead = isr.read(inputBuffer)) > 0) + { //Reading through the inputBUffer charRead is the number of characters that have been read by this process + String readString = String.copyValueOf(inputBuffer, 0, charRead);//go through the array and we start at 0 and go through however many character have been read + + xmlContents += readString; //continually add whatever we read to the xmlContents string + // and then now that we've read that we want to clear out the inputBuffer + inputBuffer = new char[BUFFER_SIZE]; + } + + return xmlContents; + + } catch (IOException e) { + e.printStackTrace(); //shows where it crashed + return null; // if there was a problem then it wont return anything + } + + } finally { + if (is != null) //no matter what, if there's an error we still want to execute the code that's in here + is.close(); //whether there is an error or not, make sure we close this InputStream + } + } + } + * + */ \ No newline at end of file diff --git a/src/main/java/nyc/c4q/json/Zipcode.java b/src/main/java/nyc/c4q/json/Zipcode.java index 6d4761f..5f93758 100644 --- a/src/main/java/nyc/c4q/json/Zipcode.java +++ b/src/main/java/nyc/c4q/json/Zipcode.java @@ -1,4 +1,96 @@ package nyc.c4q.json; +import android.os.AsyncTask; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.HashMap; + public class Zipcode { + public String _id ="11101"; + public String city = "ASTORIA"; + public String state = "NY"; + public int pop = 23142; + + public double[] loc = new double[]{-73.939393,40.750316}; + + + public static final String TAG_ID = "_id"; + public static final String TAG_CITY = "city"; + public static final String TAG_STATE = "state"; + public static final String TAG_POPULATION = "pop"; + public static final String TAG_LOCATION = "loc"; + public String data; + JSONArray jsonArray = null; + HashMap organized = new HashMap(); + + + public Zipcode(String data) { + this.data = data; + } + + public String get(String data){ + return this.data; + } + + public String getField(String tag){ + new GetInformation().execute(); + if(tag == TAG_ID){ + return organized.get("Zipcode"); + }else if(tag == TAG_CITY){ + return organized.get("City"); + }else if(tag == TAG_STATE){ + return organized.get("State"); + }else if( tag == TAG_POPULATION){ + return organized.get("Population"); + }else{ + return null; + } + } + + + + private class GetInformation extends AsyncTask{ + + @Override + protected Void doInBackground(Void... params){ + + String jsonStr = data; + + + if(jsonStr != null){ + try{ + jsonArray = new JSONArray(jsonStr); + + for(int i=0; i < jsonArray.length();i++ ){ + JSONObject object = jsonArray.getJSONObject(i); + + String id = object.getString(TAG_ID); + String city = object.getString(TAG_CITY); + String state = object.getString(TAG_STATE); + String population = object.getString(TAG_POPULATION); + String location = object.getString(TAG_LOCATION); + + organized.put("Zipcode",id); + organized.put("City",city); + organized.put("State", state); + organized.put("Population", population); + + + + } + + + }catch (JSONException e){ + e.printStackTrace(); + } + } + + return null; + } + + } + } diff --git a/src/main/res/layout/activity_listview.xml b/src/main/res/layout/activity_listview.xml index 0d4b9d6..f71d05d 100644 --- a/src/main/res/layout/activity_listview.xml +++ b/src/main/res/layout/activity_listview.xml @@ -9,20 +9,34 @@ + 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" + android:entries="@array/COLOR" /> + + + \ No newline at end of file diff --git a/src/main/res/values/string.xml b/src/main/res/values/string.xml new file mode 100644 index 0000000..4c9202d --- /dev/null +++ b/src/main/res/values/string.xml @@ -0,0 +1,19 @@ + + + + + #142b44 + #1d508d + #297cbb + #288ad6 + #0fdebd + #16c98d + #feef6d + #ffc83f + #fa5e5b + #bf538d + + + + +