From 28a94df97983be72182e812bdd6c9abb646ab837 Mon Sep 17 00:00:00 2001 From: William-Tygret Date: Wed, 24 Feb 2016 16:42:49 -0600 Subject: [PATCH 1/3] networking --- MyApplication2/.gitignore | 8 + MyApplication2/.idea/.name | 1 + MyApplication2/.idea/compiler.xml | 22 +++ .../.idea/copyright/profiles_settings.xml | 3 + MyApplication2/.idea/gradle.xml | 18 ++ MyApplication2/.idea/misc.xml | 62 +++++++ MyApplication2/.idea/modules.xml | 9 + MyApplication2/.idea/runConfigurations.xml | 12 ++ MyApplication2/.idea/vcs.xml | 6 + MyApplication2/app/.gitignore | 1 + MyApplication2/app/build.gradle | 26 +++ MyApplication2/app/proguard-rules.pro | 17 ++ .../networkinglab/ApplicationTest.java | 13 ++ .../app/src/main/AndroidManifest.xml | 23 +++ .../networkinglab/MainActivity.java | 147 ++++++++++++++++ .../app/src/main/res/layout/activity_main.xml | 44 +++++ .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3418 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2206 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4842 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7718 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 10486 bytes .../app/src/main/res/values-w820dp/dimens.xml | 6 + .../app/src/main/res/values/colors.xml | 6 + .../app/src/main/res/values/dimens.xml | 5 + .../app/src/main/res/values/strings.xml | 3 + .../app/src/main/res/values/styles.xml | 11 ++ .../networkinglab/ExampleUnitTest.java | 15 ++ MyApplication2/build.gradle | 23 +++ MyApplication2/gradle.properties | 18 ++ .../gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 53637 bytes .../gradle/wrapper/gradle-wrapper.properties | 6 + MyApplication2/gradlew | 160 ++++++++++++++++++ MyApplication2/gradlew.bat | 90 ++++++++++ MyApplication2/settings.gradle | 1 + 34 files changed, 756 insertions(+) create mode 100644 MyApplication2/.gitignore create mode 100644 MyApplication2/.idea/.name create mode 100644 MyApplication2/.idea/compiler.xml create mode 100644 MyApplication2/.idea/copyright/profiles_settings.xml create mode 100644 MyApplication2/.idea/gradle.xml create mode 100644 MyApplication2/.idea/misc.xml create mode 100644 MyApplication2/.idea/modules.xml create mode 100644 MyApplication2/.idea/runConfigurations.xml create mode 100644 MyApplication2/.idea/vcs.xml create mode 100644 MyApplication2/app/.gitignore create mode 100644 MyApplication2/app/build.gradle create mode 100644 MyApplication2/app/proguard-rules.pro create mode 100644 MyApplication2/app/src/androidTest/java/com/example/williamtygret/networkinglab/ApplicationTest.java create mode 100644 MyApplication2/app/src/main/AndroidManifest.xml create mode 100644 MyApplication2/app/src/main/java/com/example/williamtygret/networkinglab/MainActivity.java create mode 100644 MyApplication2/app/src/main/res/layout/activity_main.xml create mode 100644 MyApplication2/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 MyApplication2/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 MyApplication2/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 MyApplication2/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 MyApplication2/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 MyApplication2/app/src/main/res/values-w820dp/dimens.xml create mode 100644 MyApplication2/app/src/main/res/values/colors.xml create mode 100644 MyApplication2/app/src/main/res/values/dimens.xml create mode 100644 MyApplication2/app/src/main/res/values/strings.xml create mode 100644 MyApplication2/app/src/main/res/values/styles.xml create mode 100644 MyApplication2/app/src/test/java/com/example/williamtygret/networkinglab/ExampleUnitTest.java create mode 100644 MyApplication2/build.gradle create mode 100644 MyApplication2/gradle.properties create mode 100644 MyApplication2/gradle/wrapper/gradle-wrapper.jar create mode 100644 MyApplication2/gradle/wrapper/gradle-wrapper.properties create mode 100755 MyApplication2/gradlew create mode 100644 MyApplication2/gradlew.bat create mode 100644 MyApplication2/settings.gradle diff --git a/MyApplication2/.gitignore b/MyApplication2/.gitignore new file mode 100644 index 0000000..c6cbe56 --- /dev/null +++ b/MyApplication2/.gitignore @@ -0,0 +1,8 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures diff --git a/MyApplication2/.idea/.name b/MyApplication2/.idea/.name new file mode 100644 index 0000000..eea1ab1 --- /dev/null +++ b/MyApplication2/.idea/.name @@ -0,0 +1 @@ +NetworkingLab \ No newline at end of file diff --git a/MyApplication2/.idea/compiler.xml b/MyApplication2/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/MyApplication2/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyApplication2/.idea/copyright/profiles_settings.xml b/MyApplication2/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/MyApplication2/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/MyApplication2/.idea/gradle.xml b/MyApplication2/.idea/gradle.xml new file mode 100644 index 0000000..1bbc21d --- /dev/null +++ b/MyApplication2/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/MyApplication2/.idea/misc.xml b/MyApplication2/.idea/misc.xml new file mode 100644 index 0000000..c60d22d --- /dev/null +++ b/MyApplication2/.idea/misc.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1.7 + + + + + + + + \ No newline at end of file diff --git a/MyApplication2/.idea/modules.xml b/MyApplication2/.idea/modules.xml new file mode 100644 index 0000000..7ffac15 --- /dev/null +++ b/MyApplication2/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/MyApplication2/.idea/runConfigurations.xml b/MyApplication2/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/MyApplication2/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/MyApplication2/.idea/vcs.xml b/MyApplication2/.idea/vcs.xml new file mode 100644 index 0000000..6564d52 --- /dev/null +++ b/MyApplication2/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/MyApplication2/app/.gitignore b/MyApplication2/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/MyApplication2/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/MyApplication2/app/build.gradle b/MyApplication2/app/build.gradle new file mode 100644 index 0000000..e78a699 --- /dev/null +++ b/MyApplication2/app/build.gradle @@ -0,0 +1,26 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 23 + buildToolsVersion "23.0.2" + + defaultConfig { + applicationId "com.example.williamtygret.networkinglab" + minSdkVersion 19 + targetSdkVersion 23 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + testCompile 'junit:junit:4.12' + compile 'com.android.support:appcompat-v7:23.1.1' +} diff --git a/MyApplication2/app/proguard-rules.pro b/MyApplication2/app/proguard-rules.pro new file mode 100644 index 0000000..3f053f4 --- /dev/null +++ b/MyApplication2/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/williamtygret/Library/Android/sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/MyApplication2/app/src/androidTest/java/com/example/williamtygret/networkinglab/ApplicationTest.java b/MyApplication2/app/src/androidTest/java/com/example/williamtygret/networkinglab/ApplicationTest.java new file mode 100644 index 0000000..949c776 --- /dev/null +++ b/MyApplication2/app/src/androidTest/java/com/example/williamtygret/networkinglab/ApplicationTest.java @@ -0,0 +1,13 @@ +package com.example.williamtygret.networkinglab; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/MyApplication2/app/src/main/AndroidManifest.xml b/MyApplication2/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..5447346 --- /dev/null +++ b/MyApplication2/app/src/main/AndroidManifest.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + diff --git a/MyApplication2/app/src/main/java/com/example/williamtygret/networkinglab/MainActivity.java b/MyApplication2/app/src/main/java/com/example/williamtygret/networkinglab/MainActivity.java new file mode 100644 index 0000000..1d4e6b2 --- /dev/null +++ b/MyApplication2/app/src/main/java/com/example/williamtygret/networkinglab/MainActivity.java @@ -0,0 +1,147 @@ +package com.example.williamtygret.networkinglab; + +import android.os.AsyncTask; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.ListView; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.ArrayList; + +public class MainActivity extends AppCompatActivity { + + Button mButtonCereal; + Button mButtonChocolate; + Button mButtonTea; + private ListView mListView; + private ArrayList mStringArray; + private ArrayAdapter mAdapter; + + private String urlStringCereal; + private String urlStringChocolate; + private String urlStringTea; + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + + mListView = (ListView)findViewById(R.id.listView); + mStringArray = new ArrayList(); + mAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1,mStringArray); + mListView.setAdapter(mAdapter); + + urlStringCereal = "http://api.walmartlabs.com/v1/search?query=cereal&format=json&apiKey=3edm9cvfgkubxv4wg3gc59jv"; + urlStringChocolate = "http://api.walmartlabs.com/v1/search?query=chocolate&format=json&apiKey=3edm9cvfgkubxv4wg3gc59jv"; + urlStringTea = "http://api.walmartlabs.com/v1/search?query=tea&format=json&apiKey=3edm9cvfgkubxv4wg3gc59jv"; + + mButtonCereal = (Button)findViewById(R.id.buttonCereal); + mButtonCereal.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + DownloadAsyncWalmart downloadAsyncWalmart = new DownloadAsyncWalmart(); + downloadAsyncWalmart.execute(urlStringCereal); + } + }); + + mButtonChocolate = (Button)findViewById(R.id.buttonChocolate); + mButtonChocolate.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + DownloadAsyncWalmart downloadAsyncWalmart = new DownloadAsyncWalmart(); + downloadAsyncWalmart.execute(urlStringChocolate); + } + }); + + mButtonTea = (Button)findViewById(R.id.buttonTea); + mButtonTea.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + DownloadAsyncWalmart downloadAsyncWalmart = new DownloadAsyncWalmart(); + downloadAsyncWalmart.execute(urlStringTea); + } + }); + + } + + + public class DownloadAsyncWalmart extends AsyncTask { + + String data; + + @Override + protected String doInBackground(String... urls) { + try { + URL url = new URL(urls[0]); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.connect(); + + InputStream inStream = connection.getInputStream(); + + data = getInputData(inStream); + Log.d("StupidGuy","we got the data "+data); + + } catch (Throwable thro) { + thro.printStackTrace(); + } + + + try { + JSONObject dataObject = new JSONObject(data); + JSONArray itemsArray = dataObject.getJSONArray("items"); + mStringArray.clear(); + + for(int counter=0;counter + + +