From 55605f9a888849a76b82d05a3321b3897b585fb1 Mon Sep 17 00:00:00 2001 From: Matt Hernandez Date: Fri, 13 Jun 2014 12:51:50 -0500 Subject: [PATCH 01/29] Imported Socrata SDK and optimized compatibility with Android in build files. --- .idea/gradle.xml | 2 ++ .../libraries/android_async_http_1_4_2_66_g4b6eb97.xml | 9 +++++++++ .idea/libraries/appcompat_v7_19_1_0.xml | 2 +- .idea/libraries/play_services_4_4_52.xml | 10 ++++++++++ .idea/modules.xml | 1 + Recycle Austin/Recycle Austin.iml | 2 ++ Recycle Austin/build.gradle | 10 ++++++---- .../com/austindroids/recycleaustin/MainActivity.java | 1 + RecycleAustin.iml | 1 - settings.gradle | 2 +- 10 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 .idea/libraries/android_async_http_1_4_2_66_g4b6eb97.xml create mode 100644 .idea/libraries/play_services_4_4_52.xml diff --git a/.idea/gradle.xml b/.idea/gradle.xml index e0c956e..4d2c3a8 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -5,10 +5,12 @@ diff --git a/.idea/libraries/android_async_http_1_4_2_66_g4b6eb97.xml b/.idea/libraries/android_async_http_1_4_2_66_g4b6eb97.xml new file mode 100644 index 0000000..6596a9b --- /dev/null +++ b/.idea/libraries/android_async_http_1_4_2_66_g4b6eb97.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/appcompat_v7_19_1_0.xml b/.idea/libraries/appcompat_v7_19_1_0.xml index 5bd6ea8..2f91ad9 100644 --- a/.idea/libraries/appcompat_v7_19_1_0.xml +++ b/.idea/libraries/appcompat_v7_19_1_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/play_services_4_4_52.xml b/.idea/libraries/play_services_4_4_52.xml new file mode 100644 index 0000000..1f3bc69 --- /dev/null +++ b/.idea/libraries/play_services_4_4_52.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index d6566e3..fe23028 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -4,6 +4,7 @@ + diff --git a/Recycle Austin/Recycle Austin.iml b/Recycle Austin/Recycle Austin.iml index a6fbf22..cda241c 100644 --- a/Recycle Austin/Recycle Austin.iml +++ b/Recycle Austin/Recycle Austin.iml @@ -72,6 +72,8 @@ + + diff --git a/Recycle Austin/build.gradle b/Recycle Austin/build.gradle index a0c7ae8..b12fdeb 100644 --- a/Recycle Austin/build.gradle +++ b/Recycle Austin/build.gradle @@ -2,13 +2,12 @@ apply plugin: 'android' android { compileSdkVersion 19 - buildToolsVersion "19.1.0" - + buildToolsVersion '19.1.0' defaultConfig { - minSdkVersion 8 + minSdkVersion 9 targetSdkVersion 19 versionCode 1 - versionName "1.0" + versionName '1.0' } buildTypes { release { @@ -16,10 +15,13 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } } + productFlavors { + } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:support-v4:19.1.0' compile 'com.android.support:appcompat-v7:19.1.0' + compile project(':soda-android-sdk') } diff --git a/Recycle Austin/src/main/java/com/austindroids/recycleaustin/MainActivity.java b/Recycle Austin/src/main/java/com/austindroids/recycleaustin/MainActivity.java index 6730242..f65d847 100644 --- a/Recycle Austin/src/main/java/com/austindroids/recycleaustin/MainActivity.java +++ b/Recycle Austin/src/main/java/com/austindroids/recycleaustin/MainActivity.java @@ -12,6 +12,7 @@ public class MainActivity extends ActionBarActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + } diff --git a/RecycleAustin.iml b/RecycleAustin.iml index 58a239a..f25f018 100644 --- a/RecycleAustin.iml +++ b/RecycleAustin.iml @@ -4,7 +4,6 @@ - diff --git a/settings.gradle b/settings.gradle index 1c9bfcd..ae85e97 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':Recycle Austin' +include ':Recycle Austin', ':soda-android-sdk' From 61f80aab692fd3823883b0a5e54802b057da7ae4 Mon Sep 17 00:00:00 2001 From: dutchmo Date: Tue, 17 Jun 2014 19:43:23 -0500 Subject: [PATCH 02/29] small txt chg --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f7c1e5c..bb17f36 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ Recycle Austin ============= -Android app being developed by the Austin Droid's group (http://www.meetup.com/Austin-Android/) to help Austinites learn about Recycling options and services in their communities. +Android app being developed by the Austin Droid group (http://www.meetup.com/Austin-Android/) to help Austinites learn about Recycling options and services in their communities. From b6254a28dde93863ff8ef30af693b81655fea2ae Mon Sep 17 00:00:00 2001 From: Matt Hernandez Date: Wed, 18 Jun 2014 11:21:52 -0500 Subject: [PATCH 03/29] Created basic functionality of breaking an address into a Socrata query --- Recycle Austin/src/main/AndroidManifest.xml | 1 + .../recycleaustin/MainActivity.java | 258 +++++++++++++++++- .../recycleaustin/StreetDirectionMap.java | 13 + .../recycleaustin/StreetTypeMap.java | 43 +++ .../src/main/res/layout/activity_main.xml | 26 +- .../src/main/res/values/strings.xml | 4 + 6 files changed, 341 insertions(+), 4 deletions(-) create mode 100644 Recycle Austin/src/main/java/com/austindroids/recycleaustin/StreetDirectionMap.java create mode 100644 Recycle Austin/src/main/java/com/austindroids/recycleaustin/StreetTypeMap.java diff --git a/Recycle Austin/src/main/AndroidManifest.xml b/Recycle Austin/src/main/AndroidManifest.xml index 135fc51..0a543a6 100644 --- a/Recycle Austin/src/main/AndroidManifest.xml +++ b/Recycle Austin/src/main/AndroidManifest.xml @@ -1,6 +1,7 @@ + > { + + private AlertDialog alert; + private String URLaddress = "https://maps.googleapis.com/maps/api/geocode/json?address="; + + private GoogleHTTPGetRequest(String addr, AlertDialog alt) { + alert = alt; + addr = addr.trim().replace(" ", "+"); + URLaddress += addr + "+Austin,+Texas&key=AIzaSyCVfKDEiicmXo56w2Jrz0GHJ9z4wocMnoM"; + } + + @Override + protected List doInBackground(Void... params) { + HttpURLConnection connection = null; + List data = null; + try { + connection = (HttpURLConnection) new URL(URLaddress).openConnection(); + connection.setRequestMethod("GET"); + connection.connect(); + + InputStream in = new BufferedInputStream(connection.getInputStream()); + + data = readStream(in); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (connection != null) { + connection.disconnect(); + } + } + return data; + } + + protected List readStream(InputStream in) { + BufferedReader br = null; + StringBuilder sb = new StringBuilder(); + try { + br = new BufferedReader(new InputStreamReader(in)); + String line = null; + while ((line = br.readLine()) != null) { + sb.append(line); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + String houseNumber = null; + String streetName = null; + List address = new ArrayList(); + try { + JSONObject topObj = (JSONObject) new JSONTokener(sb.toString()).nextValue(); + JSONArray jArray = topObj.getJSONArray("results"); + JSONObject addressObj = jArray.getJSONObject(0); + JSONArray addressCompsArray = addressObj.getJSONArray("address_components"); + JSONObject houseNo = addressCompsArray.getJSONObject(0); + JSONObject streetComps = addressCompsArray.getJSONObject(1); + houseNumber = houseNo.getString("long_name"); + streetName = streetComps.getString("long_name"); + } catch (JSONException e) { + e.printStackTrace(); + } + if (houseNumber != null && streetName != null) { + address.add(houseNumber); + address.add(streetName); + return address; + } + address.add("problem"); + return address; + } + + @Override + protected void onPostExecute(List address) { + if (address == null) { + alert.dismiss(); + Toast.makeText(MainActivity.this, "Problem getting correct address", Toast.LENGTH_SHORT).show(); + return; + } + addressTest.setText(address.get(0) + " " + address.get(1)); + new SODAHTTPGetRequest(address.get(0), address.get(1), alert).execute(); + } + } + + private class SODAHTTPGetRequest extends AsyncTask { + + private String URLaddress = "https://data.austintexas.gov/resource/rfif-mmvg.json?$select=collection_day,collection_week&$where="; + private String houseNo; + private String addr; + private AlertDialog alert; + + private SODAHTTPGetRequest(String houseNo, String addr, AlertDialog alt) { + this.houseNo = houseNo; + this.addr = addr; + URLaddress += "house_no=\'" + houseNo + "\'"; + alert = alt; + } + + @Override + protected String doInBackground(Void... params) { + HttpURLConnection connection = null; + String[] addrComponents = addr.split("\\s"); + List addrComponentsParsed = new LinkedList(Arrays.asList(addrComponents)); + + String possibleStreetDir = addrComponentsParsed.get(0); + Map streetDirContainer = new StreetDirectionMap(); + + if (streetDirContainer.containsKey(possibleStreetDir)) { + addrComponentsParsed.remove(possibleStreetDir); + String streetDirAbbr = streetDirContainer.get(possibleStreetDir); + URLaddress += "&st_dir=" + streetDirAbbr; + } + Map streetTypeContainer = new StreetTypeMap(); + String possibleStreetType = addrComponentsParsed.get(addrComponentsParsed.size() - 1); + + if (streetTypeContainer.containsKey(possibleStreetType)) { + int index = addrComponentsParsed.size() - 1; + addrComponentsParsed.remove(index); + String streetTypeAbbr = streetTypeContainer.get(possibleStreetType); + URLaddress += "&street_typ=" + streetTypeAbbr; + } + + Iterator it = addrComponentsParsed.iterator(); + StringBuilder sb = new StringBuilder(); + while (it.hasNext()) { + sb.append(it.next()); + if (it.hasNext()) { + sb.append(" "); + } + } + URLaddress += "&street_nam=" + sb.toString(); + String data = null; + try { + connection = (HttpURLConnection) new URL(URLaddress.replace(" ", "+")).openConnection(); + connection.setRequestMethod("GET"); + connection.connect(); + + InputStream in = new BufferedInputStream(connection.getInputStream()); + + data = readStream(in); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (connection != null) { + connection.disconnect(); + } + } + return data; + } + + protected String readStream(InputStream in) { + BufferedReader br = null; + StringBuilder sb = new StringBuilder(); + try { + br = new BufferedReader(new InputStreamReader(in)); + String line = null; + while ((line = br.readLine()) != null) { + sb.append(line); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + String collectionDay = null; + String collectionWeek = null; + try { + JSONArray topArray = (JSONArray) new JSONTokener(sb.toString()).nextValue(); + JSONObject jObj = topArray.getJSONObject(0); + collectionDay = jObj.getString("collection_day"); + collectionWeek = jObj.getString("collection_week"); + } catch (JSONException e) { + e.printStackTrace(); + return "JSON Exception"; + } + + if (collectionDay != null && collectionWeek != null) { + return "Collection Day: " + collectionDay + "\nCollection Week: " + collectionWeek; + } + return "problem"; + } + + @Override + protected void onPostExecute(String s) { + addressTest.append("\n"); + addressTest.append(URLaddress + "\n"); + addressTest.append(s); + alert.dismiss(); + } + } @Override public boolean onCreateOptionsMenu(Menu menu) { diff --git a/Recycle Austin/src/main/java/com/austindroids/recycleaustin/StreetDirectionMap.java b/Recycle Austin/src/main/java/com/austindroids/recycleaustin/StreetDirectionMap.java new file mode 100644 index 0000000..d03f484 --- /dev/null +++ b/Recycle Austin/src/main/java/com/austindroids/recycleaustin/StreetDirectionMap.java @@ -0,0 +1,13 @@ +package com.austindroids.recycleaustin; + +import java.util.HashMap; + +public class StreetDirectionMap extends HashMap { + + public StreetDirectionMap() { + put("West", "W"); + put("East", "E"); + put("North", "N"); + put("South", "S"); + } +} diff --git a/Recycle Austin/src/main/java/com/austindroids/recycleaustin/StreetTypeMap.java b/Recycle Austin/src/main/java/com/austindroids/recycleaustin/StreetTypeMap.java new file mode 100644 index 0000000..3d107c8 --- /dev/null +++ b/Recycle Austin/src/main/java/com/austindroids/recycleaustin/StreetTypeMap.java @@ -0,0 +1,43 @@ +package com.austindroids.recycleaustin; + +import java.util.HashMap; + +public class StreetTypeMap extends HashMap { + + public StreetTypeMap() { + put("Crescent", "CRES"); + put("Plaza", "PLZ"); + put("Vale", "VALE"); + put("View", "VW"); + put("Skyway", "SKWY"); + put("Square", "SQ"); + put("Walk", "WALK"); + put("Glen", "GLN"); + put("Bridge", "BRG"); + put("Park", "PARK"); + put("Highway", "HWY"); + put("Crossing", "XING"); + put("Point", "PT"); + put("Terrace", "TER"); + put("Pass", "PASS"); + put("Run", "RUN"); + put("Row", "ROW"); + put("Hollow", "HOLW"); + put("Place", "PL"); + put("Avenue", "AVE"); + put("Way", "WAY"); + put("Loop", "LOOP"); + put("Parkway", "PKWY"); + put("Path", "PATH"); + put("Boulevard", "BLVD"); + put("Court", "CT"); + put("Road", "RD"); + put("Circle", "CIR"); + put("Lane", "LN"); + put("Street", "ST"); + put("Bend", "BND"); + put("Drive", "DR"); + put("Cove", "CV"); + put("Trail", "TRL"); + } +} diff --git a/Recycle Austin/src/main/res/layout/activity_main.xml b/Recycle Austin/src/main/res/layout/activity_main.xml index 04a83bb..97a25e4 100644 --- a/Recycle Austin/src/main/res/layout/activity_main.xml +++ b/Recycle Austin/src/main/res/layout/activity_main.xml @@ -8,9 +8,29 @@ android:paddingBottom="@dimen/activity_vertical_margin" tools:context="com.austindroids.recycleaustin.MainActivity"> - + +