diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..69fca43 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +Networking-in-Android \ No newline at end of file diff --git a/.idea/Networking-in-Android.iml b/.idea/Networking-in-Android.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/Networking-in-Android.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..9fe2e42 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + 1.7 + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..6ad68ae --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..53e6e41 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,228 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1483039223024 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file 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..c4b4927 --- /dev/null +++ b/MyApplication2/.idea/.name @@ -0,0 +1 @@ +MyApplication2 \ 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 + + +